akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int mod=1e9+7;
int pre[1000005];
int ans[1000005];
int fi[1000005];

signed main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n;
    cin>>n;
    if(n==1)
    {
        cout<<1;
        return 0;
    }
    ans[1]=1;
    pre[1]=1;
    fi[1]=1;
    for(int i=2;i<=n;i++)
    {
        int tot=0;
        if(i>3)
        {
            tot+=ans[i-3];
            tot%=mod;
            tot=(pre[i-3]*(i-2))%mod-tot+mod;
            tot%=mod;
        }
        tot++;
        ans[i]=(i*tot)%mod+ans[i-1];
        ans[i]%=mod;
        pre[i]=tot+pre[i-1];
        pre[i]%=mod;
        fi[i]=tot%mod;
    }
    int res=1;
    for(int i=1;i<n;i++)
    {
        int z=fi[i]*n;
        z%=mod;
        z*=n-1;
        z%=mod;
        res+=z;
        res%=mod;
    }
    res+=(fi[n]*(n-1))%mod;
    res%=mod;
    cout<<res;

} 



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

int main(void){
    int n = 0, a = 0, b = 0; 
    int ans = 0;

    scanf("%d%d%d", &n, &a, &b);

    for(int i = 1; i <= n; i++){
        int wa = 0, tmp = 0;
        tmp = i;
        while(tmp >= 10){
            wa += tmp % 10;
            tmp /= 10;
        }
        wa += tmp;
        if(wa >= a && wa <= b){
            ans += i;
//            printf("i = %d\n", i);
        }

    }

    printf("%d\n", ans);

    return 0;

} 


Measured memory_bytes: 256
def get_root(s):
    if s != root[s]:
        root[s] = get_root(root[s])
        return root[s]
    return s

def unite(s, t):
    root_s = get_root(s)
    root_t = get_root(t)
    if not root_s == root_t:
        if rank[s] == rank[t]:
            root[root_t] = root_s
            rank[root_s] += 1
        elif rank[s] > rank[t]:
            root[root_t] = root_s
        else:
            root[root_s] = root_t

def same(s, t):
    if get_root(s) == get_root(t):
        return True
    else:
        return False

n = int(input())
root = [i for i in range(n)]
rank = [1 for _ in range(n)]
s, t = [], []
for i in range(n):
    x, y = map(int, input().split())
    s.append([x, i])
    t.append([y, i])
s.sort()
t.sort()
u = []
for i in range(n - 1):
    u.append([abs(s[i][0] - s[i + 1][0]), s[i][1], s[i + 1][1]])
    u.append([abs(t[i][0] - t[i + 1][0]), t[i][1], t[i + 1][1]])
u.sort()
c = 0
ans = 0
for v in u:
    if not same(v[1], v[2]):
        unite(v[1], v[2])
        c += 1
        ans += v[0]
    if c == n - 1:
        break
print(ans)

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int ans,H,W,K,a[30][30];

bool check(int n){
    bool res = false;
    int tmp = 0;
    REP(i,H){
        RFOR(j,W+1,K){
            REP(k,W-j+1){
                bool flag = true;
                REP(l,j-1){
                    if(a[i][k]==0 || a[i][k+l+1]==0){
                        flag = false;
                        break;
                    }
                    if(a[i][k+l+1] != a[i][k]){
                        flag = false;
                        break;
                    }
                }
                if(flag){
                    res = true;
                    tmp += a[i][k]*j;
                    REP(l,j) a[i][k+l] = 0;
                }
            }
        }
    }
    ans += (1<<n)*tmp;
    return res;
}

void seiri(void){
    RREP(i,H){
        REP(j,W){
            if(a[i][j] == 0){
                int h = i-1;
                while(h>0 && a[h][j]==0) h--;
                if(h>=0 && a[h][j] != 0){
                    a[i][j] = a[h][j];
                    a[h][j] = 0;
                }
            }
        }
    }
}

