akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

using namespace std;

int main(){

    int a,b;
    int cnt = 0;

    cin >> a >> b;

    char s[a + b + 1];

    cin >> s;

    for(int i = 0; i < a; i++){
        if(s[i] >= '0' && s[i] <= '9'){
            cnt++;
        }
    }

    if(s[a] == '-'){
        cnt++;
    }

    for(int i = 0; i < a + b + 1; i++){
        if(s[a + i + 1] >= '0' && s[a + i + 1] <= '9'){
            cnt++;
        }
    }

    if(cnt == a + b + 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

using namespace std;
typedef long long ll;

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

  int n; cin >> n;
  vector<int> arr(n);

  for (int i = 0; i < n; ++i) cin >> arr[i];
  sort(begin(arr), end(arr));

  if (n & 1) {
    for (int i = 0; i < n; ++i) {
      if ((i + 1) / 2 * 2 != arr[i]) {
        cout << 0 << "\n";
        return 0;
      }
    }
  } else {
    for (int i = 0; i < n; ++i) {
      if (1 + i / 2 * 2 != arr[i]) {
        cout << 0 << "\n";
        return 0;
      }
    }
  }

  int res = 1;
  for (int i = 0; i < n /2; ++i) {
    res *= 2;
    res %= 1000000007;
  }

  cout << res << "\n";
}


Measured memory_bytes: 3700
import java.util.ArrayList;
import java.util.Scanner;


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


	Scanner sc =new Scanner(System.in);
	ArrayList<Integer> list=new ArrayList<Integer>();


	while(sc.hasNextLine()) {
		list.add(Integer.parseInt(sc.nextLine()));
	}
	
	int thousand=list.get(0)/1000;
	
	if(list.get(0)%1000!=0) {
	int thousands=(int) Math.floor(thousand)+1;

	System.out.print(thousands*1000-list.get(0));
	}else {
		System.out.print(0);
	}
}}




Measured memory_bytes: 35584
N,X = gets.chomp.split(" ").map(&:to_i)
L = gets.chomp.split(" ").map(&:to_i)
sum = 0
count = 1
for i in 0..L.length-1 do
    sum = sum + L[i]
    if sum <= X
        count = count + 1
    end
end
puts count

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

