akhauriyash/Code-Regression huggingface dataset:
{-# OPTIONS_GHC -O #-}

import Control.Monad
import Control.Monad.ST
import Data.List
import Control.Monad.Trans.State.Strict
import Data.Char (isSpace)
import Data.Maybe (fromJust,fromMaybe)
import qualified Data.ByteString.Lazy.Char8 as B

import Data.Array.ST
import Data.Array.Unboxed
type Dist s = STUArray s (Int,Int) Int

type Parser a = StateT B.ByteString Maybe a

parseInt :: Parser Int
parseInt = StateT (B.readInt . B.dropWhile isSpace)

parseInt2 :: Parser (Int,Int)
parseInt2 = liftM2 (,) parseInt parseInt

parseInt3 :: Parser (Int,Int,Int)
parseInt3 = liftM3 (,,) parseInt parseInt parseInt

parse :: Parser ((Int,Int), [(Int,Int,Int)])
parse = do
    (n,m)<-parseInt2
    rs<-replicateM m parseInt3
    return ((n,m),rs)

main=do
    ((n,m),rs)<-fromJust.evalStateT parse <$> B.getContents
    let da = wf n rs :: UArray (Int,Int) Int
    --
    print $ length $ filter (f n da) rs

f n da (a,b,c) = all (\s->s1 s /= s2 s) [1..n]
    where
        s1 s = da ! (s,a) + c
        s2 s = da ! (s,b)
--
wf::Int->[(Int,Int,Int)]->UArray (Int,Int) Int
wf n rs = runST $ do
    d <- newArray ((1,1),(n,n)) (maxBound`div`2) :: ST s (STUArray s (Int,Int) Int)
    forM_ [1..n] $ \v -> writeArray d (v,v) 0
    forM_ rs $ \(u,v,l) -> writeArray d (u,v) l >> writeArray d (v,u) l
    forM_ [(k,i,j)|k<-[1..n],i<-[1..n],j<-[1..n]] $ \(k,i,j) -> do
        dc <- readArray d (i,j)
        dn <- (+) <$> readArray d (i,k) <*> readArray d (k,j)
        when (dc > dn) $ writeArray d (i,j) dn
    freeze d


Measured memory_bytes: 1276
import java.util.*

fun main(args:Array<String>){
    val (n,x) = readLine()!!.split(" ").map{it.toInt()}
    val l = readLine()!!.split(" ").map{it.toInt()}
    var k = 0
    var ans = 1
    for(i in 0 until n){
        k += l[i]
        if(k > x) break
        ans++
    }
    println(ans)
}


Measured memory_bytes: 37900
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
	auto NMQ = readln.split.to!(int[]);
	auto N = NMQ[0], M = NMQ[1], Q = NMQ[2];
	int[4][] abcd;
	foreach (i; 0 .. Q) {
	    abcd ~= readln.split[0 .. 4].to!(int[4]);
	}
	int ans;
	foreach (A; A_s(N, M)) {
	    int tmp;
	    foreach (i; 0 .. Q) {
	        if (A[abcd[i][1]-1] - A[abcd[i][0]-1] == abcd[i][2]) tmp += abcd[i][3];
	    }
	    ans = max(ans, tmp);
	}
	writeln(ans);
}

int[][] A_s(int N, int M) {
    if (N == 1) {
        return [[1]];
    }
    auto Alist = A_s(N-1, M);
    int[][] result;
    
    foreach (As; Alist) {
        foreach (last; As[$-1] .. M+1) {
            result ~= (As~[last]);
        }
    }
    
    return result;
}

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

using namespace std;

vector<vector<pair<int, int>>> edges;
vector<int> colors;

void dfs(int cur) {
  auto& nexts = edges[cur];
  for (auto& next : nexts) {
    if (colors[next.first] == -1) {
      colors[next.first] = next.second ^ colors[cur];
      dfs(next.first);
    }
  }
}

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

  int N;
  cin >> N;

  edges.resize(N);
  for (int i = 1; i < N; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    edges[--u].emplace_back(--v, w % 2);
    edges[v].emplace_back(u, w % 2);
  }
  colors.resize(N, -1);
  colors[0] = 0;

  dfs(0);

  for (auto color : colors) {
    cout << color << endl;
  }
}


Measured memory_bytes: 7424
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_12_C: Single Source Shortest Path II

#include <algorithm>
#include <cstdio>
#include <queue>
#include <utility>
#include <vector>

using uint = unsigned int;

class Graph {
  using vc_t = std::pair<uint, uint>;
  std::vector<std::vector<vc_t>> g_;

public:
  Graph(const uint n) { g_.resize(n); }

  void push_to(const uint u, const uint v, const uint c)
  {
    g_[u].push_back(std::make_pair(v, c));
  }

  void dijkstra(uint* dist)
  {
    auto n = g_.size();
    const uint INFINIT = 100000*(n-1)+1;
    std::fill_n(dist, n, INFINIT);
    auto cmp = [](vc_t left, vc_t right) { return left.second > right.second; };
    std::priority_queue<vc_t, std::vector<vc_t>, decltype(cmp)> q(cmp);
    
    q.push(vc_t(0, 0));
    dist[0] = 0u;
    while (!q.empty()) {
      auto bvc = q.top();
      q.pop();
      auto v = bvc.first;
      auto c = bvc.second;
      if (dist[v] < c) {
        continue;
      }
      dist[v] = c;
      for (auto vc : g_[v]) {
        q.push(std::make_pair(vc.first, vc.second+c));
      }
    }
  }
};

