akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main()
{
   int total ,x ,y, a, b ,c ;
   a = 300000;
   b = 200000;
   c = 100000;
scanf("%d",&x);  
    if(x==1){
        x = a;
    }
    else if(x==2){
        x= b;
    }
    else if(x==3){
        x = c;
    }else {
        x=0;
    }
    scanf("%d",&y); 
if(y==1){
        y= a;
    }
    else if(y==2){
        y= b;
    }
     else if(y==3){
        y= c;
    }
    else{
        y=0;
    }
    if(x==a && y ==a) {
        total = (a*2)+400000;
    }
    else{
        total= x+y;
    }
   printf("%d", total);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef  long long   ll;
typedef  long double ld;
#define ceil(n, m) ((n / m) + ( n % m ? 1 : 0))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
int n, weight;
vector<ll> w, v;
vector<vector<ll>> dp(107, vector<ll>(1e5 + 7, -1));
ll solve(int idx, int sum) {
	if (sum > weight)
		return -1e18;
	if (idx == n)
		return 0;
	ll& ret = dp[idx][sum];
	if (~ret)
		return ret;
	ll p1 = solve(idx + 1, sum);
	ll p2 = v[idx] + solve(idx + 1, sum + w[idx]);
	return ret = max(p1, p2);
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin);
	cin >> n >> weight;
	w = vector<ll>(n);
	v = vector<ll>(n);
	dp = vector<vector<ll>>(n, vector<ll>(1e5 + 7, -1));
	for (int i = 0; i < n; ++i)
		cin >> w[i] >> v[i];
	cout << solve(0, 0);
	
	


}


Measured memory_bytes: 166112
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
  string S;
  cin >> S;
  int L=S.length();
  lint pena=0,ans=0;
  rep(i,L) if(S[i]=='W') ans+=i-pena,pena++;
  cout << ans << endl;
}

Measured memory_bytes: 720
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int n,q,t[500],s[10000],cnt=0;
  cin>>n;
  for(int i=0;i<n;i++)cin>>s[i];
  cin>>q;
  for(int i=0;i<n;i++)cin>>t[i];
  for(int i=0;i<q;i++){
    for(int j=0;j<n;j++){
      if(s[j]==t[i]){
	cnt++;
	break;
      }
    }
  }
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 3108
import java.io.*;
import java.util.*;
class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String[] lo = reader.readLine().split(" ");
		int n = Integer.parseInt(lo[0]);
		int m = Integer.parseInt(lo[1]);
		int k = Integer.parseInt(lo[2]);
		int[] As = Arrays.stream(reader.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		int[] Bs = Arrays.stream(reader.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		long[] psumA = new long[n+1];
		long[] psumB = new long[m+1];
		psumA[0] = 0;
		psumB[0] = 0;
		for(int i = 1;i<n+1;i++) psumA[i] = psumA[i-1]+As[i-1];
		for(int i = 1;i<m+1;i++) psumB[i] = psumB[i-1]+Bs[i-1];
		int j = m;
		int res = 0;
		for(int i = 0;i<n+1;i++){
			if(psumA[i]>k) break;
			while(j>=0 && psumB[j]>k-psumA[i]){
				j--;
			}
			if(j>=0 && psumB[j] <= k-psumA[i]) res = Math.max(res,i+j);
			//if(j<0 && (k-psumA[i])>=0) res= Math.max(res,i+1);
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 77792
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };
LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)

// ---- ----

template<typename T> ostream & operator<<(ostream & os, vector<T> const & v) {
	inc(i, SI(v)) { os << (i == 0 ? "" : " ") << v[i]; }
	return os;
}

int main() {
	int n, k, s;
	cin >> n >> k >> s;
	
	vector<int> a(n);
	inc(i, n) { a[i] = (i < k ? s : (s <= n ? n + 1 : 1)); }
	
	cout << a << endl;
	
	return 0;
}


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

int main(void){
    int n, k, m;
    int count = 0;
    scanf("%d%d", &n, &k);

    for(int i = 0; i <= n; i++){
        m = pow(k, i);
        if((n - m) >= 0){
            count++;
        }else{
            break;
        }
    }

    printf("%d", count);
}

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

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

const long long INF = 1LL << 60;

int main ()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i=0;i<n;i++){
        cin >> v.at(i);
    }
    for (int i=0;i<n;i++){
    
        if(v.at(i)%2==0 && v.at(i)%3!=0 ){
            if(v.at(i)%5!=0){
        cout << "DENIED"<< endl; return 0;
            }
        }
        
    }
    cout << "APPROVED"<< endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std; 