int main() {
  string s;
  cin >> s;
  i64 N = s.size();
  i64 ans = 0;
  for(i64 i = 0; i < N - 1 - i; i++) {
    if(s[i] != s[N - 1 - i]) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n_m = gets
n_m = n_m.split(" ")
n = n_m[0].to_i
ank = []

n.times do
  oneperson = gets
  oneperson = oneperson.split(" ").map{|onedata| onedata.to_i }
  oneperson.shift
  ank << oneperson
end

ank = ank.map{|onedata| onedata.uniq}

tmp = []


nextary = []


#全ての配列に一つでも含まれているものを抽出する。
ank.each do|one|
  one.each do|data|
    if tmp.include? data
    else
      tmp << data
    end
  end
end

#全体配列を見て
ank.each do|one|
  nextary = []
  one.each do|data|
    #含まれていないなら、次の配列の候補へぶっこむ
    if tmp.include? data
      nextary << data
    end
  end
  tmp = nextary
end

puts tmp.size.to_s

Measured memory_bytes: 1788
#ifdef BUILT_LOCAL

#include "niklib.h"

#endif

#include <iostream>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <map>
#include <cmath>
#include <set>
#include <list>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
constexpr ll mod = 1000000007;

int main() {
    ll n, a[100000], c[300002] = {3}, r = 1;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        c[a[i] + 1]++;
        r = (r * c[a[i]]) % mod;
        c[a[i]]--;
    }
    cout << r << endl;
}

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

#define PB push_back
#define MP make_pair
#define F first
#define S second

using namespace std;

typedef long long ll;

const int max_n = 100111, inf = 1000111222;

const ll mod = 1000000007;

ll sumq[max_n];
ll sumb[max_n];
ll sumc[max_n];
ll sumbc[max_n];
ll sumbq[max_n];
ll sumqc[max_n];
ll sumqq[max_n];


ll powm(ll a, ll b) {
    if (b < 0) return 0;
    if (b == 0) return 1;
    if (b % 2 == 0) {
        return powm((a * a) % mod, b / 2);
    } else {
        return (a * powm(a, b - 1)) % mod;
    }
}

ll ans = 0;
void add(ll a) {
    ans += a;
    ans %= mod;
}


int main() {
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    //cout.tie(0);
    string s;
    int q = 0;
    cin >> s;
    for (char c : s) {
        if (c == '?') ++q;
    }
    for (int i = (int)s.size() - 2; i >= 0; --i) {
        sumq[i] = sumq[i + 1] + (s[i + 1] == '?');
        sumb[i] = sumb[i + 1] + (s[i + 1] == 'B');
        sumc[i] = sumc[i + 1] + (s[i + 1] == 'C');

        sumbc[i] = sumbc[i + 1];
        if (s[i + 1] == 'B') sumbc[i] += sumc[i + 1];

        sumbq[i] = sumbq[i + 1];
        if (s[i + 1] == 'B') sumbq[i] += sumq[i + 1];

        sumqc[i] = sumqc[i + 1];
        if (s[i + 1] == '?') sumqc[i] += sumc[i + 1];

        sumqq[i] = sumqq[i + 1];
        if (s[i + 1] == '?') sumqq[i] += sumq[i + 1];
    }

    for (int i = 0; i + 2 < s.size(); ++i) {
        if (s[i] == 'A') {
            add((sumbc[i] * powm(3, q)) % mod);
            add((sumqq[i] * powm(3, q - 2)) % mod);
            add((sumbq[i] * powm(3, q - 1)) % mod);
            add((sumqc[i] * powm(3, q - 1)) % mod);
        } else if (s[i] == '?') {
            add((sumbc[i] * powm(3, q - 1)) % mod);
            add((sumqq[i] * powm(3, q - 3)) % mod);
            add((sumbq[i] * powm(3, q - 2)) % mod);
            add((sumqc[i] * powm(3, q - 2)) % mod);
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 5888
#import <Foundation/Foundation.h>
#import <stdarg.h>

@interface StdIO : NSObject
+(NSMutableString*)stringFromStdIn;
+(void)printf:(NSString*)format, ...;
@end
@implementation StdIO
+(NSMutableString*)stringFromStdIn
{
    NSFileHandle *handle = [NSFileHandle fileHandleWithStandardInput];
    NSMutableString *result = [NSMutableString string];
    NSData *data = [handle availableData];
    while ([data length] > 0) {
        [result appendString:[[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease]];
        data = [handle availableData];
    }
    return result;
}
+(void)printf:(NSString*)format, ...
{
    va_list arguments;
    va_start(arguments, format);
    NSString *string = [[[NSString alloc] initWithFormat: format arguments: arguments] autorelease];
    NSFileHandle *fileHandle = [NSFileHandle fileHandleWithStandardOutput];
    [fileHandle writeData:[string dataUsingEncoding: NSUTF8StringEncoding]];
    va_end(arguments);
}
@end
  
@interface NSString (Extension)
-(NSArray*)characters;
@end

@implementation NSString (Extension)
-(NSArray*)characters
{
    NSMutableArray *result = [NSMutableArray array];
    for (NSUInteger i=0; i < [self length]; i++) {
        [result addObject:[NSString stringWithFormat:@"%C", [self characterAtIndex:i]]];
    }
    return result;
}
@end

int main() {
    @autoreleasepool {
        NSArray *numbers = [[StdIO stringFromStdIn] componentsSeparatedByString:@" "];
        NSInteger N = [[numbers objectAtIndex:0] integerValue];
        NSInteger A = [[numbers objectAtIndex:1] integerValue];
        NSInteger B = [[numbers objectAtIndex:2] integerValue];
        NSInteger result = 0;
        for (NSInteger i=1; i<=N; i++) {
            NSArray *digits = [[NSString stringWithFormat:@"%ld", i] characters];
            NSInteger sum = 0;
            for (NSString *digit in digits) {
                sum += [digit integerValue];
            }
            if (A<=sum && sum<=B) {
                result += i;
            }
        }
        [StdIO printf: @"%ld", result];
    }
    return 0;
}


Measured memory_bytes: 7652
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int main() {
    int n, d;
    cin >> n >> d;
    int x[n][d];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            cin >> x[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int distance = 0;
        for (int j = i+1; j < n; j++) {
            for (int k = 0;k < d; k++) {
                distance += pow(x[i][k] - x[j][k], 2);
            }
            if (sqrt(distance) == int(sqrt(distance))) {
                ans++;
            }
            distance = 0;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
using System;

namespace ABC123 {
    class A {
        static void Main (string[] args) {
            int[] l = new int[5];
            for (int i = 0; i < 5; i++) {
                l[i] = int.Parse (Console.ReadLine ());
            }
            int k = int.Parse (Console.ReadLine ());
            bool isExist = false;
            if (k < (l[4] - l[0])) { isExist = true; }

            if (isExist) { Console.WriteLine (":("); } else { Console.WriteLine ("Yay!"); }
        }
    }
}

Measured memory_bytes: 11092
import numpy as np
from collections import Counter
from math import sqrt
from time import time


def main():
    N = int(input())
    np_a_o = list([int(x) for x in input().split()])
    np_a = Counter(np_a_o)

    np_a_keys = set(np_a.keys())

    div_list = set()
    key_max = max(np_a_keys)

    c = 0

    for key in np_a_keys:
        for div in range(key*2, key_max+1, key):
            div_list.add(div)

    r = np_a_keys - div_list

    u, count = np.unique(np.array(np_a_o), return_counts=True)
    r -= set(u[count > 1])

    print(len(r))


if __name__ == '__main__':
    main()


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

int main(){
  long long A, B , K;
  cin >> A >> B >> K;
  long long AA = A;
  A = A-K > 0 ? A-K:0;
  K = K-AA > 0 ? K-AA: 0;
  B = B-K > 0 ? B-K: 0;
  cout << A << " "<< B << endl;
  return 0;
}

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

/*int main(int argc, char **argv)
{
	int a, b, c, d, e;
	std::cin >> a >> b >> c >> d >> e;
	std::cout << std::min(a, std::min(b, c)) + std::min(d, e) - 50 << std::endl;
	return 0;
}*/
/*int main()
{
	int l, a, b, c, d;
	std::cin >> l >> a >> b >> c >> d;
	int japa, math;
	japa = a / c;
	if(a % c != 0){
		japa++;
	}
	math = b / d;
	if(b % d != 0){
		math++;
	}
	std::cout << l - std::max(japa, math) << std::endl;
}*/
/*int main()
{
	bool sub[31];
	int input;
	for(int i = 0; i < 31; i++){
		sub[i] = false;
	}
	for(int i = 0; i < 28; i++){
		std::cin >> input;
		sub[input] = true;
	}
	for(int i = 1; i < 31; i++){
		if(!sub[i]) std::cout << i << std::endl;
	}
}*/
int main()
{
	std::vector<int> w, k;
	int input;
	for(int i = 0; i < 10; i++){
		std::cin >> input;
		w.push_back(input);
	}
	for(int i = 0; i < 10; i++){
		std::cin >> input;
		k.push_back(input);
	}
	std::sort(w.begin(),w.end(),std::greater<int>());
	std::sort(k.begin(),k.end(),std::greater<int>());
	std::cout << w[0] + w[1] + w[2] << " " << k[0] + k[1] + k[2] << std::endl;
}

Measured memory_bytes: 3136
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
ll k (ll a){
    a--;
    ll ans =0;
    while(a != 0){
        ans += a;
        a--;
        
    }
    return ans;
}


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

    vector<int> vec(n);
    REP(i,n){
        cin >> vec[i];
    }
    SORT(vec);
    
    REP(i,k){
        if(i >= n){
            break;
        }
        vec[n-1-i] = 0;
    }
    ll ans = 0;
    REP(i,n){
        ans += vec[i];
    }
    cout << ans <<endl;
}



Measured memory_bytes: 1024
// きりみんちゃんの配信からきました
// 答えは2種類ぽくなりそう（いまみてるのが全体の中央値以外なら中央値になるし、そうじゃない==中央値自身ならばひとつずれる）

package main

import (
	"fmt"
	"sort"
)

var n int
var x []int

func main() {
	fmt.Scan(&n)
	x = make([]int, n)
	for i := 0; i < n; i++ {
		var j int
		fmt.Scan(&j)
		x[i] = j
	}
	tmp := append([]int{}, x...)
	sort.Ints(tmp)
	one, two := tmp[n/2-1], tmp[n/2]
	for i := 0; i < n; i++ {
		if x[i] <= one {
			fmt.Println(two)
		} else {
			fmt.Println(one)
		}
	}
}


Measured memory_bytes: 8704
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

int calc(vi& h){
    int n = (int)h.size();

    vi L(n), R(n), st(n);
    int t = 0;
    rep(i, n){
        while(t > 0 and h[st[t - 1]] >= h[i]) t--;
        L[i] = t == 0 ? 0:(st[t - 1] + 1);
        st[t++] = i;
    }
    t = 0;
    rrep(i, n){
        while(t > 0 and h[st[t - 1]] >= h[i]) t--;
        R[i] = t == 0 ? n:st[t - 1];
        st[t++] = i;
    }

    int ret = 0;
    rep(i, n){
        chmax(ret, (h[i] + 1) * (R[i] - L[i] + 1));
    }

    return ret;
}

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

    int h, w; cin >> h >> w;
    vector<string> in(h); for(auto& e : in) cin >> e;

    vector<vi> f(h - 1, vi(w - 1, 1));
    rep(y, h - 1){
        rep(x, w - 1){
            int cnt = 0;
            rep(yy, 2) rep(xx, 2) if(in[y + yy][x + xx] == '#') cnt++;
            if(cnt % 2 == 1){
                f[y][x] = 0;
            }
        }
    }

    int res = max(h, w);
    h = h - 1, w = w - 1;
    vi pre(w);
    rep(y, h){
        vi cur = pre;
        rep(x, w){
            cur[x]++;
            if(f[y][x] == 0) cur[x] = 0;
        }
        chmax(res, calc(cur));
        pre = cur;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 20224
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		if(n%(2*d+1) == 0)
		System.out.println(n/(2*d+1));
		else
		System.out.println(n/(2*d+1)+1);
}
}


Measured memory_bytes: 21844
def c_management():
    N = int(input())
    A = [int(i) for i in input().split()]

    tree = [[] for _ in range(N)]
    for k, a in enumerate(A, 2):
        tree[a - 1].append(k - 1)

    ans = [len(t) for t in tree]
    return '\n'.join(map(str, ans))

print(c_management())

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

int main(void){
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout 
    << (char)(s1[0]-'a'+'A')
    << (char)(s2[0]-'a'+'A')
    << (char)(s3[0]-'a'+'A') << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	string A,B;
	cin>>A>>B;
	if(A==B){
		cout<<"="<<endl;
	}else{
		cout<<(A<B?"<":">")<<endl;
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


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

signed main()
{
    int n, N;
    cin >> n;
    
    N = n;
    vector<int> pf;
    for (int i = 2; i * i <= N; ++i)
    {
        if (N % i == 0)
        {
            pf.push_back(i);
            while (N % i == 0) N /= i;
        }
    }
    if (N != 1) pf.push_back(N);
    
    N = n;
    vector<int> factors = {1};
    for (int p: pf)
    {
        int si = factors.size();
        int mul = 1;
        while (N % p == 0)
        {
            N /= p;
            mul *= p;
            for (int i = 0; i != si; ++i)
                factors.push_back(factors[i] * mul);
        }
    }
    
    int ans = 0;
    for (int f: factors)
    {
        if (f == 1) continue;
        int m = f - 1;
        if (n / m == n % m)
            ans += m;
    }
    
    cout << ans;
    return 0;
}

Measured memory_bytes: 384
//Khodaya aghideye man ra az dast oghde am masoon dar!
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, greater_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
#pragma optimize O3
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e5 + 3;
const int infint = (ll)1e9;
const ll inf = (ll)1e18;
int t[MAXN], pos[MAXN];
int main()
{	
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		t[i] = 1;
	pos[1] = 1;
	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		t[u]--, t[v]++;
		if(pos[u] == 1)
			pos[v] = 1;
		if(t[u] == 0)
			pos[u] = 0;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
		if(pos[i])
			ans++;
	cout << ans;
}

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

int main(){
  int n, a, b;
  vector<int> nums;
  cin >> a;
  nums.push_back(a);
  while(true){
    if (a % 2 ==0) {
      b = a / 2;
    }
    else if (a % 2 != 0)
    {
      b = 3 * a + 1;
    }
    n = nums.size();
    bool k = false;
    for(int i = 0; i < n; i++)
    {
      if (b == nums.at(i)) {
        k = true;
        break;
      }
      
    }
    if (k) {
      break;
    }
    
    nums.push_back(b);
    
    a = b;   
  }
  cout << n + 1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pob pop_back
#define vl vector<ll>
#define mp make_pair
#define sz size()
#define fast ios::sync_with_stdio(0);cin.tie(0)
#define maxx 1000005
#define mod 1000000007
#define edge pair<ll,ll>
using namespace std;
 
 
// ¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++¦¦¦++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++¦¦¦¦¦¦¦¦¦¦+++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++¦¦¦¦¦+++++++¦++¦¦
// ¦¦¦¦¦¦¦¦++¦¦¦¦¦¦++++++¦¦¦¦+++++++++++++¦
// ¦¦¦¦¦¦¦++++++¦¦¦++++++¦¦++++++++++++++¦¦
// ¦¦¦¦¦¦¦+++++++¦¦¦+++++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++¦¦¦¦¦¦¦¦¦++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++¦¦¦¦¦¦¦¦+++++++¦ 
// ¦¦¦¦¦¦¦¦¦¦++¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦++++¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦ 
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++¦¦+¦++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++¦¦+++++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+¦¦¦¦+++¦¦¦¦++++++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++¦¦+¦¦¦¦¦+++++++¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++++++¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+¦¦¦+++++++++++¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++¦¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++¦¦¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++¦¦¦¦¦¦¦¦¦¦¦¦

int main()
{
	fast;
	ll n;
	cin>>n;
	ll i,j,k;
	ll ans=0,g;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			for(k=1;k<=n;k++)
			{
				g=__gcd(i,j);
				g=__gcd(g,k);
				ans+=g;	
				
			}
		}
	}
	cout<<ans<<endl;
	return 0;
	
}



	//cout<<ans<<endl;
 
	//cout<<ans<<endl;
	
	//cout<<fixed<<setprecision(10)<<sum<<endl;


Measured memory_bytes: 3652
N, T = map(int, input().split())
t = list(map(int, input().split()))

ans = 0
now = t[0]
for i in range(0, N-1):
    next_t = t[i+1]
    if (next_t - now) >= T:
        ans += T
    else:
        ans += next_t - now
    now = next_t
ans += T
print(ans)

Measured memory_bytes: 26708
#include<iostream>
#include<cmath>
#include<iomanip>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

struct Point
{
  double x,y;
  Point(double x=-1,double y=-1):x(x),y(y){}
};

double getArg(Point A,Point B,Point C)
{
  double a = sqrt(pow(B.x-C.x,2)+pow(B.y-C.y,2));
  double b = sqrt(pow(A.x-C.x,2)+pow(A.y-C.y,2));
  double c = sqrt(pow(A.x-B.x,2)+pow(A.y-B.y,2));
  return acos( (b*b+c*c-a*a)/(2*b*c) );
}

inline double toRad(double agl){ return agl*M_PI/180.0; }

int main()
{
  int n;
  while(1)
    {
      cin >> n;
      if(n == -1)break;
      Point st = Point(0,0);
      Point now;
      double arg = 180*M_PI/180.0;
      rep(i,n)
	{
	  if(i == 0)
	    {
	      now = Point(1,0);
	      continue; 
	    }


	  arg -= 90*M_PI/180.0;
	  if(arg < 0)arg += toRad(360);

	  now.x = now.x + cos(arg);
	  now.y = now.y + sin(arg);
	  Point slide = Point(now.x+10,now.y);
	  double rarg = getArg(now,st,slide);
	  arg = (now.y <= 0 ? rarg:toRad(360)-rarg);
	}
      cout << setiosflags(ios::fixed) << setprecision(2) << now.x << endl;
      cout << setiosflags(ios::fixed) << setprecision(2) << now.y << endl;
    }
  return 0;
}

Measured memory_bytes: 1292
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    n = intin()

    ans = 0

    for div in set(get_divisors(n)):
        m = div - 1
        a = n // div
        if m <= a:
            continue
        ans += m

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4496
N = int(input())
P = [int(i) for i in input().split()]

cnt = 0
for i in range(1, N - 1):
    A = [P[i - 1], P[i], P[i + 1]]
    maxA = max(A)
    minA = min(A)
    if P[i] != maxA and P[i] != minA:
        cnt += 1
        
print(cnt)

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[200000];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		int max = Integer.MIN_VALUE;
		int min = arr[0];
		for (int i = 1; i < n; i++) {
			max = Math.max(max, arr[i] - min);
			min = Math.min(min, arr[i]);
		}
		System.out.println(max);
	}
}

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

int main() {
    int K, T;
    cin>>K>>T;
    vector<int> a;
    int tmp;
    for(int i=0;i<T;++i){
        cin>>tmp;
        a.push_back(tmp);
    }
    sort(a.begin(), a.end());
    long nokori = 0;
    for(int i=0;i<T-1;++i){
        nokori += a[i];
    }
    if(a[a.size()-1] - nokori - 1 < 0){
        cout<<0<<endl;
    }
    else {
        cout<<a[a.size()-1] - nokori-1<<endl;
    }
}


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

#define rep(i,n) for(i=0;i<n;++i)
#define int long long
#define str string
#define debg(a) cout<<#a<<":"<<a<<endl;
#define print(a) cout<<a<<endl;
#define end cout<<endl;

signed main(){
  int n,a,b;
  cin>>n>>a>>b;
  int i,p[n];
  rep(i,n)cin>>p[i];
  int ap=0,bp=0,cp=0;
  rep(i,n){
    if(p[i]<=a)ap++;
    else if(p[i]>a&&p[i]<=b)bp++;
    else cp++;
  }
  int ans=min(ap,min(cp,bp));
  print(ans);
  
  
  return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

vector<vector<ll>> mkcmb(const int MX){
	vector<vector<ll>> cmb(MX+2, vector<ll>(MX+2));
	rep(i,MX+1)  cmb[i][0] = 1;
	rep2(i,1,MX+1) rep2(j,1,i+1)
		cmb[i][j] = cmb[i-1][j] + cmb[i-1][j-1];
	return cmb;
}

int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n,a,b;
	cin >>n >>a >>b;
	
	vector<ll> v(n), sm(n+1);
	for(auto& iv :v) cin >>iv;
	sort(v.rbegin(), v.rend());
	rep(i,n) sm[i+1]=v[i]+sm[i];
	
	auto ncr = mkcmb(53);

	
	ll ans = 0;
	ll tgt = v[a-1];
	rep2(i, a, b+1){
		int cnt=0, ndc=0;
		if(v[i-1] < tgt) break;
		if(sm[a]*i != sm[i]*a) break;
		rep(j, n) if(tgt==v[j]){
			cnt++;
			if(j < i) ndc++;
		}
		//dbg(i,cnt, ndc);
		ans += ncr[cnt][ndc];
	}
	double as1 = (double)sm[a] / a;
	printf("%.14f\n%lld\n", as1, ans);

	return 0;
}

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

using namespace std;

int N;
int p[100005];

int main() {

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N;

for(int i=1; i<=N; i++){
  cin>>p[i];
}

int cnt=0;

for(int i=1; i<=N; i++){
  if(p[i]!=i) continue;
  if(i>=2&&p[i-1]==i-1){
    p[i-1]=i;
    p[i]=i-1; 
    cnt++;
  }
  else if(i<=N-1&&p[i+1]==i+1){
    p[i+1]=i;
    p[i]=i+1;
    cnt++;
  }
  else{
    if(i<=N-1){
      p[i+1]=i;
      p[i]=i+1;
      cnt++;
    }
    else if(i>=2){
      p[i-1]=i;
      p[i]=i-1; 
      cnt++;
    }
  }
}

cout<<cnt<<endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
int n,i,array1[N],counter=0;
map<int,int>visited;
scanf("%d",&n);
for(i=1;i<=n;++i){
    scanf("%d",&array1[i]);
}
i=1;
while(true){
    if(i==2){
        break;
    }
    counter++;
    if(visited[i]){
        counter=-1;
        break;
    }
    visited[i]=1;
    i=array1[i];
}
printf("%d",counter);

    return 0;
}


Measured memory_bytes: 8664
import java.util.*;
 
class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
 
        if( A + B >= C){
            System.out.println(B + C);
        }else if(Math.max(A, B) < C){
            System.out.println((2*B + A) + 1);
        }
 
    }
}

Measured memory_bytes: 23124
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
typedef long long ll;
const ll MAX=510000;
const ll mod = 1e9 + 7;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,D,Q,K,R,W,H,P,L,G;
ll ans;
string S,T;
ll h[101010];
ll y[101010];
ll a[201010];
ll c[101010];
ll k[101010];
ll b[201010];
ll d[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll l[101010];
ll r[101010];
ll v[101010];
ll s[101010];
ll x[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
struct Edge{
	ll to,cost;
	 Edge(ll to, ll cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<ll> size;
    UnionFind(ll N) : par(N),size(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
		for(ll i = 0; i < N; i++) size[i] = 1;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
	ll GetSize(ll x){
		return size[root(x)];
	}

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		size[ry]+=size[rx];

    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main(){
    cin>>N>>K;
    cin>>S;
    ans=0;
    rep(i,1,N){
        if(S[i]==S[i-1]){
            ans+=1;
        }
    }
    ans+=K*2;
    cout<<min(ans,N-1)<<endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int num = n;
        while(true){

            if(judge(num)){
                num +=1;
                continue;
            }

            else{
                System.out.println(num);
                break;
            }

        }
    }
  
    

    private static boolean judge(int num){
       if(num == 2) return false;
       
       for(int i = 2;i < (int)Math.pow(num,0.5); i++)
       {
            if(num % i == 0) return true;
            else continue;
       }
       return false;
    }
}

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

public class Main {
	
	private void doIt() {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if( n == 0)
				break;
			int [] data = new int[n];
			for(int i=0; i < n; i++){
				data[i] = sc.nextInt();
			}
			Arrays.sort(data);
			int sum = 0;
			for(int i=1; i < n - 1;i++){
				sum += data[i];
			}
			System.out.println(sum /  (n - 2));
		}
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();
	}

}

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

using namespace std;

typedef long long lint;
const lint N = 110;
string n;
lint k, dp[N][N][2][2];

lint solve(lint digit, lint cnt, lint zero, lint flag){
    if (cnt < 0)
        return 0;

    if (digit == n.size()){
        if (cnt == 0){
            return 1;
        }
        return 0;
    }

    if (dp[digit][cnt][zero][flag] != -1) return dp[digit][cnt][zero][flag];

    lint res = 0;

    lint limit;

    if (flag)
        limit = n[digit]-'0';
    else
        limit = 9;

    //cout << digit << " " << limit << endl;

    for (lint d=0;d<=limit;d++){
        //cout << digit << " " << d << endl;
        if (d)
            res += solve(digit+1, cnt-1, zero, d==n[digit]-'0'?flag:0);
        else
            res += solve(digit+1, cnt, 1, d==n[digit]-'0'?flag:0);

    }

    return dp[digit][cnt][zero][flag] = res;
}

int main(){
    cin >> n;
    scanf("%lld", &k);

    memset(dp, -1, sizeof dp);

    printf("%lld\n", solve(0, k, 0, 1));

    //cout << dp[0][0][0]+dp[0][0][1] << endl;

    return 0;
}


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

int main()
{
	int n, x;
	int i, j, k;
	int count = 0;

	while (1) {
		cin >> n >> x;

		if (n == 0 && x == 0) {
			break;
		}

		for (i = 1; i <= n; i++) {
			for (j = i + 1; j <= n; j++) {
				for (k = j + 1; k <= n; k++) {
					if (i + j + k == x) {
						count++;
					}
				}
			}
		}

		cout << count << endl;

		count = 0;
	}

	return 0;
}

Measured memory_bytes: 3088
/**
            C++14 (GCC 5.4.1)
**/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;


bool check(string s) {
    for (int i = 0; i < s.size() / 2; i++) {
        if (s[i] == s[s.size() - 1 - i]) {
            continue;
        }
        else {
            return false;
        }
    }
    return true;
}


int main() {
    string s;
    cin >> s;

    if (check(s)) {
        if (check(s.substr(0, (s.size()-1) / 2))) {
            if (check(s.substr( ((s.size() + 3) / 2) -1 ))) {
                cout << "Yes" << endl;
            }
            else {
                cout << "No" << endl;
            }
        }
        else {
            cout << "No" << endl;
        }
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
fun main(args: Array<String>){
    var N = readLine()!!.toLong()
    var ans :Long = 0
    if(N % 2 == 0L){
        N /= 2

        var div : Long = 5

        while(div <= N){
            ans += N /div
            div *=5
        }

    }


    println(ans)



}

Measured memory_bytes: 34452
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define endl        "\n"
#define si(a)       scanf("%d",&a)
#define si2(a,b)    scanf("%d%d",&a,&b)
#define si3(a,b,c)  scanf("%d%d%d",&a,&b,&c)
#define sl(a)       scanf("%lld",&a)
#define sl2(a,b)    scanf("%lld%lld",&a,&b)
#define sl3(a,b,c)  scanf("%lld%lld%lld",&a,&b,&c)
#define pb          push_back
#define mk          make_pair
#define loop(n)     for(int i=0; i<n; i++)
#define FOR(a,b)    for(int i=a; i<=b; i++)
#define sz          size()
#define pY          printf("YES")
#define pN          printf("NO")
#define py          printf("Yes")
#define pn          printf("No")
#define mem(a,val)  memset(a, val, sizeof(a))
#define md          1000000007




ll a[200010], cs[200010];
int main()
{
    ll t,n,i,j,k,l,mn=0, mx=0,m;

    sl(n);

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

    for(int i=1; i<=n; i++)
    {
       cs[i]=cs[i-1]+a[i];
       cs[i]%=md;
    }

    ll ans=0;

    for(int i=1; i<=n; i++)
    {
       ans =((ans%md)+ (a[i]*cs[i-1])%md)%md;
    }

    cout<<ans<<endl;

}







Measured memory_bytes: 6860
H, W = map(int, input().split())
a = [None] * H

for i in range(H):
    a[i] = input()

for i in range(H + 2):
    if i == 0 or i == H + 1:
        out = "#" * (W + 2)
    else:
        out = "#" + a[i - 1] + "#"
    print(out)


Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
  int n,i,d,x,ans=0,t=1,a[101];
  scanf("%d%d%d",&n,&d,&x);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    while(t<d+1){
      ans++;
      t+=a[i];
    }
    t=1;
  }
  printf("%d",x+ans);
  return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        try {
            String input = in.readLine();

            String[] inputs = input.split("\\s+");

            int a = Integer.parseInt(inputs[0]);
            int b = Integer.parseInt(inputs[1]);

            System.out.println(String.join(" ", new String[] {String.valueOf(a * b), String.valueOf((a + b) * 2)}));
        } catch (IOException ex) {
            // no op
        }
    }
}


Measured memory_bytes: 24396
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}


fun solve(out: PrintWriter) {
    val a = Array(5) {
        readInteger()
    }
    val aaa = permutationListFrom(a)
    var ans = Int.MAX_VALUE
    for (ab in aaa) {
        var cur = 0
        for ((i, abb) in ab.withIndex()) {
            cur += abb
            cur += if (cur % 10 == 0 || i == 4) 0 else 10 - cur % 10
        }

        ans = Math.min(ans, cur)
    }
    out.println(ans)

}

/** O((array.size)!) */
fun <T : Comparable<T>> permutationListFrom(array: Array<T>): List<Array<T>> {
    val current = array.copyOf()
    val permutationList = mutableListOf<Array<T>>()
    do { permutationList += current.copyOf() } while (nextPermutation(current))
    return permutationList
}

/** O(n): n = currentPermutation.size */
fun <T : Comparable<T>> nextPermutation(currentPermutation: Array<T>): Boolean {
    fun <T> Array<T>.reverse(start: Int, end: Int) {
        val midPoint = ((start + end) / 2) - 1
        if (midPoint < 0) return
        var reverseIndex = end - 1
        for (index in start..midPoint) {
            val tmp = this[index]
            this[index] = this[reverseIndex]
            this[reverseIndex] = tmp
            reverseIndex--
        }
    }

    val n = currentPermutation.size
    var i = n - 2
    while (i >= 0) {
        if (currentPermutation[i] < currentPermutation[i + 1]) break
        i--
    }
    if (i < 0) return false
    var j = n
    do { j-- } while (currentPermutation[i] > currentPermutation[j])
    if (currentPermutation[i] < currentPermutation[j]) {
        val tmp = currentPermutation[i]
        currentPermutation[i] = currentPermutation[j]
        currentPermutation[j] = tmp
        currentPermutation.reverse(i + 1, n)
        return true
    }
    return false
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


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

int main() {
    ll A,B,C;
    cin >> A >> B >>C;
    if(A%2 != 0 || B%2 !=0 || C%2 != 0){
        cout << 0 << endl;
        return 0;
    }
    if(2 *A == B+C && 2*B  ==A+C && 2*C == A+B ){
        cout << -1 << endl;
        return 0;
    }
    ll ans =0;
    while( A%2 == 0 && B%2 ==0 && C%2 ==0){
        ll nA = B/2 + C/2;
        ll nB = A/2 + C/2;
        ll nC = A/2 + B/2;
        A =nA;B =nB;C =nC;
        ans++;
    }
    cout << ans << endl;
    

    return 0;
}

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

int main() {
  int m,n;
  cin >> m >> n;
  string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
  
  for(int i=0;i<m*n;i++){
    string s;
    cin >> s;
    
    if(s=="snuke"){
      cout << alphabet.at(i%n) << i/n + 1 << endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef string str;
 
str s, t;
 
int main()
{
 	cin >> s;
  	cin >> t;
  	for (ll i = 0; i < s.length(); i++)
    {
    	if (s[i] != t[i])
        {
          	cout << "No";
          	return (0);
        }
    }
  	cout << "Yes";
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  char s[100005];
  scanf("%d",&n);
  scanf("%s",s);
  long long J[100005],I[100005];
  J[0] = 0;
  I[n-1] = 0;
  for(int i=0;i<n;i++){
    if(i != 0) J[i] = J[i-1];
    if(s[i] == 'J') J[i]++;
  }
  for(int i=n-1;i>=0;i--){
    if(i != n-1) I[i] = I[i+1];
    if(s[i] == 'I') I[i]++;
  }
  long long ans,sum=0,isum = 0,jsum = 0,oma=0;
  if(s[0] == 'O') jsum = I[1];
  if(s[n-1] == 'O') isum = J[n-2];
  for(int i=1;i<n-1;i++){
    if(s[i] == 'O'){
      sum += J[i-1]*I[i+1];
      jsum += (J[i-1]+1)*I[i+1];
      isum += J[i-1]*(I[i+1]+1);
    }
    oma = max(oma,J[i-1]*I[i]);
  }
  oma = max(oma,J[n-2]*I[n-1]);
  ans = max(jsum,isum);
  ans = max(ans,sum+oma);
  printf("%lld\n",ans);
  return (0);
}

Measured memory_bytes: 4868
#include<cstdint>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<iterator>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>
#include<utility>
#include<initializer_list>


#define repi(i,start,end)for(int64_t (i)=(start);(i)<(end);++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x, v) for(auto& (x) : (v))
#define iterate(itr, v) for(auto (itr)=(v).begin();(itr)!=(v).end();++(itr))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vin(v) rep(i,(v).size()) cin >> (v)[i];
#define vpin(v) rep(i,(v).size()) cin >> (v)[i].first >> (v)[i].second

using namespace std;
using Int = int64_t;
using pint = pair<Int, Int>;
using vint = vector<Int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
using vstr = vector<string>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;  } return 0;  }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;  } return 0;  }
template<class T>void put_double(T a){cout<<setprecision(12);cout<<a<<"\n";}
template<class T>void println(T a){cout << a << "\n";}
template<class T>void put_line(T &v){iterate(itr,v){cout<<*itr<<((itr==--v.end())?"\n":" ");}}
// auto [x, y] = make_tuple(3, 4); => let (x, y) = (3, 4);

int n;

void dfs(string &s, int bit, int &ans) {
    if(s.size() > 0 && stoll(s) > n) {
        return;
    }
    if(bit == 7) {
        ans++;
    }
    s.push_back('7');
    dfs(s, bit | 4, ans);
    s.pop_back();
    s.push_back('5');
    dfs(s, bit | 2, ans);
    s.pop_back();
    s.push_back('3');
    dfs(s, bit | 1, ans);
    s.pop_back();
    return;
}


int main(void) {
    cin >> n;
    int ans = 0;
    string s = "";
    dfs(s, 0, ans);
    println(ans);

    return 0;
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

long calc(long a, long b, long[] h) {
    // m 回で全ての魔物を倒せるか
    bool check(long m) {
        long k = 0;
        foreach (e; h) {
            long x = e - b * m; // m 回分の b ダメージ
            if (x > 0) {
                // a ダメージを何回与えると倒せるか
                k += (x + (a - b) - 1) / (a - b);
            }
        }
        return m >= k;
    }

    long lo = 1;
    long hi = int.max;
    long ans = hi;
    while (lo <= hi) {
        long m = (lo + hi) / 2;
        if (check(m)) {
            ans = min(ans, m);
            hi = m - 1;
        } else lo = m + 1;
    }
    return ans;
}

void main() {
    int n, a, b; scan(n, a, b);
    long[] h;
    foreach (_; 0..n) h ~= read!long;
    writeln(calc(a, b, h));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


Measured memory_bytes: 2044
#include <iostream>
#include <stdio.h>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
 
typedef long long ll;

#define rep(i,n) for(ll i = 0; i < n; i++)
 
using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

int main(){
  string s;
  cin >> s;
  int ans=0,num=0;
  for(auto &c:s){
    if(c=='A' || c=='C' || c=='G' || c=='T'){
      num++;
    }
    else num=0;
    ans=max(ans,num);
  }
  cout << ans << endl;
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

void solve(){
	int x, n;
	cin >> x >> n;
	vector<int> p(n);
	for(int i = 0; i < n; ++i) cin >> p[i]; 
	if(n > 0) {
		sort(all(p));
		int dif = 0;
		while(true) {
			if(!binary_search(all(p), x + -1 * dif)) {
				cout << x + -1 * dif; 
				return; 
			}
			if(!binary_search(all(p), x + dif)) { 
				cout << (x + dif); 
				return; 
			}
			++dif;
		}
	} else { 
		cout << x;
	}
}

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

	solve();
    
    return 0;
}


Measured memory_bytes: 3636
def compute_score(s):
    return sum([(a - s)**2 for a in As])

N = int(input().strip())
As = list(map(int, input().strip().split()))

s = sum(As) / N
ans = 0
if(s % 1 == 0):
    ans = compute_score(s)
else:
    ans = min(compute_score(s // 1), compute_score(s // 1 + 1))
print(int(ans))

Measured memory_bytes: 3188