int main()
{
  uint n;
  std::scanf("%u", &n);

  Graph g(n);

  uint u, k, v, c;
  for (auto i = 0u; i < n; ++i) {
    std::scanf("%u %u", &u, &k);
    for (auto j = 0u; j < k; ++j) {
      std::scanf("%u %u", &v, &c);
      g.push_to(u, v, c);
    }
  }

  uint dist[n];
  g.dijkstra(dist);
  for (auto i = 0u; i < n; ++i) {
    std::printf("%u %u\n", i, dist[i]);
  }
}

// eof

Measured memory_bytes: 15480
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a, b, c;
  cin >> a >> b >> c;
  
  char next = 'a';
  
  while (1) {
    if (next == 'a') {
      if (a.size() == 0) {
        cout << 'A' << endl;
        break;
      }
      next = a.at(0);
      a.erase(0, 1);
    }
    if (next == 'b') {
      if (b.size() == 0) {
        cout << 'B' << endl;
        break;
      }
      next = b.at(0);
      b.erase(0, 1);
    }
    if (next == 'c') {
      if (c.size() == 0) {
        cout << 'C' << endl;
        break;
      }
      next = c.at(0);
      c.erase(0, 1);
    }
  }
  
}

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

typedef long long int LLI;

LLI X;

int main() {
  scanf("%lld", &X);
  LLI sum = 0;
  for (LLI i=1; ; i++) {
    sum += i;
    if (sum >= X) {
      printf("%lld\n", i);
      break;
    }
  }
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N;
    cin >> N;

    map<ll, ll> mp;
    for(ll i = 0; i < N; i++){
        ll t; cin >> t;
        if(t >= 1 && t <= 399) mp[0]++;
        else if(t >= 400 && t <= 799) mp[1]++;
        else if(t >= 800 && t <= 1199) mp[2]++;
        else if(t >= 1200 && t <= 1599) mp[3]++;
        else if(t >= 1600 && t <= 1999) mp[4]++;
        else if(t >= 2000 && t <= 2399) mp[5]++;
        else if(t >= 2400 && t <= 2799) mp[6]++;
        else if(t >= 2800 && t <= 3199) mp[7]++;
        else if(t >= 3200) mp[8]++;
    }

    ll num = mp.size();
    ll red = mp[8];

    ll mn = num;
    if(red > 0) mn = max((ll)1, num-1);

    ll mx = num;
    if(red > 0) mx = mx-1+red;

    cout << mn << " " << mx << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,l,r) for(int i = (l),i##end = (r);i <= i##end;i++)
#define Fordown(i,r,l) for(int i = (r),i##end = (l);i >= i##end;i--)
#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long ll;

template <typename T> inline bool chkmin(T &x,T y) { return y < x ? x = y,1 : 0; }
template <typename T> inline bool chkmax(T &x,T y) { return x < y ? x = y,1 : 0; }

const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;

queue <int> Q;
int a[N],b[N],Va[N],Vb[N],fa[N],vis[N];
int e;

inline int read() {
	int x = 0,flag = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-')ch = getchar();
	if(ch == '-')flag = -1,ch = getchar();
	while(isdigit(ch))x = (x << 3) + (x << 1) + (ch - '0'),ch = getchar();
	return x * flag;
}

inline int find(int x) {
	return fa[x] == x ? x : fa[x] = find(fa[x]);
}

int main() {
	int n = read() + 1;
	For(i,1,n - 1) a[i] = read(),a[n] ^= a[i];
	For(i,1,n - 1) b[i] = read(),b[n] ^= b[i];

	For(i,1,n) Va[i] = a[i],Vb[i] = b[i];
	sort(Va + 1,Va + n + 1);
	sort(Vb + 1,Vb + n + 1);
	For(i,1,n) if(Va[i] != Vb[i]) return puts("-1"),0;
	int cnt = unique(Va + 1,Va + n + 1) - Va - 1;
	For(i,1,n) fa[i] = i;
	For(i,1,n) {
		a[i] = lower_bound(Va + 1,Va + cnt + 1,a[i]) - Va;
		b[i] = lower_bound(Va + 1,Va + cnt + 1,b[i]) - Va;
		int x = find(a[i]),y = find(b[i]);
		if(x == y) continue;
		fa[x] = y;
	}

	int ans = 0,sum = 0;
	For(i,1,n - 1) if(a[i] != b[i]) {
		ans++;
		vis[a[i]] = vis[b[i]] = true;
	}
	vis[a[n]] = vis[b[n]] = true;
	For(i,1,cnt) if(vis[i] && find(i) == i) sum++;

	printf("%d\n",ans + sum - 1);

	return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int k; std::cin >> k;
  if (k <= 9) {
    std::cout << k << "\n";
    return 0;
  }
  vector<vector<ll>> num(9);
  rep(i, 9) num[i].pb(i+1);
  k -= 9;
  while(1) {
    rep(i, 9) {
      vector<ll> tmp;
      for (auto &v : num[i]) {
        ll base = v % 10;
        if (base - 1 >= 0) tmp.pb(v*10+base-1), k--;
        tmp.pb(v*10+base), k--;
        if (base + 1 < 10) tmp.pb(v*10+base+1), k--;
      }
      if (k <= 0) {
        int sz = tmp.size()-1;
        int idx = sz + k;
        std::cout << tmp[idx] << "\n";
        return 0;
      }
      num[i] = tmp;
    }
  }
}


Measured memory_bytes: 1320
#include<cstdio>
#include<cstring>
#include<algorithm>
int a[60];

int main()
{
	int n;scanf("%d",&n);n++;
	for(int i=2;i<=n;i++)
		scanf("%d",&a[i]);
	std::sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
	{
		if(i&1)
			a[i]=24-a[i];
		if(a[i]==24)
			a[i]=0;
	}
	std::sort(a+1,a+n+1);
	int mx=2147483647;
	for(int i=2;i<=n;i++)
		mx=std::min(mx,a[i]-a[i-1]);
	printf("%d\n",mx);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef pair<int, int> P1;
typedef pair<int, pair<int, int> > P2;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };

int n,m;
int a[200005];
int v1[200005];
vector<int> v2[200005];

signed main(){
    int ans=INF;
    cin>>n>>m;
    for(int i=0;i<n;++i)cin>>a[i];
    for(int i=0;i<n;++i){
        if(i){
            v2[a[i]].PB(i);
        }
    }
    for(int i=0;i<n-1;++i){
        int l = a[i],r = a[i+1];
        if(l>r)r+=m;
        v1[l+2]++;
        v1[r+1]--;
    }
    for(int i=1;i<=2*m;++i){
        v1[i]+=v1[i-1];
        //cout<<v1[i]<<endl;
    }
    int tmp;
    int x = 1;
    int init=0;
    for(int i=1;i<n;++i){
        if(a[i]==x)init++;
        else if(a[i-1]<a[i]){
            if(a[i-1]<x-1&&a[i]>x)init+=1+(a[i]+m-x)%m;
            else init+=(a[i]+m-a[i-1])%m;
        }
        else {
            if(a[i]>x&&a[i-1]<x+m-1)init+=1+(a[i]+m-x)%m;
            else init+=(a[i]+m-a[i-1])%m;
        }
        //cout<<init<<endl;
    }
    tmp=init;
    //cout<<tmp<<endl;
    ans=min(ans,tmp);
    for(int i=2;i<=m;++i){
        //printf("x is %d\n",i);
        int a0 = 0,a1 = 0;
        int val = 0;
        a0 = v1[i];
        for(int j=0;j<v2[i-1].size();++j){
            int id = v2[i-1][j];
            a1 += (a[id]+m-a[id-1])%m-1;
        }
        //printf("////////////////////\n");
        //cout<<a0<<" "<<a1<<endl;
        val += a1-a0;
        a0=a1=0;
        a0 = v1[i+m];
        for(int j=0;j<v2[i-1+m].size();++j){
            int id = v2[i-1+m][j];
            a1 += (a[id]+m-a[id-1])%m-1;
        }
        //cout<<a0<<" "<<a1<<endl;
        //printf("/////////////////////\n");
        val += a1-a0;
        tmp+=val;
        //printf("tmp is %d\n\n",tmp);
        ans = min(ans,tmp);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
	int n;
	cin >> n;
	vector<int> t(n), a(n);
	rep(i,n) cin >> t[i];
	rep(i,n) cin >> a[i];
	vector<int> mt(n, 0);
	int tmax = 0, amax = 0;
	ll ans = 1;
	rep(i,n){
		if(i!=n-1&&t[i]>t[i+1]){
			cout << 0 << endl;
			return 0;
		}
		if(tmax < t[i]){
			tmax = t[i];
			mt[i] = t[i];
		}
	}
	for(int i = n-1; i >= 0; i--){
		if(i!=n-1&&a[i]<a[i+1]){
			cout << 0 << endl;
			return 0;
		}
		if(amax < a[i]){
			if((mt[i]!=0&&mt[i]!=a[i])||a[i]>t[i]){
				cout << 0 << endl;
				return 0;
			}
			mt[i] = a[i];
			amax = a[i]; 
		}
	}
	if(amax!=tmax){
		cout << 0 << endl;
		return 0;
	}
	rep(i,n){
		if(mt[i]!=0) continue;
		int p = min(a[i], t[i]);
		ans *= p;
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

const int N=1005;
long long dp[N][N];
char a[N][N];
long long int mod=1e9+7;

int main()
{

    int w,h; cin>>h>>w;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>a[i][j];
        }
    }
    dp[0][0]=1;
    bool czy=false;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(a[i][j]=='#') dp[i][j]=0;
            else
            {
                if(j!=0) dp[i][j]+=dp[i][j-1];
                if(i!=0) dp[i][j]+=dp[i-1][j];
            }
            dp[i][j]%=mod;
        }
    }
    cout<<dp[h-1][w-1];

    return 0;
}


