akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int O = 80 * 80;
bitset<O * 2> bs[80][80];

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

    int h, w;
    cin >> h >> w;

    int a[80][80];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int b;
            cin >> b;
            a[i][j] = abs(a[i][j] - b);
        }
    }

    bs[0][0][O + a[0][0]] = true;
    bs[0][0][O - a[0][0]] = true;

    for (int j = 1; j < w; j++) {
        bs[0][j] = bs[0][j - 1] >> a[0][j] | bs[0][j - 1] << a[0][j];
    }
    for (int i = 1; i < h; i++) {
        bs[i][0] = bs[i - 1][0] >> a[i][0] | bs[i - 1][0] << a[i][0];
        for (int j = 1; j < w; j++) {
            bs[i][j] = bs[i - 1][j] >> a[i][j] | bs[i - 1][j] << a[i][j] | bs[i][j - 1] >> a[i][j] | bs[i][j - 1] << a[i][j];
        }
    }

    for (int x = 0; x < O; x++) {
        if (bs[h - 1][w - 1][O + x]) {
            cout << x << endl;
            break;
        }
    }

    //差は最大でも80 160回足して
    //合計としてありえるもの 切れ目としてありえるものは共通じゃないからなあ

    return 0;
}

Measured memory_bytes: 10368
#include<stdio.h>

long gg[8][8],box[8];
long dis=200000000;
long min(long x,long y){
  if(x<y) return x;
  else return y;
}

void dfs(int r,long d,int n){
  int i,j,flag=1;
  if(r==n) {dis=min(dis,d);}
  else{
    for(i=0;i<r;i++){
      flag=1;
      for(j=0;j<n;j++)
        if(box[j]==i) flag=0;
      if(flag){
        box[n]=i;
        if(n==0) dfs(r,d,n+1);
        else dfs(r,d+gg[box[n]][box[n-1]],n+1);
      }
    }
  }
}

int main(){
  int n,m,r,a[20000],b[20000],i,j,k,rr[8],f[8];
  long c[20000];
  long g[201][201]={};
  scanf("%d %d %d",&n,&m,&r);
  for(i=0;i<r;i++)
    scanf("%d",rr+i);
  for(i=0;i<=n-1;i++){
    for(j=i+1;j<=n;j++){
      g[i][j]=g[j][i]=20000001;
    }
  }
  for(i=0;i<m;i++){
    scanf("%d %d %ld",a+i,b+i,c+i);
    g[a[i]][b[i]]=g[b[i]][a[i]]=c[i];
  }
  
  for(k=1;k<=n;k++){
    for(i=1;i<=n;i++){
      for(j=1;j<=n;j++){
        if(g[i][j]>g[i][k]+g[k][j])
          g[i][j]=g[j][i]=g[i][k]+g[k][j];
      }
    }
  }
  for(i=0;i<r;i++){
    for(j=0;j<r;j++){
      gg[i][j]=g[rr[i]][rr[j]];
     // printf("%ld ",gg[i][j]);
    }
   // printf("\n");
  }
  dfs(r,0,0);
  printf("%ld\n",dis);
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m,x,y,res=0;
	cin>>n>>m;
	int num[100001]={0},ball_num[100001]={0};
	num[1]=1;
	for(int i=0;i<m;i++){
		cin>>x>>y;
		ball_num[x]--;
		ball_num[y]++;
		if(num[x]==1){
			num[y]=1;			
		}
		if(ball_num[x]==-1){
			num[x]=0;
		}
	}
	for(int i=1;i<=n;i++){
		if(num[i]==1)
			res++;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  ll d;
  cin >> n >> d;
  int cnt = 0;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    if (d * d >= x * x + y * y) {
      cnt++;
    }
  }
  cout << cnt;
  return 0;
}


Measured memory_bytes: 3628
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Stack;

public class Main {
	public static void main(String[] args) {
		Main p = new Main();
	}

	public Main() {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			String s = sc.next();
			if (s.charAt(0) == '.')
				break;
			solve(s);
		}
	}

	public void solve(String s) {
		int res = 0;
		for (int p = 0; p <= 2; p++) {
			for (int q = 0; q <= 2; q++) {
				for (int r = 0; r <= 2; r++) {
					cur = 0;
					fomula = s.replaceAll("P", p + "")
							.replaceAll("Q", q + "").replaceAll("R", r + "");
					int v = scan();
					if (v == 2){
//						System.out.println(fomula);
						res++;
					}
				}
			}
		}
		System.out.println(res);
	}

	String fomula;
	int cur = 0;

	private int scan() {
		int v = -1;
		char c = next();
		switch (c) {
		case '0':
		case '1':
		case '2':
			v = c - '0';
			break;

		case '-':
			v = 2 - scan();
			break;
		
		case '(':
			v = op();
			break;
		}

		return v;

	}

	private int op() {
		int v = scan();
		char c = next();
		switch(c){
		case '+':
			v = Math.max(v, scan());
			break;
			
		case '*':
			v = Math.min(v, scan());
			break;
		}
		next();
		return v;
	}

	private char next() {
		char c = fomula.charAt(cur);
		cur++;
		return c;
	}
}

