akhauriyash/Code-Regression huggingface dataset:
a, b, c = map(int,input().split())

day = 0
coin = 0
loginCont = 0
while True:
    day += 1
    loginCont += 1
    coin += a
    if day == 7:
        coin += b
        day = 0
        if coin >= c:
            break
    if coin >= c:
        break

print(loginCont)


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

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

    static class DGridComponents {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 白
            int a = in.nextInt();
            // 黒
            int b = in.nextInt();
            char[][] c = new char[100][100];

            for (int i = 0; i < 100; i++) {
                for (int j = 0; j < 100; j++) {
                    if (i < 50) {
                        // 黒字に白
                        if (i % 2 != 0 && j % 2 != 0 && a > 1) {
                            c[i][j] = '.';
                            a--;
                        } else {
                            c[i][j] = '#';
                        }
                    } else {
                        if (i % 2 != 0 && j % 2 != 0 && b > 1) {
                            c[i][j] = '#';
                            b--;
                        } else {
                            c[i][j] = '.';
                        }
                    }
                }
            }
                
            out.println("100 100");
            for (int i = 0; i < 100; i++) {
                for (int j = 0; j < 100; j++) {
                    out.print(c[i][j]);
                }
                out.println();
            }

        }

    }
}



Measured memory_bytes: 24020
/*
    ????????°??§???????????¨????????????
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int> 
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\n")
#define debugd(a) printf("--%d\n",a)
#define debugdd(a,b) printf("--%d %d\n",a,b)
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; a++)
#define forde(a,b,c) for(int a=b ; a<c ; a--)


inline void scd(int &a){scanf("%d",&a);}
inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void scdlld(long int &a,long int &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(long long int &a){scanf("%I64d",&a);}

#define scarrd(a,b) for(int i=0 ; i<b ; i++)scanf("%d",&a[i])
#define prdlld(a,b) printf("%I64d %I64d",a,b)
#define prdd(a,b) printf("%d %d",a,b)
#define prd(a) printf("%d",a)
#define prarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i])
#define iniarr(a,b) for(int i=0 ; i<b ;i++)a[i]=0
#define arr(a,b) int *a=(int *)malloc(b*sizeof(int))
#define llarr(a,b) long long int *a=(long long int *)malloc(b*sizeof(long long int))
#define st(a,b) char *a=(char *)malloc(b*sizeof(char))
#define grav 9.8
#define pi 3.14159265

int main()
{
	int a;
	scd(a);
	int i=1;
	while(a!=0)
	{
		printf("Case %d: %d\n",i,a);
		i++;
		scd(a);
	}
	return 0;
}

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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
typedef long long ll;

bool prime[10000001];
void Eratosthenes(int n)
{
	rep(i,n) prime[i] = true;
	prime[1] = false;

	REP(i,2,(int)sqrt(n))
	{
		if(prime[i])
		{
			for(int j=0;i*(j+2)<n;j++)
			{
				prime[i*(j+2)] = 0;
			}
		}
	}
} 

int main()
{
	Eratosthenes(10000001);
	
	int n;
	while(cin >> n && n)
	{
		ll ans = 0;
		for(int i=n;i>=0;i--)
		{
			if(prime[i] && prime[i-2] && prime[i-6] && prime[i-8])
			{
				ans = i;
				break;
			}
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 10920
#include<iostream>
#include<cmath>
#include<cstdio>

using namespace std;

const int MAX = 20;
typedef pair<long double,long double> P;
P data[MAX];
int rev;
long double ans;

long double getlength(int i, int j){
  return sqrt((data[i].first - data[j].first)*(data[i].first - data[j].first)+
	      (data[i].second - data[j].second)*(data[i].second - data[j].second));

}
void solve(){
  long double num[3];
  for(int i = 1; i < rev-1; i++){
    long double z = 0;
    num[0] = getlength(0,i);
    num[1] = getlength(0,i+1);
    num[2] = getlength(i,i+1);
    z  = (num[0]+num[1]+num[2])/2;
    ans += sqrt(z*(z-num[0])*(z-num[1])*(z-num[2]));
  }
}
int main(){
  char c;
  while(cin >> data[rev].first >> c >> data[rev].second){
    rev++;
  }
  solve();
  // cout << ans << endl;
  printf("%.6Lf\n",ans);
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main()
{	int n;
	scanf("%d",&n);
	if(n==1) printf("1\n");
	else if(n<=3) printf("2\n");
	else if(n<8) printf("4\n");
	else if(n<16) printf("8\n");
	else if(n<32) printf("16\n");
	else if(n<64) printf("32\n");
	else if(n<101) printf("64\n");
	return 0;
}

Measured memory_bytes: 128
// INCLUDES
#include <bits/stdc++.h>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define c1 __builtin_popcount
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//HELPERS
int n,k;
vector<int> v;
void solve(){
cin>>n>>k;
v.resize(n);
FOR(i,0,n) cin>>v[i];
int x = 100005;
int dp[x] = {};
FOR(i,0,x) {
    for(auto a : v ) if(i>=a && !dp[i-a]) dp[i] = 1;
}
// FOR(i,0,20) dp[i] == 0 ? cout<<"Jiro " : cout<<"Taro ";
// cout<<endl;
cout<<(dp[k] == 0 ? "Second" : "First");
}
int32_t main()
{
IOS
int t=1;
// cin>>t;
while(t--) {
    solve();
}
return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

ll gcd(ll a, ll b) { return (a == 0) ? b : gcd(b % a, a); }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

int f(int x) {
  int ans = 0;
  rep(i, 30) {
    if (!(x & 1)) {
      x /= 2;
      ans++;
    } else {
      break;
    }
  }
  return ans;
}

void solve() {
  int n, m;
  cin >> n >> m;
  vi a(n);
  rep(i, n) cin >> a[i];
  rep(i, n) a[i] /= 2;
  int b = f(a[0]);
  rep(i, n) {
    if (b != f(a[i])) {
      cout << 0 << endl;
      return;
    }
  }
  dump(a);
  ll mn = a[0];
  for (int i = 1; i < n; i++) mn = lcm(mn, a[i]);
  dump(mn);
  if (m < mn) {
    cout << 0 << endl;
    return;
  }
  ll ans = m / mn;
  if (ans & 1)
    ans = (ans + 1) / 2;
  else
    ans /= 2;
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

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

int main(){
    ll A, B, K;
    cin >> A >> B >> K;
    
    ll first1 = A;
    ll first2 = B - K + 1;
    ll last1 = A + K - 1;
    ll last2 = B;

    if(last1 >= first2){
        for(ll i = first1; i <= last2; ++i) cout << i << endl;
    } else {
        for(int i = 0; i < K; ++i) cout << A + i << endl;
        for(int i = K - 1; i >= 0; --i) cout << B - i << endl;
    }
    
    return 0;
}

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

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int n;cin>>n;
  int arr[n];
  for(int i = 0; i<n; i++){
    cin>>arr[i];
  }
  // int dp[n];
  int INF = 1e9 + 5;
  // memset(dp, INF, sizeof(int)*n);
  vector<int> dp(n,INF);
  dp[0] = 0;
  for(int i=0; i<n; i++){
    for(int j=1; j<=2;j++){
      if(i+j<n)
        dp[i+j] = min(dp[i+j], dp[i] + abs(arr[i+j]-arr[i]));
    }
  }
  cout<<dp[n-1];
  return 0;
}


Measured memory_bytes: 1024
N = int(input())
cnt = 0
def dfs(n, cnt):
    if int(n) > N:
        return cnt
    if n.count("3") >= 1 and n.count("5") >= 1 and n.count("7") >= 1:
        cnt += 1

    for i in ("3","5","7"):
        cnt = max(cnt, dfs(n+i, cnt))
    return cnt

print(dfs("0", 0))

Measured memory_bytes: 3060
n=int(input())
v=list(map(int,input().split()))
odds=[[0,i]  for i in range(10**5+1)]
even=[[0,i]  for i in range(10**5+1)]
for i in range(n):
    if i%2==0:
        even[v[i]][0]+=1
    else:
        odds[v[i]][0]+=1
even.sort(reverse=True)
odds.sort(reverse=True)
if even[0][1]==odds[0][1]:
    m=max(even[0][0]+odds[1][0],even[1][0]+odds[0][0])
    print(n-m)
else:
    print(n-even[0][0]-odds[0][0])

Measured memory_bytes: 34232
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e18;

signed main() {
    string s;
    cin >> s;
    int x, y;
    cin >> x >> y;
    int cnt = 0;
    rep(i, s.size()) {
        if(s[i]=='T') break;
        cnt++;
    }

    V(V(bool)) dpx(8050, V(bool)(16050, false)), dpy(8050, V(bool)(16050, false));
    dpx[0][8000] = true; dpy[0][8000] = true;
    dpx[1][8000+cnt] = true;


    vi xa, ya;
    //xa.pb(cnt);
    int t = cnt+1;
    cnt = 0;
    bool tx = false;
    
    while(t < s.size()) {
        if(s[t]=='T') {
            if(tx) xa.pb(cnt);
            else ya.pb(cnt);
            cnt = 0;
            tx = !tx;
        } else cnt++;
        t++;
    }
    if(cnt) {
        if(tx) xa.pb(cnt);
        else ya.pb(cnt);
    }


    rep(i, xa.size()) {
        rep(n, 16000) {
            if(dpx[i+1][n]) {
                
                dpx[i+2][n+xa[i]] = true;
                dpx[i+2][n-xa[i]] = true;
            }
        }
    }
    rep(i, ya.size()) {
        rep(n, 16000) {
            if(dpy[i][n]) {
                dpy[i+1][n+ya[i]] = true;
                dpy[i+1][n-ya[i]] = true;
            }
        }
    }

    if(dpx[xa.size()+1][x+8000] && dpy[ya.size()][y+8000]) cout << "Yes" << endl;
    else cout << "No" << endl;

    
    return 0;
}

Measured memory_bytes: 32640
N = int(input())
l = [int(x) for x in input().split()]
ans = 0
for i in range(N):
  if l[i] % 2 == 0:
    if l[i] % 3 == 0 or l[i] % 5 == 0:
      pass
    else:
      ans += 1
      break
if ans == 0:
  print('APPROVED')
else:
  print('DENIED')

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

public class Main{
	static int[] dx = {-1, 0, 1, 0};
	static int[] dy = {0, -1, 0, 1};

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

		while(true){
			int tile_num = sc.nextInt();
			if(tile_num==0) break;
			int[] array_x = new int[tile_num];
			int[] array_y = new int[tile_num];

			for(int i=1; i<tile_num; i++){
				int num = sc.nextInt();
				int j = sc.nextInt();
				array_x[i] = array_x[num]+dx[j];
				array_y[i] = array_y[num]+dy[j];
			}
			Arrays.sort(array_x);
			Arrays.sort(array_y);

			int width = array_x[tile_num-1] - array_x[0] + 1;
			int height = array_y[tile_num-1] - array_y[0] + 1;

			System.out.println(width + " " + height);
		}
	}
}

Measured memory_bytes: 40992
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main(){
	ll A, B;
	cin >> A >> B;
	if (A == B) {
		cout << A*2 << '\n';
	}
	else{
		ll c = std::max(A, B);
		cout << c*2-1 << '\n';
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
using namespace std;
typedef long long ll;
template <class T> inline bool dpmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool dpmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve(long long N, vector<long long> X) {
    ll min_hp = 1e8;

    for (int i = 1; i <= 100; i++) {
        ll hp = 0;
        for (int j=0; j < N; j++) {
            hp += (X[j] - i) * (X[j] - i);
        }
        if (hp <= min_hp) min_hp = hp;
    }

    cout << min_hp << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  long long N;
  cin >> N;
  vector<long long> X(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i];
  }
  solve(N, move(X));
  return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;
 
class Main {
    Scanner sc = new Scanner(System.in);
 
    public void run() {
        while (true) {
            int H = sc.nextInt(),W= sc.nextInt();
            if (H==0 && W==0) {
                break;
            }
            for(int h=0;h<H;h++){
                for(int w=0;w<W;w++){
                    pr("#");
                }
                ln();
            }
            ln();
        }
    }
 
    public static void main(String[] args) {
        new Main().run();
    }
 
    public static void pr(Object o) {
        System.out.print(o);
    }
 
    public static void ln(Object o) {
        System.out.println(o);
    }
 
    public static void ln() {
        System.out.println();
    }
}


Measured memory_bytes: 35264
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main() {
    let mut x: usize;
    input!(x);
    let mut ans = 0_usize;
    ans += 1000 * (x / 500);
    x %= 500;
    ans += 5 * (x / 5);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<bitset> 
#include<unordered_map> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include "boost/algorithm/string.hpp"
// RAJJI KI MEHER 
#define fio ios_base::sync_with_stdio(false)
//#define mod 1000000007
#define mod1 mod
#define mod2 100000009
#define li long long int
#define ll int
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define readi(x) scanf("%d",&x)
#define  reads(x)  scanf("%s", x)
#define readl(x) scanf("%lld",&x)
#define rep(i,n) for(i=0;i<n;i++)
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define myrep1(i,a,b) for(i=a;i<=b;i++)
#define myrep2(i,a,b) for(i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define MAXN 100000000000000005
#define MINN -10000000000000000
#define INTMAX 1000001000
#define pii pair<li,li>
#define pdd pair<double,double>
#define pic pair<int,char>
//#define N 5005
#define lgn 20
#define ddouble long double
#define minus minu
#define PI 3.1415926535
#define lgn 20
using namespace std;
vector<li>a(105);li n,n1=0,n2=0,n3=0,k,mod=1000000007;
li AA[105][100005];
li ff(li i1,li i2){if(i2<0) return(0);
    if(i1==1) {if(i2<=a[i1-1]) return(1);
    else return(0);}
    //if(i==0) return(0);
    if(AA[i1][i2]!=-1) return(AA[i1][i2]);    
    li ans=0;
ans=(ff(i1,i2-1)-ff(i1-1,i2-1-a[i1-1])+ff(i1-1,i2)+mod)%mod;
AA[i1][i2]=ans;return(ans);}
int main(){readl(n);readl(k);memset(AA,-1,sizeof(AA));li i;
for(i=0;i<n;i++) {cin>>a[i];}
li ans=ff(n,k);
cout<<ans;
}

Measured memory_bytes: 90112
k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()
cnt, yep = 0, 0
while True:
    yep = (yep * 10 + 7) % k
    cnt += 1
    if yep == 0:
        break
print(cnt)

Measured memory_bytes: 9028
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main() {
  INIT;
  VAR(int, n);
  VEC(int,w,n);

  int ans = INF;
  int sm = 0;
  REP(i,n) {
    sm += w[i];
  }

  int ds = 0;
  REP(i,n){
    ds += w[i];
    ans = min(ans, abs(ds-(sm-ds)));
  }
  OUT(ans)BR;
  
  return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
S=[int(i) for i in input().split()]

dp=[False]*(K+1)

for i in range(K+1):
    #print(dp)
    for s in S:
        f=False
        if i-s<0:
            break
        if not dp[i-s]:
            dp[i]=True
            break
#print(dp)
if dp[-1]:
    print("First")
else:
    print("Second")

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

int s_len, t_len;

inline int index(int i, int j) {
    return (t_len + 1) * i + j;
}

int main() {
    string s, t;
    cin >> s >> t;
    s_len = s.size();
    t_len = t.size();
    int dp[(s_len + 1) * (t_len + 1)], trace[(s_len + 1) * (t_len + 1)];
    for (int i = 0; i <= s_len; i++) {
        for (int j = 0; j <= t_len; j++) {
            dp[index(i, j)] = 0;
            trace[index(i, j)] = index(i, j);
        }
    }
    for (int i = 0; i < s_len; i++) {
        for (int j = 0; j < t_len; j++) {
            int next = dp[index(i, j)] + ((s[i] == t[j]) ? 1 : 0);
            if (next < dp[index(i, j + 1)]) {
                dp[index(i + 1, j + 1)] = dp[index(i, j + 1)];
                trace[index(i + 1, j + 1)] = index(i, j + 1);
            } else if (next < dp[index(i + 1, j)]) {
                dp[index(i + 1, j + 1)] = dp[index(i + 1, j)];
                trace[index(i + 1, j + 1)] = index(i + 1, j);
            } else {
                dp[index(i + 1, j + 1)] = next;
                trace[index(i + 1, j + 1)] = index(i, j);
            }
        }
    }
    stack<char> st;
    int i = s_len, j = t_len;
    int p = index(i, j);
    while (trace[p] != p) {
        i = p / (t_len + 1);
        j = p % (t_len + 1);
        if (s[i - 1] == t[j - 1])
            st.push(s[i - 1]);
        p = trace[p];
    }
    while (!st.empty()) {
        char head = st.top(); st.pop();
        cout << head;
    }
    cout << endl;
    return 0;
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    map<string, int> m;
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        m[s]++;
    }
    int maxi = 0;
    for (auto &iter: m) {
        maxi = max(maxi, iter.second);
    }
    for (auto &iter: m) {
        if (iter.second == maxi) cout << iter.first << "\n";
    }
    return 0;
}

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

int main()
{

	int64_t n;
	cin >> n;

	vector<int64_t> pow26(13),sum26(13);
	pow26[0]=1;
	sum26[0]=0;
	for (int i=1;i<13;++i)
	{
		pow26[i]=pow26[i-1]*26;
		sum26[i]=sum26[i-1]+pow26[i];
		//fprintf(stderr,"pow %lld sum %lld\n",pow26[i],sum26[i]);
	}

	bool initial=true;
	for (int i=12;i>0;--i)
	{
		int count=0;
		while (n>sum26[i])
		{
			++count;
			n-=pow26[i];
		}
		//fprintf(stderr,"i %d count %d\n",i,count);
		if ((initial!=false)&&(count>0))
		{
			cout << (char)(count+'a'-1);
			initial=false;
		}
		else if (initial==false)
		{
			cout << (char)(count+'a'-1);
		}
	}
	cout << (char)(n+'a'-1) << endl;
}



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

bool inArr (int* arr,int len,int X){
  for(int i=0;i<len;i++){
    if(X==arr[i]){
      return true;
    }
  }
  return false;
}

int main(){
  int x,n;
  int arr[101];
  while(cin>>x>>n){
    for(int i=0;i<n;i++){
      cin>> arr[i];
    }
    int XX=x,dif_n=0;
    while(inArr(arr,n,XX)){
      XX-=1;
      dif_n=abs(x-XX);
    }
    int NN=x,dif_p=0;
    while(inArr(arr,n,NN)){
      NN+=1;
      dif_p=abs(x-NN);
    }
    if(dif_p<dif_n){
      cout<<NN<<endl;
    }
    else{
      cout<<XX<<endl;
    }
  }
}

Measured memory_bytes: 3192
#include <iostream>
#include <string>
using namespace std;
int main(void){
	char c[2][3];
	for(int i=0; i<2; i++){
		for(int j=0; j<3; j++){
			cin >> c[i][j];
		}
	}
	if(c[0][0]!=c[1][2]){cout << "NO" << endl;return 0;}
	if(c[0][1]!=c[1][1]){cout << "NO" << endl;return 0;}
	if(c[0][2]!=c[1][0]){cout << "NO" << endl;return 0;}
	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define debugVec(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define mod (int)(998244353)
using namespace std;
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " ";
    err(++it, args...);
}

signed main(){

    fastIO
    
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]){
    	cout << "Yes";
    }else{
    	cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int n, A, B, w[301000], cnt;
int main() {
	int i;
	scanf("%d%d%d",&n, &A, &B);
	if (1ll*A*B<n || A + B>n + 1) {
		printf("-1\n");
		return 0;
	}
	int pv = 0;
	while (pv <= n) {
		for (i = pv + B; i >=pv+1; i--) {
			w[++cnt] = i;
		}
		pv += B;
		if (pv + B > n || pv / B + 1 + n - pv - B < A) break;
	}
	int t = A - pv / B;
	for (i = n - t + 1; i <= n; i++)w[++cnt] = i;
	for (i = n - t; i > pv; i--)w[++cnt] = i;
	for (i = 1; i <= n; i++)printf("%d ", w[i]);
}

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

map<int,int> m;
vector<int> v;

int main(){
	int n,ans;
	cin>>n;
	for(register int i=1;i<=n;++i){
		int x;
		cin>>x;
		if(m[x]==0) v.push_back(x);
		++m[x];
	}
	for(register int i=0;i<v.size();++i) if(m[v[i]]>=v[i]) ans+=m[v[i]]-v[i]; else ans+=m[v[i]];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5112
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;

struct edge { int to, cost; };

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

signed main()
{
   int n; cin >> n;
   V<int> a(3*n);
   for (int i = 0; i < 3*n; i++) {
      cin >> a[i];
   }

   sort(a.rbegin(), a.rend());

   int ans = 0;
   for (int i = 0; i < n; i++) {
      ans += a[2*i + 1];
   }
   cout << ans << endl;


   return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    string s;
    cin>>s;
    int cur=0,mx=0;
    rep(i,s.size()){
        if(s[i]=='T') ++cur;
        else --cur;
        mx=max(cur,mx);
    }
    cout<<mx*2<<endl;
    return 0;
}

Measured memory_bytes: 640
from fractions import gcd

def main():
    N,M=map(int,input().split())
    a=[int(_) for _ in input().split()]
    flag=0
    n=1

    for i in range(N):
        a[i] //= 2

    for i in range(N):
        n=n*a[i]//gcd(n,a[i])
        if n>M:
            flag=1
            break

    for i in range(N):
        if (n//a[i])%2==0:
            flag=1
            break

    if flag==0 and M>=n:
        ans=1
        M-=n
        ans+=M//(2*n)
        print(ans)
    else:
        print(0)

main()

Measured memory_bytes: 16292
#include <iostream>
#include<vector>
#include <cstdlib>
#include<cmath>
#include<string>
#include <iomanip>
#include <sstream>

using namespace std;





int main () {


   long long n,i,j;
    cin>>n;

    string s="";
    char t;

char a[26]={'a', 'b', 'c', 'd' , 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm' , 'n', 'o', 'p', 'q', 'r', 's', 't',
            'u', 'v', 'w', 'x', 'y', 'z'};





while (n>0){

    j=n%26;
    n=n/26;
    if( j==0 ){

        s=a[25]+s;
        n-=1;
    }

    else {

        s=a[j-1]+s;

    }




}

cout<<s;


}


















/*#include <iostream>
#include<vector>
#include <cstdlib>
#include<cmath>
#include<string>
#include <iomanip>
#include <sstream>

using namespace std;


int main (){


    unsigned long long n,i,j,m,cnt=0;

    cin>>n;

    vector<unsigned long long> a(n);

    stringstream s[n];

    string final[n];

    for(i=0;i<n;i++){

        cin>>a[i];
    }

    for(i=0;i<n;i++){

        s[i]<<a[i];
        s[i]>>final[i];

    }

    vector<long long>b(n,0);



    for(i=0;i<n;i++){

        m=final[i].size();

        for(j=0;j<m;j++){

            b[i]+=final[i][j]-'0';


        }



    }

    for(i=0;i<n;i++){


        cout<<b[i]<<endl;
    }



}
 */

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int w[100];
int main()
{
  int n;
  int t;
  int rj=10000000;
  cin>>n;
  for(int i=0;i<n;i++)
  {
    cin>>w[i];
  }
  for(int t=0;t<n;t++)
  {
    int s1=0;
    int s2=0;
    for (int i=0;i<=t;i++)
    {
        s1+=w[i];
    }
    for(int i=t+1;i<=n-1;i++)
    {
    s2+=w[i];
    }
    rj=min(rj,abs(s1-s2));
  }
  cout << rj;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n],b[n],c[n];
    for(int i=0;i<n;i++) cin >> a[i] >> b[i] >> c[i];
    int dp[n][3];
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    for(int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
    }
    cout << max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]) << endl;
    return 0;
}


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

