akhauriyash/Code-Regression huggingface dataset:
import itertools
N, M , Q = map(int,input().split())
suuji = [i for i in range(1,M+1)]
L = []
for i in range(Q):
  temp = list(map(int,input().split()))
  L.append(temp)

#print(suuji)

Aall = list(itertools.combinations_with_replacement(suuji, N))
#print(Aall)

ans = 0
for A in Aall:
  test = 0
  for i in range(Q): #Q組のセットで確認 L[i]という数列が四つの数の組
    #print(L[i])
    #print(A)
    if A[L[i][1]-1]-A[L[i][0]-1] == L[i][2]:
      test += L[i][3]
  ans = max(ans,test)
print(ans)

Measured memory_bytes: 21544
import scala.io.StdIn.{readInt,readLine}

object Main {
  val codes = {for(i<-'A' to 'Z') yield i->("00000"+(i-65).toBinaryString).takeRight(5)}
          .toMap ++ Map(' '->"11010",'.'->"11011",','->"11100",'-'->"11101",'\''->"11110",'?'->"11111")

  val str = Map("101"->' ',"000000"->'\'', "000011"->',',
    "10010001"->'-',"010001"->'.',"000001"->'?',
    "100101"->'A',"10011010"->'B',"0101"->'C',"0001"->'D',
    "110"->'E',"01001"->'F',"10011011"->'G',"010000"->'H',
    "0111"->'I',"10011000"->'J',"0110"->'K',"00100"->'L',
    "10011001"->'M',"10011110"->'N',"00101"->'O',"111"->'P',
    "10011111"->'Q',"1000"->'R',"00110"->'S',"00111"->'T',
    "10011100"->'U',"10011101"->'V',"000010"->'W',"10010010"->'X',
    "10010011"->'Y',"10010000"->'Z')

  def scan(s:String,r:String):String = {
    def loop(i:Int):(String,String) = {
      if(i==9) (s,"")
      else{
        val s2 = s.take(i)
        if(str.contains(s2)) (s.drop(i),str(s2).toString)
        else loop(i+1)
      }
    }
    val x=loop(3)
    if(x._2!="") scan(x._1,r+x._2)
    else r
  }

  def main(args:Array[String]) = {
    Iterator.continually(readLine).takeWhile(_!=null).foreach { line=>
      val s = line.map(codes(_)).mkString
      println(scan(s,""))
    }
  }
}

Measured memory_bytes: 61036
#include<iostream>
using namespace std;
int main(){
	int a,b;
	char op;
	
	while(1){
		cin>>a>>op>>b;	

		if(op=='+')
			cout<<a+b<<"\n";
		else if(op=='-')
			cout<<a-b<<"\n";
		else if(op=='*')
			cout<<a*b<<"\n";
		else if(op=='/')
			cout<<a/b<<"\n";
		else if(op=='?')
			break;
	}
}
		

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  int x = A;
  int count = 0;
  while(x <= B){
    int man = x/10000;
    int sen = (x - man*10000)/1000;
    int juu = (x%100)/10;
    int ichi = x%100-juu*10;
    if(man == ichi && sen ==juu){
      count++;
    }
    x++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		String cur=scan.next();
		int k=scan.nextInt();
		TreeSet<String> set=new TreeSet<String>();
		for(int i=0;i<cur.length();i++)
		{
			for(int j=1;j<=5;j++)
			{
				if((i+j)>cur.length())break;
				set.add(cur.substring(i,i+j));
			}
		}
		int indx=1;
		for(String ad:set)
		{
			if(k==indx)
			{
				System.out.println(ad);
				break;
			}
			indx++;
		}
	}
}


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

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>
 
using namespace std;

const int N=100010;

int n,x,y;
int dsu[N];
struct edge {
	int a,b,val;
	bool operator<(const edge& rhs) const {
		return val<rhs.val;
	}
}; 
vector<edge> vec;
vector<PII> v1,v2;

int fi(int x) {
	return dsu[x]==x?x:(dsu[x]=fi(dsu[x]));
}

int main() {
	scanf("%d",&n);
	for (int i=0;i<n;i++) {
		scanf("%d%d",&x,&y);
		v1.pb(mp(x,i+1));v2.pb(mp(y,i+1));
	}
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());
	for (int i=1;i<n;i++) {
		vec.pb({v1[i].second,v1[i-1].second,v1[i].first-v1[i-1].first});
		vec.pb({v2[i].second,v2[i-1].second,v2[i].first-v2[i-1].first});
	}
	for (int i=1;i<=n;i++) dsu[i]=i;
	sort(vec.begin(),vec.end());
	ll ans=0;
	for (auto& e:vec) {
		int r1=fi(e.a);
		int r2=fi(e.b);
		if (r1!=r2) {
			ans+=e.val;
			dsu[r1]=r2;
		}
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 7144
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * 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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String S = in.next();
            int b1 = 0, b2 = 0, len = S.length();
            for (int i = 0; i < len; i++) {
                if (i % 2 == 0) {
                    if (S.charAt(i) == '0') {
                        b2++;
                    } else {
                        b1++;
                    }
                }
                if (i % 2 == 1) {
                    if (S.charAt(i) == '0') {
                        b1++;
                    } else {
                        b2++;
                    }
                }
            }
            out.println(Math.min(b1, b2));
        }

    }
}