Measured memory_bytes: 9088
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		
		int x = Integer.parseInt(tmpArray[0]);
		int t = Integer.parseInt(tmpArray[1]);
		
		System.out.println(Math.max(x-t, 0));
		
	}

}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define N 100010
int main() {
  int n,m,A_sum=0;
  cin>>n>>m;
  rep(i,m){
    int a;
    cin>>a;
    A_sum+=a;
  } 

  if(A_sum>n){
    cout<<-1<<endl;
  }else{
    cout<<n-A_sum<<endl;
  }
}

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		int strN = 1; //文字列を何行受け取るか
		for(int i = 0; i < strN; i++){
			line += br.readLine() + " ";
		}
		String[] param = line.split(" ");

		StringAline(param,br);
	}

	static void StringAline(String[] param,BufferedReader br) throws IOException { //1行,"並べる文字"でメソッド内で指定した文字に枠をつける
		String mozi = "#"; //並べる文字

		int str1 = Integer.parseInt(param[0]); // 縦軸
		int str2 = Integer.parseInt(param[1]); // 横軸

		String[] yoko = new String[str2 + 2];
		for (int i = 0; i < yoko.length; i++) {
			System.out.print(mozi);
		}
		System.out.println();

		for (int j = 0; j < str1; j++) {
			System.out.print(mozi);
			System.out.print(br.readLine());
			System.out.print(mozi);
			System.out.println();
		}

		for (int i = 0; i < yoko.length; i++) {
			System.out.print(mozi);
		}
	}


}

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