Measured memory_bytes: 33088
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() 
{
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    long long int i,j,k,l,inc,dec,t,r,mod=1000000007;
   	long long int c,d,e,s,ans=0,n,temp,m,p,x,y;
   	//cin>>t;
   	t=1;
   	while(t--)
   	{
   		cin>>n>>k;
   		long long int w[n+1],v[n+1];
   		w[0]=0;
   		v[0]=0;
   		for(i=1;i<=n;i++)
   		{
   			cin>>w[i]>>v[i];
   			ans=ans+v[i];
		}
		long long int dp[n+1][ans+1];
		for(i=0;i<=n;i++)	
			for(j=0;j<=ans;j++)
				dp[i][j]=INT_MAX;
				
		for(i=0;i<=n;i++)
				dp[i][0]=0;
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=ans;j++)
			{
	
				if(v[i]>j)
				{
					dp[i][j]=dp[i-1][j];
				}
				else
				{
					dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
				}	
			}
		}
		x=0;
	
		for(i=0;i<=ans;i++)
		{
			if(dp[n][i]<=k)
			{
				x=i;
			}
		}
		cout<<x<<endl;
		
	}
   	
	
   return 0;
}
/*
3 5
1 1
2 3
3 4
*/


Measured memory_bytes: 79104
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;

public class Main {

    static int cnt = 0;
    public static void main(String args[]) throws Exception
    {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M  = sc.nextInt();

        boolean map[][] = new boolean[N][N];

        for(int i=0;i<M;i++){
            int x = sc.nextInt();
            int y = sc.nextInt();
            map[x-1][y-1] = true;
            map[y-1][x-1] = true;
        }
        Stack<Integer> stack = new Stack<>();
        stack.push(0);
        dfsCount(map,stack);
        System.out.println(cnt);


        sc.close();
    }

    static void dfsCount(boolean [][] map , Stack<Integer> path ){
        int size = map.length;
        if (path.size()==size) {
            cnt++;
            return;
        }
        int peek = path.peek();
        for(int i =0;i<size;i++){
            if(map[peek][i]&&!path.contains(i)){
                Stack<Integer> sq = (Stack<Integer>)path.clone();
                sq.push(i);
                dfsCount(map,sq);
            }
        }
    }

}

Measured memory_bytes: 23636
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	long long a,b,c;	cin>>a>>b>>c;
	long long k=c-a-b;
	if(k<0)
		cout<<"No"<<endl;
	else if(k*k>4*a*b)
		cout<<"Yes"<<endl;
	else 
		cout<<"No"<<endl;
}

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

int main(){
    ios_base::sync_with_stdio(false) , cin.tie(0) ,cout.tie(0);
	
	string s1,s2,s3;
	cin>>s1>>s2>>s3;
	
	int current = 0;
	int i=0,j=0,k=0;
	
	while(true){
		
		if(current == 0){
				while(s1[i] == 'a'){
						i++;
				}
				if(i == s1.length()){
					cout<<'A';
					return 0;
				}
				else{
					if(s1[i] == 'c'){
						current = 2;
					}else{
						current = 1;
					}
				}
				i++;
		}else if(current == 1){
			
				while(s2[j] == 'b'){
						j++;
				}
				if(j == s2.length()){
					cout<<'B';
					return 0;
				}
				else{
					if(s2[j] == 'c'){
						current = 2;
					}else{
						current = 0;
					}
				}
				j++;
		}else{
			
				while(s3[k] == 'c'){
						k++;
				}
				if(k == s3.length()){
					cout<<'C';
					return 0;
				}
				else{
					if(s3[k] == 'a'){
						current = 0;
					}else{
						current = 1;
					}
				}
				k++;
		}
	}
	return 0;
} 


Measured memory_bytes: 3652
s = input()
even = ["R","U","D"]
odd = ["L","U","D"]
for i in range(len(s)):
    if i % 2 == 0:
        if not s[i] in even:
            print("No")
            break
    else:
        if not s[i] in odd:
            print("No")
            break
else:
    print("Yes")

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

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

    vector<int> ans;
    for(int i=0; i<N; i++){
        int idx = -1;
        for(int j=b.size()-1; j>=0; j--){
            if(b[j] == j+1){
                idx = j;
                break;
            }
        }
        if(idx == -1){
            cout << -1 << endl;
            return 0;
        }
        ans.push_back(idx);
        vector<int> c;
        for(int i=0; i<idx; i++)
            c.push_back(b[i]);
        for(int i=idx+1; i<b.size(); i++)
            c.push_back(b[i]);
        b = c;
    }
    reverse(ans.begin(), ans.end());
    for(int x : ans)
        cout << x+1 << endl;


    return 0;
}

Measured memory_bytes: 256
#include <math.h>

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;

  string tmp = S;
  for(int i=0; i<S.size(); i++) {
    tmp = S.substr(i, S.size()) + S.substr(0, i);
    if (tmp == T) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}


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