Measured memory_bytes: 25728
df (a:[]) = []
df (a:b:s) = (b-a):(df (b:s))

ans [] = []
ans (_:d:r) =
  let a = df d
      mx= maximum a
      mn= minimum a
      mx'= if mx < 0 then 0 else  mx
      mn'= if mn > 0 then 0 else -mn
  in
    [mx',mn']:(ans r)
  
main = do
  _ <- getLine
  c <- getContents
  let i = map (map read) $ map words $ lines c :: [[Int]]
      o = ans i
  mapM_ putStrLn $ map unwords $ map (map show) o



Measured memory_bytes: 5380
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

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

    ll black = 0, ans = 0;
    for (auto &c : S) {
        if (c == 'W') {
            ans += black;
        } else {
            black++;
        }
    }

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


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

int main(){
    string o, e;
    int onum = 0, enu = 0;
    cin >> o >> e;
    for (int i = 0; i < o.size() + e.size(); i++) {
        if (i % 2 == 0){
            cout << o[onum];
            onum++;
        } else{
            cout << e[enu];
            enu++;
        }
    }

    cout << endl;

}


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

#define reg register
#define pr std::pair<int, int>
#define fi first
#define se second
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
#define Rep(i, n) rep(i, 1, n)
#define Lep(i, n) lep(i, 1, n)
#define IRep(i, n) irep(i, n, 1)
#define ILep(i, n) ilep(i, n, 1)
typedef long long ll;
typedef long double ld;

namespace modular {
    const int MOD = 1000000007;
    inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
    inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
    inline int mul(int x, int y) { return 1LL * x * y % MOD; }
    inline int qpow(int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x))
            if (y & 1) ans = mul(ans, x);
        return ans;
    }
};  // namespace modular

namespace Base {
    template <typename Tp>
    inline Tp input() {
        Tp x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return 0;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        return x *= y;
    }
    template <typename Tp>
    inline void read(Tp &x) {
        x = input<Tp>();
    }
    template <typename Tp>
    inline void chmax(Tp &x, Tp y) {
        x < y ? x = y : 0;
    }
    template <typename Tp>
    inline void chmin(Tp &x, Tp y) {
        x > y ? x = y : 0;
    }
};  // namespace Base
using namespace Base;
/*----------------------------------------------------------------------------*/

#define MAX_N 200007

int N, M;
int head[MAX_N], to[MAX_N << 1], nxt[MAX_N << 1], cap = 1;
int d[MAX_N];
bool vis[MAX_N];

void addE(int u, int v) {
    nxt[++cap] = head[u];
    head[u] = cap;
    to[cap] = v;
}

bool dfs(int x, int s, int t, int las = 0) {
    vis[x] = true;
    for (int i = head[x]; i; i = nxt[i])
        if (to[i] != t && to[i] != las) {
            if (to[i] == s) return true;
            if (!vis[to[i]] && dfs(to[i], s, t, x)) return true;
        }
    return false;
}

bool check() {
    int u = 0, v;
    Rep(i, N) if (d[i] == 4) !u ? u = i : v = i;
    return dfs(u, u, v);
}

void answ(int x) {
    puts(x ? "Yes" : "No");
    exit(0);
}

int main() {
#ifdef LOCAL
    FIN("in");
#endif
    read(N), read(M);
    int u, v;
    Rep(i, M) {
        read(u), read(v);
        addE(u, v), addE(v, u);
        d[u]++, d[v]++;
    }
    Rep(i, N) if (d[i] & 1) answ(0);
    Rep(i, N) if (d[i] > 4) answ(1);
    int cnt = 0;
    Rep(i, N) if (d[i] == 4) cnt++;
    if (cnt > 2 || (cnt == 2 && check())) answ(1);
    answ(0);
    return 0;
}


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