int main(){
	int m;
	while( cin >> m , m ){
		vector<int> a(m), b(m);
		for(int i=0 ; i < m ; i++ ){
			cin >> a[i] >> b[i];
		}
		
		// dp[i][j] := a[0..i] までのカードを使ったとき,和が j になる組合せ数
		int dp[10][1001] = {0};
		dp[0][0] = 1;
		for(int i=0 ; i < a.size() ; i++ ){
			for(int j=0 ; j < 1001 ; j++ ){
				for(int k=0 ; k <= b[i] ; k++ ){
					// k := a[i] のカードを使う枚数
					if( j+a[i]*k < 1001 ){
						dp[i+1][j+a[i]*k] += dp[i][j];
					}
				}
			}
		}
		
		int g;
		cin >> g;
		for(int i=0 ; i < g ; i++ ){
			int n;
			cin >> n;
			cout << dp[m][n] << endl;
		}
	}
}

Measured memory_bytes: 1240
d = [[[-1, -1], [0, -1], [1, -1], [1, 0], [0, 1], [-1, 0]],
     [[-1,  0], [0, -1], [1,  0], [1, 1], [0, 1], [-1, 1]]]

w, h = gets.split.map(&:to_i)
fld = (h+2).times.map{ [false]*(w+2) }
(1..h).each do |i|
  gets.split(" ").each_with_index{ |e, j| fld[i][j+1] = true if e == "1" }
end

tmp = (h+2).times.map{ [false]*(w+2) }
arr = []
arr << [0, 0]
tmp[0][0] = true
until arr.empty?
  y, x = arr.pop
  d[y%2].each do |dy, dx|
    u = y + dy; v = x + dx
    next if u < 0 || u > h+1 || v < 0 || v > w+1
    if !fld[u][v] && !tmp[u][v]
      tmp[u][v] = true
      arr << [u, v]
    end
  end
end
fld = fld.flatten.zip(tmp.flatten).map{|f,p| !(!f&p) }
p fld.map.each_with_index{ |e, i| d[(i/(w+2))%2].count{ |y, x| !fld[i+y*(w+2)+x] } if e }.compact.reduce(:+)

Measured memory_bytes: 9484
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


int main()
{
    int N, M;
    cin >> N >> M;
    map<int, int> m;
    m[0]++;
    lint sum = 0;
    lint res = 0;
    REP(i, N)
    {
        lint tmp;
        cin >> tmp;
        sum = (sum + tmp) % M;
        res += m[sum];
        m[sum]++;
    }
    cout << res << endl;
}


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

int H, W, K;
int A[30][30];
int B[31][31];
int C[31][31];

void move() {
  for (int x=0; x<W; x++) {
    for (int y=0; y<H; y++) {
      C[x][y] = B[x][y];
    }
  }
  for (int x=0; x<W; x++) {
    int h = 0;
    for (int y=0; y<H; y++) {
      if (B[x][y] == 0) continue;
      B[x][h++] = C[x][y];
    }
    for (int y=h; y<H; y++) {
      B[x][y] = 0;
    }
  }
}

long long score() {
  long long s = 0;
  for (int y=0; y<H; y++) {
    int l = -1, lc = 0;
    for (int x=0; x<=W; x++) {
      if (B[x][y] == lc) continue;
      if (x-l >= K && lc != 0) {
        s += 1LL*lc*(x-l);
        for (int xx=l; xx<x; xx++) B[xx][y] = 0;
      }
      lc = B[x][y];
      l = x;
    }
  }
  return s;
}

long long solve(int sx, int sy) {
  for (int x=0; x<W; x++) {
    for (int y=0; y<H; y++) {
      B[x][y] = A[x][y];
    }
  }
  B[sx][sy] = 0;
  move();
  long long s = 0;
  for (int i=0; ; i++) {
    int f = score();
    if (f == 0) break;
    s += (1LL<<i) * f;
    move();
  }
  return s;
}

signed main() {
  cin >> H >> W >> K;
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      char c;
      cin >> c;
      A[j][H-1-i] = (int)(c - '0');
    }
  }
  long long s = 0;
  for (int x=0; x<W; x++) {
    for (int y=0; y<H; y++) {
      s = max(s, solve(x, y));
    }
  }
  cout << s << "\n";
  return 0;
}


Measured memory_bytes: 256
N=int(input())
mod=10**9+7
memo=[{} for _ in range(N+1)]

def ok(x, y, z, nx):
  if y=='A' and z=='G' and nx=='C':
    return False
  if x=='A' and z=='G' and nx=='C':
    return False
  if y=='G' and z=='A' and nx=='C':
    return False
  if y=='A' and z=='C' and nx=='G':
    return False
  if x=='A' and y=='G' and nx=='C':
    return False
  return True

def f(num,A):
  if num==N:
    return 1
  else:
    x,y,z=A[0],A[1],A[2]
    if (x,y,z) in memo[num]:
      return  memo[num][(x,y,z)]
    else:
      s=0
      for i in ['A','C','G','T']:
        if ok(x,y,z,i):
          s+=f(num+1,(y,z,i))
      memo[num][(x,y,z)]=s%mod
      return s%mod