int main()
{
    string top, bottom, ans_s[2] = {"NO", "YES"};
    cin >> top >> bottom;
    cout << ans_s[(top[0] == bottom[2] && top[1] == bottom[1] && top[2] == bottom[0])] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <bits/stdc++.h>
     
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
     
using namespace std;
     
const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 10.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    ll n, m;
    cin >> n >> m;
    ll r1 = 1, r2 = 1;
    rep(i, 1, n + 1)
        r1 = (r1 * i) % MOD;
    rep(i, 1, m + 1)
        r2 = (r2 * i) % MOD;
    if (n == m)
        cout << r1 * r2 * 2 % MOD << endl;
    else if (abs(n - m) == 1)
        cout << r1 * r2 % MOD << endl;
    else
        cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 764
n, k = map(int, input().split())
nums = [int(i) for i in input().split()]

mod = 10 ** 9 + 7 # (modの値をすごく大きくすれば（5乗とか）、普通のnCrとして使える)
MAX = 10 ** 5 + 1 # これは変動するので注意。せいぜい10 ** 6くらいまでがTLEの限界

def com_init(MAX, mod):
    fac = [0] * MAX
    finv = [0] * MAX
    inv = [0] * MAX
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod
    return fac, finv

fac, finv = com_init(MAX, mod)

def nCr(n, r):
    if n < r:
        return 0
    elif n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod

nums.sort()
MIN = 0
for i in range(n - k + 1):
    MIN += (nums[i] * nCr(n - i - 1, k - 1)) % mod

nums.sort(reverse=True)
MAX = 0
for i in range(n - k + 1):
    MAX += (nums[i] * nCr(n - i - 1, k - 1)) % mod

ans = (MAX - MIN) % mod
print(ans)

Measured memory_bytes: 63344
#include <iostream>
#include <vector>
#include <set> 
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long int ll;
#define mod 1000000007
map <int,ll> fact,inv_fact;
ll dmod(ll x){
    return ((x+mod)%mod);
}
ll power(ll x,ll y){
    ll ans=1;
    while(y>0){
        if(y&1)ans=dmod(ans*x);
        y/=2;
        x=dmod(x*x);
    }
    return ans;
}
void precompute(int x){
    inv_fact[0]=1;
    fact[0]=1;
    for(int i=1;i<=x;++i){
        fact[i]=dmod(fact[i-1]*i);
    }
}
ll outsource(ll n,ll r){
    return power(dmod(fact[r]*fact[n-r]),mod-2);
}
ll ncr(ll n,ll r){
    return dmod(fact[n]*outsource(n,r));
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin>>k;
    string s;
    cin>>s;
    int n=s.length();
    precompute(n+k);
    ll ans=0;
    for(int i=n;i<=n+k;++i){
        ans+=dmod(ncr(n+k,i)*power(25,n+k-i));
    }
    cout<<dmod(ans)<<endl;
    return 0;
}

Measured memory_bytes: 129060
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <vector>
#include <bitset>
#include <stack>
#include <iomanip>
#include <set>
#include <queue>
#include <map>


typedef long long ll;
typedef unsigned long long ull;
#define mk make_pair
#define mkt make_tuple
#define fi first
#define se second


using namespace std;
int const N = 200005;
ll ans[N], a[N];

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	
	 ll sign = 1ll;
	 for (int i = 0; i < n; i++) {
		 ans[0] += a[i] * sign;
		 sign = -sign;
	 }
	 ans[0] /= 2;
	 cout << ans[0]*2 << ' ';
	 for (int i = 1; i < n; i++) {
		 ans[i] = a[i - 1] - ans[i - 1];
		 cout << ans[i]*2 << ' ';
	 }
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define f first
#define s second
#define mod 1000000007

ll power(ll x, ll y){
	if(y==0)return 1;
	ll ps = power(x, y/2)%mod;
	ll ss = (ps%mod*ps%mod)%mod;
	if(y&1)ss = (x%mod*ss%mod)%mod;
	return ss%mod;
}

int main(){
	
	ll a, b;
	cin>>a>>b;
	ll ans = a-2*b;
	cout<<max(0LL,ans)<<endl;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace

solve :: Int -> Int
solve n | n <= 9 = 0
        | otherwise = ((fm 4) * ((fm 4) - 1) `div` 2) * ((fm 2) - 2)
                      + (fm 14) * ((fm 4) - 1)
                      + (fm 24) * ((fm 2) - 1)
                      + (fm 74)
  where

  pvec = VU.toList $ VU.create $ do
    v <- VUM.replicate 101 0
    forM_ [2..n] $ \k -> do
      forM_ (prfac k) $ \(p,r) -> VUM.modify v (+ r) p
    return v

  fm :: Int -> Int
  fm k = length (filter (>= k) pvec)

sieve :: [Int]
sieve = 2 : sieve_sub [2] [3..]

sieve_sub :: [Int] -> [Int] -> [Int]
sieve_sub (n:yet) cand =
  let
    (cnfmd, rem) = span (< n*n) cand
    newcand = filter (\i -> i `mod` n /= 0) rem
  in cnfmd ++ sieve_sub (yet ++ cnfmd) newcand

-- prfac : prime factorization

prfac :: Int -> [(Int,Int)]
prfac n = filter ((>= 1) . snd) $ unfoldr f (sieve, n)
  where
    f (_, 1) = Nothing
    f (p:ps, k) | p*p > k   = Just ((k, 1), ([], 1))
                | otherwise = Just ((p, pow), (ps, div k p_pow))
      where (pow, p_pow) = divmany k p
    divmany k p = sub 0 1 k
      where sub pow p_pow x | m == 0    = sub (pow+1) (p_pow*p) d
                            | otherwise = (pow, p_pow)
              where (d,m) = divMod x p

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n]:remLines1 = remLines0
      n = readBInt bs_n
  in solve n

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, b, a) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;

template <typename T>
struct MinCostFlow {
  struct Edge {
    int u, v;
    T c, w, f;
  };
  const T eps = T(1e-9), INF = numeric_limits<T>::max();
  vector<Edge> E;
  int n, src, sink;
  vector<vector<int>> G;
  T flow = T(), cost = T();
  MinCostFlow(int n, int src, int sink) : n(n), src(src), sink(sink), G(n) {}

