akhauriyash/Code-Regression huggingface dataset:
def main():
    mod=998244353
    n,s=map(int,input().split())
    A=list(map(int,input().split()))
    DP=[[0]*(s+1) for _ in range(n+1)]
    p=1
    for i in range(n+1):
        DP[i][0]=p
        p*=2
        p%=mod
    for i,a in enumerate(A):
        for j in range(1,s+1):
            DP[i+1][j]=DP[i][j]*2
            if j>=a:
                DP[i+1][j]+=DP[i][j-a]
            DP[i+1][j]%=mod
    print(DP[-1][-1])
    #print(DP)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 132528
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
ll factorial(ll x){
  if(x==0)return 1;
  return x*factorial(x-1)%MOD;
}
int main(){
  ll h,w;cin>>h>>w;
  vector<string>c(h);
  rep(i,h)cin>>c[i];
  rep(i,h){
    cout<<c[i]<<endl;
    cout<<c[i]<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
int main(){
     int n;
    cin >> n;
    vector<int> fl(n);
    for (int i = 0; i < n; i++)
        cin >> fl[i];
        int sum = 0;
        for(int i = 1; i < n; i++){
            if(fl[i] - fl[i - 1] < 0)
            sum += abs(fl[i] - fl[i - 1]);
        }
    sum += fl[n -1];
    cout << sum << endl;
    return 0 ;
}

Measured memory_bytes: 256
using System;

namespace GreedyTakahashi
{
    class Program
    {
        static void Main(string[] args)
        {

            var input = Console.ReadLine();
            var A = long.Parse(input.Split(' ')[0]);
            var B = long.Parse(input.Split(' ')[1]);
            var K = long.Parse(input.Split(' ')[2]);

            if(A == 0 && B == 0)
            {
                Console.WriteLine("0 0");
                return;
            }

            var takahasi = A - K;
            if(takahasi >= 0)
            {
                Console.WriteLine(takahasi + " " + B);
            }
            else
            {
                var aoki = B + takahasi;
                if (aoki < 0) aoki = 0;
                Console.WriteLine("0 " + aoki);

            }
        }
    }
}


Measured memory_bytes: 13140
#include <vector>
#include <iostream>
using namespace std;
typedef long long ll;

#define fastio  ios::sync_with_stdio(false); cin.tie(0);

class BeingZero{
    public:
        ll minCost(vector<int> a, int k){
            ll n = a.size();
            int dp[n];
            dp[0] = 0;
            dp[1] = abs(a[1]-a[0]);
            for(int i=2;i<n;i++){
                dp[i] = INT_MAX;
                for(int j=1;i-j>=0 && j<=k;j++)
                    dp[i] = min( dp[i], abs(a[i]-a[i-j]) + dp[i-j]);
            }
            return dp[n-1];
        }
};

int main() {
    fastio;
    BeingZero bz;
    int n, k;
    while(cin>>n>>k){
        if(n==-1) break;
        vector<int> v(n);
        for(int i=0;i<n;i++)
            cin>>v[i];
        cout<<bz.minCost(v, k)<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3884
#include <iostream>
#include <queue>
#include <string>
#include <set>

using namespace std;

typedef pair<int,int> P;

vector<vector<int> > dist;

int dh[] = {1, 0, -1, 0};
int dw[] = {0, 1, 0, -1};

vector<P> bfs(int h, int w, string *s, int sh, int sw, int k) {
    dist[sh][sw] = k;
    queue<P> que;
    que.push(P(sh, sw));
    vector<P> v;
    v.push_back(P(sh, sw));

    while (!que.empty()) {
        P p = que.front();
        que.pop();

        int h_ = p.first, w_ = p.second;
        for (int i = 0; i < 4; i++) {
            int nh = h_ + dh[i], nw = w_ + dw[i];

            if (nh < 0 || h <= nh || nw < 0 || w <= nw || s[nh][nw] == '#' || dist[nh][nw] != -1)
                continue;

            dist[nh][nw] = k;
            que.push(P(nh, nw));
            v.push_back(P(nh, nw));
        }
    }
    return v;
}

int main() {
    int h, w;   cin >> h >> w;
    dist.resize(h, vector<int>(w, -1));
    int ch, cw, dh, dw; cin >> ch >> cw >> dh >> dw;
    ch--, cw--, dh--, dw--;
    string *s = new string[h];
    for (int i = 0; i < h; i++)
        cin >> s[i];

    set<P> se;
    vector<P> v;
    v = bfs(h, w, s, ch, cw, 0);
    for (int i = 0; i < v.size(); i++)
        se.insert(v[i]);
    if (se.find(P(dh, dw)) != se.end()) {
        cout << 0 << endl;
        return 0;
    }
    int k = 1;

    bool flag;
    do {
        flag = false;
        set<P> se_;
        for (auto ite = se.begin(); ite != se.end(); ite++) {
            int sh = (*ite).first, sw = (*ite).second;
            for (int a = -2; a < 3; a++) {
                for (int b = -2; b < 3; b++) {
                    int nh = sh + a, nw = sw + b;

                    if (nh < 0 || h <= nh || nw < 0 || w <= nw || s[nh][nw] == '#' || dist[nh][nw] != -1)
                        continue;
                    flag = true;
                    v = bfs(h, w, s, nh, nw, k);
                    for (int i = 0; i < v.size(); i++)
                        se_.insert(v[i]);
                }
            }
        }
        if (se_.find(P(dh, dw)) != se_.end()) {
            cout << k << endl;
            return 0;
        }

        swap(se, se_);
        k++;
    } while (flag);

    cout << -1 << endl;

    return 0;
}

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

int main(void){
    
    int a, b, k;
    int c=101;
    int ans = 3;
    
    scanf("%d %d %d", &a ,&b, &k);
    
    for(int i=100; i>0; i--){
        c--;
        if(b%c==0 && a%c==0){
            ans = c;
            k--;
            if(k==0) break;
        }
    }
    
    printf("%d", ans);
}


Measured memory_bytes: 128
#include <string.h>
#include <stdio.h>
typedef long long ll;
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main()
{  int a,b,ans,cnt=0;
   char s[1001],t[1001];
   scanf("%s", s);
   scanf("%s", t);


   a=strlen(s);
   b=strlen(t);
ans=b;
   rep(i,a-b+1){
      cnt=0;
      rep(j,b){
         if (s[i+j]!=t[j])
         {
            cnt++;
         }

      }
      if (ans>cnt)
      {
         ans=cnt;
      }


   }
   printf("%d\n", ans);

   return 0;
}

Measured memory_bytes: 1728
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

__attribute__((noinline))
uint32_t gcd(uint32_t a, uint32_t b){
	if(a==0 || b==0) return a==0?b:a;
	int ans;
	__asm__ (
		"movl %1, %%ecx;"
		"movl %2, %%eax;"
		"movl $0, %%edx;"
		"divl %%ecx;"
		"cmpl $0, %%edx;"
		"jz asm_gcd2_in2;"
		"asm_gcd2_in1:"
		"movl %%ecx, %%eax;"
		"movl %%edx, %%ecx;"
		"movl $0, %%edx;"
		"divl %%ecx;"
		"cmpl $0, %%edx;"
		"jnz asm_gcd2_in1;"
		"asm_gcd2_in2:"
		"movl %%ecx, %0;"
		:"=r"(ans)
		:"r"(a),"r"(b)
		:"%eax", "%ecx", "%edx", "cc"
	);
	return ans;
}

int main(void){
	int n, i;
	int a[100001];
	int l[100002], r[100002];
	scanf("%d", &n);
	for(i=1; i<=n; i++){
		scanf("%d", a+i);
	}
	l[0]=0;
	for(i=1; i<=n; i++){
		l[i] = gcd(l[i-1], a[i]);
	}
	r[n+1]=0;
	for(i=n; i>0; i--){
		r[i] = gcd(r[i+1], a[i]);
	}
	int max=0;
	for(i=1; i<=n; i++){
		int now=gcd(l[i-1], r[i+1]);
		if(now>max) max=now;
	}
	printf("%d\n", max);
}


Measured memory_bytes: 1280
import sys

n = int(input())
s_list = [int(input()) for _ in range(n)]

s_list.sort()

num_sum = sum(s_list)

if num_sum % 10 == 0:
    for num in s_list:
        if num % 10 != 0:
            print(num_sum-num)
            sys.exit()
else:
    print(num_sum)
    sys.exit()

print(0)

Measured memory_bytes: 3060
double M,M0,M1,a[20][3];
n,i,j,k,v[20];
D(depth,m,c){
	if(m==0){
		for(M0=i=0;i<depth-1;i++)for(j=i+1;j<depth;j++)for(k=0;k<3;k++)M0+=(M1=a[v[i]][k]-a[v[j]][k])*M1;
		if(M<M0)M=M0;
	}else for(;c<=n-m;c++)v[depth]=c,D(depth+1,m-1,c+1);
}
main(m){
	scanf("%d%d",&n,&m);
	if(m<2)puts("0"),exit(0);
	for(i=0;i<n;i++)for(j=0;j<3;j++)scanf("%lf",a[i]+j);
	M=0;D(0,m,0);
	printf("%f\n",M),exit(0);
}

Measured memory_bytes: 660
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

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

int main() {
	// input
	int N, M, S, T;
	cin >> N >> M;
	vector<vector<int>> graph(N);
	rep(i, M) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		graph[u].push_back(v);
		//graph[v].push_back(u); // 有向グラフなので逆方向は記録しない
	}
	cin >> S >> T;
	S--; T--;

	vector<vector<int>> len(N, vector<int>(3, -1)); // startからの最短距離
	queue<pair<int, int>> q;
	q.push(make_pair(S, 0));
	len[S][0] = 0;
	
	while(!q.empty()) {
		pair<int, int> p = q.front();
		q.pop();

		for(int c: graph[p.first]) {
			int nl = (p.second+1)%3;
			if(len[c][nl]>=0) continue;
			len[c][nl] = len[p.first][p.second]+1;
			q.push(make_pair(c, nl));
		}
	}
	
	// cout << "len:" << endl;
	// rep(i, N) {
	// 	cout << i << ": " ;
	// 	rep(j, 3) cout << len[i][j] << ' ';
	// 	cout << endl;
	// }

	if(len[T][0]>0) cout << len[T][0]/3 << endl;
	else cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;

int  main(){
  long long  n,m,k,cnt=0;
  long long a[300000] = {0};
  long long  b[300000] = {0};

  int debug;
  cin >> n >> m >> k;
  for(long long  i = 0; i < n; i++){
    cin >> a[i];
    //a[i] = 1000000000;
    if ( i == 0 ) continue;
    if(2147483646-a[i] < a[i-1]) a[i] = 2147483646;
    else if(i!=0) a[i] += a[i-1];
  }
  //cout << "HERE" << endl;

  for(long long  i = 0; i < m; i++){
    cin >> b[i];
    //b[i] = 1000000000;
    if ( i == 0) continue;
    if(2147483646-b[i] < b[i-1]) b[i] = 2147483646;
    else if(i!=0) b[i] += b[i-1];
  }
  //cout << "HERE2" << endl;

  long long nn=n,mm=m;
  for(long long  i = 0; i < n; i++){
    if (a[i] > k) {nn = i;break;}
  }
  for(long long  i = 0; i < m; i++){
    if (b[i] > k) {mm = i;break;}
  }
  //if(mm == 0) mm = m;
  //if (nn == 0) nn = n;
  long long jj = mm-1;
  for(long long  i = 0; i < nn; i++){
    for(long long  j = jj; j >= 0; j--){
      //cout << i << ' ' << j << endl;
      if(2147483646 - a[i] < b[j]) continue;
      if(a[i] + b[j] <= k) {jj = j;cnt = max(cnt,i+j+2);break;}
    }
  }

  //cout << "HERE3" << endl;

  for(long long  i = nn-1; i >= 0; i --){
    if(a[i] <= k) {cnt = max(cnt,i+1);break;}
  }
  for(long long  i = mm-1; i >= 0; i --){
    if(b[i] <= k) {cnt = max(cnt,i+1);break;}
  }

  cout << cnt;
}


Measured memory_bytes: 8328
package main
import (
    "fmt"
)
    
func main(){
    var N, ans int
    fmt.Scan(&N)
    div := N/3
    for i:=3;div>1;i+=2{
        div = N/i
        mod := N%i
        if mod == 0 {
            continue
        }
        i+=mod/div-1
        if mod%div == 0{
            ans += i
        }
        
    }
    fmt.Println(ans)
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		int[] to = new int[n + 10];
		for (int i = 1; i <= n; ++i) {
			to[i] = sc.nextInt();
		}

		int[] visited = new int[n + 10];
		int current = 1, stepCnt = 0;
		while (visited[current] < 1) {
			++visited[current];
			current = to[current];
			++stepCnt;

			if (stepCnt == k) {
				System.out.println(current);
				return;
			}
		}

		int cycleLen = 0;
		while (visited[current] < 2) {
			++visited[current];
			current = to[current];
			++stepCnt;
			++cycleLen;

			if (stepCnt == k) {
				System.out.println(current);
				return;
			}
		}

		k -= stepCnt;
		k %= cycleLen;
		while (k > 0) {
			current = to[current];
			--k;
		}

		System.out.println(current);
	}

}


Measured memory_bytes: 60076
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b;
  int some=1;
  int count=0;
  cin>>a>>b;
    if(some>=b){
      cout<<count<<"\n";
      return(0);
    }
  while(1){
    some--;
    count++;
    some+=a;
    if(some>=b){
      cout<<count<<"\n";
      return(0);
    }
  }
}


Measured memory_bytes: 256
num,renzoku=map(int,input().split())
dices=list(map(int,input().split()))

sum_si=sum(dices[0:renzoku])
max_si=sum_si
for i in range(1,num-renzoku+1):
  sum_si=sum_si-dices[i-1]+dices[i+renzoku-1]
  if max_si<sum_si:
    max_si=sum_si
print((renzoku+max_si)/2)

Measured memory_bytes: 25060
import sys
import math
import numpy as np
import bisect
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

l, r = na()

if l + 2019 - 1 < r:
    r = l + 2019 - 1
ans = 2018
for i in range(l, r):
    for j in range(i+1, r+1):
        ans = min(ans, (i*j)%2019)
print(ans)



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

int main()
{
  int i,j,k,N;
  int i2,i3,i4;
  int a,b,c;
  char A,B,C;
  char input[30010];
  int count;
  
  scanf("%d",&N);
  scanf("%s",input);
  /*for(i=0;i<N;i++){
    scanf("%d",&input[i]);
  }
  for(i=0;i<N;i++){
    printf("%d",&input[i]);
  }*/
  
  count = 0;
  for(i=0;i<=999;i++){
    
    a = i/100;  j = i%100;
    b = j/10;   k = i%10;
    c = k;
    A = '0'+a; B = '0'+b; C = '0'+c;
    //printf("%c%c%c\n",A,B,C);
    
    for(i2=0;i2<N;i2++){
      if( A == input[i2] ){
        for(i3=i2+1;i3<N;i3++){
          if( B == input[i3] ){
            for(i4=i3+1;i4<N;i4++){
              if( C == input[i4] ){
                count++;
                break;
              }
            }
            break;
          }
        }
        break;
      }
    }
    
  }
  
  
  printf("%d\n",count);
  
  return 0; 
}

Measured memory_bytes: 128
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 666;
long long n;
int len;
int c[maxn];
int ans[maxn];
int main()
{
	cin >> n, ++n;
	int len = 0;
	while(n) c[++len] = n & 1, n >>= 1;
	int num = 0, begin = 200, end = 199;
	for(int i = len - 1; i >= 1; --i)
	{
		ans[++end] = ++num;
		if(c[i]) ans[--begin] = ++num;
	}
	cout << ((end - begin + 1) << 1) << endl;
	for(int i = begin; i <= end; ++i) printf("%d ", ans[i]);
	for(int i = begin; i <= end; ++i) printf("%d ", i - begin + 1);
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
int query(vvi &v, int i, int j, int ii, int jj) {
	return v[ii][jj] - v[i][jj] - v[ii][j] + v[i][j];
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m, q;
	cin >> n >> m >> q;
	vector<string> s(n);
	REP(i, n)cin >> s[i];
	vvi v(n + 1, vi(m + 1, 0));
	REP(i, n) {
		REP(j, m) {
			v[i + 1][j + 1] = s[i][j] - '0';
		}
	}
	vvi a(n + 1, vi(m + 1, 0)), b(n + 1, vi(m + 1, 0));
	REP(i, n) {
		REP(j, m - 1) {
			if (v[i + 1][j + 1] & v[i + 1][j + 2]) {
				a[i + 1][j + 1] = 1;
			}
		}
	}

	REP(i, n - 1) {
		REP(j, m) {
			if (v[i + 1][j + 1] & v[i + 2][j + 1]) {
				b[i + 1][j + 1] = 1;
			}
		}
	}
	REP(i, n + 1)REP(j, m) {
		v[i][j + 1] += v[i][j];
		a[i][j + 1] += a[i][j];
		b[i][j + 1] += b[i][j];
	}
	REP(i, n)REP(j, m + 1) {
		v[i + 1][j] += v[i][j];
		a[i + 1][j] += a[i][j];
		b[i + 1][j] += b[i][j];
	}

	REP(i, q) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		x1--; x2--; y1--; y2--;
		int t = query(v, x1, y1, x2 + 1, y2 + 1),
			y = query(a, x1, y1, x2 + 1, y2),
			u = query(b, x1, y1, x2, y2 + 1);
		cout << t - y - u << endl;
	}

}


Measured memory_bytes: 53248
import sys, math
N, M = map(int, input().split())
MOD = 10 ** 9 + 7
if abs(N - M) > 1:
    print(0)
    sys.exit()

NN = math.factorial(N) % MOD
MM = math.factorial(M) % MOD
if N == M:
    print(2 * NN * MM % MOD)
else:
    print(NN * MM % MOD)

Measured memory_bytes: 10012
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

int main()
{
    int N;
    cin >> N;
    vector<int> v(N);
    int mini = -101,maxi = 101;
    for(int i = 0;i < N;i++)
    {
        cin >> v[i];
        mini = min(mini,v[i]);
        maxi = max(maxi,v[i]);
    }
    int sum = 0;
    int minsum = 1 << 20;
    for(int i = mini;i <= maxi;i++)
    {
        sum = 0;
        for(int j = 0;j < N;j++)
        {
            sum += (v[j] - i) * (v[j] - i);
        }
        minsum = min(minsum,sum);
    }
    cout << minsum << '\n';
}


Measured memory_bytes: 256
/*input
*/
#define debug 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; typedef double db;
const int N = 1e7 + 5, M = 1e9 + 7; const db eps = 1e-8;
typedef vector<ll> vi; typedef vector<vi> vii;
void solve();
void print(){cout<<'\n';}template<class T,class ...U>void print(T x, U ...y){cout<<x<<' ';print(y...);}
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  cout << setprecision(2) << fixed;
  if(debug){freopen("main.cpp","r",stdin);string x;cin>>x;}
  solve();
}
//
ll cnt[100][100];
void add(int x) {
  int t = x % 10;
  while (x >= 10) x /= 10;
  cnt[x][t]++;
}
void solve() {
  int n; cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) add(i);
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      ans += cnt[i][j] * cnt[j][i];
      // if (tmp) cout << i << ' ' << j << ' ' << tmp << endl;
    }
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int gcd(int a, int b){
	if(a==0 || b==0) return a==0?b:a;
	if(a==b) return a;
	int d=0;
	while((a&1)==0 && (b&1)==0){a>>=1; b>>=1; d++;}
	while(1){
		if((a&1)!=0){
			while((b&1)==0) b>>=1;
			if(a<b) b-=a; else if(a>b) a-=b; else break;
		}else{
			while((a&1)==0) a>>=1;
			if(a<b) b-=a; else if(a>b) a-=b; else break;
		}
	}
	return a<<d;
}