int main(){
  int n,k,tmp;
  int s[100];
  bool f;

  while(1){
    cin >> n >> k;
    if(!n && !k)break;

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

    f = true;
    for(int i=0;i<n;i++){
      for(int j=0;j<k;j++){
	cin >> tmp;
	if(f)s[j] -= tmp;
	if(s[j] < 0)f = false;
      }
    }

    if(f)cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <cassert>
#include <functional>
#include <numeric>
#include <chrono>
#include <random>
#include <optional>

using namespace std;
typedef long long ll;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  map<ll, ll> odd, even;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (i & 1) odd[a]++;
    else even[a]++;
  }

  vector<pair<ll, ll>> impar;
  for (auto p: odd) {
    ll tot = n / 2;
    ll dif = tot - p.second;
    impar.push_back({dif, p.first});
  }

  vector<pair<ll, ll>> par;
  for (auto p: even) {
    ll tot = n / 2;
    ll dif = tot - p.second;
    par.push_back({dif, p.first});
  }

  sort(impar.begin(), impar.end());
  sort(par.begin(), par.end());
  ll res = 1e9;
  for (int i = 0; i < min(2, (int)impar.size()); i++) {
    for (int j = 0; j < min(2, (int)par.size()); j++) {
      ll val = impar[i].first + par[j].first;
      if (impar[i].second == par[j].second) {
        val = min(impar[i].first, par[j].first) + n/2;
      }
      res = min(res, val);
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 11680
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AHappyBirthday solver = new AHappyBirthday();
        solver.solve(1, in, out);
        out.close();
    }

    static class AHappyBirthday {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            out.println(in.nextInt() > 8 || in.nextInt() > 8 ? ":(" : "Yay!");
        }

    }
}



Measured memory_bytes: 21972
import sys
sys.setrecursionlimit(10000)

L = input()
n = 1
p = (1, 0)  # 3 ** 0 = 1
mod = 10 ** 9 + 7

for i in range(len(L)):
    if L[len(L) - 1 - i] == '1':
        k = (p[0] * (3 ** (i - p[1]))) % mod
        n = n * 2 + k
        n %= mod
        p = (k, i)

print(n)


Measured memory_bytes: 3188
import sys
input = sys.stdin.readline
 
import numpy as np
 
def main():
  n, W = map(int, input().split())
  dp = np.zeros(W+1, dtype=np.int64)
  for _ in range(n):
    w, v = map(int, input().split())
    # w, vを使うかどうかで更新する
    dp[w:W+1] = np.maximum(dp[:W-w+1]+v, dp[w:W+1])
  print(dp[W])

if __name__ == "__main__":
  main()

Measured memory_bytes: 21892
import Control.Applicative ((<$>))
import Control.Monad (unless)

main :: IO ()
main = do
  n <- readLn
  unless (n == 0) $ do
    solve <$> map read <$> words <$> getLine >>= print
    main

solve :: [Int] -> Int
solve = f 0 0
  where f a b [] = abs (a - b)
        f a b (x:xs) = min (f (a+x) b xs) (f a (b+x) xs)