  void clear_flow() {
    for (auto& e : E) e.f = T();
    flow = cost = T();
  }
  void reduce() {
    for (auto& e : E) e.c -= e.f;
  }
  void add_edge(int u, int v, T cap, T cost) {
    assert(0 <= u && u < n && 0 <= v && v < n);
    G[u].push_back(E.size()), E.push_back({u, v, cap, cost, T()});
    G[v].push_back(E.size()), E.push_back({v, u, 0, -cost, T()});
  }
  T min_cost_flow(T f = -1) {
    if (f < 0) f = INF;
    if (flow > f) clear_flow();
    f -= flow;
    while (f > eps) {
      vector<T> D(n, INF);
      vector<int> Inq(n), P(n);
      queue<int> Q;
      Q.push(src), D[src] = T(), Inq[src] = 1;
      while (!Q.empty()) {
        int u = Q.front();
        Q.pop(), Inq[u] = 0;
        for (auto i : G[u]) {
          const auto& e = E[i];
          if (e.c - e.f > eps && D[e.v] > D[u] + e.w) {
            D[e.v] = D[u] + e.w, P[e.v] = i;
            if (!Inq[e.v]) Q.push(e.v), Inq[e.v] = 1;
          }
        }
      }
      if (D[sink] == INF) break;
      T can = f;
      for (int u = sink; u != src; u = E[P[u]].u) can = min(can, E[P[u]].c - E[P[u]].f);
      f -= can, flow += can, cost += D[sink] * can;
      for (int u = sink; u != src; u = E[P[u]].u) E[P[u]].f += can, E[P[u] ^ 1].f -= can;
    }
    return cost;
  }
};

const int N = 1005;
int n, RX[N], RY[N], BX[N], BY[N], RC[N], BC[N];

int main() {
  scanf("%d", &n);
  int src = 0, sink = n + n + 5;
  MinCostFlow<LL> mc(n + n + 6, src, sink);
  FI(i, 1, n) scanf("%d%d%d", &RX[i], &RY[i], &RC[i]);
  FI(i, 1, n) scanf("%d%d%d", &BX[i], &BY[i], &BC[i]);
  FI(i, 1, n) {
    mc.add_edge(src, i, RC[i], 0LL);
    mc.add_edge(i + n, sink, BC[i], 0LL);
  }
  FI(i, 1, n) {
    mc.add_edge(i, n + n + 1, RC[i], -(RX[i] + RY[i]));
    mc.add_edge(i, n + n + 2, RC[i], -(RX[i] - RY[i]));
    mc.add_edge(i, n + n + 3, RC[i], -(-RX[i] + RY[i]));
    mc.add_edge(i, n + n + 4, RC[i], -(-RX[i] - RY[i]));
  }
  FI(i, 1, n) {
    mc.add_edge(n + n + 1, i + n, BC[i], (BX[i] + BY[i]));
    mc.add_edge(n + n + 2, i + n, BC[i], (BX[i] - BY[i]));
    mc.add_edge(n + n + 3, i + n, BC[i], (-BX[i] + BY[i]));
    mc.add_edge(n + n + 4, i + n, BC[i], (-BX[i] - BY[i]));
  }
  cout << -mc.min_cost_flow() << endl;
}


Measured memory_bytes: 1604
#include <bits/stdc++.h>
using namespace std;
#define w(x) int x;cin>>x;while(x--)
#define ll long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define vi vector<int>
#define fr(a,b) for(int i=a;i<=b;i++)
#define inf 1e18
#define mod 99824435
int main()
{   
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r",stdin);
	freopen("output.txt", "w",stdout);
#endif*/
	fast;
    int n;
    cin>>n;
    if(n==1)
    	cout<<"0\n";
    else if(n==0)
    	cout<<1<<"\n";
	return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
vector<int> G[10];
int n,m;
int vis[15];
bool check(){
    fore(i,0,n)
        if(vis[i] == -1)
            return 0;
    return 1;
}
int dfs(int u){
    if(check())
        return 1;

    int ans = 0;
    fore(i,0,sz(G[u])){
        int v = G[u][i];
        if(vis[v] == -1){
            vis[v] = 1;
            ans += dfs(v);
            vis[v] = -1;
        }
    }
    return ans;
}
int main(){/*
    freopen("in","r",stdin);
    freopen("out","w",stdout);*/
    fast;
    cin >> n >> m;
    while(m--){
        int u,v;
        cin >> u >> v;
        u--;v--;
        G[u].pb(v);
        G[v].pb(u);
    }
    cls(vis,-1);
    vis[0] = 1;
    cout << dfs(0) << '\n';
    return 0;   
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	a := nextInt()
	b := nextInt()
	if a*b%2 == 1 {
		fmt.Println("Odd")
	} else {
		fmt.Println("Even")
	}
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<map>
using namespace std;
const int N=1e5+50;
const int INF=0x3f3f3f3f;
typedef long long ll;
char s[N],ss[N];
int main()
{
    scanf("%s",s);
    int sum=0,ans=0,len=strlen(s);
    while(1)
    {
        for(int i=1;i<len-1;i++)
        {
            if(s[i]!='\0')
            {
                int x=i-1;
                while(s[x]=='\0')
                    x--;
                if(s[x]!=s[i+1])
                {
                    s[i]='\0';
                    sum++;
                }
            }
        }
        int cnt=0;
        for(int i=0;i<len;i++)
            if(s[i]!='\0')
                ss[cnt++]=s[i];
        for(int i=0;i<len;i++)
            s[i]=ss[i];
        len=cnt;
        if(sum==ans)
            break;
        ans=sum;
    }
    if(sum%2)
        printf("First\n");
    else
        printf("Second\n");
    return 0;
}


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

main()
{
    while(1)
    {
        int n,m; cin>>n>>m;
        if(!n and !m) break;
        vector<int> a(n);
        for(int&x:a) cin>>x;
        int ans=-1;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<i;j++)
            {
                if(m>=a[i]+a[j])
                {
                    ans=max(ans,a[i]+a[j]);
                }
            }
        }
        if(~ans) cout<<ans<<endl;
        else cout<<"NONE\n";
    }
}



