akhauriyash/Code-Regression huggingface dataset:
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define sz(a) (int)(a).size() 
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;  
#define mt make_tuple 
#define vec vector
 
#define int long long 
 
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
 
typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

void solve(int test) {
	int n ; cin >> n ;
	cout << (1000 - n%1000)%1000 ;
}
 
int32_t main() {

    fast;
	int t=1;
	// cin>>t;
	rep(i,0,t) {
		solve(i) ;
	}
 
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 3652
import sys

input = sys.stdin.readline


def main():
    H, W = [int(x) for x in input().split()]

    s = []
    s.append(['.' for i in range(W + 2)])
    for _ in range(H):
        S = input().strip()
        s.append(list('.' + S + '.'))

    s.append(['.' for i in range(W + 2)])

    for i in range(1, H + 1):
        for j in range(1, W + 1):
            if s[i][j] == '#':
                if all([s[i - 1][j] == '.', s[i][j - 1] == '.', s[i + 1][j] == '.', s[i][j + 1] == '.']):
                    print("No")
                    exit()

    print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
k = int(input())
a, b = map(int, input().split())

flag = 0
i = 1
while flag == 0:
    if k * i <= b:
        if a <= k * i <= b:
            flag = 1
        i = i + 1
    else:
        break

if flag == 1:
    print("OK")
else:
    print("NG")


Measured memory_bytes: 9140
#include <stdio.h>
#define N 10
int main(void)
{
	int chpre, p[N], cnt, max, i, sum;
	cnt = 0; max = 0; sum = 0;

	do{
		scanf("%d", &chpre);
	}while(chpre < 2 || chpre > N);

	for(i = 0; i < chpre; i++){
		do{
			scanf("%d", &p[i]);
		}while(p[i] < 100 || p[i] > 10000 || p[i] % 2 != 0);

		if(max < p[i]){
			max = p[i];
			cnt = i;
		}
	}

	p[cnt] /= 2;

	for(i = 0; i < chpre; i++){
		sum += p[i];
	}

	printf("%d", sum);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int Maxn=13;
int n,m,p[Maxn],ans,light[Maxn][Maxn],cnt[Maxn];
bool on[Maxn];
void cal(void)
{
	for(int i=1;i<=m;i++)
	{
		int tmp=0;
		for(int j=1;j<=cnt[i];j++)
			tmp^=on[light[i][j]];
		if(tmp!=p[i]) return ;
	}
	ans++;
}
void dfs(int u)
{
	if(u==n+1) cal();
	else
	{
		dfs(u+1);
		on[u]=true;
		dfs(u+1);
		on[u]=false;
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&cnt[i]);
		for(int j=1;j<=cnt[i];j++)
			scanf("%d",&light[i][j]);
	}
	for(int i=1;i<=m;i++)
		scanf("%d",&p[i]);
	dfs(1);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
  
  static int n;
  static double[] p;
  static double[][] dp;
  
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    n = in.nextInt();
    p = new double[n + 1];
    for (int i = 1; i <= n; ++i) {
      p[i] = in.nextDouble();   
    }

    dp = new double[n + 1][n + 1];

    dp[0][0] = 1;
    
    for (int i = 1; i <= n; ++i) {
      for (int j = 0; j <= i; ++j) {
        dp[i][j] += (1 - p[i]) * dp[i - 1][j];
        if (j > 0) {
          dp[i][j] += p[i] * dp[i - 1][j - 1];
        }
      }
    }


    double ans = 0;
    for (int j = ((n+1) / 2); j <= n; ++j) {
      System.err.print(dp[n][j] + " ");
      ans += dp[n][j];
    } System.err.println();

    System.out.println(ans);//dp(0, 0));
  }

  static double dp(int i, int j) {
    if (i == n) {
      if (j > (n/2)) return 1.0;
      else return 0.0;
    }

    if (dp[i][j] >= 0) return dp[i][j];
    return dp[i][j] = p[i] * dp(i + 1, j + 1) + (1 - p[i]) * dp(i + 1, j);
  }

}