int main(void){
	int n, i;
	int a[100001];
	int l[100002], r[100002];
	scanf("%d", &n);
	for(i=1; i<=n; i++){
		scanf("%d", a+i);
	}
	l[0]=0;
	for(i=1; i<=n; i++){
		l[i] = gcd(l[i-1], a[i]);
	}
	r[n+1]=0;
	for(i=n; i>0; i--){
		r[i] = gcd(r[i+1], a[i]);
	}
	int max=0;
	for(i=1; i<=n; i++){
		int now=gcd(l[i-1], r[i+1]);
		if(now>max) max=now;
	}
	printf("%d\n", max);
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
//////////////////////////////////

int main(){
  char a, b; cin >> a >> b;
  vector<string> s(2);
  s[0] = string(b-'0', a);
  s[1] = string(a-'0', b);
  sort(all(s));
  cout << s[0] << endl;

  return 0;
}

// EOF


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int N=sc.nextInt();
		for(int i =0;i<=8;i++){
			if(Math.pow(2, i)<=N&&N<Math.pow(2, i+1)){
				System.out.println((int)Math.pow(2, i));
				break;
			}

		}

	}

}


Measured memory_bytes: 23380
import java.util.Scanner;

public class Main{
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
		int hit=0;
		int bro=0;
		int[] a = new int[4]; //Aさんの配列
		int[] b = new int[4]; //Bさんの配列