Measured memory_bytes: 3100
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        k: usize,
        ll: [u32; n],
    };
    let mut l = ll.clone();
    l.sort_by(|a, b| b.cmp(a));
    println!("{}", l.iter().take(k).sum::<u32>());
}


Measured memory_bytes: 4352
import Control.Arrow
import Data.List

sclMult :: Num a => a -> (a,a) -> (a,a)
sclMult a = (*a) *** (*a)
addVect :: Num a => (a,a) -> (a,a) -> (a,a)
addVect (x,y) (z,w) = (x+z,y+w)

hunt :: [(Int,Int)] -> (Int,Int)
hunt = (truncate *** truncate) . fst . foldl' step ((0,0),90) where
    step :: ((Double,Double), Int) -> (Int,Int) -> ((Double,Double),Int)
    step (loc,dir) (d,theta) = (newloc,(dir-theta) `mod` 360) where
        t =  pi * fromIntegral dir / 180
        newloc = addVect loc . sclMult (fromIntegral d) $ (cos t, sin t)

main = getContents >>=
    (\(x,y) -> do print x; print y) . hunt
            . map ( (\[x,y] -> (x,y)) . map read . split) . lines


split :: String -> [String]
split [] = []
split xs = let (pre,post) = span (/= ',') xs
               in
                   if null post then [pre]
                                else pre: split (tail post)

Measured memory_bytes: 3952
#include <iostream>
#include <utility>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

constexpr long long int inf = INT64_MAX / 2;

class path {
public:
    long long int from,to,cost;
    path(long long int from_,long long int to_,long long int cost_) {
        from = from_;
        to = to_;
        cost = cost_;
    }
    bool operator<(const path& e) const {
        if (from != e.from) return from < e.from;
        if (to != e.to) return to < e.to;
        return cost < e.cost;
    }
};

int main() {
    long long int n,m,p;
    cin >> n >> m >> p;
    long long int a,b,c;
    vector<long long int> cs,reach;
    for(long long int i = 0;i < n;i++) {
        cs.push_back(inf);
        reach.push_back(inf);
    }
    cs[0] = 0;
    reach[n-1] = 0;
    vector<path> pt,pp;
    for(long long int i = 0;i < m;i++) {
        cin >> a >> b >> c;
        a--;
        b--;
        c = -(c - p);
        pt.push_back(path(a,b,c));
        pp.push_back(path(b,a,c));
    }
    sort(pt.begin(),pt.end());
    sort(pp.begin(),pp.end());
    bool flag = true;
    while(flag){
        flag = false;
        for(long long int j = 0;j < n;j++) {
            auto il = lower_bound(pp.begin(),pp.end(),path(j,-10,0));
            auto ir = lower_bound(pp.begin(),pp.end(),path(j+1,-10,0));
            for(auto itr = il;itr != ir;itr++) {
                if(reach[itr->to] != min(reach[itr->to],reach[itr->from])) {
                    reach[itr->to] = min(reach[itr->to], reach[itr->from]);
                    flag = true;
                }
            }
        }
    }

    flag = true;
    long long int cnt = 0;
    while(flag) {
        flag = false;
        cnt++;
        if(cnt > max(n,m) + 10) goto no_max;
        for(long long int i = 0; i < n;i++) {
            if(reach[i] == inf || cs[i] == inf) continue;
            auto il = lower_bound(pt.begin(),pt.end(),path(i,-10,0));
            auto ir = lower_bound(pt.begin(),pt.end(),path(i+1,-10,0));
            for(auto itr = il;itr != ir;itr++) {
                if(cs[itr->to] > cs[itr->from] + itr->cost) {
                    cs[itr->to] = cs[itr->from] + itr->cost;
                    flag = true;
                }
            }
        }
    }
    cout << max((long long)0,-cs[n-1]) << endl;
    return 0;
    no_max:
    cout << -1 << endl;
}

Measured memory_bytes: 740
n = gets.to_i
s = n.times.map { gets.chomp }

a = s.grep(/^[^B].*A$/).size
b = s.grep(/^B.*[^A]$/).size
c = s.grep(/^B.*A$/).size
d = s.map{|s| s.scan(/AB/).size}.inject(:+)

ans = d #それぞれの文字の中のABの数
if c > 0 # B..Aが一つ以上
  ans += c - 1
  ans += 1 if a > 0
  ans += 1 if b > 0
  ans += [a-1,b-1].min if a > 1 && b > 1
else
  ans += [a,b].min
end

puts ans


Measured memory_bytes: 6012
#include <bits/stdc++.h>
#define L long long
#define LL long long
#define SS string
#define PB push_back
#define pp pair<L,L>
#define f(x,n) for (L i = x ; i <= n ; i++)
#define N 100005
using namespace std;
L visited[N];
L a[N] , h[N];
    L n ,k;