Measured memory_bytes: 4372
#include <iostream>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    int sum = a + b;
    if (sum % 2 != 0) {
        cout << "IMPOSSIBLE" << endl;
    } else {
        cout << sum / 2 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>

int main(){
    int N, M;
    std::cin >> N >> M;
    int Ncount = (N * (N - 1)) / 2;
    int Mcount = (M * (M - 1)) / 2;
    std::cout << Ncount + Mcount << std::endl;
    return 0;
}


Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'

ld d(ld x, ld y, ld a, ld b){
  return sqrt(pow(x - a, 2) + pow(y - b, 2));
}

void solve(){
  ll n;
  cin >> n;
  cout << n * (n + 1) / 2 - n;
}

int main() {
  ios::sync_with_stdio(false);
  // cin.tie(0); cout.tie(0);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 

k (k-1) (k-1)

2 6 3
4 6 5
6 6 7
7 7 7

*/

Measured memory_bytes: 3624
#include<bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
 
ll fast_pow( ll a , ll b , ll m )
{
 
    ll res=1;
    while(b>0)
    {
        if(b&1) res =  (res*a)%m;
        a=(a*a)%m;
        b=b/2;
    }
    return res;
}
 
template <typename T,typename U>                                                   
std::pair<T,U> operator-(const std::pair<T,U> & l,const std::pair<T,U> & r) {   
    return {l.first-r.first,l.second-r.second};                                    
} 
 
template <typename T,typename U>                                                   
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {   
    return {l.first+r.first,l.second+r.second};                                    
} 
 
const ll maxn = 1000000;
const int inf = 0x3f3f3f;
const ll MOD = 1e9+7LL;
int ns;

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

/*
    java implementation of highestOneBit and NumberOfTrailingZeroes
*/

ll highestOnebit(ll x)
{
    x |= (x>>1);
    x |= (x>>2);
    x |= (x>>4);
    x |= (x>>8);
    x |= (x>>16);
    x |= (x>>32);
    
    return x-((unsigned ll)x>>1);
}   

int numberOfTrailingZeros(ll i)
{
    if (i == 0) return 64;
    ll x = i;
    ll y;
    int n = 63;
    y = x << 32; if (y != 0) { n -= 32; x = y; }
    y = x << 16; if (y != 0) { n -= 16; x = y; }
    y = x <<  8; if (y != 0) { n -=  8; x = y; }
    y = x <<  4; if (y != 0) { n -=  4; x = y; }
    y = x <<  2; if (y != 0) { n -=  2; x = y; }
    return (int) (n - ((unsigned ll)(x << 1) >> 63));
}


vector<int> parent;
vector<int> depth;
vector<vector<int>> adj;
vector<bool> vis;
vector<int> tin;
vector<int> tout;
int T = 0;

void dfs(int u , int d)
{
    tin[u] = T++;
    depth[u]=d;
    vis[u]=true;
    for(auto v : adj[u])
    {
        if(!vis[v])
        {
            dfs(v , d+1);
            parent[v]=u;
        }
    }    
    tout[u]=T++;
}


int main()
{
    // freopen( "input.txt" , "w" , stdout );
    
    
 
    srand(time(0));
    // Using time point and system_clock 
    std::chrono::time_point<std::chrono::system_clock> start, end; 
  
    start = std::chrono::system_clock::now(); 
 
 
    //------- INPUT GENERATION ------
 
    // cout<<200000<<endl;
 
    //------- /INPUT GENERATION ------

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n ,k;
    cin>>k>>n;
    vector<int> houses(n);
    for(int i=-0;i<n;i++)
    {
        cin>>houses[i];
    }

    int maxdis=0;

    for(int i=0;i<n;i++)
    {
        maxdis = max( maxdis , ( ( houses[(i+1)%n] - houses[i] )%k + k )%k );
    }
    // cout<<"maxdis = "<<maxdis<<endl;
    cout<<k-maxdis<<endl;


    

   
    // cout<<endl;
    // end = std::chrono::system_clock::now(); 
  
    // std::chrono::duration<double> elapsed_seconds = end - start; 
    // std::time_t end_time = std::chrono::system_clock::to_time_t(end); 
  
    // std::cout << "finished computation at " << std::ctime(&end_time) 
    //           << "elapsed time: " << elapsed_seconds.count() << "s\n"; 
 
 
 
 
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node
{
	ll v;
	int x;
}arr[100010];

bool cmp(node a,node b)
{ 
	if(a.v==b.v)
	return a.x<b.x;
	else 
	return a.v>b.v;
}

int idx[100010];
ll num[100010];
ll flag[100010];
ll val[100010];
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		//memset(idx,-1,sizeof idx);
		memset(num,0,sizeof num);
		memset(flag,0,sizeof flag);
		//memset(val,0,sizeof val);
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&arr[i].v);
			arr[i].x=i;
		}
		sort(arr+1,arr+1+n,cmp);
		//for(int )
		arr[0].v=-1;
		int cnt=0;
		//idx[cnt] = arr[1].x;
		for(int i=1;i<=n;i++)
		{
			if(arr[i-1].v!=arr[i].v)
			{
				cnt++;
				idx[cnt]=arr[i].x;
				num[cnt]=1ll;
				val[cnt]=arr[i].v;
			}
			else 
			num[cnt]++;
		}
		for(int i=1;i<cnt;i++)
		{
			flag[idx[i]]+=1ll*num[i]*(val[i]-val[i+1]);
			idx[i+1]=min(idx[i],idx[i+1]);
			num[i+1]+=num[i];
		}
		flag[idx[cnt]]+=1ll*num[cnt]*val[cnt];
		for(int i=1;i<=n;i++)
		printf("%lld\n",flag[i]);
	}
	return 0;
}

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

#define POS(i,j) (((i)&1)*(k+2)+((j)<0?(0):(j)+1))

void run(void){
  int n,k;
  scanf("%d%d",&n,&k);
  const int mod=1000000007;
  int *dp=(int *)calloc(2*(k+2),sizeof(int));
  dp[POS(0,0)]=1;
  for(int i=1;i<=n;i++){
    int a;
    scanf("%d",&a);
    for(int j=0;j<=k;j++){
      dp[POS(i,j)]=(dp[POS(i,j-1)]+dp[POS(i-1,j)]-dp[POS(i-1,j-a-1)])%mod;
      if(dp[POS(i,j)]<0) dp[POS(i,j)]+=mod;
    }
  }
  printf("%d\n",dp[POS(n,k)]);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>

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

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

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition){ cout << "Yes" << '\n'; }else{ cout << "No" << '\n'; }
#define YES(condition) if(condition){ cout << "YES" << '\n'; }else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition){ cout << "yes" << '\n'; }else{ cout << "no" << '\n'; }