		for(int i=0; i<4;i++) //Aさんの要素数を入力
		{
			a[i]=sc.nextInt();
		}
		for(int i=0; i<4;i++)
		{ //Bさんの要素数を入力
			b[i]=sc.nextInt();
		}
		for(int i=0; i<4;i++) {
			for(int j=0; j<4; j++) {
				if(a[i]==b[j] && i!=j) { //ブローの条件式
					bro++;
				}else if(a[i]==b[j] && i==j){ //ヒットの条件式
					hit++;
				}
			}
		}System.out.println(hit +" "+ bro);

		}
	}
}


Measured memory_bytes: 26172
a,b,c = map(int, input().split())
listed = list(map(int, input().split()))
cnt = 0
for i in range(a):
    lister=list(map(int, input().split()))
    combined1 = [x * y for (x, y) in zip(listed, lister)]
    if sum(combined1)+c>0:cnt += 1
print(cnt)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i ++) cin >> a.at(i);

  reverse(a.begin(), a.end());
  for (int i = 0; i < n; i ++) {
    if (i) {
      cout << " " << a.at(i);
    } else {
      cout << a.at(i);
    }
  }
  cout << endl;
}



Measured memory_bytes: 3088
from itertools import combinations

N, K = map(int, input().split())
XY = [tuple(map(int, input().split())) for _ in range(N)]