int main(void){
    cin >> H >> W >> K;
    REP(i,H)REP(j,W){
        char c; cin >> c;
        a[i][j] = c - '0';
    }
    int b[H][W]; REP(i,H)REP(j,W) b[i][j] = a[i][j];
    int ans1 = 0;
    REP(i,H)REP(j,W){
        ans = 0;
        REP(s,H)REP(t,W) a[s][t] = b[s][t];
        a[i][j] = 0;
        seiri();
        REP(k,H*W){
            if(check(k)) seiri();
            else break;
        }
        chmax(ans1, ans);
    }
    cout << ans1 << en;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

string a;
int aa;

int main() {
	cin >> a;
	for (int i = 0; i < a.length(); i ++){
		if (aa == 0 && a[i] == 'C') aa = 1;
		if (aa == 1 && a[i] == 'F') aa = 2;
	}
	if (aa == 2) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

int m, n, k, aj[1001][1001], ao[1001][1001], ai[1001][1001];
int main()
{
	cin >> m >> n >> k;
	for (int i = 1; i <= m; i++){
		for (int j = 1; j <= n; j++){
			char in;
			cin >> in;
			aj[i][j] = aj[i - 1][j] + aj[i][j - 1] - aj[i - 1][j - 1];
			ao[i][j] = ao[i - 1][j] + ao[i][j - 1] - ao[i - 1][j - 1];
			ai[i][j] = ai[i - 1][j] + ai[i][j - 1] - ai[i - 1][j - 1];
			if (in == 'J') aj[i][j]++;
			else if (in == 'O') ao[i][j]++;
			else ai[i][j]++;
		}
	}

	for (int i = 0; i < k; i++){
		int a, b, c, d, ansj, anso, ansi;
		cin >> a >> b >> c >> d;
		a--; b--;
		ansj = aj[c][d] - aj[c][b] - aj[a][d] + aj[a][b];
		anso = ao[c][d] - ao[c][b] - ao[a][d] + ao[a][b];
		ansi = ai[c][d] - ai[c][b] - ai[a][d] + ai[a][b];
		cout << ansj << " " << anso << " " << ansi << endl;
	}
	return 0;
}

Measured memory_bytes: 12872
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <set>
#include <vector>
#include <queue>
#include <map>
using namespace std;
long long int c;
long long ans1,ans2;
int main()
{
    int n;
    while(cin>>n)
    {
       bool flag=false;
       for(long long int i=1;i<=3500;i++)
       {
           for(long long int j=1;j<=3500;j++)
           {
               long long a=n*i*j;
               long long b=4*i*j-n*i-n*j;
               if(b==0) continue;
               if(a % b ==0 && a / b >0)
               {
                   c=a/b;
                   flag=true;
                   ans1=i;
                   ans2=j;
                   break;
               }
           }
           if(flag) break;
       }
       cout<<ans1<<" "<<ans2<<" "<<c<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define R register
#define ll long long
#define mp make_pair
#define pii pair<int, int>
using namespace std;
const int N = 31000;

int n, f[N][4], lst[N];
char s[N];

template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}

int main() {
    read(n);
    scanf("%s", s + 1);
    f[0][0] = 1;
    for (R int i = 1; i <= n; ++i) {
        f[i][0] = 1;
        for (R int j = 1; j <= 3; ++j)
            f[i][j] = f[i - 1][j] + f[i - 1][j - 1] - (lst[s[i] - '0'] ? f[lst[s[i] - '0'] - 1][j - 1] : 0);
        lst[s[i] - '0'] = i;
    }
    cout << f[n][3] << endl;
    return 0;
}

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

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

int main(){

    int N;
    cin >> N;
    map<string, int> check;
    rep (i, N){
        string s = "";
        cin >> s;
        sort(s.begin(), s.end());
        check[s] += 1;
    }
    long ans = 0;
    for (auto p:check){
        if (2 <= p.second) ans += nCr(p.second, 2);
    }

    cout << ans << endl;

    return 0;
}

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


int main(){
  int n,m;
  cin>>n>>m;
  int x[n+1],y[m+1];
  cin>>x[0]>>y[0];
  rep(i,n)cin>>x[i+1];
  rep(i,m)cin>>y[i+1];
  sort(x,x+n+1,greater<int>());
  sort(y,y+m+1);
  if (x[0]<y[0]) cout<<"No War"<<endl;
  else cout<<"War"<<endl;
  return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::fmt::{Debug, Display};
use std::io::{self, Read};
use std::str::{self, FromStr};


fn solve(n: u32, m: u32, k: u32) -> bool {
    for i in 0..n + 1 {
        for j in 0..m + 1 {
            if m * i + n * j - 2 * i * j == k {
                return true;
            }
        }
    }
    false
}


fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock().bytes());
    print_yesno(solve(sc.next(), sc.next(), sc.next()), "Yes", "No")
}


struct Scanner<R: Read> {
    buf: Vec<u8>,
    bytes: io::Bytes<R>,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(bytes: io::Bytes<R>) -> Self {
        Scanner {
            buf: Vec::with_capacity(256),
            bytes: bytes,
        }
    }

    fn next<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: Debug,
    {
        self.buf.clear();
        for c in self.bytes
            .by_ref()
            .map(|c| c.unwrap())
            .skip_while(|&c| c == ' ' as u8 || c == '\n' as u8)
            .take_while(|&c| !(c == ' ' as u8 || c == '\n' as u8))
        {
            self.buf.push(c);
        }
        str::from_utf8(&self.buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<A: FromStr, B: FromStr>(&mut self, n: usize) -> Vec<(A, B)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<A: FromStr, B: FromStr, C: FromStr>(&mut self, n: usize) -> Vec<(A, B, C)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
        <C as FromStr>::Err: Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.vec(m)).collect()
    }
}


#[allow(dead_code)]
fn print_yesno(x: bool, yes: &'static str, no: &'static str) {
    println!("{}", if x { yes } else { no });
}


#[allow(dead_code)]
fn print_foreach<T: Display, I: IntoIterator<Item = T>>(xs: I) {
    for x in xs.into_iter() {
        println!("{}", x);
    }
}


#[allow(dead_code)]
fn print_or<T: Display>(x: Option<T>, or: &'static str) {
    if let Some(x) = x {
        println!("{}", x);
    } else {
        println!("{}", or);
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <iostream>

int main( void )
{
	long A;
  	long B;
  	long K;
    std::cin>> A >> B >> K;
//    std::cout << "A=" << A << std::endl;
//    std::cout << "B=" << B << std::endl;
//    std::cout << "K=" << K << std::endl;

  	if(A >= K)
    {
//    std::cout << "--1--" << K << std::endl;
      A=A-K;
    }
  	else if(A+B >= K)
    {
//    std::cout << "--2--" << std::endl;
     long d = K-A;
//      std::cout << "K-A=" << d << std::endl;
      B=B-d;
      A=0;
    }
	else
    {
//    std::cout << "--3--" << std::endl;
      A=B=0;
    }
  
//    std::cout << "A=" << A << std::endl;
//    std::cout << "B=" << B << std::endl;
//    std::cout << "K=" << K << std::endl;

  std::cout << A << " " << B << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

/*
 * kを超えるまで表が出続ける確率を計算
 */
double calc_coin_p(int k, int base) {
    // 振る回数
    int count = 0;
    // 確率
    double p = 1;

    // k以上になるまで振り続け、点数を倍にする
    while(base <= k - 1) {
        count++;   // 振る
        base *= 2; // 点数が倍
        p /= 2;    // 確率はさらに半分
    }
    return p;
}

int main() {
    int n, k;
    cin >> n >> k;
    double p = 0;

    double total = 0;
    for(int i = 1; i <= n; ++i) {
        total += calc_coin_p(k, i) / n;
    }

    cout << fixed << setprecision(15) << total << endl;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb() pop_back()
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define gll greater<ll>()



void solve(){
 ll n;
  cin >> n;
 ll ans=0;
  rep(i,1,n+1) ans+=ll(i)*(n-i+1);
  
  rep(i,0,n-1){
   ll u,v;
    cin >> u >> v;
    if(u>v) swap(u,v);
    ans-=ll(u)*(n-v+1);
  }
  cout << ans << endl;
  
}

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>> 
ld pie=3.141592653589793238462643383279;
int mod=1e9+7;
int dx[]={-1,1,0,0};
int dy[]={0,0,1,-1};
 
 
int dig(int a){
  int r=0;
  while(a!=0){
    int xp=a%10;
    a/=10; if(xp==1) ++r;
  }
  return r;
}
 
int fact[2000005];
int infact[2000005];
 
int inv(int a){
  int y=mod-2;
  int r=1;
  while(y!=0){
    if(y&1){
      r*=a; r%=mod;
    }
    y/=2; a*=a; a%=mod;
  }
  return r;
}
 
int po(int a,int y){
  int r=1;
  while(y!=0){
    if(y&1){
      r*=a; r%=mod;
    }
    y/=2; a*=a; a%=mod;
  }
  return r; 
}
 
void facto(){
  fact[0]=1;
  f(i,1,2000005) {fact[i]=i*fact[i-1]; fact[i]%=mod;}
  f(i,0,2000005) infact[i]=inv(fact[i]); 
}
 
int nck (int n,int k){
  if(k<0 || k>n) return 0;
  int ret=fact[n]; ret*=infact[k]; ret%=mod;
  ret*=infact[n-k]; ret%=mod;
  return ret;
}
void q1(){
  string s; cin>>s;
  if(s>="a" && s<="z") cout<<"a";
  else cout<<"A";
}
void q2(){
  int n,k; cin>>n>>k;
  int a[n]; f(i,0,n) cin>>a[i];
  sort(a,a+n);
  int s=0;
  f(i,0,k)s+=a[i];
  cout<<s;
}
void q3(){
  string ret="";
  int a; cin>>a;
  while(a!=0){
    a--;
    ret+=(a%26 +'a');
    a/=26;
  }
  reverse(ret.begin(),ret.end());
  cout<<ret;
}
void q4(){
  int n; cin>>n;
   int a[100005]={0};
   int s=0;
  f(i,0,n){
    int x; cin>>x;
    s+=x;
    a[x]++;
  }
  int q; cin>>q;
  while(q--){
    int b,c; cin>>b>>c;
    s-=a[b]*b;
    s+=a[b]*c;
    a[c]+=a[b];
    a[b]=0;
    cout<<s<<"\n";
  }
 
}
void q5(){
  int n; cin>>n;
  int x=0;
  int a[n]; f(i,0,n){
    cin>>a[i];
    x^=a[i];
  } 
   f(i,0,n) cout<<(x^a[i])<<" ";
}
int32_t main(){
#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  facto();
  int k; cin>>k;
  string s; cin>>s;
  int l=k+s.size();
  int xp=s.size();
  // total = 26^l - those which do not contain subsequence
  // --- i= 0 to  xp-1 prefix present as subseqeunce and remaining have 25^(l-i)
  int ret=1;
  f(i,0,l){
    ret*=26; ret%=mod;
  }
  int sub=0;
 
  f(i,0,xp){
    // l choose i
    sub+= (nck(l,i)*po(25,l-i));
    sub%=mod; 
  }
 
  cout<<((ret-sub)%mod + mod) %mod <<"\n";
  return 0;
}

Measured memory_bytes: 35500
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi; 
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_B() {}

int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, K; cin >> N >> K;    
    vi l(N); REP(i, N) cin >> l[i];

    sort(l.begin(), l.end(), greater<int>());

    int ans = 0;
    REP(i, K) ans += l[i];
     
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int trainFee = n * a;
		if (trainFee < b) {
			System.out.println(trainFee);
		} else {
			System.out.println(b);
		}
	}
}

Measured memory_bytes: 23636
using System;

namespace cs_AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var w = int.Parse(Console.ReadLine());
            for (int i = 0; i < s.Length; i++)
            {
                if (i % w == 0) Console.Write(s[i]);
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define MAX(a,b) (((a)>(b))?a:b)

LL dp[101][100001];
LL value[101]={0};
LL weight[101]={0};

LL cal(LL left,LL remweight)
{
    if(left==0 || remweight<=0)
    {
        return 0;
    }
    else 
    {
        if(dp[left][remweight]==-1)
        {
            if(dp[left-1][remweight]==-1)
            {
               dp[left-1][remweight]=cal(left-1,remweight); 
            }
            if(remweight-weight[left]<0)
            {
                dp[left][remweight]=dp[left-1][remweight];
            }
            else if(dp[left-1][remweight-weight[left]]==-1)
            {
                dp[left-1][remweight-weight[left]]=cal(left-1,remweight-weight[left]);
                dp[left][remweight]=MAX(dp[left-1][remweight],value[left]+dp[left-1][remweight-weight[left]]);                
            }
            else
            {
                dp[left][remweight]=MAX(dp[left-1][remweight],value[left]+dp[left-1][remweight-weight[left]]);
            }
            
            return dp[left][remweight];
            
        }
    }
}

int main()
{
    LL n,w,i,j,k;
    cin>>n>>w;
    
    for(i=1;i<=n;i++)
    {
        cin>>weight[i]>>value[i];
    }

    for(i=0;i<101;i++)
    {
        for(j=0;j<100001;j++)
        {
            dp[i][j]=-1;
        }
    }

    LL ans=cal(n,w);

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 79104
/* ****GT_18**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll i,j,k,l;
		cin>>i>>j;
		if(j==1)
		{
			cout<<0;
		}
		else
		{
			cout<<i-j;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int nax = 2e5 + 10;
int n, k;
int a[nax];


int main () {
    cin.tie(0)->sync_with_stdio(false);
    cin >> n >> k;

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

    int l = 1, r = 1e9;
    int ans = -1;

    while (l <= r) {
        int mid = l + r >> 1;
        long long tot = 0;

        for (int i = 1 ; i <= n ; ++ i) {
            tot += max(0, (a[i] - 1) / mid);
        }

        if (tot <= k) {
            ans = mid;
            r = mid - 1;
        } else l = mid + 1;
    }

    assert(ans != -1);
    cout << ans << '\n';
}


Measured memory_bytes: 4376
using System;

namespace AtCoder
{
    internal static class Program
    {
        private static void Main()
        {
            string s = Console.ReadLine();
            string t = Console.ReadLine();
            bool res = true;

            if (s.Length == t.Length - 1)
            {
                for (int i = 0; i < s.Length; i++)
                {
                    if (s[i] != t[i])
                        res = false;
                }
            }
            else
                res = false;

            if (res == true)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 25804
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;

int main() {
	int n,ans=1;
	string a;
	cin >> n >> a;

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

}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=1e5+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
#endif
}
int n;
ll a[N],b[N];
void input()
{
	n=read<int>();
	For(i,1,n)a[i]=read<int>(),b[i]=read<int>();
}
ll ans;
void work()
{
	Fordown(i,n,1)ans+=(b[i]-(a[i]+ans)%b[i])%b[i];
	write(ans,'\n');
}
int main()
{
	//file();
	input();
	work();
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;

int main() {
  int N, L; cin >> N >> L;
  int sum = 0;
  int minR = INF;
  int ans;
  for (int i = 0; i < N; i++)
  {
    sum += L + i;
    if (minR > abs(L + i)) {
      minR = abs(L + i);
      ans = L + i;
    }
  }

  cout << sum - ans << endl;
}


Measured memory_bytes: 256
#define _DEBUG 1
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
void yesOrNo(bool flg) {
  if (flg)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

void solve(ll N) {
  string s = to_string(N);
  yesOrNo(s.find('7') != string::npos);
}

int main() {
  ll N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Measured memory_bytes: 3760
#include<cstdio>
using namespace std;
int main(void){
	int r,g,y;
	int x;
	scanf("%d %d %d",&r,&g,&y);
	x=r*100+g*10+y;
	if(x%4==0)	printf("YES\n");
	else 		printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, T t){return v2<T>(r, vector<T>(c, t));}

ll n;
void solve(){
    cin >> n;
    string s;
    while(n){
        s += 'a'+(n-1)%26;
        n = (n-1)/26;
    }

    reverse(s.begin(), s.end());

    cout << s << '\n';
}

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


Measured memory_bytes: 3648
import java.util.Scanner;

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

	int n = scan.nextInt();
	int m = scan.nextInt();
	int x = scan.nextInt();
	int[] a = new int[m];
	int[] cost = new int[n+1];
	for(int i = 0; i < m; i++){
	    a[i] = scan.nextInt();
	    cost[a[i]]++;
	}

	int[] ruiseki = new int[n+1];
	for(int i = 1; i < n+1; i++){
	    ruiseki[i] = ruiseki[i-1]+cost[i];
	}

	if(ruiseki[x-1] >= (ruiseki[n]-ruiseki[x])){
	    System.out.println(ruiseki[n]-ruiseki[x]);
	}else{
	    System.out.println(ruiseki[x-1]);
	}
    }
}
			       


Measured memory_bytes: 22228
#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(void){
  string s;
  cin >> s;
  if(s == "SUN") cout << 7 << endl;
  if(s == "MON") cout << 6 << endl;
  if(s == "TUE") cout << 5 << endl;
  if(s == "WED") cout << 4 << endl;
  if(s == "THU") cout << 3 << endl;
  if(s == "FRI") cout << 2 << endl;
  if(s == "SAT") cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 3564
/*************************************************************************
    > File Name: d.cpp
    > Author: Amano Sei
    > Mail: amano_sei@outlook.com 
    > Created Time: 2020年01月02日 星期四 22时08分59秒
 ************************************************************************/

#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn = 100005;

char t[maxn];

int main(){
    int n, k;
    int r, s, p;
    int ans = 0;
    scanf("%d%d", &n, &k);
    scanf("%d%d%d", &s, &p, &r);
    scanf("%s", t);
    for(int i = 0; i < k; i++){
        register char pc = 0;
        for(int j = i; j < n; j += k)
            if(pc != t[j]){
                pc = t[j];
                switch(pc){
                    case 'r':
                        ans += r;
                        break;
                    case 's':
                        ans += s;
                        break;
                    case 'p':
                        ans += p;
                        break;
                }
            }else
                pc = 0;
    }
    printf("%d\n", ans);
    return 0;
}



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

int main() {
	int H, A;
	cin >> H >> A;
	cout << (H+A-1)/A << endl;
	return 0;
}

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

int mindist[203][203];
int rp[10];
int m,n,r;
int flag[10];
int result;

void DFS(int d, int now, int total)
{
	if (total == r)
	{
		result = min(result, d);
		return;
	}
	for(int i = 0; i<r; i++)
		if (flag[i] == 0)
		{
			flag[i] = 1;
			DFS(d + mindist[rp[now]][rp[i]], i, total+1);
			flag[i] = 0;
		}
	return;
}
			

int main()
{
	scanf("%d%d%d", &n, &m, &r);
	for (int i = 0; i<r; i++)
		scanf("%d", &rp[i]);

	result = INT_MAX;
	for (int i = 1; i<=n; i++)
		for (int j = 1; j<=n; j++)
			mindist[i][j] = INT_MAX;

	for (int i = 0; i<m; i++)
	{
		int a,b,l;
		scanf("%d%d%d", &a,&b, &l);
		mindist[a][b] = l;
		mindist[b][a] = l;
	}

	for (int k = 1; k<=n; k++)
		for (int i = 1; i<=n; i++)
			for (int j = 1; j<=n; j++)
			{
				if (j == i) continue;
				if (mindist[i][k] != INT_MAX && mindist[k][j] != INT_MAX)
					mindist[i][j] = min(mindist[i][j], mindist[i][k] + mindist[k][j]);
			}
	
		for (int i = 0; i<r; i++)
		{
			memset(flag, 0, sizeof(flag));
			flag[i] = 1;
			DFS(0, i, 1);
		}
		printf("%d\n", result);

}



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

int main(){

    int K;
    cin >>K;
    int kisu=0;
    int gusu=0;
    for(int i=1;i<K+1;i+=2){
      kisu++;
    }
    for(int i=2;i<K+1;i+=2){
      gusu++;
    }

    int ans=kisu*gusu;

    cout<<ans<<endl;

  }


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		int Q = GetInt();
		long[] A = GetLongs(N);
		long[] X = GetLongs(Q);

		long[] sum = new long[N + 1];
		long[] evenSum = new long[N + 1];
		long[] oddSum = new long[N + 1];
		for(int i = 1; i <= N; i++)
		{
			sum[i] = sum[i - 1] + A[i - 1];
			evenSum[i] = evenSum[i - 1];
			oddSum[i] = oddSum[i - 1];
			if(i % 2 == 0)
				evenSum[i] += A[i - 1];
			else
				oddSum[i] += A[i - 1];
		}

		long[] ans = new long[Q];
		for(int i = 0; i < Q; i++)
			ans[i] = solve(N, A, X[i], sum, evenSum, oddSum);

		WriteLine(string.Join("\n", ans));
	}

	private long solve(int N, long[] A, long X, long[] sum, long[] evenSum, long[] oddSum)
	{
		int ok = 0;
		int ng = N + 1;
		while(Abs(ok - ng) > 1)
		{
			int mid = (ok + ng) / 2;
			if(Abs(A[N - mid] - X) <= Abs(A[N - (mid + 1)/2] - X))
				ok = mid;
			else
				ng = mid;
		}
		long ans = sum[N] - sum[N - (ok + 1)/2];
		int rest = (ok % 2 == 0) ? N - ok : Max(0, N - ok - 1);
		ans += (rest % 2 == 0) ? evenSum[rest] : oddSum[rest];
		return ans;
	}
}

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

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

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

const ll INF = 1e15;
int main(){

  int n;
  cin >> n;
  ll dp[n+10][3];
  rep(i,3) dp[0][i] = 0;

  FOR(i,1,n)rep(j,3) dp[i][j] = INF;

  rep(i,n){
    ll cost[3];
    rep(j,3) cin >> cost[j];
    rep(j,3){
      dp[i+1][0] = max<ll>(dp[i][1] ,dp[i][2])  + cost[0];
      dp[i+1][1] = max<ll>(dp[i][0] ,dp[i][2])  + cost[1];
      dp[i+1][2] = max<ll>(dp[i][0] ,dp[i][1])  + cost[2];
    }
  }
  ll ans = 0;
  rep(i,3) ans = max<ll>(ans,dp[n][i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <fstream>
#include <vector>

#define NMAX 100005
#define MOD 1000000007

#define f cin
using namespace std;

//ifstream f("date.in");

int n, k;
int a[NMAX];
int dp[NMAX][2];


int main() {

    f >> n >> k;
    int max_start = 0;
    for (int i = 0; i < n; ++i) {
        f >> a[i];
    }


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

    for (int i = 1; i <= k; ++i) {
        for (int j = 0; j < 2; ++j) {
            if (dp[i][j]) continue;
            dp[i][j] = 0;
            for (int j1 = 0; j1 < n; ++j1) {
                if (i < a[j1]) continue;
                if (dp[i - a[j1]][1 - j] == 0) {
                    dp[i][j] = 1;
                }
            }
        }
    }

    if (dp[k][0]) {
        cout << "First";
    } else {
        cout << "Second";
    }

    return 0;
}


Measured memory_bytes: 1152
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long ans = 0;
    HashMap<Integer, Long> map = new HashMap<Integer, Long>();
    int[] a = new int[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      if(map.containsKey(a[i])) {
        ans += map.get(a[i]);
        map.put(a[i], map.get(a[i]) + 1);
      } else {
        map.put(a[i], (long)1);
      }
    }
    for(int i = 0; i < n; i++) {
      System.out.println(ans - (map.get(a[i]) - 1));
    }
  }
}

Measured memory_bytes: 69852
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define M 1000000007
#define ff first
#define ss second
#define pb push_back  
#define INF 10000000000

 

 int main(){
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   ll n;
 cin>>n;
 ll fl = 0,p,i;
 map<ll,ll> m;
 for(i=0;i<n;i++){
 	cin>>p;
 	if(m[p]){
 		fl = 1;
	 }
	 m[p] = 1;
 }
 if(fl)	cout<<"NO";
 else	cout<<"YES";
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N,Q; cin>>N>>Q;
    string S; cin>>S;
    vector<pair<int,int>> SubS(Q);
    rep(q,0,Q){
        int l,r; cin>>l>>r;
        SubS.at(q)=make_pair(l-1,r-1);
    }

    vector<int> CumSum(S.size(),0);
    rep(i,1,S.size()){
        char pre_c=S.at(i-1), c=S.at(i);
        if(pre_c=='A' && c=='C') CumSum.at(i)=CumSum.at(i-1)+1;
        else CumSum.at(i)=CumSum.at(i-1);
    }

    for(auto s:SubS){
        int ans=CumSum.at(s.second);
        if(s.first>0) ans-=CumSum.at(s.first);

        cout<<ans<<endl;
    }
}

Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;
string s[305];

rep(i,0,n-1)
cin>>s[i];

int ans=0;

rep(ii,0,n-1)
{
	string a[305];
	rep(i,0,n-1)
	{
		a[i]=s[i];
		rep(j,0,n-1)
		a[i][(j+ii)%n]=s[i][j];
	}
	int foo=1;
	rep(i,0,n-1)
	{
		rep(j,0,n-1)
		{
			if(a[i][j]!=a[j][i])foo=0;
		}
	}
	ans+=foo*n;
}
ol(ans);
return 0;
}



Measured memory_bytes: 568
#include "bits/stdc++.h"
#define rep(i, n) for (int (i) = 1; (i) <= (n); (i)++)
long long GCD(int A, int B) {
	if (B == 0) return A;
	else return GCD(B, A % B);
}
using namespace std;
int main() {
	long long N;
	cin >> N;
	long long ans = 0;
	rep(i, N) {
		rep(j, N) {
			rep(k, N) {
				ans += GCD(GCD(i, j), k);
			}
		}
	}
	cout << ans << endl;
 }

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

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

template<typename T>
bool chmax(T& a,T b){ if(a<b){ a=b;return true; }return false; }
template<typename T>
bool chmin(T& a,T b){ if(a>b){ a=b;return true; }return false; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	auto D=in();
	auto C=vecin(26);
	vvll S(D,vll(26));
	REP(i,D){
		REP(j,26) S[i][j]=in();
	}
	auto T=vecin(D);
	vll L(26,0);

	ll A=0;
	REP(i,D){
		ll d=i+1;
		A += S[i][T[i]-1];
		L[T[i]-1] = d;
		REP(j,26){
			if(T[i]-1!=j){
				A -= C[j]*(d-L[j]);
			}
		}
		out(A);
	}
	return 0;
}


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

int main() {
    int N; cin >> N;
    long long int arr[N + 1];
    for (int i = 0; i <= N; i++) {
        if (i == 0) {
            arr[i] = 2;
        } else if (i == 1) {
            arr[i] = 1;
        } else {
            arr[i] = arr[i - 1] + arr[i - 2];
        }
    }
    cout << arr[N] << endl;
}


Measured memory_bytes: 3620
/*
ID: espr1t
TASK: 
KEYWORDS: 
*/

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;
FILE* in = stdin; FILE* out = stdout;

const int MAX = 1024;

int main(void) {
	// in = fopen("B.in", "rt");
	
	char a[MAX];
	fscanf(in, "%s", a);
	int n = (int)strlen(a);
	
	int bestDiff = 1000000001;
	for (int i1 = 0; i1 + 2 < n; i1++) {
	    int i2 = i1 + 1, i3 = i1 + 2;
        int num = (a[i1] - '0') * 100 + (a[i2] - '0') * 10 + (a[i3] - '0');
        if (bestDiff > abs(753 - num)) {
            bestDiff = abs(753 - num);
        }
    }
	fprintf(out, "%d\n", bestDiff);
	
	return 0;
}

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

int main() {
int n, m,c, a,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,ac=0;
cin >> n >> m >> c ;
if (m>=1){
cin >> b1;
}if(m>=2){
cin >> b2;
}if(m>=3){
cin >> b3;
}if(m>=4){
cin >> b4;
}if(m>=5){
cin >> b5;
}if(m>=6){
cin >> b6;
}if(m>=7){
cin >> b7;
}if(m>=8){
cin >> b8;
}if(m>=9){
cin >> b9;
}if(m>=10){
cin >> b10;
}if(m>=11){
cin >> b11;
}if(m>=12){
cin >> b12;
}if(m>=13){
cin >> b13;
}if(m>=14){
cin >> b14;
}if(m>=15){
cin >> b15;
}if(m>=16){
cin >> b16;
}if(m>=17){
cin >> b17;
}if(m>=18){
cin >> b18;
}if(m>=19){
cin >> b19;
}if(m>=20){
cin >> b20;
}
  
  for (int i=0; i<n; i++){
   long long coudo=0;
    if (m>=1){
      cin>>a;
      coudo+=a*b1;
    } 
    if (m>=2){
      cin>>a;
      coudo+=a*b2;
    } 
    if (m>=3){
      cin>>a;
      coudo+=a*b3;
    } 
    if (m>=4){
      cin>>a;
      coudo+=a*b4;
    } 
    if (m>=5){
      cin>>a;
      coudo+=a*b5;
    } 
    if (m>=6){
      cin>>a;
      coudo+=a*b6;
    } 
    if (m>=7){
      cin>>a;
      coudo+=a*b7;
    } 
    if (m>=8){
      cin>>a;
      coudo+=a*b8;
    } 
    if (m>=9){
      cin>>a;
      coudo+=a*b9;
    } 
    if (m>=10){
      cin>>a;
      coudo+=a*b10;
    } 
    if (m>=11){
      cin>>a;
      coudo+=a*b11;
    } 
    if (m>=12){
      cin>>a;
      coudo+=a*b12;
    } 
    if (m>=13){
      cin>>a;
      coudo+=a*b13;
    } 
    if (m>=14){
      cin>>a;
      coudo+=a*b14;
    } 
    if (m>=15){
      cin>>a;
      coudo+=a*b15;
    } 
    if (m>=16){
      cin>>a;
      coudo+=a*b16;
    } 
    if (m>=17){
      cin>>a;
      coudo+=a*b17;
    } 
    if (m>=18){
      cin>>a;
      coudo+=a*b18;
    } 
    if (m>=19){
      cin>>a;
      coudo+=a*b19;
    } 
    if (m>=20){
      cin>>a;
      coudo+=a*b20;
    } 
    if (coudo+c>0){
    ac++;
    }
  }

  cout << ac << endl;
}


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

using namespace std;

int main()
{
	int n;
	int num;
	vector<int> v;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> num;
		v.push_back(num);
	}

	sort(v.begin(),v.end());

	cout << v[n / 2] - v[(n / 2) - 1] << endl;

	return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
const ll MOD=1000000007;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const vector<pll> dir={{0,1},{1,0},{-1,0},{0,-1},{1,1},{-1,1},{1,-1},{-1,-1}};
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=b-1;i>=a;i--)
#define range(i) (i).begin(),(i).end()
#define rrange(i) (i).rbegin(),(i).rend()
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm (ll a,ll b) {return a*b/gcd(a,b);}
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
inline constexpr int modf(ll n){
    ll ans=1;
    rep(i,0,n) {ans=ans*(n-i)%MOD;}
    return ans;
}

vector<ll> func,inv;
void init(ll n){
    func.resize(n+1);inv.resize(n+1);
    func[0]=1;
    rep(i,0,n) {func[i+1]=func[i]*(i+1)%MOD;}
    inv[n]=intpow(func[n],MOD-2);
    rrep(i,1,n+1) {inv[i-1]=inv[i]*i%MOD;}
}
ll comb(ll a,ll b) {return func[a]*inv[b]%MOD*inv[a-b]%MOD;}

inline long double median(vector<ll> v){
    ll size=v.size();
    sort(v.begin(),v.end());
    if (size % 2 == 1) return v[(size - 1) / 2];
    else return v[(size / 2) - 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;}
template<class T,class L>ostream& operator << (ostream& os, pair<T,L>& p){os << p.first << " " << p.second;return os;}

int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  cout<<min(n*a,b);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N;cin>>N;
    vector<ll> a(N),t(N);
    REP(i,N)cin>>a[i]>>t[i];
    ll na=a[0];
    ll nt=t[0];
    FOR(i,1,N){
        if(na*t[i]==nt*a[i])continue;
        else{
            ll u=(na%a[i]==0?na/a[i]:na/a[i]+1);
            ll v=(nt%t[i]==0?nt/t[i]:nt/t[i]+1);
            ll w=max(u,v);
            na=w*a[i];
            nt=w*t[i];
        }
    }
    cout<<na+nt<<endl;
    return 0;
}

Measured memory_bytes: 256