int main() {
    ll n;
    cin >> n;
    
    vector<ll> cnt(105);
    for(ll i = 2; i <= n; i++){
        ll k = i;
        for(ll j = 2; j <= k; j++){
            while(k % j == 0){
                k /= j;
                cnt[j]++;
            }
        }
    }
    
    ll ans = 0;
    REP(i, 105){
        if(cnt[i] >= 2){
            REP(j, 105){
                if(i == j) continue;
                if(cnt[j] >= 4){
                    for(ll k = j + 1; k < 105; k++){
                        if(i == k || j == k || cnt[k] < 4) continue;
                        ans++;
                    }
                }
                if(cnt[j] >= 24){
                    ans++;
                }
            }
        }
        if(cnt[i] >= 4){
            REP(j, 105){
                if(i == j) continue;
                if(cnt[j] >= 14){
                    ans++;
                }
            }
        }
        if(cnt[i] >= 74){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

class AParking {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int n, a, b;
    cin >> n >> a >> b;

    cout << min(n * a, b) << endl;
}
};

int main() {
	AParking solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  int n;
	cin>>n;
  for (int i=n; i>1; i--) {
    for (int j=2; j<i; j++) {
      int x=j;
      while (x<i) x*=j;
      if (x==i) out(i);
    }
  }
  
  out(1);

  return 0;
}


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

using namespace std;

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if((a+b)>(c+d)){
        cout << "Left" << endl;
    } else if ((a+b)==(c+d)){
        cout << "Balanced" << endl;
    } else {
        cout << "Right" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	string h;
	cin >> h;
	reverse(h.begin(), h.end());
	while (1) {
		if (h.substr(0, 5) == "maerd") h = h.substr(5, h.length() - 5);
		else if (h.substr(0, 5) == "esare") h = h.substr(5, h.length() - 5);
		else if (h.substr(0, 7) == "remaerd") h = h.substr(7, h.length() - 7);
		else if (h.substr(0, 6) == "resare") h = h.substr(6, h.length() - 6);
		else if (h.length() == 0) {
			cout << "YES" << endl;
			break;
		}
		else {
			cout << "NO" << endl;
			break;
		}
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return (rand()<<16|rand())%x;
}
const int N=100005;
int n,m,sum,flag,jb,vis[N],tong[3];
ll ans;
vector<int> f[N],g[N];
void dfs(int p,int color){
	if(vis[p]!=-1){if(vis[p]!=color) flag=1; return;}
	else vis[p]=color;
	tong[color]++; sum++; jb+=f[p].size();
	for(unsigned i=0;i<f[p].size();i++)dfs(f[p][i],(color+1)%3);
	for(unsigned i=0;i<g[p].size();i++)dfs(g[p][i],(color+2)%3);
}
int main(){
	n=read(); m=read();
	memset(vis,-1,sizeof(vis));
	for(int i=1;i<=m;i++){
		int x=read(),y=read();
		f[x].push_back(y); g[y].push_back(x);
	}
	for(int i=1;i<=n;i++)if(vis[i]==-1){
		tong[0]=tong[1]=tong[2]=flag=jb=sum=0; 
		dfs(i,0); if(flag)ans+=(ll)sum*sum; 
		else if(tong[0]&&tong[1]&&tong[2]){for(int i=0;i<3;i++)ans+=(ll)tong[i]*tong[(i+1)%3];}
		else ans+=jb;
		//cout<<tong[0]<<" "<<tong[1]<<" "<<tong[2]<<" "<<flag<<" "<<jb<<endl;
	}
	cout<<ans<<endl;
}

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

#define PI acos(-1.0)
#define INF 2e9
#define INFLL 9e18
#define EPS 1e-9
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int a[1000000],b[1000000];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(2);
    cout << fixed;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);


    ll t,a,b,c,d,n,m,i,j,x,y,k,mx,mn,res=0,cnt=0;
    cin >> n ;
    string s;
    cin >> s;
    for(i=0;i<n;i++){
        if(s[i]=='W') res++;
    }
    for(i=n-1;i>n-1-res;i--) if(s[i]=='W') cnt++;
    cout << res-cnt << endl;
    return 0;
}



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

int factorial(int n){
    int ans = 1;
    rep(i, 0, n) ans *= i+1;
    return ans;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n) a[i] = i;
    vector<double> x(n), y(n);
    rep(i, 0, n) cin >> x[i] >> y[i];
    double dist = 0;
    do{
        rep(i, 0, n-1){
            dist += pow(pow(x[a[i]] - x[a[i+1]], 2) + pow(y[a[i]] - y[a[i+1]], 2), 0.5);
        }
    }while(next_permutation(a.begin(), a.end()));
    printf("%.10f\n", dist/factorial(n));
    return 0;
}


Measured memory_bytes: 4204
#include <bits/stdc++.h>
using namespace std;
int dp[10003];
int main(){
	int h,n;cin>>h>>n;
	for (int j=0;j<10003;j++) dp[j]=1e9;
	dp[0]=0;
	for (int i=1;i<=n;i++){
		int a,b;cin>>a>>b;
		for (int j=0;j<=h;j++)
			dp[min(h,j+a)]=min(dp[min(h,j+a)],dp[j]+b);
	}
	cout<<dp[h];
}

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