Measured memory_bytes: 122548
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define RFOR(i, begin, end) for(int i=(end)-1, i##_begin_=(begin);i>=i##_begin_;i--)
#define rep(i, N) FOR(i, 0, N)
#define rrep(i, N) RFOR(i, 0, N)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long int;
using V = vector<ll>;
using P = pair<ll, ll>;
using VP = vector<P>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
constexpr int inf = 1e9;
constexpr int mod = 1e9+7;
ll gcd(ll a, ll b) { return b? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}


int main() {
    ll n;
    cin >> n;
    V h(n);
    rep(i, n) cin >> h[i];

    ll ret = 0;
    ll active = 0;
    rep(i, n) {
        if (active >= h[i]) {
            active = h[i];
        }
        else {
            ret += h[i] - active;
            active = h[i];
        }
    }
    cout << ret << endl;
    return 0;
}


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

int main()
{
  int N;
  vector<int> A;
  cin >> N;
  
  for(long long i = 0; i < N; ++i)
  {
    int a;
    cin >> a;
    A.push_back(a);
  }
  
  int max = A[0];
  long long step = 0;
  for(long long i = 1; i < N; i++)
  {
    if(max > A[i])
    {
      step += max - A[i];
    }
    else
    {
      max = A[i];
    }
  }
  
  cout << step << endl;
  
  return 0;
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	
	int ab = a+ b;
	int bc = b + c;
	int ca = c + a;
	
	int mi;
	
	mi = min(ab, bc);
	mi = min(mi, ca);
	
	cout << mi;
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N (2009)
#define K (10009)
#define S (1000009)
using namespace std;

int n,k,cnt,len[N];
char s[N][K];
bitset<K>f[N];
pair<int,int>v[2][K];

int main()
{
	cin>>n>>k;
	for (int i=1; i<=n; ++i)
		cin>>s[i], len[i]=strlen(s[i]);
	f[n+1][0]=1;
	for (int i=n; i>=1; --i)
		f[i]=f[i+1]|(f[i+1]<<len[i]);
	for (int i=1; i<=n; ++i)
		if (f[i+1][k-len[i]])
			v[0][++cnt]=make_pair(i,0);
	for (int i=1; i<=k; ++i)
	{
		char Min='z'; int ncnt=0;
		for (int j=1; j<=cnt; ++j)
			Min=min(Min,s[v[i-1&1][j].first][v[i-1&1][j].second]);
		putchar(Min);
		int ID=n+1;
		for (int j=1; j<=cnt; ++j)
		{
			int id=v[i-1&1][j].first,pos=v[i-1&1][j].second;
			if (s[id][pos]!=Min) continue;
			if (pos<len[id]-1) v[i&1][++ncnt]=make_pair(id,pos+1);
			else ID=min(ID,id);
		}
		for (int j=ID+1; j<=n; ++j)
			if (k-i-len[j]>=0 && f[j+1][k-i-len[j]])
				v[i&1][++ncnt]=make_pair(j,0);
		cnt=ncnt;
	}
}

Measured memory_bytes: 21504
#include <iostream>
#include <string>
using namespace std;
int caz = 0;
string sir1,sir2;
void fct(int i ,int poz,int sum)
{
       if(poz == 1 &&  caz == 0 && i>=0){
            sum += sir2[i]-'0';
       }else if (poz==0 && caz == 0 && i>=0){
            sum -= sir2[i]-'0';
       }else if(poz ==-1 && caz == 0 && i>=0){
            sum = sir2[i]-'0';
       }
       if(sum == 7 && i == 3 ){
          caz = 1;
       }
       if(caz == 0 && i < 3){
                fct(i+1,0,sum);
       }

       if(caz == 0 && i < 3){
                fct(i+1,1,sum);
       }

       if(caz == 1){
            if(poz == 1 && i<3){
                cout<<'+';
            }else if(poz == 0 && i<3){
                cout<<'-';
            }
            if(i>-1)cout<<sir2[i];
            if(poz == -1 ){
                cout<<"=7";
            }
       }
}
int main()
{
    cin>>sir1;
    for(int i=3;i>=0;i--)
    {
        sir2.push_back(sir1[i]);
    }
    fct(-1,-1,0);
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  
  int n,k,x,y;
  
    cin>> n >> k >> x >>y ;
  
  if (n<=k){
    cout << n*x << endl;
  }
  if(n>k){
    cout << x*k + (n-k)*y << endl;
  }
  
  
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

#define MOD 1000000007

long long llpow(long long x, long long n) {
	if (n == 0) return 1;
	if (n & 1) return x * llpow(x * x % MOD, n / 2) % MOD;
	return llpow(x * x % MOD, n / 2) % MOD;
}

int main() {
	long long m; cin >> m;
	string c; cin >> c;
	long long ccnt[10] = {};
	for (int i = 0; i < c.size(); ++i)
		(ccnt[c[i] - '0'] += llpow(10, c.size() - i - 1)) %= MOD;
	vector<int> cipher(10);
	for (int i = 0; i < 10; ++i) cipher[i] = i;
	do {
		long long x = 0;
		for (int i = 0; i < 10; ++i) (x += ccnt[i] * cipher[i]) %= MOD;
		if (x == m) {
			if (c.size() > 1 && cipher[c[0] - '0'] == 0) continue;
			for (int i = 0; i < c.size(); ++i) cout << cipher[c[i] - '0'];
			cout << endl;
			return 0;
		}
	} while (next_permutation(cipher.begin(), cipher.end()));
	cout << -1 << endl;

	return 0;
}


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

using namespace std;

#define int long long

const int inf = 1LL << 55;

struct edge
{
  int to, cap, rev, ini;

  edge() {}

  edge(int to, int cap, int rev, int ini) : to(to), cap(cap), rev(rev), ini(ini) {}
};

using Pi = pair< int, int >;

struct Dinic
{
  vector< vector< edge > > graph;
  vector< int > iter, level;

  Dinic(int V) : graph(V), iter(V), level(V) {}

  Pi add_edge(int from, int to, int cap)
  {
    graph[from].emplace_back(to, cap, graph[to].size(), cap);
    graph[to].emplace_back(from, cap, graph[from].size() - 1, 0);
    return Pi(from, graph[from].size() - 1);
  }

  bool bfs(int s, int t)
  {
    queue< int > que;
    fill(level.begin(), level.end(), -1);
    level[s] = 0;
    que.push(s);
    while(!que.empty()) {
      int v = que.front();
      que.pop();
      for(edge e : graph[v]) {
        if(e.cap > 0 && level[e.to] < 0) {
          que.push(e.to);
          level[e.to] = level[v] + 1;
        }
      }
    }
    return level[t] >= 0;
  }

  int dfs(int v, int t, int f)
  {
    if(v == t) return f;
    for(int &i = iter[v]; i < (int) graph[v].size(); i++) {
      edge &e = graph[v][i];
      if(e.cap > 0 && level[e.to] > level[v]) {
        int d = dfs(e.to, t, min(f, e.cap));
        if(d > 0) {
          e.cap -= d;
          graph[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  int max_flow(int s, int t, int ff = inf)
  {
    int flow = 0;
    while(bfs(s, t) && flow < ff) {
      fill(iter.begin(), iter.end(), 0);
      int f;
      while((f = dfs(s, t, ff)) > 0 && flow < ff) flow += f;
    }
    return flow;
  }
};

signed main()
{
  int V, E;
  cin >> V >> E;
  Dinic graph(V);
  vector< Pi > vec;
  for(int i = 0; i < E; i++) {
    int s, t, c;
    cin >> s >> t >> c;
    Pi p = graph.add_edge(s, t, c);
    if(c == 1) vec.push_back(p);
  }
  int flow = graph.max_flow(0, V - 1);
  int flag = 0;
  for(Pi p : vec) {
    edge &e = graph.graph[p.first][p.second];
    if(e.cap == 0 || graph.graph[e.to][e.rev].cap == 0) {
      bool hoge = e.cap == 0;
      e.cap = graph.graph[e.to][e.rev].cap = 0;
      if(hoge) {
        if(e.to != V - 1) graph.max_flow(V - 1, e.to, 1);
        if(p.first != 0) graph.max_flow(p.first, 0, 1);
      } else {
        if(p.first != V - 1) graph.max_flow(V - 1, p.first, 1);
        if(e.to != 0) graph.max_flow(e.to, 0, 1);
      }
      int f = graph.max_flow(0, V - 1, 1);
      if(f == 0) {
        flag = 1;
        break;
      }

      if(hoge) {
        graph.graph[e.to][e.rev].cap = 1;
        if(e.to != V - 1) graph.max_flow(e.to, V - 1, 1);
        if(p.first != 0) graph.max_flow(0, p.first, 1);
      } else {
        e.cap = 1;
        if(p.first != V - 1) graph.max_flow(p.first, V - 1, 1);
        if(e.to != 0) graph.max_flow(0, e.to, 1);
      }
    }
  }
  if(flow - flag > 10000) cout << -1 << endl;
  else cout << flow - flag << endl;

  return 0;
}

Measured memory_bytes: 3640
arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(arr[k-1])


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

#define ms(s,n) memset(s,n,sizeof(s))
#define all(a) a.begin(),a.end()
#define present(t, x) (t.find(x) != t.end())
#define sz(a) int((a).size())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;

const int MOD = (int) 1e9+7;
const int INF = (int) 1e9+1;
inline ll gcd(ll a,ll b){ll r;while(b){r=a%b;a=b;b=r;}return a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int n,m,k;

void inp(){
	cin>>n>>m>>k;
	int a[n],b[m],ans=0,j=0;
	ll suma=0,sumb=0;
	FOR(i,0,n){
		cin>>a[i];
		suma+=a[i];
	}
	FOR(i,0,m)
		cin>>b[i];
	FORd(i,n+1,0){
		if(i<n)
			suma-=a[i];
		if(suma<=k){
			while(j<m&&suma+b[j]+sumb<=k){
				sumb+=b[j];
				j++;
			}
			ans=max(ans,i+j);
		}
	}
	cout<<ans<<endl;
}

int main(){
	//cout<<INT_MAX<<endl;
	inp();
	return 0;
}


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

namespace Test06
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			int[] mountains = new int[10];
			for (int i = 0; i < 10; i++)
			{
				mountains [i]= int.Parse(Console.ReadLine());
			}
			Console.WriteLine(mountains.Max());
			for (int i = 0; i < 10; i++)
			{
				if (mountains[i] == mountains.Max())
				{
					mountains[i] = 0;
					break;
				}
			}
			Console.WriteLine(mountains.Max());
			for (int i = 0; i < 10; i++)
			{
				if (mountains[i] == mountains.Max())
				{
					mountains[i] = 0;
					break;
				}
			}
			Console.WriteLine(mountains.Max());
		}
	}
}

Measured memory_bytes: 9284
#include<bits/stdc++.h>
using namespace std;
const int N = 501;
const int mod = 1e9 + 7;
int main(){
    long long n, p;
    long long ans = 1;
    scanf("%lld %lld", &n, &p);
    for(int i = 2; 1LL * i * i <= p; i++){
        if(p % i) continue;
        int cnt = 0;
        while(p % i == 0){
            p /= i;
            cnt++;
            if(cnt == n){
                ans *= i;
                cnt = 0;
            }
        }
    }
    if(p > 1 && n == 1){
        ans *= p;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

#define repss(name, start, stop, step) for (int name = start; name < stop; name += step)
#define reps(name, start, stop) repss(name, start, stop, 1)
#define rep(name, stop) reps(name, 0, stop)

using namespace std;

int count_divisors(int n) {
  int cnt = 0;
  reps(a, 1, n+1) if (n % a == 0) cnt++;
  return cnt;
}

int main() {
  int N;
  scanf("%d", &N);

  int cnt = 0;
  repss(n, 1, N+1, 2) cnt += count_divisors(n) == 8;
  printf("%d\n", cnt);
}


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

void dfs(int v, vector<vector<int>> &adj, vector<bool> &visited, stack<int> &s) {
	visited[v] = true;
	//cout << v << endl;
	for(auto x : adj[v]) {
		if(!visited[x]) dfs(x, adj, visited, s);
	}
	s.push(v);
}

void dfs1(int v, vector<vector<int>> &adj, vector<int> &comp, int t) {
	comp[v] = t;
	for(auto x : adj[v]) {
		if(comp[x] == -1) dfs1(x, adj, comp, t);
	}
}

int main() {
	int n, d;
	cin >> n >> d;
	vector<pair<int, int>> pt(n);
	for(int i = 0; i < n; i++) cin >> pt[i].first >> pt[i].second;
	vector<vector<int>> adj(2*n), adjt(2*n);
	for(int i = 0; i < n; i++) {
		//adj[2*i].first = pt[i].first;
		//adj[2*i+1].first = pt[i].second;
		for(int j = 0; j < n; j++) {
			if(i != j) {
				if(abs(pt[i].first - pt[j].first) < d) { // cannot take both simultaneously
					adj[2*i].push_back(2*j+1);
					adjt[2*j+1].push_back(2*i);
				}
				if(abs(pt[i].first - pt[j].second) < d) { // cannot take both simultaneously
					adj[2*i].push_back(2*j);
					adjt[2*j].push_back(2*i);
				}
				if(abs(pt[i].second - pt[j].first) < d) { // cannot take both simultaneously
					adj[2*i+1].push_back(2*j+1);
					adjt[2*j+1].push_back(2*i+1);
				}
				if(abs(pt[i].second - pt[j].second) < d) { // cannot take both simultaneously
					adj[2*i+1].push_back(2*j);
					adjt[2*j].push_back(2*i+1);
				}
			}
		}
	}
	stack<int> s;
	vector<bool> visited(2*n, false);
	vector<int> comp(2*n, -1); 
	for(int i = 0; i < 2*n; i++) {
		if(!visited[i]) dfs(i, adj, visited, s);
	}
	//visited.assign(2*n, false);
	int j = 0;
	while(!s.empty()) {
		int i = s.top();
		s.pop();
		if(comp[i] == -1) dfs1(i, adjt, comp, j++);
	}
	vector<int> ans(n);
	bool ispos = true;
	for(int i = 0; i < n; i++) {
		if(comp[2*i] == comp[2*i+1]) {
			ispos = false;
			break;
		}
		ans[i] = comp[2*i] < comp[2*i+1] ? pt[i].second : pt[i].first;
	}
	if(!ispos) cout << "No";
	else {
		cout << "Yes" << endl;
		for(auto x : ans) cout << x << endl;
	}
	return 0;
}


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

int main(){
  string s;
  cin >> s;
  int cnt = 0;
  for(int i=0;i<(s.size()+1)/2;i++){
    if(s.at(i) != s.at(s.size()-1-i)){
      cnt++;
    }
  }
  cout << cnt << endl;   
}


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

int main(){
  int step,flag=0,n,l,x;
  while(1){
    cin >> n;
    if(n==0){break;}
    string w[n];
    for(int i=0;i<n;i++){
      cin >> w[i];
    }
    for(int i=0;i<n;i++){
      l=0;
      step=1;
      flag=0;
      x=i;
      while(1){
        if(flag==1){break;}
        l+=w[x].length();
        switch(step){
          case 1:
          if(l>5){flag=1;}
          else if(l==5){step++;}
          break;
          case 2:
          if(l>12){flag=1;}
          else if(l==12){step++;}
          break;
          case 3:
          if(l>17){flag=1;}
          else if(l==17){step++;}
          break;
          case 4:
          if(l>24){flag=1;}
          else if(l==24){step++;}
          break;
          case 5:
          if(l>31){flag=1;}
          else if(l==31){flag=2;}
          break;
        }
        if(flag==2){break;}
        x++;
      }
      if(flag==2){x=i+1;break;}
    }
    if(flag==2){cout << x << endl;}
  }
  return 0;
}

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

#define F(i, a, b) for(int i=a; i<b; i++)
#define mem(arr, val) memset(arr, val, sizeof(arr))

#define MOD 1000000007
#define INF 1000000001
#define epsilon 1e-15

typedef long long int ll;
typedef unsigned long long int ull;

int main()
{

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

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int N, W;
    cin >> N >> W;
    int w[N], v[N];
    for(int i=0; i<N; i++)
        cin >> w[i] >> v[i];

    ll dp[N+1][W+1];
    for(int i=0; i<=W; i++)
        dp[0][i] = 0;
    for(int i=0; i<=N; i++)
        dp[i][0] = 0;

    for(int wt=1; wt<=W; wt++){
        for(int i=1; i<=N; i++){
            if(wt >= w[i-1]) dp[i][wt] = max(dp[i-1][wt], dp[i-1][wt-w[i-1]] + v[i-1]);
            else dp[i][wt] = dp[i-1][wt];
        }
    }

    ll ans =0;
    for(int wt=1; wt<=W; wt++)
        ans = max(ans, dp[N][wt]);
    cout << ans << '\n';

    return 0;
   
}

Measured memory_bytes: 82444
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define all(vec) vec.begin(), vec.end()

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int ans;
    ans = c/(7*a+b)*7; 
    if ((c%(7*a+b)+a-1)/a >= 7) ans += 7;
    else ans += (c%(7*a+b)+a-1)/a;
    printf("%d\n", ans);
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;
/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/

int main(){
  int N;cin >> N;
  vector<int> a(N);
  ll total = 0;
  rep(i,N){
    cin >> a[i];
  }
  for(int i=0;i<N;i++) total+=(a[i]-1);
  cout << total << endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <math.h>
using namespace std;

int main(void){
double r;
cin >> r;
double a = r*r*M_PI;
double b = 2*r*M_PI;
cout << fixed << setprecision(6) << a ;
cout << " ";
cout << fixed << setprecision(6) << b;
cout << endl;
}




Measured memory_bytes: 3220
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN (-2147483647 - 1)
#define INF 100000000
#define _INF -100000000
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;

int main() {
	string s;
	cin >> s;
	int p = 0;
	while (p < s.length()) {
		if (p + 7 <= s.length() && s.substr(p, 7) == "dreamer") {
			if (s.substr(p + 5, 5) == "erase") p += 5;
			else p += 7;
		}
		else if (p + 5 <= s.length() && s.substr(p, 5) == "dream") {
			p += 5;
		}
		else if (p + 6 <= s.length() && s.substr(p, 6) == "eraser") {
			p += 6;
		}
		else if (p + 5 <= s.length() && s.substr(p, 5) == "erase") {
			p += 5;
		}
		else break;
	}
	if (p >= s.length()) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	
	static int count = 1;

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		long h = Long.parseLong(scan.nextLine());
		
		test(h);
		System.out.println((long) Math.pow(2, count) - 1);
	}
	
	public static void test(long hp) {
		hp = hp / 2;
		if (hp == 0) return; 
		count++;
		test(hp);
	}
	
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N;
  cin>>N;
  string S;
  cin>>S;
  int ans=0;
  rep(i,0,N-1){
    bitset<26> A,B,C;
    REP(j,0,i)
      A.set(S[j]-'a');
    rep(j,i+1,N)
      B.set(S[j]-'a');
    C=A&B;
    ans=max(ans,(int)C.count());
    }
  cout<<ans;
  }


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

#define debug_input freopen("stdin.in", "r", stdin)
#define debug_output freopen("stdout.out", "w", stdout)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORALL(i, n) for(int i = 0; i < n; i++)
#define FORD(i, a, b) for(int i = a; i >= b; i--)
#define SORT(a) sort(a.begin(), a.end())
#define REV(a) reverse(a.begin(), a.end())
#define NP(a) next_permutation(a.begin(), a.end())
#define ALL(a) a.begin, a.end()
#define mp make_pair
#define pb push_back
#define endl "\n"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int n;
	int ans = 0;
	cin >> n;
	FOR(c, 1, n) {
		int temp = n - c;
		vector<pair<int,int> > v;
		
		int mult = 1;
		for(int i = 2; temp > 1 and i * i <= temp; i++) {
			int cnt = 0; 
			while(temp % i == 0) {
				temp /= i;
				cnt++;
			}

			if(cnt) {
				mult *= (cnt + 1);
			}
		}	
		if(temp != 1) mult *= 2;

		ans += mult;
	}

	cout << ans - 2 << endl;
	return 0;
}

Measured memory_bytes: 3632
from itertools import product

n = int(input())
res = 0
for pattern in product(["0", "3", "5", "7"], repeat=9):
    p = int("".join(pattern))
    if "0" not in str(p):
        for i in [3, 5, 7]:
            if str(i) not in str(p):
                break
        else:
            if p <= n:
                res += 1
            else:
                break
print(res)

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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)



typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
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;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            cout<<x<<"/"<<y<<endl;
            return;
        }
    }
    cout<<"nun"<<endl;
}
//////////////////////////


#define MAX_N (ll)2E7///変更！！！！！！！
vector<ll>prime;
bool is_prime[MAX_N+1];
void precal(){
    rep(i,0,MAX_N)is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    rep(i,2,MAX_N){
        if(is_prime[i]){
            prime.pb(i);
            for(ll j=2*i;j<=MAX_N;j+=i)is_prime[j]=false;
        }
    }
}
vector<l_l> fact(ll n){
    vector<l_l>v;
    for(ll p:prime){
        if(p*p>n)break;
        ll c=0;
        while(n%p==0){
            n/=p;
            c++;
        }
        if(c)v.pb(l_l(p,c));//pという素因数がc個入っている
    }
    if(n!=1){
        ll vsize=v.size();
        if(vsize>=1&&v[vsize-1].first==n)v[vsize-1].second++;
        else v.pb(l_l(n,1));
    }
    /*
    if(v.size()==0){
        v.pb(l_l(1,1));
    }*/
    return v;
}
/////////////////////////////////////////////////////

ll SOLVE(){
    precal();
    ll n;cin>>n;
    vector<l_l>v=fact(n);
    ll ans=0;
    for(auto x:v){
        rep(c,3,100000){
            if(x.se<c*(c-1)/2){
                ans+=c-2;
                break;
            }
        }
    }
    /*
    for(auto x:v){
        cout<<x.fi<<" "<<x.se<<endl;
    }*/
    cout<<ans<<endl;
    
    return 0;
}

int main(){fastio
    
    clock_t start = clock();
    SOLVE();
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    cerr<<endl<<time<<"ms"<<endl;
    
    return 0;
}



Measured memory_bytes: 39272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, d, a, k, s, t;
  in3(n, d, a);
  vector<pair<ll, ll>> c(n);
  rep(i, n)
    in2(c[i].first, c[i].second);
  c.pb(make_pair(9999999999999, 999999999999999));
  sort(all(c));
  d = d * 2;
  vector<ll> f(n), e(n + 1, 0);
  s = 0;
  t = 1;
  while(s < n){
    while(c[t].first <= c[s].first + d)
      t++;
    f[s] = t;
    s++;
  }
  s = 0; // damage
  k = 0;
  rep(i, n){
    s -= e[i];
    if(s >= c[i].second)
      continue;
    t = (c[i].second - s + a - 1) / a;
    s += t * a;
    e[f[i]] += t * a;
    k += t;
  }
  out(k);
  memi;
}


Measured memory_bytes: 8136
N = int(input())
A = list(map(int, input().split()))
B = []
now = 1
ans = 1

if A[0] == 2:
    print(-1)
    exit()
if A[0] == 1 and len(A) != 1:
    print(-1)
    exit()

for a in A[1:]:
    now *= 2
    now -= a
    ans += a
    if now < 0:
        print(-1)
        exit()
    B.append(now)

cnt = A[-1]
for a, b in zip(A[:-1][::-1], B[:-1][::-1]):
    if cnt <= b:
        ans += cnt
    else:
        cnt = b
        ans += cnt
    cnt += a
print(ans)

Measured memory_bytes: 704860
#include <iostream>
#include <limits.h>
#include <cstdio>
using namespace std;

int r[200010];

int main()
{
    int n;

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

        int Max = INT_MIN;
        int Min = r[0];
        for(int i=1; i<n; i++)
        {
            Max = max(Max, r[i] - Min);
            Min = min(Min, r[i]);

        }

        cout << Max << endl;
    }


    return 0;
}



Measured memory_bytes: 3868
#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>
#include <cmath>
#include <cstdio>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)

const double PI=4*atan(1.0);
typedef complex<double> P;

// àÏ
double dot(P a, P b) {
  return (a.real() * b.real() + a.imag() * b.imag());
}
// OÏ
double cross(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}
// a©çbÖ¶üèÅ½x©
double diffAngle(P a,P b){
  // cos>0&&sin>0 -> 0 -> 90
  // cos<0&&sin>0 -> 90->180
  // cos<0&&sin<0 -> 180->270
  // cos>0&&sin<0 -> 270 -> 359
  //double cosn=dot(a,b)/(abs(a)*abs(b));
  //double sinn=cross(a,b)/(abs(a)*abs(b));
  //double angle=acos(cosn);
  //if(sinn>=0)
  //    return angle;
  //return 2*PI-angle;
    double angle=atan2(cross(a,b),dot(a,b));
    return angle+PI;
}

int main(){
    int n;
    while(cin>>n&&n!=0){
        vector<P> points;
        for(int i = 0; i < n; i++){
            int x,y;
            cin>>x>>y;
            points.push_back(P(x,y));
        }
        vector<bool> isUsed(points.size(),false);
        double sum=0;
        P cp=P(0,1);
        P pp=P(0,0);
        int cnt=n;
        while(cnt--){
            int idx=-1;
            double minAngle=100000000;
            for(int i = 0; i < points.size(); i++){
                if(isUsed[i]) continue;
                double ca=diffAngle(points[i]-pp,cp);
                if(EQ(minAngle,ca)){
                    if(abs(points[idx]-pp)>abs(points[i]-pp))
                        idx=i;
                }
                else if(minAngle>ca){
                    idx=i;
                    minAngle=ca;
                }
            }
            isUsed[idx]=true;
            double inc=abs(points[idx]-pp);
            sum+=inc;
            P p=(points[idx]-pp);
            cp=p/abs(p);
            pp=points[idx];
        }
        printf("%.1f\n",sum);
    }
    return 0;
}

Measured memory_bytes: 0
#include<cstdio>
int main()
{
    int n,A,B,a,b;
    while(1)
    {
        A=0;
        B=0;
        scanf("%d",&n);
        if(n==0)break;
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&a,&b);
            if(a>b)A=A+a+b;
            else if(a<b)B=B+a+b;
            else
            {
                A+=a;
                B+=b;
            }
        }
        printf("%d %d\n",A,B);
    }
    return 0;
}

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

