akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      cout << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}


signed main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) {
    cin >> A[i];
  }

  vector<ll> sum(N + 1);
  rep(i, N) {
    sum[i + 1] = sum[i] + A[i];
  }

  map<ll, ll> m;
  rep(i, N + 1) {
    m[sum[i]]++;
  }

  ll ans = 0;
  for (auto item : m) {
    auto Fi = item.fi;
    auto Se = item.se;
    ans += Se * (Se - 1) / 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 15872
import java.util.Scanner;

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

        Long inputNum = Long.parseLong(sc.next());
        Long sum = 0L;

        for(int i = 1; i <= inputNum; i++) {
            if(i % 3 == 0 && i % 5 == 0) {
                continue;
            } else if(i % 3 == 0) {
                continue;
            } else if(i % 5 == 0) {
                continue;
            } else {
                sum += i;
            }
        }

        System.out.println(sum);
        sc.close();
    }
}

Measured memory_bytes: 48176
<?php
while (true) {
    list($height, $width) = getSpacesByExplodeTrimInput();

    if ($height == 0 && $width == 0) {
        break;
    }

    $widthSymbolNum = str_repeat('#', $width).PHP_EOL;
    echo str_repeat($widthSymbolNum, $height).PHP_EOL;
}

function getSpacesByExplodeTrimInput()
{
    return explode(' ', trim(fgets(STDIN)));
}

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

int main(void)
{
    long long N; cin >> N;
    long long A, B, C, D, E; cin >> A >> B >> C >> D >> E;

    long long mn = min({A, B, C, D, E});

    long long botltime = (N+mn-1)/mn;
    cout << 4 + botltime << endl;
    return 0;
}

Measured memory_bytes: 256
import math
while True :
    alist = [ x for x in input().split() ]
    if alist[1] == "?" :
        break
    elif alist[1] == "*" :
        print(int(alist[0]) * int(alist[2]))
    elif alist[1] == "/" :
        print(math.floor(int(alist[0]) / int(alist[2])))
    elif alist[1] == "+" :
        print(int(alist[0]) + int(alist[2]))
    elif alist[1] == "-" :
        print(int(alist[0]) - int(alist[2]))

Measured memory_bytes: 7804
// In The Name Of The Queen
#include<bits/stdc++.h>
using namespace std;
const int N = 2009;
int n, k, D[N];
vector < int > Adj[N];
int main()
{
    scanf("%d%d", &n, &k);
    for (int i = 1; i < n; i ++)
    {
        int v, u;
        scanf("%d%d", &v, &u);
        Adj[v].push_back(u);
        Adj[u].push_back(v);
    }
    int Mx = 0;
    if (k % 2 == 0)
    {
        for (int centre = 1; centre <= n; centre ++)
        {
            queue < int > qu;
            memset(D, 63, sizeof(D));
            qu.push(centre);
            D[centre] = 0;
            while (qu.size())
            {
                int v = qu.front();
                qu.pop();
                for (int u : Adj[v])
                    if (D[u] > D[v] + 1)
                        D[u] = D[v] + 1, qu.push(u);
            }
            int Cnt = 0;
            for (int i = 1; i <= n; i ++)
                if (D[i] <= k / 2)
                    Cnt ++;
            Mx = max(Mx, Cnt);
        }
    }
    else
    {
        for (int centre = 1; centre <= n; centre ++)
        {
            for (int centre2 : Adj[centre])
            {
                queue < int > qu;
                memset(D, 63, sizeof(D));
                D[centre] = 1;
                D[centre2] = 1;
                qu.push(centre);
                qu.push(centre2);
                while (qu.size())
                {
                    int v = qu.front();
                    qu.pop();
                    for (int u : Adj[v])
                        if (D[u] > D[v] + 1)
                            D[u] = D[v] + 1, qu.push(u);
                }
                int Cnt = 0;
                for (int i = 1; i <= n; i ++)
                    if (D[i] <= (k + 1) / 2)
                        Cnt ++;
                Mx = max(Mx, Cnt);

            }
        }
    }
    return !printf("%d\n", n - Mx);
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void){

  int a,b,c;
  scanf("%d %d %d", &a, &b, &c);
  if (a == b) {
    printf("%d\n", c);
  }
  if (b == c) {
    printf("%d\n", a);
  }
  if (c == a) {
    printf("%d\n", b);
  }

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
uint64_t gcd(uint64_t u, uint64_t v) {
  while (v != 0) {
    uint64_t r = u % v;
    u = v;
    v = r;
  }
  return u;
}

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

  uint64_t n, m;
  string s, t;
  cin >> n >> m >> s >> t;
  uint64_t lcm = n * m / gcd(n, m);
  unordered_map<int, char> good;
  for (size_t i = 0; i < s.size(); ++i) {
    good[i * lcm / n] = s[i];
  }
  for (size_t i = 0; i < t.size(); ++i) {
    if (good.find(i * lcm / m) != good.end()) {
      if (good[i * lcm / m] != t[i]) {
        cout << "-1\n";
        return 0;
      }
    }
  }
  cout << lcm << "\n";
}


