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

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define fo(i, a, b, k) for(int i = a; i <= b; i += k)
#define _fo(i, a, b, k) for(int i = a; i >= b; i -= k)
#define foa(i, a) for (auto &i : a)
#define fod(i, a) for(int i = 1; i*i <= a; i++)
#define sz(a) ((int) a.size())
#define all(a) begin(a), end(a)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mk(x, y) make_pair(x, y)  
#define log2i(x) (31-__builtin_clz(x))
#define log2ll(x) (63-__builtin_clzll(x)) 
#define msz(x) __builtin_popcount(x) 
#define mszll(x) __builtin_popcountll(x) 
#define fom(i, a, b) for(int i = a; i < (1<<b); i++)
#define ifon(i, mask) if(mask&(1<<i))
#define ss(i, mask) while(i=(i-mask)&mask)
#define ifss(i, mask) if(i > (mask^i)) 

typedef struct pos {
	int left, right, up, down;
} pos;

const int MAX = 2e3+5;

char grid[MAX][MAX];
pos p[MAX][MAX];
int h, w;

void precompute() {
	fo(i, 1, h, 1) {
		p[i][0].left = 0;
		fo(j, 1, w, 1) p[i][j].left = (grid[i][j] == '#') ? j : p[i][j-1].left;
	}
	fo(i, 1, h, 1) {
		p[i][w+1].right = w+1;
		_fo(j, w, 1, 1) p[i][j].right = (grid[i][j] == '#') ? j : p[i][j+1].right;
	}
	fo(i, 1, w, 1) {
		p[0][i].up = 0;
		fo(j, 1, h, 1) p[j][i].up = (grid[j][i] == '#') ? j : p[j-1][i].up;
	}		
	fo(i, 1, w, 1) {
		p[h+1][i].down = h+1;
		_fo(j, h, 1, 1) p[j][i].down = (grid[j][i] == '#') ? j : p[j+1][i].down;
	}
}

int solve() {
	int ans = 0;
	fo(i, 1, h, 1) {
		fo(j, 1, w, 1) {
			if(grid[i][j] == '#') continue;
			int temp = (p[i][j].right-p[i][j].left-1)+(p[i][j].down-p[i][j].up-1)-1;
			ans = max(ans, temp);			
		}
	}
	return ans;
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin >> h >> w;
	fo(i, 1, h, 1)
		fo(j, 1, w, 1) cin >> grid[i][j];
		
	precompute();
	cout << solve();
}

Measured memory_bytes: 66944
program main
    use,intrinsic :: iso_fortran_env
    implicit none

    integer(int32) :: n, i
    integer(int32),allocatable :: a(:)
    integer(int32),allocatable :: x(:)
    integer(int32) :: s

    read *, n
    allocate(a(n))
    read *, (a(i), i = 1, n)
    allocate(x(n))

    s = 0
    do i = 1, n
        s = ieor(s, a(i))
    enddo

    do i = 1, n
        x(i) = ieor(s, a(i))
    enddo

    print '(*(i0,:,1x))', (x(i), i = 1,n)

end program main


Measured memory_bytes: 6836
#include <iostream>

using namespace std;



int main() {
	long long int i, n, t,a,min=1e10,max=0,cos=0;
	cin >> n >> t;
	for (i = 0; i < n; i++) {
		cin >> a;
		if (a < min)min = a;
		if (a - min == max)cos++;
		else if (a - min > max) {
			max = a - min;
			cos = 1;
		}
	}
	
	cout <<cos<< endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections


n = int(input())
a = list(map(int,input().split()))
n1 = 0
n2 = 0
n4 = 0
for i in range(n):
    if a[i]%4 == 0:
        n4+=1
    elif a[i]%2 == 0:
        n2 +=1
    else:
        n1+=1

if n2 == 1:
    n2 = 0

if n4*2 + n2 >= n or n4*2 + 1 == n:
    print("Yes")
else:
    print("No") 

Measured memory_bytes: 14636
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

const int N = 5e5 + 5;

int n;
char s[N];
int L[N], R[N];

int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1) + 1;
	for (int i = 1; i <= n; i++)
		L[i] = (s[i - 1] == '<') * (L[i - 1] + 1);
	for (int i = n; i; i--)
		R[i] = (s[i] == '>') * (R[i + 1] + 1);
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += max(L[i], R[i]);
//		cerr << max(L[i], R[i]) << ' ';
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
const long long mod=1000000007;