ans = 10**20
for rect in combinations(XY, r=min(K, 4)):
    X = [x for x, _ in rect]
    Y = [y for _, y in rect]

    miX, mxX = min(X), max(X)
    miY, mxY = min(Y), max(Y)

    cnt = len([x for x, y in XY if miY <= y <= mxY and miX <= x <= mxX])
    if cnt >= K:
        ans = min(ans, (mxX - miX) * (mxY - miY))
print(ans)


Measured memory_bytes: 49116
use std::cmp::min;

pub fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

const INF: usize = 1000000;

fn main() {
    let s1 = read1::<String>().chars().collect::<Vec<char>>();
    let s2 = read1::<String>().chars().collect::<Vec<char>>();
    let l1 = s1.len();
    let l2 = s2.len();

    let mut dp = vec![vec![INF; l2 + 1]; l1 + 1];
    for i in 0..l1+1 {
        dp[i][0] = i;
    }
    for i in 0..l2+1 {
        dp[0][i] = i;
    }
    for i in 0..l1 {
        for j in 0..l2 {
            let cost;
            if s1[i] == s2[j] { cost = 0 }
            else { cost = 1 }

            dp[i+1][j+1] = min(dp[i][j+1] + 1, min(dp[i+1][j] + 1, dp[i][j] + cost));
        }
    }
    println!("{}", dp[l1][l2]);
}


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  if ((s[0] == s[s.size() - 1] && s.size()&1) || (s[0] != s[s.size()-1] && s.size()%2 == 0)) {
    puts("Second");
  } else {
    puts("First");
  }
  return 0;
}


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

