akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
import sys
sys.setrecursionlimit(50000000)
max_c=101
vec=[(0,2),(2,0),(0,-2),(-2,0)]
try:
    while True:
        log=[-1 for i in range(10001)]
        n,x0,y0,t=map(int,input().split())
        field=[[0 for i in range(max_c)]for i in range(max_c)]
        for i in range(n):
            a,b,c,d=map(lambda x:int(x)*2,input().split())
            if b==d:
                field[b][min(a,c):max(a,c)+1]=[1 for i in range(max(a,c)+1-min(a,c))]
            else:
                for p in field[min(b,d):max(b,d)+1]:
                    p[a]=1
        a,b=-1,-1
        pt=0
        for i in range(t):
            a,b=input().split()
            a=int(a)+pt
            pt=a
            b='NESW'.find(b)
            log[a]=b
        end_t=pt
        end_v=b
        ans=[]
        memo=set({})
        def check(t,x,y,v):
            if t>end_t or (log[t]!=-1 and not((v+2)%4!=log[t])) or ((t,x,y,v) in memo):
                return
            memo.add((t,x,y,v))
            if t==end_t:
                ex,ey=vec[end_v]
                if v==end_v or 0<=y+ey//2<=100 and 0<=x+ex//2<=100 and field[y+ey//2][x+ex//2]==1 and (v+2)%4!=end_v:
                    ans.append((x,y))
                return
            if log[t]!=-1 and v==log[t] or log[t]==-1:
                i=0
                for mx,my in vec:
                    if i==(v+2)%4:
                        i+=1
                        continue
                    nx,ny=x+mx,y+my
                    if 0<=nx<=100 and 0<=ny<=100 and field[ny-my//2][nx-mx//2]==1:
                        check(t+1,nx,ny,i)
                    i+=1
            elif log[t]!=-1:
                i=0
                for mx,my in vec:
                    if i!=log[t]:
                        i+=1
                        continue
                    nx,ny=x+mx,y+my
                    if 0<=nx<=100 and 0<=ny<=100 and field[ny-my//2][nx-mx//2]==1:
                        check(t+1,nx,ny,i)
                    i+=1
        
        for i in range(4):
            check(0,x0*2,y0*2,i)
        
        for q in sorted(set(ans)):
            print(q[0]//2,q[1]//2)
except:
    pass


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

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
#define vvint(N,M) vector<vector<int>>

typedef struct{
  int i;
  int j;
  int depth;
}data;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H,W;
  cin >> H >> W;
  char A[H+2][W+2];
  for(int i = 0; i < H+2;i++){
    for(int j = 0; j < W+2;j++){
      A[i][j] = '#';
    }
  }

  queue<data> q;

  for(int i = 0; i < H;i++){
    for(int j = 0; j < W;j++){
      cin >> A[i+1][j+1];
      if(A[i+1][j+1]  == '#'){
        data tmp = {i+1,j+1,0};
        q.push(tmp);
      }
    }
  }
  
  int ans = 0;
  data tmp, dt;
  while(!q.empty()){
    dt = q.front();
    q.pop();
    //ans = max(ans,dt.depth);
    if(A[dt.i-1][dt.j] == '.'){
      A[dt.i-1][dt.j] = '#';
      tmp = {dt.i-1,dt.j,dt.depth+1};
      q.push(tmp);
    }
    if(A[dt.i][dt.j-1] == '.'){
      A[dt.i][dt.j-1] = '#';
      tmp = {dt.i,dt.j-1,dt.depth+1};
      q.push(tmp);
    }
    if(A[dt.i+1][dt.j] == '.'){
      A[dt.i+1][dt.j] = '#';
      tmp = {dt.i+1,dt.j,dt.depth+1};
      q.push(tmp);
    }
    if(A[dt.i][dt.j+1] == '.'){
      A[dt.i][dt.j+1] = '#';
      tmp = {dt.i,dt.j+1,dt.depth+1};
      q.push(tmp);
    }
  }
  ans = tmp.depth;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 13328
use std::cmp;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn bellman_ford(graph: &[Vec<(usize, i64)>]) -> Option<i64> {
    let mut dists = vec![1 << 60; graph.len()];
    dists[1] = 0;
    for _ in 0..graph.len() {
        for i in 1..graph.len() {
            for r in graph[i].iter() {
                dists[r.0] = cmp::min(dists[r.0], dists[i] + r.1)
            }
        }
    }

    let v = -dists[graph.len() - 1];
    for _ in 0..graph.len() {
        for i in 1..graph.len() {
            for r in graph[i].iter() {
                dists[r.0] = cmp::min(dists[r.0], dists[i] + r.1)
            }
        }
    }
    if v < -dists[graph.len() - 1] {
        None
    } else {
        Some(v)
    }
}

fn main() {
    let (n, m) = scan!(usize, usize);
    let mut graph = (0..n + 1)
        .map(|_| vec![])
        .collect::<Vec<Vec<(usize, i64)>>>();
    for _ in 0..m {
        let (a, b, c) = scan!(usize, usize, i64);
        graph[a].push((b, -c));
    }

    if let Some(v) = bellman_ford(&graph) {
        println!("{}", v);
    } else {
        println!("inf");
    }
}


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

using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define THINK_TWICE_CODE_ONCE cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define to_str to_string
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n)  ((n)? (ll)(log10(n)+1) : 1)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double dd;
typedef string str;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef pair<int, int> pii;

int main()
{
    THINK_TWICE_CODE_ONCE
    //freopen("test cases\\.txt", "r", stdin) ;
    ll n; cin>>n;
    ll m = (n / 500) * 2 * 500 + ((n%500)/5)*5;
    cout<<m;
    return 0;
}







Measured memory_bytes: 256
N,M = [int(i) for i in input().split()]
switches = []
for i in range(M):
    buff = 0
    k,*sss = [int(i) for i in input().split()]
    for s in sss:
        buff += 1 << (s-1)
    switches.append(buff)

ppp = [int(i) for i in input().split()]
ans = 0
for i in range(1<<N):
    for p,s in zip(ppp,switches):
        buff = s&i
        buff = bin(buff).count("1")%2
        if buff != p:
            break
    else:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <set>

using namespace std;


int main(){

    int n;
    cin>>n;
    set<string> tmp;
    for(int i=0;i<n;i++){
        string a;
        cin>>a;
        tmp.insert(a);
    }

    printf("%d\n",tmp.size());

    return 0;
}

Measured memory_bytes: 19288
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    ll x,y,z,k;
    cin>>x>>y>>z>>k;
    ll a[x],b[y],c[z];
    rep(i,x)cin>>a[i];
    rep(i,y)cin>>b[i];
    rep(i,z)cin>>c[i];
    vector<ll> cur;
    rep(i,x)rep(j,y){
        cur.push_back(a[i]+b[j]);
    }
    sort(cur.rbegin(),cur.rend());
    if(cur.size()>k)cur.resize(k);
    vector<ll> res;
    rep(i,cur.size())rep(j,z){
        res.push_back(cur[i]+c[j]);
    }
    sort(res.rbegin(),res.rend());
    rep(i,k){
        cout<<res[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 43236
num = int(input())

n_list = list(map(int,input().split()))

sum1 = 0
sum2 = 0
sa_list = list()
for j in range(1,num):
    sum1 = sum(n_list[0:j])
    sum2 = sum(n_list[j:num])
    sa = sum1 - sum2
    if sa < 0:
        sa = -sa
    sa_list.append(sa)
    sa = 0

print(min(sa_list))


Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef map<int, int> Mii;
typedef vector<int> Vi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

struct sol{
	int n, s, ti, wr[20];
	sol(){};
	bool operator<(const sol& rhs) {
		if (s == rhs.s) 
			if (ti == rhs.ti) {
				return n > rhs.n;
			} else 
				return  ti < rhs.ti;
		return s > rhs.s;
	}
};
sol x[55];

int main()
{
	while (1) {
		int M, T, P, R;
		cin >> M >> T >> P >> R;
		if (M==0) break;
		memset(x, 0, sizeof(x));
		rep(i,0,T) x[i].n = i+1;

		rep(i,0,R) {
			int m, t, p, j;
			cin >> m >> t >> p >> j;
			t--;
			if (j==0) {
				x[t].s++;
				x[t].ti += m + x[t].wr[p];
			}
			else {
				x[t].wr[p] += 20;
			}
		}
		sort(x, x+T);
		cout << x[0].n;
		rep(i,1,T) {
			if (x[i].s == x[i-1].s && x[i].ti == x[i-1].ti) cout << "=";
			else cout << ",";
			cout << x[i].n;
		}
		cout << endl;
	}

	return 0;
}

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

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
inline string numstr(int m){str s="";while(m>0){char c;int a=m/10;if(a>0)a=m%(a*10);else a=m;c=(char)('0'+a);s+=c;m/=10;}str st="";for(int i=s.size()-1;i>=0;i--){st+=s[i];}return st;}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,num[100005],cop[100005];
    cin >> a >> b;
    rep(i,0,a){
        cin >> num[i];
        cop[i]=num[i];
    }
    int ans=0;
    if((num[0]+num[1])>b){
        int ab=(num[0]+num[1])-b;
        if(ab>num[1]){
            num[0]-=(ab-num[1]);
            num[1]=0;
        }else{
            num[1]-=ab;
        }
        ans+=ab;
    }
    rep(i,0,a-1){
        if((num[i]+num[i+1])>b){
            ans+=(num[i+1]-(b-num[i]));
            num[i+1]-=(num[i+1]-(b-num[i]));
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))
# a.sort()
# now = a[0]
# for i in range(1, n):
#     if (a[i] % now != 0):
#         now = a[i] % now
# print(now)
import fractions
from functools import reduce
print(reduce(fractions.gcd,a))

Measured memory_bytes: 14252
from math import sqrt
from bisect import bisect_left as bi
n = int(input())
x,z = [0]*98,[]
for i in range(2,n+1):
	m = i
	while 1:
		f = 0
		for j in range(2,int(sqrt(m))+1):
			if m%j==0:
				x[j]+=1
				f = 1
				break
		if f: m//=j
		else:
			x[m]+=1
			break
for i in x[::-1]:
	if i>1: z.append(i)
p = len(z)
print(p-bi(z,74)+max((p-bi(z,24))*(p-bi(z,2)-1),0)+max((p-bi(z,14))*(p-bi(z,4)-1),0)+max((p-bi(z,4))*(p-bi(z,4)-1)*(p-bi(z,2)-2)//2,0))

Measured memory_bytes: 3064
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define ll long long
#define maxn 300010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
char s[maxn];
int n,A,B,C,D;
int main()
{
	n=read(); A=read(); B=read(); C=read(); D=read();
	scanf("%s",s+1);
	for(int i=A;i<C;i++)
		if(s[i]=='#'&&s[i+1]=='#'){
			puts("No"); return 0;
		}
	for(int i=B;i<D;i++)
		if(s[i]=='#'&&s[i+1]=='#'){
			puts("No"); return 0;
		}
	if(C<D)puts("Yes");
	else{
		int flag=0;
		for(int i=B;i<=D;i++)
			if(s[i]=='.'&&s[i-1]=='.'&&s[i+1]=='.'){
				flag=1; break;
			}
		puts(flag?"Yes":"No");
	}
	return 0;
}

Measured memory_bytes: 384
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn to_bits(mut n: u64) -> Vec<bool> {
    let mut result = vec![false; 50];
    let mut index = 0;
    while n > 0 {
        if n & 1 == 1 {
            result[index] = true;
        }

        n /= 2;
        index += 1;
    }

    result
}

fn from_bits(bits: &[bool]) -> u64 {
    bits.into_iter()
        .enumerate()
        .filter(|&(_, &b)| b)
        .map(|(i, _)| 2u64.pow(i as _))
        .sum()
}

fn maximize_xor(ans: &[Vec<bool>], base: &[bool], n_exp: usize) -> Vec<bool> {
    let mut result = base.to_owned();
    let n = ans.len();
    let n_half = n / 2;

    for i in 0..n_exp {
        if ans.into_iter().filter(|an| !an[i]).count() > n_half {
            result[i] = true;
        } else {
            result[i] = false;
        }
    }

    result[n_exp] = false;

    result
}

fn main() {
    input! {
        n: usize,
        k: u64,
        ans: [u64; n],
    };

    let k_bits = to_bits(k);
    let an_bits = ans.iter().map(|&an| to_bits(an)).collect::<Vec<_>>();
    let max_exp = k_bits.iter().rev().skip_while(|&&b| !b).count();

    let result = (0..max_exp)
        .filter(|&n_exp| k_bits[n_exp])
        .map(|n_exp| maximize_xor(&an_bits, &k_bits, n_exp))
        .map(|bits| from_bits(&bits))
        .chain(k..k + 1)
        .map(|k| ans.iter().map(|an| an ^ k).sum::<u64>())
        .max()
        .unwrap();

    println!("{}", result);
}


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

int main(){
  long a[3];
  long n;
  int i,j,h;
    for(i=0;i<3;i++){
    scanf("%ld",a+i);
  }
if(a[1]/a[0]<a[2]){
  printf("%d",a[1]/a[0]);
}else{
  printf("%d",a[2]);
}

//   long b[a[1]];
//   long c[a[1]];
//   long d[a[1]];//番目
//   long *e;
//   e = (long *)malloc(sizeof(long) * a[0]*a[1]);
//   long *f;
//   f = (long *)malloc(sizeof(long) * a[0]*a[1]);
//   for(i=0;i<a[0]*a[1];i++){
//     e[i]=0;
//     f[i]=0;
//   }
//   long g[a[0]];
//     for(i=0;i<a[0];i++){
//     g[i]=0;
//   }
//   for(j=0;j<a[1];j++){
//     scanf("%ld",b+j);
//     scanf("%ld",c+j);
//     e[(b[j]-1)*a[1]+g[b[j]-1]]=c[j];
//     f[(b[j]-1)*a[1]+g[b[j]-1]]=j;
//     d[j]=1;
//     g[b[j]-1]++;
//     for(h=0;h<g[b[j]-1];h++){
//       if(e[(b[j]-1)*a[1]+h]==0){}
//       else if(e[(b[j]-1)*a[1]+h]<c[j]){
//         d[j]++;
//       }
//       else if(e[(b[j]-1)*a[1]+h]>c[j]){
//         d[f[(b[j]-1)*a[1]+h]]++;
//       }
//     }
//   }
// for(i=0;i<a[1];i++){
//   printf("%06d",b[i]);
//   printf("%06d\n",d[i]);
// }
// for(i=0;i<a[1]*a[0];i++){
//   printf("%d,",e[i]);
// }
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define fgx cerr<<"-------------"<<endl
#define N 1000000
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
void dbg(){cerr<<endl;}
template<typename A,typename... B>void dbg(A x,B... y){cerr<<x<<" ";dbg(y...);}
#define debug(...) cerr<<#__VA_ARGS__<<"=",dbg(__VA_ARGS__)
const int mod=1e9+7;
char c[N]; int num[N];
inline int qpow(int x,int y){int A=1;for(;y;y>>=1,x=(ll)x*x%mod)if(y&1)A=(ll)A*x%mod;return A;}
int main()
{	int n,ans=1; cin>>n; scanf("%s",c+1);
	for(rint i=1;i<=n;i++) num[c[i]-'a']++;
	for(rint i=0;i<26;i++) ans=(ans+(ll)ans*num[i]%mod)%mod;
	cout<<(ans-1+mod)%mod;
	return 0;
}



Measured memory_bytes: 2304
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

string s;
ll dp[3000][3000];//dp[i][j] := i番目(0-idx)の数字を決定して, jこの未使用の数字が決定された数字よりも大きいときの場合の数
ll ruisekiwa[2][3001];

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

	auto sum_f = ruisekiwa[0], sum_s = ruisekiwa[1];

	sum_f[0] = 0;
	for (int i = 0; i < N; i++) {
		dp[0][i] = 1;
		sum_f[i + 1] = (sum_f[i] + dp[0][i]) % MOD;
	}
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < N; j++)sum_s[j] = 0;
		for (int j = 0; j < N; j++) {
			if (s[i - 1] == '<') {
				//前の数字より大きくないといけないとき、dp[i][j] = sigma(dp[i - 1][(j + 1) ~ (N - i)])
				//今の時点で今の数字より多いのがj個あるとき、一つ前としてありうるのは(j + 1) ~ (N - i)個の全部
				if(N - i >= j + 1)dp[i][j] = (sum_f[N - i + 1] - sum_f[j + 1] + MOD) % MOD;
				sum_s[j + 1] = (sum_s[j] + dp[i][j]) % MOD;
			}
			else {
				//前の数字より小さくないといけないとき、dp[i][j] = sigma(dp[i - 1][0 ~ j])
				//今の時点で今の数字より少ないのが(N - 1 - i - j)個あるとき、
				//一つ前としてありうるのは(N - i - j) ~ (N - i)個の全部(今の場所より小さい数字の個数)
				//つまり今より大きい個数に直すと、0 ~ j 個の全部
				if(j >= 0)dp[i][j] = (sum_f[j + 1] - sum_f[0] + MOD) % MOD;
				sum_s[j + 1] = (sum_s[j] + dp[i][j]) % MOD;
					
			}
		}
		swap(sum_f, sum_s);
	}
	
	cout << dp[N - 1][0] << endl;

	return 0;
}


Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1000000007;
 
int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for(int i=0;i<N;i++)cin >> H[i];
  int ans=0;
  for(int i=0;i<N;i++){
    int cnt=0;
    while(i<N-1 && H[i]>=H[i+1]){cnt++; i++;}
    ans=max(ans,cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
using System;
using System.Linq;

//namespace _0074

class Program
{
    static void Main(string[] args)
    {
        while (true)
        {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (a[1] == a[0] && a[2] == a[1] && a[1] == -1) { break; }
            int seconds = 120 * 60, trueeconds = 120 * 60;
            seconds -= a[0] * 3600 + a[1] * 60 + a[2];
            trueeconds = seconds*3;
            int h = seconds / 3600;
            int h1 = trueeconds / 3600;
            int m = (seconds % 3600) / 60;
            int m1 = (trueeconds % 3600) / 60;
            int s = seconds % 60;
            int s1 = trueeconds % 60;
            if (h < 10) { Console.Write("0" + h); }
            else { Console.Write(h); }
            Console.Write(":");
            if (m < 10) { Console.Write("0" + m); }
            else { Console.Write(m); }
            Console.Write(":");
            if (s < 10) { Console.WriteLine("0" + s); }
            else { Console.WriteLine(s); }
            if (h1 < 10) { Console.Write("0" + h1); }
            else { Console.Write(h1); }
            Console.Write(":");
            if (m1 < 10) { Console.Write("0" + m1); }
            else { Console.Write(m1); }
            Console.Write(":");
            if (s1 < 10) { Console.WriteLine("0" + s1); }
            else { Console.WriteLine(s1); }
        }
        Console.ReadLine();
    }
}

Measured memory_bytes: 9500
/*input
2
100
200
*/
/**
    Author: Kristopher Paul
    Date Created: 16-01-2020
    Contest Name:
                _/    _/   _/_/_/_/   _/   _/_/_/_/
               _/  _/     _/    _/   _/   _/
              _/_/       _/_/_/_/   _/   _/_/_/_/
             _/  _/     _/  _/     _/         _/
            _/    _/   _/    _/   _/   _/_/_/_/
**/
#include<bits/stdc++.h>
#include<stdio.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int ll
#define pb push_back
#define INF 1e18
#define MOD 1000000007
//#define MOD 998244353
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

//Uncomment for File I/O
/*
#define cin fin
#define cout fout

ifstream fin("input.in");
ofstream fout("input.out");
*/

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // set
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // multiset

int ModExp(int x,int y,int m){
    int res = 1;
    x = x % m;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % m;

        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

void solve(){
    int h,w,n;
    cin >> h >> w >> n;
    int a = max(h,w);
    int b = min(h,w);
    cout << ceil(double(n)/double(a)) << endl;
}

signed main(){
    FastIO;
    int t = 1;
//    cin >> t;
    WL(t){
        solve();
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i=s;i<n;++i)
#define drep(i,s,n) for (int i=n;i>=s;--i)
#define all(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define print(x) cout<<(x)<<endl
using namespace std;
typedef long long ll;

int gcd(int a,int b)
{if (a%b == 0) return(b);
 else          return(gcd(b,a%b));}
int lcm(int a,int b)
{return a*b/gcd(a,b);}
void printv(vector<auto> v) {cout<<'[';rep(i,0,v.size()){cout<<v[i]<<',';}cout<<']'<<endl;}
void printvv(vector<vector<auto>> vv)
{
  cout<<'['<<endl;
  rep(q,0,vv.size()){cout<<'[';rep(p,0,vv.at(q).size())cout<<vv.at(q).at(p)<<',';cout <<']'<<endl;}
  cout<<']'<<endl;
}
void solve(); int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}
int step_x[] = {-1,0,0,1};
int step_y[] = {0,-1,1,0};
int INF=10e5;
//------------------------------------------------------------
int A,B;

void solve() {
  cin>>A>>B;

  print(A*B);
  return;
}

Measured memory_bytes: 3648
n = int(input())
s = list(input())

ans = s.count('R')*s.count('G')*s.count('B')

for x in range(n):
  for y in range(n):
    if not x < y:
      continue
    z = y + (y-x)
    if z < n and "".join( sorted([s[x], s[y], s[z]]) ) == "BGR":
      ans -= 1
      
print(ans)


Measured memory_bytes: 74288
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    int n;
    scanf("%d", &n);
    lint x[n], y[n];
    rep(i, n) scanf("%lld%lld", &x[i], &y[i]);
    int ans = n;
    rep(i, n)For(j, i+1, n){
        lint p = x[j]-x[i], q = y[j]-y[i];
        int tmp = n;
        rep(k, n)For(l, k+1, n){
            tmp -= ((x[k]+p == x[l] && y[k]+q == y[l]) || (x[k]-p == x[l] && y[k]-q == y[l]));
        }
        chmin(ans, tmp);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 3836
count = 0
abclist = [int(x) for x in input().split()]
abclist = sorted(abclist)
while(abclist[1] - abclist[0] >= 2):
    abclist[0] += 2
    count += 1
while(abclist[1] - abclist[0] == 1):
    abclist[0] += 1
    abclist[2] += 1
    count += 1
while(abclist[2] - abclist[1] > 0):
    abclist[0] += 1
    abclist[1] += 1
    count += 1
print(count)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll max(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
double max(double a, double b) {

	if (a > b)return a;
	else return b;

}
//aとbの大きい方

ll min(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
//aとbの小さい方

ll avd_i(ll a, ll b) {

	if (a > b)return a - b;
	else return b - a;

}
double avd_d(double a, double b) {

	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;

}
//aとbの差の絶対値

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

	}
	ll r;
	r = b%a;
	if (r == 0)return a;
	else return gcd(r, a);

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

int main() {

	int N, K, fig = 1;

	cin >> N >> K;

	for (int i = 0; i < N; i++) {

		fig = min(fig * 2, fig + K);

	}

	cout << fig << endl;

	return 0;
}

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

#define rep(i,n) for(int i = 0;i< (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

//priority_queue<int, vector<int>, greater<int>> min_heap;
//long long ccw(const Point& A, const Point& B, const Point& C) {
//   return 1LL * (B.x - A.x)*(C.y - A.y) - 1LL * (B.y - A.y)*(C.x - A.x);
//}

int main() { // E 
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n; cin >> n;
	int k; cin >> k;
	int ans = 0;
	rep(i, n) {
		int x; cin >> x;
		if (x >= k) {
			ans += 1;
		}
	}
	cout << ans << '\n';





}

Measured memory_bytes: 256
#include<iostream>
    using namespace std;
    int main()
    {
      int n;
      cin>>n;
      char s[n];
      cin>>s;
      int count=0;
      for (int i=0;i<n-2;i++)
      {
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
          count++;
      }
      cout<<count;
      return 0;
    }

Measured memory_bytes: 256
from math import log2, floor
n, k = map(int, input().split())
a = 1/n
ans = 0
for i in range(1, n+1):
    if i >= k:
        ans += a
        continue
    j = int(log2(k/i)) + 1
    if i*2**(j-1) == k:
        j -= 1
    ans += a/2**j
print(ans)

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i, n) for ( int i = 0; i < (int)n; i++)

class P{
public:
  int s, c, r, t;
  P(int s=0, int c=0):s(s), c(c){ r = s; t = 0;}
  bool operator < ( const P &p ) const{ return s < p.s; }
};

vector<P> getNext(vector<P> &l, int w){
  vector<P> nl;
  rep(i, l.size()) l[i].r -= w;
  while ( 0 < l.size() && l[0].r <= 0 ){
    P p = l[0]; l.erase(l.begin());
    p.t++;
    if ( p.c*2 >= p.t ){
      p.r = p.s;
      nl.push_back(p);
    }
  }
  sort(nl.begin(), nl.end());
  return nl;
}

void simulate(vector<P> U, vector<P> D){
  vector<P> nU, nD;
  int w, e = 0;
  while( U.size() + D.size() > 0){
    if ( U.size() == 0 ) w = D[0].r;
    else if ( D.size() == 0 ) w = U[0].r;
    else w = min(U[0].r, D[0].r);
    e += w;
    nU = getNext(D, w);
    nD = getNext(U, w);
    rep(i, nU.size()) U.push_back(nU[i]);
    rep(i, nD.size()) D.push_back(nD[i]);
  }
  cout << e << endl;
}

main(){
  int n;
  while( cin >> n && n ){
    vector<P> U, D;
    rep(i, n){
      P p; cin >> p.s >> p.c;
      U.push_back(p);
    }
    sort(U.begin(), U.end());
    simulate(U, D);
  }
}

Measured memory_bytes: 916
#include <climits>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

struct node {
  int cost;
  int k;
  vector<int> nodes;
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<node> nodes(n + 1, {INT_MAX, 0, {}});

  for (auto &v : nodes)
    v = {INT_MAX, 0, {}};

  while (m--) {
    int a, b;
    cin >> a >> b;
    nodes[a].nodes.push_back(b);
    nodes[b].nodes.push_back(a);
  }

  nodes[1].cost = 0;
  nodes[1].k = 1;
  queue<int> que;
  que.push(1);

  while (!que.empty()) {
    int c = que.front();
    que.pop();
    node *nodec = &nodes[c];
    for (auto &b : nodec->nodes) {
      node *noden = &nodes[b];

      if (noden->cost <= nodec->cost + 1)
        continue;
      noden->cost = nodec->cost + 1;
      noden->k = c;
      que.push(b);
    }
  }

  bool det = true;
  for (int i = 2; i < n + 1; ++i)
    if (nodes[i].k == 0)
      det = false;

  if (det == false) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for (int i = 2; i < n + 1; ++i)
      cout << nodes[i].k << endl;
  }
}

Measured memory_bytes: 10540
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]

INF = 10 ** 5

# L[i]までのコスト
# L[i+1]をAにしたコスト
# L[i+1]をBにしたコスト
# L[i+1]をCにしたコスト

def cost(lres, a, b, c):
    if len(lres) == 0:
        if a * b * c > 0:
            return abs(a - A) + abs(b - B) + abs(c - C)
        else:
            return INF

    x = lres[0]
    return min(
        cost(lres[1:], a, b, c),
        cost(lres[1:], a + x, b, c) + (10 if a > 0 else 0),
        cost(lres[1:], a, b + x, c) + (10 if b > 0 else 0),
        cost(lres[1:], a, b, c + x) + (10 if c > 0 else 0),
    )

print(cost(l, 0, 0, 0))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define re cin>>
#define pr cout<<
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)


const int N=2e6+5;
const int mod=1e9+7;

int n,ar[N];
int main(){
      n=5;
      int x=1;
      for(int i=1;i<=n;i++){
            cin>>ar[i];
            if(!ar[i]) x=i;
      }
      cout<<x;
      return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll a, b, c, k;
    cin>>a>>b>>c>>k;

    if (a > k) {
        cout<<k<<endl;
        return 0;
    }

    if (a + b >= k) {
        cout<<a<<endl;
        return 0;
    }
    cout<<a - (k - a - b)<<endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    vector<P> B(n);
    rep(i, n) {
        cin >> A[i];
        B[i] = P(A[i], i);
    }
    sort(B.rbegin(), B.rend());
    vector<vector<ll>> dp(n+1, vector<ll>(n+1, 0));
    rep(i, n) rep(j, i+1) {
        dp[i+1][j] = max(dp[i][j] + (ll)B[i].first * abs(n-1-(i-j)-B[i].second), dp[i+1][j]);
        dp[i+1][j+1] = dp[i][j] + (ll)B[i].first * abs(B[i].second - j);
    }
    ll ans = 0;
    rep(i, n+1) ans = max(ans, dp[n][i]);
    cout << ans << endl;
    return 0;
}

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

  vector<vector<int>> a(3, vector<int>(3));
  vector<vector<int>> f(3, vector<int>(3));
  
  int N;
  for (int i=0; i<3; i++){
    for (int j=0; j<3; j++){
    	cin >> a.at(i).at(j);
   		f.at(i).at(j)=0;
    }
  }
  cin >> N;
  vector<int> b(N);
  for (int i=0; i<N; i++){
    cin >> b.at(i);
  }
  
  for (int i=0; i<3; i++){
    for (int j=0; j<3; j++){  
  		for (int k=0; k<N; k++){
          if (a.at(i).at(j)==b.at(k)){
            f.at(i).at(j)=1;
          }
        }
    }
  }
  
  int bingo=0;
  for (int i=0; i<3 ;i++){
     if (f.at(i).at(0)*f.at(i).at(1)*f.at(i).at(2)==1){
      bingo=1;
     }
  }
  
  for (int i=0; i<3 ;i++){
    if (f.at(0).at(i)*f.at(1).at(i)*f.at(2).at(i)==1){
      bingo=1;
    }
  }
  
  if (f.at(0).at(0)*f.at(1).at(1)*f.at(2).at(2)==1){
    bingo=1;
  }
  
    
  if (f.at(2).at(0)*f.at(1).at(1)*f.at(0).at(2)==1){
    bingo=1;
  }
  

  if (bingo==1){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
    
}

Measured memory_bytes: 256
let n, a, b, c = Scanf.scanf " %d %d %d %d" @@ fun a b c d -> a, b, c, d
let ls = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let rec f mp i la lb lc =
  if i >= n then if min la (min lb lc) = 0 then max_int else mp + abs (la - a) + abs (lb - b) + abs (lc - c) - 30
  else List.fold_left min (f mp (i + 1) la lb lc)
    [f (mp + 10) (i + 1) (la + ls.(i)) lb lc; f (mp + 10) (i + 1) la (lb + ls.(i)) lc; f (mp + 10) (i + 1) la lb (lc + ls.(i))]
let _ = f 0 0 0 0 0 |> Printf.printf "%d\n"

Measured memory_bytes: 1920
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	char ch[10000];
	cin>>ch;
	int now=0,ans=0;
	for(int i=0;i<strlen(ch);i++)
	{
		if(ch[i]=='I')
		{
			now++;
		}
		else
		{
			now--;
		}
		ans=max(ans,now);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
if !ENV['RUBY_THREAD_VM_STACK_SIZE']
  exec({'RUBY_THREAD_VM_STACK_SIZE'=>'268435456'}, '/usr/bin/ruby', $0)
end

N, M = gets.split.map(&:to_i)
@nodes = Array.new(N + 1) { [] }
M.times.map do
  x, y = gets.split.map(&:to_i)
  @nodes[x] ||= []
  @nodes[x] << y
end

@dp = []

def solve(i)
  return @dp[i] if @dp[i]

  max = 0
  @nodes[i].each do |to|
    solved = solve(to) + 1
    max = solved if solved > max
  end

  @dp[i] = max
  return max
end

ans = 0
1.upto(N) do |i|
  solved = solve(i)
  ans = solved if ans < solved
end

puts ans


Measured memory_bytes: 103888
#include<cstdio>
const int t=500;
int k,n;
int a[503][503];
inline int add(int x,int y)
{
	x+=y-1;
	return (x>n)?x-n:x;
}
int main()
{
	scanf(" %d",&k);
	n=(k>t)?t:k;
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=n;++j)
		{
			a[i][add(i,j)]=j;
		}
	}
	if(k>t)
	{
		k-=t;
		for(int c=1;c<=k;++c)
		{
			for(int r=2;r<=n;r+=2)
			{
				a[r][add(r,c)]+=n;
			}
		}
	}
	printf("%d\n",n);
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<n;++j)printf("%d ",a[i][j]);
		printf("%d\n",a[i][n]);
	}
	return 0;
}

Measured memory_bytes: 2048
import sys
from itertools import accumulate
import bisect

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    D = ii()
    c = list(mi())
    s = [list(mi()) for i in range(D)]

    t = [ii()-1 for i in range(D)]

    last = [[0]*26 for i in range(D)]
    v = [0]*D

    for d in range(D):
        for i in range(26):
            if i == t[d]:
                last[d][i] = d+1
            else:
                last[d][i] = last[d-1][i]

        k = sum(c[i]*(d+1-last[d][i]) for i in range(26))
        v[d] = v[d-1] + s[d][t[d]] - k
    
    print(*v, sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 68472
#include <iostream>

#define N 20
#define Q 200

using namespace std;

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

  int q;
  cin >> q;
  int m[Q];
  int m_max;
  for(int i= 0; i<q; i++) {
    cin >> m[i];
    if(i == 0) m_max = m[i];
    else if(m_max < m[i]) m_max = m[i];
  }

  int DP[N][2000] = {0};
  for(int i = 0; i<n; i++) {
    for(int j = 1; j<=m_max; j++) {
      if(i >= 1) DP[i][j] = DP[i-1][j];
      if(j >= A[i]) {
	if(i == 0) DP[i][j] = A[i];
	else if(DP[i-1][j] < DP[i-1][j-A[i]]+A[i]) {
	  DP[i][j] = DP[i-1][j-A[i]]+A[i];
	}
      }
    }
  }

  int c = 0;
  for(int i = 0; i<q; i++) {
    for(int j = 0; j<n; j++) {
      if(DP[j][m[i]] == m[i]) c = 1;
    }
    if(c == 1) cout << "yes" << endl;
    else cout << "no" << endl;
    c = 0;
  }

  return 0;
}



Measured memory_bytes: 3252
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

ll mod=1000000007;
const int SIZE=2000010;
ll fac[SIZE], finv[SIZE], inv[SIZE];
void COMinit(ll m){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for (int i=2; i<SIZE; ++i){
        fac[i]=(fac[i-1]*i)%m;
        inv[i]=m-(inv[m%i]*(m/i))%m;
        finv[i]=(finv[i-1]*inv[i])%m;
    }
}
ll COM(int n, int k, ll m){
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return (fac[n]*((finv[k]*finv[n-k])%m))%m;
}
ll solve(int R, int C){
	return (COM(R+C+2, R+1, mod)+mod-1)%mod;
}

int main() {
	int r1, c1, r2, c2;
	cin >> r1 >> c1 >> r2 >> c2;
	COMinit(mod);
	cout << (solve(r2, c2)+solve(r1-1, c1-1)+mod*2-solve(r2, c1-1)-solve(r1-1, c2))%mod << endl;
	return 0;
}


Measured memory_bytes: 47104
package main

import (
	"fmt"
)

func main() {
	var a, b string
	fmt.Scan(&a)
	fmt.Scan(&b)
	naga := len(b) - 1
	if a == string(b[0:naga]) {
		fmt.Println("Yes")

	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1752
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
  return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
  read_all = [tuple(map(int, input().split())) for _ in range(N)]
  return map(list,zip(*read_all))

#################

N = I()
A = III()
B = III()

counter = 0
for i in range(N):
  if A[i]+A[i+1] <= B[i]:
    counter += A[i]+A[i+1]
    A[i+1]=0
  elif A[i] < B[i]:
    counter += B[i]
    A[i+1] -= B[i]-A[i]
  else:
    counter += B[i]
print(counter) 

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n, A, B; cin >> n >> A >> B;
    string s; cin >> s;
    int cnt1 = 0, cnt2 = 0;
    REP(i, s.size()) {
        bool ans = false;
        if (s[i] == 'a') {
            if (cnt1 + cnt2 < A + B) {
                ++cnt1;
                ans = true;
            }
        }
        else if (s[i] == 'b') {
            if (cnt1 + cnt2 < A + B && cnt2 < B) {
                ++cnt2;
                ans = true;
            }
        }

        if (ans) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
}


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

typedef long long ll;
const int maxn=1e5+100;
const ll mod=1e9+7;

ll dp[maxn];
int n,m;
bool f[maxn];

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int x;
		scanf("%d",&x);
		f[x]=1;
	}
	dp[0]=1;
	for(int i=1;i<=n;i++){
		if(i-2>=0) if(!f[i-2]) dp[i]=(dp[i]+dp[i-2])%mod;
		if(!f[i-1]) dp[i]=(dp[i]+dp[i-1])%mod;
	}
	printf("%lld",dp[n]);
	return 0;
}

Measured memory_bytes: 1152
import collections

def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

mod=10**9+7
n=int(input())
dic=collections.defaultdict(int)
cnt=0
for _ in range(n):
  a,b=map(int,input().split())
  if a!=0 and b!=0:
    g=gcd(abs(a),abs(b))
    if a*b>0:
      dic[(abs(a)//g,abs(b)//g)]+=1
    else:
      dic[(-abs(a)//g,abs(b)//g)]+=1
  else:
    if a==0 and b==0:
      cnt+=1
    elif a==0:
      dic[(0,1)]+=1
    elif b==0:
      dic[(1,0)]+=1
ans=1
s=set()
for a,b in dic.keys():
  if (a,b) in s:
    continue
  s.add((a,b))
  if a>0:
    s.add((-b,a))
    cnt1=dic[(a,b)]
    if (-b,a) in dic:
      cnt2=dic[(-b,a)]
    else:
      cnt2=0
    ans*=(pow(2,cnt1,mod)+pow(2,cnt2,mod)-1)%mod
    ans%=mod
  else:
    s.add((b,-a))
    cnt1=dic[(a,b)]
    if (b,-a) in dic:
      cnt2=dic[(b,-a)]
    else:
      cnt2=0
    ans*=(pow(2,cnt1,mod)+pow(2,cnt2,mod)-1)%mod
    ans%=mod
print((ans+cnt-1)%mod)

Measured memory_bytes: 172976
#include <cmath>
#include <cstdio>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <stdio.h>
#include <functional>
#include <chrono>
using namespace std;

#define rep(i,s,n) for(ll i=s;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MAX_INF = 9223372036854775807;
//constexpr ll MOD = (1e9 + 7);
constexpr ll MOD = (998244353);

using vl = vector<ll>;
using vvl = vector<vector<ll>>;

template<class T>
vector<vector<T>> vvt(T init, ll m, ll n) {
	vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
	return move(ans);
}

template<class T>
vector<T> vt(T init,ll n) {
	vector<T> ans = vector<T>(n, init);
	return move(ans);
}

template<class T>
T maxVec(vector<T> &v) {
	T ans = -INF;
	rep(i,0, v.size()) {
		ans = max(ans, v[i]);
	}
	return ans;
}

// 素数判定
bool judge(ll n) {
	for (ll i = 2; i * i <= n; i++) if (n %= i)return false;
	return true;
}


template <class C>
void print(const C& c, std::ostream& os = std::cout)
{
	std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, ", "));
	os << std::endl;
}
/*
ll count(ll n,ll r) {
	ll ans = 0,check = 1;
	rep(i,0, r) {
		if ((n & check) > 0) {
			ans++;
		}
		check = check << 1;
	}
	return ans;
}
*/
bool sortreverse(ll a, ll b) {
	return a > b;
}

ll kiriage(ll a, ll b) {
	if (a % b == 0)return a / b;
	return a / b + 1;
}

// グラフは<頂点,コスト>
void Dijkstra(ll v, vector<vector<pll>> graph, ll s, vl& ans) {
	auto comp = [](const pll a, const pll b) { return a.first > b.first; };
	priority_queue<pll, vector<pll>, decltype(comp)> que(comp);
	ans = vl(v, INF);
	ans[s] = 0;
	que.push(pll{ 0, s });
	pll a;
	while (!que.empty()) {
		ll c = que.top().first, p = que.top().second;
		que.pop();
		rep(i, 0, graph[p].size()) {
			a = graph[p][i];
			if (ans[a.first] > a.second + c) {
				ans[a.first] = a.second + c;
				que.push(pll{ a.second + c,a.first });
			}
		}
	}
}

ll n,m,x,y,t,q,s;

int main() {
	cin >> n >> m >> s >> t;
	ll v, u, a, b;
	vector<vector<pll>> yenGraph(n, vector<pll>(0));
	vector<vector<pll>> sunGraph(n, vector<pll>(0));
	rep(i, 0,m) {
		cin >> u >> v >> a >> b;
		yenGraph[u - 1].push_back(pll{ v - 1,a });
		yenGraph[v - 1].push_back(pll{ u - 1,a });
		sunGraph[u - 1].push_back(pll{ v - 1,b });
		sunGraph[v - 1].push_back(pll{ u - 1,b });
	}
	vl yen, sun;
	Dijkstra(n, yenGraph, s - 1, yen);
	Dijkstra(n, sunGraph, t - 1, sun);
	ll moto = 1000000000000000;
	vl ans(n, 0);
	ans[n-1] = moto - yen[n - 1] - sun[n - 1];
	for (ll i = n-2;i >= 0;i --) {
		ans[i] = max(ans[i+1], moto - yen[i] - sun[i]);
	}
	rep(i, 0, n) {
		printf("%lld\n", ans[i]);
	}
}

Measured memory_bytes: 26684