print(f(0,'ZZZ'))

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

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

    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> p(A), q(B), r(C);
    for (auto &x : p) cin >> x;
    for (auto &x : q) cin >> x;
    for (auto &x : r) cin >> x;
    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());
    sort(r.begin(), r.end(), greater<ll>());

    vector<ll> V;
    for (int i = 0; i < X; ++i) {
        V.push_back(p.at(i));
    }
    for (int i = 0; i < Y; ++i) {
        V.push_back(q.at(i));
    }
    for (auto &x : r) {
        V.push_back(x);
    }
    sort(V.begin(), V.end(), greater<ll>());
    ll sum = 0;
    for (int i = 0; i < X + Y; ++i) {
        sum += V.at(i);
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 8688
n = gets.to_i
v = gets.chomp.split.map(&:to_i)
c = gets.chomp.split.map(&:to_i)

length = n
number = 0
max = 0

while number <= length - 1 do
  if v[number] > c[number]
    max = max + (v[number] - c[number])
  end
  number += 1
end

puts max




Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string s, t;
  cin >> s >> t;
  int ns = s.size(), nt = t.size();
  bool flag1 = false;
  for (int i = ns - nt; i >= 0; i--) {
    bool flag = true;
    rep(j, nt) if (s[i + j] != '?') flag &= (t[j] == s[i + j]);
    if (flag) {
      rep(j, nt) s[i + j] = t[j];
      flag1 = true;
      break;
    }
  }
  if (!flag1) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  rep(i, ns) if (s[i] == '?') s[i] = 'a';
  cout << s << endl;
  return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;

//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int bigint;

const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	ll  k;
	cin >>s >>k;
	
/*
	vector<vector<ll>> p(10, vector<ll>(64, 0));
	rep(i,10) p[i][0] = i;
	ll mx = (ll)1e18;
	
	rep2(i,1, 10){
		rep(j, 62){
			if(p[i][j]  <= mx /i) p[i][j+1] = p[i][j] * i;
			else break;
		}
	}
	*/
	//for(auto xl: p){for(auto x :xl) printf("%lld, ",x); puts("");}

	rep(i, sz(s)){
		int d= s[i] -'0';
		if(d==1){
			k--;
			if(k==0){
				cout << 1 <<"\n"; return 0;
			}
			continue;
		}else{
				cout << d <<"\n"; return 0;
		}
	}
	
	//cout << 2<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <iostream>
#include <functional>
#include <iomanip>
#include <set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <deque>
#include <algorithm>
#include  <cstring>
#include <string>
#include <cmath> 
using namespace std;
typedef long long LL;
const int MAX = 3010;
const LL base = 1e9 + 7;


struct Node {
	int x, y, w;
};

int dp[MAX][MAX];
int pt[MAX][MAX];
void solve() {

	LL result = 0; 

	string s, t;
	cin >> s >> t;
	int l1 = s.size();
	int l2 = t.size();
	for (int i = 0; i < l1; ++i) {
		for (int j = 0; j < l2; ++j) {
			if (i > 0) {
				if (dp[i - 1][j] > dp[i][j]) {
					dp[i][j] = dp[i - 1][j];
					pt[i][j] = 0;
				}
			}
			if (j > 0) {
				if (dp[i ][j-1] > dp[i][j]) {
					dp[i][j] = dp[i][j - 1];
					pt[i][j] = 1;
				}
			}
			if (s[i] == t[j]) {
				int t = 0;
				if (i > 0 && j > 0) t = dp[i - 1][j - 1];
				if (t + 1 > dp[i][j]) {
					dp[i][j] = t + 1;
					pt[i][j] = 2;
				}
			}
		}
	}
	string r(dp[l1 - 1][l2 - 1], ' ');
	int ni = l1 - 1, nj = l2 - 1;
	int now = r.size() - 1;
	while (now >=0) {
		switch (pt[ni][nj]) {
		case 0:
			ni--;
			break;
		case 1:
			nj--;
			break;
		case 2:
			r[now] = s[ni];
			now--;
			ni--;
			nj--;
			break;
		}
	}
	cout << r << endl;
}

int main() {
	const int inId = 0;
	const int outId = 0;
	if (inId>0) {
		cerr << "redirect stdin to input " << inId << endl;
		string s = "input";
		s += to_string(inId);
		s += ".txt";
		auto r = freopen(s.c_str(), "r", stdin);	
		if (r == nullptr) {
			cerr<< "invalid input file "<< s;
		}
	}
	if (outId>0) {
		cerr << "redirect stdout to stdout " << outId << endl;
		string s = "stdout";
		s += to_string(outId);
		s += ".txt";
		auto r = freopen(s.c_str(), "w", stdout);
		if (r == nullptr) {
			cerr<< "invalid output file "<< s;
		}		
	}
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // close sync between cout and printf
	cout.precision(10);
	solve();
}
 

Measured memory_bytes: 70912
#include <stdio.h>
#include <stdlib.h>

int opera( int a, int b, char c) {
	if (c == '+')
		return a+b;
	return a-b;
	}

int main() {
	int *num1 = malloc(sizeof(int)), *num2 = malloc(sizeof(int));
	char * op;
	op = malloc(sizeof(char));
	scanf("%d %c %d", &num1, &op, &num2);
	//printf("%d %c %d", num1, op, num2);
	printf("%d\n",opera(num1,num2,op));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int K, N, M, n;
  cin >> N >>K;
  M = 1;
  while (M<=K&&N>0){
    M *=2;
    N--;
  }
  while (N>0){
     M += K;
    N--;
  }
  cout << M << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
static const int INF = 2000000000;


int main(){
  int n;
  string s;
  cin >> n >> s;
  int x = 0;
  int maxx = 0;
  rep(i, n) {
    if (s[i] == 'I') x++;
    else x--;
    maxx = max(maxx, x);
  }
  cout << maxx << endl;
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <time.h>
#include <ctime>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int d, c[28], s[370][28], b[370][28];

int score(int* t) {
    int i, j, ans;

    for (i = 0; i < 26; i++) {
        b[0][i] = 1;
    }

    ans = 0;
    for (i = 0; i < d; i++) {
        ans += s[i][t[i]];
        b[i][t[i]] = 0;
        for (j = 0; j < 26; j++) {
            ans -= c[j] * b[i][j];
            b[i + 1][j] = b[i][j] + 1;
        }
    }

    return ans;
}

int delta(int* t, int chd, int cht) {
    int i, res;

    res = s[chd][cht] - s[chd][t[chd]];

    i = chd + 1;
    while (i < d && t[i] != t[chd]) {
        i++;
    }

    if (chd == 0) {
        res -= (i - chd) * c[t[chd]];
    }
    else {
        res -= (b[chd - 1][t[chd]] + 1) * (i - chd) * c[t[chd]];
    }

    i = chd;
    while (i < d && t[i] != cht) {
        i++;
    }

    res += b[chd][cht] * (i - chd) * c[cht];

    return res;
}

void change(int* t, int chd, int cht) {
    int i;

    i = chd;
    while (i < d && t[i] != t[chd]) {
        if (chd == 0) {
            b[i][t[chd]] = i + 1;
        }
        else {
            b[i][t[chd]] = b[i - 1][t[chd]] + 1;
        }
        i++;
    }

    i = chd;
    while (i < d && t[i] != cht) {
        b[cht][i] = i - chd;
        i++;
    }

    t[chd] = cht;
}

int main(void) {
    int i, j;

    clock_t start = clock(), end;
    double rtime;

    scanf("%d", &d);
    for (i = 0; i < 26; i++) {
        scanf("%d", &c[i]);
    }
    for (i = 0; i < d; i++) for (j = 0; j < 26; j++) {
        scanf("%d", &s[i][j]);
    }

    int t[370], scmax, scmi;

    for (i = 0; i < d; i++) {
        scmax = 0;
        scmi = 0;
        for (j = 0; j < 26; j++) {
            if (scmax < s[i][j]) {
                scmax = s[i][j];
                scmi = j;
            }
        }
        t[i] = scmi;
    }

    int before = score(t), after, chd, cht;

    srand(time(nullptr));

    while (1) {
        end = clock();
        rtime = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
        if (rtime > 1950) {
            break;
        }

        chd = rand() % d;
        cht = rand() % 26;

        while (t[chd] == cht) {
            cht = rand() % 26;
        }

        after = before + delta(t, chd, cht);

        if (after > before) {
            change(t, chd, cht);
            before = after;
        }
    }

    for (i = 0; i < d; i++) {
        printf("%d\n", t[i] + 1);
    }
    
    return 0;
}

Measured memory_bytes: 3916
from itertools import product as p

c = [list(map(int, input().split())) for _ in range(3)]

a = [0]*3
b = [0]*3
for a1 in range(c[0][0]+1):
    a[0] = a1
    b[0] = c[0][0] - a1
    for a2 in range(c[1][1]+1):
        a[1] = a2
        b[1] = c[1][1] - a2
        for a3 in range(c[2][2]+1):
            a[2] = a3
            b[2] = c[2][2] - a3

            for i, j in p(range(3), range(3)):
                if c[i][j] != a[i] + b[j]:
                    break
            else:
                print('Yes')
                exit()

print('No')


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

int main() {
    string s;
    cin >> s;
    s.at(5) = ' ';
    s.at(13) = ' ';
    ct(s);
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7;
ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}
ll LCM(ll x, ll y) { 
  return x * y / GCD(x, y);
}

int main(){
  string a, b; cin >> a >> b;
  int ans=0;
  rep(i, 3) {
    if(a[i] == b[i]) ans++;
  }
  cout << ans << endl;
}


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

int main(void) {
	int n, cnt = 0, remain;
	cin >> n;
	// the number of 25 cents
	cnt += n / 25;
	remain = n % 25;
	// the number of 10 cents
	cnt += remain / 10;
	remain = remain % 10;
	// the number of 5 cents
	cnt += remain / 5;
	// the number of 1 cents
	cnt += remain % 5;
	cout << cnt << endl;
}


Measured memory_bytes: 3120
#include <stdio.h>
#include <math.h>
int main(void){
	int n,x[100],y[100],i,t;
	double d1=0,d2=0,d3=0,di=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&x[i]);
	}
	for(i=0;i<n;i++){
		scanf("%d",&y[i]);
	}
	for(i=0;i<n;i++){
		t=x[i]-y[i];
		if(t<0)
			t=-t;
		d1+=t;
		d2+=t*t;
		d3+=t*t*t;
		if(di<t) di=t;
	}
	d2=pow(d2,1./2);
	d3=pow(d3,1./3);
	printf("%.6f\n%.6f\n%.6f\n%.6f\n",d1,d2,d3,di);
	return 0;
}

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define Rep(i,n) for(ll i = 0; i <= n; i++)
#define REp(i,n) for(ll i = 1; i < n; i++)
#define REP(i,n) for(ll i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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


Measured memory_bytes: 3592
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<string.h>
#include<stack>
#define n 200000
#define loop(a) for(int i=0; i<a; i++)
using namespace std;
typedef pair<int, int> P;
struct edge{
	int from, to, weight;
	bool operator < (const edge& thing) const
	{
		return thing.weight < weight;
	}
};
bool cmp(int a, int b)
{
	return a > b;
}
vector<edge> V[n + 50];
bool visit[n + 50];
int arr[n + 50], a, b, c, d;
string str1, str2;
void addedge(int a, int b, int c)
{
	edge one, two;
	one.from = a; one.to = b; one.weight = c;
	two.from = b; two.to = a; two.weight = c;
	V[a].push_back(one);
	V[b].push_back(two);
}


//////////////////////////////////////////


void solve()
{
	cin >> a >> str1;
	int cnt[a][2];
	memset(cnt, 0, sizeof(cnt));
	loop(a)
	{
		if(i)
		{
			cnt[i][0] = cnt[i - 1][0];
			cnt[i][1] = cnt[i - 1][1];
		}
		if(str1[i] == 'W') cnt[i][0] ++;
		else               cnt[i][1] ++;
	}
	int ans = 2e9;
	for(int i=0; i<a; i++)
	{
		int sum = 0;
		sum += cnt[a - 1][1] - cnt[i][1];
		if(i) sum += cnt[i - 1][0];
		ans = min(ans, sum);
//		printf("%d %d\n",sum, i);
	}
	printf("%d\n",ans);
}
int main()
{
	int times = 1;
//	cin << times;
	loop(times)
	{
		solve();
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 7684
#ifdef loc
    #include "loc_debug.h"
#else
    #include <bits/stdc++.h>
    #define pr(...)
    #define pra(a,n)
    #define praa(a,n,m)
    #define prl()
#endif
using namespace std;

typedef long long ll;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define sz(a) int(a.size())
const int N = 100005, mod = 1e9 + 7;

bool a[21][21];
int f[21][1 << 21];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    rep(i, 0, n) {
        rep(j, 0, n) {
            cin >> a[i][j];
        }
    }
    rep(i, 0, n) {
        rep(j, 0, (int)1 << n) {
            if(__builtin_popcount(j) != i + 1) {
                continue;
            }
            rep(k, 0, n) {
                if(((j >> k) & 1) && a[i][k]) {
                    if(i) {
                        f[i][j] += f[i - 1][j ^ (1 << k)];
                        if(f[i][j] >= mod) {
                            f[i][j] -= mod;
                        }
                    } else {
                        f[i][j] = 1;
                    }
                }
            }
        }
    }
    cout << f[n - 1][(1 << n) - 1] << endl;
}

Measured memory_bytes: 160000
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll inf =1LL << 62;

int cur[2001];
int ans[4001];

int main(void){
	int n;
	vi  list;
	rep(a,1001)
		rep(b,1001){
			int x=a+b;
			cur[x]++;
	}
	rep(s,4001){
		rep(a,2001){
			int b=s-a;
			if(0<=a&&a<=2000&&0<=b&&b<=2000)
				ans[s]+=cur[a]*cur[b];
		}
	}
	while(cin >>n){
		if(cin.eof())
			break;
		cout << ans[n] << endl;
	}
	return 0;
}

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  double a, b, x; cin >> a >> b >> x;
  if (x <= a*a*b / 2) {
    double h = (2 * x) / (a * b);
    double th = atan2(h, b);
    double p = th / M_PI * 180.0;
    cout << 90.0 - p << endl;
  }else {
    double t = (2.0 * (a * b - x / a)) / (a * a);
    double th = atan2(t, 1);
    double p = th / M_PI * 180.0;
    cout << p << endl;
  }

  return 0;
}



Measured memory_bytes: 4120
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

const double pi=3.1415;
ll absc(ll a,ll b){return (a-b>0?a-b:b-a);
}
ll mini(ll a,ll b){return (a>b?b:a);}
ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	return (a%b?gcd(a%b,b):b);
}
ll gojou(ll n){return pow(n,5);}
int main()
{
   ll x,ans1=0,ans2=0;
   cin>>x;
   bool f=false;
   for(ll i=-200;i<200;i++)
   {
   	for(ll j=-200;j<200;j++)
   {
   	if(gojou(i)-gojou(j)==x){ans1=i;ans2=j;f=true;}
   	if(f)break;
   }
   if(f)break;
   }
   cout<<ans1<<" "<<ans2;
}


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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int i=0; i<n; i++)
#define FOR1(i, n) for(int i=1; i<=n; i++)
#define FORI(i, n) for(int i=n-1; i>=0; i--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n);  for(auto& a : v) init(a, x, m...); }

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    string s, t;
    cin >> s >> t;
    int n = s.length();
    int m = t.length();

    int sol = m;
    FOR(i, n){
        if (i+m > n) break;
        int cost = 0;
        FOR(j, m)
            cost += s[i+j] != t[j];
        umin(sol, cost);
    }

    cout << sol << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}



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