int main(){
	int d, n;
	cin>>d>>n;
	if(d==0){
		if(n==100) cout<<101<<endl;
		else cout<<n<<endl;
	}
	else {
		if(n==100){
			if(d==1) cout<<10100<<endl;
			if(d==2) cout<<1010000<<endl;
		}
		else cout<<n*power(100, d)<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[])
{
    long a, b, x, y;

    while (scanf("%ld %ld", &a, &b) != EOF){
        for (y=a; 0!=y%b; y+=a);
        x = (long)(a*b)/y;
        printf("%ld %ld\n",x,y);
    }
    return 0;
}

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

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

  string T="AKIHABARA";
  vector<bool> ok(T.size(),false);
  int now=0;
  for(int i=0;i<S.size();i++){
    bool flag=false;
    for(;now<T.size();now++){
      if(S.at(i)==T.at(now)){
        flag=true;
        ok.at(now)=true;
        now++;
        break;
      }
    }
    if(!flag){
      cout << "NO" << endl;
      return 0;
    }
  }
  for(int i=0;i<T.size();i++){
    if(ok.at(i))  continue;
    if(T.at(i)=='A')  continue;
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;

  return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
Ps = list(map(int, input().split()))
Ps = [i - 1 for i in Ps]
Cs = list(map(int, input().split()))
max_score = -float("inf")


for i in range(N):
    scores = []
    idx = i  # starting index
    while True:
        idx = Ps[idx]  # point to the next index
        scores.append(Cs[idx])  # fetch a score to add
        if idx == i:  # when the cycle is closed
            break

    len_cycle = len(scores)
    sum_cycle = sum(scores)

    if sum_cycle <= 0:  # when each cycle reduces the total score
        score = 0
        for j in range(min(K, len_cycle)):
            score += scores[j]
            max_score = max(max_score, score)
    else:
        if K // len_cycle > 0:
            num_multiply = K // len_cycle - 1
            score = sum_cycle * num_multiply
            scores = scores * 2
            for j in range(K % len_cycle + len_cycle):
                score += scores[j]
                max_score = max(max_score, score)
        else:
            num_multiply = 0  # len_cycle > K
            score = sum_cycle * num_multiply
            for j in range(K):
                score += scores[j]
                max_score = max(max_score, score)

print(max_score)


Measured memory_bytes: 82768
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  b -= a;
  int ans = 0;
  for(int i = 1; i < b; i++){
    ans += i;
  }
  cout << ans - a << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a==b)
    {
        printf("a == b\n");
    }
    else if (a>b)
    {
        printf("a > b\n");
    }
    else
    {
        printf("a < b\n");
    }
}


Measured memory_bytes: 2568
n, x = input().split()
n = int(n)
x = int(x)

l = [int(y) for y in input().split()]

d = [0]
c = 1
for i in range(n):
    bounce = d[i] + l[i]
    d.append(bounce)
    if bounce <= x:
        c += 1
    else:
        break