using namespace std;

#define A_MAX 10000

void countingSort(const vector<int> &a, vector<int> &b, const int k)
{
    vector<int> c(k + 1);
    for (int i = 0; i <= k; i++)
    {
        c[i] = 0;
    }

    int n = a.size();
    for (int j = 0; j < n; j++)
        c[a[j]]++;

    for (int i = 1; i <= k; i++)
        c[i] += c[i - 1];

    for (int j = n - 1; j >= 0; j--)
    {
        b[c[a[j]] - 1] = a[j];
        c[a[j]]--;
    }
}

int main()
{
    int n;
    scanf("%d", &n);
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }

    countingSort(a, b, A_MAX);
    for (int i = 0; i < n; i++)
    {
        printf("%d", b[i]);
        if (i != n - 1)
            printf(" ");
    }
    printf("\n");

    return 0;
}



Measured memory_bytes: 18416
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;

#define LL long long
#define LD long double
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(a,n) memset(a,n,sizeof(a));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

const int N=200005;

int que[N],sum[N];
int main()
{
    int n,k,a,i,ans,ans1,ans2;
    int frnt,tail;
    scanf("%d%d",&n,&k);
    sum[0]=0;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a);
        sum[i]=sum[i-1]+a;
    }
    frnt = 0;tail = 0;
    ans=-1;
    for(i=1;i<=n;i++)
    {
        while(tail>frnt&&sum[i-1]<sum[que[tail-1]])
            tail--;
        que[tail++]=i-1;
        while(tail>frnt&&i-que[frnt]>k)
            frnt++;
        if(ans<sum[i]-sum[que[frnt]])
        {
            ans=sum[i]-sum[que[frnt]];
            ans1=que[frnt]+1;
            ans2=i;
        }
    }
    double sov=(1.0*ans+1.0*k)/2.0;
    printf("%.8f\n",sov);
    return 0;
}
















Measured memory_bytes: 1792
#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 long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

const int MAX=110;
long long COM[MAX][MAX];
// テーブル作成
void COMinit(){
    memset(COM,0,sizeof(COM));
    COM[0][0]=1;
    for(int i=1;i<MAX;i++){
        COM[i][0]=1;
        for(int j=1;j<MAX;j++){
            COM[i][j]=(COM[i-1][j-1]+COM[i-1][j])%MOD;
        }
    }
}
map<int,int> mp;
void prime_factorization(int n){
    int i=2;
    while(n>1){
        if(n%i==0){
            n/=i;
            mp[i]++;
        }else{
            i++;
        }
    }
}
int main(){
    COMinit();
    int n; cin>>n;
    for(int i=2;i<=n;i++) prime_factorization(i);
    // {2,4,14,24,74}
    long long cnt[5]={};
    for(auto i:mp){
        if(i.second>=74) cnt[4]++;
        if(i.second>=24) cnt[3]++;
        if(i.second>=14) cnt[2]++;
        if(i.second>=4) cnt[1]++;
        if(i.second>=2) cnt[0]++;
    }
    long long ans=0;
    // {2,4,4}
    if(cnt[0]>=3&&cnt[1]>=2){
        ans+=COM[cnt[1]][2]*(cnt[0]-2);
    }
    // {4,14}
    if(cnt[1]>=2&&cnt[2]>=1){
        ans+=cnt[2]*(cnt[1]-1);
    }
    // {2,24}
    if(cnt[0]>=2&&cnt[3]>=1){
        ans+=cnt[3]*(cnt[0]-1);
    }
    // {74}
    ans+=cnt[4];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll h,w;
    ll x[]={-1,0,1,-1,1,-1,0,1};
    ll y[]={-1,-1,-1,0,0,1,1,1};
    cin >> h >> w;
    string s[h];
    rep(i,h) cin >> s[i];
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='#') continue;
            ll cnt=0;
            rep(k,8){
                ll xx=j+x[k];
                ll yy=i+y[k];
                if(xx<0 || w<=xx || yy<0 || h<=yy) continue;
                if(s[yy][xx]=='#') cnt++;
            }
            s[i][j]='0'+cnt;
        }
    }
    rep(i,h){
        rep(j,w){
            cout << s[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
package main

import (
  "fmt"
  "math"
)

func main() {
  var N int
  var T, A float64

  // N, T, Aを入力する
  fmt.Scan(&N, &T, &A)

  // Hを入力する
  H := make([]float64, N)
  for i, _ := range H {
    fmt.Scan(&H[i])
  }

  // TODO: Nの数だけ計算する > 結果を格納
  min := float64(10000)
  ans := 0
  for i, h := range H {
    diff := math.Abs(A - (T - h * 0.006))
    if diff < min {
      min = diff
      ans = i
    }
  }
  fmt.Println(ans + 1)
}

Measured memory_bytes: 512
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int V[300000], W[300000];

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


	int N;
	cin >> N;

	int A[1000001] = {};
	rep(i, N) {
		int a;
		cin >> a;
		A[a]++;
	}

	int kotae = 0;
	rep1(i, 1000000) {
		if (A[i]) {
			if (A[i] == 1) kotae++;

			for (int j = i + i; j <= 1000000; j += i) {
				A[j] = 0;
			}

		}
	}
	co(kotae);


	Would you please return 0;
}

Measured memory_bytes: 7556
#include<iostream>
#include<math.h>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<string>
#include<string.h>
#include<map>
#include<vector>
#include<set>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n/10==9||n%10==9)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int[] p = new int[n];
        int[] q = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = std.nextInt();
        }

        for (int i = 0; i < n; i++) {
            q[i] = std.nextInt();
        }

        int[] sortedP = Arrays.copyOf(p, p.length);
        Arrays.sort(sortedP);
        int[] sortedQ = Arrays.copyOf(q, q.length);
        Arrays.sort(sortedQ);

        List<List<Integer>> listP = new ArrayList<>();
        backtrack(listP, new ArrayList<>(), sortedP);

        List<List<Integer>> listQ = new ArrayList<>();
        backtrack(listQ, new ArrayList<>(), sortedQ);

        int indexP = matchedIndex(listP, p);
        int indexQ = matchedIndex(listQ, q);
        int ans = Math.abs(indexP - indexQ);
        System.out.println(ans);
    }

    static int matchedIndex(List<List<Integer>> list, int[] nums) {
        int index = 0;
        for (int i = 0; i < list.size(); i++) {
            List<Integer> elements = list.get(i);
            boolean isMatched = true;
            for (int j = 0; j < elements.size(); j++) {
                int listValue = elements.get(j);
                if (listValue != nums[j]) {
                    isMatched = false;
                    break;
                }
            }

            if (isMatched) {
                index = i;
            }
        }

        return index;
    }

    static void backtrack(List<List<Integer>> out, List<Integer> tmpList, int[] nums) {
        if (tmpList.size() == nums.length) {
            out.add(new ArrayList<>(tmpList));
        } else {
            for (int i = 0; i < nums.length; i++) {
                if (tmpList.contains(nums[i])) {
                    continue;
                }

                tmpList.add(nums[i]);
                backtrack(out, tmpList, nums);
                tmpList.remove(tmpList.size() - 1);
            }
        }
    }
}


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


