akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
	int ans = 0;
	vector<int> jijo;
	for (int i = 0; i < 1000; ++i)jijo.push_back(i * i);
	int n, d;
	cin >> n >> d;
	vector<vector<int>> x(n);
	for (int i = 0; i < n; ++i) {
		x[i].resize(d);
		for (int j = 0; j < d; ++j)cin >> x[i][j];
	}
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			int dist = 0;
			for (int k = 0; k < d; ++k)dist += pow(x[i][k] - x[j][k], 2);
			if (find(jijo.begin(), jijo.end(), dist) != jijo.end())++ans;
		}
	}
	cout << ans << endl;
}

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

int main(){
  int n;
  cin>>n;
  int x = n%10;
  if(x==2 || x==4 || x==5 || x==7 || x==9) cout<<"hon"<<endl;
  else if(x==0 || x==1 || x==6 || x==8) cout<<"pon"<<endl;
  else cout<<"bon"<<endl;
}

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {

    try (Scanner sc = new Scanner(System.in)) {
      String line = sc.nextLine();
      String answer = "";
      int length = line.length();
      for (int i = 0; i < length; i++) {
        char ch = line.charAt(i);
        if(Character.isLowerCase(ch)){
          answer += Character.toUpperCase(ch);
        }else{
          answer += Character.toLowerCase(ch);
        }
        
      }
      System.out.println(answer);
    }
  }
}


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

int main(){
  long N,A,B;
  cin >> N >> A >> B;
  long ans=0;
  ans += N/(A+B)*A;
  if(N%(A+B) <= A) ans += N%(A+B);
  else ans += A;
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

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

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int a = in.nextInt();
			int b = in.nextInt();
			int dif = b - a;
			int total = 0;
			for(int i = 1; i <= dif; i++) {
				total += i;
			}
			out.println(total  - b);
		}
	}
		
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int a,b,c,d,e,f;
	cin >> a >> b  >> c >> d >> e >> f;

	int mwat = -1;
	int msug = -1;
	for(int i=0; 100*i*a <= f; i++){
		for(int j=0; 100*i*a + 100*j*b <= f; j++){
			int wat = 100*i*a + 100*j*b;
			if(wat == 0) continue;

			for(int k=0; (wat+k*c <= f) && (k*c <= wat/100*e); k++){
				for(int l=0; (wat+k*c+l*d <= f) && (k*c + l*d <= wat/100*e); l++){
					int sug = k*c+l*d;
					if(mwat == -1){
						msug = sug;
						mwat = wat;
					}
					if(sug*(msug+mwat) > msug*(sug+wat)){
						msug = sug;
						mwat = wat;
					}
				}
			}
		}
	}

	cout << (mwat+msug) << " " << msug;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
static const int INF=100000000;

int main() {
  int H,N;
  cin>>H>>N;
  int A[N];
  int B[N];
  int maxA=0;
  for(int i=0;i<N;i++){
    cin>>A[i]>>B[i];
    maxA=max(maxA,A[i]);
  }
  
  int DP[H+maxA+1];
  for(int i=0;i<=H+maxA;i++){
    DP[i]=INF;
  }
  DP[0]=0;
  for(int i=0;i<=H+maxA;i++){
    for(int j=0;j<N;j++){
      if(i+A[j]<=H+maxA){
        DP[i+A[j]]=min(DP[i+A[j]],DP[i]+B[j]);
      }
    }
  }
  int ans=INF;
  for(int i=H;i<=H+maxA;i++){
    ans=min(ans,DP[i]);
  }
  cout<<ans<<endl;
  
}

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

int n, x, y, res, fir=1, rt, f[101000];
vector<int>G[101000];

void dfs(int x,int fff){
  int isrt=0;
  if (G[x].size()>2&&fir) fir=0, isrt=1;
  for (auto y:G[x]) if (y!=fff) dfs(y,x);
  int t=max(0,(int)G[x].size()+isrt-2-f[x]);
  f[fff]+=!!f[x]|!!t;
  res+=t;
}

int main(){
  cin>>n;
  for (int i=n-1;i--;){
    scanf("%d%d",&x,&y); ++x; ++y;
    G[x].push_back(y); G[y].push_back(x);
  }
  for (rt=1;G[rt].size()!=1;++rt); dfs(rt,0);
  cout<<max(res,1);
}

Measured memory_bytes: 12416
#include<iostream>
using namespace  std;
bool isPrime(int p)
{
	if (p <= 1)return false;
	for (int i = 2; i * i <= p; i++)
	{
		if (p % i == 0)return false;
	}
	return true;
}
int main()
{
	int n;

	while (cin >> n)
	{
		int mi = -1, ma = -1;
		for (int i = n - 1; i >= 2; i--)
		{
			if (isPrime(i))
			{
				mi = i;
				break;
			}
		}
		for (int i = n + 1;; i++)
		{
			if (isPrime(i))
			{
				ma = i;
				break;
			}
		}
		cout << mi << " " << ma << endl;
	}
	return 0;
}

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