L recursivedpminpath(L stone)
{
    if (stone == 1)
    return 0;
    if (stone < 1)
    return INT_MAX;
    if (visited[stone])
    return a[stone];
    visited[stone] = 1;
    L b = 1;
    L tk = k;
    while (tk--)
    {
        if (stone - b <= 0)
        break;
        a[stone] = min(a[stone],recursivedpminpath(stone-b) + abs(h[stone]-h[stone-b]));
        b++;
    }
    return a[stone];
}
int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    L i;
    f(1,n)
    {
        a[i] = INT_MAX;
        cin >> h[i];
    }
    a[1] = 0;
    cout << recursivedpminpath(n);
    return 0; 
}

Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n, a;
int f[1000];

int main() {
	cin >> n;
	REP(i, n) {
		cin >> a;
		f[a / 400]++;
	}
	int cnt = 0;
	int ans = 0;
	REP(i, 13) {
		if (i >= 8) {
			ans += f[i];
			cnt += f[i];
		}
		else {
			ans += (f[i] > 0);
		}
	}
	cout << max(1, ans - cnt) << " " << ans << endl;
}

Measured memory_bytes: 256
void repeat(char c, int n) {
    for (; n; n--) putchar(c);
}

int main() {
    for (;;) {
        int h, w;
        scanf("%d %d", &h, &w);
        if (h == 0) return 0;

	repeat('#', w);
	putchar('\n');
        for (h -= 2; h; h--) {
	    putchar('#');
            repeat('.', w -2);
	    putchar('#');
            putchar('\n');
        }
	repeat('#', w);
        putchar('\n');
        putchar('\n');
    }
}


Measured memory_bytes: 2028
#include<stdio.h>
int main () {
    int N, M, C, A[20][20], B[20], i, k, D[20], count = 0;
    scanf("%d %d %d", &N, &M, &C);
    for(i = 0; i < M; ++i) scanf("%d", &B[i]);
    for(i = 0; i < N; ++i){
        D[i] = C;
        for(k = 0; k < M; ++k){
            scanf("%d", &A[i][k]);
            D[i] += A[i][k] * B[k];
        }
        if(D[i] > 0) count++;
    }
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

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

    System.out.println(LCS(a, b));
  }

  private static String LCS(String a, String b) {
    if (a.length() == 0 || b.length() == 0)
      return "";
    int[][] dp = new int[a.length() + 1][b.length() + 1];

    for (int i = 0; i < dp.length; i++)
      dp[i][0] = i;

    for (int j = 0; j < dp[0].length; j++)
      dp[0][j] = j;

    for (int i = 1; i < dp.length; i++)
    for (int j = 1; j < dp[0].length; j++) {
      if (a.charAt(i - 1) == b.charAt(j - 1)) {
        dp[i][j] = dp[i-1][j-1];
      } else {
        dp[i][j] = Math.min(dp[i][j-1], dp[i-1][j]) + 1;
      }
    }

    StringBuilder sb = new StringBuilder();

    int i = dp.length - 1;
    int j = dp[0].length - 1;

    while (i >= 0 && j >= 0) {
      int strI = i - 1;
      int strJ = j - 1;
      if (strI >= 0 && strJ >= 0 && a.charAt(strI) == b.charAt(strJ)) {
        sb.append(a.charAt(strI));
        i--;
        j--;
      } else {
        int top = i > 0 ? dp[i - 1][j] : Integer.MAX_VALUE;
        int left  = j > 0 ? dp[i][j - 1] : Integer.MAX_VALUE;

        if (left > top) i--;
        else j--;
      }
    }
    return sb.reverse().toString();
  }

}

Measured memory_bytes: 80844
a,b,c,d=map(int,input().split())
p=c
q=d
e=b//c-(a-1)//c
f=b//d-(a-1)//d
while c%d!=0 and d%c!=0:
    if c>d:
        c=c-d
    elif c<=d:
        d=d-c
if c>d:
    gcm=d
else:
    gcm=c
lcm=(p*q)//gcm
g=b//lcm-(a-1)//lcm
ans=b-a+1-e-f+g
print(int(ans))

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

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

    int m;
    cin >> m;
    while (m--) {
        string s;
        cin >> s;
        int n = s.size();
        set<string> st;
        for (int i = 1; i <= n - 1; i++) {
            string t = s.substr(0, i);
            string u = s.substr(i);
            rep(j, 2) {
                rep(k, 2) {
                    rep(l, 2) {
                        st.insert(t + u);
                        swap(t, u);
                    }
                    reverse(all(u));
                }
                reverse(all(t));
            }
        }
        cout << st.size() << endl;
    }
}

Measured memory_bytes: 3096
#include<iostream>
#include<bits/stdc++.h>
#define LL long long int
using namespace std;
int main()
{	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int t;
	t=1;
	while(t--)
	{
			LL k;
			cin>>k;
			if(k%2==0|| k%5==0)
			{
				cout<<-1<<"\n";
			}
			else
			{
				string s;
				LL count=0;
				LL sum=0;
			LL a=0;
				for(LL i=0; ;i++)
				{
					count++;
					a=a*10+7;
					a=a%k;
					if(a==0)
					break;
					
				}
				cout<<count<<"\n";
			}
		
	
	}
}

Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 4000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;