int main() {
  int a, b, x, y, h, w;
  cin >> a >> b >> x >> y;
  
  h = y-b; w = x-a;
  
  for(int i = 0; i < h; i++) {
  	cout << 'U';
  }
  
  for(int i = 0; i < w; i++) {
  	cout << 'R';
  }
  
  for(int i = 0; i < h; i++) {
  	cout << 'D';
  }
  
  for(int i = 0; i < w+1; i++) {
  	cout << 'L';
  }
  
  for(int i = 0; i < h+1; i++) {
  	cout << 'U';
  }
  
  for(int i = 0; i < w+1; i++) {
  	cout << 'R';
  }
  
  cout << 'D' << 'R';
  
  for(int i = 0; i < h+1; i++) {
  	cout << 'D';
  }
  
  for(int i = 0; i < w+1; i++) {
  	cout << 'L';
  }
  
  cout << 'U' << endl;
}

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

int main(){
    long n,a,b,c,d,e;
    cin>>n>>a>>b>>c>>d>>e;
    long bottleneck=1000000000000001;
    
    if(bottleneck>a) bottleneck=a;
    if(bottleneck>b) bottleneck=b;
    if(bottleneck>c) bottleneck=c;
    if(bottleneck>d) bottleneck=d;
    if(bottleneck>e) bottleneck=e;
    
    long ans;
    ans = n/bottleneck + 4;
    if(n%bottleneck!=0) ans++;
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int N, a, b;
    cin >> N;
    int A[N];
    int B[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
        B[i] = A[i];
    }
    sort(A, A+N);
    a = A[N-1];
    b = A[N-2];
    for(int i = 0; i < N; i++){
       if(B[i] == a){
           cout << b << endl;
       }else{
           cout << a << endl;
       }
    }
    
}


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

