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

#define N 100000

int main(void){
    vector<bool> prime(N+1,true);
    prime[0]=prime[1]=false;
    for (size_t i = 0; i <= sqrt(N); i++)
    {
        if (prime[i])
        {
            for (size_t j = 2; i*j <= N; j++)
            {
                prime[i*j]=false;
            }
        }
    }
    vector<int> likeCnt(N);
    for (size_t i = 1; i <= N; i++)
    {
        likeCnt[i]=likeCnt[i-1];
        if (i%2==1&&prime[i]&&prime[(i+1)/2])
        {
            likeCnt[i]++;
        }
    }
    /**************************************/
    int q;
    cin >> q;
    int l[q],r[q];
    for (size_t i = 0; i < q; i++)
    {
        cin >>l[i]>>r[i];
    }
    for (size_t i = 0; i < q; i++)
    {
        cout << likeCnt[r[i]]-likeCnt[l[i]-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>

int main(){
	//入力機構
	int N;//intは10^9を表せるのでこれを保存
	std::cin>>N;

	//処理機構
	int sn=0;//総和
	int a=N;//Aには商を格納
	for(;a>0;a=a/10){
		sn+=(a%10);
	}

	//出力機構
	std::cout<<(N%sn==0?"Yes":"No")<<std::endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<=(end);i++)
#define REP(i, n) FOR(i,1,n)
#define IFOR(i, begin, end) for(int i=(end);i>=(begin);i--)
#define IREP(i, n) IFOR(i,1,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())

#define ll long long
using namespace std;

bool is_prime(int k)
{
    for(int j=2;j*j<=k;j++){
        if(k%j==0) {
            return false;
        }
    }
    return true;
}

int main()
{
	stringstream ss;
    // 入力
    int N;
    cin>>N;
    if(N==1) cout<<"Hello World"<<endl;
    else if(N==2){
    	int A,B;
    	cin>>A>>B;
    	cout<<A+B<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
const lli mod=1e9+7;
const lli pINF=100000000000000000;
const lli nINF=-LLONG_MAX;
void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);}
lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;}b/=2;a*=a;} return ans;}
lli invmod(lli a) {return pow(a,mod-2);}
#define vi vector<int>
#define vlli vector<lli>
#define pb push_back
#define mp make_pair
#define F first
const int INF = 0x3f3f3f3f ;
#define PII pair<int,int>
#define S second
#define si(n) scanf("%d",&n)
#define sli(n) scanf("%lld",&n)
#define printi(n) printf("%d\n",n)
#define printli(n) printf("%lld\n",n)
#define all(v) v.begin(),v.end()
#define forn(i,n) for(int i=0;i<n;i++)
void print(int a[],int n){for(int i=0;i<n;i++) cout<<a[i]<<" ";}
#define MAX 100005
vi adj[MAX];
bool vis[MAX];
int a[MAX];
int comp[MAX];
int cc;

void dfs(int node)
{
    if(vis[node]) return;
    vis[node]=true;
    comp[node]=cc;
    
    for(int i:adj[node]){
        if(!vis[i]){
            dfs(i);
        }
    }
}