int main() {
    int n, sol = 0;
    cin >> n;
    int a[2][n];
    for (int i = 0; i < 2; i++)
        for (int j = 0; j < n; j++)
            cin >> a[i][j];
    for (int i = 0; i < n; i++) {
        int tmp = 0;
        for (int j = 0; j <= i; j++) tmp += a[0][j];
        for (int j = i; j < n; j++) tmp += a[1][j];
        sol = max(sol, tmp);
    }
    cout << sol;
    return 0;
}


Measured memory_bytes: 256
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      int N = nextInt();
      myout((N <= 999) ? "ABC" : "ABD");
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 33044
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInt();
            var a = ReadInt();
            var x = n % 500;
            if (a >= x)
            {
                WriteLine("Yes");
            }
            else
            {
                WriteLine("No");
            }
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int a[mx5];

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

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

    for(int i = 1; i < n; i++){
        a[i] = __gcd(a[i], a[i - 1]);
    }

    cout << a[n - 1] << '\n';
    return 0;
}


Measured memory_bytes: 3952
#include<stdio.h>

int main(void){
  int W,H,x,y,r;
  int flag = 1;
  
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

  if(x+r > W){
    flag = 0;
  }else if(x-r < 0){
    flag = 0;
  }else if(y+r > H){
    flag = 0;
  }else if(y-r < 0){
    flag = 0;
  }

  if(flag){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}



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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<ll> A(N);
    for (int i=0;i<N;++i) cin >> A[i];
    ll cnt=0,ans=0;
    for (int i=0;i<N;++i){
        ans+=(A[i]-1)/(cnt+1);
        if (cnt+1==A[i]||!i) ++cnt;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 1024
h, w = [int(i) for i in input().split()]
a = []
d = []
h_new = 0
for i in range(h):
  b = input()
  if "#" in b:
    a.append(list(b))
    h_new += 1
for i in range(w):
  c = []
  for j in range(h_new):
    c.append(a[j][i])
  if "#" not in c:
    d.append(i)
e = ""
for i in range(h_new):
  for j in range(w):
    if j not in d:
      print(a[i][j],end="")
  print("\n")

Measured memory_bytes: 4596
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

void solve_A(); void solve_B(); void solve_C(); void solve_D();

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    /*
     solve_A();
     //*/
    
    /*
     solve_B();
     //*/
    
    
    //*
     solve_C();
     //*/
    
    /*
    solve_D();
     //*/
	return 0;
}

void solve_A(){
    ll N; cin >> N;
    cout << N/3 << endl;
}

void solve_B(){
    ll N; cin >> N;
    vector<char> S(N);
    for(auto &in:S) cin >> in;
    bool f1,f2,f3,f4;
    f1 = f2 = f3 = f4 = false;
    for(int i = 0; i < N;i++){
        if(S[i] == 'P') f1 = true;
        if(S[i] == 'W') f2 = true;
        if(S[i] == 'G') f3 = true;
        if(S[i] == 'Y') f4 = true;
    }
    if(f4){
        cout << "Four" << endl;
    }else{
        cout << "Three" << endl;
    }
}

void solve_C(){
    ll N; cin >> N;
    vector<string> S(N);
    for(auto &in:S) cin >> in;
    ll MARCH[5] = {};
    char C[5] = {'M','A','R','C','H'};
    for(int i = 0 ;i < N;i++){
        for(int j = 0; j < 5;j++){
            if(S[i][0] == C[j]) MARCH[j]++;
        }
    }
    ll ans = 0;
    for(int i = 0; i < 5; i++){
        for(int j = i + 1; j < 5;j++){
            for(int k = j + 1; k < 5;k++){
                ans += MARCH[i] * MARCH[j] * MARCH[k];
            }
        }
    }
    cout << ans << endl;
}

void solve_D(){
    
}


Measured memory_bytes: 5760
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <bitset>

using ll = long long int;
using ul = unsigned long long int;

namespace lamlib
{
	// Absolute
	template<class T> inline T abs(const T &a){ return (a>0) ? a : -a; }
	// GCD: a > b
	ul gcd(ul a,ul b) { return (!b) ? a : gcd(b,a%b); }
}

int main(int argc,char *argv[])
{
	long double a,b,c;
	std::cin >> a >> b >> c;

	long double d = c - a - b;
	bool is = ((d*d) > (4.0 * a * b));

	if(d > 0 && is) std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  bool flag = false;
  if(a+b+c==17){
    if(a==5&&b==7)flag = true;
    if(a==7&&b==5)flag = true;
    if(a==5&&b==5)flag = true;
  }
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int n;
vector<P> p;
int main(void){
    cin >> n;
    p.reserve(n);
    for(int i=0;i<n;i++){
        int x, l;
        cin >> x >> l;
        p.push_back(P(x+l, x-l));
    }
    sort(p.begin(), p.end());

    int ans = 1, b = p[0].first;
    for(int i=1;i<n;i++){
        if(p[i].second < b) continue;
        ans++;
        b = p[i].first;
    }
    cout << ans << endl;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  map<int, int> cnt;
  for (int i = 1; i < N + 1; i++) {
    int n = i;
    for (int j = 2; j * j < n + 1; j++) {
      while (n % j == 0) {
        cnt[j]++;
        n /= j;
      }
    }
    if (n > 1) cnt[n]++;
  }

  // (1, 75), (3, 25), (3, 5, 5), (5, 15)
  auto f = [&](int x) -> int {
    int res = 0;
    for (int i = 0; i < N + 1; i++) {
      if (cnt[i] >= x - 1) res++;
    }
    return res;
  };

  cout << f(75) + f(25) * (f(3) - 1) + f(15) * (f(5) - 1) +
              f(5) * (f(5) - 1) * (f(3) - 2) / 2
       << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<pair<int,int>> a;
int main(){
	int n,k;
	cin>>n>>k;
	int sum=((n-1)*(n-2))/2;
	if(k>sum){
		cout<<-1<<endl;
		return 0;
	}
	for(int i=2;i<=n;i++){
		a.push_back({1,i});
	}
	int now=2;
	while(sum>k){
		for(int i=now+1;i<=n;i++){
			if(sum>k) sum--,a.push_back({now,i});
			else break;
		}
		now++;
	}
	cout<<a.size()<<endl;
	for(int i=0;i<a.size();i++){
		cout<<a[i].first<<" "<<a[i].second<<endl;
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5+5;
const ll mod =   1e9+7;

int main()
{  fast
int x;
cin>>x;if(x>=30)
cout<<"Yes\n";
else
cout<<"No\n";
}

Measured memory_bytes: 3648
#ifdef __GNUG__
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG // ArrayOutofBounds
#else
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#endif
#define rep(i, N) for (int i = 0; i < N; i++) //制御変数iを用いてN回転
using namespace std;
using ll = long long;
//0:上 1:左 2:下 3:右
const int di[] = { -1, 0, 1, 0};
const int dj[] = { 0, -1, 0, 1};

int main() {
    int N;
    const ll mod = 1000000007;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll ans = 0, sum = 0;;
    for (int j = 1; j < N; j++) {
        sum += A[j - 1] % mod;
        sum %= mod;
        ans += (sum * A[j]) % mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

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

int main(int argc, char *argv[]) {
	uint32_t input_a = 0;
	uint32_t input_b = 0;
	char op;
	int32_t result = 0;

	std::cin >> input_a;
	std::cin >> op;
	std::cin >> input_b;

	switch (op) {
	case '+':
		result = input_a + input_b;
		break;
	case '-':
		result = input_a - input_b;
		break;
	}

	std::cout << result << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int search(int A[], int n, int key) {
  int i = 0;  A[n] = key;
  while(A[i] != key) i++;
  return i != n;
}
int main(void) {
  int i, n, A[10000+1], q, key, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d", &A[i]);
  scanf("%d",&q);
  for(i=0; i<q; i++) {
    scanf("%d", &key);
    if(search(A, n, key)) sum++;
  }
  printf("%d\n", sum);
  return 0;
}


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

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define FORR(v, c) for (auto &v : c)
#define F first
#define S second
#define SQ(x) (x)*(x)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define dbg(x) cerr<<#x<<" = " << (x) << endl
#define pnl(x) cout << x << '\n'
#define pns(x) cout << x << ' '
#define read(x) cin >> x
#define read2(x,y) cin >> x >> y
#define read3(x, y, z) cin >> x >> y >> z
#define read4(a, b, c, d) cin >> a >> b >> c >> d
#define readv(v) FORR(c,v) read(c)

struct Arrete { int v, c;};
struct Point {int x, y; double distance(Point other) const {return sqrt(SQ(x-other.x)+SQ(y-other.y));}};

typedef	vector<int>	vi;
typedef pair<int,int>	ii;
typedef vector<string>	vs;
typedef vector<ii>	vii;
typedef vector<Arrete>	vg;
typedef vector<long long>	vl;
typedef	long long ll;

const int MAXK = 1e5;
const int MAXN = 1e2+1;
const int MOD = 1e9+7;

int max_candy[MAXN];
ll dp[MAXN][MAXK];
int N, K;


int		main(void)
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	read2(N, K);
	FOR(i,0, N) read(max_candy[i]);
	
	dp[0][K] = 1;
	for (int i(1); i <= N; ++i)
	{
//		cout << i << ": ";
		for (int k(0); k <= K; ++k)
		{
			dp[i][k] = (dp[i-1][min(K, max_candy[i-1]+k)] - (k ? dp[i-1][k-1]: 0) + MOD)%MOD;
//			cout << k << ":" << dp[i][k] << " ";
		}
		
//		cout << endl;
		

		for (int j(0); j < K; ++j)
			dp[i][j+1] = (dp[i][j] + dp[i][j+1])%MOD;
	}

	pnl(dp[N][0]);
}



Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  int H[N];
  int flag=0;
  rep(i,N) cin >> H[i];
  for(int i=N-1; i>0; i--){
    if(H[i] < H[i-1]){
      H[i-1]--;
    }    
  }
  rep(i,N){
    if(H[i] < H[i-1]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
    

}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)







vector<vector<pair<ll, ll>>> g;
vector<ll> ans;

void dfs(ll now, ll par, ll par_col){
    ll col = 1;
    for(auto &e : g[now]){
        if(e.first == par) continue;
        if(col == par_col) col++;
        ans[e.second] = col;
        dfs(e.first, now, col);
        col++;
    }
}



int main(){
    ll n;
    cin >> n;
    g.resize(n);
    ans.resize(n - 1);
    REP(i, n - 1){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back({b, i});
        g[b].push_back({a, i});
    }
    dfs(0, -1, -1);
    cout << *max_element(ans.begin(), ans.end()) << endl;
    REP(i, n - 1){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 9728
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>
#include <sys/time.h>
#include <fstream>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define REP(i,n)  FOR(i,0,n)
#define each(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define deb(x) cerr << #x << " = " << (x) << " , ";
#define debl cerr << " (L" << __LINE__ << ")"<< endl;
#define sz(s) (int)((s).size())


#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(x,y) make_pair((x),(y))

double pi=3.14159265358979323846;

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& z){
	os << "[ ";
	REP(i,z.size())os << z[i] << ", " ;
	return ( os << "]" << endl);
}

template<typename T> std::ostream& operator<<(std::ostream& os, const set<T>& z){
	os << "set( ";
	EACH(p,z)os << (*p) << ", " ;
	return ( os << ")" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const map<T,U>& z){
	os << "{ ";
	EACH(p,z)os << (p->first) << ": " << (p->second) << ", " ;
	return ( os << "}" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const pair<T,U>& z){
	return ( os << "(" << z.first << ", " << z.second << ",)" );
}

double get_time(){
	struct timeval tv;
	gettimeofday(&tv, NULL);
	return tv.tv_sec + tv.tv_usec*1e-6;
}

typedef unsigned int uint32_t;
struct RND{
	uint32_t x;
	uint32_t y;
	uint32_t z;
	uint32_t w;
	RND(){
		x=123456789;
		y=362436069;
		z=521288629;
		w=88675123;
	}
	void init(int seed){
		x=123456789;
		y=362436069;
		z=521288629;
		w=seed+100;
		REP(i,10)get();
	}
	uint32_t get(){
		uint32_t t;
		t=x^(x<<11);
		x=y;y=z;z=w;
		w=(w^(w>>19))^(t^(t>>8));
		return w;
	}
};
RND rnd;

ll A,B,C,D;
ll gcd(ll x, ll y){
	if(y==0)return x;
	return gcd(y,x%y);
}


bool cal(ll A, ll B, ll C, ll D){
	if(A<B)return false;
	if(D<B)return false;
	ll m = gcd(B,D);
	ll p = ((A-C)%m+m)%m;
	if(p==0)p=m;
	return (C+p) >=B;

}

void _main(istream &inp){
	ll T;
	inp >> T;
	rep(ii,T){
		ll A,B,C,D;
		inp >> A >> B >> C >> D;
		if(cal(A,B,C,D)){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	while(true){
		break;
	}

}

int main(){
	if(0){
		ifstream ifs("test.txt");
		_main(ifs);
	}
	else{
		_main(cin);
	}
	return 0;
}


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

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using ull = unsigned long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using ii = pair<int,int>;
using vii = vector<ii>;
using vvii = vector<vii>;
using dd = pair<double, double>;
using vdd = vector<dd>;
using vvdd = vector<vdd>;
using Mii = map<int,int>;
using vMii = vector<Mii>;
using Si = set<int>;
using vSi = vector<Si>;
using vvSi = vector<vSi>;

#define fi first
#define se second
#define INF 1e9 + 5
#define mod(a,m) (a%m+m)%m
#define PB push_back
#define MP make_pair

int main(){
//	cout.setf(ios::fixed);
//	cout.precision(4);
	int n;
	while(cin >> n) {
		vll d(n);
		for (int i = 0; i < n; ++i) {
			cin >> d[i];
		}
		ll ans = 0;
		ll sum = 0;
		for (int i = 0; i < n; ++i) {
			sum += d[i];
		}
		for (int i = n-1; i >= 0; --i) {
			sum -= d[i];
			ans += d[i] * sum;
		}
		cout << ans << endl;
	}
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long a[100005],maxn;
int n,k;
int check(long long p)
{
    int i=0;
    for(int j=1;j<=k;j++)
    {
        long long s=0;
        while(s+a[i]<=p)
        {
            s+=a[i];
            i++;
            if(i==n) return n;
        }
    }
    return i;
}
int solve()
{
    long long left=0,right=maxn,mid;
    while(left<right-1)
    {
        mid=left+(right-left)/2;
        if(check(mid)>=n) right=mid;
        else left=mid;
    }
    return right;
}
int main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        maxn+=a[i];
    }
    cout<<solve()<<endl;
    return 0;
}


Measured memory_bytes: 3888
#include <ext/rope>
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
typedef vector<vector<ll>> mat;

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

    int n;
    cin >> n;
    int cnt[100005] = {};
    int x;
    for(int i = 0 ; i < n ; i++)
        cin >> x ,cnt[x]++;
    int out = 0;
    for(int i = 1; i < 100005 ; i++) cnt[i] += cnt[i - 1];
    for(int i = 0 ; i <= 100000 ; i++)
        if(cnt[i] == n - cnt[i]) out++;
    cout << out;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int, int>
#define ld long double
const int mod = 1e9 + 7;
 
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};



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


    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22)
    {
      cout<<"bust\n";
    }
    else
    {
      cout<<"win\n"; 
    }
    
}


Measured memory_bytes: 256
N = input()
dic = {
    '0': 'pon',
    '1': 'pon',
    '2': 'hon',
    '3': 'bon',
    '4': 'hon',
    '5': 'hon',
    '6': 'pon',
    '7': 'hon',
    '8': 'pon',
    '9': 'hon',
}

print(dic[N[-1]])


Measured memory_bytes: 8960
s = input()

wa = False

if s[0] != 'A':
  wa = True
if s[2:-1].count('C') != 1:
  wa = True

l_s = list(s)
  
if 'A' in l_s:
	del l_s[l_s.index('A')]

if 'C' in l_s:
	del l_s[l_s.index('C')]

for c in l_s:
  if c != c.lower():
    wa = True
    
if wa == True:
  print('WA')
else:
  print('AC')

Measured memory_bytes: 9032
#include <bits/stdc++.h>
#define N 4050
#define c 2010
#define mod 1000000007
using namespace std;
typedef long long LL;
int n,a[50*N],b[50*N],F[N][N],jc[5*N];
inline int rd() {
	int x=0,f=1;char ch=getchar();
	while (ch>'9'||ch<'0') {if(ch=='-')f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return x*f;
}

inline void inc(int &x,int y) {x=(x+y)%mod;}

inline int qp(int a,int b) {
	int ret = 1;
	while (b) {
		if (b&1) ret = 1LL * ret * a % mod;
		b >>= 1, a = 1LL * a * a % mod;
	}
	return ret;
}

inline int C(int a,int b) {
	return 1LL * jc[a] * qp(jc[b], mod-2) % mod * qp(jc[a-b], mod-2) % mod;
}

int main() {
	n = rd();
	for (int _=1;_<=n;_++) a[_] = rd(), b[_] = rd();
	
	for (int _=1;_<=n;_++) F[c-a[_]][c-b[_]]++;
	for (int x=c-2000;x<=c+2000;x++)
		for (int y=c-2000;y<=c+2000;y++)
			inc(F[x][y], F[x-1][y]), inc(F[x][y], F[x][y-1]);

	jc[0] = 1;
	for (int i=1;i<=8000;i++) jc[i] = 1LL * jc[i-1] * i % mod;
			
	int ans = 0;
	for (int _=1;_<=n;_++) inc(ans, F[ c+a[_] ][ c+b[_] ]);
	for (int _=1;_<=n;_++) inc(ans, mod - C(2*a[_]+2*b[_], 2*a[_]) );
	ans = 1LL * ans * qp(2, mod-2) % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 65792
#include<stdio.h>

int main(){
  int n,i,j,c;
  int flag=1,a=0;
  int A[100];
  
 scanf("%d",&n);

for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  

  
  while(flag){
    flag = 0;
    for(j=n-1;j>0;j--){
      if(A[j]<A[j-1]){
	c = A[j];
	A[j] = A[j-1];
	A[j-1] = c;
	flag = 1;
	a++;
      }
    }
  }

  for(i=0;i<n;i++){
    if(i!=0)printf(" ");
    printf("%d",A[i]);
  }

  printf("\n%d\n",a);
  
  return 0;
}



Measured memory_bytes: 2128
def main():
    n = int(input())
    a = list(map(int, input().split()))
    if 0 in a:
        print(0)
        return
    prod = 1
    for i in a:
        prod *= i
        if prod > 1000000000000000000:
            print(-1)
            return
    print(prod)
main()

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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define ll long long
#define ll long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  


int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    string a,b;
    cin >> a >> b;
    bool check = true;
  	int n = a.length(), m = b.length();
  	if(m != n+1)
  	{
  		cout << "No\n";
  	}
  	else
  	{
  		for(int i=0;i<n;i++)
  		{
  			if(a[i] != b[i]) 
  			{
  				cout << "No\n";
  				return 0;
  			}
  		}
  		cout << "Yes\n";
  	}
    return 0;
}



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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return abs(x-y)/gcd(x,y); }


int main() {
  int h,w; cin >> h >> w;
  char a[h][w]; for(int i=0;i<h;i++) { for(int j=0;j<w;j++) { cin >> a[i][j]; } }

  int cnt=0;
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      if(a[i][j] == '#') { cnt++; }
    }
  }

  if(cnt == h+w-1) { cout << "Possible\n"; }
  else { cout << "Impossible\n"; }
  return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

#[allow(unused_macros)]
macro_rules! trace {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    };
    ($($args:expr),*) => { trace!(($($args),*)) }
}

#[allow(unused_macros)]
macro_rules! put {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stdout(), "{}", $var);
    };
    ($var:expr, $($args:expr),*) => {
        let _ = write!(&mut std::io::stdout(), "{} ", $var);
        put!($($args),*);
    };
}

const M: i64 = 1_000_000_007;

fn sadness(xs:&Vec<i64>, z:i64) -> i64 {
    let n = xs.len();
    let mut sum = 0;
    for i in 0..n {
        let idx = (i + 1) as i64;
        sum += (xs[i] - z - idx).abs();
    }
    sum
}

fn main() {
    let mut sc = Scanner::new();

    let n: usize = sc.cin();
    let xs = (0..n).map(|_| sc.cin::<i64>()).collect::<Vec<_>>();

    let mut left = -M;
    let mut right = M;
    for _ in 0..1000 {
        let m1 = (left + left + right) / 3;
        let m2 = (left + right + right) / 3;
        // trace!(left, right);
        // trace!((m1, sadness(&xs, m1)));
        // trace!((m2, sadness(&xs, m2)));
        if sadness(&xs, m1) < sadness(&xs, m2) {
            right = m2;
        } else {
            left = m1;
        }
    }

    let mut ans = sadness(&xs, left);
    for i in left..(left+10) {
        ans = min(ans, sadness(&xs, i));
    }
    put!(ans);

}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
}


Measured memory_bytes: 18056
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;

const ll MOD = 1e9 + 7;

ll pow_fast(ll n, ll k) {
  if (k == 0) {
    return 1LL;
  }
  if (k == 1) {
    return n;
  }

  if (k % 2 == 0) {
    ll tmp = pow_fast(n, k / 2);
    return tmp * tmp % MOD;
  } else {
    ll tmp = pow_fast(n, (k - 1) / 2);
    tmp *= tmp;
    tmp %= MOD;
    return tmp * n % MOD;
  }
}

template <typename T>
class stack {
 private:
  vector<T> _vec;

 public:
  stack(){};

  void push(T n) {
    _vec.push_back(n);
    return;
  }

  void pop() {
    if (this->empty()) {
      return;
    }
    _vec.erase(_vec.end() - 1);
    _vec.shrink_to_fit();
    return;
  }

  size_t size() { return _vec.size(); }

  T top() { return _vec[this->size() - 1]; }
  bool empty() { return _vec.empty(); }
};

bool isOk(string s) {
  if (s.size() % 2 == 1){ 
    return false;
  }
  string pre = s.substr(0, s.size() / 2);
  string suf = s.substr(s.size() / 2, s.size() / 2);
  return pre == suf;
}
int main() {
  string s;
  cin >> s;

  ll ans = 1;
  while (true)
  {
    s.pop_back();
    if (isOk(s)) {
      cout << s.size() << endl;
      return 0;
    }
    ans += 1;
  }
  
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int A,B,C;
cin >> A >> B >> C;
string ans = "No";
if(A<=C&&C<=B) ans = "Yes";
cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
    int N;
    cin >> N;
    vector<int> ds(N);
    for (auto&d : ds) cin >> d;
    uint64_t s = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            s += ds[i] * ds[j];
        }
    }
    cout << s << endl;
    return 0;
}


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

import static java.lang.System.in;

public class Main {
    ArrayList<Integer>[] graph;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        long ans = a[0]-1;
        int max = 1;
        for(int i=1;i<n;i++){
            if(a[i]<=max+1) max=Math.max(max,a[i]);
            else{
                ans += (a[i]-1)/(max+1);
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 50544
import java.util.Scanner

import scala.collection.mutable


object Main {

  case class ResidueRing(private val input: Long) {
    val representative: Long = ((input % ResidueRing.mod) + ResidueRing.mod) % ResidueRing.mod

    def +(that: ResidueRing): ResidueRing = ResidueRing(this.representative + that.representative)

    def -(that: ResidueRing): ResidueRing = ResidueRing(this.representative - that.representative)

    def *(that: ResidueRing): ResidueRing = ResidueRing(this.representative * that.representative)

    def unary_- : ResidueRing = ResidueRing(-this.representative)

  }

  object ResidueRing {
    val mod: Long = (1e9 + 7).toLong
    val _0: ResidueRing = ResidueRing(0)
    val _1: ResidueRing = ResidueRing(1)
  }


  def read() = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    n
  }


  def solve(n: Int): Long = {
    // 過去3文字分記憶しておけばいい
    val alphabets = "ATGC"
    val stateList: IndexedSeq[String] =
      for (c1 <- alphabets;
           c2 <- alphabets;
           c3 <- alphabets) yield IndexedSeq(c1, c2, c3).mkString


    def transition(state: String, alphabet: Char): Option[String] = {
      (state(0), state(1), state(2), alphabet) match {
        case (_, 'A', 'G', 'C')
             | (_, 'G', 'A', 'C')
             | (_, 'A', 'C', 'G')
             | ('A', _, 'G', 'C')
             | ('A', 'G', _, 'C') => None
        case _ => Some(IndexedSeq(state(1), state(2), alphabet).mkString)
      }
    }

    val mapAll0: mutable.Map[String, ResidueRing] = mutable.Map.empty
    for (state <- stateList) {
      mapAll0.+=((state, ResidueRing._0))
    }
    val dp: Array[mutable.Map[String, ResidueRing]] = Array.fill(n + 1)(mapAll0.clone)

    dp(0)("TTT") += ResidueRing._1
    for (i <- 0 until n) {
      for (state <- stateList) {
        for (alphabet <- alphabets) {
          val next = transition(state, alphabet)
          next match {
            case Some(nextState) => dp(i + 1)(nextState) += dp(i)(state)
            case None =>
          }

        }
      }
    }
    val result = dp.last.values.foldLeft(ResidueRing._0)(_ + _)
    result.representative
  }


  def main(args: Array[String]): Unit = {
    val n = read()
    println(solve(n))
  }
}

Measured memory_bytes: 41016
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,n;
  while(cin>>m,m){
    cin >> n;
    int d[300]={};
    int i;
    int p,b;
    fill(d,d+300,0);
    for(i=1;i<=n;i++) cin >> d[i];
    int used[300];
    bool r[300]={};
    bool g[300]={};
    queue<int> q1,q2;
    q1.push(0);
    bool c=true;
    while(!q1.empty()){
      b=q1.front();q1.pop();
      if(r[b]) continue;
      r[b]=true;
      q2.push(b);
      //cout << b << endl;
      fill(used,used+300,false);
      while(!q2.empty()){
	p=q2.front();q2.pop();
	//cout << p << endl;
	if(p<0) p=0;
	if(p>n+1) p=n+1;
	if(used[p]) continue;
	used[p]=true;
	q1.push(p);
	for(i=1;i<=m;i++){
	  //cout <<p<<":"<< i <<":"<<p+i+d[p+i]<< endl;
	  q2.push(p+i+d[p+i]);
	}
      }
      if(!used[n+1]){
	c=false;
	break;
      }
    }
    if(c) cout << "OK" << endl;
    else cout << "NG" << endl;
  }
  return 0;
}

Measured memory_bytes: 1292
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn main() {
    let n: u64 = input();
    println!("{}", (n / 2) * ((n + 1) / 2));
}


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

int main() {
    int k, s;
    cin >> k >> s;

    int ans = 0;
    for (int x = 0; x <= k; x++) {
        if (x > s) break;

        for (int y = 0; y <= k; y++) {
            if (x + y > s) break;

            int z = s - x - y;
            if (z <= k) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import Data.Array.IO
import Control.Applicative
import Data.List
import Control.Monad

getNum = read <$> getLine :: IO Int

main = do
    n <- getNum
    putStrLn.format.take n $ filter ((==1).flip mod 5) $ eratosthenes 55555

format [] = []
format (x:xs) = show x ++ " " ++ format xs

eratosthenes :: Integer -> [Integer]
eratosthenes n =
    let primes = [2..n]
        recursion ms = 
          case ms of
            [] -> []
            (m:_) -> m : recursion [x | x <- ms, x `mod` m /= 0]
    in  recursion primes

Measured memory_bytes: 1020
import java.util.Arrays;
import java.util.Scanner;

/**
 * Silk Road
 * JOI 14th, Pre 4
 */
public class Main {

	static final int INF = Integer.MAX_VALUE;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line;
		String[] words;

		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] D = new int[N + 1];
		int[] C = new int[M + 1];
		int[][] DC = new int[D.length][C.length];

		for (int i = 1; i <= N; i++) {
			D[i] = sc.nextInt();
		}
		for (int i = 1; i <= M; i++) {
			C[i] = sc.nextInt();
		}
		for (int i = 0; i < D.length; i++) {
			for (int j = 0; j < C.length; j++) {
				DC[i][j] = D[i] * C[j];
			}
		}

		//
		int[][] dp = new int[N + 1][M + 1];

		for (int i = 1; i < dp.length; i++) {
			Arrays.fill(dp[i], INF);
		}

		for (int i = 1; i <= N; i++) {
			for (int j = i; j <= M; j++) {
				dp[i][j] = Math.min(dp[i][j - 1], dp[i - 1][j - 1] + DC[i][j]);
			}
		}
		System.out.println(dp[N][M]);
	}
}

Measured memory_bytes: 40640
#include<cstdio>
#include<cstdlib>
#include<ctime>
int last[500];
long long s[500][30];
long long c[30];
int tt[500];
int out[500];

long long getD(int d){
    for(int i = 1; i <= 26; i++) last[i] = 0;
    long long cur = 0;
    for(int i = 1; i <= d; i++){
        int t = tt[i];
        cur += s[i][t];
        last[t] = i;
        for(int j = 1; j <= 26; j++) cur -= c[j]*(i-last[j]);
    }
    return  cur;
}

int main(){
    srand(time(NULL));
    int d;
    scanf("%d",&d);
    for(int i = 1; i <= 26; i++) scanf("%lld",&c[i]);
    for(int i = 1; i <= d; i++){
        for(int j = 1; j <= 26; j++) scanf("%lld",&s[i][j]);
    }
    long long ans = 0;
    for(int i = 0; i < 100000; i++){
        for(int j = 1; j <= d; j++) tt[j] = rand()%26+1;
        long long res = getD(d);
        if(res>ans || i==0){
            ans = res;
            for(int j = 1; j <= d; j++) out[j] = tt[j];
        }
    }
    for(int i = 1; i <= d; i++) printf("%d\n",out[i]);
    return 0;
}


Measured memory_bytes: 1824
import std.stdio, std.string, std.conv;

void main() {
    auto input = getStdin!(string[])[0];
    auto num = input.split(" ").to!(int[]);
    int a = num[0];
    int b = num[1];
    real f = a.to!(real) / b.to!(real);
    writefln("%d %d %.5f", a / b, a % b, f);
}

T getStdin(T)() {
    string[] cmd;
    string line;
    while ((line = chomp(stdin.readln())) != "") cmd ~= line;
    return to!(T)(cmd);
}

Measured memory_bytes: 2524
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
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 nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int n;
    cin >> n;

    vector<int> primes;
    for(int i = 2; i <= 55555; i++){
        bool f = true;
        for(int j = 2; j * j <= i; j++){
            if(i % j == 0){
                f = false;
                break;
            }
        }
        if(f) primes.push_back(i);
    }
    int cnt = 0;
    for(int i = 0; i < primes.size(); i++){
        if(i >= 10 && primes[i] % 5 == 1){
            cout << primes[i] << endl;
            cnt++;
        }
        if(cnt >= n){
            return 0;
        }
    }
}

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

int main() {
  ll n;
  cin >> n;
  --n;
  ll ans = (n+1) * n / 2;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3648
using System;

namespace object1
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            if (a < 3200)
            {
                Console.WriteLine("red");
            }
            else
            {
                Console.WriteLine(s);
            }
        }
    }
}



Measured memory_bytes: 11092
import sys
from itertools import combinations

input = sys.stdin.readline


def main():
    N = int(input())
    S = [""] * N
    for i in range(N):
        S[i] = input().rstrip()

    count = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
    for s in S:
        if s[0] in "MARCH":
            count[s[0]] += 1

    ans = 0
    for c1, c2, c3 in combinations("MARCH", 3):
        ans += count[c1] * count[c2] * count[c3]

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 15800