constexpr int N = 505;
int dp[N][N];

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, m, q;
    cin >> n >> m >> q;
    for(int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        dp[a][b]++;
    }
    for(int x = N - 2; x >= 1; --x) {
        for(int y = 1; y < N; ++y) {
            dp[x][y] = dp[x][y] + dp[x + 1][y] + dp[x][y - 1] - dp[x + 1][y - 1];
        }
    }
    while(q--) {
        int ql, qr;
        cin >> ql >> qr;
        cout << dp[ql][qr] << '\n';
    }
}


Measured memory_bytes: 1920
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define user spaesk
#define pi acos(-1)
#define lli long long int
#define ld long double
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

typedef vector<vector<lli> > matrix ;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;

const int maxN = 1003;

lli n, m;
lli a[maxN], b[maxN], c[maxN][15];
lli cache[maxN][(1 << 15)];

lli dp(lli i, lli mask) {

//    if(i == m)
//        cout<<i<<' '<<mask<<' '<<cost<<endl;

    if(i > m)
        return inf;

    if(i == m and mask + 1 == (1 << n))
        return 0;

    lli &ans = cache[i][mask];

    if(ans != -1)
        return ans;

    lli t_mask = mask;
    for(int j = 0; j < b[i]; j ++) {
        t_mask |= (1 << c[i][j]);
    }

    ans = min(dp(i + 1, mask), dp(i + 1, t_mask) + a[i]);
    return ans;
}