print(c)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;

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

		try{

			while((str = br.readLine()) != null){
				int n = Integer.parseInt(str);
				int count = 0;

				if(n <= 2){
					count = 0;
				}else if(n == 3){
					count = 1;
				}else if(n % 2 == 0){
					//nが偶数の場合は，2の相方だけ調べればいい
					if(isPrime(n-1)) count = 2;
				}else{
					// まず2の相方を調べる
					if(isPrime(n-1)) count = 2;

					// 中心の数が素数かどうか調べる
					int middle = (1 + n) / 2;
					if(isPrime(middle)) count++;

					for(int i = 3; i < middle; i += 2){
						//System.out.println(i + "\t" + (n+1-i));
						if(isPrime(i)&&isPrime(n+1-i)){
							count += 2;
							//System.out.println("\t互いに素数");
						}
					}
				}
				System.out.println(count);
			}

		}catch(Exception e){
			//System.err.println(e);
		}
	}

	static boolean isPrime(int n){
		if(n % 2 == 0) return false;
		for (int i = 3; i <= n - 1; i += 2){
			if (n % i == 0) {
				return false;
			}
		}
		return true;
	}
}

Measured memory_bytes: 21040
#include <cstdio>
#include <algorithm>
#define MAX(a,b) ((a)>(b))?(a):(b)
#define MIN(a,b) ((a)<(b))?(a):(b)
using namespace std;


int main() {
	int n,p,q,r,max=-1,w;
	int i,j;
	int c;
	int *sum;
	int p_under;
	int p_over;
	bool flag=false;
	scanf("%d%d",&n,&q);
	sum=(int *)malloc(sizeof(int)*n);
	scanf("%d",&w);
	max=sum[0]=w;
	for(i=1; i<n; ++i) {
		scanf("%d",&w);
		max=MAX(w,max);
		sum[i]=sum[i-1]+w;
	}
	if(q==1) {
		printf("%d\n",sum[n-1]);
		return 0;
	}
	p=max;
	p_over=sum[n-1];
	p_under=0;
	while(1) {
		i=0;
		for(c=0; c<q-1; ++c) {
			for(j=0; i+j<n; ++j) {
				if(i==0) {
					if(sum[j]>p) {
						i=j;
						j=0;
						break;
					}
				} else {
					if(sum[i+j]-sum[i-1]>p) {
						i+=j;
						j=0;
						break;
					}
				}
			}
			if(i+j==n-1 && c<q-2) {
				if(p==max || flag) {
					printf("%d\n",p);
					return 0;
				}
				p_over=MIN(p_over,p);
				if(flag) {
					++p;
				} else {
					p=(p_under+p_over)/2;
				}
			}
		}
		r=sum[n-1]-sum[i-1];
		if(r==p) {
			printf("%d\n",p);
			return 0;
		} else if (!flag) {
			if(r<p) {
				p_over=MIN(p_over,p);
				p=(p_over+p_under)/2;
			} else if(r>p) {
				if(p_over-p_under<=10 || r-p<=10 ) {
					flag=true;
					p_under=MAX(p_under,p);
					++p;
				} else {
					p_under=MAX(p_under,p);
					p=(p_under+p_over)/2;
				}
			}
		} else {
			if(r>p) {
				++p;
			} else {
				printf("%d\n",p);
				return 0;
			}
		}
	}
	return 0;
}

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

