akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long int lli;
typedef long double ldb;
 
#define endl '\n'
#define loop(i, m, n) for (lli i = m; i < n; i++)
#define loope(i, m, n) for (lli i = m; i <= n; i++)
#define epool(i, m, n) for (lli i = m; i >= n; i--)
#define pool(i,m,n) for(lli i=m; i>n; i++)
#define maxe *max_element
#define mine *min_element
#define plli pair<lli, lli>
#define mod 1000000007
#define mod2 998244353
#define vt vector<lli>
#define fi first
#define se second
#define pb push_back
#define umap unordered_map
#define mmap multimap
#define mp make_pair
#define inp1(a) cin >> a
#define inp2(a, b) cin >> a >> b
#define inp3(a, b, c) cin >> a >> b >> c
#define inp4(a, b, c, d) cin >> a >> b >> c >> d
#define inp5(a, b, c, d, e) cin >> a >> b >> c >> d >> e
#define inp6(a, b, c, d, e, f) cin >> a >> b >> c >> d >> e >> f
#define pr0() cout << " "
#define pr1(a) cout << a << " "
#define pr2(a, b) cout << a << " " << b << " "
#define pr3(a, b, c) cout << a << " " << b << " " << c << " "
#define pr4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << " "
#define emp emplace //used to push a pair etc..
#define empf emplace_front
#define empb emplace_back
#define ret(x) return cout << x, 0;
#define all(v) v.begin(),v.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
//especially for deque both sides dynamic
#define pf push_front
//list doubly linked lists can insert at mid. splice fn can be used
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
using namespace std;
 