long long f(int n,int k){
  long long s;
  s=((n-k+1)%mod)*(k%mod);
  s=(s+1)%mod;
  return s;
}
int main() {
  int n,k;
  long long ans=0;
  cin>>n>>k;
  for(int i=k;i<=n+1;i++){
  	ans=(ans+f(n,i))%mod;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3616
#include <stdio.h>
int absolute(int a,int b) {
  if (a < b) {
    return b - a;
  } else {
    return a - b;
  }
}
int main() {
  int A[3];
  scanf("%d %d %d",&A[0],&A[1],&A[2]);
  int ans[6];
  ans[0] = absolute(A[0],A[1]) + absolute(A[1],A[2]);
  ans[1] = absolute(A[0],A[1]) + absolute(A[0],A[2]);
  ans[2] = absolute(A[0],A[2]) + absolute(A[1],A[2]);
  ans[3] = absolute(A[0],A[2]) + absolute(A[1],A[0]);
  ans[4] = absolute(A[1],A[2]) + absolute(A[0],A[2]);
  ans[5] = absolute(A[1],A[2]) + absolute(A[0],A[1]);
  int i;
  int temp = ans[0];
  for (i = 0;i < 5;++i) {
    if (temp > ans[i]) {
      temp = ans[i];
    }
  }
  printf("%d\n",temp);
  return 0;
}

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

answer = 0
number_of_digits = len(str(N))

total = 0
for nth in range(1, number_of_digits + 1):
    is_odd = nth % 2 is 1
    if not is_odd: continue
    number_of_intergers = (10 ** ((nth - 1))) * 9
    total += number_of_intergers

    if 10 ** nth -1 >= N:
        total -= 10 ** number_of_digits - 1 - N

print(total)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <complex>
#include <algorithm>
#include "limits.h"
#include <queue>
#include <sstream>
#include <bitset>
#define INF 1e18
#define FL(i,j,k) for(int i=j;i<k;++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> ii;
typedef complex<int> pt;

ll A[100000],B[100000];
int main(){
    int n;scanf("%d",&n);
    for(int i=n-1;i>=0;--i){
        scanf("%lld%lld",A+i,B+i);
    }
    ll sum=0;
    FL(i, 0, n){
        if((sum+A[i])%B[i]==0)continue;
        else sum+=(B[i]-(A[i]+sum)%B[i]);
    }
    printf("%lld",sum);
}

Measured memory_bytes: 1792
def main():
    N = int(input())
    A = input()
    B = input()
    C = input()
    ans = 0
    for i in range(N):
        if A[i] == B[i] != C[i] or \
            A[i] != B[i] == C[i] or \
                A[i] == C[i] != B[i]:
            ans += 1
        elif A[i] != B[i] != C[i]:
            ans += 2
    print(ans)


main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;

int main()
{

    char a, b;
    cin >> a >> b;
    int ia = a - '0';
    int ib = b - '0';

    string aa, bb;
    REP(i, ib)
    aa += a;
    REP(i, ia)
    bb += b;

    int ra = atoi(aa.c_str());
    int rb = atoi(bb.c_str());

    if (ra > rb)
    {
        Cout(ra);
    }
    else
        Cout(rb);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":"\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
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;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------
 
signed main() {
    string s;
    cin>>s;
    char t=s[0];
    bool ok=1;
    REP(i,3) {
        if(s[i]!=t) {
            ok=0;
            break;
        }
    }
    t=s[3];
    bool ok2=1;
    REP(i,3) {
        if(s[i+1]!=t) {
            ok2=0;
            break;
        }
    }
    if(ok || ok2) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
gets.to_i.times do |i|
    r, t = gets.split.map(&:to_f)
    arr = Array.new
    arr.push((t / 30).floor * 5 + ((r - 100) / 100).floor + 1)
    arr.push((t / 30).floor * 5 + ((r - 100) / 100).ceil + 1)
    arr.push((t / 30).ceil * 5 + ((r - 100) / 100).floor + 1)
    arr.push((t / 30).ceil * 5 + ((r - 100) / 100).ceil + 1)
    puts arr.uniq.join(" ")
end

Measured memory_bytes: 8724
#include "bits/stdc++.h"
using ll = long long;
#define ALL(a)  begin((a)),end((a))
#define REP(y) for(ll i=0;i<(y);i++)

using namespace std;
int main(){
ll n;
cin>>n;
vector<ll> a(n);
REP(n)cin>>a[i];
sort(ALL(a));
cout<<a.back()-a[0]<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
unsigned long long i,j,n,m,x,k,y,a,b;
int main()
{
    std::cin.sync_with_stdio(false);
    std::cin.tie(0);
    cin >> n;
    i=1;
    while (i<=n&&i<10)
    {
        cout << i << "\n";
        i++;
    }
    m=9;
    x=10;
    while (i<=n)
    {
        m+=x;
        cout << m << "\n";
        k=m+x;
        y=0;
        while (k>0)
        {
            y+=k%10;
            k/=10;
        }
        a=m+x*10;
        b=0;
        while (a>0)
        {
            b+=a%10;
            a/=10;
        }
        //cout << m+x*10 << " " << y << " " << m+x << " " << b << "\n";
        if ((m+x*10)*y<=(m+x)*b)
        {
            x*=10;
        }
        i++;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>

using namespace std;

int main(){
  string w,t;
  int ans = 0;
  
  cin >> w;
  transform( w.begin(), w.end(), w.begin(), ::toupper);
  while(true){
    cin >> t;
    if( t == "END_OF_TEXT"){
      break;
    }
    transform( t.begin(), t.end(), t.begin(), ::toupper);
    if( w == t){
      ++ans;
    }
  }
  cout << ans << endl;
  return  0;
}

Measured memory_bytes: 3116
a = readline.chomp.split("").map(&:to_i)
s = a.size
k = [0, *a]
r = k.zip(k.reverse).all?{|(i,j)| i == j}
unless a[0] == 1 && a[s-2] == 1 && a[s-1] == 0 && r
    puts -1
    exit
end

pc = 2
nc = 2
res = []
res << [1, 2]
a[1..s-2].each{|k|
    if k == 0
        nc += 1
        res << [pc, nc]
    else
        res << [pc, nc + 1]
        pc = nc + 1
        nc = nc + 1
    end
}

res.each{|(i, j)|
    puts "#{i} #{j}"
}

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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int main( ) {
        IO;
        #ifdef LOCAL
            //freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        int len , k;
        cin >> len >> k;
        string s;
        cin >> s;
        s[k-1] -= 'A' , s[k-1] += 'a';
        cout << s << endl;
        return 0;
}










Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    int n;
    cin>>n;
    int front = n / 100;
    int back = n % 100;
    if(front == 0 && back == 0){
        cout<<"NA"<<endl;
    }else if(front == 0 && back > 12){
        cout<<"NA"<<endl;
    }else if(back == 0 && front > 12){
        cout<<"NA"<<endl;
    }else if(front == 0 && back <= 12){
        cout<<"YYMM"<<endl;
    }else if(back == 0 && front <=12){
        cout<<"MMYY"<<endl;
    }else if(front <= 12 && back <= 12){
        cout<<"AMBIGUOUS"<<endl;
    }else if(front <= 12 && back > 12){
        cout<<"MMYY"<<endl;
    }else if(back <= 12 && front > 12){
        cout<<"YYMM"<<endl;
    }else if(back > 12 && front >12){
        cout<<"NA"<<endl;
    }


    return 0;
}


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

const int mod=1e9+7;

ll L,R;

ll f[64][2][2][2][2];
int l[100],r[100];

ll dfs(int x,int fl,int fr,int s,int ht)
{
	if(x<0)return 1;
	
	ll &ans=f[x][fl][fr][s][ht];
	if(ans)return ans;
	
	for(int i=0;i<2;i++)//y
	{
		for(int j=0;j<2;j++)//x
		{
			int tl=fl,tr=fr,ts=s,tt=ht;
			if(!tt&&i)if(i!=j)continue;
			if((j&i)!=j)continue;
			if(!tl&&j<l[x])continue;
			if(!tr&&i>r[x])continue;
			if(!ts&&j>i)continue;
			if(j>l[x])tl=1;if(i<r[x])tr=1;if(j<i)ts=1;if(j)tt=1;
			ans+=dfs(x-1,tl,tr,ts,tt);
		}
	}
	ans%=mod;
	return ans;
}

int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	cin>>L>>R;
	for(int i=63;i>=0;i--)
	{
		l[i]=(bool)((1ll<<i)&L);r[i]=(bool((1ll<<i)&R));
	}
	
	cout<<dfs(63,0,0,0,0);
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
//#include"../bits/stdc++.hpp"
//
#include <vector>
//#include <string>

using namespace std;

void Cont(){
    int R;
    cin >> R;
    cout << (R * 3.1415 * 2);
}


int main()
{
//	std::cin.tie(nullptr);
//    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Cont();
}





Measured memory_bytes: 3780
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main () {
	int argA, argB;
	cin >> argA >> argB;

	float ret = ((float)argA + (float)argB) / 2.0f;
	cout << ceil(ret) << endl;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

bool era[252525];

int main(){
  REP(i,252525)era[i]=true;
  era[0]=false;
  era[1]=false;
  vi ps(10000);
  int psiter = 0;
  FOR(i,2,252525){
    if(!era[i])continue;
    ps[psiter] = i;
    psiter++;
    if(psiter==10000)break;
    int iter = 2*i;
    while(iter < 252525){
      era[iter] = false;
      iter += i;
    }
  }
  vi sum(10000);
  REP(i,10000)sum[i]=ps[i];
  REPR(i,10000)sum[i]+=sum[i-1];
  while(true){
    int n;
    cin>>n;
    if(n==0)break;
    cout<<sum[n-1]<<endl;
  }
  return 0;
}

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> snake(n);
    for (int i = 0; i < n; i++){
        cin >> snake[i];
    }
    sort(snake.begin(),snake.end());
    reverse(snake.begin(),snake.end());

    int ans = 0;
    for (int i = 0; i < k; i++){
        ans += snake[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
D = [len(set(LIST()))==1 for _ in range(N)]
for i in range(N):
    if sum(D[i:i+3]) == 3:
        print("Yes")
        break
else:
    print("No")


Measured memory_bytes: 10048
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define PB push_back
#define MAXN 100005
#define MP make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define SQ(a) (a)*(a)
#define nl "\n"
#define INF std::numeric_limits<int>::max()
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
ll mod=1000000009;
int t[4*MAXN],n;
void build(int a[],int v,int tl,int tr){
	if( tl == tr) t[v] = a[tl];
	else{
		int tm = (tl + tr)/2;
		build(a,2*v,tl,tm);
		build(a,2*v+1,tm+1,tr);
		t[v] = min(t[2*v],t[2*v+1]);
	}
}

int min(int v,int tl,int tr,int l,int r){
	if(l > r){
		return INF - 1;
	}	
	if(l == tl && r == tr)
		return t[v];
	else{
		int tm = (tl + tr)/2;
		return min(min(2*v,tl,tm,l,min(tm,r)),min(2*v+1,tm+1,tr,max(tm+1,l),r));
	}
}

void update(int v,int tl,int tr,int pos,int new_val){
	if(tl == tr){
		t[v] = new_val;
	}
	else{
		int tm = (tl + tr)/2;
		if(pos<=tm)
			update(2*v,tl,tm,pos,new_val);
		else update(2*v+1,tl,tm,pos,new_val);
		t[v] = min(t[2*v],t[2*v+1]);
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	string s[n];
	map<string,int> mp;
	int mx = 0,mxi=-1;
	rep(i,0,n-1){
		cin>>s[i];
		if(mp[s[i]]>0)
		mp[s[i]]++;
		else mp[s[i]] = 1;
		if(mp[s[i]]>mx){
			mx = mp[s[i]];
			mxi = i;
		}
	}
	set<string> all;
	rep(i,0,n-1){
		if(mp[s[i]] == mx){
			all.insert(s[i]);
		}
	}
	for(auto x:all)cout<<x<<nl;
	return 0;
}






Measured memory_bytes: 34816
#include <iostream>
#include <math.h>
using namespace std;

int main() {
	int n, k,a,b;
	a = 1;
	b = 1;
	cin >> n >> k;
	if (n == 1) {
		cout << k << endl;
	}
	else {
		for (int i = 0; i <  n- 1; i++) {
			b*=(k - 1);
		}
		cout << b*k << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long a[200010];

const int MOD = 1000000007;

long long modpow(long long x, long long pow) {
    if (pow == 0)return 1;
    long long ret = modpow(x, pow / 2);
    ret *= ret, ret %= MOD;
    if (pow % 2 == 1)ret *= x, ret %= MOD;
    return ret;
}

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

    long long count = 0;
    for (long long i = 0; i < n; i++) count += a[i], count %= MOD;
    count *= count, count %= MOD;

    long long acount = 0;
    for (long long i = 0; i < n; i++) {
        long long koo = a[i] * a[i] % MOD;
        acount -= koo;
        if (acount < 0)acount += MOD;
    }

    count += acount, count %= MOD;

    long long ret = count * modpow(2, MOD - 2);
    cout << ret % MOD << endl;
    return 0;
}

Measured memory_bytes: 5152
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main(){
    int N, X;
    cin >> N;
    cin >> X;
    int m[110];
    int min = 1001;
    for(int i = 1;i <= N;i++){
        cin >> m[i];
        if(m[i] < min)min = m[i];
        X -= m[i];
    }
    cout << X / min + N;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) < (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;
using unit= unsigned;
using ull = unsigned long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vvi = vector<vi>;
using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
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; }
template<class T>T gcd(T a, T b){ if (b==0){ return a; }else{ return gcd(b, a%b); }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
constexpr double eps = 1e-10;
constexpr int inf = INT_MAX / 2;
constexpr ll infl = 1LL << 60;

void _main() {
  int N;
  cin >> N;
  vl A(N);
  rep(i, 0, N) cin >> A[i];
  sort(all(A));

  ll ans;
  ostringstream oss;

  if (0 <= A[0]) {
    ans = A[0];
    rep(i, 1, N-1) {
      oss << ans << " " << A[i] << endl;
      ans -= A[i];
    }
    oss << A[N-1] << " " << ans << endl;
    ans = A[N-1] - ans;
  } else if (A[N-1] <= 0) {
    ans = A[N-1];
    rrep(i, N-2, 0) {
      oss << ans << " " << A[i] << endl;
      ans -= A[i];
    }
  } else {
    ll sum_plus = A[N-1];
    ll sum_minus= A[0];
    int i = 1;
    for (; A[i] < 0; ++i) {
      oss << sum_plus << " " << A[i] << endl;
      sum_plus -= A[i];
    }
    for (; i < N-1; ++i) {
      oss << sum_minus << " " << A[i] << endl;
      sum_minus -= A[i];
    }
    oss << sum_plus << " " << sum_minus << endl;
    ans = sum_plus - sum_minus;
  }

  cout << ans << endl;
  cout << oss.str();
}

Measured memory_bytes: 6148
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    a,b=map(int, input().split())
    print((a+b+1)//2)

main()

Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int minimize(int a, int b){
    int ans = a;
    if (a > b){
        ans = b;
    }
    return ans;
}
int maximize(int a, int b){
    int ans = a;
    if (a < b){
        ans = b;
    }
    return ans;
}

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

    int ans = A * X + B * Y;

    for (int i = 0; i <= (maximize(X, Y)); i ++){
        int sum = A * maximize(0, X - i) + B * maximize(0, Y - i) + C * i * 2;
        if (sum < ans){
            ans = sum;
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
def solve():
  X = raw_input()
  Y = raw_input()
  a = len(X)
  b = len(Y)
  c1 = [0 for i in range(b+1)]
 
  for i in range(a):
    c2 = c1 + []
    for j in range(b):
      if X[i] == Y[j]:
        c1[j+1] = c2[j] + 1
      elif c1[j+1] < c1[j]:
        c1[j+1] = c1[j]
 
  return c1[-1]
 
n = input()
for k in range(n):
  print solve()

Measured memory_bytes: 6400
n, k = map(int, input().split())
a = list(map(int, input().split()))
dir = a[0]
hash_a = [0 for _ in range(n)]
hash_a[0] = 1
cnt = 0
two = 0
while True:
    k -= 1
    cnt += 1
    if k == 0:
        break
    dir = a[dir - 1]
    if hash_a[dir - 1] == 0 or hash_a[dir - 1] == 1 or hash_a[dir - 1] == 2:
        hash_a[dir - 1] += 1
        if hash_a[dir - 1] == 2:
            two += 1
    elif hash_a[dir - 1] == 3:
        k = (k + cnt) - (cnt - (two * 2))
        k %= two
        hash_a = [-k for _ in range(n)]
print(dir)

Measured memory_bytes: 32404
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using uint = unsigned int;

int main() {

	string Day;
	cin >> Day;

	vector<string> D = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
	auto itr = find(D.begin(), D.end(), Day);
	uint ans = distance(itr, D.end());
	cout << ans;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);

/* -----  2019/06/29  Problem: ABC 132 E / Link: http://abc132.contest.atcoder.jp/tasks/abc132_e  ----- */


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

	LL N, M; cin >> N >> M;
	VVI G(N);
	FOR(i, 0, M) {
		int a, b; cin >> a >> b;
		a--, b--;
		G[a].push_back(b);
	}
	using tp = tuple<LL, LL, LL>;
	priority_queue<tp, vector<tp>, greater<tp>>pq;
	VVL dist(N, VL(3, LINF));
	auto IFPUSH = [&](LL d, int mod, int nx) {
		if (dist[nx][mod] > d) {
			dist[nx][mod] = d;
			pq.push(tp(d, mod, nx));
		}
	};
	int S, T; cin >> S >> T;
	S--, T--;
	IFPUSH(0, 0, S);

	while (!pq.empty()) {
		LL di, m, v;
		tie(di, m, v) = pq.top(); pq.pop();
		if (dist[v][m] < di)continue;
		for (auto nx : G[v]) {
			LL nxd = di + (m % 3 == 0);
			LL nxm = (m + 1) % 3;
			IFPUSH(nxd, nxm, nx);
		}
	}
	LL ans = dist[T][0];
	if (ans == LINF)ans = -1;
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 11264
n = int(input())
a = [int(x) for x in input().split()]
preMin = [a[0]]
for i in range(1,n):
    preMin.append(min(preMin[-1],a[i]))
ans = 1
for i in range(1,n):
    if a[i]<preMin[i-1]:
        ans+=1
print(ans)

Measured memory_bytes: 26012
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define int long long
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int bit[100010],n;

int mx(int i){
	int s = 0;
	while(i>0){
		s = max(s,bit[i]);
		i -= i& -i;
	}
	return s;
}

void add(int i,int x){
	while(i<=n){
		bit[i] = max(bit[i],x);
		i += i& -i;
	}
}



signed main(){
	cin >> n;
	vector<int>v(n);
	int ans = 0;
	rep(i,n){
		cin >> v[i];
		ans += v[i];
	}
	rep(i,n){
		int tmp = mx(v[i]);
		add(v[i],tmp+v[i]);
	}
	int m=0;
	rep(i,n){
		m = max(m,mx(i+1));
	}
	cout << ans - m << endl;
	return 0;
}


Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int main(){
	int A,B,H;
	cin>>A>>B>>H;
        cout<<(A+B)*H/2<<endl;
	return(0);
}

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

const double eps=1e-11;
int main(){
    int k;
    double r,l;
    cin>>k>>r>>l;
    double p,e,t;
    cin>>p>>e>>t;
    p=1-p;
    function<double(int,double,double)> dfs=[&](int i,double lb,double ub){
        if(ub+e<t+eps) return 0.0;
        if(t-eps<lb-e) return 0.0;
        if(t-e-eps<lb && ub<t+e+eps) return 1.0;
        double mid=(lb+ub)/2;
        if(i==k) return abs(mid-t)<=e+eps ? double(1.0) : double(0.0);
        if(mid<=t+eps){
            return p*dfs(i+1,mid,ub)+(1-p)*dfs(i+1,lb,mid);    
        }
        else{
            return (1-p)*dfs(i+1,mid,ub)+p*dfs(i+1,lb,mid);    
        }
    };
    cout<<fixed<<setprecision(10);
    cout<<dfs(0,r,l)<<endl;

    return 0;
}


Measured memory_bytes: 3288
import sys

if __name__ == '__main__':
    N, K = map(int, sys.stdin.readline().split())
    S = sys.stdin.readline()
    # ans = 0
    # for i in range(N-1):
    #     if S[i] == S[i+1]:
    #         ans += 1
    ans = N - 1 - S.count('LR') - S.count('RL')
    ans = min(N-1, ans+K*2)
    print(ans)


Measured memory_bytes: 38768
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
  int i,j;
  int n,m;
  while(cin>>n>>m,n||m){
    int a[1000];
    int imn,tmn,fmn;
    for(i=0;i<n;++i){
      cin>>a[i];  
      if(i){
	for(j=0;a[i]*(j+1)<=m;++j);
	if(0){
	}else if(a[i]*j<tmn){
	  imn=i;
	  tmn=a[i]*j;
	  fmn=0;
	}else if(a[i]*j==tmn){
	  if(0){
	  }else if(a[imn]>a[i]){
	    imn=i;
	    fmn=0;
	  }else if(a[imn]==a[i]){
	    fmn=1;
	  }
	}
      }else{
	for(j=0;a[i]*(j+1)<=m;++j);
	imn=i;
	tmn=a[i]*j;
	fmn=0;
      }
    }
    if(fmn){
      cout<<n<<endl;
    }else{
      cout<<imn+1<<endl;
    }
  }
  return 0;
}

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

int main(){
    char a[5],sat[]="SAT",sun[]="SUN",mon[]="MON",tue[]="TUE",wed[]="WED",thu[]="THU",fri[]="FRI";
    
    scanf("%s",a);
    
    if(strcmp(a,sat)==0){
        printf("1\n");
    }
    
    else if(strcmp(a,sun)==0){
        printf("7\n");
    }
    
    else if(strcmp(a,mon)==0){
        printf("6\n");
    }
    
    else if(strcmp(a,tue)==0){
        printf("5\n");
    }
    
    else if(strcmp(a,wed)==0){
        printf("4\n");
    }
    
    else if(strcmp(a,thu)==0){
        printf("3\n");
    }
    
    else if(strcmp(a,fri)==0){
        printf("2\n");
    }
    
    
    return 0;
}

Measured memory_bytes: 128
N = int(input())
xy = [[int(_) for _ in input().split()] for i in range(N)]

xsort_n = sorted(range(N), key=lambda n:xy[n][0])
ysort_n = sorted(range(N), key=lambda n:xy[n][1])

from collections import defaultdict

neighbors = defaultdict(list)

for i in range(N - 1):
    x1 = xsort_n[i]
    x2 = xsort_n[i+1]
    xd = xy[x2][0] - xy[x1][0]
    y1 = ysort_n[i]
    y2 = ysort_n[i+1]
    yd = xy[y2][1] - xy[y1][1]
    neighbors[x1].append((x2, xd))
    neighbors[x2].append((x1, xd))
    neighbors[y1].append((y2, yd))
    neighbors[y2].append((y1, yd))

from heapq import *

isused = [0] * N

h = []

heappush(h, (0, 0))

result = 0

while h:
    d, n = heappop(h)
    if isused[n]:
        continue
    result += d
    isused[n] = 1
    for ni, nd in neighbors[n]:
        if not isused[ni]:
            heappush(h, (nd, ni))
    
print(result)


Measured memory_bytes: 85796
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int x,a,b;
	cin>>x>>a>>b;
	x -=a;
	while(x >= b){
		x -=b;
	}
	cout<<x<<endl;
}


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

int main(){
  int A[10000]={0};
  int n,cnt=0;
  std::cin>>n;
  for(int i=0;i<n;i++){
    std::cin>>A[i];
  }
  for(int i=0;i<n;i++){
    double q=sqrt(A[i]);
    if((A[i]==2)||(A[i]==3)){
      cnt++;
    }else{
      for(int j=1;j<=(int)q;j++){
	if((A[i]%j==0)&&(j>=2)){
	  break;
	}
	if((j==(int)q)&&(A[i]%j!=0)){
	  cnt++;
	}
      }
    }
  }
  std::cout<<cnt<<"\n";
  return 0;
}


Measured memory_bytes: 3104
#include<stdio.h>

int main(void){
	char mark,tkt;
	int i, x, y, s, t[52];
	for(i = 0;i < 52;i++){
			t[i] = 0;
	}
	//0~12=S 13~25=H 26~38=C 39~51=D
	scanf("%d",&x);
	for(i = 0;i < x+1;i++){
		scanf("%c %d%c",&mark,&s,&tkt);
		switch (mark){
		case('S'):
			t[s-1] = 1;
			break;
		case('H'):
			t[s + 12] = 1;
			break;
		case('C'):
			t[s + 25] = 1;
			break;
		case('D'):
			t[s + 38] = 1;
			break;
		}
	}
		for(i = 0;i < 52;i++){
			if(t[i] == 0){
				y = i / 13;
				if(y == 0){
					printf("S %d\n",i % 13 + 1);
				}if(y == 1){
					printf("H %d\n",i % 13 + 1);
				}if(y == 2){
					printf("C %d\n",i % 13 + 1);
				}if(y == 3){
					printf("D %d\n",i % 13 + 1);
				}
			}
		}
	
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

set<pair<long, long> > done;
set<pair<long, long> > black;
map<int, int> ans;
long long H, W, N;

bool valid(int x, int y){
	return (x >= 0 && x < W - 2 && y >= 0 && y < H - 2);
}

int count(int x, int y){
	int ret = 0;
	for(int i = 0; i < 3;i++){
		for(int j = 0; j < 3; j++){
			if(black.count(make_pair(x+i, y+j))){
				ret++;
			}
		}
	}
	//cout << "x=" << x << " y= " <<y << endl;
	//cout << "ret =" << ret << endl;
	return ret;
}

int main(){
	cin >> H >> W >> N;
	for(int i = 0; i < N; i++){
		long y, x;
		cin >> y >> x;
		y--;x--;
		black.insert(make_pair(x, y));
	}

	for(auto po: black){
		long x = po.first;
		long y = po.second;
		for(int i = -2; i <= 0; i++){
			for(int j = -2; j <= 0; j++){
				if(valid(x+i, y+j) && done.count(make_pair(x+i, y+j)) == 0){
					ans[count(x+i, y+j)]++;
					done.insert(make_pair(x+i, y+j));
				}
			}
		}

	}

	long long tmp = 0;
	for(int i = 1; i < 10; i++){
		tmp += ans[i];
	}

	cout <<(H - 2)* (W - 2) - tmp << endl;

	for(int i = 1; i < 10; i++){
		tmp += ans[i];
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 62720
#include <bits/stdc++.h>
using namespace std;
#define endl            "\n"
#define ll                long long
#define all(v)            ((v).begin()), ((v).end())
#define sz(v)            ((int)((v).size()))
#define clr(v, d)        memset(v, d, sizeof(v))
#define rep(i, v)        for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define vi                vector <int>
#define vl                vector <ll>
#define ii                pair <ll,ll>
#define vii                vector <ii>
const double PI = 2 * acos(0.0);
void run() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
}
const int M = 1e5;
int n, m;
vi g[M + 3];
bool vis[M + 3];
int cnt[M + 3];
int dfs(int node) {
	vis[node] = 1;
	int &ret = cnt[node];
	for (int i : g[node]) {
		if (!vis[i])
			ret = max(ret, dfs(i) + 1);
		else
			ret = max(ret, cnt[i] + 1);
	}
	return ret;
}
int main() {
	run();
	cin >> n >> m;
	lp(i,m)
	{
		int x, y;
		cin >> x >> y;
		g[x].push_back(y);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = max(ans, dfs(i));
		//cout << i << " >> " << dfs(i) << endl;
	}
	cout << ans;
}


Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = 10101010;

int n,x[3];
int l[8];

ll ans = INF;
int dfs(int d, vector<int> v){
    if(d==n){
        rep(i,3)if(v[i]==0) return INF;

        int res = 0;
        rep(i,3) res += abs(x[i]-v[i]);
        return res;
    }

    int ret = INF;
    // use
    rep(i,3){
        vector<int> nv(v);
        int add = 10;
        if(nv[i]==0) add = 0;

        nv[i] += l[d];
        ret = min(ret, dfs(d+1,nv)+add);
    }

    // not use
    ret = min(ret, dfs(d+1,v));
    return ret;
}


int main(){
    cin >>n;
    rep(i,3) cin >>x[i];
    rep(i,n) cin >>l[i];

    vector<int> v(3);
    cout << dfs(0,v) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
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;
}
signed main() {
    int D;cin>>D;
    int C[26];rep(i,26)cin>>C[i];
    int S[D+1][26];
    rep(i,D){
        rep(j,26)cin>>S[i+1][j];
    }
    int t[D+1];
    rep(i,D){
        cin>>t[i+1];
        t[i+1]--;
    }
    int score=0;
    for(int i=1;i<=D;i++){
        score+=S[i][t[i]];
        rep(j,26){
            int now=0;
            for(int k=1;k<=i;k++){
                if(t[k]==j)chmax(now,k);
            }
            score-=C[j]*(i-now);
        }
        cout<<score<<endl;
    }
}



Measured memory_bytes: 3692
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vl vector<ll>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll m, d, c, ans = 0;
  std::cin >> m;
  deque<ll> q;
  std::vector<ll> ne(10, 0), time(10, 0);
  for(int i=0;i<=9;i++){
    ll o = i + i;
    ne[i] = o/10 + o%10;
    time[i] = (o>=10?2:1);
  }
  for(int i=0;i<m;i++){
    std::cin >> d >> c;
    ll now = d;
    deque<ll> p;
    while(c>0){
      if(c%2==1) p.push_back(now);
      ans+=c/2*time[now];
      now = ne[now];
      c/=2;
    }
    while(p.size()!=1){
      ll a = *(--p.end());
      p.pop_back();
      ll b = *(--p.end());
      p.pop_back();
      if(a+b>=10) p.push_back(1),p.push_back((a+b)%10);
      else p.push_back(a+b);
      ans++;
    }
    ll nokori = *p.begin();
    //std::cout << nokori << " " << ans << '\n';
    q.push_back(nokori);
  }

  while(q.size()!=1){
    ll a = *(--q.end());
    q.pop_back();
    ll b = *(--q.end());
    q.pop_back();
    if(a+b>=10) q.push_back(1),q.push_back((a+b)%10);
    else q.push_back(a+b);
    ans++;
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1792
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort()
high = max(a)*max(f)
low = 0
while high > low:
  mid = (high+low)//2
  b = 0
  for i in range(n):
    b += max(a[i]-mid//f[n-i-1],0)
  if b > k:
    low = mid + (low==mid)
  else:
    high = mid - (high==mid)
mid = (high+low)//2
print(mid)

Measured memory_bytes: 119500
import sys
input = sys.stdin.buffer.readline

N = int(input())
S = input()
ans = 0
for i in range(0, 1000):
    k = str(i).zfill(3)
    dic = {0: False, 1: False, 2: False}
    for t in str(S):
        if dic[0] is False:
            if t == k[0]:
                dic[0] = True
        else:
            if dic[1] is False:
                if t == k[1]:
                    dic[1] = True
            else:
                if dic[2] is False:
                    if t == k[2]:
                        dic[2] = True
                        ans += 1
                        break
                else:
                    ans += 1
                    break

print(ans)


Measured memory_bytes: 59868
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;

        //static int N;
        static string S, T;
        

        public static void Input()
        {
            var cin = new Scanner();
            S = Console.ReadLine();
            T = Console.ReadLine();
        }

        static void Main(string[] args)
        {
            Input();
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            string ans = "UNRESTORABLE";
            if (S.Length >= T.Length)
            {
                List<string> ss = new List<string>();

                for (var i = 0; i <= S.Length - T.Length; i++)
                {
                    string tt = S.Substring(i, T.Length);
                    bool same = true;
                    for (var j = 0; j < tt.Length; j++)
                    {
                        if (tt[j] != '?' && tt[j] != T[j])
                        {
                            same = false;
                            break;
                        }
                    }

                    if (same)
                    {
                        var c = new StringBuilder();
                        for (var j = 0; j < S.Length; j++)
                        {
                            if (j == i)
                            {
                                c.Append(T);
                                j += T.Length - 1;
                            }
                            else if (S[j] == '?')
                            {
                                c.Append('a');
                            }
                            else
                            {
                                c.Append(S[j]);
                            }
                        }
                        ss.Add(c.ToString());
                    }
                }
                if (ss.Count() > 0)
                {
                    ss.Sort();
                    ans = ss[0];
                }
            }

            Console.WriteLine(ans);
            //Console.Out.Flush();
        }

        
    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }

    }

    public class Graph
    {
        
    }
}

    



Measured memory_bytes: 13408
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
using namespace std;

int main(){
    vector<int> a(5);
    while(~scanf("%d,%d,%d,%d,%d", &a[0], &a[1], &a[2], &a[3], &a[4])){
	sort(a.begin(), a.end());
	if(count(a.begin(), a.end(), a[3]) == 4){
	    cout << "four card" << endl;
	}
	else if(count(a.begin(), a.end(), a[0]) + count(a.begin(), a.end(), a[4]) == 5){
	    cout << "full house" << endl;
	}
	else if(count(a.begin(), a.end(), a[2]) == 3){
	    cout << "three card" << endl;
	}
	else if(count(a.begin(), a.end(), a[1]) + count(a.begin(), a.end(), a[3]) == 4){
	    cout << "two pair" << endl;
	}
	else{
	    
	    for(int i = 0;i < 5;i++){
		if(count(a.begin(), a.end(), a[i]) == 2){
		    cout << "one pair" << endl;
		    goto done;
		}
	    }
	    if(a[0] == 1 && a[1] == 10 && a[2] == 11 && a[3] == 12 && a[4] == 13){
		cout << "straight" << endl;
		goto done;
	    }
	    for(int i = 0;i < 5;i++){
		if(a[i] != a[0] + i)break;
		if(i == 4){
		    cout << "straight" << endl;
		    goto done;
		}
	    }
	    cout << "null" << endl;
	}
    done :;
    }
}

Measured memory_bytes: 1220
#include "bits/stdc++.h"
using namespace std;

int main(){
    int a , b , g;
    scanf( "%d%d" , &a , &b );
    g = __gcd( a , b );
    long long l;

    l = ( a * 1LL * b ) / g;
    printf( "%lld\n" , l );
    return 0;
}

Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_B
// Sort II - Partition

#define SUBMIT

#include <utility>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <limits>
#include <numeric>
#include <set>
#include <cmath>
#include <cstring>

using namespace std;
using i64 = long long;

const int MAX_N = 100000;
int A[MAX_N + 1];

int partition(int p, int r) {
    auto x = A[r];
    auto i = p - 1;
    for (int j = p; j < r; ++j) {
        if (A[j] <= x) {
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i + 1], A[r]);
    return i + 1;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> A[i];

    auto q = partition(0, n - 1);
    for (int i = 0; i < n; ++i) {
        if (i != q) cout << A[i];
        else cout << "[" << A[i] << "]";

        if (i != n - 1) cout << " ";
        else cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3372
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string s,t;
  cin >> N >> s >> t;
  string ans;
  for(int i=0; i<=N; i++){
    ans = s.substr(0,i) + t;
    if(ans.substr(0,N) == s && ans.substr(i,N) == t){
      cout << ans.size() << endl;
      return 0;
    }
  }
}

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

using pii = pair<int, int>;
using vi = vector<int>;
using ll = long long;

int main() {
    int n;
    cin >> n;
    map<string, int> cnt;
    for(int i = 0; i < n; ++i) {
        string s; int m;
        cin >> s >> m;
        cnt[s] += m;
    }
    vector<pair<string, int>> res;
    for(auto& p : cnt) {
        res.push_back(p);
    }
    sort(begin(res), end(res), [](auto const& p1, auto const& p2) {
        return p1.first.size() < p2.first.size() || p1.first.size() == p2.first.size() && p1.first < p2.first;
    });
    for(auto& p : res) {
        cout << p.first << ' ' << p.second << endl;
    }
}


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

using namespace std;

int main() {
  int N, R;
  cin >> N >> R;
  
  if (N >= 10) {
    cout << R << endl;
  } else {
    cout << R + (100 * (10 - N)) << endl;
  }
  
}

Measured memory_bytes: 3572
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
int a, b, c;
int t[5];

int main() {
	while(~scanf("%d %d %d", &a, &b, &c)) {
		int cnt = 0;
		t[1] = a, t[2] = b, t[3] = c;
		sort(t + 1, t + 4);
		int max = t[3];
		int tmp = t[3] - t[2];
		cnt += tmp;
		int tmp0 = t[3] - (t[1] + tmp);
		if(tmp0 & 1) {
			cnt += tmp0 / 2;
			cnt += 2;
		}
		else cnt += tmp0 / 2;
		printf("%d\n", cnt);
	}
	return 0;
}

Measured memory_bytes: 128