int main(){
	int n;
	cin >> n;
	map<string, int> mp;
	mp["AC"] = 0;
	mp["WA"] = 0;
	mp["TLE"] = 0;
	mp["RE"] = 0;
	
	for(int i=1; i<=n; i++){
		string s;
		cin >> s;
		mp[s]++;
	}
	
	printf("AC x %d\n", mp["AC"]);
	printf("WA x %d\n", mp["WA"]);
	printf("TLE x %d\n", mp["TLE"]);
	printf("RE x %d\n", mp["RE"]);
	return 0;
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define stat pair<int, pii>

bool grid[1000][1000];

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

int32_t main()
{
    int H, W, Ch, Cw, Dh, Dw;
    cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
    --Ch, --Cw, --Dh, --Dw;
    for (int i = 0; i < H; ++i)
    {
        for (int j = 0; j < W; ++j)
        {
            char c;
            cin >> c;
            if (c == '.')
                grid[i][j] = 0;
            else
                grid[i][j] = 1;
        }
    }
    priority_queue<stat, vector<stat>, greater<stat>> pq;
    pq.push(make_pair(0, make_pair(Ch, Cw)));
    int ans = -1;
    while (!pq.empty())
    {
        stat tmd = pq.top();
        pq.pop();
        int x = tmd.second.first, y = tmd.second.second;
        if (grid[x][y])
            continue;
        else
            grid[x][y] = 1;
        if (x == Dh && y == Dw)
        {
            ans = tmd.first;
            break;
        }
        //cout << x << ' ' << y << '\n';
        for (int i = 0; i < 24; ++i)
        {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (0 <= nx && nx < H && 0 <= ny && ny < W && !grid[nx][ny])
            {
                //cout << ' ' << nx << ' ' << ny << '\n';
                stat nxt = tmd;
                nxt.second = make_pair(nx, ny);
                if (i >= 4)
                    ++nxt.first;
                pq.push(nxt);
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 5844
import sys
input = sys.stdin.readline
N = int(input())
i = 1
res = float("inf")
while i * i <= N:
  if N % i == 0:
    x = i + 0
    j = N // i
    di = 0
    dj = 0
    while x // 10:
      di += 1
      x //= 10
    while j // 10:
      dj += 1
      j //= 10
    res = min(res, max(di, dj))
  i += 1
print(res + 1)

Measured memory_bytes: 39664
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

const int N = 1e6 + 10;

int main() {
  int n;
  cin >> n;
  int g = 0;
  vector<int> visit(N);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    g = gcd(g, x);
    visit[x]++;
  }
  if (g > 1) {
    cout << "not coprime\n";
    return 0;
  }
  bool found = false;
  for (int i = 2; i < N; ++i) {
    int sum = 0;
    for (int j = i; j < N; j += i) sum += visit[j];
    if (sum > 1) {
      found = true;
      break;
    }
  }
  if (found) {
    cout << "setwise coprime\n";
  } else {
    cout << "pairwise coprime\n";
  }
  return 0;
}


Measured memory_bytes: 6772
#include <iostream>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;

ll N;
string S1, S2;

int main(void) {
  cin >> N >> S1 >> S2;

  ll ans = 1;
  REP(i, 0, N) {
    if(i == 0) {
      if(S1[i] == S2[i]) {
        ans *= 3;
        ans %= MOD;
      } else {
        i++;
        ans *= 6;
        ans %= MOD;
      }
    } else {
      if(S1[i - 1] == S2[i - 1] && S1[i] == S2[i]) {
        ans *= 2;
        ans %= MOD;
      } else if(S1[i - 1] == S2[i - 1] && S1[i] != S2[i]) {
        ans *= 2;
        ans %= MOD;
        i++;
      } else if(S1[i - 1] != S2[i - 1] && S1[i] == S2[i]) {
        ans *= 1;
        ans %= MOD;
      } else {
        ans *= 3;
        ans %= MOD;
        i++;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
   //freopen("t5.in","r",stdin);
   //freopen("t5.out","w",stdout);
   //ios::sync_with_stdio(false);
   //cin.tie(0); cout.tie(0);
    int i,j,n,m;
    long long a,b;
    cin>>a>>b;
    long long p1=a%b;
    long long p2=b-p1;
    cout<<min(p1,p2);
    return 0;
}


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

using namespace std;

#define db(x) cout << (x) << '\n';
#define all(x) x.begin(),x.end()
#define UNIQUE(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define LB(v,x) lower_bound(all(v),x)
#define UB(v,x) upper_bound(all(v),x)
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define PF push_front
#define int long long
#define trick int m = (l+r)>>1,lc=n<<1,rc=lc|1

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

int dy[]={0,1,1,1,0,-1,-1,-1};
int dx[]={-1,-1,0,1,1,1,0,-1};
const int maxn = 1e5;
const int OO = 1e18;
const int mod = 1e9 + 7;
const double PI = acos(-1);

void maxself(int &a,int b)
{a=max(a,b);}
void minself(int &a,int b)
{a=min(a,b);}


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

//	freopen("name.in","r",stdin);
//	freopen("name.out","w",stdout);
	
	int n,k;
	cin >> n >> k;
	if(n*500 >= k)
	cout << "Yes";
	else
	cout << "No";
	
	return 0;
}



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

bool appear[26];

int main(){
	string str;
	cin >> str;
	for(char c : str){
		appear[c - 'a'] = true;
	}
	for(int a = 0; a < 26; a++){
		if(!appear[a]){
			cout << char('a' + a);
			return 0;
		}
	}
	cout << "None";
}

Measured memory_bytes: 512
#include <iostream>
#include <string.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <vector>
#include <map>
using namespace std;

#define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define ii pair < int, int >
#define iii pair < int, ii >
#define INF 987654321
#define LINF 987654321987654321

int main()
{
	cio;
	int n;
	cin >> n;

	cout << 1000 - ((n - 1) % 1000 + 1);
}

Measured memory_bytes: 3188