Measured memory_bytes: 4260
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }

int main(){
    INT(n);
    vector<int> vec(n);
    in(vec);
    sort(rall(vec));
    int minv=vec[0],ans=vec[0],harf=vec[0]/2;
    for(int i=1;i<n;i++){
        if(abs(vec[i]-harf)<minv){
            minv=abs(vec[i]-harf);
            ans=vec[i];
        }
    }
    out(vec[0],ans);
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define VIN(n,v) for(int64_t i=0;i<(n);i++){cin >> (v).at(i);}

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

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

int ctoi(char c){
  return c - '0';
}

int main(){
  string s;
  string t;
  cin >> s >> t;
  int64_t c = INT_MIN;
  REP(i,s.size() - t.size()+1){
    bool chk = true;
    REP(j,t.size()){
      if (s.at(i+j) == '?' || s.at(i+j) == t.at(j)){
      }else{
        chk = false;
        break;
      }
    }
    if (chk){
      c = i;
    }
  }
  if (c == INT_MIN){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  REP(i,s.size()){
    if (s.at(i) != '?'){
      cout << s.at(i);
    }else{
      if (c <= i and c + t.size() > i){
        cout << t.at(i-c);
      }else{
        cout << 'a';
      }
    }
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const ll INF=(1e18);
const int maxn=(2e5)+10;
int n,m;
ll dp[maxn],sum;
struct node { int x,y; };
vector<node> d[maxn];
ll tr[maxn*4],lazy[maxn*4];
void pushdown(int root) {
	if (!lazy[root]) return;
	tr[root*2]+=lazy[root];
	tr[root*2+1]+=lazy[root];
	lazy[root*2]+=lazy[root];
	lazy[root*2+1]+=lazy[root];
	lazy[root]=0;
}
void add(int L,int R,int l,int r,int root,ll delta) {
	if (L<=l&&r<=R) {
		tr[root]+=delta;
		lazy[root]+=delta;
		return;
	}
	pushdown(root);
	int mid=(l+r)/2;
	if (L<=mid) add(L,R,l,mid,root*2,delta);
	if (mid<R) add(L,R,mid+1,r,root*2+1,delta);
	tr[root]=min(tr[root*2],tr[root*2+1]);
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	read(m);
	int x,y,z;
	for (int i=1;i<=m;i++) {
		read(x); read(y); read(z);
		d[y].push_back((node){x,z});
		sum+=z;
	}
	for (int i=1;i<=n*4;i++) tr[i]=INF;
	add(0,0,0,n,1,-INF);
	for (int i=1;i<=n+1;i++) {
		for (int j=0;j<d[i-1].size();j++) {
			x=d[i-1][j].x; y=d[i-1][j].y;
			add(0,x-1,0,n,1,y);
		}
		dp[i]=tr[1];
		//printf("%d %lld\n",i,dp[i]);
		if (i>n) break;
		add(i,i,0,n,1,dp[i]-INF);
	}
	printf("%lld\n",sum-dp[n+1]);
	return 0;
}

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

int main(void) {
	llong h; cin >> h;
	llong sum = 0;
	while (h != 1) {
		h /= 2;
		sum += 1;
	}
	cout << (llong)(pow(2, (sum + 1)) - 1) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>

using namespace std;

int main(){
  int n;
  int cake = 0, donut = 0;
  cin >> n;
  cake = n / 4 + 1;
  donut =  n / 7 + 1;
  for(int i = 0; i <= cake; ++i){
    for(int j = 0; j <= donut; ++j){
      if((i * 4 + j * 7) == n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#define AMA (100000007)
using namespace std;
int r,c,a1,a2,b1,b2,K;
typedef pair<int,int> P;
inline int ab(int a){ return a>0?a:-a; }
int dx[4][2]={ {1,0},
	       {-1,0},
	       {0,1},
	       {0,-1} };
int dy[4][2]={ {0,1},
	       {0,-1},
	       {-1,0},
	       {1,0} };
int dp[1001][1001];

struct st{
  int x,y,c;
  st(int x,int y,int c) : x(x),y(y),c(c) {}
};
int dmx[]={1,0,-1,0};
int dmy[]={0,1,0,-1};
int memo[1001][1001];
int solve(int x,int y,int num){
  /*  if(memo[x][y]!=num) return 0;
  if(x==b1 && y==b2){/*printf("%d %d %d %d\n",x,y,st,num); return dp[x][y][st]=1;}
  if(K<=num) return 0;
  if(dp[x][y][st]!=-1) return dp[x][y][st];

  int ret=0;
  for(int i=0;i<2;i++){
    int nx = (x + dx[st][i])%r;
    int ny = (y + dy[st][i])%c;
    if(nx<0) nx=r-1;
    if(ny<0) ny=c-1;
    ret+=(solve(nx,ny,st,num+1))%AMA;
    ret%=AMA;
  }*/

  if(x==b1 && y==b2) return dp[x][y]=1;
  if(K<=num) return dp[x][y]=0;
  if(dp[x][y]!=-1) return dp[x][y];
  int ret=0;
  for(int i=0;i<4;i++){
      int nx=(x+dmx[i])%r;
      int ny=(y+dmy[i])%c;
      if(nx<0) nx=r-1;
      if(ny<0) ny=c-1;
      if(memo[nx][ny]==num+1){
	ret+=(solve(nx,ny,num+1))%AMA;
	ret%=AMA;
      }
  }
  return dp[x][y]=ret;
}
void search(int x,int y){
  queue<st> q;
  q.push(st(x,y,0));
  memo[x][y]=0;
  while(!q.empty()){
    st p = q.front(); q.pop();
    x = p.x;
    y = p.y;
    //    if(x==b1 && y==b2) return p.c;
    for(int i=0;i<4;i++){
      int nx=(x+dmx[i])%r;
      int ny=(y+dmy[i])%c;
      if(nx<0) nx=r-1;
      if(ny<0) ny=c-1;
      if(memo[nx][ny]!=-1) continue;
      memo[nx][ny]=p.c+1;
      q.push(st(nx,ny,p.c+1));
    }
  }
}
int main(){
  memset(dp,-1,sizeof(dp));
  memset(memo,-1,sizeof(memo));
  scanf("%d %d %d %d %d %d",&r,&c,&a1,&a2,&b1,&b2);
  int res=0;
  search(a1,a2);
  K = memo[b1][b2];
  //   printf("%d\n",K);
  if(a1==b1 && a2==b2) puts("1");
  /*  else if(a1==b1 || a2==b2){
    for(int i=0;i<2;i++) res+=(solve(a1,a2,i,0))%AMA;    
    printf("%d\n",res);
  }
  else{
    for(int i=0;i<4;i++) res+=(solve(a1,a2,i,0))%AMA;
    printf("%d\n",res);
    }*/
  printf("%d\n",(solve(a1,a2,0))%AMA);
}

Measured memory_bytes: 8988
#!/usr/bin/perl
#= CPAN mocules =====================================================#
use strict;				# strictモード
use warnings;			# 警告有効

#= Global values ====================================================#
#= Local routines ===================================================#
sub gcd{
	my $a = shift;
	my $b = shift;

	if ($a < $b){
		my $tmp = $a;
		$a = $b;
		$b = $tmp;
	}
	
	my $r = $a % $b;
	while ($r != 0){
		$a = $b;
		$b = $r;
		$r = $a % $b;
	}

	return $b;
}

sub main(){
	my $in = <>;
	chomp $in;
	my @result = (0) x 200;
	my $sum = 0;

	foreach my $a (1 .. $in){
		foreach my $b (1 .. $in){
			my $r = gcd($a, $b);
			
			if ($result[$r - 1] == 0){
				my $lsum = 0;
				foreach my $c (1 .. $in){
					$lsum += gcd($r, $c);
				}
				$result[$r - 1] = $lsum;
			}
			$sum += $result[$r - 1];
		}
	}
	
	print $sum, "\n";
	
	return 0;
}

#----- 実行 -----#
exit( main() );




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

int main(){
  
  int a,b;
  cin >> a >> b;
  vector<int> vec(a);
  for (int i = 0; i < a; i++) {
    
    cin >> vec.at(i);         
  
  }
  
   sort( vec.begin(),vec.end() );
   int sum = 0;  
  
   for(int i=0; i < b; i++){
     
     sum += vec.at(i);
     
   }
  
     cout << sum << endl;
  
}

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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int W, H, N; 
int b[16], k[16];
int s[10][10];
int ans[10][10];
int used[10][10];
int TX[20], TY[20];
class DFSError {};
void dfs(int idx){
  if(idx == N) {
    if(ans[0][0] != -1) throw DFSError();
    REP(y, H)REP(x, W) ans[y][x] = used[y][x];
    return;
  }
  /*
  printf("idx = %d\n", idx);
  REP(y, H){
    REP(x, W){
      cout << used[y][x];
      if(x != W - 1) cout << " ";
      else cout << endl;
    }
  }
  */
  int tx = TX[b[idx] - 1];
  int ty = TY[b[idx] - 1];
  //printf("idx = %d tx = %d ty = %d\n", idx, tx, ty);
  
  assert(idx < N);
  assert(b[idx] >= 1 && b[idx] <= N);
  assert(tx != -1);
  for(int h = 1; h <= k[idx]; h++) if(k[idx] % h == 0){
    int w = k[idx] / h;
    for(int by = 0; by > -h; by--) for(int bx = 0; bx > -w; bx--){
      int sx = tx + bx;
      int sy = ty + by;
      bool ok = true;
      for(int y = 0; y < h; y++) for(int x = 0; x < w; x++) {
        if(!valid(sx + x, sy + y, W, H) || used[sy + y][sx + x] != -1) ok = false;
      }
      if(ok){
        int tmp[10][10];
        memcpy(tmp, used, sizeof(used));
        for(int y = 0; y < h; y++) for(int x = 0; x < w; x++) {
          used[sy + y][sx + x] = b[idx];
        }
        dfs(idx + 1);
        memcpy(used, tmp, sizeof(used));
      }
    }
  }
}

int main(){
  while(cin >> W >> H >> N && (W | H | N)){
    REP(i, N) cin >> b[i] >> k[i];
    REP(y, H)REP(x, W) cin >> s[y][x];
    try{
      memset(used, -1, sizeof(used));
      memset(ans, -1, sizeof(ans));
      memset(TX, -1, sizeof(TX));
      memset(TY, -1, sizeof(TY));
      REP(y, H) REP(x, W) if(s[y][x] > 0) TX[s[y][x] - 1] = x, TY[s[y][x] - 1] = y;
      REP(i, N)if(TX[i] == -1){
        /*
        cerr << W << " " << H << " " << N << endl;
        REP(j, N) cerr << b[j] << " " << k[j] << endl;
        REP(y, H) { REP(x, W) cerr << s[y][x] << " "; cerr << endl; }
        assert("bord is dissapeared" == "");
        */
        throw 0;
      }
      dfs(0);
      if(ans[0][0] == -1) throw DFSError();
      REP(y, H){
        REP(x, W){
          cout << ans[y][x];
          if(x != W - 1) cout << " ";
          else cout << endl;
        }
      }
    }catch(...){
      cout << "NA" << endl;
    }
  }
  return 0;
}

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

int top,S[1000];
void push(int);
int pop();

int main(){
  int a,b;
  top = 0;
  char s[100];

  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(s[0]=='-'){
      b=pop();
      a=pop();
      push(a-b);
    }
    else if(s[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }
    else {
      push(atoi(s));
    }
  }
  printf("%d\n",pop());

  return 0;
}

void push(int x){
  S[++top] = x;
}

int pop(){
  top--;

  return S[top+1];
}


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



vector<vector<int>> get_comb(vector<vector<int>> comb, int N, int M){
    vector<vector<int>> ret;
    if (comb.size() == 0){
        vector<int> c(1);
        for (int i=1; i<=M; i++){
            c[0] = i;
            ret.push_back(c);
        }
        return get_comb(ret, N, M);
    }
    if (comb[0].size() == N){
        return comb;
    }
    for (int i=0; i<comb.size(); i++){
        int n = comb[i].size();
        vector<int> newone(n+1);
        copy(comb[i].begin(), comb[i].end(), newone.begin());
        for (int j=comb[i][n-1]; j<=M; j++){
            newone[n] = j;
            ret.push_back(newone);
        }
    }
    return get_comb(ret, N, M);
}

int main(){
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> A;
    vector<int> B;
    vector<int> C;
    vector<int> D;
    for (int i=0; i<Q; i++){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--;
        b--;
        A.push_back(a);
        B.push_back(b);
        C.push_back(c);
        D.push_back(d);
    }
    vector<vector<int>> comb;
    comb = get_comb(comb, N, M);
    // cout << comb.size() << endl;
    // for (vector<int> v : comb){
    //     for (int vv : v){
    //         cout << vv;
    //     }
    //     cout << endl;
    // }
    // printf("\n");
    ll ans = 0;
    for (vector<int> v : comb){
        // cout << "v: " << v[0] << v[1] << v[2] << endl;
        ll score = 0;
        for (int i=0; i<Q; i++){
            // cout << v[B[i]] << v[A[i]] << C[i] << endl;
            if (v[B[i]] - v[A[i]] == C[i]){
                // cout << D[i] << endl;
                score += D[i];
            }
        }
        if (ans < score){
            ans = score;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 28884
#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;
    cout << (1000 - n % 1000) % 1000 << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

ll ppow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
ll dp[200][10];
signed main(){
	int h,w,k;cin>>h>>w>>k;
	dp[0][0]=1;
	rep(i,h){
		rep(j,w){
			rep(k,1<<(w-1)){
				bool flag=true;
				int c=j;
				rep(t,w-1){
					if(k>>t&1){
						if(t&&(k>>(t-1)&1)){
							flag=false;break;
						}
						if(t==j-1)c=j-1;
						else if(t==j)c=j+1;
					}
				}
				if(flag){
					(dp[i+1][c]+=dp[i][j])%=MOD;
				}
			}
		}
	}
	cout<<dp[h][k-1]<<endl;
}

Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n; cin >> n;
	vector<int> a(n); rep(i, n)cin >> a[i];
	ll res = 0;
	rep(i, n - 1)
	{
		if (a[i] % 2 == 1 && a[i + 1] > 0)
		{
			--a[i];
			--a[i + 1];
			++res;
		}
	}
	rep(i, n)res += a[i] / 2;
	cout << res << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main() {
        int n;
	cin>>n;
        int a[n+1];
	for (int i=0; i<n;i++) {
		cin>>a[i];
         }
        int k=0;
        for (int i=0; i<n;i++) {
         while (a[i] % 2 == 0) {
                   a[i] /= 2;
                   k++;
            }
       }
	cout<<k<<"\n";
	
}

Measured memory_bytes: 3648
N = int(input())
h = list(map(int,input().split()))
cost = [0]*N
cost[0] = 0
cost[1] = abs(h[1]-h[0])

for i in range(2,N):
  cost[i] = min((cost[i-2]+abs(h[i]-h[i-2])), (cost[i-1]+abs(h[i]-h[i-1])))
print(cost[-1])

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

int main(){
    int n;
    cin >> n;
    vector<vector<int> > A(3, vector<int>(10));
    vector<vector<int> > B(3, vector<int>(10));
    vector<vector<int> > C(3, vector<int>(10));
    vector<vector<int> > D(3, vector<int>(10));

    int b, f, r, v;

    for(int i = 0; i < n; i++){
        cin >> b >> f >> r >> v;
        if(b == 1){
            A[f - 1][r - 1] += v;
        }
        if(b == 2){
            B[f - 1][r - 1] += v;
        }
        if(b == 3){
            C[f - 1][r - 1] += v;
        }
        if(b == 4){
            D[f - 1][r - 1] += v;
        }
    }
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 10; j++){
            cout << " " << A[i][j];
        }
        cout << endl;
    }
    cout  << "####################" << endl;
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 10; j++){
            cout << " " << B[i][j];
        }
        cout << endl;
    }
    cout  << "####################" << endl;
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 10; j++){
            cout << " " << C[i][j];
        }
        cout << endl;
    }
    cout  << "####################" << endl;
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 10; j++){
            cout << " " << D[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3116
main = do
  list <- map read.words<$>getLine
  if canHaiku list
     then putStrLn "YES"
     else putStrLn "NO"

isFive 5 = True
isFive _ = False

isSeven 7 = True
isSeven _ = False

canHaiku = lengthCheck [] [isFive,isFive,isSeven]

lengthCheck gs fs [] = True
lengthCheck _ [] _ = False
lengthCheck gs (f:fs) (x:xs)
  | f x = lengthCheck [] (gs++fs) xs
  | otherwise = lengthCheck (f:gs) fs (x:xs)


Measured memory_bytes: 508
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vll vector<long long>
#define pll pair<long long, long long>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1e18
 

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;

long long power(long long x, long long y, long long p)
{
long long res = 1;


x = x % p;


while (y > 0)
{
if (y & 1)
res = (res*x) % p;


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

void solve()
{
    string s;
    cin>>s;
    // no of multiples of 2019 substrings
    mll m;
    m[0]=1;
    ll p10=0;
    ll n=s.length();
    ll i;
    ll res=0;
    const int mm = 2019;
    ll sum=0;
    
    for(i=n-1;i>=0;i--)
    {
       ll no = s[i]-'0';
       ll no2 = no*power(10,p10,mm);
       no2%=mm;
       sum+=no2;
       sum%=mm;
       res+=m[sum];
    //    cout<<sum<<" "<<m[sum]<<"\n";
       m[sum]++;
       p10++;
    }
    cout<<res<<"\n";

}



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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

Measured memory_bytes: 3784
from math import radians, cos, sin


def calc_koch(depth, p1, p2):
    if depth == 0:
        return

    s = ((2 * p1[0] + 1 * p2[0]) / 3.0, (2 * p1[1] + 1 * p2[1]) / 3.0)
    t = ((1 * p1[0] + 2 * p2[0]) / 3.0, (1 * p1[1] + 2 * p2[1]) / 3.0)
    ux = (t[0] - s[0]) * cos(radians(60)) - (t[1] - s[1]) * sin(radians(60)) + s[0]
    uy = (t[0] - s[0]) * sin(radians(60)) + (t[1] - s[1]) * cos(radians(60)) + s[1]
    u = (ux, uy)

    calc_koch(depth-1, p1, s)
    print('{0:.8f} {1:.8f}'.format(*s))
    calc_koch(depth-1, s, u)
    print('{0:.8f} {1:.8f}'.format(*u))
    calc_koch(depth-1, u, t)
    print('{0:.8f} {1:.8f}'.format(*t))
    calc_koch(depth-1, t, p2)


if __name__ == '__main__':
    # ??????????????\???
    depth = int(input())

    # ??????
    p1 = (0.0, 0.0)
    p2 = (100.0, 0.0)

    print('{0:.8f} {1:.8f}'.format(*p1))
    result = calc_koch(depth, p1, p2)
    print('{0:.8f} {1:.8f}'.format(*p2))

Measured memory_bytes: 7960
n, q = gets.split.map &:to_i
Vertex = Struct.new(:count, :connected)
vertexes = n.times.map {Vertex[0, []]}
(n-1).times do
  a, b = gets.split.map &:to_i
  vertexes[a-1].connected << b-1
  vertexes[b-1].connected << a-1
end
q.times do
  p, x = gets.split.map &:to_i
  vertexes[p-1].count += x
end

def search(i, value, graph, parent = 0)
  node = graph[i]
  v = node.count += value
  node.connected.each { |j| search(j, v, graph, i) if j != parent }
end
search 0, 0, vertexes
puts vertexes.map { |v| v.count }.join(" ")

Measured memory_bytes: 277696
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++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(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define VECV(a,n,m) vector<vector<int>> a(n, vector<int>(m));
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  int t[110000],x[110000],y[110000];
  t[0]=x[0]=y[0]=0;
  cin>>N;
  rep(i,N)cin>>t[i+1]>>x[i+1]>>y[i+1];
  bool f=true;
  rep(i,N){
    int dt=t[i+1]-t[i];
    int dist=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
    if(dist>dt) f=false;
    if(dist%2!=dt%2) f=false;
  }
  if(f)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

}


Measured memory_bytes: 1408
import sys
sys.setrecursionlimit(10**6)
f=lambda:map(int,input().split())
n,k=f()
g=[[] for _ in range(n)]
for i in range(n-1):
  a,b=f()
  g[a-1]+=[b-1]
  g[b-1]+=[a-1]
l=[0]*n
for _ in range(k):
  p,x=f()
  l[p-1]+=x
def dfs(v,p=-1):
  for c in g[v]:
    if c==p: continue
    l[c]+=l[v]
    dfs(c,v)
dfs(0)
print(*l)

Measured memory_bytes: 283156
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    s = S()
    t = [c for c in 'ATCG']

    return t[t.index(s) ^ 1]


print(main())




Measured memory_bytes: 5336
# -*- coding: utf-8 -*-
#ABC142E
import sys
import math
import collections
#sys.setrecursionlimit(100000)


n=int(input())

#tmp = input().split()
#n,x = list(map(lambda a: int(a), tmp))

tmp = input().split()
d = list(map(lambda a: int(a), tmp))


sum = 0
for i in range(n):
	for j in range(i+1,n):
		sum+=d[i]*d[j]



print(sum)



Measured memory_bytes: 3436
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int x[] = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
        }
        int sum = 1000000000;
        for (int i = 0; i + k - 1 < n; i++) {
            sum = Math.min(sum, Math.min(Math.abs(x[i]) + Math.abs(x[i + k - 1] - x[i]), Math.abs(x[i + k - 1]) + Math.abs(x[i + k - 1] - x[i])));
        }
        System.out.println(sum);
    }
}

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

using namespace std;

const int INF = 1e9 + 7;



void solve()
{
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();

    vector<vector<int> > dp(n + 1, vector<int>(m + 1, 0));

    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= m; ++j)
        {
            if(s[i - 1] == t[j - 1])
                dp[i][j] = 1 + dp[i - 1][j - 1];
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }

    string answer(dp[n][m], 0);
    int i = n, j = m, index = dp[n][m] - 1;
    while(i && j && index >= 0)
    {
        if(s[i - 1] == t[j - 1])
            answer[index] = s[i - 1], --i, --j, --index;
        else if(dp[i - 1][j] > dp[i][j - 1])
            --i;
        else
            --j;
    }

    cout << answer << '\n';


}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //srand (time(0));

    solve();
}






Measured memory_bytes: 35584
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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 all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    long long N, K; cin >> N >> K;
    cout << min(N % K, K - (N % K)) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;
const ld pi = acos(-1.0);

struct SegT {
private:
	int sz; vector<ll> node, nodel, noder, nodeall;
	const ll init_c = -1000000007;
public:
	SegT(vector<ll> v) {
		int n = v.size();
		sz = 1;
		while (sz < n)sz *= 2;
		node.resize(2 * sz - 1, 0);
		nodel.resize(2 * sz - 1, 0);
		noder.resize(2 * sz - 1, 0);
		nodeall.resize(2 * sz - 1, 0);
		rep(i, n) {
			node[i+sz-1] = max((ll)0,v[i]);
			nodel[i+sz-1 ] = max((ll)0, v[i]);
			noder[i+sz-1] = max((ll)0, v[i]);
			nodeall[i+sz-1] = v[i];
		}
		per(i, sz - 1) {
			merge(i);
		}
	}
	void merge(int i) {
		int l = 2 * i + 1; int r = 2 * i + 2;
		node[i] = max({ node[l],node[r],noder[l] + nodel[r] });
		nodel[i] = max({ nodel[l],nodeall[l] + nodel[r] });
		noder[i] = max({ noder[r],nodeall[r] + noder[l] });
		nodeall[i] = nodeall[l] + nodeall[r];
	}
	void update(int k, int a) {
		k += sz - 1;
		node[k] = max(0,a);
		nodel[k] = max(0, a);
		noder[k] = max(0, a);
		nodeall[k] = a;

		while (k > 0) {
			k = (k - 1) / 2;
			merge(k);
		}
	}
	ll query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = sz;
		if (r <= a || b <= l)return init_c;
		else if (a <= l && r <= b)return node[k];
		else {
			ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return max(vl,vr);
		}
	}
	ll query() {
		return node[0];
	}
};

void solve() {
	int n, q; cin >> n >> q;
	vector<ll> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	SegT st(a);
	cout << max((ll)0,st.query()) << endl;
	rep(i, q) {
		int k, c; cin >> k >> c; k--;
		st.update(k, c);
		cout << max((ll)0,st.query()) << endl;
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}




Measured memory_bytes: 12644
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
using namespace std;


int main() {
	map<int, int> mp;
	long long int n, m = 0,r=0,cou=0,s=0;
	long double dp[4000][1505] = {},p[4000],tmp=0;
	string str, str2;
	cin >> str ;
	for (int i = 0; i < str.length(); i++) {

		if (str[i] == 'S') {
			s++;
		}
		else if(str[i] == 'T'&&s==0){
			
			cou+=2;
		}
		else {
			s--;
		}


	}


	cout << cou;
}


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

bool check(string s,int b,int e){
  int n = e -b;
  for(int i = 0; i < n;i++){
    if(s[b+i] != s[e-i]) return false;
  }
  return true;
}

int main(void){
  string s;
  cin >> s;
  int N = s.size();
  bool a = false;
  if(check(s,0,N-1) && check(s,0,(N-1)/2-1) && check(s,(N+3)/2-1,N-1)) a = true;

  if(a) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

template <typename T>
class fenwick_tree {
public:
    fenwick_tree(int n) : n(n), dat(n, 0) {}

    void add(int i, T value) {
        for(; i<n; i |= i + 1) {
            dat[i] += value;
        }
    }

    // [0..r]
    T sum(int i) const {
        T res = 0;
        for(; i>=0; i = (i & (i+1)) - 1) {
            res += dat[i];
        }
        return res;
    }
    // [l, r)
    T sum(int l, int r) const {
        return sum(r-1) - sum(l-1);
    }

private:
    const int n;
    std::vector<T> dat;
};

int main() {
    int q, lim;
    while(cin >> q >> lim, q) {
        vector<int> query(q), x(q);
        map<int, int> pos;
        map<int, int> unzip;
        for(int i = 0; i < q; ++i) {
            cin >> query[i] >> x[i];
            if(query[i] == 0 && pos.count(x[i]) == 0) {
                int idx = pos.size();
                pos[x[i]] = idx;
                unzip[idx] = x[i];
            }
        }

        fenwick_tree<int> bit(pos.size());
        auto get_idx = [&](int cnt) {
            int lb = -1, ub = pos.size() - 1;
            while(ub - lb > 1) {
                int m = (ub + lb) / 2;
                if(bit.sum(m) >= cnt) {
                    ub = m;
                } else {
                    lb = m;
                }
            }
            return ub;
        };
        for(int i = 0; i < q; ++i) {
            if(query[i] == 0) {
                bit.add(pos[x[i]], 1);
                if(bit.sum(pos.size() - 1) > lim) {
                    bit.add(get_idx(1), -1);
                }
            } else if(query[i] == 1) {
                bit.add(get_idx(x[i]), -1);
            } else if(query[i] == 2) {
                cout << unzip[get_idx(x[i])] << endl;
            } else {
                bit.add(pos[x[i]], -1);
            }
        }
        cout << "end" << endl;
    }
}


Measured memory_bytes: 44820
from collections import defaultdict
K=int(input())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

gcd_set = defaultdict(int)
for i in range(1, K+1):
    for j in range(i, K+1):
        res = gcd(i,j)
        gcd_set[(i,j)] = res
        gcd_set[(j,i)] = res

ans=0
for i in range(1,K+1):
    for j in range(1,K+1):
        left = gcd_set[(i,j)]

        if left == 1:
            ans += K
        else:    
            for k in range(1, K+1):
                if k == 1:
                    ans += 1
                elif k%left == 0:
                    ans += left
                else:
                    ans += gcd_set[(left, k)]
            
print(ans)


Measured memory_bytes: 73932
D = int(input())
N = 26
c = [int(i) for i in input().split()]
s = list()
last = [0 for i in range(N)]
score = 0

for i in range(D):
  s.append([int(j) for j in input().split()])

for i in range(D):
  n = int(input())
  last[n-1] = i+1
  for j in range(N):
    last_day = i+1-last[j]
    score -= c[j]*last_day
  score += s[i][n-1]
  print(score)


Measured memory_bytes: 9396
import sys
input = sys.stdin.buffer.readline
N,Q = map(int,input().split())
BIT = [0]*(N+1)

def BIT_query(idx):
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

def BIT_update(idx,x):
    while idx <= N:
        BIT[idx] += x
        idx += idx&(-idx)
    return

a = list(map(int,input().split()))
for i in range(N):
    BIT_update(i+1,a[i])

for i in range(Q):
    a,b,c = map(int,input().split())
    if a == 0:
        BIT_update(b+1,c)
    else:
        print(BIT_query(c)-BIT_query(b))


Measured memory_bytes: 129656
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
  
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<max(c-(a-b),0)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

bool isPrime(int num)
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

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

    for (int i = 0; i <= N; i++)
    {
        for (int j = 0; j <= M; j++)
        {
            if ((i * (M - j) + (N - i) * j) == K)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
input = input().split()
# inputList = list(input[0])

a = int(input[0])
b = int(input[1])
# c = int(input[2])

ans =int(( 3*a + b )/2)
print(ans)

# inputList.sort()
# 
# list = [a+b, b+c ,c+a]
# 
# ans = min(list)
# print(ans)



# flg = 1
# for i in range(0, len(inputList)-1):
#     if inputList[i] == inputList[i + 1]:
#         flg = 0
#         break
#
# if flg == 0:
#     print("Bad")
# else:
#     print("Good")


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


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


	int N;
	cin >> N;
	ll kotae = 0;
	int mae = 0;
	rep(i, N) {
		int a;
		cin >> a;
		if (mae && a) {
			kotae++;
			a--;
		}
		kotae += a / 2;
		mae = a % 2;
	}
	co(kotae);


	Would you please return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

int main(){
  int n;
  ll k;
  cin >> n >> k;

  vector<int> p(n);
  rep(i,n) cin >> p.at(i);
  vector<ll> c(n);
  rep(i,n) cin >> c.at(i);
  
  vector<vector<ll>> data(n, vector<ll>(4,-1));
  rep(i,n){
    vector<int> check(n,-1);
    vector<ll> score(n);
    int now=i;
    int next;
    check.at(i)=0;
    score.at(now)=0;
    rep(j,n){
      next = p.at(now)-1;
      //cout << next << " ";
      if(check.at(next)!=-1){
        data.at(i).at(0) = check.at(next);
        data.at(i).at(1) = score.at(next);
        data.at(i).at(2) = score.at(now) +  c.at(next) - score.at(next);
        data.at(i).at(3) = j+1-check.at(next);
        break;
      }
      check.at(next) = j+1;
      score.at(next) = score.at(now)+c.at(next);
      now = p.at(now)-1;
    }
  }
  //rep(i,n) cout << data.at(i).at(2) << " ";
 

  vector<ll> ansscore(n, -10000000000);
  rep(i,n){
    if(data.at(i).at(3)>k){
      int now = p.at(i)-1;
      ll t = c.at(now);
      ansscore.at(i) = t;
      rep(j, k-1){
        t += c.at(p.at(now)-1);
        ansscore.at(i) = max(ansscore.at(i), t);
        now = p.at(now)-1;
      }
    }else if(data.at(i).at(2)<=0){
      int now = p.at(i)-1;
      ll t = c.at(now);
      ansscore.at(i) = t;
      rep(j, n-1){
        t += c.at(p.at(now)-1);
        ansscore.at(i) = max(ansscore.at(i), t);
        now = p.at(now)-1;
      }
    }else{
      int now = p.at(i)-1;
      ll t = c.at(now);
      ansscore.at(i) = t;
      rep(j, data.at(i).at(3)+k%data.at(i).at(3)-1){
        t += c.at(p.at(now)-1);
        ansscore.at(i) = max(ansscore.at(i), t);
        now = p.at(now)-1;
      }
      ansscore.at(i) = ansscore.at(i) + data.at(i).at(2)*((k/data.at(i).at(3))-1);
    }
  }
  ll ans = -10000000000;
  rep(i,n) ans = max(ansscore.at(i), ans);
  //rep(i,n) cout << ansscore.at(i) << " ";
  cout << ans;
}


Measured memory_bytes: 4080