int main(int argc,char const* argv[])
{
  string s;
  string t;
  string ans;
  int i,j,k,m,n,maxmatch=0,smatch=1000,rmatch=0;
  bool check=false;
  cin >> s;
  cin >> t;
  m=s.size();
  n=t.size();
  if(n>m)
    {
      cout << "UNRESTORABLE" <<endl;
      return 0;
    }
  for(k=0;k<=m-n;k++)
    {
      j=m-1;
      check=true;
	for(i=n-1;i>=0;i--)
	  { 
	    // cout << t[i] << " " << s[j-k] << endl;
	    if(t[i] != s[j-k] && s[j-k] != '?')
	      {
		check=false;
	      }
	    j--;
	  }
	if(check == true)
	  {
	    smatch=m-k-1;
	    if(maxmatch<=smatch) maxmatch=smatch;
	    // cout << smatch;
	  }
    }
  if(smatch==1000)
    {
      cout << "UNRESTORABLE" <<endl;
      return 0;
    } 
  j=0;
  for(i=maxmatch;i>maxmatch-n;i--)
    {
      s[i]=t[n-1-j];
      j++;
    }
  for(j=0;j<m;j++)
    {
      if(s[j]=='?') s[j]='a';
    }
  for(j=0;j<m;j++)
    {
      cout << s[j];
    }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(llint a, llint b) {
	return a > b;
}

int main() {
	llint n, p;
	cin >> n >> p;
	for (llint i = pow(p, max(0.5,(double)1 / n)); i >= 1 ; i--) {
		if (p % (llint)pow(i, (double)n) == 0) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
    
    ll h,w,n,i,s=0,ans=0;
    cin>>h>>w>>n;
    if(h<w) swap(h,w);
    while(s<n)
    {
    	s += h;
    	ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+1;
int n,a[N],tag4,tag2;
int main()
{
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i];
	for(int i=1;i<=n;++i)
	if(a[i]%4==0)tag4++;
	else if(a[i]%2==0)	tag2++;
	if(tag4*2+max(tag2-1,0)>=n-1)cout<<"Yes";
	else	cout<<"No";
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

void solve() {
    int n, k;
    cin >> n >> k;

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

    vector<int> dp(n+1);
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);

    for (int i = 2; i < n; i++) {
        int mn = dp[i - 1] + abs(h[i - 1] - h[i]);
        for (int j = 2; i >= j && j <= k; j++) {
            mn = min(mn, dp[i - j] + abs(h[i - j] - h[i]));
        }
        dp[i] = mn;
        assert(true);
    }

    cout << dp[n-1];
}


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

Measured memory_bytes: 1024
def myAnswer(N:int,S:list) -> int:
   ans = []
   for s in S:
      if(s % 10 != 0):
         ans.append(s)
   ans.sort()
   ans = list(set(ans))
   total = sum(S)
   if(total % 10 == 0):
      if(ans != []):
         return total - ans[0]
      else:
         return 0
   else:
      return total

def modelAnswer():
   return
def main():
   N = int(input())
   S = [int(input()) for _ in range(N)]
   print(myAnswer(N,S[:]))
if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IMS
import Data.Bool (bool)
import Data.Tuple (swap)
import qualified Data.Vector.Unboxed as VU
import Data.List (intercalate)

main :: IO ()
main = do
  [n, m, k] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  abs <- sequence . replicate m $ unsafeListToPair . map (pred . unsafeTextToInt) . T.words <$> T.getLine :: IO [(Int, Int)]
  let
    (u, v) = foldl step (IMS.empty, IMS.empty) abs :: (IntMap Int, IntMap Int)
      where
        step uv (i, j) = fst $ unite i j uv
    v0 = VU.generate n (\i -> IMS.findWithDefault 0 (snd $ root i u) v) :: VU.Vector Int
    v1 = VU.accum (const . pred) v0 . concatMap (\(i, j) -> [(i, ()), (j, ())]) $ abs :: VU.Vector Int
  cds <- sequence . replicate k $ unsafeListToPair . map (pred . unsafeTextToInt) . T.words <$> T.getLine :: IO [(Int, Int)]
  let
    v2 = VU.accum (const . pred) v1 . concatMap (\(i, j) -> bool [] [(i, ()), (j, ())] (snd $ isSame i j u)) $ cds :: VU.Vector Int
  putStrLn . intercalate " " . map show . VU.toList $ v2

type UF = IntMap Int

parent :: Int -> UF -> Maybe Int
parent = IMS.lookup

root :: Int -> UF -> (UF, Int)
root i u = maybe (u, i) (\j -> let (u', j') = root j u in (bool (IMS.insert i j' u') u (j' == j), j')) (parent i u)

unite :: Int -> Int -> (UF, IntMap Int) -> ((UF, IntMap Int), ())
unite i j (u, v) | i' == j'  = ((u'', v), ())
                 | otherwise = ((IMS.insert j' i' u'', IMS.alter (Just . succ . ((IMS.findWithDefault 0 j' v) +) . maybe 0 id) i' v), ())
  where
    (u', i') = root i u
    (u'', j') = root j u'

isSame :: Int -> Int -> UF -> (UF, Bool)
isSame i j u = (u'', i' == j')
  where
    (u', i') = root i u
    (u'', j') = root j u'

unsafeListToPair :: [Int] -> (Int, Int)
unsafeListToPair [x, y] = (x, y)
{-# INLINE unsafeListToPair #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n, r; cin >> n >> r;
    cout << r + 100 * max(0, (10 - n)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define OK puts("OK");
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define all(s) s.begin(), s.end()
#define allr(s) s.rbegin(), s.rend()
#define rep(i,n) for (i=0;i<(n);++i)
#define rep1(i,n) for (i=1;i<=(n);++i)
#define ret return
#define scan1(a) scanf("%lld",&(a));
#define scan2(a,b) scanf("%lld %lld",&(a),&(b));
#define scan3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c));
#define nemeshay ios::sync_with_stdio(0),cin.tie(0);
const int INF=1e9+7,N=2e5+12;
int dp[N],q[N];
int main(){
    int n,i,j,k;
    scan1(n)
    rep1(i,n)
        scan1(q[i])
    dp[2] = abs(q[2]-q[1]);
    for (i=3;i<=n;++i){
        dp[i] = min(dp[i-1] + abs(q[i]-q[i-1]),dp[i-2] + abs(q[i]-q[i-2]));
    }
    cout <<dp[n];
}









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

int main() {
  int n, m;
  cin >> n >> m;
  string ans(n, 'a');
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (ans[s - 1] != 'a' && ans[s - 1] != '0' + c) {
      cout << -1 << endl;
      return 0;
    }
    ans[s - 1] = '0' + c;
  }
  if (ans[0] == '0' && n > 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < ans.size(); i++) {
    if (ans[i] == 'a')
      ans[i] = (i == 0 && n > 1 ? '1' : '0');
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
macro_rules! get {
    (Vec<$t:ty>) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (N, K) = get!(usize, i32);
    let (A, B): (Vec<_>, Vec<_>) = get!(i32, usize; N).into_iter().unzip();

    // 桁DPにより解を求める
    let L = 30;
    let ans = (0..(L + 1)).map(
        |k|
        {
            (0..N).filter(
                |&i|
                {
                    let a = A[i];
                    let b = B[i];
                    (0..k).all(|i| ((a >> (L - i - 1)) & 1) <= ((K >> (L - i - 1)) & 1)) &&
                    (k == L || (a >> (L - k - 1) & 1) == 0) &&
                    (k == L || (K >> (L - k - 1) & 1) == 1)
                }
            )
            .map(|i| B[i])
            .sum::<usize>()
        }
    )
    .max()
    .unwrap();

    println!("{}", ans);
}


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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;

typedef long long ll;

int main(){

    int n;

    cin >> n;

    int ans = 0;

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

        int count = 0;
        for(int j = 1; j <= i; j++){
            if(i % j == 0) count++;
        }

        if(count == 8) ans++;

    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())

ans = [0]*(10**7)
for x in range(1,101):
  for y in range(1,101):
    for z in range(1,101):      
      tmp = x**2 + y**2 + z**2 + x*y + y*z + z*x
      ans[tmp] += 1
  
for i in range(1,n+1):
  print(ans[i])

Measured memory_bytes: 146492
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)

int main(){
	int N,K; cin>>N>>K;
	// vi A(N);
	// rp(i,0,N)cin>>A[i];
	vi C(N+1);
	rp(i,0,N){
		int a; cin>>a;
		C[a]++;
	}
	// for(auto e:C)cout<<e<<" ";puts("");//
	sort(allr(C));
	// for(auto e:C)cout<<e<<" ";puts("");//
	int removecount = 0;
	rp(i, K, N+1){
		if(C[i]==0) break;
		removecount += C[i];
	}
	ote(removecount);
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
#define VI vector<int>
#define VL vector<LL>
#define VII vector< vector<int> >
#define VLL vector< vector<LL> >
#define VS  vector<string>
#define VSS vector< vector<string> >
#define PII pair<int,int>
#define PIS pair<int,string>
#define PSI pair<string,int>
#define PLL pair<LL,LL>
const LL MOD = 1000000007;
const LL INF = 1e16;
LL facctorialMethod(int k);
int main(){
    LL n,count_comb;
    cin >> n;
    count_comb = 0;
    for(int i = 1; i <= (n-1); i++) {
        for(int j = 1; i*j <= (n-1); j++) {
            count_comb++;
        }
    }
//    cout << "count_comb :" << count_comb << endl;
    cout << count_comb << endl;
}

LL facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i){
        sum *= i;
    }
    return sum;
}


Measured memory_bytes: 3632
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

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

ll gcd(ll a, ll b, ll c) {
	return gcd(gcd(a, b), c);
}

int main() {
	int K; cin >> K;
	ll res = 0;
	for (int a = 1; a <= K; ++a)
		for (int b = 1; b <= K; ++b)
			for (int c = 1; c <= K; ++c)
				res += gcd(a, b, c);
	cout << res << endl;
	return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int cnt[1005];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; cin >> n;
	rep(i, 1, n + 1) {
		int t = i;
		rep(j, 2, t + 1) while (t % j == 0) t /= j, cnt[j]++;
	}
	ll ans = 1;
	const ll mod = 1000000007;
	rep(i, 0, 1005) ans = ans * (cnt[i] + 1) % mod;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#define MAX 15
using namespace std;

int main(){
    char s[MAX+1];
    int count,i;
    cin >> s;
    for(i=0;i<MAX && s[i] != '\0'; i++){
        if( s[i] == 'o' )
            count++;
    }
    if( count + ( MAX - strlen(s) ) >= 8){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

string C[200];

int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < 2 * H; i += 2) {
    cin >> C[i];
    C[i + 1] = C[i];
  }
  for (int i = 0; i < 2 * H; ++i) {
    printf("%s\n", C[i].c_str());
  }
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
signed main(){
  int n,c;
  cin>>n>>c;
  int a[n],b[n];
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n;i++) cin>>b[i];
  //for(int i=0;i<n;i++) assert(a[i]==b[i]);
  int po[505][505];
  int im[505][505];
  for(int i=0;i<500;i++){
    po[i][0]=1;
    for(int j=0;j<500;j++)
      po[i][j+1]=(po[i][j]*i)%MOD;
  }
  for(int i=0;i<500;i++){
    im[0][i]=0;
    for(int j=0;j<500;j++)
      im[j+1][i]=(im[j][i]+po[j][i])%MOD;
  }
  //puts("OK");
  //cout<<im[n][c]<<endl;
  int dp[n+1][c+1];
  memset(dp,0,sizeof(dp));
  dp[0][0]=1;
  for(int i=0;i<n;i++){
    for(int j=0;j<=c;j++){
      for(int k=j;k<=c;k++){
	//cout<<a[i]<<":"<<((im[b[i]+1][k-j]+MOD-im[a[i]][k-j])%MOD)<<endl;
	(dp[i+1][k]+=(dp[i][j]*((im[b[i]+1][k-j]+MOD-im[a[i]][k-j])%MOD))%MOD)%=MOD;
      }
    }
  }
  cout<<dp[n][c]<<endl;
  return 0;
}


Measured memory_bytes: 5504
wholeString = input()
firstSub = wholeString[0:int((len(wholeString)-1)/2)]
secondSub = wholeString[int(((len(wholeString)+3)/2)-1):]

if len(wholeString) % 2 == 0 or len(wholeString) < 3 or len(wholeString) > 99:
  print("No")
if firstSub == firstSub[::-1] and secondSub == secondSub[::-1] and wholeString == wholeString[::-1]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,n;
	scanf("%d %d %d",&a,&b,&n);
	if(a+b>=n)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String o = sc.next();
		String e = sc.next();
		int O = o.length();
		int E = e.length();
		for (int i = 0; i < O; i++) {
			if (i < O) {
				System.out.print(o.charAt(i));
			}
			if (i < E) {
				System.out.print(e.charAt(i));
			}
		}
	}
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair<long long ,long long> ii; 	

ll mod = 1e9+7;

ll power(ll x, ll y) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % mod;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % mod; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % mod;   
    } 
    return res; 
} 
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll x,y;
	cin >> x >> y;
	if ((2*y-x)%3 == 0 && (2*x-y)%3 == 0){
		ll a = (2*y-x)/3;
		ll b = (2*x-y)/3;
		if (a < 0){
			cout << 0 << endl;
			return 0;
		}
		if (b < 0){
			cout << 0 << endl;
			return 0;
		}
		ll k = 1;
		ll p = 1;
		ll q = 1;
		for (int z=1;z<=(a+b);z++){
			k *= z;
			k %= mod;
			if (z == a)p = k;
			if (z == b)q = k;
		}
		k = (k*power(p,mod-2))%mod;
		k = (k*power(q,mod-2))%mod;
		cout << k%mod << endl;
	} else {
		cout << 0 << endl;
	}
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

void shortestPath(const vector<vector<int> >& edges, int start, vector<int>& dist)
{
    int n = edges.size();
    dist.assign(n, INT_MAX);
    dist[start] = 0;
    queue<int> q;
    q.push(start);

    while(!q.empty()){
        int v = q.front();
        q.pop();
        for(unsigned i=0; i<edges[v].size(); ++i){
            int u = edges[v][i];
            if(dist[u] == INT_MAX){
                dist[u] = dist[v] + 1;
                q.push(u);
            }
        }
    }
}

void shortestPath(const vector<vector<int> >& edges, vector<vector<int> >& dist)
{
    dist.resize(edges.size());
    for(unsigned i=0; i<edges.size(); ++i)
        shortestPath(edges, i, dist[i]);
}

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n), b(n);
    vector<vector<int> > tree(n);
    for(int i=0; i<n-1; ++i){
        cin >> a[i] >> b[i];
        -- a[i];
        -- b[i];
        tree[a[i]].push_back(b[i]);
        tree[b[i]].push_back(a[i]);
    }

    vector<vector<int> > dist;
    shortestPath(tree, dist);

    int ans = INT_MAX;
    if(k % 2 == 0){
        for(int i=0; i<n; ++i){
            int cnt = 0;
            for(int j=0; j<n; ++j){
                if(dist[i][j] > k / 2)
                    ++ cnt;
            }
            ans = min(ans, cnt);
        }
    }
    else{
        for(int i=0; i<n-1; ++i){
            int cnt = 0;
            for(int j=0; j<n; ++j){
                if(min(dist[a[i]][j], dist[b[i]][j]) > k / 2)
                    ++ cnt;
            }
            ans = min(ans, cnt);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 16128
import sys
import math
def get_array(): return list(map(int,sys.stdin.readline().strip().split()))
def get_ints(): return map(int,sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
a,b,c,d=get_ints()
if a<d:
    ans1=a 
    d=d-a 
    if b<d:
        ans2=b 
        d=d-b
        if c<d:
            ans3=c 
            d=d-c 
            ans=ans1+ans2-ans3
        else:
            ans=ans1-d
    elif b>=d:
        ans=ans1
elif a>=d:
    ans=d
print(ans)
    
    

Measured memory_bytes: 62104
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int H = scan.nextInt();
        int W = scan.nextInt();
        int K = scan.nextInt();
        char[][] map = new char[H][W];
        for (int i = 0; i < H; i++) {
            String s = scan.next();
            map[i] = s.toCharArray();
        }
        int[][] ans = solve(H, W, K, map);
        for (int i = 0; i < H; i++) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < W; j++) {
                sb.append(ans[i][j]);
                sb.append(" ");
            }
            System.out.println(sb.substring(0, sb.length()-1));
        }
    }
    private int[][] solve(int H, int W, int K, char[][] map) {
        int[] Y = new int[H];
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (map[i][j] == '#') {
                    Y[i] += 1;
                }
            }
        }
        int[] sY = new int[H+1];
        for (int i = 0; i < H; i++) {
            sY[i+1] = sY[i] + Y[i];
        }
        for (int i = H; 0 < i; i--) {
            if (0 < sY[i]) {
                continue;
            }
            sY[i] = sY[i+1];
        }
        int[][] result = new int[H][W];
        int cnt = 0;
        int prev = 0;
        int prevS = 0;
        for (int i = 0; i < H - 1; i++) {
            if (sY[i+1] == sY[i+2]) {
                continue;
            }
            result = sub(result, W, map, prev, i, cnt+1);
            cnt += sY[i+1]-prevS;
            prev = i + 1;
            prevS = sY[i+1];
        }
        if (cnt < K) {
            result = sub(result, W, map, prev, H-1, cnt+1);
        }
        return result;
    }
    private int[][] sub(int[][] result, int W, char[][] map, int from, int to, int index) {
        int[] X = new int[W];
        for (int i = 0; i < W; i++) {
            for (int j = from; j <= to; j++) {
                if (map[j][i] == '#') {
                    X[i] += 1;
                }
            }
        }
        int[] sX = new int[W+1];
        for (int i = 0; i < W; i++) {
            sX[i+1] = sX[i] + X[i];
        }
        for (int i = W; 0 < i; i--) {
            if (0 < sX[i]) {
                continue;
            }
            sX[i] = sX[i+1];
        }
        int target = sX[1];
        for (int i = 0; i < W; i++) {
            if (target != sX[i+1]) {
                index += 1;
                target = sX[i+1];
            }
            for (int j = from; j <= to; j++) {
                result[j][i] = index;
            }
        }
        return result;
    }
}


Measured memory_bytes: 34040
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
int n,k,a[200005];ll ans;
int main()
{
    scanf("%d%d",&n,&k);
    rep(i,1,n) scanf("%d",a+i);
    sort(a+1,a+n+1);reverse(a+1,a+n+1);
    rep(i,k+1,n) ans+=a[i];
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))

def calc():
    dp = [[0] * n for _ in range(n)]
    for i in range(n):
        dp[i][i] = a[i]

    for i in range(n - 2, -1, -1):
        for j in range(i + 1, n):
            dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1])
    return dp

dp = calc()
print(dp[0][n - 1])

Measured memory_bytes: 111708
// C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>
#include <sstream>
#include <unistd.h>

#define ll long long
#define Int int
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)
#define rep(n) for(int x = 0; x < n; x++)
#define span(a,x,y) a.begin()+x,a.begin()+y
#define span_all(a) a.begin(),a.end()
#define len(x) (x.size())
#define last(x) (*(x.end()-1))