const int maxn = 1e6+5;
int n, m;
struct node {
    int to, next, w;
    bool operator < (const node& a) const {
        return w > a.w;
    }
} e[maxn<<1];
int cnt, head[maxn];
void add(int u, int v, int w) {
    e[cnt] = node{v, head[u], w};
    head[u] = cnt++;
}
bool vis[maxn];
int dis[maxn];
void SPFA(int st, int ed) {
    priority_queue<node> q;
    memset(dis,INF,sizeof(dis));
    memset(vis,false,sizeof(vis));
    dis[st] = 0;
    q.push(node{st, 0, 0});
    while (!q.empty()) {
        node u = q.top();
        q.pop();
        if(vis[u.to]) continue;
        vis[u.to] = 1;

        for (int i = head[u.to]; ~i; i = e[i].next) {
            int to = e[i].to;
            if (dis[to] > dis[u.to] + e[i].w) {
                dis[to] = dis[u.to] + e[i].w;
                q.push(node{to, 0, dis[to]});
            }
        }
    }
    printf("%d\n", dis[ed] == INF?-1:dis[ed]/2);
}
map<int, int>mp[maxn];
void init() {
    cnt = 0;
    memset(head,-1,sizeof(head));
    for (int i = 1 ; i <= n ; i ++) {
        mp[i].clear();
    }
}
int getid(int x, int y) {
    if (!mp[x][y]) mp[x][y] = ++n;
    return mp[x][y];
}
int main() {
    scanf("%d%d",&n,&m);
        init();
        int endd=n;
        for (int i=1; i<=m; i++) {
            int u, v, c;
            scanf("%d%d%d", &u, &v, &c);
            int uc = getid(u, c);
            int vc = getid(v, c);
            add(uc, vc, 0);
            add(vc, uc, 0);
            add(u, uc, 1);
            add(uc, u, 1);
            add(v, vc, 1);
            add(vc, v, 1);
        }
        SPFA(1,endd);
    
    return 0;
}


Measured memory_bytes: 94068
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;
// ------------------------------