lli gcd(lli a, lli b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
 
lli lcm(lli a, lli b){
    return (a * b) / gcd(a, b);
}
 
lli modi(lli n,lli m=mod){ 
    if(n==0) return 0;
    n%=m;
    n+=m;
    n%=m;
    return n;
}
 
 
lli mpow(lli base, lli exp){
    base %= mod;
    lli result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((lli)result * base) % mod;
        base = ((lli)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

//lli dp[1005][2010][2][2];

lli f(lli* arr,lli l, lli r){
    bool sorted=1;
    loop(i,l+1,r){
        if(arr[i-1]>arr[i]){
            sorted=0;
            break;
        }
    }
    if(sorted) return r-l;
    lli mid=(l+r)/2;
    return max(f(arr,l,mid),f(arr,mid,r));
}

int32_t main(){
    fast_io
    lli i = 0,j = 0;
//   freopen("input.txt","r",stdin);
//   freopen("output.txt","w",stdout);

    lli a,b,c;
    inp3(a,b,c);
    pr3(c,a,b);
    cout << endl;

}

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

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b;
	cin >> a >> b;
	string ans;
	if(a<=0 && b>=0)ans = "Zero";
	else if(a>0 && b>0)ans = "Positive";
	else{
		ll dis = b-a + 1;
		if(dis%2==0)ans = "Positive";
		else ans = "Negative";
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

const int MAX = 100000;

long long int A[300];

int main(int argc, char *argv[])
{

  int N;
  cin >> N;

  long long int m = 100000000;

  for (int i = 0; i < N; i++) {
    long long int v = 0, a = 0;
    cin >> a;
    while ((a & 1) != 1 && a != 0) {
      v++;
      a = (a >> 1);
    }
    m = min(m, v);

    if (m == 0) {
      printf("%lld\n", m);
      return 0;
    }
  }

  printf("%lld\n", m);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
using namespace std;
const int N=1e5+5;
int n,T,c,a,ans,u[N],v[N];
int la[N*2],st[N*2],ne[N*8],to[N*8],l[N*8],h[N*2],d[N*2],js;
bool bz[N*2];
vector<int>e[N*2];
void link(int x,int y){
	ne[++js]=la[x];la[x]=js;to[js]=y;l[js]=1;
	ne[++js]=la[y];la[y]=js;to[js]=x;
}
bool get(){
	fo(i,0,T)st[i]=la[i],h[i]=-1;
	h[0]=0;d[1]=0;
	for(int s=0,t=1,x;x=d[++s],s<=t;)
		for(int i=la[x];i;i=ne[i])if(l[i]&&h[to[i]]==-1)
			h[to[i]]=h[x]+1,d[++t]=to[i];
	return h[T]>-1;
}
int dinic(int x,int su){
	if(x==T)return su;int us=0;
	for(int i=st[x];i;i=ne[i])
		if(l[i]&&h[to[i]]==h[x]+1){
			int tt=dinic(to[i],min(su-us,l[i]));
			if(tt){
				l[i]-=tt;l[i^1]+=tt;us+=tt;
				if(us==su)return us;
			}
			st[x]=i;
		}
	h[x]=-1;
	return us;
}
void dfs(int x){
	bz[x]=1;
	if(x<=n){
		for(int i:e[x])if(!bz[i])u[i-n]=x,dfs(i);
	}else{
		if(!bz[v[x-n]])dfs(v[x-n]);
	}
}
bool ck(){
	fo(i,1,n*2-1)if(!bz[i])return 0;
	return 1;
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;js=1;
	T=n+n+1;
	fo(i,1,n-1){
		cin>>c;
		link(0,i);
		fo(j,1,c){
			cin>>a;
			if(a!=1)link(i,n+a);
			e[a].push_back(n+i);
			e[n+i].push_back(a);
		}
	}
	fo(i,2,n)link(n+i,T);
	for(;get();)ans+=dinic(0,n);
	if(ans==n-1){
		fo(i,1,n-1)for(int j=la[i];j;j=ne[j])if(!l[j])v[i]=to[j]-n;
		dfs(1);
		if(ck()){
			fo(i,1,n-1)printf("%d %d\n",u[i],v[i]);
			return 0;
		}
	}
	cout<<-1;
}

Measured memory_bytes: 27520
N,A,B,C = map(int,input().split())
l = [int(input()) for i in range(N)]
INF = 10**9

def dfs(cur, a, b, c):
  if cur == N:
    if min(a,b,c) > 0:
      return abs(a-A)+abs(b-B)+abs(c-C)-30
    else:
      return INF
  ret0 = dfs(cur+1, a, b, c)
  ret1 = dfs(cur+1, a+l[cur], b, c) + 10
  ret2 = dfs(cur+1, a, b+l[cur], c) + 10
  ret3 = dfs(cur+1, a, b, c+l[cur]) + 10
  return min(ret0,ret1,ret2,ret3)

print(dfs(0,0,0,0))

Measured memory_bytes: 3064
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
aa = inpl()
used = set()
cnt = defaultdict(int)

for a in aa:
	if cnt[a] == 0:
		used.add(a)
	cnt[a] += 1

ans = 0
for n in used:
	if cnt[n] > n:
		ans += cnt[n]-n
	elif cnt[n] < n:
		ans += cnt[n]

print(ans) 


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

int main(){

  string S; cin >> S;


  long long int sum = 0;

  for(int i = 0;i <(1 << (S.size()-1));i++){

    vector<int> plus;

    int count = 0;

    for(int j = 0;j < (S.size()-1);j++){

      if((i >> j) & 1){
        plus.push_back(j+1);//+の位置を格納
        count++;
      }

    }

    for(int k = 0;k < count;k++){//ここでは文字列全体自体の値を加算していない.
      if(k == 0)sum += stoll(S.substr(0,plus[0]));//最初の+によって切り取られる部分列の値
      else sum += stoll(S.substr(plus[k-1],plus[k]-plus[k-1]));//2番目以降の+によって切り取られる部分列の値

      if(k == (count-1))sum += stoll(S.substr(plus[k],S.size()-plus[k]));//最後の+によって切り取られる部分列の値
    }


  }

  sum += stoll(S);

  cout << sum << endl;

}

Measured memory_bytes: 256
n = int(input())
s = input()
cnt = 0
for i in range(10):
    a = s.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b = s.find(str(j), a+1)
        if b == -1:
            continue
        for k in range(10):
            c = s.find(str(k), b+1)
            if c != -1:
                cnt = cnt+1
print(cnt)


Measured memory_bytes: 3060
def check():
  N = int(input())
  H = list(map(int, input().split()))
  for i in range(N-1):
    if H[i]>H[i+1]+1:
      return 'No'
    if H[i]==H[i+1]+1:
      H[i+1] += 1
  return 'Yes'
print(check())

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

int main(){
  int N;
  int ord = 30;
  int temp;
  int A;
  cin >> N;
  for(int i =0; i<N ;i++){
    temp =0;
    cin >> A;
    while(A%2 == 0){
      temp++;
      A /=2;
    }
    if(temp <= ord)
      ord = temp;
  }
  cout << ord << endl;
}
  

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if((a * b) % 2 == 0) {
			System.out.println("Even");
		}else {
			System.out.println("Odd");
		}
	}

}


Measured memory_bytes: 22740
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (b - a == c - b) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
struct edge{ll to,cost;};
const int inf = 1<<28;
const ll INF = 1LL<<53;
const int COMBMAX = 500005;
const ll MOD = 1e9+7;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;++i)
#define repf(i,n) for(int i=0;i<=n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define eachdo(v, e) for(const auto& e : v)
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (ll)distance(v.begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (ll)distance(v.begin(), upper_bound((v).begin(), (v).end(), e))
ll mpow(ll a, ll n,ll mod=MOD){ll res=1;while(n>0){if(n&1)res=res*a%mod;a=a*a%mod;n>>=1;}return res;}
template<class T1, class T2> ll bcount(T1 v, T2 a){return upper_index(v,a)-lower_index(v,a);} 
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
template<class T> void debug2(T v){rep(i,v.size()){rep(j,v[i].size())cout<<v[i][j]<<" ";cout<<endl;}}
template<class T> void rdv(T &v){rep(i,v.size())cin>>v[i];}
template<class T> void rdvv(T &v){rep(i,v.size()){rep(j,v[i].size())cin>>v[i][j];}}

int main(){
    ll N; cin >> N;
    vl a(N);rdv(a);
    ll ans = 0;
    vector<bool> used(N,false);
    for(ll num = 1LL<<33 ; 1<num ; num>>=1){
        unordered_map<ll,ll> md;// a[i]%num,そのようになる個数
        unordered_multimap<ll,ll> list;// a[i]%num、それを満たすlist
        rep(i,N){
            if (used[i] || num<=a[i]) continue;
            md[a[i] % num]++;
            list.emplace(a[i] % num,i);
        }
        eachdo(md,e){
            if(num/2<e.first) continue;
            if(!md.count(num - e.first)) continue;
            if(e.first!=num - e.first){
                ll tm = min(e.second,md[num - e.first]);
                ans += tm;
                ll cnt = 0;
                auto p = list.equal_range(e.first);
                for(auto it = p.first; it != p.second ; ++it){
                    if (cnt>=tm) break;
                    used[it->second] = true;
                    cnt++;
                }
                cnt = 0;
                auto q = list.equal_range(num - e.first);
                for(auto it = q.first; it != q.second ; ++it){
                    if (cnt>=tm) break;
                    used[it->second] = true;
                    cnt++;
                }
            }else{
                ll tm = e.second/2;
                ans += tm;
                ll cnt = 0;
                auto p = list.equal_range(e.first);
                for(auto it = p.first; it != p.second ; ++it){
                    if (cnt>=tm*2) break;
                    used[it->second] = true;
                    cnt++;
                }
            }
        }
        // rep(i,N) cout << used[i] ? 1 : 0;
        // cout << endl;
    }
    cout << ans << endl;
    return 0;
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/combine.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int64_t count_i(int64_t k, int64_t p) {
    int64_t t = 0;
    while (k % p == 0) {
        ++t;
        k /= p;
    }

    return min(t, 18L);
}

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

    vector<int64_t> a(n);
    for (auto&& aa : a) {
        double d;
        cin >> d;

        aa = llround(d * 1000000000L);
    }

    vector m(19, vector(19, 0L));
    for (auto aa : a) {
        auto b2 = count_i(aa, 2);
        auto b5 = count_i(aa, 5);

        ++m[b2][b5];
    }

    int64_t ans = 0;
    for (auto aa : a) {
        auto b2 = count_i(aa, 2);
        auto b5 = count_i(aa, 5);

        for (auto i2 : irange(18L - b2, 19L)) {
            for (auto i5 : irange(18L - b5, 19L)) {
                ans += m[i2][i5];
            }
        }

        if (b2 >= 9 && b5 >= 9) {
            --ans;
        }
    }

    assert(ans % 2 == 0);
    cout << ans / 2 << endl;
}


Measured memory_bytes: 4756
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

MOD = 1000000007

def mod_add(a, b):
  return (a+b)%MOD

def mod_sub(a, b):
  return (a+MOD-b)%MOD

def mod_mul(a, b):
  return a*b%MOD

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = (1,0,a)
    w = (0,1,b)
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return (w[0],w[1])

def mod_inv(a):
    x,_  = extgcd(a, MOD)
    return (MOD+x%MOD)%MOD

def mod_div(a, b):
    return a*mod_inv(b)%MOD

def mod_pow(a, b):
    res = 1
    while b > 0:
        if b & 1:
            res = res * a % MOD
        a = a * a % MOD
        b >>= 1
    return res

MAX = 510000

fac  = [0]*MAX
finv = [0]*MAX
inv  = [0]*MAX

def cominit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;

def mod_com(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;

#cominit()

n,k= l_in()
res = 0

m=0
l=0
for i in range(1, k):
    m += n-i+1
    l += i-1
#    print(i,m,l)

for i in range(k,n+2):
    m += n-i+1
    l += i-1
#    print(i,m,l)
    res = mod_add(res, m-l+1)

print(res)


Measured memory_bytes: 77148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define lPair pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
long long re(ll x){
    if(x % 4 == 0) return x;
    else if(x % 4 == 1) return 1;
    else if(x % 4 == 2) return x+1;
    else return 0;
}
int main(){
    ll A,B; cin >> A >> B;
    ll ans = re(B)^re(A-1);
    cout << ans << endl;
}



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

int main()
{
	static int count[4][3][10];
	int n;
	int b, f, r, v;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> b >> f >> r >> v;
		--b; --f; --r;
		count[b][f][r] += v;
	}
	for (int i = 0; i < 4; ++i) {
		for (int j = 0; j < 3; ++j) {
			for (int k = 0; k < 10; ++k) {
				cout << " " << count[i][j][k];
			}
			cout << endl;
		}
		string sh(20, '#');
		if (i < 3)
			cout << sh << endl;
	}
	return 0;
}


Measured memory_bytes: 3136
import qualified Data.Vector.Unboxed as V
import qualified Data.ByteString.Char8 as B

solve :: Int -> Int -> V.Vector Int -> Int
solve n k xs = (\t -> if null t then 0 else minimum t) $ map (\i -> dist (xs V.! i) (xs V.! (i+k-1))) [0..n-k] where
  dist x y =
    let
      l = max (-x) 0
      r = max y 0
    in
      l + r + min l r

readInt :: B.ByteString -> Int
readInt = fst . (\(Just x) -> x) . B.readInt

main = do
  [n,k] <- map readInt . B.words <$> B.getLine
  xs <- map readInt . B.words <$> B.getLine
  print $ solve n k $ V.fromList xs



Measured memory_bytes: 6524
#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
	char c = getchar();
	bool f = false;
	for (x = 0; !isdigit(c); c = getchar()) {
		if (c == '-') {
			f = true;
		}
	}
	for (; isdigit(c); c = getchar()) {
		x = x * 10 + c - '0';
	}
	if (f) {
		x = -x;
	}
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
	read(x), read(y...);
}
char s[110],g[110];
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
  scanf("%s",s+1);
  memcpy(g,s,sizeof(s));
  int n=strlen(s+1),res=n;
  for(int i=0;i<26;++i) {
    int cnt=0;
    for(int j=1;j<=n;++j) if(s[j]-'a'==i) ++cnt;
    if(!cnt) continue;
    int m=n,t=0;
    while(1) {
      bool OK=true;
      for(int j=1;j<=m;++j) {
        if(s[j]-'a'!=i) {
          OK=false;
          break;
        }
      }
      if(OK) break;
      --m; ++t;
      for(int j=1;j<=m;++j) {
        if(s[j]-'a'!=i) {
          s[j]=s[j+1];
        }
      }
    }
    res=min(res,t);
    memcpy(s,g,sizeof(g));
  }
  printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	if(N==1){
		cout << "Hello World" << endl;
	}else{
		int A,B;
		cin >> A;
		cin >> B;
		cout << A+B << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
    
        var sc = new Scanner(System.in);
    
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        var p = new int[n+1];
        for(int i = 1; i <= n; i++){
            p[i] = Integer.parseInt(sc.next());
        }
        var c = new int[n+1];
        for(int i = 1; i <= n; i++){
            c[i] = Integer.parseInt(sc.next());
        }
        
        long ans = Long.MIN_VALUE;
        var maxScore = new long[n+1];
        for(int i = 1; i <= n; i++){
            int pos = p[i];
            int move = 1;
            long score = c[pos];
            long max = score;
            maxScore[move] = max;
            while(pos != i && move < k){
                pos = p[pos];
                move++;
                score += c[pos];
                max = Math.max(score, max);
                maxScore[move] = max;
            }
            ans = Math.max(max, ans);
            if(pos == i && score > 0){
                int j = k%move;
                if(j != 0){
                    ans = Math.max(score * (k / move) + maxScore[k%move], ans);
                }else{
                    ans = Math.max(score * (k / move -1) + maxScore[move], ans);
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 43344
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int MAXM = 4e2 + 5;
const int MAXN = 26 + 5;
const ll linf = 0x3f3f3f3f3f3f3f3f;

int c[MAXN];
int a[MAXM][MAXN];

int main(void)
{
	int n=26, m;
	scanf("%d",&m);
	for(int i=1; i<=n; ++i) scanf("%d",&c[i]);
	for(int i=1; i<=m; ++i)
		for(int j=1; j<=n; ++j)
			scanf("%d",&a[i][j]);
	
	static int lst[MAXM];
	
	ll ans = 0;
	for(int k=1; k<=m; ++k)
	{
		int x;
		scanf("%d",&x);
		
		ans += a[k][x];
		for(int i=1; i<=n; ++i) if(i!=x)
			ans -= c[i] * (k-lst[i]);
		lst[x] = k;
		
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1780
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define x first
#define y second
typedef pair< int , int > Pt;
int main(){
  int m;
  while(cin >> m , m){
    vector< Pt > a(m);
    for(int i = 0 ; i < m ; i++ ) cin >> a[i].x >> a[i].y;
    int n;
    cin >> n;
    vector< Pt > all(n);
    for(int i = 0 ; i < n ; i++ ) cin >> all[i].x >> all[i].y;
    sort(a.begin(),a.end());
    sort(all.begin(),all.end());
    for(int i = 0 ; i < n ; i++ ){
      int xx = all[i].x - a[0].x, yy = all[i].y - a[0].y, j;
      for(j = 0 ; j < m ; j++ ){
        if(!binary_search(all.begin(),all.end(),Pt(a[j].x+xx,a[j].y+yy))){
          break;
        }
      }
      if(j == m){
        cout << all[i].x - a[0].x << " "  << all[i].y - a[0].y << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int memo[100001];
vector<int> V[100001];

int dfs(int A) {
	if (memo[A] != -1) return memo[A];
	int saidai = 0;
	for (int i : V[A]) {
		saidai = max(saidai, dfs(i));
	}
	memo[A] = saidai + 1;
	return memo[A];
}



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


	int N, M;
	cin >> N >> M;
	rep(i, M) {
		int x, y;
		cin >> x >> y;
		V[x].pb(y);
	}

	rep1(i, N) memo[i] = -1;

	int saidai = 0;
	rep1(i, N) {
		saidai = max(saidai, dfs(i) - 1);
	}
	co(saidai);

	Would you please return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF (1e9)
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a * b / g;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}

int N,M;

int main()
{
	int H,W;
	cin>>H>>W;
	int c[10][10];
	REP(i,0,10){
		REP(j,0,10){
			cin>>c[i][j];
		}
	}
	

	REP(k,0,10){
		REP(i,0,10){
			REP(j,0,10){
				if(c[i][j]>c[i][k]+c[k][j]){
					c[i][j]=c[i][k]+c[k][j];
				}
			}
		}
	}

	int ans=0;
	REP(i,0,H){
		REP(j,0,W){
			int A;
			cin>>A;
			if(A!=-1){
			ans+=c[A][1];
			}
		}
	}

	cout<<ans<<endl;
	
	

	return 0;
}

Measured memory_bytes: 256
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <algorithm>
#include <complex>

typedef std::complex<double> Point;
 
const double Eps = 1e-8;
 
double dot(const Point& a, const Point& b)
{
    return a.real()*b.real() + a.imag()*b.imag();
}
double cross(const Point& a, const Point& b)
{
    return a.real()*b.imag() - a.imag()*b.real();
}
double distance_line_point(const Point& point, const Point& a, const Point& b)
{
    return abs(cross(a-b, point-b) / (a-b));
}
double distance_linesegment_point(const Point& point, const Point& a, const Point& b)
{
    if (dot(b-a, point-a) < 0)
        return abs(a-point);
    else if (dot(a-b, point-b) < 0)
        return abs(b-point);
    else
        return distance_line_point(point, a, b);
}

int main()
{
    struct UFO {
        float x, y;
        float v;
        float r;
        float sita;
        float d;
    };
    
    while (true) {
        int count = 0;
        int R, N;
        std::cin >> R >> N;
        
        if (R == 0 && N == 0) {
            break;
        }
        
        std::vector<UFO> ufos(N);
        
        for (int i = 0; i < N; i++) {
            std::cin >> ufos[i].x >> ufos[i].y >> ufos[i].r >> ufos[i].v;
            ufos[i].sita = std::atan2(ufos[i].y, ufos[i].x);
            ufos[i].d = std::sqrt(ufos[i].x * ufos[i].x + ufos[i].y * ufos[i].y);
        }
        
        while (!ufos.empty()) {
            for (std::size_t i = 0; i < ufos.size(); i++) {
                ufos[i].d = std::max(ufos[i].d - ufos[i].v, 0.0f);
                ufos[i].x = std::cos(ufos[i].sita) * ufos[i].d;
                ufos[i].y = std::sin(ufos[i].sita) * ufos[i].d;
            }
            
            count += std::count_if(ufos.begin(), ufos.end(), [R](auto& elem){
                return elem.d <= R;
            });
            
            {
                auto rm_it = std::remove_if(ufos.begin(), ufos.end(), [R](auto& elem){
                    return elem.d <= R;
                });
                ufos.erase(rm_it, ufos.end());
            }
            
            std::sort(ufos.begin(), ufos.end(), [](auto& lhs, auto& rhs){
                return lhs.d < rhs.d;
            });
            
            if (ufos.empty()) {
                break;
            }
            
            float a = ufos[0].y / ufos[0].x;
            {
                
                float shot_angle = std::atan2(ufos[0].y, ufos[0].x);
                auto rm_it = std::remove_if(ufos.begin(), ufos.end(), [shot_angle, R, a, &ufos](auto& elem){
                    return distance_linesegment_point(Point(elem.x, elem.y), 
                                               Point(1e10*cos(shot_angle), 1e10*sin(shot_angle)), 
                                               Point(R*cos(shot_angle), R*sin(shot_angle))) < elem.r + Eps;
                    //return elem.r >= d + 1e-6 && (ufos[0].sita * elem.sita) >= 0;
                });
                ufos.erase(rm_it, ufos.end());
            }
        }
        printf("%d\n", count);
    }
}



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

using namespace std;
using ll = long long;
constexpr int mod = 1e9+7;
constexpr int md = mod;
int main(){
    vector<int> g(5,0);
    for(int i=0;i<4;++i){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        g[a]++;
        g[b]++;
    }
    bool ok = true;
    for(int i=0;i<4;++i){
        if(g[i] >3) ok =false;
    }
    if(ok) cout <<  "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}





Measured memory_bytes: 256
import java.util.*;
public class Main {
  	static int mod = 1000000007;
  static int size = 200001;
	static long[] fac = new long[size];
	static long[] finv = new long[size];
	static long[] inv = new long[size];
	static int INF = Integer.MAX_VALUE;
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	// 整数の入力
	int N = sc.nextInt();
  int M = N/2;
    System.out.println((double)(N-M)/N);



} 

 //fac, inv, finvテーブルの初期化、これ使う場合はinitComb()で初期化必要
	public static  void initComb(){
		fac[0] = finv[0] = inv[0] = fac[1] = finv[1] = inv[1] = 1;
		for (int i = 2; i < size; ++i) {
			fac[i] = fac[i - 1] * i % mod;
			inv[i] = mod - (mod / i) * inv[(int) (mod % i)] % mod;
			finv[i] = finv[i - 1] * inv[i] % mod;
		}
	}
 
	//nCk % mod
	public static long comb(int n, int k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
		return fac[n] * finv[k] % mod * finv[n - k] % mod;
	}
 
	//n! % mod
	public static long fact(int n){
		return fac[n];
	}
 
	//(n!)^-1 with % mod
	public static long finv(int n){
		return finv[n];
	}
  
}

Measured memory_bytes: 25940
#include<stdio.h>

int main(){

	int a[10];
	int tmp,i,j;

	// input
	for(i=0;i<10;i++){
		scanf("%d",&a[i]);
	}

	// sort
	for(i=0;i<9;i++){
		for(j=0;j<9-i;j++){
			if(a[j]<a[j+1]){
				tmp=a[j];
				a[j]=a[j+1];
				a[j+1]=tmp;
			}
		}
	}

	// output
	for(i=0;i<3;i++){
		printf("%d\n",a[i]);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
int main(){
    string S;cin >> S;
    int N = S.length()-1;
    
    //bit全探索
    ll ans = 0;
    rep(i,1<<N){
        ll a = S[0]-'0';
        ll b = 0;
        for(int bits = 0; bits < N; bits++){
            if(i & (1<<bits)){
                b += a;
                a = S[bits+1]-'0';
            }else{
                a = a*10+(int)(S[bits+1]-'0');
            }
        }
        b += a;
        ans += b;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> m(9,0);
    rep(i,n){
        int a;
        cin >> a;
        a /= 400;
        if(a>=8) a = 8;
        m[a]++;
    }
    int mi,ma;
    if(m[8]>0){
        int t = 0;
        rep(i,8){
            if(m[i]>0) t++;
        }
        mi = t;
        if(mi==0) mi = 1;
        //cout << t <<" " << m[8] << endl;
        ma = t + m[8];
    }else{
        int t = 0;
        rep(i,8){
            if(m[i]>0) t++;
        }
        mi = t;
        ma = t;
    }
    cout << mi << " " << ma << endl;
}

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

int main(void){
    long long int a, b, c, i, j, min, ans=0;
    char s[5], t[5];
    scanf("%s %s", s, t);
    if(s[0]==t[0]) ans++;
    if(s[1]==t[1]) ans++;
    if(s[2]==t[2]) ans++;
    printf("%lld", ans);
    
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
// atoi : atoi(str.c_str())
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int n;
  long h;
  cin >> n >> h;
  vector<pair<long,long>> dm(n);
  long a,b;
  rep(i,n){
    cin >> a >> b;
    dm.at(i).first = a;
    dm.at(i).second = b;
  }
  sort(dm.begin(),dm.end());
  long a_maxi = dm.at(n-1).first;
  long tmp1,tmp2;
  int sword_id = 0;
  for(int i=n-2;i>=0;i--){
    tmp1 = dm.at(i+1).first;
    tmp2 = dm.at(i).first;
    if(tmp1 != tmp2){
      sword_id = i+1;
      break;
    }
  }
  long a_maxi_b = dm.at(sword_id).second;
  vector<long> knife;
  rep(i,n){
    if(i == sword_id) continue;
    b = dm.at(i).second;
    knife.push_back(b);
  }
  sort(knife.begin(),knife.end());
  long attack = 0;
  long memo = -1;
  for(int i=n-2;i>=0;i--){
    if(knife.at(i) < a_maxi_b){
      memo = i;
      break;
    }else{
      h -= knife.at(i);
      attack++;
      if(h <= 0){
        cout << attack << endl;
        return 0;
      }
    }
  }
  long copy_h = h;
  long copy_attack = attack;
  //ALL throw
  copy_h -= a_maxi_b;
  copy_attack++;
  if(copy_h <= 0){
    cout << copy_attack << endl;
    return 0;
  }
  for(int i=memo;i>=0;i--){
    if(knife.at(i) <= a_maxi){
      break;
    }else{
      copy_h -= knife.at(i);
      copy_attack++;
      if(copy_h <= 0){
        cout << copy_attack << endl;
        return 0;
      }
    }
  }
  //not ALL
  for(int i=memo;i>=0;i--){
    if(knife.at(i) <= a_maxi){
      break;
    }else{
      h -= knife.at(i);
      attack++;
      if(h <= 0){
        cout << attack << endl;
        return 0;
      }
    }
  }
  h -= a_maxi_b;
  attack++;
  attack += (h+a_maxi-1)/a_maxi;
  cout << attack << endl;
}


Measured memory_bytes: 2936
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

int tomin(int n)
{
	return n/100*60+n%100;
}

int main()
{
	for(int n,p,q;cin>>n>>p>>q,n|p|q;){
		p=tomin(p); q=tomin(q);
		vi a(1440);
		while(n--){
			int k; cin>>k;
			vi t(1440,1);
			while(k--){
				int b,e; cin>>b>>e;
				b=tomin(b),e=tomin(e);
				repi(i,b,e)
					t[i]=0;
			}
			repi(i,p,q)
				a[i]|=t[i];
		}
		int res=0;
		for(int i=p,j=p;i<q;i=j){
			i=find(a.begin()+j,a.end(),1)-a.begin();
			j=find(a.begin()+i,a.end(),0)-a.begin();
			res=max(res,j-i);
		}
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long int;
template<typename T>
ostream& operator+(ostream& out, const vector<T> &vec){
    for(const auto &x : vec){
        out<<x<<" ";
    }
    out<<"\n";
    return out;
}
template<typename T>
ostream& operator*(ostream& out, const vector<T> &vec){
    for(const auto &x : vec){
        out+x;
    }
    return out;
}
template<typename T>
istream& operator>>(istream& in, vector<T> &vec){
    for(auto &x : vec){
        in>>x;
    }
    return in;
}
const int p = 998244353;
void solve(){
    int n,k;
    cin>>n>>k;
    vector<pair<int,int>> seq(k);
    for(auto &[u,v] : seq){
        cin>>u>>v;
    }
    vector<int> dp(n);
    dp[0] = 1;
    for(int i=1,ans=0;i<n;i++){
        for(const auto &[u,v] : seq){
            if(i-u >= 0){
                ans+=dp[i-u];
                ans>=p ? ans-=p : 0;
            }
            if(i-v-1 >= 0){
                ans-=dp[i-v-1];
                ans<0 ? ans+=p : 0;
            }
        }
        dp[i] = ans;
    }
    cout<<dp[n-1]<<"\n";
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}

Measured memory_bytes: 3988
#include <stdio.h>
#include <string.h>

int main()
{
    int A, B;
    char S[11], T[11], U[11];
    
    scanf("%s%s", S,T);
    scanf ("%d%d", &A,&B);
    scanf("%s", U);
    
    if (strcmp(S,U) == 0)
        A -= 1;
    else
        B -= 1;
    
    printf("%d %d", A,B);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1000000007;

long long mod(long long a) {
	a %= MOD;
	return a >= 0 ? a : a+MOD;
}

int main() {
	int n;
	cin >> n;
	vector<long long> A(n), S(n+1, 0);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		S[i] = mod(S[i] + A[i]);
		S[i+1] = mod(S[i+1] + S[i]);
	}
	long long ans = 0;
	for (int i = 1; i < n; i++) {
		ans = mod(ans + A[i] * S[i-1] % MOD);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6048
// Header {{{
#include <bits/stdc++.h>

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}

signed main() {
    ll n;
    cin>>n;
    map<ll,ll> m; // value -> num of value
    rep(i,0,n){
        ll a;
        cin>>a;
        m[a]++;
    }
    vector<ll> v;
    for(auto &e : m)
        if(e.second>=4){
            v.push_back(e.first);
            v.push_back(e.first);
        }else if(e.second>=2){
            v.push_back(e.first);
        }
    sort(begin(v),end(v),greater<ll>());
    if(v.size()<2)
        cout<<0<<endl;
    else
        cout<<v[0]*v[1]<<endl;
    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;
 
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()
 
 
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int k; cin >> k;
    ll ans = 0;
    for (int a = 1; a < k + 1; a++) {
        for (int b = 1; b < k + 1; b++) {
            for (int c = 1; c < k + 1; c++) {
                ans += gcd(a, gcd(b, c));
            }
        }
    }
 
    cout << ans << endl;
   
}

Measured memory_bytes: 3648
// atcoder/abc078/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

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

  lli x, y, z;
  while (cin >> x >> y >> z) {
    lli mx = 0;
    for (int i = 1; i < 100000; ++i) {
      if (y * i + (i + 1) * z <= x) {
        mx = i;
      }
    }
    cout << mx << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <string>
#include <iostream>
#include <complex>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <stack>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <random>
#include <set>
#include <vector>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#include <array>
#include <forward_list>
//#include <chrono>
#include <iomanip>
#include <utility>
#include <assert.h>

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

mt19937 gen(34);

int n, d[100000], calc[100000];
const ll mod = 998244353;

ll step(ll a, int n)
{
	ll res = 1;
	for (int i = 0; i < n; i++)
	{
		res *= a;
		res %= mod;
	}
	return res;
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> d[i];
		calc[d[i]]++;
	}
	if (d[0] != 0 || calc[0] > 1)
	{
		cout << 0;
		return 0;
	}
	for (int i = 1; i < n; i++)
		if (calc[i] != 0 && calc[i - 1] == 0)
		{
			cout << 0;
			return 0;
		}
	ll res = 1;
	for (int i = 1; i < n; i++)
	{
		res *= step(calc[i - 1], calc[i]);
		res %= mod;
	}
	cout << res;

	return 0;
}

Measured memory_bytes: 1024
s = str(input())
n = int(input())
q_list = [list(map(str, input().strip().split())) for i in range(n)]

rev = 0
for_s = ''
rev_s = ''

out = ''
for q in q_list:
    if q[0] == '1':
        rev = 1 - rev
    elif q[1] == '1':
        if rev == 0:
            rev_s += q[2]
        else:
            for_s += q[2]
    else:
        if rev == 0:
            for_s += q[2]
        else:
            rev_s += q[2]

if rev == 0:
    out = rev_s[::-1] + s + for_s
else:
    out = for_s[::-1] + s[::-1] + rev_s
print(out)


Measured memory_bytes: 40436
#include <iostream>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include "math.h"
using namespace std;



int main(){
  int N;
  int M;
  cin >> N;
  cin >> M;
  int s[5];
  int c[5];
  for (int i = 0; i < M; i++){
    cin >> s[i] >> c[i] ;
  }
  int ans = -1;
  for(int n = 0; n < pow(10,N); n++){
    bool flag = true;;
    for (int j = 0; j < M; j++){
      //s[j]桁めを取り出す
      string temp = to_string(n);

      if ((int)(temp[s[j]-1])-48 != c[j]){ flag = false;}

    }
    if (flag) {
      if ((to_string(n)).length() == N)
      {ans = n;break;}
    }

  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#[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 str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

}
use input::*;
use std::cmp;

fn main() {
    let n: usize;
    let mut max: usize = 0;
    let mut sum: usize = 0;
    input!(n);
    for _ in 0..n {
        let buf: usize;
        input!(buf);
        max = cmp::max(max, buf);
        sum += buf;
    }
    sum -= max;
    sum += max / 2;
    p(sum);
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    double seal[100][2] = {0};
    int max = 1;
    for(int i=0; i<n; i++){scanf("%lf,%lf",&seal[i][0],&seal[i][1]);}
    for(int i=0; i<n; i++){
      for(int j=i+1; j<n; j++){
	double x = seal[i][0]-seal[j][0];
	double y = seal[i][1]-seal[j][1];
	if(x*x+y*y<=4){
	  double edge = sqrt(1-(x*x+y*y)/4);
	  double vecx = y/(x*x+y*y)*edge;
	  double vecy = -x/(x*x+y*y)*edge;
	  double cx = (seal[i][0]+seal[j][0])/2;
	  double cy = (seal[i][1]+seal[j][1])/2;
	  cx+=vecx;
	  cy+=vecy;
	  int a = 0;
	  for(int k=0; k<n; k++){if((cx-seal[k][0])*(cx-seal[k][0])+(cy-seal[k][1])*(cy-seal[k][1])<=1){a++;}}
	  if(a>max){max = a;}
	  cx-=vecx*2;
	  cy-=vecy*2;
	  a = 0;
	  for(int k=0; k<n; k++){if((cx-seal[k][0])*(cx-seal[k][0])+(cy-seal[k][1])*(cy-seal[k][1])<=1){a++;}}
	  if(a>max){max = a;}
	}
      }
    }
    cout <<max<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN
#define INF         100000000000000000
#define PI          3.1415926535897932384626433832795l



#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"


// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)






// struct mycomp {
//     bool operator() (const pair<int,int> &a, const pair<int,int> &b) const{
//         if (a.second-a.first != b.second-b.first)
//         return (a.second-a.first > b.second-b.first);
//         return a.first < b.first;
//     }
// };



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


ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a%b, x1, y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}	
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while(b)
	{
		if(b%2)
		{
			b--;
			ans = (ans%mod*a%mod)%mod;
		}
		b/=2;
		a = (a%mod*a%mod)%mod;
	}
	return ans;
}


///////////////////////////BFS//////////////////////////////////
void bfs(vector<int>& distance, vector<int> a[], vector<bool>& visited, int u, vector<int>& parent)
{
	visited[u]=true;
	parent[u]=-1;
	distance[u]=0;
	queue<int> q;

	q.push(u); 
    while (!q.empty()) { 
  
        int f = q.front(); 
        q.pop(); 
  		for(int i =0; i < a[f].size(); i++)
  		{
  			if(visited[a[f][i]]==false)
  			{
  				distance[a[f][i]]=distance[f]+1;
  				parent[a[f][i]]=f;
  				visited[a[f][i]]=true;
  				q.push(a[f][i]);
  			}
  		}
    } 

}

void solve()
{

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

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	int a;
	cin>>a;
	cout<<a+a*a+a*a*a<<endl;
	return 0;
}

Measured memory_bytes: 3672
def resolve():
    n=int(input())
    a = list(map(int, input().split()))
    b=[0]*n
    c=[0]*n
    ans=0
    for i in range(n):
        b[i]=a[i]+i
    for i in range(n):
        c[i]=i-a[i]
    bc=set(b).intersection(set(c))
    bd={}
    cd={}
    for i in bc:
        bd[i]=0
    for j in b:
            if j in bc:
                bd[j]+=1
    for i in bc:
        cd[i]=0
    for j in c:
            if j in bc:
                cd[j]+=1
    ansb=list(bd.values())
    ansc=list(cd.values())
    for k in range(len(bc)):
        ans+=ansb[k]*ansc[k]
    print(ans)
resolve()

Measured memory_bytes: 166228
def main():
    n = int(input())
    md = 10 ** 9 + 7
    ##0または9を使わない組み合わせ
    tmp1 = 9 ** n % md + 9 ** n % md - 8 ** n % md
    ans = 10 ** n - tmp1
    ans %= md
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 10752
#coding:utf-8

n = int(input())

data = list(map(int, input().split()))
minv = 100000000000000000
for x in range(0, 101):
    sumv = 0
    for v in data:
        sumv += (v - x) ** 2
    minv = min(minv, sumv)
    
print(minv)

Measured memory_bytes: 2940