using namespace std;

#define EPS 0.0000000001
#define MOD 1000000007

class Vector2 {
public:
  double x, y;
  
  Vector2(double x = 0, double y = 0): x(x), y(y) {}
  
  Vector2 operator + (Vector2 v) { return Vector2(x + v.x, y + v.y); }
  Vector2 operator - (Vector2 v) { return Vector2(x - v.x, y - v.y); }
  Vector2 operator * (double k) { return Vector2(x * k, y * k); }
  Vector2 operator / (double k) { return Vector2(x / k, y / k); }
  
  double length() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  double dot (Vector2 v) { return x * v.x + y * v.y; }
  double cross (Vector2 v) { return x * v.y - y * v.x; }
  
  bool operator < (const Vector2 &v) const {
    return x != v.x ? x < v.x : y < v.y;
  }
  
  bool operator == (const Vector2 &v) const {
    return fabs(x - v.x) < EPS && fabs(y - v.y) < EPS;
  }
};

ostream & operator << (ostream & out, Vector2 const & v) { 
  out<< "Vector2(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Vector2 & v) { 
  double x, y;
  in >> x;
  in >> y;
  v.x = x;
  v.y = y;
  return in;
}

#define MAX_H 1000
#define INFTY (MAX_H*MAX_H)

Int H, W;
char c_;
vector<bool> M(MAX_H * MAX_H, false);
vector<Int> dist(MAX_H * MAX_H, INFTY);
vector<Vector2> starts;