void solve()
{

    memset(cache, -1, sizeof cache);
    cin>>n>>m;
    for(int i = 0; i < m; i ++) {
        cin>>a[i]>>b[i];
        for(int j = 0; j < b[i]; j ++) {
            cin>>c[i][j];
            c[i][j] --;
        }
    }

    lli ans = dp(0, 0);

    if(ans >= inf)
        ans = -1;

    cout<<ans;

    cout<<"\n";
    return ;
}

/*
*/

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

    int t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    return (x*y);
}

#define WA printf("WA\n");
int main()
{
    ll a,b,k;
    cin >> a >> b >> k;
    vll ans;
    //ll j=0;
    for(ll i=a;i<=min(a+k-1,b);i++){
        ans.push_back(i);
        //ans[j]=i;
        //j++;
    }
    for(ll i=max(a,b-k+1);i<=b;i++){
        ans.push_back(i);
        //ans[j]=i;
        //j++;
    }
    sort(all(ans));

    rep(i,SIZE(ans)){
        if(i==0)cout << ans[i] << endl;
        else if(ans[i] != ans[i-1])cout << ans[i] << endl;

    }
    return 0;
}


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

int main ()
{


string  s ;
cin >> s;
if (s=="Sunny"){
    cout <<"Cloudy";
}
 else if (s=="Cloudy")
{

    cout << "Rainy";
}
else if (s=="Rainy"){
    cout <<"Sunny";
}

return 0;
}