int main() {
    int N;
    cin >> N;
    if (N % 1000 == 0) cout << 0 << endl;
    else cout << 1000 - N % 1000 << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <math.h>

int main(){


int s[1001];
 long long n,sum=0,i;
 double ave=0,ans2,ans1;

 for(;;){

  scanf("%lld",&n);

  if(n==0){
    break;
  }

for(i=1;i<=n;i++){

  scanf("%d",&s[i]);

  sum+=s[i];
 }

ave=(double)sum/n;

for(i=1;i<=n;i++){

  ans1 += ( s[i] - ave) * (s[i] - ave);


 }

ans2 =sqrt(ans1/n);

printf("%lf\n",ans2);

 sum=0;
 ave=0;
 ans1=0;
 ans2=0;

 }
return 0;
}
 

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

int main()
{
    string S;
    cin >> S;

    rep(i, 3) {
        if (S.at(i) == '7') {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 3072
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <iostream>

using namespace std;
typedef long long ll;

const int MAX_N = 100;

int N;
ll W;
ll w[MAX_N + 1], v[MAX_N + 1];
ll dp[MAX_N + 1][3 * (MAX_N - 1) + 1][MAX_N + 1];

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

    cin >> N >> W;

    ll bw;
    cin >> bw;
    cin >> v[1];

    ll sw = 0;

    for (int i = 2; i <= N; i++) {
        ll wgt;
        cin >> wgt;
        w[i] = wgt - bw;
        sw += w[i];
        cin >> v[i];
    }
    dp[1][0][1] = v[1];

    for (int i = 1; i < N; i++) {
        for (int j = 0; j <= sw; j++) {
            for (int k = 0; k <= i; k++) {
                if (j >= w[i + 1] && i >= k + 1) {
                    dp[i + 1][j][k + 1] = max(dp[i][j - w[i + 1]][k] + v[i + 1], dp[i][j][k + 1]);
                } else if (j >= w[i + 1]) {
                    dp[i + 1][j][k + 1] = dp[i][j - w[i + 1]][k] + v[i + 1];
                } else if (i >= k + 1) {
                    dp[i + 1][j][k + 1] = dp[i][j][k + 1];
                }
            }
        }
    }

    ll ans = 0;
    for (int j = 0; j <= sw; j++) {
        for (int k = 1; k <= N; k++) {
            if (k * bw + j <= W) {
                ans = max(ans, dp[N][j][k]);
            }
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 16808
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //  repマクロ
#define leng(n) (int)(log10(n)+1)  //  桁数
using namespace std;

signed main() {
  int A, P;
  cin >> A >> P;
  cout << (3*A + P) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef pair<int, int> P;
const int INF = 1000000000;

char maze[100][101];
int N, M; 
int sx, sy;
int d[100][101];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int bfs(){
    queue<P> que;
    rep(i, N) rep(j, M) d[i][j] = INF; 
    que.push(P(sx, sy)); 
    d[sx][sy] = 0;
    while(que.size()){
        P p = que.front(); que.pop();
        rep(i, 4){
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if (0 <= nx && nx < N && 0 <= ny && ny < M && maze[nx][ny] != '#' && d[nx][ny] == INF){
                que.push(P(nx, ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
  int maxa =0;
  rep(i,N) rep(j,M) if(d[i][j]!=INF) maxa=max(maxa,d[i][j]);
  return maxa;
}

int main() {
  cin>>N>>M;
  rep(i,N) rep(j,M) cin>>maze[i][j];
  int res=0;
  rep(i,N) rep(j,M) if(maze[i][j]!='#'){
    sx = i, sy = j;
    res = max(bfs(),res);
   }
    printf("%d\n", res);

}

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


int main(){

    int res = 0;
    int sum=0;
    int n, m, c;
    cin >> n >> m >> c;

    int A[m];
    int B[m];
    for(int i=0; i<m; i++){
        cin >> B[i];
    }
    
    for(int i=0; i<n; i++){
        sum = c;
        for(int j=0; j<m; j++){
            cin >> A[j];
            sum += A[j]*B[j]; 
        }
        if(sum > 0)
            res++;
    }

    cout << res << endl;

}

Measured memory_bytes: 3592
// https://atcoder.jp/contests/abc106/tasks/abc106_d
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

// 二次元BIT
// source: https://iq.opengenus.org/2d-fenwick-tree/

// 2D fenwick tree for sub-matrix sum problem
class FenwickTree {
  private:
    // Matrix to store the tree
    std::vector<std::vector<int>> ft;

  public:
    // Function to get least significant bit
    inline int LSB(int x) { return x & (-x); }

    inline int query(int x, int y) {
        int sum = 0;
        for (int x_ = x; x_ > 0; x_ = x_ - LSB(x_)) {
            for (int y_ = y; y_ > 0; y_ = y_ - LSB(y_)) {
                sum = sum + ft[x_][y_];
            }
        }
        return sum;
    }

    inline int query(int x1, int y1, int x2, int y2) {
        return (query(x2, y2) - query(x1 - 1, y2) - query(x2, y1 - 1) +
                query(x1 - 1, y1 - 1));
    }

    inline void update(int x, int y, int value) {
        // also update matrix[x][y] if needed.
        for (int x_ = x; x_ < (int)ft.size(); x_ = x_ + LSB(x_)) {
            for (int y_ = y; y_ < (int)ft[0].size(); y_ = y_ + LSB(y_)) {
                ft[x_][y_] += value;
            }
        }
    }

    FenwickTree(std::vector<std::vector<int>> matrix) {
        // 引用元のコードはn, mが逆転してバグっているので修正
        int n = matrix.size();
        // matrix must not be empty.
        int m = matrix[0].size();
        // Initialize matrix ft
        ft.assign(n + 1, std::vector<int>(m + 1, 0));
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j)
                update(i + 1, j + 1, matrix[i][j]);
        }
    }

    FenwickTree(int h, int w) { ft.assign(h + 1, std::vector<int>(w + 1, 0)); }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M, Q;
    cin >> N >> M >> Q;
    FenwickTree ft(N, N);
    REP(i, M) {
        int l, r;
        cin >> l >> r;
        ft.update(l, r, 1);
    }
    while (Q--) {
        int l, r;
        cin >> l >> r;
        cout << ft.query(l, l, r, r) << "\n";
    }

    return 0;
}


Measured memory_bytes: 4224
INF = 1000
N = int(input())
h = list(map(lambda x: int(x), input().split()))
# DP 配列全体を「DP の種類に応じた初期値」で初期化
# dp[i] はノードiにたどり着くまでの最小コスト
dp = [INF for _ in range(N)]

# 初期条件を入力
dp[0] = 0
dp[1] = abs(h[0] - h[1])

# ループを回す
for i in range(0, N - 2):
    dp[i + 2] = min(dp[i + 1] + abs(h[i + 2] - h[i + 1]), dp[i] + abs(h[i + 2] - h[i]))

# テーブルから解を得て出力
print(dp[N - 1])


Measured memory_bytes: 13924
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int kuku[10][10];
    int i,j;
    for(i=1;i<=9;i++){
        for(j=1;j<=9;j++){
            kuku[i][j] = i*j;
        }
    }
    for(i=1;i<=9;i++){
        for(j=1;j<=9;j++){
            if(n == kuku[i][j]){
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
    return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  double n,k;
  cin>>n>>k;
  double ans = 0.0;
  for(int i=1;i<=n;++i){
    double x = i;
    double tmp = 1.0/n;
    while(x<k){x*=2.0;tmp/=2.0;}
    ans += tmp;
  }
  cout<<fixed<<setprecision(10);
  cout<<ans<<endl;

}

Measured memory_bytes: 3720
x=int(input())
if x==1000:
  print(1000)
  exit()
l=[1]
for i in range(2,32):
  k=2
  while i**k<=1000:
    l.append(i**k)
    k+=1
l=sorted(l)
for i in range(len(l)-1):
  if l[i]<=x<l[i+1]:
    print(l[i])
    exit()
print(961)

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
char alpha1[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};


int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(){
    int n; cin >> n;
    string s; cin >> s;
    REP(i, 0, s.size()){
        int k = s[i]-'A';
        cout << alpha1[(k+n)%26];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000
const int mod = INF+7;

int main(){
  char buf[1024];
  int N,M;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d %d", &N, &M);

  if(M==1){
    printf("%d\n", 0);
  }
  else{
    printf("%d\n", N-M);
  }

  return 0;

}


Measured memory_bytes: 128
n,m=map(int,input().split())
x=list(map(int,input().split()))
x=sorted(x)
sub=[]
for i in range(len(x)-1):
	sub.append(x[i+1]-x[i])
sub=sorted(sub)
if n==1:
	print(sum(sub))
else:
	print(sum(sub[:-(n-1)]))

Measured memory_bytes: 13964