Int at(Int x, Int y) {
  return y*W+x;
}

Int at(Vector2 &v) {
  return v.y*W+v.x;
}

bool valid(Vector2 &v) {
  if (v.x < 0 || v.x >= W || v.y < 0 || v.y >= H) return false;
  if (dist.at(at(v)) < INFTY) return false;
  return true;
}

void input() {
  cin >> H >> W;
  loop(h,0,H) {
    loop(w,0,W) {
      cin >> c_;
      if (c_ == '#') {
        M[at(w, h)] = true;
        starts.push_back(Vector2(w, h));
      }
    }
  }
  M.resize(H * W);
  dist.resize(H * W);
}

vector<Vector2> udlr = { {0, 1}, {0, -1}, {-1, 0}, {1, 0} };

Int bfs() {
  Int counter = starts.size();
  if (counter >= H*W) return 0;

  queue<Vector2> Q;
  for (auto s: starts) {
    Q.push(s);
    dist[at(s)] = 0;
  }

  while (Q.size()) {
    Vector2 u = Q.front(); Q.pop();
    for (auto dxdy: udlr) {
      Vector2 next = u + dxdy;
      if (!valid(next)) continue;
      dist[at(next)] = dist.at(at(u)) + 1;
      counter++;
      if (counter >= H*W) {
        return dist.at(at(next));
      }
      Q.push(next);
    }
  }

  return -1;
}