using ll = long long;

int main() {
  ll H, W;
  cin >> H >> W;
  if (H == 1 || W == 1) {
    cout << 1 << endl;
    return 0;
  }

  ll ans = ((H - (H % 2)) * W) / 2;
  if (H % 2 == 1) {
    ans += W / 2;
    if (W % 2 == 1) {
      ans += 1;
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// ABCテンプレート

#define rep(i,n) for (int i = 0; i<(n); i++)
#define in(n) cin >> (n)
#define out(ans) cout << (ans) << endl;
#define keta(n) cout << fixed << setprecision((n));
using ll = int64_t;
using v = vector<int>;

int main() {
  int N;
  cin >> N;
  int d1, d2;
  int jud=0;
  for(int i=0; i<N; i++){
    cin >> d1 >> d2;
    if(d1==d2){
      jud++;
    }
    else{
      jud=0;
    }
    if(jud==3){
      break;
    }
  }
  if(jud==3) {
    cout << "Yes";
  }
  else {
    cout << "No";
  }
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
  int mn,cnt;
  string s,t;
  
  cin >> s >> t;
  
  mn = t.length();
  
  for(int i = 0;i < s.length() - t.length() + 1;i++){
    cnt = 0;
    for(int j = 0;j < t.length();j++){
      if(s.at(i + j) != t.at(j))
        cnt++;
    }
    mn = min(mn,cnt);
  }
  
  cout << mn << endl;
}

Measured memory_bytes: 3624
#include<cstdio>

int par[100500];

int find(int x) {
    if(par[x] == x) return x;
    return par[x] = find(par[x]);
}

void unite(int x,int y) {
    x = find(x);
    y = find(y);
    par[x] = y;
}

void init() {
    for(int i=0; i<100500; i++)
        par[i] = i;
}

int main(void) {
    int n,m,q;
    scanf("%d%d",&n,&m);
    init();
    for(int i=0; i<m; i++) {
        int s,t;
        scanf("%d%d",&s,&t);
        unite(s,t);
    }
    scanf("%d",&q);
    for(int i=0; i<q; i++) {
        int s,t;
        scanf("%d%d",&s,&t);
        puts(find(s) == find(t) ? "yes" : "no");
    }
    return 0;
}

Measured memory_bytes: 3556
N = int(input())
A = []
B = []
C = []#最長辺
for i in range(N):
    a, b, c = map(int, input().split())
    if(a > b):#a,bを昇順に並び替える
        t = a
        a = b
        b = t
    if(b > c):#b,cを昇順に並び替える
        t = b
        b = c
        c = t
    A.append(a)
    B.append(b)
    C.append(c)
for i in range(N):
    if(A[i]**2 + B[i]**2 == C[i]**2):
        print("YES")
    else:
        print("NO")



Measured memory_bytes: 5712
n=int(input())
a=list(map(int,input().split()))
cnt2,cnt4=0,0
for i in range(n):
  if a[i]%4==0:
    cnt4+=1
  elif a[i]%2==0:
    cnt2+=1
if cnt4*2+cnt2>=n or cnt4*2+1>=n:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 84860
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    ll x, k, d;
    cin >> x >> k >> d;
    
    ll dir = x / abs(x);
    ll target1 = x - abs(x) / d * d * dir;
    ll target2 = x - (1 + abs(x) / d) * d * dir;
    ll target = abs(target1) <= abs(target2) ? target1 : target2;
    
    ll kr = abs(target - x) / d;
    if (k <= kr) {
        put(abs(x - dir * k * d));
    }
    else if ((kr - k) % 2 == 0) {
        put(abs(target));        
    }
    else {
        put(min(abs(target+d), abs(target-d)));        
    }

    return 0;
}

Measured memory_bytes: 3608
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#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 repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#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 n;
       cin>>n;
       ll a[28],b[28],c[28];
       for(int i=1;i<=n;i++)
           cin>>a[i];
       for(int i=1;i<=n;i++)
       {
             cin>>b[i];
       }
       a[0]=500;
       for(int i=1;i<=n-1;i++)
           cin>>c[i];
       ll ans=0;
       for(int i=1;i<=n;i++)
       {
           ans+=b[a[i]];
           if(a[i]==a[i-1]+1)
               ans+=c[a[i-1]];
       }
       cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
ll modinv(ll a, ll m){
  ll b=m,u=1,v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  u%=m;
  if(u<0) u+=m;
  return u;
}
signed main(){
  init_io();
  ll n,p,tmp=0,ans=0,keta=1;
  map<ll,ll> mp;
  string s;
  cin >> n >> p >> s;
  if(p==2||p==5){
    for(int i=n-1;i>=0;i--){
      if((s[i]-'0')%p == 0){
        ans += i+1;
      }
    }
  }else{
    mp[0]++;
    for(int i=n-1;i>=0;i--){
      tmp += keta * (s[i]-'0');
      tmp %= p;
      ans += mp[tmp];
      mp[tmp]++;
      keta *= 10;
      keta %= p;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1044
#include <iostream>
#include <algorithm>
int main() {
	int N, a[100];
	std::cin >> N;
	for (int i = 0; i < N; i++)
		std::cin >> a[i];
	std::sort(a, a + N);
	std::cout << a[N - 1] - a[0] << std::endl;
}

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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;

lli dp[11][11]; // k 個分用意しなくても上書きしてけば良いので、dp[i][j]のみ用意
#define INF (LLONG_MAX / 3);

int main() {
    lli h, w;
    cin2(h, w);
    REP(i, 0, 10) {
        REP(j, 0, 10) {
            lli c;
            cin >> c;
            dp[i][j] = c;
        }
    }
    // 初期化
    REPE(i, 0, 9) {
        REPE(j, 0, 9) {
            if (dp[i][j])
                continue;
            if (i == j)
                continue;
            dp[i][j] = INF;
        }
    }
    REPE(k, 0, 9) {
        REPE(i, 0, 9) {
            REPE(j, 0, 9) {
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]);
            }
        }
    }

    lli ans = 0;
    lli a[h][w];
    REP(i, 0, h) {
        REP(j, 0, w) {
            cin >> a[i][j];
            if (a[i][j] == -1)
                continue;
            ans +=  dp[a[i][j]][1];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {
	
	int num;
	int l;
	vector<int> val;
	int ans;
	
	scanf("%d", &num);
	for(int i=0; i<num; i++){
		scanf("%d", &l);
		val.push_back(l);
	}
	
	sort(val.begin(), val.end());
	reverse(val.begin(), val.end());
	
	int left, right;
	
	left = val[0];
	right = accumulate(val.begin()+1, val.end(), 0);
	
	printf("%s\n", (left < right) ? "Yes" : "No");
	
	return 0;
	
}


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

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

    int n, m;
    cin >> n >> m;

    vector<set<int>> adj(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        adj[a].insert(b);
        adj[b].insert(a);
    }
    for (int i = 1; i < n - 1; i++) {
        if (adj[i].count(0) && adj[i].count(n - 1)) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 28416
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
using namespace std;
#define ll long long
#define vel vector<ll>
#define vvel vector<vel>
#define vvvel vector<vvel>
#define veb vector<bool>
#define pin pair<int,int>
#define mkp make_pair
#define mot pair<D,D>//time,dist
#define root pair<int,mot>
#define path pair<ll,int>//cost,to
#define int long long
using namespace std;
vvel ta_min(0);
vvel ta_max(0);
int leth = 1024 * 512;
int siz = leth * 2;
int p = 1000000007;
void mmax(ll &a, ll b) { a = max(a, b); }
void mmin(ll &a, ll b) { a = min(a, b); }
vel dij(int s, vector<vector<path>> &way) {
	int n = way.size();
	int x = 1000 * 1000 * 1000;
	int INF = n * x + 1;
	vel tim(n, INF); tim[s] = 0;
	priority_queue<path> q;
	q.push(mkp(-0,s));
	veb seen(n,false);
	while (!q.empty()) {
		path tp = q.top(); q.pop();
		tp.first *= -1;
		int num = tp.second;
		if (!seen[num]) {
			tim[num] = tp.first;
			seen[num] = true;
			for (int i = 0; i < way[num].size(); i++) {
				path nex = way[num][i];
				path add = mkp(nex.first + tp.first, nex.second);
				add.first *= -1;
				q.push(add);
			}
		}
	}
	return tim;
}
void ref(int &x) { x = x % p; x = (x + p) % p; }
signed main() {
	int n; cin >> n;
	vvel a(2, vel(n));
	for (int i = 0; i < 2; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; } }
	int ans = a[0][0];
	for (int i = 0; i < n; i++) { ans += a[1][i]; }
	int qans = ans;
	for (int i = 1; i < n; i++) {
		qans += a[0][i] - a[1][i - 1];
		mmax(ans, qans);
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main() {
    
    
    int n, k;
    cin >> n >> k;
    
    cout << n - k + 1 << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int w = scan.nextInt();
        int data = 1;
        while (w != 0) {
            int n = scan.nextInt();
            int[] value = new int[n];
            int[] weight = new int[n];
            for (int i = 0; i < n; i++) {
                String[] str = scan.next().split(",");
                value[i] = Integer.parseInt(str[0]);
                weight[i] = Integer.parseInt(str[1]);;
            }
            int[] dp = new int[w+1];
            for (int i = 0; i < n; i++) {
                for (int j = w; j >= 0; j--) {
                    if ((dp[j] != 0 && (j + weight[i]) <= w)
                            || (j == 0)) {
                        dp[j + weight[i]] = 
                            max(dp[j + weight[i]], dp[j] + value[i]);
                            }
                }
            }
            int max = 0;
            for (int i = 0; i <= w; i++) {
                if (dp[i] > dp[max]) {
                    max = i;
                }
            }
            System.out.println("Case " + data + ":");
            System.out.println(dp[max]);
            System.out.println(max);
            data++;
            w = scan.nextInt();
        }
    }

    public static int max(int a, int b) {
        if (a < b) {
            return b;
        } else {
            return a;
        }
    }
}

Measured memory_bytes: 33948
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);
const std::string yes = "Yes";
const std::string no  = "No";

int main(){
    int n;
    std::cin >> n;

    ll s = 0;
    std::vector<ll> a(n);
    rep(i,n){
        std::cin >> a[i];
        s += a[i];
    }

    ll ans = s, cnt = 0;
    rep(i,n){
        cnt += a[i];
        ans = std::min<ll>(ans, llabs(cnt - (s - cnt)));
    }

    std::cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4844
import std.functional,
       std.algorithm,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv,
       std.math;

void main() {
  int N = readln.chomp.to!int;
  int[] a = readln.chomp.split.to!(int[]);
  int t = round((a.sum / a.length.to!double)).to!int;
  int ans;

  foreach (e; a) {
    ans += (e - t)^^2;
  }

  writeln(ans);
}

Measured memory_bytes: 508