akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

const int N = 2005;

int n, x, a[N], b[N];
long long ans = 1e18;

int main(){
    //freopen("test.inp", "r", stdin);
    //freopen("test.out", "w", stdout);

    scanf("%d %d", &n, &x);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) b[i] = a[i];
    for (int i = 0; i < n; i++) {
        long long res = 1LL * x * i;
        for (int j = 1; j <= n; j++) {
            b[j] = min(b[j], a[(j - i < 1 ? j - i + n : j - i)]);
            res += b[j];
        }

        ans = min(ans, res);
    }

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


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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int cnt[26];

signed main(){

	int N;
	int ans = 1;
	cin >> N;
	string S;
	cin >> S;

	rep(i, N){
		cnt[S[i] - 'a']++;
	}

	rep(i, 26){
		if (cnt[i] == 1) (ans *= 2)%=mod;
		else if (cnt[i] > 1){
			ans *= cnt[i]+1;
			ans %= mod;
		}
	}

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

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


int main(){
    vector<ll> list(4);
    rep(i, 4)   cin >> list[i];

    ll ans;
    cin >> ans;
    ans *= 4;

    rep(i, 3){
        if(2*list[i] < list[i+1])   list[i+1] = 2*list[i];
    }

    ll res = 0;
    rep(i, 4){
        int p = pow(2, 3-i);
        res += list[3-i]*(ans/p);
        ans %= p;
    }

    cout << res << endl;


    return 0;
}


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

int main(){
 int N,K;
 cin>>N>>K;
 int v[N+1];
 for(int i=1;i<=N;i++){
    cin>>v[i];
 }

 int *dp = new int [N+1]();
 for(int i=1;i<=N;i++)dp[i]=INT_MAX;
 dp[1]=0;
 dp[2]=abs(v[2]-v[1]);

 for(int i=3;i<=N;i++){
     //cout<<dp[i]<<endl;
     int j=max(i-K,1);
     while(j<i){
  dp[i]=min(dp[j]+abs(v[i]-v[j]),dp[i]);
         j++;
     }
     //cout<<dp[i]<<endl;
 }
cout<<dp[N]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <iterator>
#include <cmath>
#include <map>
using namespace std;



void func161a() {
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y;
}



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

Measured memory_bytes: 256
h, w = gets.split.map(&:to_i)
grid = h.times.map{gets}.map(&:chomp).map(&:chars)
grid = grid.select{|line| line.any?{|c| c == "#"}}.transpose.select{|line| line.any?{|c| c == "#"}}.transpose

grid.each{|line|
    puts line.join
}


Measured memory_bytes: 3836
//BISMILLAHIR RAHMANIR RAHEEM
//ALLAH IS WATCHING ME
// Allah amader korona virus theke rokkha korun.Amin.

//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp> //order_of_key return number of elements less than x, find_by_order return index (pointer use kora lgbe)

using namespace std;
using namespace __gnu_pbds;

#define ull    unsigned long long
#define ll    long long
#define ios    ios::sync_with_stdio(0);cin.tie(0);
#define ses   "\n"
#define all(x) (x).begin(), (x).end()
//#define INF   ((int)2e18)
#define ii pair<ll, ll>

string digit="0123456789";
string small="abcdefghijklmnopqrstuvwxyz";
string capital="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; // 8-direction.......
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[]= {1,-1,0,0}; // 4-direction...........
int dy4[]= {0,0,1,-1};

const int N=1e6+5;
const ll M=1e18;

typedef tree< ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

struct Edge
{
    int u, vv;
    bool operator<(Edge const& other)
    {
        return vv > other.vv;
    }
}; // eta joss jinis.krsukal er jnno and sort 1 out of 3 or more er jnno better

/////////////////////////////////////////////////////////////////////////////
bool subsequence(string s, string t,ll i , ll point){
  for(ll k = i ; k<s.size();k++){
            if(s[k]==t[point])point++;
            if(point==t.size())return 1;
  }
  if(point<t.size())return 0;
}
////////////////////////////////////////////////////////////////////////////
//main function is here.........
int main()
{
       //ios
   ll n,m;
   cin>>n>>m;
   n--;
   m--;
   cout<<((n*(n+1))/2) + ((m*(m+1))/2);
}


/*



*/



//Alhamdulillah


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,a,b,c=map(int,input().split())
    L=[int(input()) for _ in range(n)]

    def dfs(v,Idx)->int:
        # terminate condition
        if(v==n):
            score=0
            Idx=tuple(Idx)
            A,B,C=[],[],[]
            for i,k in enumerate(Idx):
                if(k==0): A.append(L[i])
                elif(k==1): B.append(L[i])
                elif(k==2): C.append(L[i])
            if((not A) or (not B) or (not C)): return INF # 1つも竹が無いのはダメ
            score+=(len(A)+len(B)+len(C)-3)*10

            SA=sum(A)
            SB=sum(B)
            SC=sum(C)
            score+=abs(SA-a)
            score+=abs(SB-b)
            score+=abs(SC-c)
            return score
            
        res=INF
        for i in range(4):
            Idx[v]=i
            res=min(res,dfs(v+1,Idx))
        return res

    print(dfs(0,[0]*n))
resolve()

Measured memory_bytes: 68572
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>


#define ll long long


//gcdやり直す

void swap (int *x, int *y) {
  int temp;    

  temp = *x;
  *x = *y;
  *y = temp;
}




/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition (int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}





/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  int n;
  scanf("%d",&n);
  int ans=(n-3)*n/2+n;
  ans-=n/2;
  printf("%d\n",ans);
  if(n%2==0){
    for(int i=1;i<=n;i++){
      for(int j=i+1;j<=n;j++){
        if(i+j==n+1){
          continue;
        }

        printf("%d %d\n",i,j);
      }
    }
  }

  else{
    for(int i=1;i<=n;i++){
      for(int j=i+1;j<=n;j++){
        if(i+j==n){
          continue;
        }

        printf("%d %d\n",i,j);
      }
    }
  }
}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  ll n;
  cin>>n;

  int made;
  int nozo;
  rep(i,5000) {
    if(i*(i+1)/2<n && n<=(i+1)*(i+2)/2) {
      made=i+1;
      nozo=(i+1)*(i+2)/2-n;
      break;
    }
  }

  repo(i,made+1){
    if(i!=nozo) cout << i << endl;
  }

}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main()
{
    int m,n,i,j,s,max;
    char a[101][11],b[101][11],temp;
    scanf("%d",&n);
    scanf("%c",&temp);

    for(i=0;i<n;i++)
    {
        j=-1;
        do
        {
            j++;
            scanf("%s",&a[i]);
                scanf("%c",&temp);

        }while(a[i][j]=='\0');
    }
    scanf("%d",&m);
    getchar();
    for(i=0;i<m;i++)
    {
        j=-1;
        do
        {
            j++;
            scanf("%s",&b[i]);
                scanf("%c",&temp);

        }while(b[i][j]=='\0');
    }
    max=0;
    for(i=0;i<n;i++)
    {
        s=0;
        for(j=0;j<n;j++)
        {
            if(strcmp(a[i],a[j])==0)
                s++;
        }
        for(j=0;j<m;j++)
        {
            if(strcmp(a[i],b[j])==0)
                s--;
        }
        if(s>=max)
            max=s;
    }
    printf("%d\n",max);
    return 0;
}


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

