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

struct G{
  int group, people, now, time;
};

int main(){
  int minutes[100];
  int chair[17]; //あーじゅうななせきあった！！
  fill_n( chair, 17, 0);

  queue< G > mati;

  for(int i = 0; i < 10000; i++){
   if(i % 5 == 0 && i / 5 < 100){ //group leave
      int group = i / 5;
      mati.push((G){ group, group % 5 == 1 ? 5 : 2, i, 17 * (group % 2) + 3 * (group % 3) + 19});
    }


    while(!mati.empty()){
      G& g = mati.front();
      int count = 0, pos = -1;
      for(int j = 0; j < 17; j++){
        if(!chair[j]){
          count++;
          if(count == g.people){
            pos = j - g.people + 1;
            break;
          }
        }else{
          count = 0;
        }
      }
      if(pos != -1){
        minutes[g.group] = i - g.now;
        for(int j = pos; j < pos + g.people; j++){
          chair[j] = g.time;
        }
        mati.pop();
      } else {
        break;
      }
    }

    for(int j = 0; j < 17; j++){
      if(chair[j] > 0) chair[j]--;
    }

  }
  int n;
  while(cin >> n){
    cout << minutes[n] << endl;
  }
}

Measured memory_bytes: 1196
import java.io.IOException;
import java.io.*;
import java.util.*;


class Main {

	static class Res  
	{
		String name;
		int score;
		int index;
		Res(int i,String x, int g)
		{
			index = i;
			name = x;
			score = g;
		}
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
			FastScanner s = new FastScanner();
			int a = s.nextInt();
			
	TreeSet<Res> tree = new TreeSet<>((x, y)-> x.name.compareTo(y.name)==0?Integer.compare(y.score, x.score):x.name.compareTo(y.name));	
		
      
      
			for(int i = 0;i<a;i++)
			{
				tree.add( new Res(i+1,s.nextString(), s.nextInt()) );
			}
				
			for(Res res : tree)
				System.out.println(res.index);
			
	}

static   class FastScanner {
		
	    private InputStream mIs;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner() {
			this(System.in);
		}

		public FastScanner(InputStream is) {
			mIs = is;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = mIs.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		
		}	

	}

}


Measured memory_bytes: 28116
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll t,i,j,k,l,m,n,o,p,q,val;
    string list1,list2,s;
    cin>>s;
    val=0;
    cin>>q;
    while(q--)
    {
        cin>>k;
        if(k==1)
        {
            val++;
        }
        else if(k==2)
        {
            char c;
            cin>>p;
            if(p==1)
            {
              cin>>c;
              if(val%2==0)
              {
              list1+=c;
              }
              else 
              {
                  list2+=c;
              }
            }
            else 
            {
                cin>>c;
              if(val%2==1)
              {
              list1+=c;
              }
              else 
              {
                  list2+=c;
              }
            }
        }
    }
    reverse(list1.begin(),list1.end());
    string out=(list1+s+list2);
    if(val%2==1)
    {
        reverse(out.begin(),out.end());
    }
    cout<<out<<endl;
    return 0;
}

Measured memory_bytes: 1348
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define per(i,a,b) for(int i=b; i>=a; i--)