int main() {
  string s; cin >> s;
  set<char> u;
  string ans = "no";
  int sn = s.size();
  rep(i,sn) u.insert(s[i]);
  if (u.size() == sn) ans = "yes";
  cout << ans << endl;
  return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int dp[2][16100];

int main() {
    string s;
    int x, y;
    vector<int> f;
    cin >> s >> x >> y;
    s += "T";
    int cnt = 0;
    rep(i, s.size()) {
        if (s[i] == 'T') {
            f.push_back(cnt);
            cnt = 0;
        }
        else {
            cnt++;
        }
    }

    fill(dp[0], dp[2], 1e8);
    dp[0][8000] = 0;
    int idx = 0;
    int num = 0;
    for (int i = 0; i < f.size(); i += 2) {
        for (int j = 0; j <= 16010; ++j) {
            if (dp[idx][j] == num) {
                dp[(idx + 1) % 2][j + f[i]] = num + 1;
                if (i > 0 and j >= f[i]) dp[(idx + 1) % 2][j - f[i]] = num + 1;
            }
        }
        num++;
        idx = (idx + 1) % 2;
    }
    if (dp[0][8000 + x] != num and dp[1][8000 + x] != num) {
        cout << "No" << endl;
        return 0;
    }

    fill(dp[0], dp[2], 1e8);
    dp[0][8000] = 0;
    num = 0;
    idx = 0;
    for (int i = 1; i < f.size(); i += 2) {
        for (int j = 0; j <= 16010; ++j) {
            if (dp[idx][j] == num) {
                dp[(idx + 1) % 2][j + f[i]] = num + 1;
                if (j >= f[i]) dp[(idx + 1) % 2][j - f[i]] = num + 1;
            }
        }
        idx = (idx + 1) % 2;
        num++;
    }
    if (dp[0][8000 + y] != num and dp[1][8000 + y] != num) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 384
use std::io;
use std::io::BufRead;

fn main() {
  let stdin = io::stdin();
  for line in stdin.lock().lines() {
    let line = line.unwrap();
    let mut iter = line.trim()
      .split_whitespace()
      .map(|x| x.parse::<usize>().unwrap());
    let (h, w) = (iter.next().unwrap(), iter.next().unwrap());

    if h == 0 && w == 0 { break; }

    let vert_end = "#".repeat(w);
    let inner = "#".to_string() + &".".repeat(w - 2) + "#";

    println!("{}", vert_end);
    for _ in 0..h-2 {
      println!("{}", inner);
    }
    println!("{}", vert_end);
    println!("");
  }
}


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

using namespace std;

#define llong long long int
#define rep(i, n) for (int i = 0; i < n; ++i) 
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 31;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int p, q, r;
    cin >> p >> q >> r;
    int a = abs(p + q), b = abs(q + r), c = abs(r + p);
    cout << min({a, b, c}) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
ll MOD = 1000000007;
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);

	ll n,X;
	cin >> n >> X;
	vector<ll>x(n),tmp;
	rep(i, n)cin >> x[i],tmp.push_back(abs(X-x[i]) == 0 ? INF : abs(X-x[i]));
	for (ll d = *min_element(all(tmp)); d >= 1; d--) {
		for (ll i = 0; i < n; i++) {
			if (abs(x[i] - X) % d != 0)break;
			else if(i==n-1)return cout << d << endl,0;
		}
	}
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
using namespace std;
ifstream f ("test.in"); ofstream g ("test.out");
ll n,W,dp[100005],w[105],v[105];
int main()
{   ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>W;
    for(int i=1;i<=n;i++) cin>>w[i]>>v[i];
    for(int i=1;i<=n;i++)
    {   for(int j=W-w[i];j>=0;j--)
            dp[j+w[i]]=max(v[i]+dp[j],dp[j+w[i]]);
    }
    ll ans=0;
    for(int i=0;i<=W;i++)
        ans=max(ans,dp[i]);
    cout<<ans;
    return 0;
}


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

int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int sum = 0;
    rep(i, N) sum += A[i];
    if (H <= sum) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline
A,B,K=map(int,input().rstrip().split())

def resolve():
    
    if(A>K):
        ansA=int(A)-int(K)
        ansB=int(B)
    else:
        ansA=0
        ansB=int(B)-(int(K)-int(A))
        if(ansB<0):
            ansB=0
    print(str(int(ansA))+" "+str(int(ansB)))

import sys
from io import StringIO
import unittest
#1000000000000 1000000000000 1000000000001
class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 3 3"""
        output = """0 2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """500000000000 500000000000 1000000000000"""
        output = """0 0"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Measured memory_bytes: 51564
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int ch=getchar();
	int sum=0;
	while(ch>='0'&&ch<='9')
	{
		sum+=ch-'0';
		ch=getchar();
	}
	if(sum%9==0)
	{
		cout<<"Yes";
	}
	else
	{cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  int a,b;
  cin>>a>>b;
  if(a>12) cout<<b<<endl;
  else if(a>5) cout<<b/2<<endl;
  else cout<<"0"<<endl;
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N, sumA(0), sumB(0); cin >> N;
	vector<ll> A,B,AB;
	for (int i(0); i < N; ++i){
		ll a; cin >> a;
		A.push_back(a);
		sumA += a;
	}
	for (int j(0); j < N; ++j){
		ll b; cin >> b;
		B.push_back(b);
		sumB += b;
	}
	ll ans(0), neg(0);
	if (sumB > sumA){
		cout << -1;
	}
	else{
		for (int i(0); i < N; ++i){
			if (A[i]<B[i]){
				++ans;
				neg += A[i]-B[i];
			}
		}
		vector<ll> v;
		for (int j(0); j < N; ++j){
			if (A[j]>B[j]){
				v.push_back(A[j]-B[j]);
			}
		}
		sort(v.begin(),v.end());
		while (neg<0){
			++ ans;
			neg += v[v.size()-1];
			v.pop_back();
		}
		cout << ans;
	}
	return 0;
}

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

int main() {
  int x;
  cin >> x;
  int ans = 0;
  for(int i=x;i<=pow(10, 7);i++) {
    bool prime = true;
    for(int j=2;j<x;j++) {
      if(i % j==0) {
        prime = false;
        break;
      }
    }
    if(prime) {
      ans = i;
      break;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
template <typename T = int>
T in() {
    T temp; cin >> temp; return temp;
}

template <typename VType = int>
list<VType> const LR(VType start, VType end) {
    list<VType> ret;
    for (VType i = start; i < end; i++) ret.push_back(i);
    return move(ret);
}

int main() {
    int N(in());
    char s[N];
    int r = 0, b = 0;
    for (char c : s) {
        cin >> c;
        if ('R' == c) r++;
        else b++;
    }

    cout << ((r > b) ? "Yes" : "No") << endl;
    return 0;
}




Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n, k; cin >> n >> k;
  n -= 2;
  if (n <= 0) {
    cout << "0\n";
    return 0;
  }
  vector<vector<int> > cal(13, vector<int>(7));
  REP(i, 13) REP(j, 7) cal[i][j] = 7 * i + j + 1;
  vector<vector<int> > sum(11, vector<int>(5, 0));
  REP(i, 11) REP(j, 5) {
    REP(y, 3) REP(x, 3) sum[i][j] += cal[i + y][j + x];
  }
  ll ans = 0;
  int t = 0;
  REP(i, 11) REP(j, 5) t += sum[i][j] % 11 == k;
  ans += 1LL * t * (n / 11);
  n %= 11;
  REP(i, n) REP(j, 5) ans += sum[i][j] % 11 == k;
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
typedef std::pair<int,int> pii;
typedef std::pair<pii,int> piii;
int main(){
    int n,m,p,y,j;
    std::vector<piii> v_pyi,v_ipj;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d%d",&p,&y);
        v_pyi.push_back({{p,y},i});
    }
    std::sort(v_pyi.begin(),v_pyi.end());
    p=0;
    for(int k=0;k<m;k++){
        if(p==v_pyi[k].first.first)j++;
        else{
            j=1;
            p=v_pyi[k].first.first;
        }
        y=v_pyi[k].first.second;
        int i=v_pyi[k].second;
        v_ipj.push_back({{i,p},j});
    }
    std::sort(v_ipj.begin(),v_ipj.end());
    for(int i=0;i<m;i++){
        p=v_ipj[i].first.second;
        int j=v_ipj[i].second;
        printf("%06d%06d\n",p,j);
    }
    return 0;
}

Measured memory_bytes: 3956
#include <stdio.h>

int main(void){
  int n, d[101] = {0};
  int i, t, ans;

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

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

  return 0;
}

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

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

Measured memory_bytes: 3628
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <limits>

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

// 二項係数計算
long long COM(long long facn, int k){
    
    return facn * finv[k]  % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;


  COMinit();

  long long zen;
  zen = modpow(2,n,MOD)-1;


  long long NA=1;
  for(int i=n-a+1; i<= n; i++){
    NA = NA * i %MOD;
  }

  long long NB=1;
  for(int i=n-b+1; i<=n; i++){
    NB = NB * i % MOD;
  }
  //cout << zen << " "<< NA <<" "<< NB << endl;
  zen = mod(zen- COM(NA, a), MOD);
  zen = mod(zen- COM(NB, b), MOD);

  cout << zen << endl;

  return 0;
}

Measured memory_bytes: 12160
#![allow(dead_code)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(unused_variables)]

use std::collections::BinaryHeap;
use std::io::Read;

const U32_LARGE: u32 = 1 << 30;

fn read<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let a: Vec<usize> = (0..n).map(|_| read()).collect();
    let b: Vec<u32> = (0..n).map(|_| read()).collect();
    let c: Vec<u32> = (0..n - 1).map(|_| read()).collect();

    let mut res: u32 = 0;
    for v in b {
        res += v;
    }

    for i in 0..n - 1 {
        if a[i + 1] == a[i] + 1 {
            res += c[a[i] - 1];
        }
    }
    println!("{}", res);
}


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

typedef long long ll;

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    sort(h.begin(), h.end(), greater<int>());
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if (i >= k) {
            ans += h[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
read n a b;
for((i=0;i++<n;))do
	m=0;
	for c in 1 10 100 1000 10000;do
		m=$[m+i/c%10]
	done
	if [ $m -ge $a -a $m -le $b ];then
		s=$[s+i]
	fi
done
echo $s


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

using namespace std;

int main(){
  int N,answer;
  string S;
  cin >> N >> S;
  vector<int> w(N);
  vector<int> e(N);
  answer=1000000;
  //累積和を取る
  for (int i = 0; i < N-1; i++) {
    if (S.at(i) == 'W'){
      w.at(i+1) = w.at(i) + 1;
    }
    else {
      w.at(i+1) = w.at(i);
    }
  }
  
  for (int i = N-1; i > 0; i--) {
    if (S.at(i) == 'E'){
      e.at(i-1) = e.at(i) + 1;
    }
    else {
      e.at(i-1) = e.at(i);
    }
  }
  
  for (int i = 0; i < N; i++) {
    answer = min(answer, e.at(i) + w.at(i));
  }
  cout << answer << endl;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


int main(void) {
  ll N;
  cin >> N;
  ll a[3][111];
  ll i, j;
  
  for(i=0; i<2; i++) {
    for(j=0; j<N; j++) {
      cin >> a[i][j];
    }
  }
  
  
  ll dp[2][111]={};
  dp[0][0]=a[0][0];
  for(i=0; i<2; i++) {
    for(j=0; j<N; j++) {
      chmax(dp[i+1][j], dp[i][j]+a[i+1][j]);
      chmax(dp[i][j+1], dp[i][j]+a[i][j+1]);
    }
  }
  
  pt(dp[1][N-1]);
}








Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
int main(){
    int n,k,l,d[10]={};
    cin>>n>>k;
    for(int i=0;i<k;i++){
        cin>>l;
        d[l]=1;
    }
    string retstr;
    bool flag=true;
    while(flag){
        flag=false;
        retstr=to_string(n);
        for(int i=0;i<retstr.length();i++){
            if(1==d[(int)(retstr[i])-48]){
                n++;
                flag=true;
                break;
            }
        }
    }
    cout<<n;
}

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

int main(){
  int n;
  cin >> n;
  vector<long long> a(n);
  vector<int> dp(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  
  bool up=false;
  bool down=false;
  
  for(int i=0; i<n-1; i++){
    if(up == false && down == false){
      if(a[i] < a[i+1]){
        up = true;
      }else if(a[i] > a[i+1]){
        down = true;
      }
    }else if(up == true){
      if(a[i] > a[i+1]){
        up = false;
        dp[i] = 1;
      }
    }else if(down == true){
      if(a[i] < a[i+1]){
        down = false;
        dp[i] = 1;
      }
    }
  }
    
  int sum=1;
  for(int i=0; i<n; i++){
    sum += dp[i];
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define M 100005
vector<int>E[M];
int n,m,s,t,a,b;
int Min=1e9;
struct Node {
	int x,y;
};
bool Mark[M][3];
queue<Node>Q;
void bfs(int x) {
	Q.push((Node)<%x,0%>);
	Mark[x][0]=1;
	while(!Q.empty()) {
		int x=Q.front().x,y=Q.front().y;
		Q.pop();
		if(x==t&&y%3==0)Min=min(Min,y);
		for(int i=0; i<E[x].size(); i++) {
			int u=E[x][i],w=(y+1)%3;
			if(!Mark[u][w])Q.push((Node)<%u,y+1%>),Mark[u][w]=1;
		}
	}
}
int main() {
	scanf("%d%d",&n,&m);
	for(int i=1; i<=m; i++) {
		scanf("%d%d",&a,&b);
		E[a].push_back(b);
	}
	scanf("%d%d",&s,&t);
	bfs(s);
	if(!Mark[t][0])puts("-1");
	else printf("%d",Min/3);
}

Measured memory_bytes: 6016