void solve() {
  cout << bfs() << endl;
}

int main(void) {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 24932
# ------ combination -------
N, MOD = 10**5 + 1, 10**9 + 7
fc, ifc = [0] * (N+1), [0] * (N+1)

def power(n, a):
    res, exp = 1, n
    while(a):
        if a & 1:
            res = res * exp % MOD
        exp = exp * exp % MOD
        a = a >> 1
    return res

fc[0] = 1
for i in range(1, N+1):
    fc[i] = fc[i-1] * i % MOD
ifc[N] = power(fc[N], MOD-2)
for i in range(N-1, -1, -1):
    ifc[i] = ifc[i+1] * (i+1) % MOD

def Comb(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    return fc[n] * ifc[r] % MOD * ifc[n-r] % MOD

# --------------------------

n = int(input())
a = list(map(int, input().split()))

num = [-1] * (n+1)
l = r = -1
for i in range(len(a)):
    if num[a[i]] != -1:
        l, r = num[a[i]], i
        break
    num[a[i]] = i

for k in range(1, len(a)+1):
    ans = Comb(len(a), k) - Comb(l+len(a)-r-1, k-1)
    while ans < 0:
        ans += MOD
    print(ans)

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

int main(){
    ll x;
    cin >> x;

    if(x % 11 > 6){
        cout << 2 * (x / 11) + 2 << endl;
    }else if(x % 11 > 0){
        cout << 2 * (x / 11) + 1 << endl;
    }else{
        cout << 2 * (x / 11) << endl;
    }

    return 0;

}

Measured memory_bytes: 256
N, M = [int(s) for s in input().split()]
A = []
for _ in range(M):
    A.append(int(input()))
A = set(A)

counts = [0] * (N + 1)
for i in range(N + 1):
    if i == 0:
        counts[i] = 1
    elif i == 1:
        if i not in A:
            counts[i] = 1
    else:
        if i not in A:
            for j in [i - 2, i - 1]:
                if j not in A:
                    counts[i] += counts[j]
                    counts[i] %= 1000000007

print(counts[N])


Measured memory_bytes: 13192
#include <tuple>
#include <vector>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
using ll	= long long;
using ull	= unsigned long long;
using ld	= long double;
using pii	= pair<int,int>;
using pll	= pair<ll,ll>;
using vi	= vector<int>;
using vb	= vector<bool>;
using vc	= vector<char>;
using vvi	= vector<vi>;
using vvb	= vector<vb>;
using vpii	= vector<pii>;
using vpll	= vector<pll>;
using vll	= vector<ll>;
using vull	= vector<ull>;
using vvll	= vector<vll>;
#define ever (;;)
#define f first
#define s second
#define pb emplace_back
#define sz size()
#define graph vector<vertex>
#define deg(X) (int)G[X].e.size()
#define INF 1234567890
#define INFll 2000000000000000000
#define maxe(X, Y) if((Y) > (X)) (X) = (Y)
#define mine(X, Y) if((Y) < (X)) (X) = (Y)
#define rep(i, begin, end) for(__typeof(end) i = (begin); i < (end); ++i)
#define repr(i, begin, end) for(__typeof(end) i = (begin)-1; i >= (end); --i)
#define bend(X) X.begin(), X.end()
pii operator+(const pii& A, const pii& B) { return {A.f+B.f, A.s+B.s}; }
pii operator-(const pii& A, const pii& B) { return {A.f-B.f, A.s-B.s}; }
pii operator-(const pii& A) { return {-A.f, -A.s}; }

//
// END OF DEFINES
//

constexpr ll mod = 1e9+7;
int n, m;
vvb T;
vvll DP;

bool in() {
	scanf("%d %d ", &n, &m);
	T.resize(n+1, vb(m+1));
	DP.resize(n+1, vll(m+1));
	rep(i, 1, n+1) {
		rep(j, 1, m+1) {
			char x = getchar_unlocked();
			if(x == '.')
				T[i][j] = 1;
			else if(x == '#')
				T[i][j] = 0;
			else
				return false;
		}
		getchar_unlocked();
	}
	T[1][1] = 0;
	
	return true;
}

ll solve() {
	DP[1][1] = 1;
	rep(i, 1, n+1) {
		rep(j, 1, m+1) {
			if(!T[i][j])
				continue;
			DP[i][j] = (DP[i][j-1] + DP[i-1][j])%mod;
		}
	}
	return DP[n][m];
	
	return -INF;
}

int main() {
	int noOfTests = 1;
	//scanf("%d", &noOfTests);
	
	while(noOfTests --> 0) {
		if(!in()) {
			printf("popsute wejscie\n");
			continue;
		}
		ll result = solve();
		if(result == ll(-'t'))
			printf("TAK\n");
		else if(result == ll(-'n'))
			printf("NIE\n");
		else if(result != -INF)
			printf("%lld\n", result);
	}
	
	return 0;
}


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

const int inf = 1e9;
const ll linf = 1e18;

class UnionFind
{
private:
    vector<int> par;
    vector<int> rank;
    vector<int> sz;
    int _count;

public:
    UnionFind(int n) : par(n), rank(n, 0), sz(n, 1), _count(n) {
        iota(par.begin(), par.end(), 0);
    }

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

    void unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return;

        _count--;
        if (rank[x] < rank[y]) {
            par[x] = y; sz[y] += sz[x];
        } else {
            par[y] = x; sz[x] += sz[y];
            if (rank[x] == rank[y]) rank[x]++;
        }
    }

    bool same(int x, int y) { return find(x) == find(y); }

    int size(int x) { return sz[find(x)]; }

    int count() { return _count; }
};

struct edge
{
    int u, v; ll cost;
};
bool operator<(const edge &lhs, const edge &rhs) { return lhs.cost < rhs.cost; };

int main()
{
    int V, E; cin >> V >> E;
    vector<edge> es(E);
    for (int i = 0; i < E; i++) cin >> es[i].u >> es[i].v >> es[i].cost;

    UnionFind uf(V);

    // kruskal法
    sort(es.begin(), es.end());
    ll ans = 0;
    for (auto &e: es) {
        if (!uf.same(e.u, e.v)) {
            uf.unite(e.u, e.v);
            ans += e.cost;
        }
    }

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


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

int main() {
    long long int n, c, x, v, x_ = 0, ans = 0;
    cin >> n >> c;
    long long int r[n+1] = {0}, l[n+1] = {0}, r_max[n+1] = {0}, l_max[n+1] = {0};
    vector<pair<long long int, long long int>> a;
    
    // 順方向累積和
    for(int i = 0; i < n; ++i) {
        cin >> x >> v;
        a.push_back(make_pair(x, v));
        r[i+1] = r[i] + v - (x - x_);
        ans = max(ans, r[i+1]);
        r_max[i+1] = max(r_max[i], r[i+1]);
        x_ = x;
    }
    
    // 逆方向累積和
    x_ = 0;
    for(int i = n; i > 0; --i) {
        l[i-1] += l[i] + a[i-1].second - (c - a[i-1].first - x_);
        ans = max(ans, l[i-1]);
        l_max[i-1] = max(l_max[i], l[i-1]);
        x_ = c - a[i-1].first;
    }

    // 順方向からの反転
    for(int i = 1; i < n; ++i) 
        ans = max(ans, r[i] + l_max[i] - a[i-1].first);        

    // 逆方向からの反転
    for(int i = n-1; i >= 0; --i) 
        ans = max(ans, l[i] + r_max[i] - (c - a[i].first));

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 5492
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;
queue<char>qu;
//priority_queue<int, vector<int>, greater<int> > que;
priority_queue<int> que;
int n,m,p,o;
int x;
char st;
int a[1005],b[1005];
int h;
int xx,yy;

int main()
{
	
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		que.push(x);
	}
	for(int i=1;i<=m;i++)
	{
	
	h+=que.top();
	que.pop();
}
	cout<<h<<endl;
	return 0;
}

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

int main()
{
  int H1, M1, H2, M2, K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  int total_minite;
  total_minite = 60*(H2-H1) + (M2 - M1);
  cout << total_minite - K << endl;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define sq(x) ((x)*(x))
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
int N,M;
int C[20];
int x[20010];
ll dp[20010][256];
int solve(){
    scanf("%d %d",&N,&M);
    if(N==0&&M==0)return 1;
    for(int i=0;i<M;i++)scanf("%d",&C[i]);
    for(int i=0;i<N;i++)scanf("%d",&x[i]);
    for(int i=0;i<=N;i++){
        for(int j=0;j<256;j++){
            dp[i][j]=LLINF;
        }
    }
    dp[0][128]=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<256;j++){
            if(dp[i][j]==LLINF)continue;
            for(int k=0;k<M;k++){
                int nxt = j+C[k];
                nxt = max(0,nxt);
                nxt = min(255,nxt);
                dp[i+1][nxt]=min(dp[i+1][nxt],(ll)(dp[i][j]+sq(abs(nxt-x[i]))));
            }
        }
    }
    ll ans = LLINF;
    for(int i=0;i<256;i++)ans = min(ans,dp[N][i]);
    cout << ans << endl;
    return 0;
}
int main(){
    while(1){
        if(solve())return 0;
    }
    return 0;
}

Measured memory_bytes: 43136
from collections import Counter
n = int(input())
a = Counter(list(map(int, input().split())))

ans = 0
for k, v in a.items():
    ans+=k*v

q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    if b in a:
        ans-=b*a[b]
        temp = a[b]
        a[b]=0

        ans+=c*temp
        a[c]+=temp
        print(ans)
    else:
        print(ans)


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

using namespace std;
typedef long long ll;
int n, k;
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> k;
	if( k == 1 || k == (2*n - 1))
		cout << "No" << endl;
	else{
		cout << "Yes" << endl;
		int cur = 1;
		for(int i = 0; i < n - 2;  i ++){
			if( cur == k - 1) cur = k + 2;
			cout << cur << endl;
			cur ++;
		}
		cout << k - 1 << endl << k << endl << k + 1 << endl;
		for(int i = 0; i < n - 2; i ++){
			if( cur == k - 1) cur = k + 2;
			cout << cur << endl;
			cur ++;
		}
	}
	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>

using namespace std;

int main() {
  int c[5][5],a1,a2,a3,b1,b2,b3;
  for(int i = 1; i <= 3; i++) {
    for(int j = 1; j <= 3; j++)
      cin >> c[i][j];
  }

  for(a1 = 0; a1 <= 100; a1++) {
    b1 = c[1][1] - a1;
    b2 = c[1][2] - a1;
    b3 = c[1][3] - a1;
    if(b1<0 & 100<b1) continue;
    if(b2<0 & 100<b2) continue;
    if(b3<0 & 100<b3) continue;
    
    if((c[2][1]-b1) == (c[2][2]-b2) & (c[2][2]-b2) == (c[2][3]-b3)) {
      if((c[3][1]-b1) == (c[3][2]-b2) & (c[3][2]-b2) == (c[3][3]-b3)) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  
  cout << "No" << endl;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define repd(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>; // グラフ型
using pint = pair<int, int>;

int main()
{
    string S;
    cin >> S;
    if (S[2] == S[3] & S[4] == S[5])
    {
        cout << "Yes" << endl;
    }
    else
    {
        /* code */
        cout << "No" << endl;
    }
}

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

bool isValid(vector<int> t){
    return t[0]%5==t[1]/12;
}

int calc(vector<int> t){
    return (t[0]/5)*60*60+t[1]*60+t[2];
}

void output(int t){
    cout<<setw(2);
    cout<<setfill('0');
    cout<<(t/3600)<<":";
    cout<<setw(2);
    cout<<setfill('0');
    cout<<(t/60%60)<<":";
    cout<<setw(2);
    cout<<setfill('0');
    cout<<(t%60);
}
int solve(int n){
    vector<vector<int>> t(n,vector<int>(3));
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>t[i][j];
        }
    }

    vector<vector<int>> cand(n);
    for(int i=0;i<n;i++){
        for(int k=0;k<60;k++){
            for(int j=0;j<3;j++) t[i][j]=(t[i][j]+1)%60;
            for(int j=0;j<6;j++){
                if(isValid(t[i])){
                    cand[i].push_back(calc(t[i]));
                    cand[i].push_back(calc(t[i])+12*60*60);
                }
                next_permutation(t[i].begin(),t[i].end());
            }
        }
        cand[i].push_back(1e8);
        sort(cand[i].begin(),cand[i].end());
    }
    pair<int,int> res={1e8,1e8};
    for(int i=0;i<24*60*60;i++){
        int till=0;
        for(int j=0;j<n;j++){
            till=max(till,*lower_bound(cand[j].begin(),cand[j].end(),i));
        }
        res=min(res,{till-i,i});
    }
    output(res.second);
    cout<<" ";
    output(res.first+res.second);
    cout<<endl;
}

int main(){
    int n;
    while(cin>>n,n){
        solve(n);
    }
    return 0;
}


Measured memory_bytes: 3124