const int maxn = 102 ;
int n ;
int a[maxn] ;
int main()
{
    ios::sync_with_stdio(false) ; cin.tie(NULL) ;
    cin >> n ;
    rep(i,0,n-1) cin >> a[i] ;
    vector<int> v ;
    int ct = 1 ;
    a[n] = -1 ;
    rep(i,0,n-1)
    {
        if(a[i] == a[i+1])  ct++ ;
        else
        {
            v.push_back(ct) ;
            ct = 1 ;
        }
    }
    int le = v.size() ;
    int ans = 0 ;
    rep(i,0,le-1)
    {
        ans += v[i]/2 ;
    }
    cout << ans << "\n" ;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>

int main(void){
    bool sosu[100000];
    int ans[100000],q,l,r;
    ans[0]=0;
    for (int i=1; i<100000; i++){
        ans[i]=0;
        sosu[i]=true;
        for (int j=2; j<i; j++){
            if (i%j==0){
                sosu[i]=false;
                break;
            }
        }
        if (i%2!=0 && sosu[i]==true && sosu[(i+1)/2]==true){
            ans[i]=ans[i-1]+1;
        } else {
            ans[i]=ans[i-1];
        }
    }
    ans[0]=1;
    scanf("%d",&q);
    for (int i=0; i<q; i++){
        scanf("%d%d",&l,&r);
        printf("%d\n",ans[r]-ans[l-1]);
    }
	return 0 ;
}

Measured memory_bytes: 1024
n,a,b = map(int,input().split())

mod = 10**9 + 7

def comb(n,k,mod):
    if n<k:
        return 0
    if n<0 or k<0:
        return 0
    k=min(n-k,k)
    ans=1
    inv=[1]*(k+1)
    if k>=1:
        ans*=(n-k+1)%mod
    for i in range(2,k+1):
        inv[i]=mod-inv[mod%i]*(mod//i)%mod
        ans=ans*(n-k+i)*inv[i]%mod
    return ans

def comb_mod(n, r, mod):
    if n < r:
        return 0
    elif n < 0 or r < 0:
        return 0
    else:
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, n + 1):
            fac.append(fac[-1] * i % mod)
            inv.append(-inv[mod % i] * (mod // i) % mod)
            finv.append((finv[-1] * inv[-1]) % mod)
        return int(fac[n] * finv[r] * finv[n - r] % mod)

m = pow(2,n,mod) - 1

import math
def perm(n,r):
    return (math.factorial(n)//math.factorial(n-r))

s = comb(n,a,mod)
# print(s)

t = comb(n,b,mod)
# print(t)

ans = m - s - t

print(ans%mod)

Measured memory_bytes: 42876
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t;
    cin >> s >> t;
    cout << t << s << endl;

    return 0;
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  cin >>n>>m;
  int a[n];
  long long int all = 0L;

  for(int i=0;i<n;i++){
    cin >> a[i];
    all += a[i];
  }

  int num = 0;
  double th = (double)all / 4/ m;
  for(int i=0; i<n; i++){
    if(a[i] >= th) num++;
  }

  if(num >= m)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}


Measured memory_bytes: 384
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

import itertools

A = [i for i in range(1, N+1)]

T = [list(i) for i in list(itertools.permutations(A, N))]
# print(T)
n1 = T.index(P)
n2 = T.index(Q)
print(abs(n1-n2))

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

int main(){
    char S[100];
  	cin >> S;
    int N = strlen(S);
    int i,count=0;
    for(i=0;i<N/2;i++){
        if(S[i] != S[N-1-i]) count++;
    }

    cout << count << endl;
}

Measured memory_bytes: 256
N = int(input())
A_arr = list(map(lambda n: int(n), input().split()))
B_arr = list(map(lambda n: int(n), input().split()))
C_arr = list(map(lambda n: int(n), input().split()))
sum = 0

for i, a in enumerate(A_arr):
    if (i != 0) and (A_arr[i-1]+1 == a):
        sum += B_arr[a-1] + C_arr[A_arr[i-1]-1]
    else:
        sum += B_arr[a-1]

print(sum)

Measured memory_bytes: 3064
#include <iostream>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

int main() {
  int N[3],K;
  cin >>N[0]>>N[1]>>N[2]>>K;
  sort(N,N+3);
  REP(i,K) N[2]*=2;
  cout << N[0]+N[1]+N[2] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
 

  int64_t a,b,k;
  cin>>a>>b>>k;

  if(b-a+1>=k*2){
    for(int i=a;i<a+k;i++){
      cout<<i<<endl;
    }

    for(int i=b-k+1;i<=b;i++){
      cout<<i<<endl;
    }

  }else{
    for(int i=a;i<=b;i++){
      cout<<i<<endl;
    }
  }

	return 0;
}

Measured memory_bytes: 3608
n, m, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

asum = [0]
a.each do |ai|
  asum << asum.last + ai
end
asum << asum.last + k + 1

bsum = [0]
b.each do |bi|
  bsum << bsum.last + bi
end
bsum << bsum.last + k + 1

ans = 0
asum.each_with_index do |av, i|
  break if av > k
  j = bsum.bsearch_index{|x| x + av > k}
  j -= 1
  ans = [i + j, ans].max
end
puts ans


Measured memory_bytes: 45036
R = int(input())
G = int(input())

print(2 * G - R)

# 高橋君が取るべきレーティングをXと置くと　(R + X) / 2 = G となる。
# 式を変形すると　X = 2 * G - R となる。これが高橋君が取るべきレーティング。

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


from sys import stdin

############################################
#from sys import stdin
import numpy as np

# read data for n sequences.
n = int(stdin.readline())
data = np.zeros(n)
d = stdin.readline().split()
for i,x in enumerate(d):
    data[i] = int(x)

max = np.max(data)
if max >= (np.sum(data)-max):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 14428
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class E
{
	public static void Main()
	{
		int maxV = (int)1e5;
		int N = GetInt();
		long W = GetLong();
		long[] w = new long[N];
		long[] v = new long[N];
		for(int i = 0; i < N; i++)
		{
			w[i] = GetLong();
			v[i] = GetLong();
		}

		long[] dp = Enumerable.Repeat(long.MaxValue / 2, maxV + 1).ToArray();		
		dp[0] = 0;
		for(int i = 0; i < N; i++)
			for(long j = maxV - v[i]; j >= 0; j--)
				dp[j + v[i]] = Math.Min(dp[j + v[i]], dp[j] + w[i]);

		for(int i = maxV; i >= 0; i--)
		{
			if(dp[i] <= W)
			{
				Console.WriteLine(i);
				return;
			}
		}
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





Measured memory_bytes: 15712
#include <bits/stdc++.h>
using namespace std;
#define Max 100005
#define MOD 1000000007

int N,K;
vector <int> nd[Max];

long long dfs(int x,int s){
    int color_n;
    long long ret = 1;
    if(x == 1) color_n = K-1;
    else color_n = K-2;
    if(nd[x].size() > K)
        return 0;
    int t = nd[x].size();
    for(int i = 0;i< t;i++){
        if(nd[x][i] != s){
            ret *= color_n--;
            ret %= MOD;
        }

    }
    for(int i = 0;i<t;i++){
        if(nd[x][i]!=s)
            ret *= dfs(nd[x][i],x),ret %= MOD;
    }
    return ret%MOD;
}

int main () {
    ios::sync_with_stdio(false);
    cin >> N >> K;
    int t1,t2;
    for(int i = 1;i<=N-1;i++){
        cin >> t1 >> t2;
        nd[t1].push_back(t2);
        nd[t2].push_back(t1);
    }
    cout << ((long long)(K)*dfs(1,0))%MOD <<endl;
    return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    
    int p[4][3][10] = {};
    
    for (int i = 0; i < n; ++i)
    {
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        b--, f--, r--;
        p[b][f][r] += v;
    }
    
    for (int b = 0; b < 4; ++b)
    {
        for (int f = 0; f < 3; ++f)
        {
            for (int r = 0; r < 10; ++r)
            {
                cout << ' ' << p[b][f][r];
            }
            cout << endl;
        }
        if (b != 3)
        {
            for (int i = 0; i < 20; ++i)
                cout << '#';
            cout << endl;
        }
    }
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int K, N;
    cin >> K >> N;
    ll A[N];
    for(int i = 0; i < N; i++) cin >> A[i];

    ll ans = K - A[N - 1] + A[0], max_diff = K - A[N - 1] + A[0];
    for(int i = 1; i < N; i++) {
        ans += A[i] - A[i - 1];
        max_diff = max(max_diff, A[i] - A[i - 1]);
    }
    ans -= max_diff;
    cout << ans;
    return 0;
}


Measured memory_bytes: 1792
// rust input macro: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
  input!{
    a: i32, b: i32, c: i32, d: i32
  };
  
  let t1 = (c + b - 1) / b;
  let t2 = (a + d - 1) / d;
  if t1 <= t2 {
    println!("Yes");
  }else{
    println!("No");
  }
    
}

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

using namespace std;
typedef long long ll;

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

  int n, a, b;
  cin >> n >> a >> b;

  int res = min(a * n, b);
  cout << res << "\n";
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)


typedef  long long ll;
int main(){

    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string ans = "IMPOSSIBLE";
    int N,M; cin >> N >> M;
    vector <bool> start_next(N,false);
    vector <bool> end_prev(N,false);
    REP(i,M){
        int a,b;
        cin >> a >> b;
        a--;b--;
        if(a==0){
            start_next[b]=true;
        }
        if(b==0){
            start_next[a]=true;
        }
        if(a==N-1){
            end_prev[b]=true;
        }
        if(b==N-1){
            end_prev[a]=true;
        }
    }
    REP(i,N){
        if(start_next[i]==true && end_prev[i]==true){
            ans = "POSSIBLE";
        }
    }
    cout << ans <<endl;
    
}

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

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

  vector<int> r(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    r.at(a - 1) += 1;
    r.at(b - 1) += 1;
  }

  for (int i = 0; i < r.size(); i++) {
    cout << r.at(i) << endl;
  }
}


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

int main() {
  int n, cnt = 0;
  vector<int> ls;
  cin >> n;
  ls.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> ls[i];
  }
  sort(ls.begin(), ls.end());
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = j + 1; k < n; k++) {
        if (ls[i] != ls[j] && ls[j] != ls[k] && ls[k] != ls[i] &&
            ls[i] + ls[j] > ls[k]) {
          cnt++;
        }
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3616
#include<stdio.h>

int main(){

int a, b, c;

a = 1;
b = 1;

while(1){

   c = a * b;

   printf("%dx%d=%d\n", a, b, c);

   b++;

   if(b == 10){
     a++;
     b = b - 9;
   }

   if(a == 10)
     break;
  
}

 return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
const int INF = 1001001001;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define re0 return 0

int npr(int n , int r){//nPr
    r = n - r;
    int sum = 1;
    int i;
    for (i=n;i>=r+1;i--)sum*=i;
    return sum;
}
int gcd(int a, int b) {//最大公約数
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {//最小公倍数
    return a * b / gcd(a, b);
}
int digsum(int n) {//桁和
    int res = 0;
    while(n > 0) {
        //res += n%10;
        //　↑をres++;にすれば桁数
         res++;
        n /= 10;
    }
    return res;
}
bool isPrime(int x){//素数判定
    if(x==1)return 0;
    if(x==2)return 1;
    if(x%2==0)return 0;
    for(int i=3;i*i<=x;i++)if(x%i==0)return 0;
    return 1;
}
/*bit全探索
for (int bit = 0; bit < (1<<N); ++bit) {
}
if (bit & (1 << i)) {
}
*/


signed main(){ 
    string s; cin >> s;
    ll len = s.length();
    vector<int>x(len);
    rep(i,len){
        if(s[i]=='B'){
            x[i]=1;
        }else{
            x[i]=0;
        }
    }
    int now;
    if(x[0]==0){
        now=0;
    }else{
        now=1;
    }
    int cnt=0;
    for(int i=1; i<len; i++){
        if(x[i]==now){
            continue;
        }else{
            now=x[i];
            cnt++;
        }
    }
    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    int n,a,b;
    cin >> n >> a >> b;
    cout << min(n*a,b)<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> p;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define srep(i, from, to) for(int i = from; i < (int)(to); i++)
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
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;
}

vector<pair<ll, int>> primefactors(ll n) {
  vector<pair<ll, int>> res;
  int sq = sqrt(n);
  for(int x = 2; x <= sq; x++) {
    int cnt = 0;
    while(n % x == 0) {
      cnt++;
      n /= x;
    }
    res.push_back(make_pair(x, cnt));
  }
  if(n > 1) res.push_back(make_pair(n, 1));
  return res;
}
ll pfcount[100];

int main() {
  int n;
  cin >> n;
  for(int i = 1; i <= n; i++) {
    // int x = i;
    // for(int y = 2; y * y <= x; y++) {
    //   while(x % y == 0) {
    //     x /= y;
    //     pfcount[y]++;
    //   }
    // }
    // if(x > 1) pfcount[x]++;
    vector<pair<ll, int>> res = primefactors(i);
    for(auto pf : res) {
      pfcount[pf.first] += pf.second;
    }
  }

  ll ans = 0;
  // x^2 * y^4 * z^4
  for(int i = 1; i < 100; i++) {
    if(pfcount[i] < 2) continue;
    for(int j = 1; j < 100; j++) {
      if(pfcount[j] < 4) continue;
      for(int k = 1; k < 100; k++) {
        if(i == j || i == k || j == k) continue;
        if(k > j) continue;
        if(pfcount[k] < 4) continue;
        ans++;
      }
    }
  }

  // x^2 * y^24
  for(int i = 1; i < 100; i++) {
    if(pfcount[i] < 2) continue;
    for(int j = 1; j < 100; j++) {
      if(i == j) continue;
      if(pfcount[j] < 24) continue;
      ans++;
    }
  }

  // x^4 * y^14
  for(int i = 1; i < 100; i++) {
    if(pfcount[i] < 4) continue;
    for(int j = 1; j < 100; j++) {
      if(i == j) continue;
      if(pfcount[j] < 14) continue;
      ans++;
    }
  }

  // x^74
  for(int i = 1; i < 100; i++) {
    if(pfcount[i] < 74) continue;
    ans++;
  }

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


Measured memory_bytes: 256
#N = int(input())
#N, K = map(int,input().split())
#lst = [list(map(int,input().split())) for i in range(Q)]
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]

N = int(input())
D, X = map(int,input().split())
A = [int(input()) for _ in range(N)]

eaten = 0
for i in range(N):
  eaten_i = (D - 1) // A[i] + 1
  eaten += eaten_i
  
print(eaten + X)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int  x,y,z,k,s,num=0;
int main(){
	cin>>k>>s;
	for(x=0;x<=k and x<=s;x++)
		for(y=0;y<=k and y<=s-x;y++)
			if(s-x-y>=0 and s-x-y<=k)num++;
	cout<<num<<endl;
}

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

int main(){
  int k,L;
  cin >> k;
  if(k%7==0)  k/=7;
  L = 9*k;

  if(L%2==0 || L%5==0){
    cout << -1 << '\n';
    return 0;
  }

  int tmp = 10,cnt=1;
  while(1){
    if(tmp%L==1){
      cout << cnt << '\n';
      return 0;
    }
    tmp%=L;
    tmp*=10;
    cnt++;
  }
}


Measured memory_bytes: 3512
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    int n;
    cin >> n;
    vector<int> a(n+1);
    for(int i = 1; i <= n; i++) cin >> a[i];
    int ans = 0;
    for(int i = 1; i <= n; i++) if (a[a[i]] == i) ans++;
    cout << ans / 2 << endl;
}

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

int main()
{
  	vector<string> repeated;
  	repeated.push_back("111");
  	repeated.push_back("222");
  	repeated.push_back("333");
  	repeated.push_back("444");
  	repeated.push_back("555");
  	repeated.push_back("666");
  	repeated.push_back("777");
  	repeated.push_back("888");
  	repeated.push_back("999");

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

Measured memory_bytes: 256
(defparameter *ans* 1000000000000) 
(defparameter n (read))

(defun main (&optional (a 1))
        (cond ((> a (ceiling (sqrt n))) *ans*)
	      ((and (zerop (mod n a)) (< (+ a (/ n a)) *ans*)) (setf *ans* (- (+ a (/ n a)) 2)) (main (1+ a)))
              (t (main (1+ a)))))

(main)
(princ *ans*)


Measured memory_bytes: 6504
import sys
readline = sys.stdin.readline

import math

# 最短距離をワーシャルフロイドで求める
# 最短距離がL以下の街には燃料1で行けるので、辺を貼り直してワーシャルフロイド

N,M,L = map(int,readline().split())

import numpy as np
from scipy.sparse.csgraph import shortest_path
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse.csgraph import csgraph_from_dense
INF = 10 ** 9 + 1
G = [[INF for i in range(N)] for j in range(N)]
for i in range(M):
  a,b,c = map(int,readline().split())
  G[a - 1][b - 1] = c
  G[b - 1][a - 1] = c
G = csgraph_from_dense(G, null_value=INF)
d = floyd_warshall(G)

EG = [[INF for i in range(N)] for j in range(N)]
for i in range(N):
  for j in range(N):
    if d[i][j] <= L:
      EG[i][j] = 1

EG = csgraph_from_dense(EG, null_value=INF)
d = floyd_warshall(EG)

Q = int(readline())
for i in range(Q):
  s,t = map(int,readline().split())
  if d[s - 1][t - 1] != math.inf:
    print(int(d[s - 1][t - 1] - 1))
  else:
    print(-1)

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

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pt;

#define fi first
#define se second
#define dump(x) cout << #x << " = " << x << endl

li n, k, res;

int main () {
    cin >> n >> k;
    res=(n-1)*(n-2)/2;
    if (res<k) {
        cout << -1;
        return 0;
    }
    cout << n-1+(res-k) << endl;
    for(li i=2; i<n && res>k; i++) {
        for (li j=i+1; j<=n && res>k; j++) {
            cout << i << " " << j << endl;
            res--;
        }
    }
    for (li i=2; i<=n; i++) cout << 1 << " " << i << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
string s;
int K;
int n;

int dp[310][310][310];

int calc(int l, int r, int k) {
    if(dp[l][r][k] != INF) return dp[l][r][k];
    int& ret = dp[l][r][k];
    ret = 0;
    int len = r - l;
    if(len == 1) return ret = 1;
    else if(len == 2) {
        if(s[l] != s[r-1]) ret = (k > 0 ? 2 : 1);
        else ret = 2;
        return ret;
    }
    else { // len >= 3
        if(s[l] == s[r-1]) ret = calc(l+1, r-1, k) + 2;
        else {
            ret = max({ret, calc(l+1, r, k), calc(l, r-1, k)});
            if(k > 0) {
                ret = max(ret, calc(l+1, r-1, k-1) + 2);
            }
        }
    }
    return ret;
}

int main(){
    cin >> s >> K;
    n = s.size();
    rep(i, 310) rep(j, 310) rep(k, 310) dp[i][j][k] = INF;
    rep(i, n) {
        dp[i][i+1][0] = 1;
    }
    rep(i, n-1) {
        if(s[i] != s[i+1]) {
            dp[i][i+2][0] = 1;
            dp[i][i+2][1] = 2;
        }
        else {
            dp[i][i+2][0] = 2;
        }
    }
    cout << calc(0, n, K) << endl;

    return 0;
}

Measured memory_bytes: 116608
def resolve():
    N, K, C = map(int, input().split())
    S = input()

    left = [0]*N
    i = 0
    cnt = 1
    while i < N:
        if S[i] == "o":
            left[i] = cnt
            i += C
            cnt += 1
        i += 1

    right = [0]*N
    i = 0
    cnt = K
    T = S[::-1]
    while i < N:
        if T[i] == "o":
            right[i] = cnt
            i += C
            cnt -= 1
        i += 1
    right = right[::-1]

    for i in range(N):
        if left[i] == 0:
            continue
        if left[i] == right[i]:
            print(i+1)

if __name__ == "__main__":
    resolve()


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

int main()
{
	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt", "r", stdin);
 //    freopen("output.txt", "w", stdout);
	// #endif

    long long int product, i;
    cin >> product;

    long long int factor2 = 1;
    long long int factor1 = product;
    for(i = 2; i <= sqrt(product); i++)
    {
        if(product % i == 0)
        {
            factor2 = product / i;
            factor1 = i;
        }
    }
    // cout << factor1 << " " << factor2; 
    long long int ans = factor2 - 1 + factor1 - 1;
    cout << ans;
}

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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

signed main()
{
   cin.tie(nullptr);
   ios_base::sync_with_stdio(false);

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

   if(((2*sqrtl(a*b))+a+b) < c){
      cout << "Yes\n";
   }else{
      cout << "No\n";
   }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007
#define INF 1000000000
#define EPS 0.0000000001
typedef long long ll;

int main() {
  int x,y,z;
  cin >> x>>y>>z;
  vector<int> aaa={x,y,z};
  sort(aaa.begin(),aaa.end());
  
  
  
  
  cout << aaa.at(2)-aaa.at(0)<< endl;
}

Measured memory_bytes: 256
#include <stdio.h>

void insertion_sort(int *values, size_t n)
{
    for (int *elm = values + 1, *const end = values + n; elm < end; ++elm)
    {
        for (int *p = values, *const pend = p + n; p != pend; ++p)
        {
            printf("%d%c", *p, p == pend - 1 ? '\n' : ' ');
        }
        const int key = *elm;
        int *cmp;
        for (cmp = elm; cmp != values && *(cmp - 1) > key; --cmp)
        {
            *cmp = *(cmp - 1);
        }
        *cmp = key;
    }
}

int main(int argc, char *argv[])
{
    int n;
    scanf("%d", &n);
    int values[100];
    for (int *elm = values, *const end = elm + n; elm != end; ++elm)
    {
        scanf("%d", elm);
    }
    insertion_sort(values, n);
    for (int *p = values, *const pend = p + n; p != pend; ++p)
    {
        printf("%d%c", *p, p == pend - 1 ? '\n' : ' ');
    }
    return 0;
}



Measured memory_bytes: 2120
a, b, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
XYC = [list(map(int, input().split())) for _ in range(m)]

mn = min(A) + min(B)

for x, y, c in XYC:
    mn = min(mn, A[x - 1] + B[y - 1] - c)
print(mn)

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

using namespace std;

const int MAX = 1e6;
const int INF = 2e9;
typedef long long ll;

unsigned int h, w, k;
char choco[11][1002];

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

    cin >> h >> w >> k;
    for (int i = 0; i < h; ++i)
    {
        cin >> choco[i];
    }

    // check no cut
    int total = 0;
    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            if (choco[i][j] == '1') total++;
        }
    }

    if (total <= k) {
        cout << 0;
        return 0;
    }

    int minCut = INF;
    const unsigned int maxset = (1u << (h - 1u)) - 1u;
    for (unsigned int mask = maxset;
            mask ; mask = ((mask - 1) & maxset))
    {
        int groupCount = __builtin_popcount(mask);
        int cut = groupCount;
        vector<int> whites(groupCount + 1, 0);

        bool skip = false;
        int wsize = 1;
        for (int j = 0; j < w; ++j)
        {
            bool needToCut = false;
            for (unsigned int i = 0; i < h; ++i)
            {
                unsigned int wi = __builtin_popcount(mask & ((1u << i) - 1u));
                //printf("lineCount : %d, Curr Row : %d, Group No : %d\n", groupCount, i, wi);
                if (choco[i][j] == '1') {
                    whites[wi]++;
                    if (whites[wi] > k) {
                        needToCut = true;
                    }
                }
            }

            if (needToCut) {
                if (wsize == 1) {
                    skip = true;
                    break;
                }

                cut++;
                for (int m = 0; m < whites.size(); ++m) {
                    whites[m] = 0;
                }
                j--;
                wsize = 1;
            } else {
                wsize++;
            }
        }

        if (!skip) {
            minCut = min(minCut, cut);
        }
    }

    cout << minCut;

    return 0;
}


Measured memory_bytes: 256
package main
 
import (
  "fmt"
  "os"
  "bufio"
  "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
    sc.Scan()
    i, e := strconv.Atoi(sc.Text())
    if e != nil {
        panic(e)
    }
    return i
}

func main() {
  sc.Split(bufio.ScanWords)
  s := nextStr()
  n := len(s)

  for i := 0; i < n; i++ {
    fmt.Print("x")
  }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  string N;cin>>N;
  int n=N.size();
  if(n==1){
    P("Yes");
    return 0;
  }
  int m=0;
  REP(i,n){
    m+=N[i]-48;
  }
  int NN=stoi(N);
  if(NN%m){
    P("No");
  }else{
    P("Yes");
  }
  return 0;
}


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

int main() {
	int a;
	cin >> a;
	int cnt = 1;
	map<int, int> ma;
	ma[a] = 1;
	while (1) {
		if (a % 2 == 0) {
			a /= 2;
		} else {
			a = 3 * a + 1;
		}
		cnt++;

		if (ma[a] != 0) {
			break;
		} else {
			ma[a] = 1;
		}
	}

	cout << cnt << endl;
}

Measured memory_bytes: 256
n = int(input())
mat = []

for i in range(n):
    v, w, t, d, s = map(str, input().split())
    mat.append([int(v), int(w), t, int(d), s])

mat.sort()

for i in range(n):
    print(' '.join(str(m) for m in mat[i]))



Measured memory_bytes: 32928
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		sc.close();
		do {
			c -= b; // 高橋くんの攻撃
			if(c <= 0) break;
			a -= d; // 青木くんの攻撃
		} while(a > 0);
		System.out.println(a > 0 ? "Yes" : "No");
	}
}


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

int main(){
    string S;
    cin >> S;
    int ans = 0;
    int ren = 0;
    for (int i = 0; i < 3; i++) {
        if (S[i] == 'R') ren++;
        else ren = 0;
        ans = max(ans, ren);
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3620
a = ("a".."z").to_a
b = Array.new(26, 0)

while x = gets
  x = x.downcase
  x.chars { |i|
    for j in 0..25
      i == a[j] && b[j] += 1
    end
  }
end

a.size.times { |c|
  puts "#{a[c]} : #{b[c]}"
}

Measured memory_bytes: 8708
N = int(input())
s = 0
t = 0
u = 0
v = 0
for i in range(N):
    m = input()
    u += m.count("AB")
    if m[0] == "B" and m[-1] == "A":
        v += 1
    else:
        if m[0] == "B":
            s += 1
        if m[-1] == "A":
            t += 1
if s == 0 and t == 0 and v != 0:
    u += v - 1
    print(u)
elif s == 0 or t == 0:
    u += v
    print(u)
else: 
    u += min(s - 1, t - 1) + v + 1
    print(u)

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

using ll = long long;

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

    int n; cin >> n;
    int a[n]; for (int i = 0; i < n; ++i) cin >> a[i];
    deque<int> b;

    for (int i = 0; i < n; ++i) {
        if (i % 2 == (n - 1) % 2) {
            b.push_front(a[i]);
        } else {
            b.push_back(a[i]);
        }
    }

    string ans;
    for (int v : b) {
        ans.append(to_string(v));
        ans.push_back(' ');
    }
    ans.pop_back();

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5892
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
#define int lint
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
map<int, int> m;
int count(int n)
{
    int res = 0;
    for (auto i = m.begin(); i != m.end(); i++)
    {
        if (i->second >= (n - 1))
        {
            res++;
        }
    }
    return res;
}
signed main()
{
    int n;
    cin >> n;
    repi(i, 2, n + 1)
    {
        int copy = i;
        for (int j = 2; j * j <= copy; j++)
        {
            while (copy % j == 0)
            {
                m[j]++;
                copy /= j;
            }
        }
        if (copy != 1)
        {
            m[copy]++;
        }
    }
    int ans;
    ans = count(75) + count(25) * (count(3) - 1) + count(15) * (count(5) - 1) + count(5) * (count(5) - 1) * (count(3) - 2) / 2;
    cout << ans << endl;
    return 0;
}

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

static const int IINF = 1 << 30;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

int main() {
  // Input
  std::string S;
  int K;
  int N;
  std::cin >> S;
  std::cin >> K;
  N = S.length();

  // Initialization
  auto dp = vectors<int>(1 + N + 1, 1 + N + 1, 1 + K + 1, -IINF);
  // auto dp = vectors<int>(1 + N + 1, 1 + N + 1, 1 + K + 1, 0);

  // Initial condition
  // dp[0][0][0] = 0;
  for (int k = 0; k <= K; ++k)
    dp[0][0][k] = 0;

  // DP main
  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j <= N; ++j) {
      for (int k = 0; k <= K; ++k) {
        chmax(dp[i + 1][j][k], dp[i][j][k]);
        chmax(dp[i][j + 1][k], dp[i][j][k]);
        chmax(dp[i + 1][j + 1][k + 1], dp[i][j][k] + 1);
        if (i < N and k < N and S[i] == S[N - j - 1])
          chmax(dp[i + 1][j + 1][k], dp[i][j][k] + 1);
      }
    }
  }

  // Output
  int res = -1;
  for (int i = 0; i <= N; ++i)
    chmax(res, 2 * dp[i][N - i][K]);
  for (int i = 0; i < N; ++i)
    chmax(res, 2 * dp[i][N - i - 1][K] + 1);

  std::cout << res << std::endl;

  return 0;
}


Measured memory_bytes: 111104
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__)
inline char nc()
{
	return getchar();
	static char buf[100000], * l = buf, * r = buf;
	if(l == r) r = (l = buf) + fread(buf, 1, 100000, stdin);
	if(l == r) return EOF;
	return *l++;
}
template<class T> void readin(T & x)
{
	x = 0; int f = 1, ch = nc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
	x *= f;
}
const int mod = 1e9 + 7;
long long quick_power(long long x, long long y)
{
	long long res = 1;
	while(y)
	{
		if(y & 1) res = res * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int n, a[100050];
int f[100050], g[100050], h[100050];
void solve()
{
	f[0] = 1;
	g[0] = 0;
	for(int i = 1; i <= n; i++)
	{
		f[i] = 1ll * f[i - 1] * i % mod;
		g[i] = (1ll * g[i - 1] * (i + 1) % mod + f[i]) % mod;
	}
	h[n] = quick_power(f[n], mod - 2);
	for(int i = n - 1; ~ i; i--)
	{
		h[i] = 1ll * h[i + 1] * (i + 1) % mod;
	}
	for(int i = 1; i <= n; i++)
	{
		g[i] = 1ll * g[i] * f[n] % mod * h[i + 1] % mod;
	}
	int ans = 0;
	for(int i = 1; i <= n; i++)
	{
		ans += 1ll * ((f[n] + g[i - 1]) % mod + g[n - i]) % mod * a[i] % mod;
		ans %= mod;
	}
	cout << ans << endl;
}
int main()
{

	readin(n);
	for(int i = 1; i <= n; i++)
	{
		readin(a[i]);
	}
	solve();
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

ll MX=200000;
vvl G(MX,vl());
vl ans(MX);

void dfs(ll i,ll p=-1){
  for(auto v:G[i]){
    if(v==p){
      continue;
    }
    ans[v] +=ans[i];
    dfs(v,i);
  }
}

int main() {
  ll n,q;
  cin >> n >> q;
  rep(i,n-1){
    ll a,b;
    cin >> a >> b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  rep(i,q){
    ll p,x;
    cin >> p >> x;
    p--;
    ans[p]+=x;
  }
  dfs(0);
  rep(i,n){
    cout << ans[i] << " " << endl;
  }
}

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

const int MOD = 1000000007;
const int INF = 1000000000;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

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; }


int main(){
int N;
cin >> N;
vector<int>A(N);
REP(i, N) cin >> A[i];
int dp[N];
dp[0] = 0;
dp[1] = abs(A.at(1) - A.at(0));
for(int i = 2; N > i; i++){
  int a, b;
    a = dp[i - 2] + abs(A.at(i) - A.at(i - 2));
    b = dp[i - 1] + abs(A.at(i) - A.at(i - 1));
    dp[i] = min(a, b);
}
print(dp[N - 1]);

}




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

int N;
vector<int> T;
vector<int> A;
vector<int> ma;
vector<int> mi;
int main(){
  cin >> N;
  T.resize(N);
  A.resize(N);
  ma.resize(N);
  mi.resize(N);
  REP( i, N )
    cin >> T[i];
  REP( i, N )
    cin >> A[i];
  REP( i, N ){
    ma[i] = min( T[i], A[i] );
  }
  int pre = -1;
  REP( i, N ){
    if( pre < T[i] ){
      mi[i] = T[i];
    }else{
      mi[i] = 1;
    }
    pre = T[i];
  }
  pre = -1;
  REP( i, N ){
    if( pre < A[N-i-1] ){
      mi[N-i-1] = max( mi[N-i-1], A[N-i-1] );
    }
    pre = A[N-i-1];
  }
  long long ans = 1;
  long long M = 1e9+7;
  REP(i,N){
    //    cout << "(" << ma[i] << "," << mi[i] << ") ";
    if( ma[i] - mi[i] + 1 <= 0 ) ans *= 0;
    ans *=  ma[i] - mi[i] + 1;
    ans %= M;
  }
  //  cout << endl;
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>

int main()
{
    int i,j,len,check[3]={0,0,0};
    char s[4];
    
    len=scanf("%s",s);
    
    for(i=0;i<3;i++)
    {
        switch(s[i])
        {
        case 'a':
            j=0;
            break;
        case 'b':
            j=1;
            break;
        default:
            j=2;
            break;
        }
        if(check[j] == 0)
        {
            check[j] = 1;
        }
        else
        {
            break;
        }
    }
    if(i == 3)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	int n;
	int p[9],q[9];
	cin>>n;
	int t=1;
	ll a=0,b=0;
	int f1[9]={},f2[9]={};
	rep(i,n){
		cin>>p[i+1];
		t*=i+1;
	}
	rep(i,n)cin>>q[i+1];
	for(int i=1; i<n+1; i++){
		t/=n-i+1;
		for(int j=p[i]-1; j>0; j--){
			if(f1[j]==0)a+=t;
		}
		for(int j=q[i]-1; j>0; j--){
			if(f2[j]==0)b+=t;
		}
		f1[p[i]]=1;
		f2[q[i]]=1;
	}
	cout<<labs(a-b)<<endl;
	return 0;
}


Measured memory_bytes: 256
n,m,q = map(int,input().split())

lr = [[0 for i in range(n)] for j in range(n)]
for i in range(m) :
    l,r = map(int,input().split())    
    lr[l-1][r-1] = lr[l-1][r-1] + 1

#for l in lr :        
#    print(l)
#print()

# 二次元累積和
for i in range(n) :
    for j in range(n) :
        left = 0
        btm  = 0
        mid  = 0

        if i > 0 :
            left = lr[j][i-1]
        if j > 0 :
            btm  = lr[j-1][i]
        if i > 0 and j > 0 :
            mid  = lr[j-1][i-1]
       
        lr[j][i] = lr[j][i] + left + btm - mid

#for l in lr :        
#    print(l)

ans=[] 
for i in range(q) :
    l,r = map(int,input().split())

    l = l - 1
    r = r - 1
    pre = 0
    if l > 0:    
        #print(lr[r][r],lr[l-1][r],lr[r][l-1],lr[l-1][l-1])
        pre = lr[l-1][r] + lr[r][l-1] - lr[l-1][l-1]     

    count = lr[r][r] - pre
    ans.append(count)

for a in ans:
    print(a)

Measured memory_bytes: 17692