Measured memory_bytes: 256
// abc178_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e18)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

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

    vector<ll> v{a, b, c, d};

    ll ans = -INF;
    REP(i, 2) REP(j, 2){
        ans = max(ans, v[i] * v[2 + j]);
    }

    print(ans);

    return 0;
}


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

int main() {
  int x, y, z, n;
  cin >> x >> y >> z >> n;
  int count = 0;
  int x_c = 0;
  int y_c = 0;
  while (n - x_c * x >= 0) {
    y_c = 0;
    while (n - x_c * x - y_c * y >= 0) {
	  if ((n - x_c * x - y_c * y) % z == 0) count++;
      y_c++;
    }
    x_c++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

ll mod_pow(ll x,ll n,ll mod){
  if(n==0)return 1;
  ll res=mod_pow( x*x%mod , n/2 , mod );
  if( n & 1 )res = res*x%mod;
  return res;
}

int main(){
  ll n,a[111111];
  ll p=1e9+7;
  
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }

  ll inv[111111];
  inv[0]=0;
  ll exn=1;
  for(ll i=1;i<=n;i++){
    inv[i]=mod_pow(i,p-2,p);
    if(i>1){
	 inv[i]+=inv[i-1];
	 inv[i]%=p;
    }
    exn*=i;
    exn%=p;
  }

  
  
  ll ans=0;
  for(int i=0;i<n;i++){
    ans+=(((exn*inv[i+1])%p)*a[i])%p;
    ans%=p;
    ans+=(((exn*inv[n-i])%p)*a[i])%p;
    ans%=p;
    ans=(p+ans-(exn*a[i])%p)%p;
  }

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


Measured memory_bytes: 1792
#無限ループ.0が来たら終わる
while True:
    num = int(input())
    if num == 0:break
    else:
        #カウントするためのリストを作成し、対応する数値を増やす
        num_list = [0 for a in range(7)]
        for _ in range(num):
            i = int(input())
            if i < 10:num_list[0] += 1
            elif i < 20:num_list[1] += 1
            elif i < 30:num_list[2] += 1
            elif i < 40:num_list[3] += 1
            elif i < 50:num_list[4] += 1
            elif i < 60:num_list[5] += 1
            else:num_list[6] += 1
            
        #リストの要素を順番に出力する
        for j in range(0,7):
            print(num_list[j])


Measured memory_bytes: 5620
import heapq

def int_minus(x):
    return -1 * int(x)

n,m=map(int,input().split())
a=list(map(int_minus,input().split()))
heapq.heapify(a)
for i in range(m):
    maxa=-1 * heapq.heappop(a)
    maxa = maxa // 2
    heapq.heappush(a, -1 * maxa)
print(-1 * sum(a))

Measured memory_bytes: 14180
#include <stdio.h>
int main(){
	int n, m, c, s, d, ss[3]={-1,-1,-1}, ans=0;
	scanf("%d%d",&n,&m);
	for(int i=0; i<m; i++){
        scanf("%d%d",&s,&c);
		if( ss[s-1] != -1 && ss[s-1] != c ){ printf("-1\n"); return 0; }
		if( ss[s-1] != -1 ){ continue; }
        ss[s-1] = c;
      	if	   ( (s==3) || (s==2 && n==2) || (s==1 && n==1) ){ d=  1; }
      	else if( 		   (s==2 && n==3) || (s==1 && n==2) ){ d= 10; }
      	else if( 							  s==1 && n==3  ){ d=100; }
      	ans += (d*c);
	}
  	if	   ( (n==2 || n==3) && ss[0]==0 ){ printf("-1\n"); return 0; }
    else if(  n==2 && ans< 10 ){ ans+= 10; }
  	else if(  n==3 && ans<100 ){ ans+=100; }
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1708
#n=int(input())
#a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

s=list(input())

if s.count("A")==3 or s.count("B")==3 :
    print("No")
else:
    print("Yes")


Measured memory_bytes: 2940
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

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

int main()
{
    int n, m, ans = 0;
    cin >> n >> m;
    vector<int> obs(n);
    vector<int> good(n);
    rep(i, n) cin >> obs[i];
    rep(i, m)
    {
        int from, to;
        cin >> from >> to;
        if (obs[from-1] > obs[to-1])
        {
            if (good[from - 1] == 0) good[from - 1] = 2;
            good[to-1] = 1;
        }
        else if(obs[from - 1] < obs[to - 1])
        {
            good[from-1] = 1;
            if(good[to-1] == 0) good[to - 1] = 2;
            
        }
        else
        {
            good[from - 1] = 1;
            good[to - 1] = 1;
        }
    }

    rep(i, n) if (good[i] != 1) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4040
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <queue>
#include <deque>
#include <string>

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define rep(i, N) for (ll i = 0; i < (N); ++i)

int main()
{
    cin.tie(nullptr);

    int K;
    std::string S;
    std::cin >> K;
    std::cin >> S;
    if (S.length() > K)
    {
        std::cout << S.substr(0, K) << "..." << std::endl;
    }
    else
    {
        std::cout << S << std::endl;
    }

    return 0;
}

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

int main() {
  int N;
  cin >> N;

  int acCount = 0, waCount = 0, tleCount = 0, reCount = 0;

  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    if (s == "AC")
      acCount++;
    else if (s == "WA")
      waCount++;
    else if (s == "TLE")
      tleCount++;
    else if (s == "RE")
      reCount++;
  }

  cout << "AC x " << acCount << endl;
  cout << "WA x " << waCount << endl;
  cout << "TLE x " << tleCount << endl;
  cout << "RE x " << reCount << endl;
}

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

#define NIL (Node *)-1

struct Node {
	int key;
	Node *p, *left, *right;
	Node( int k ) { key = k; p = left = right = NIL; }
};
Node *root = NIL;

void insert( Node *z )
{
	Node *y = NIL;
	Node *x = root;
	while( x != NIL ) {
		y = x;
		if( z->key < x->key ) {
			x = x->left;
		}
		else {
			x = x->right;
		}
	}
	z->p = y;
	if( y == NIL ) {
		root = z;
	}
	else if( z->key < y->key ) {
		y->left = z;
	}
	else {
		y->right = z;
	}
}

bool find( int key )
{
	Node *x = root;
	while( x != NIL ) {
		if( key == x->key ) {
			return true;
		}
		else if( key < x->key ) {
			x = x->left;
		}
		else {
			x = x->right;
		}
	}
	return false;
}

void printp( Node *n )
{
	if( n == NIL ) return;
	cout << " " << n->key;
	printp( n->left );
	printp( n->right );
}

void printm( Node *n )
{
	if( n == NIL ) return;
	printm( n->left );
	cout << " " << n->key;
	printm( n->right );
}

int main()
{
	int m;
	cin >> m;
	for( int i = 0; i < m; i++ ) {
		string com;
		cin >> com;
		if( com == "insert" ) {
			int k;
			cin >> k;
			Node *n = new Node( k );
			insert( n );
		}
		else if( com == "print" ) {
			printm( root );
			cout << endl;
			printp( root );
			cout << endl;
		}
		else {
			int k;
			cin >> k;
			string ans = "no";
			if( find( k) ) ans = "yes";
			cout << ans << endl;
		}
	}
}



Measured memory_bytes: 21764
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();int m=sc.nextInt();
  n=Integer.parseInt(n+""+m);
  int i=0;
  for(i=0;i*i<n;i++){}
  System.out.println((i*i==n)?"Yes":"No");
}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include<math.h>
#include<string.h>
#include<vector>
using namespace std;
#define MAX 100000
#define MOD 1000000007
#define MAX_BIT 35
vector<long long int> current[10],previous[10],L;
void initialize()
{
    int i,j,k;
    long long int m=1,c;
    for(j=0;j<10;j++)
    {
        previous[j].push_back(j);
        L.push_back(j);
    }
    for(m=m*10;;m=m*10)
    {
        for(i=0;i<10;i++)
        {
            current[i].clear();
            for(j=i-1;j<=i+1;j++)
            {
                if(j<0||j>9) continue;
                for(k=0;k<previous[j].size();k++)
                {
                    c=m*i+previous[j][k];
                    current[i].push_back(c);
                    if(i>0)
                    {
                        L.push_back(c);
                        if(L.size()>MAX) return;
                    }

                }
            }
        }
        for(i=0;i<10;i++) previous[i].clear();
        for(i=0;i<10;i++)
        {
            for(j=0;j<current[i].size();j++)
            {
                previous[i].push_back(current[i][j]);
            }
        }
    }
}
int main()
{
    initialize();
    int n;
    scanf("%d",&n);
    printf("%lld",L[n]);
    return 0;
}


Measured memory_bytes: 2292