int main() 
{
    int n,m,x,y;
    si(n);si(m);
    
    for(int i=1;i<=n;i++) si(a[i]);
    
    for(int i=0;i<m;i++){
        si(x);si(y);
        adj[x].pb(y);
        adj[y].pb(x);
    }
    cc=0;
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            cc++;
            dfs(i);
        }
    }
    
    int ans=0;
    for(int i=1;i<=n;i++){
        if(a[i]==i) ans++;
        else{
            if(comp[i]==comp[a[i]]) ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

const ll INF = 1e9;

struct edge {
	int to;
	int cost;
	edge(int t, int c) : to(t), cost(c) {}
};

struct dijk {
	int v, t;
	ll dist;
	dijk(int v, int t, ll d) : v(v), t(t), dist(d) {}
	bool operator>(const dijk& that) const {
		return dist > that.dist;
	}
};

int main()
{
	int N, M, X;
	cin >> N >> M >> X;
	vector<int> T(N);
	for (int i = 0; i < N; i++) {
		cin >> T[i];
	}
	vector<vector<edge>> G(N);
	for (int i = 0; i < M; i++) {
		int a, b, d;
		cin >> a >> b >> d; a--, b--;
		G[a].emplace_back(b, d);
		G[b].emplace_back(a, d);
	}
	vector<vector<ll>> d(N, vector<ll>(X * 2 + 1, INF));
	priority_queue<dijk, vector<dijk>, greater<>> pq;
	pq.emplace(0, 0, 0);
	while (!pq.empty()) {
		auto p = pq.top(); pq.pop();
		if (d[p.v][p.t] != INF) continue;
		d[p.v][p.t] = p.dist;
		for (auto e : G[p.v]) {
			int tt = p.t < X ? min(X, p.t + e.cost) : p.t > X ? max(X, p.t - e.cost) : X;
			if (T[e.to] == 0) {
				if (tt > X) continue;
				tt = 0;
			}
			else if (T[e.to] == 2) {
				if(tt < X) continue;
				tt = X * 2;
			}
			if (d[e.to][tt] == INF) {
				pq.emplace(e.to, tt, p.dist + e.cost);
			}
		}
	}
	cout << *min_element(d[N - 1].begin(), d[N - 1].end()) << endl;
	return 0;
}



Measured memory_bytes: 35588
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int pc[n+1];
    for(int i=0;i<=n;i++){
        int one=0;
        for(int j=i;j>0;j/=2)if(j%2)one++;
        pc[i]=one;
    }
    string x;
    cin>>x;
    int k=0;//1の個数
    for(int i=0;i<n;i++){
        x[i]-='0';
        if(x[i])k++;
    }
    if(k==1){
        if(x[n-1]==1){
            for(int i=0;i<n-1;i++)cout<<"2"<<endl;
            cout<<"0"<<endl;
        }
        else{
            for(int i=0;i<n-1;i++){
                if(x[i]==1)cout<<"0"<<endl;
                else cout<<"1"<<endl;
            }
            cout<<"2"<<endl;
        }
        return 0;
    }
    long long m0=0,m1=0,p0[n+1],p1[n+1];
    p0[n]=1,p1[n]=1;
    for(int i=n-1;i>=0;i--){
        m1+=x[i]*p1[i+1];
        m0+=x[i]*p0[i+1];
        m1%=(k+1);
        m0%=(k-1);
        p1[i]=(p1[i+1]*2)%(k+1);
        p0[i]=(p0[i+1]*2)%(k-1);
    }
    for(int i=0;i<n;i++){
        int I,f=1;
        if(x[i]==0)I=(m1+p1[i+1])%(k+1);
        else I=(m0-p0[i+1]+k-1)%(k-1);
        while(I){
            I%=pc[I];
            f++;
        }
        cout<<f<<endl;
    }
    return 0;
}

Measured memory_bytes: 7660
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main(){
  long long a;
  double b;
  cin >> a >> b;
  if(a==0 || b==0){
    cout << 0 << endl;
    return 0;
  }
  long long num=b*100+0.000001;
  long long ans=num*a;
  ans/=100;
  cout << ans << endl;
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
    #include <chrono>
  
    using namespace std;
    using namespace std::chrono; 
 
    typedef long long int ll;
 
    #define MOD (ll)(1e9+7)
    #define endl "\n"
    #define pb push_back
    #define TEST_CASES  ll t;cin>>t;while(t--)
    #define forn(i,a,n) for (int i = a; i < n; ++i)
    #define f first
    #define s second
    #define all(x) x.begin(), x.end()
    
    ll powD(ll x,ll y){
      ll res = 1;
      while(y > 0){
        if(y & 1)
          res = (res*x)%MOD;
        x = (x*x)%MOD;
        y = y>>1;
      }
      return res;
    }
    
    ll MAX = 1e18;
    int main()
    {
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      ll n;
      cin>>n;
      ll ans = 1;
      bool flag = 1;
      vector<ll> a(n);
      forn(i,0,n){
        cin>>a[i];
        if(a[i] == 0){
          flag = 0;
        }
      }
      if(!flag){
        cout<<0<<endl;
        return 0;
      }
      forn(i,0,n){
        if(a[i] > MAX/ans){
          cout<<-1<<endl;
          return 0;
        }
        ans = ans*a[i];
      }
      cout<<ans<<endl;

    }


Measured memory_bytes: 3976
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string input = Console.ReadLine();
                string[] change = input.Split(' ');
                int h = int.Parse(change[0]);
                int w = int.Parse(change[1]);

                if (h == 0 && w == 0)//????????????0?????£????????????
                    break;

                for (int i = 1; i <= h; i++)//????????????????????°?????§
                {
                    for (int j = 1; j <= w; j++)//?????????????¨??????°?????§
                    {
                        if ((j == 1 || j == w) || (i == 1 || i == h))//#??????????????????????????¶
                        {
                            Console.Write("#");
                        }
                        else//????????\???????????????????????????
                        {
                            Console.Write(".");
                        }
                        
                    }
                    Console.WriteLine();//?????´???for??§1??????????????????????????§???????????\??????
                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 8740
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
using namespace std;

int N, K;
vector<long> a;
bitset<5005> dp;

// when a <= b and b is unnecessary, a is also unnecessary.
bool C(long i) {
    dp >>= 5005;
    dp[0] = true;

    for(int j = 0; j < N; ++j) {
        if(i == j) continue;
        for(int k = K; k >= a[j]; --k) {
            dp[k] = dp[k] | dp[k - a[j]];
        }
    }

    bool need = false;
    for(int k = K - a[i]; k < K; ++k) need |= dp[k];
    return need;
}

int main(){
    cin.tie(0); ios_base::sync_with_stdio(false);
    cin >> N >> K;
    long tmp;
    for(int i=0; i < N; ++i) {
        cin >> tmp;
        if(tmp < K) a.push_back(tmp);
    }
    sort(a.begin(), a.end());
    N = (int)a.size();

    // binary search
    int ng = -1, ok = N;
    while(abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if(C(mid)) ok = mid;
        else ng = mid;
    }

    cout << ok << '\n';
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

#define MOD_N 1000000007
#define MAX_N 200001

int main(void){
    int N,K;
    long int sum[MAX_N+1],ans=0,min,max,i;

    scanf("%d %d",&N,&K);
    sum[0];
    for(i = 1;i <= N;i++){
        sum[i] = i;
        sum[i] += sum[i-1];
    }

    for(i = K;i <= N+1;i++){
        min = sum[i-1];
        if(i == N+1) max = sum[N];
        else max = sum[N] - sum[N-i];
        ans += max - min + 1;
    }

    printf("%ld\n",ans % MOD_N);
    return 0;
}

Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  string s;cin >> s;
  bool sat = true;
  if(N%2==1)sat = false;
  rep(i,N/2){
    if(s[i] != s[i+N/2]) sat = false;
  }
  YesNo(sat);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;


int main()
{
    for (int i = 1; i < 10; i++)
    {
        for (int j = 1; j < 10; j++)
        {
            cout << i << "x" << j << "=" << i * j << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3072
#include <stdio.h>
int main(void)
{
	int i,a, x, y, z;
	scanf("%d %d",&x, &y);
	if(y<x)
	{
		z = x % y;
		for(i=1;i<z;i++)
		{
			if(z%i==0 && y%i==0)
			{
				a=i;
			}
		}
	}
	else if(x<y)
	{
		z = y % x;
		for(i=1;i<z;i++)
		{
			if(z%i==0 && x%i==0)
			{
				a=i;
			}
		}
	}

	else
	{
		a=x;
	}
	printf("%d\n",a);
}


Measured memory_bytes: 2036
n, m = map(int, input().split())
if n >= m:
    print(0)
else:
    li = list(map(int, input().split()))
    li = sorted(li)
    lidelta = []
    a = li[m-1] - li[0]
    for i in range(m-1):
        lidelta.append(li[i+1] - li[i])

    lidelta = list(reversed(sorted(lidelta)))

    for i in range(n-1):
        a -= lidelta[i]
    
    print(a)

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

def divisors(a):
	divisors=[]
	for i in range(1,int(a**0.5)+1):
		if a%i==0:
			divisors.append(i)
			if i!=a//i:
				divisors.append(a//i)
	divisors.sort() # 昇順
	# divisors.sort(reverse=True) # 降順
	return divisors

d=divisors(N)
l=len(d)
if l%2==0:
  a=d[int(l/2)]+d[int(l/2-1)]
else:
  a=d[int((l-1)/2)]*2
print(a-2)

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;
using P = pair<int,int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main(){
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}

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

int main(){
    int n,x; cin >> n >> x;
    int l[n];
    int d[n];

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

    int count = 0;

    for (int j=0;j<n+1;j++){
        if (j==0) {
            count++;
            d[j] = 0;
            continue;
        }

        d[j] = d[j-1] + l[j-1];

        if (x >= d[j]) {
            count++;
        }
    }

    cout << count << endl;
    return 0;
}

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

int main(){
  int n,d,x;
  cin >> n >> d >> x;
  int a[n];
  rep(i,n)cin >> a[i];
  int ans=x;
  for(int i=1;i<=d;i++){
    rep(j,n){
      if((i-1)%a[j]==0)ans++;
    }
  }
  cout << ans << endl;
return 0;}

Measured memory_bytes: 256
n = int(input())
s, t = input(), input()

ans = 1<<30
for i in range(len(s)+1) :
  st = s[0 : i] + t
  if len(st) >= n and st[ : n] == s and st[-n : ] == t :
    ans = min(ans, len(st))
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
#define INFTY 1000000
#define N 100

int matrixChainOrder(int *);

int n;

int main()
{
  int i,r,c,ret,p[N+1];

  scanf("%d",&n);

  for(i = 1; i <= n; i++){
    scanf("%d %d",&p[i-1],&p[i]);
  }
  
  ret = matrixChainOrder(p);
  printf("%d\n",ret);

  return 0;
}

int matrixChainOrder(int p[])
{
  int i,j,k,l,m[N+1][N+1],q;

  for(i = 1; i <= n; i++){
    m[i][i] = 0;
  }

  for(l = 2; l <= n; l++){
    for(i = 1; i <= n-l+1; i++){
      j = i+l-1;
      m[i][j] = INFTY;
      for(k = i; k < j; k++){
	q = m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j];
	if(q < m[i][j])m[i][j] = q;
      }
    }
  }
  return m[i-1][j];
}



Measured memory_bytes: 2108
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const LL mod = 1000000007ll;

LL N,R;
LL A[100000];

LL ans = 0;

void solve(){
	if(N>=10){
		ans = R;
	}
	else{
		ans = R + 100*(10-N);
	}
}
 
int main(){
	cin >> N >> R;
 
	solve();

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

Measured memory_bytes: 256
import numpy as np

def main():
    N = int(input())
    a = np.array([int(_) for _ in input().split(" ")])

    Alice = np.array([])
    Bob = np.array([])

    turn = 1
    while len(a) != 0:
        if int(turn%2) != 0:
            Alice = np.append(a.max(), Alice)
        else:
            Bob = np.append(a.max(), Bob)

        a = np.delete(a, a.argmax())
        turn += 1

    print(int(Alice.sum() - Bob.sum()))

main()

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

public class Main {
	static final FastIn in = new FastIn();
	static final PrintWriter out = new PrintWriter(System.out);
	public static void main(String[] $) {
		int N = in.nextInt(), M = in.nextInt();
		List<Integer>[] adj = new List[N];
		for (int i = 0; i < N; ++i) adj[i] = new ArrayList<Integer>();
		for (int i = 0; i < M; ++i) {
			int a = in.nextInt() - 1, b = in.nextInt() - 1;
			adj[a].add(b);
			adj[b].add(a);
		}
		ArrayList<Integer> individuals = new ArrayList<>();
		boolean[] visited = new boolean[N];
		for (int i = 0; i < N; ++i) {
			if (visited[i]) continue;
			ArrayList<Integer> component = new ArrayList<>();
			Stack<Integer> stack = new Stack<>();
			stack.add(i);
			while (!stack.empty()) {
				int top = stack.pop();
				if (visited[top]) continue;
				visited[top] = true;
				component.add(top);
				for (int child : adj[top]) {
					if (visited[child]) continue;
					stack.push(child);
				}
			}
			individuals.add(component.size());
		}
		int ans = individuals.stream().mapToInt(a -> a).max().orElse(0);
		out.println(ans);
		out.close();
	}
	
	private static class FastIn {
		private BufferedReader br;
		private StringTokenizer st;
		public FastIn() {
			st = null;
			br = new BufferedReader(new InputStreamReader(System.in), 1 << 20);
		}
		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}

Measured memory_bytes: 86388
s = input()
a,b = int(s[:2]), int(s[2:])
if 0 < a <= 12 and 0 < b <= 12:
  print('AMBIGUOUS')
elif (a == 0 or a >= 12) and 0 < b <= 12:
  print('YYMM')
elif 0 < a <= 12 and (b == 0 or b >= 12):
  print('MMYY')
else:
  print('NA')

Measured memory_bytes: 3064
import sys

input = sys.stdin.readline

def main():
    ans = 0
    N = int(input())
    a = list(map(int, input().split()))
    for i in range(N):
        if a[i]%2 == 0:
            while a[i]%2 == 0:
                a[i] = a[i]//2
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 4212
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := NewScanner(os.Stdin)
	S := sc.Next()
	ans := 0
	cnt := 0
	for _, a := range S {
		if strings.ContainsRune("ACGT", a) {
			cnt++
		} else {
			ans = max(ans, cnt)
			cnt = 0
		}
	}
	ans = max(ans, cnt)
	fmt.Println(ans)
}

func lcm(x, y int) int {
	x, y = max(x, y), min(x, y)
	if y == 0 {
		return x
	}
	return lcm(y, x%y)
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

// scanner
type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner(r io.Reader) *Scanner {
	rdr := bufio.NewReaderSize(r, 1024)
	return &Scanner{r: rdr}
}

func (s *Scanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		line, isp, err := s.r.ReadLine()
		if err != nil {
			os.Exit(1)
		}
		s.buf = append(s.buf, line...)
		if !isp {
			break
		}
	}
}

func (s *Scanner) NextInt() int {
	i, err := strconv.Atoi(s.Next())
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextFloat64() float64 {
	i, err := strconv.ParseFloat(s.Next(), 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	next := string(s.buf[start:s.p])
	s.p++
	return next
}

func (s *Scanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}


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

int main() {
int	A, B;
cin >> A >> B;
cout << A * B << endl;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-10;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/
const ll mod = 1ll << 32;
int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		ll a[9];
		REP(i, 9) cin >> hex >> a[i];
		ll k = 0;
		REP(i, 32)
		{
			ll t = k;
			ll sum = 0;
			REP(j, 8)
			{
				sum += t^a[j];
			}
			bool f = false;
			ll b = a[8] ^ t;
			REP(j, i+1)
			{
				int x = (b >> j) & 1, y = (sum >> j) & 1;
				if (x != y) f = true;
			}
			if (f) k |= (1ll << i);
		}
		k %= mod;
		cout << hex << k << endl;
	}
	return 0;
}

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

const int INF = 1001001001;
const int NV=100100;

int main() {
  int N, ans=0;
  char x='*',a='*',b='*',c='*';
  cin>>N;
  for(int i=0; i<N; i++){
    cin>>x;
    a=b; b=c; c=x;
    if(a=='A'&&b=='B'&&c=='C'){
      ans+=1;
    }
  }
  cout<<ans<<endl;
}

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

string f(string s, string t)
{

    int n=s.size(),m=t.size();
    int** dp=new int *[n+5];
    for(int i=0;i<n+5;i++)
    dp[i]=new int[m+5];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        {
            if(i==0||j==0)dp[i][j]=0;
            else if(s[i-1]==t[j-1])
            dp[i][j]=dp[i-1][j-1]+1;
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
   
    int i=n,j=m;
    string ans="";
    while(i>0 && j>0)
    {
        if(s[i-1]==t[j-1])
        {
        ans=string(1,s[i-1])+ans;
        i--;
        j--;
        }
        else if(dp[i-1][j]>dp[i][j-1])
        i--;
        else j--;
        
    }
    return ans;
}



int main()
{
    string s,t;
    cin>>s>>t;
    cout<<f(s,t);
}

Measured memory_bytes: 35584
#include <stdio.h>
int main(){
  char s[10];
  scanf("%s",s);
  //printf("%s\n",s);
  if(s[0]=='Y' &&
     s[1]=='A' &&
     s[2]=='K' &&
     s[3]=='I' ){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

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

#define H 4100

int main(void){
	int n;
	int E[H];
	int flag[H];
	int e,p,q;
	int count=0;

	while(scanf("%d",&n)){
		if(n==0){break;}
		count=0;
		for(int i=0;i<H;i++){
			E[i]=0;
			flag[i]=0;
		}
		for(int i=0;i<n;i++){
			scanf("%d %d %d",&e,&p,&q);
			E[e]+=(p*q);
			if(E[e]>=1000000){
				if(flag[e]==0){
					printf("%d\n",e);
					flag[e]=0;
					count++;
				}
			}
		}

		if(count==0){
			printf("NA\n");
		}
	}


	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

struct UnionFind {
  // 子は親のID,親は-サイズ
  vector<int> d;
  UnionFind(int n) : d(n, -1) {}
  int root(int x) {
    if (d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int size(int x) { return -d[root(x)]; }
};

int main() {
  ll n, ans = INF;
  cin >> n;
  if (n == 1) {
    puts("1");
    return 0;
  }
  vector<ll> x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i == j) continue;
      int p = x[i] - x[j];
      int q = y[i] - y[j];
      ll cnt = 0;
      UnionFind uf(n);
      for (int k = 0; k < n; ++k) {
        for (int l = 0; l < n; ++l) {
          if (k == l) continue;
          if (x[l] == x[k] + p && y[l] == y[k] + q) uf.unite(k, l);
        }
      }
      unordered_set<ll> st;
      rep(k, n) st.insert(uf.root(k));
      ans = min(ans, (ll)st.size());
    }
  }

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


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int MAXN = 100 + 4;
const int INF = 1000000;
int M[MAXN][MAXN];
int d[MAXN];

int main()
{
    int N, u, k, m;
    memset ( M, 0, sizeof(M) );
    d[1] = 0;
    cin>>N;
    for ( int i = 0; i < N; i++ ) {
        cin>>u>>k;
        for ( int j = 0; j < k; j++ ){
            cin>>m;
            M[u][m] = 1;
        }
    }


    queue<int> q;
    q.push(1);
    for ( int i = 0; i <= N; i++ ) d[i] = INF;
    d[1] = 0;
    while ( !q.empty() ) {
        int u = q.front(); q.pop();
        for ( int v = 1; v <= N; v++ ) {
            if ( M[u][v] == 0 ) continue;
            if ( d[v] != INF ) continue;
            d[v] = d[u] + 1;
            q.push(v);
        }
    }

    for ( int i = 1; i <= N; i++ ) {
        cout<<i<<' '<<( d[i] == INF ? -1:d[i] )<<endl;
    }
    return 0;
}



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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define inv(n, a) for(int i = 0; i < n; i++) cin >> a[i]
#define MOD 1000000007
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
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; }
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25

int main() {
    int n; cin >> n;
    vector<int> v(n); inv(n, v);
    vector<int> odd, even;
    for(int i = 0; i < n; i++){
        if(i % 2 != 0) even.emplace_back(v[i]);
        else odd.emplace_back(v[i]);
    }
    sort(even.begin(), even.end());
    sort(odd.begin(), odd.end());
    int prev = -1;
    int cnt = 0;
    vector<pair<int, int>> O, E;
    rep(i, n/2){
        if(prev != odd[i]) {
            O.emplace_back(make_pair(prev, cnt));
            cnt = 0;
        }
        prev = odd[i];
        cnt++;
    }
    O.emplace_back(make_pair(prev, cnt));
    prev = -1;
    cnt = 0;
    rep(i, n/2){
        if(prev != even[i]) {
            E.emplace_back(make_pair(prev, cnt));
            cnt = 0;
        }
        prev = even[i];
        cnt++;
    }
    E.emplace_back(make_pair(prev, cnt));
    sort(O.begin(), O.end(), [](auto const& a, auto const& b){return a.second > b.second;});
    sort(E.begin(), E.end(), [](auto const& a, auto const& b){return a.second > b.second;});
    if(O[0].first == E[0].first){
        int ans;
        if(O.size() != 1 && E.size() != 1){
            ans = min(n - (O[0].second + E[1].second), n - (O[1].second + E[0].second));
        }else if(O.size() == 1 && E.size() == 1){
            ans = O[0].second;
        }else if(O.size() == 1){
            ans = n - (O[0].second - E[1].second);
        }else if(E.size() == 1){
            ans = n - (O[1].second - E[0].second);
        }
        cout << ans << endl;
        return 0;
    }else {
        int ans = n - (O[0].second + E[0].second);
        cout << ans << endl;
        return 0;
    }
}


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

using namespace std;

using ll = long long;

//部分点解法
//f(A, B)を全て求める
//max_lenは部分文字列であって同じ文字からなるもののうち最長のものの長さ（3番目の条件のやつ）
//求め方は公式解説のKの決定方法と同じ
string solve(int a, int b, int max_len) {
    //自明なやつ
    if (b == 0) return string(a, 'A');
    if (a == 0) return string(b, 'B');
    if (max(a, b) <= max_len) return string(a, 'A') + string(b, 'B');

    //a >= bなら'A' * max_len + 'B'を前に
    //a < bなら'A' + 'B' * max_lenを後ろに足していく
    //という操作を再帰的にやると上手くいく
    //（これで破綻しないことはmax_lenの計算方法から証明可能）
    if (a >= b) {
        if (max_len == -1) max_len = (a + b) / (b + 1);
        return string(max_len, 'A') + "B" + solve(a - max_len, b - 1, max_len);
    } else {
        if (max_len == -1) max_len = (a + b) / (a + 1);
        return solve(a - 1, b - max_len, max_len) + "A" + string(max_len, 'B');
    }
}

//満点解法
//前に足す操作をA，後ろに足す操作をBとすると
//操作列はAAA...ABAB...(or BBB...BABA...)みたいになる
//これらの操作列はAAA...のひたすら同じ操作をする部分と
//ABAB...の違う操作を交互にする部分に分けられる
string solve(int a, int b, int c, int d) {
    int max_len;
    int cnt_a = 0; //前に足す操作をした回数
    int cnt_b = 0; //後ろに足す操作をした回数

    //ひたすら前か後ろに足し続けるパート
    if (a >= b) {
        max_len = (a + b) / (b + 1);
        cnt_a = min({(a + b) / (max_len + 1), a / max_len, b});
        if (max_len > 1) cnt_a = min((a - b) / (max_len - 1), cnt_a);
        a -= cnt_a * max_len;
        b -= cnt_a;
    } else {
        max_len = (a + b) / (a + 1);
        cnt_b = min({(a + b) / (max_len + 1), b / max_len, a});
        if (max_len > 1) cnt_b = min((b - a) / (max_len - 1), cnt_b);
        b -= cnt_b * max_len;
        a -= cnt_b;
    }

    //前と後ろに交互に足すパート
    //このパート以降，(a <= max_len || b <= max_len)となる
    int tmp = min(b / (max_len + 1), a / (max_len + 1));
    cnt_a += tmp;
    cnt_b += tmp;
    a -= tmp * (max_len + 1);
    b -= tmp * (max_len + 1);

    //帳尻合わせ
    //これにより，(a <= max_len && b <= max_len)となる
    if (a >= b) {
        int tmp2 = min(a / max_len, b);
        cnt_a += tmp2;
        a -= tmp2 * max_len;
        b -= tmp2;
    } else {
        int tmp2 = min(b / max_len, a);
        cnt_b += tmp2;
        b -= tmp2 * max_len;
        a -= tmp2;
    }

    string res = "";
    //各インデックスの文字を調べる
    int ml1 = max_len + 1;
    int hoge1 = cnt_a * ml1;
    int hoge2 = hoge1 + a;
    int hoge3 = hoge2 + b;
    for (int i = c; i < d; i++) {
        if (i < hoge1) {
            int idx = i % ml1;
            res += (idx == max_len ? 'B' : 'A');
        } else if (i < hoge2) {
            res += 'A';
        } else if (i < hoge3) {
            res += 'B';
        } else {
            int idx = (i - hoge3) % ml1;
            res += (idx == 0 ? 'A' : 'B');
        }
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        c--;
        cout << solve(a, b, c, d) << "\n";
    }
    return 0;
}

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

int N;
int A[210];

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

  int res = 0;

  while(true) {
    bool exist_odd = false;
    for (int i = 0; i < N; ++i) {
      if (A[i] % 2 != 0) exist_odd = true;
    }

    if (exist_odd) break;

    for (int i = 0; i < N; ++i) {
      A[i] /= 2;
    }
    ++res;
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 3568
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let a = read::<u32>();
    let _ = read::<u32>();
    let _ = read::<u32>();
    let _ = read::<u32>();
    let e = read::<u32>();
    let k = read::<u32>();

    if e - a <= k {
        println!("Yay!");
    } else {
        println!(":(");
    }
}


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

int main() {
    int x[5];

    for (int j = 0; j < 5; ++j) {
        cin >> x[j];
    }

    for (int j = 0; j < 5; ++j) {
        if (x[j] == 0) {
            cout << j+1;
            break;
        }
    }

    return 0;
}




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

const int mod = 1e9+7 ;

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int h, w ;
	cin >> h >> w ;

	vector<string> g(h) ;
	for(auto &i : g)
		cin >> i ; 
	
	vector<vector<int> > dp (h, vector<int> (w, 0)) ;

	dp[0][0] = 1 ;
	
	for(int i = 1 ; i < w ; i++)
		dp[0][i] = (g[0][i] == '#' ? 0 : dp[0][i-1]) ;
	for(int i = 1 ; i < h ; i++)
		dp[i][0] = (g[i][0] == '#' ? 0 : dp[i-1][0]) ;

	for(int i = 1 ; i < h ; i++){
		for(int j = 1 ; j < w ; j++){
			if(g[i][j] == '#')
				continue ;

			dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod ;
		}
	}

	cout << dp[h-1][w-1] << endl ;

	return 0;
}

Measured memory_bytes: 5248
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N = I()
X,Y = [],[]
for i in range(N):
    x,y = MI()
    X.append((x,i+1))
    Y.append((y,i+1))

X.sort()
Y.sort()


# Kruskal


class Kruskal():
    def __init__(self,n):
        self.e = []
        self.par = [i for i in range(n+1)]  # 親のノード番号
        self.rank = [0]*(n+1)
    def add(self,u,v,d):  # クラスカル法で考えるのは無向グラフ
        self.e.append([u,v,d])
    def find(self,x):  # xの根のノード番号
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def same_check(self,x,y):  # x,yが同じグループか否か
        return self.find(x) == self.find(y)
    def unite(self,x,y):  # x,yの属するグループの併合
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        elif self.rank[x] > self.rank[y]:
            self.par[y] = x
        else:
            self.par[y] = x
            self.rank[x] += 1
    def Kruskal(self):
        edges = sorted(self.e,key=lambda x: x[2])  # 距離でソート
        a = 0
        for e in edges:
            if not self.same_check(e[0],e[1]):
                self.unite(e[0],e[1])
                a += e[2]
        return a


K = Kruskal(N)
for j in range(N-1):
    x0,i0 = X[j]
    x1,i1 = X[j+1]
    K.add(i0,i1,x1-x0)
for j in range(N-1):
    y0,i0 = Y[j]
    y1,i1 = Y[j+1]
    K.add(i0,i1,y1-y0)

print(K.Kruskal())


Measured memory_bytes: 121064
#include <iostream>
#include <string>
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define SIZE(x) ll(x.size())

typedef long long ll;

using namespace std;
int main() {
  string S, T;
  cin >> S >> T;
  int num = SIZE(S);
  REP(i, num) {
    if (S == T) {
      cout << "Yes";
      return 0;

    } else {
      string tmp = T;
      tmp.erase(num - 1);
      T = T[num - 1] + tmp;
    }
  }
  cout << "No";
  return 0;
}

Measured memory_bytes: 3576
import numpy as np

def main():
	S=input()
	array=[]
	pack=['A','T','G','C']
	for i in range(len(S)):
		temp=False
		for j in range(len(pack)):
			if(S[i]==pack[j]):
				temp=True
		if(temp):
			array.append(1)
		else:
			array.append(0)
	
	result=[]
	for i in range(len(array)):
		temp=0
		for j in range(i,len(array)):
			if(array[j]==1):
				temp+=1
			else:
				break
		result.append(temp)
	
	print(max(result))


def inputList():
	a=list(map(int,input().split()))
	return a

def multisort(li,index):
	return sorted(li,key=lambda x: x[index])

if(__name__=='__main__'):
	main()


Measured memory_bytes: 20776
//luckYrat written
//Twitter: @luckYrat_


//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <map>

//god(強すぎるので使用禁止！！！！！！！)
//#include <tourist>

using namespace std;

typedef pair<int,int> Paint;

bool Pairsecond(const Paint& pf,Paint&ps){//sortCompare
  return pf.second < ps.second;
}

#define anyfill(n,s) setw(n) << setfill(s)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define MAX 1000000000
#define MOD 1000000007


/*
確認ポイント
to_string() はC++11以降の実装;
cout<< (char)数値 //数値にあった文字に置き換えられる
cout<< (double)int型/(2など)//小数になる
length(),size()に括弧をつけ忘れてないか;
sort()が使える型//vector,string...
大文字小文字間違えてないか
cout << fixed << 小数計算//正しい小数表記になる(基本6桁)(e記法回避にも使える)
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
sqrt(数値型)でrootが取れる
vector.unique()は隣接した同じ要素を削除するので先にソートをする
*/

int main(){
  long long l,r;cin>>l>>r;
  if(r-l > 2019){
    cout << 0 << endl;
    return 0;
  }
  long long ans = 2019;
  for(int i = l; r >= i; i++){
    for(int j = i+1; r >= j; j++){
      //cout << i << " " << j << endl;
      if(i==j)continue;
      long long tmp = (long long)(i%2019)*(j%2019)%2019;
      ans = min(tmp,ans);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return 1;}return 0;}

const long long INF = 1LL << 60;
int n;
long long h[100010];
long long dp[100010];
int main(){
    int k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> h[i];
    for(int i = 0; i < 100010; i++) dp[i] = INF;
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 1; j <= k; j++){
            chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
        }
    }
    //for(int i = 0; i < n; i++)
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

int main(){
  int n, y;
  int b, t;
  double r;
  pair<int, double> ans;
  while(cin >> n, n){
    ans.second = 0;
    cin >> y;

    for(int i = 0 ; i < n ; i++){
      double tmp;
      cin >> b >> r >> t;
      
      if(t == 1){
	tmp = 1+(y*(r/100));
      }
      if(t == 2){
	tmp = 1 + (r/100);
	tmp = pow(tmp,y);
      }
      if(ans.second < tmp){
	ans.first = b;
	ans.second = tmp;
      }
    }
    cout << ans.first << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll p;
vl pw;

ll Div(ll n,ll m){
	return n*pw[m]%p;
}

vi a,dp;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>p;
	pw=vl(p,1);
	dp=vi(p+1);
	a=vi(p);
	dp[1]++;
	for(int i=0;i<p;i++) for(int j=0;j<p-2;j++) (pw[i]*=i)%=p;
	for(int i=1;i<p;i++){
		vi DP(p+1);
		for(int j=0;j<=p;j++){
			(DP[j]+=dp[j]*(p-i))%=p;
			if(j+1<=p) (DP[j+1]+=dp[j])%=p;
		}
		dp=DP;
	}
	for(int i=0;i<p;i++){
		int t;
		cin>>t;
		if(!t) continue;
		int x=1;
		vi DP(p);
		DP[p-1]=dp[p];
		for(int j=p-2;j>=0;j--) DP[j]=(dp[j+1]+DP[j+1]*i)%p;
		for(int j=0;j<p;j++) if(i!=j) (x*=i-j+p)%=p;
		for(int j=0;j<p;j++) (a[j]+=Div(DP[j],x))%=p;
	}
	for(int i=0;i<p;i++) cout<<a[i]<<" \n"[i==p-1];
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

ll N,M;

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

	for(int i=0;i<M;i++){
		ll a;
		cin>>a;
		N -= a;
	}
	if(N>=0)
		cout<<N<<endl;
	else
		cout<<-1<<endl;

}

Measured memory_bytes: 3620
import bisect
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))

cnt = 0
for ti in t:
    x = bisect.bisect_left(s, ti)
    if x < n and s[x] == ti:
        cnt += 1

print(cnt)


Measured memory_bytes: 16740
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	vector<string> s(n);
	vector<int> t(n);
	for(int i = 0; i < n; i++) cin >> s[i] >> t[i];
	string to; cin >> to;
	int i = 0;
	while(s[i] != to) i++;
	i++;
	int ans = 0;
	while(i < n) ans += t[i++];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1'000'000'007;
constexpr ll MOD2   = 998'244'353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    int dp[1000005];

    dp[1] = abs(h[1] - h[0]);
    for(int i = 2; i < n; ++i){
        dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]),
                    dp[i - 1] + abs(h[i] - h[i - 1]));
    }

    cout << dp[n - 1] << endl;

return 0;
}


Measured memory_bytes: 4036
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;

ll dp[103][103][503];

int main() {
	int N, W; cin >> N >> W;
	ll w[103], v[103];
	for (int i = 1; i <= N; ++i) {
		cin >> w[i] >> v[i];
	}
	ll ans = 0;
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= i; ++j) {
			for (int k = 0; k <= 500; ++k) {
				dp[i][j][k] = dp[i - 1][j][k];
				if (k >= 1) dp[i][j][k] = max(dp[i][j][k - 1], dp[i][j][k]);
				if (k - w[i] + w[1] >= 0) {
					dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - 1][k - w[i] + w[1]] + v[i]);
				}
				if (w[1] * j + k <= W) ans = max(ans, dp[i][j][k]);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 39168
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <bitset>

using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<int,ii> iii;

int A[5003], B[5003];
string dp[5003];
vector<string> vec, opt;

int main()
{
	ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);
	
	int n; cin >> n;
	string s; cin >> s;
	int cnt1 = 0, cnt2 = 0;
	string temp = "";
	for(int i = 0; i < s.size(); i++)
	{
		temp += s[i];
		cnt1 += (s[i] == 'a');
		cnt2 += (s[i] == 'b');
		if(cnt1 == cnt2)
		{
			vec.push_back(temp);
			cnt1 = cnt2 = 0;
			temp = "";
		}
	}
	for(string t : vec)
	{
		// cout << "T : " << t << "\n"; fflush(stdout);
		string temp = "";	
		if(t[0] == 'a')
		{
			memset(A, 0, sizeof A);
			memset(B, 0, sizeof B);
			cnt1 = cnt2 = 1;
			for(int i = 0; i < t.size(); i++)
			{
				if(t[i] == 'a') A[cnt1++] = i;
				if(t[i] == 'b') B[cnt2++] = i;
			}
			int ri = -1;
			for(int i = 1; i < cnt1; i++)
			{
				// cout << A[i] << " " << B[i] << " " << ri << "\n";
				if(A[i] > ri)
				{
					temp += "ab";
					ri = B[i];
				}
			}
			opt.push_back(temp);
		}
		else
		{
			temp = "";
			string now = "";
			cnt1 = cnt2 = 0;
			for(int i = t.size()-1; i >= 0; i--)
			{
				now += t[i];
				cnt1 += (t[i] == 'a');
				cnt2 += (t[i] == 'b');
				string temp2 = now;
				int cnt3 = cnt2;
				int j = i;
				while(cnt3 != cnt1)
				{
					j--;
					if(t[j] == 'a') continue;
					temp2 += 'b';
					cnt3++;
				}
				reverse(temp2.begin(), temp2.end());
				temp = max(temp,temp2);
			}
			opt.push_back(temp);
		}
	}
	string ans = "";
	for(int i = 0; i < opt.size(); i++)
	{
		dp[i] = opt[i];
		ans = max(dp[i], ans);
		for(int j = 0; j < i; j++)
		{
			dp[i] = max(dp[i], dp[j]+opt[i]);
			ans = max(dp[i], ans);
		}
	}
	cout << ans << "\n";
}











Measured memory_bytes: 14464
n = gets.to_i
hs = gets.split.map(&:to_i)

dp = []
dp[0] = 0
dp[1] = (hs[0] - hs[1]).abs
(2..n-1).each do |i|
  dp[i] = [dp[i-2] + (hs[i-2] - hs[i]).abs, dp[i-1] + (hs[i-1] - hs[i]).abs].min
end
puts dp[n-1]


Measured memory_bytes: 11524