int main(){
	int array[100]={};
	int N,M;
	int input;
	cin >> N >> M;
	for(int i=0;i<M;i++){
		cin >> input;
		array[input]++;
		cin >> input;
		array[input]++;
	}
	for(int i=1;i<=N;i++){
		cout << array[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()

ans_list = [ 0 for i in range(n)]
ans_list2 = [0 for i in range(n)] 
ans_list3 = ['' for i in range(n)] 

for i in range(len(t)):
    if t[i] == 'r':
        if (t[i-k] != 'r') | (ans_list2[i-k] == 0):
            ans_list[i] = p
            ans_list2[i] = 1
            ans_list3[i] = 'p'
        else:
            ans_list2[i] = 0
            
    elif t[i] == 's':
        if (t[i-k] != 's') | (ans_list2[i-k] == 0):        
            ans_list[i] = r
            ans_list2[i] = 1
            ans_list3[i] = 'r'
        else:
            ans_list2[i] = 0

    else: #t[i] == 'p'
        if (t[i-k] != 'p') | (ans_list2[i-k] == 0):        
            ans_list[i] = s
            ans_list2[i] = 1
            ans_list3[i] = 's'
        else:
            ans_list2[i] = 0

print(sum(ans_list))

Measured memory_bytes: 5748
#include <bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;
template <typename T> using vvec = vector<vector<T>>;

constexpr int64_t mpow(int64_t a, int64_t b, int64_t mod = 1000000007) {
    if (b <= 0) { return 1; } if (b == 1) { return a % mod; } if (b == 2) { return (a * a) % mod; }
    return (max(a * (b & 1), (int64_t)1) * mpow(mpow(a, b / 2, mod), 2, mod)) % mod;
}
constexpr int64_t mdiv(int64_t a, int64_t b, int64_t mod = 1000000007) {
    return (a * mpow(b, mod - 2, mod)) % mod;
}

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

    int64_t cbeg, clen;
    vec<int64_t> sum(2);
    sum[0] = 0; sum[1] = x;

    // 剰余の結果は一意なので、高々mでサイクルを見つけることができる
    {
        vec<int> vis(m, -1); vis[x] = 0;
        for (int64_t i = (x * x) % m, j = x; ; j = i, i = (i * i) % m) {
            if (0 <= vis[i]) {
                cbeg = vis[i];
                clen = vis[j] + 1 - vis[i];
                break;
            }
            vis[i] = vis[j] + 1;
            sum.push_back(sum.back() + i);
        }
    }

    int64_t ans = 0;

    // サイクルの手前まで移動
    ans += sum[min(n, cbeg)];
    n -= min(n, cbeg);
    // サイクルを回る
    ans += (n / clen) * (sum[cbeg + clen] - sum[cbeg]);
    n %= clen;
    // 端数を移動
    ans += sum[cbeg + n] - sum[cbeg];

    cout << ans << endl;
}



Measured memory_bytes: 4204
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int h,n;

int main(){
	cin>>h>>n;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		h-=x;
	}
	cout<<(h<=0?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
int modpow(int x, int k, int MOD) {
  int a = 1;
  while (k) {
    if (k&1) a = (1LL*a*x)%MOD;
    x = (1LL*x*x)%MOD;
    k>>=1;
  }
  return a;
}
const int B = 3213212;
// <= INT_MAX/2
const vector<int> hashes = {
  1000000007,
  1000000009,
};
struct Hash {
  vector<int> data;
  Hash(int x) {
    data.resize(hashes.size(), 0);
    rep(i, hashes.size()) data[i] = ((x%hashes[i])+hashes[i])%hashes[i];
  }
  Hash() : Hash(0) {}
};
Hash operator+(const Hash &a, const Hash &b) {
  Hash ret;
  rep(i, hashes.size()) ret.data[i] = (0LL+a.data[i]+b.data[i]) % hashes[i];
  return ret;
}
Hash operator*(Hash a, Hash b) {
  rep(i, hashes.size()) a.data[i] = (1LL*a.data[i]*b.data[i]) % hashes[i];
  return a;
}
Hash inv(Hash a) {
  Hash ret;
  rep(i, hashes.size()) ret.data[i] = modpow(a.data[i], hashes[i]-2, hashes[i]);
  return ret;
}


int N;
string S;
Hash pB[500001];
Hash memo[250000];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  pB[0] = Hash(1);
  for (int i=1; i<=500000; i++) pB[i] = pB[i-1] * B;

  cin >> N >> S;
  int p = 250000;
  Hash hash(0);
  map<vector<int>, int> mp;
  rep(i, N) {
    if (S[i] == '+') hash = hash + pB[p];
    if (S[i] == '-') hash = hash + pB[p] * Hash(-1);
    if (S[i] == '>') p++;
    if (S[i] == '<') p--;
    memo[i] = hash;
    mp[hash.data]++;
  }

  const Hash ONE = pB[250000];
  Hash invB = inv(B);
  long long sum = 0;

  Hash a(1), b(0); // h -> h*a+b
  rep(l, N) {
    Hash h = hash*a + b;
    sum += mp[h.data];

    if (S[l] == '+') b = b + a*ONE; // all -= ONE
    if (S[l] == '-') b = b + a*(ONE*Hash(-1)); // all += ONE
    if (S[l] == '>') a = a * B; // all /= B
    if (S[l] == '<') a = a * invB; // all *= B
    mp[memo[l].data]--;
  }
  cout << sum << "\n";
  return 0;
}


Measured memory_bytes: 96148
#D
N = int(input())
A = list(map(int, input().split()))
A.append(0)

cash = 1000
stock = 0
for i in range(N):
    if A[i] < A[i+1]:
        stock += cash // A[i]
        cash = cash % A[i]
    else:
        cash += stock * A[i]
        stock = 0

print(cash)

Measured memory_bytes: 9128
import numpy as np
import itertools

n, d = map(int,input().split())
x = np.array([list(map(int,input().split())) for i in range(n)])

i = 1
sq = []
while i**2 <= 40**2*10:
    sq.append(i**2)
    i += 1

cnt = 0
l = [int(i) for i in range(n)]
for v in itertools.combinations(l, 2):
    i, j = v[0], v[1]
    sub = x[i] - x[j]
    dist = sum(sub**2)
    if dist in sq:
        cnt += 1
print(cnt)

Measured memory_bytes: 26748
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a = []
    now = 0

    for i in range(n):
        a.append(int(input()) - 1)

    for i in range(n):
        now = a[now]
        if now == 1:
            print(i + 1)
            break
    else:
        print(-1)

main()

Measured memory_bytes: 7084
package main

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

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		n, m := io.NextInt(), io.NextInt()
		if n == 0 {
			break
		}
		p := make([][]int, m)
		for i := 0; i < n; i++ {
			d, v := io.NextInt()-1, io.NextInt()
			p[d] = append(p[d], v)
		}
		sum := 0
		for i := 0; i < m; i++ {
			max := 0
			for _, v := range p[i] {
				max = intMax(v, max)
			}
			sum += max
		}
		io.Println(sum)
	}
}

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

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}



Measured memory_bytes: 1344