int ans(int a,int b,int c){
	if(a+b<30||a==-1||b==-1){
		cout<<"F"<<endl;
	}
	else if(a+b>=80){
		cout<<"A"<<endl;
	}
	else if(a+b>=65){
		cout<<"B"<<endl;
	}
	else if(a+b>=50||c>=50){
		cout<<"C"<<endl;
	}
	else if(a+b>=30){
		cout<<"D"<<endl;
	}
	return 0;
}

int main(){
	while(1){
		int m,f,r;
		cin>>m>>f>>r;
		if(m==-1&&f==-1&&r==-1)break;
		ans(m,f,r);
	}
	return 0;
}

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

#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i,a) for (auto i = rbegin(a); i != rend(a); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
using namespace std;
using ll = long long;
using ld = long double;
template<class T> using priority_queuel = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-10;
ll mod = static_cast<ll>(1e9 + 7);
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr void mins(T& a, Args... args) { a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr void maxs(T& a, Args... args) { a = max<T>({ a,args... }); }
template<class A, int N, class T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

int n;
string s;
int cnt[8005][3];
void solve() {
    cin >> n;
    cin >> s;
    s = ' ' + s;
    reps(i, n) {
        if (s[i] == 'R') ++cnt[i][0];
        else if (s[i] == 'G') ++cnt[i][1];
        else ++cnt[i][2];
    }
    rep(i, 8003) rep(j, 3) cnt[i + 1][j] += cnt[i][j];

    ll ans = 0;
    reps(i, n) loops(j, i + 1, n) {
        if (s[i] == s[j]) continue;
        int now = 0;
        if (s[i] == 'R' && s[j] == 'G' || s[i] == 'G' && s[j] == 'R')
            now = 2;
        else if (s[i] == 'R' && s[j] == 'B' || s[i] == 'B' && s[j] == 'R')
            now = 1;
        else now = 0;
        ans += cnt[j + j - i - 1][now] - cnt[j][now] + cnt[n][now] - cnt[j + j - i][now];
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3744
#include <stdio.h>

int main(void)
{
	long long a,b;
	scanf("%lld%lld", &a,&b);

	if(a == 1||b == 1)
		printf("1");

	else if(b % 2)
		printf("%lld", ((a+1)/2+a/2) * (b/2) + (a+1)/2);
	else
		printf("%lld", ((a+1)/2+a/2) * (b/2));
	return 0;
}

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

int main(){
  int n,t,e;
  cin >> n >> t >> e;
  int res = -1;
  for(int i=0;i<n;i++){
    int x, k = 1; cin >> x;
    while(k*x<=t+e){
      if(t-e <= k*x && k*x <= t+e){
	res = i+1;
      }
      k++;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

int main() {
	int n;
	cin >> n;
	vector<int> l(n);
	rep(i, 0, n) cin >> l[i];

	SORT(l);
	int max = l[n - 1];
	int sum = 0;
	rep(i, 0, n - 1) {
		sum += l[i];
	}

	if (max < sum) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

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

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

    //cout << fixed << setprecision(15);

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


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int H1,H2,M1,M2,k;
int main(){
	H1=read(),M1=read(),H2=read(),M2=read(),k=read();
	int p=(H2-H1)*60+(M2-M1);
	printf("%d\n",max(0,p-k));
	return 0;
}



Measured memory_bytes: 3704
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
	vector <string> s;
	s.push_back("Sunny");
	s.push_back("Cloudy");
	s.push_back("Rainy");
	string a;
	cin >> a;
	for (int i = 0;i < 3;++i)
	{
		if (s[i] == a)
		{
			int p = (i + 1) % 3;
			cout << s[p] << "\n";
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 888
#include<stdio.h>
#include<math.h>

int main(){
    int n,i,j,cnt=0,check,num;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&num);
        if(num%2==0 && num!=2)continue;
        check=0;
        for(j=2;j<=sqrt(num);j++){
            if(num%j==0)check++;
        }
        if(check==0)cnt++;
    }
printf("%d\n",cnt);
    return 0;
}



Measured memory_bytes: 2084
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,k = readInts()
    # n = 0,1,2,3,4
    # k以上、選ぶ数をaとすると、最小の和の数と、最大の和の数っていうのが分かる
    # その選びかたは、k = 2 だとすると、
    # 最小の和の数は、0+1 = 1 (2番目まで)
    # 最大の和の数は、4+3 = 7 (n+1番目からn番目まで)
    # ということは、1,2,3,4,5,6,7の7通りあるので、
    # 7 - 1 + 1 = 7 という風に出すことが出来る
    # という感じで、各kに対してfor文を回してあげればいい
    # 和の数は、初項 + 末尾 ) * 項数 // 2 で求めれる
    def calc(a):
        sml = (0 + a-1) * a // 2
        lar = sml + a * (n-a+1)
        return lar - sml + 1
    ans = 0
    for i in range(k,n+2):
        ans += calc(i)%mod
    print(ans%mod)
if __name__ == '__main__':
  main()


Measured memory_bytes: 9076
n = int(input())
l = list(map(int,input().split()))
l.sort()

total = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        if l[i] == l[j]: continue
        w = l[i] + l[j]
        cnt = 0
        for k in range(j+1, n):
            if l[j] == l[k]: continue
            if l[k] >= w: break
            cnt += 1
        total += cnt

print(total)



Measured memory_bytes: 9052
var inputRaw = require('fs').readFileSync('/dev/stdin', 'utf8')
var rows = inputRaw.trim().split('\n');
var N = Number(rows[0]);
var list = rows.slice(1).map(r => r.split(' ').map(Number));
var dp = Array.from({ length: N }, _ => Array(3).fill(0));

function solve() {
  dp[0] = [list[0][0], list[0][1], list[0][2]];

  for (var i = 1; i < N; i++) {
    dp[i] = [list[i][0], list[i][1], list[i][2]];
    dp[i][0] = Math.max(dp[i - 1][1], dp[i - 1][2]) + list[i][0];
    dp[i][1] = Math.max(dp[i - 1][0], dp[i - 1][2]) + list[i][1];
    dp[i][2] = Math.max(dp[i - 1][0], dp[i - 1][1]) + list[i][2];
  }
  return Math.max.apply(null, dp[N - 1]);
}

console.log(solve());


Measured memory_bytes: 57392
#include<cstdio>
using namespace std;
typedef long long ll;

ll a[100000];
int main(void){
  int n, q;
  scanf("%d%d", &n, &q);
  for(int i = 0;i < n;++i)scanf("%lld", &a[i]);
  for(;q--;){
    int l = 0, r = 0;
    ll sum = 0, res = 0, s;
    scanf("%lld", &s);
    for(;l < n;){
      if(l == r)sum = a[r++];
      else{
        if(sum > s)sum -= a[l++];
        else if(r < n)sum += a[r++];
        else break;
      }
      if(sum <= s)res += r - l;
    }
    printf("%lld\n", res);
  }

  return 0;
}

Measured memory_bytes: 3472
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <stdlib.h>
#include <math.h>
#include <string.h>
//MJC *start on @date: 2020-09-13 20:13 
using namespace std;
typedef long long ll;

struct node
{
    int c;  //价格
    int a[15];  //提升的等级
}book[15];   //每本书

int b[15];  //提升某个算法的总等级数

int main()
{
    int n,m,x;
    cin>>n>>m>>x;
    for (int  i=0; i < n; i++)
    {
        cin>>book[i].c;
        for (int  j = 0; j<m; j++)
            cin>>book[i].a[j];  
    }
    int ans=2e9;
    for (int  i = 0;i<(1<<n); i++)
    {
        memset(b,0,sizeof b);
        int sum=0;
        for(int j=0;j < n;j++)
            if(i>>j&1){
                sum+=book[j].c;
                for(int k=0; k < m; k++) 
                    b[k]+=book[j].a[k];
            }
        bool flag=1;
        for (int  j = 0; j < m; j++)
            if(b[j] < x)
                flag=0;
        if(flag) 
            ans=min(ans,sum);
    }
    if(ans==2e9) 
        cout<<"-1";
    else
        cout<<ans;
    return 0;
}

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

using namespace std;

using ll = long long;

const long long MOD = 1e9 + 7;
const int INF = 1e9 + 7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    int l = (n + 1) / 2;
    int p = n - 1;
    for (int i = 0; i < l; ++i) {
        if (i > 0) cout << " ";
        cout << a[p];
        p -= 2;
    }
    int r = n / 2;
    p = n % 2;
    for (int i = 0; i < r; ++i) {
        cout << " ";
        cout << a[p];
        p += 2;
    }
    cout << endl;
}

Measured memory_bytes: 3072
import numpy as np
n =  list(map(int,input().split(' ')))

#print(n)
#ans =np.array([])
ans = []
for p in range(1,n[0]+1):
    c = 0
    while p < n[1]:
        p *= 2
        c+=1
#    print(c+1)
    ans.append((1/n[0])*(1/2)**(c+1))
#    np.append(ans,((1/n[0])*(1/2)**(c+1)))
#print(ans)   
print(sum(ans)*2)

Measured memory_bytes: 15540
import java.util.Scanner;

public class Main{
	static Scanner s = new Scanner(System.in);			//文字の入力

	static int A = s.nextInt();
	static int B = s.nextInt();

		
static int sum =0;

	public static void main(String[] args){
		solve();
	}

	static void solve() {
		int C = A*B;
		if(C%2 == 1){
			System.out.println("Odd");
			
		}else{
			System.out.println("Even");
		}

		


	}





}

Measured memory_bytes: 21588
def slove():
    import sys
    import fractions
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    gcd = fractions.gcd(a, b)
    cnt = 1
    for i in range(2, int(gcd ** 0.5) + 1):
        if gcd % i == 0:
            cnt += 1
            while True:
                if gcd % i == 0:
                    gcd //= i
                else:
                    break
    cnt += 0 if gcd == 1 else 1
    print(cnt)


if __name__ == '__main__':
    slove()


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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int MOD = 1e9+7;
const long long INF = 1LL << 60;
const int INF_INT = 1e9;
typedef long long ll;

int main(){
    ll l,r;
    cin >> l >> r;
    r = min(r, l+4038);
    int ans = 2018;
    for(ll i = l; i <= r; i++) {
        for(ll j = i+1; j <= r; j++) {
            int hoge = i*j%2019;
            ans = min(ans, hoge);
        }
    }
    cout << ans << endl;
}

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

int main() {
  string s;cin>>s;
  cout<<s.substr(0,4)<<" "<<s.substr(4)<<endl;
}

Measured memory_bytes: 3448
#include <bits/stdc++.h>
#define rep(i, x, N) for (long long i = x; i < (N); i++)
using namespace std;

int main()
{
    long N, K;
    cin >> N >> K;
    vector<long> p(N);
    rep(i, 0, N)
    {
        cin >> p[i];
    }
    int l, r;
    long sum;
    sum = 0;
    rep(i, 0, K)
    {
        sum += p[i];
    }
    l = 0;
    r = K;
    long ans = sum;
    while (r < N)
    {
        sum = sum - p[l] + p[r];
        ans = max(ans, sum);
        r++;
        l++;
    }
    double anser;
    anser = (ans + K) * 0.5;
    printf("%.7f\n", anser);
}


Measured memory_bytes: 1792
x,y=0,0
s=input()

a=s.count("N")>0
b=s.count("S")>0
c=s.count("E")>0
d=s.count("W")>0
e=(a,b,c,d)
if e==(True,True,False,False) or e==(False,False,True,True) or e==(True,True,True,True):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
N,K = map(int,input().split())
S = list(str(input()))
if S[K-1] == 'A':
  S[K-1] = 'a'
elif S[K-1] == 'B':
  S[K-1] = 'b'
else:
  S[K-1] = 'c'
print(''.join(S))

Measured memory_bytes: 3060
#include<functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
int const M = 1000000007;
int R, C;
vector<string> g;
int dp[1001][1001];
int calc(int r, int c) {
	if (r == R || c == C || g[r][c] == '#')
		return 0;
	if (r == R - 1 && c == C - 1)
		return 1;
	int &ret = dp[r][c];
	if (ret != -1)
		return  ret;
	ret = (calc(r + 1, c) + calc(r, c + 1)) % M;
	return ret;
}
int main() {
	//freopen("src.txt", "r", stdin);
	memset(dp, -1, sizeof dp);
	cin >> R >> C;
	g.resize(R);
	for (int i = 0; i < R; ++i)
		cin >> g[i];
	cout << calc(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 5248
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string S;
    cin >> S;
    bool white = false;
    int result = 0;
    string a = "";
    a = S[0];
    if(a=="W"){
        white = true;
    }
    for (int i = 1; i < S.size(); ++i)
    {
        a = S[i];
        if((white && a=="B")||(!white && a=="W")){
            result++;
            white = !white;
        }
    }
    
    cout << result << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	int n, a, b;
	scanf("%d %d %d%*c", &n, &a, &b);
	int sum = 0, t;
	for(int i=1;i<=n;i++) {
		int s = 0;
		t = i;
		for(int b=10000;b>0;b/=10) {
			s += t/b;
			t %= b;
		}
		if(s >= a && s <= b) sum += i;
	}
	printf("%d", sum);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
//#define int long long int
using namespace std;


int main(){
    int a; string s;
    cin>>a>>s;
    if(a >= 3200) cout<<s<<endl;
    else cout<<"red"<<endl;
    
    return 0 ;
}

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

int n,a;
int main()
{
	int i,cnt=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a);
		if((i&1)&&(a&1)) cnt++;
	}
	printf("%d",cnt);
	return 0;
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1000000007;
const long long INF = 1LL << 55;
const double EPS = 1e-10;

int main()
{
    int A, B, C;
    cin >> A >> B >> C;

    if ((A + B + C) >= 22)
    {
        cout << "bust" << endl;
    }
    else
    {
        cout << "win" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n;
  cin >> n;
  cout << n * n * n;

	
}

Measured memory_bytes: 256
mod = int(1e9+7)
def add(a, b):
    c = a + b
    if c >= mod:
        c -= mod
    return c

def main():
    n = int(raw_input())
    
    arr = map(int,raw_input().split())
    
    ans = 0
    
    max_ele = max(arr)
    
    arr.sort()
    
    marked = [False] * (max_ele+5)
    
    for i in range(n):
        diff_prev = i-1 < 0 or arr[i] != arr[i-1]
        diff_next = i+1 >= n or arr[i] != arr[i+1]
        num = arr[i]
        if not marked[num]:
            cur = num 
            if diff_next and diff_prev:
                ans += 1
            while cur <= max_ele:
                marked[cur] = True
                cur += num
    
    print(ans)
    

main()

Measured memory_bytes: 100216
#include<stdio.h>

int main(void){
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	do{
		a-=d;
		c-=b;
	}while(a>0&&c>0);
	if(c<=0){
		printf("Yes");
	}else{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 1704
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;


struct RollingHash {
  using ui64 = uint64_t;
  using ui128 = __uint128_t;
  static const ui64 mod = (1ull<<61) - 1;
  vector<ui64> hash, power;
  ui64 base;

  static inline ui64 add(ui64 a, ui64 b) { if ((a += b) >= mod) a -= mod; return a; }
  static inline ui64 mul(ui64 a, ui64 b) { ui128 c = ui128(a)*b; return add(c>>61, c&mod); }
  static inline ui64 generate_base() {
    mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<ui64> rand(2, mod-2);
    return rand(mt);
  }

  template<typename T>
  RollingHash(const T &s) {
    base = generate_base();
    int n = s.size();
    hash.assign(n+1, 0);
    power.assign(n+1, 1);
    rep(i, n) {
      power[i+1] = mul(power[i], base);
      hash[i+1] = add(mul(hash[i], base), s[i]);
    }
  }

  ui64 query(int l, int r) const { return add(hash[r], mod - mul(hash[l], power[r-l])); }
  ui64 combine(ui64 h1, ui64 h2, size_t h2len) const { return add(mul(h1, power[h2len]), h2); }

  int lcp(int l1, int r1, int l2, int r2) const {
    int len = min(r1-l1, r2-l2);
    int ok = 0, ng = len+1;
    while (ng-ok > 1) {
      int md = (ok+ng)>>1;
      if (query(l1, l1+md) == query(l2, l2+md)) ok = md;
      else ng = md;
    }
    return ok;
  }
};


int main() {
    int n; cin >> n;
    string s; cin >> s;
    RollingHash rh(s);

    int ans = 0;
    rep(i, n) rep2(j, i+1, n) {
      int lcp = rh.lcp(i, j, j, n);
      ans = max(ans, lcp);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3676
#include <iostream>
#include <cmath>
using namespace std;
const long long MAXN = 2e5+5;
int main()
{
	long long n,relsum = 0;
	cin >> n;
	long long sl[MAXN];
	for (int i = 0; i < n; i++)
	{
		cin >> sl[i];
	}
	for (int i = 0; i < n; i++)
	{
		relsum += sl[i];
	}
	//cout << relsum;
	long long sumx[n] = {0};
	long long sumy[n] = {0};
	for (int i = 1; i <= n - 1;i++)
	{
		sumx[i] += sumx[i - 1] + sl[i - 1];
		sumy[i] = relsum - sumx[i];
	}

	/*
	for (int i = 1; i < n - 1;i++)
	{
		cout << sumx[i] << "xxx" << sumy[i] << endl;
	}
	*/
	
	long long cha[n - 1] = {0};
	for (int i = 1; i <= n - 1;i++)
	{
		cha[i] = abs((sumx[i])- (sumy[i]));
		
	}
	/*
	for (int i = 1; i < n - 1;i++)
	{
		cout << cha[i] << endl;
	}*/
	
	long long min = cha[1]; 
	for (int i = 1; i <= n - 1;i++)
	{
		if (cha[i] < min)
		min = cha[i];
	}
	cout << min;
} 


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

const ll MX = 1e18;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  bool ng = false;
  rep(i,n) {
    ll a;
    cin >> a;
    if (a == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (ng || __int128(ans)*a > MX) {
      ng = true;
    }
    ans *= a;
  }
  if (ng) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<cstring>
using namespace std;
#define ll long long int
 
int N,K;
int h[100005];
 
int dp[100005];
 
int main(){
    cin>>N>>K;
    for(int i=0;i<N;++i)cin>>h[i];
    for(int i=0;i<N;++i)dp[i]=999999999;
    dp[0]=0;
    for(int i=0;i<N;++i){
        for(int j=1;j<=K;++j){
            dp[i+j]=min(dp[i]+abs(h[i+j]-h[i]),dp[i+j]);
        }
    }
    cout<<dp[N-1]<<endl;
}

Measured memory_bytes: 1024
N=int(input())

h=list(map(int,input().split()))

def forwardpropagation(forwardlist):
  temp=forwardlist[0]
  calc=0
  for i in range(len(forwardlist)-1):
    calc=temp
    if temp>forwardlist[i+1]:
      temp=forwardlist[i+1]
    forwardlist[i+1]=max(0,forwardlist[i+1]-calc)
  return forwardlist

def backwardpropagation(backwardlist):
  templist=forwardpropagation(backwardlist[::-1])
  backwardlist=templist[::-1]
  return backwardlist

answer=0
count=0
while(True):
  if max(h)==0:
    print(answer)
    exit()
  maxindex=h.index(max(h))
  answer+=h[maxindex]
  h[maxindex:]=forwardpropagation(h[maxindex:])
  h[:maxindex+1]=backwardpropagation(h[:maxindex+1])
  h[maxindex]=0

Measured memory_bytes: 3064
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,(n)-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, int n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n in O(log(n)) time

const int MOD = 1000000007; //10^9+7
const double PI = 3.1415926535897932384626;

/*********** variables ************/
int N, A;
int x[60];
lng po[3010];
lng ne[3010];
/**********************************/


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>N>>A;
    REP(i, N) cin >> x[i];
    REP(i, N) x[i] -= A;

    ne[0] = 1;
    REP(i, N) {
        lng *a = po;
        lng *b = ne;
        if(x[i]<=0) {
            a = ne; b = po;
        }
        DOWN(k, 3000, 1) {
            if(a[k] > 0) {
                int y = x[i] + (x[i]>0 ? k : -k);
                if(y>0) po[y]+= a[k];
                else ne[-y] += a[k];
            }
        }
        if(x[i]>0) po[x[i]] += ne[0];
        else ne[-x[i]] += ne[0];
        UP(k, 1, 3000) {
            if(b[k] > 0) {
                int y = x[i] + (x[i]>0 ? -k : k);
                if(y>0) po[y] += b[k];
                else ne[-y] += b[k];
            }
        }
        // cout <<ne[2]<<" " << ne[1] << " "<<ne[0]<<" "<<po[1]<<" "<<po[2]<<endl;
    }

    cout << ne[0]-1 << endl;
}


Measured memory_bytes: 256
def insertionSort(a, n, g)
  g.upto(n-1) do |i|
    v = a[i]
    j = i - g
    while 0 <= j && v < a[j]
      a[j+g] = a[j]
      j = j - g
      @cnt += 1
    end
    a[j+g] = v
  end
end

def shellSort(a, n)
  h = 1
  while h < n / 3
    h = 3 * h + 1
    @g.unshift(h)
  end
  @m = @g.size

  0.upto(@m-1) do |i|
    insertionSort(a, n, @g[i])
  end
end

@cnt = 0
@m = 0
@g = [1]

a = []
(n = gets.to_i).times do
  a << gets.to_i
end

shellSort(a, n)

puts @m
puts @g * ' '
puts @cnt
puts a * "\n"

Measured memory_bytes: 24112
#include<stdio.h>
#define NIL -1
int parent[100001],cleft[100001],right[100001];
int depth(int i){
    int d=0;
    while(parent[i]!=NIL){
        d++;
        i=parent[i];
    }
    return d;
}
void printchildren(int i){
    int c=cleft[i];
    while(c!=NIL && right[c]!=NIL){
        printf("%d, ",c);
        c=right[c];
    }
    if(cleft[i]!=NIL)printf("%d",c);
}

int main(){
    int n;scanf("%d",&n);
    int i;
    for(i=0;i<=n-1;i++)parent[i]=cleft[i]=right[i]=NIL;
    for(i=0;i<=n-1;i++){
        int id,k;
        scanf("%d %d",&id,&k);
        int c[k+1],j;
        for(j=1;j<=k;j++)scanf("%d",&c[j]);
        if(k>=1){
            parent[c[1]]=id;
            cleft[id]=c[1];
        }
        for(j=2;j<=k;j++){
            parent[c[j]]=id;
            right[c[j-1]]=c[j];
        }
    }
    
    
    for(i=0;i<=n-1;i++){
        printf("node %d: parent = %d, depth = %d, ",i,parent[i],depth(i));
        if(parent[i]==NIL) printf("root, [");
        else if(cleft[i]==NIL) printf("leaf, [");
        else printf("internal node, [");
        printchildren(i);
        printf("]\n");
        
    }
    
    return 0;
}

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

#define int long long
#define pb push_back
#define ld long double

using namespace std;

const int MAXN = 1048576 , MOD = 1e9 + 7 ;

vector<int> adj[MAXN] ; 

int dp[MAXN] ; 

void dfs(int u , int p)
{
    for(auto v : adj[u])
    {
        if(v==p) continue ; 
        dfs(v,u) ; 
        dp[u] ^= dp[v] + 1 ; 
    }       
}

int32_t main() 
{
    ios::sync_with_stdio(0); 
    int n ;
    cin >> n ; 
    for(int i = 1 ; i < n ; i ++ )
    {
        int x ,  y ; 
        cin >> x >> y ;
        adj[x].push_back(y) ; 
        adj[y].push_back(x) ; 
    }
    dfs(1,-1) ; 
    cout << (dp[1]?"Alice":"Bob") << endl ; 
}

Measured memory_bytes: 33408
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
const int INF = 10000000;
typedef long long ll;
typedef vector<vector<int>> Matrix;
Matrix dist; // グラフの距離を格納した2次元配列（隣接行列）
          // d[u][v]は辺e=(u,v)のコスト（辺が存在しない場合はINF、ただしd[i][i]=0）

void warshall_floyd(int n) { // nは頂点数
  for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++)  // 終端
        dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
}

int main() {
  int n, m;
  cin >> n >> m;
  dist = Matrix(n, vector<int>(n, INF));
  vector<int> a(m), b(m), c(m);
  for (int i = 0; i < n; i++) dist[i][i] = 0;
  for (int i = 0; i < m; i++){
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--;
    dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
    dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
  }
  warshall_floyd(n);
  int ans = m;
  for (int i = 0; i < m; i++){
    bool shortest = false;
    for (int j = 0; j < n; j++){
      if(dist[j][b[i]] == dist[j][a[i]] + c[i]) shortest = true;
    }
    if(shortest)ans--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<list>
#include<algorithm>
using namespace std;

int main(void){
    int i, q, x;
    char com[20];
    list<int> v;
    scanf("%d", &q);
    for(i=0;i<q;i++){
        scanf("%s", com);
        if(com[0]=='i'){
            scanf("%d", &x);
            v.push_front(x);
        }
        else if(com[6]=='L'){
            v.pop_back();
        }
        else if(com[6]=='F'){
            v.pop_front();
        }
        else if(com[0]=='d'){
            scanf("%d", &x);
            for(list<int>::iterator itr=v.begin(); itr!=v.end(); itr++){
                if(*itr==x){
                    v.erase(itr);
                    break;
                }
            }
        }
    }
    //out put
    i=0;
    for(list<int>::iterator itr=v.begin(); itr!=v.end(); itr++){
        if(i++) printf(" "); 
        printf("%d", *itr);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 33912
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    ll k;
    cin >> k;
    ll r = 0, x = 7;
    REP(i,2 * k){
        r = (r + x) % k;
        if (r == 0){
            cout << i + 1 << endl;
            return 0;
        }
        x = (10 * x) % k;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int a[10][10];
void Get(int n){
	int u=n%10;
	int x=n;
	while(x>=10) x/=10;
	a[u][x]++;
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	for(int i=1; i<=n; i++){
		Get(i);
	}
	long long res=0;
	for(int i=1; i<=9; i++){
		for(int j=1; j<=9; j++){
			res+=a[i][j]*a[j][i];
		}
	}
	cout << res;
}

Measured memory_bytes: 256
#  --*-coding:utf-8-*--

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    lastIdx = -1
    sc = 0

    for a in A:
        sc += B[a-1]
        if a == lastIdx + 1:
            sc += C[lastIdx-1]

        lastIdx = a

    print(sc)


if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 510000;
ll const MOD = 1000000007;

int main() {
    ll N, T, A;
    cin >> N >> T >> A;

    vector<pair<double, ll>> H(N);
    rep(i, N) {
        double tmp;
        cin >> tmp;
        H[i] = make_pair(tmp, i);
    }

    rep(i, N) { H[i].first = abs(A - (T - H[i].first * 0.006)); }
    sort(H.begin(), H.end());
    cout << H[0].second + 1 << endl;

    // rep(i, N) { cout << H[i].second << ": " << H[i].first << endl; }

    return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  size_t N; cin >> N;
  vector<int> D(N);
  for(auto& i : D) cin >> i;

  ll res{};
  for (size_t i = 0; i < N; ++i) {
    for (size_t k = i + 1; k < N; ++k) {
      res += D[i] * D[k];      
    }
  }

  cout << res << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 384
from collections import deque


def bfs(s_i, s_j):
    q = deque([(s_i, s_j)])
    dists = {(s_i, s_j): 0}
    max_dist = 0
    while q:
        i, j = q.popleft()
        for di, dj in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            ni = i + di
            nj = j + dj
            if 0 <= ni < H and 0 <= nj < W and field[ni][nj] == '.' and (ni, nj) not in dists:
                dists[(ni, nj)] = dists[(i, j)] + 1
                max_dist = max(max_dist, dists[(ni, nj)])
                q.append((ni, nj))
    return max_dist


H, W = map(int, input().split())
field = [input() for _ in range(H)]
ans = 0
for i in range(H):
    for j in range(W):
        if field[i][j] == '#':
            continue
        ans = max(ans, bfs(i, j))
print(ans)

Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}


int main(void) {
    int i,j;
    int n, l;
    while(cin >> n >> l,n){
        int v[105][2][2] = {};//ind,d(L:1,R:0)
        rep(i,n){
            string d;
            int p;
            cin >> d >> p;
            v[p][0][0] = i+1;
            v[p][0][1] = (d=="L");
        }
        rep(t,l+1){
            int u[105][2][2] = {};
            int left = v[1][0][0]?v[1][0][0]:v[l-1][0][0];//左から出る蟻のindex
            rep(i,l)rep(j,2)if(v[i][j][0]){
                if(v[i][j][1]){//左に移動
                    if(i==1)continue;
                    if(u[i-1][0][0] == 0){
                        u[i-1][0][0] = v[i][j][0];
                        u[i-1][0][1] = v[i][j][1];
                    }else{
                        u[i-1][1][0] = v[i][j][0];
                        u[i-1][1][1] = v[i][j][1];
                    }
                }else{//右に移動
                    if(i == l-1)continue;
                    if(u[i+1][0][0] == 0){
                        u[i+1][0][0] = v[i][j][0];
                        u[i+1][0][1] = v[i][j][1];
                    }else{
                        u[i+1][1][0] = v[i][j][0];
                        u[i+1][1][1] = v[i][j][1];
                    }
                }
            }
            rep(i,l)if(u[i][0][0] && u[i][1][0]){
                swap(u[i][0][1],u[i][1][1]);
            }
            int cnt = 0;
            rep(i,l+1)rep(j,2){
                if(u[i][j][0]) cnt++;
                rep(k,2){
                    v[i][j][k] = u[i][j][k];
                }
            }
            if(cnt == 0){
                cout << t+1 << " " << left << endl;
                break;
            }
        }
    }
}



Measured memory_bytes: 3128
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() { 
    int n;cin >> n;
    string s;cin >> s;
    if(n%2==1) {
        cout << "No\n";
        return 0;
    }
    rep(i, n/2)  {
        if(s[i]!=s[i+n/2]) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 3600