akhauriyash/Code-Regression huggingface dataset:
package main

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

var nextString func() string

func init() {
	nextString = newReadString(os.Stdin)
}

func main() {
	s := nextString()
	n := len(s)

	fmt.Print(string(s[0]))
	fmt.Print(n - 2)
	fmt.Println(string(s[n-1]))
}

func nextInt() (result int) {
	result, _ = strconv.Atoi(nextString())
	return
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
		}
		return r.Text()
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323


ll pw(ll n)
{
       ll ans=1;
       rep(i,0,n) ans*=2;
       return ans;
}


void solve()
{
       ll n,p;
       cin>>n>>p;
       ll ec=0, oc=0;
       rep(i,0,n)
       {
              ll x; cin>>x;
              if(x&1) oc++;
              else ec++;
       }
       if(ec==n)
       {
              if(p==0) cout<<pw(n)<<endl;
              else cout<<0<<endl;
       }
       else
       {
              cout<<pw(n-1)<<endl;
       }

}


int main()
{
    speed_up
    ll T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define print(X) cout << (X) << "\n"
#define _ << " " <<
static const int INF = 1e+9+7;

int main(){
  int W,H,x,y,r;
  cin >> W >> H >> x >> y >> r;
  if(x+r<=W and x-r>=0 and y+r<=H and y-r>=0) print("Yes");
  else print("No");

  return 0;
}





Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <cstdlib>
int main(int argc, char const *argv[]) {

  while(1){
    std::string s;
    int sum=0;
    std::getline(std::cin, s);
    if(atoi(s.c_str()) == 0)break;
    std::string::const_iterator it = s.begin();
    while(it != s.end()){
      std::string c;
      int x;
      c = *it;
      x = atoi(c.c_str());
      sum += x;
      it++;
    }
    std::cout << sum << std::endl;
  }

  return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int i;
   long long a,b;
  cin>>a;
  b=(a/11*2);
  a=a%11;
  if(a>0){b+=1;a-=6;}
  if(a>0){b+=1;a-=5;}
  cout<<b<<endl;
}

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

// O(ElogE)

// pq<pair> はfirstが大きい順に出てくるのですか？
// s:= 開始ノード  v:= 頂点数  adjlist:= 隣接リスト (first:= コスト   second:= 行先)
vector<int> dijk(int s, int v, vector<vector<pair<int, int> > > adjlist){
    
    priority_queue <pair<int, int> > wait;
    vector<int> result(v, INF);

    //スタート地点を追加
    result[s] = 0;
    wait.push(make_pair(0, s));

    //ダイクストラ本体
    while(!wait.empty()){    //waitが空になるまで

        int nowpoint = wait.top().second;
        int nowcost = -wait.top().first;
        wait.pop();

        if(result[nowpoint] < nowcost) continue;


        //今いる頂点と隣接しているすべての頂点をなめる
        for(int i = 0; i < adjlist[nowpoint].size(); i++){

            int nextpoint = adjlist[nowpoint][i].second;
            int nextcost = nowcost + adjlist[nowpoint][i].first;
            //現時点より安く到達できそうであれば、結果を更新して優先度付きキューに格納
            if(result[nextpoint] > nextcost){
                result[nextpoint] = nextcost;
                wait.push(make_pair(-nextcost, nextpoint));
            }
        }
    }
    
    return result;         //結果列を返す
}

int main(){

    int V; cin >> V;
    vector<vector<pair<int, int> > > adjlist(V);      //first := コスト　second := 行先

    //入力
    for(int i = 0; i < V; i++){
        int gomi; cin >> gomi;
        int k; cin >> k;
        for(int j = 0; j < k; j++){
            int v, c; cin >> v >> c;           // a ,b 間に コスト c の辺がある
            adjlist[i].push_back(make_pair(c, v));
        }     
    }

    vector<int> result(V);
    result = dijk(0, V, adjlist);
    //cout << result[G] << endl;

    for(int i = 0; i < V; i++){
        cout << i << " " << result[i] << endl;
    }
    return 0;
}


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

using namespace std;

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <limits>
#include <cassert>

using namespace std;

using i64 = long long int;
using u64 = std::uint_fast64_t;
using P = pair<i64, i64>;

struct edge {
    i64 from, to, cost;
    edge(i64 from, i64 to) : from(from), to(to), cost(1) {}
    edge(i64 from, i64 to, i64 cost) : from(from), to(to), cost(cost) {}
};
using Graph = vector<vector<edge>>;

constexpr i64 INF = std::numeric_limits<i64>::max();
constexpr i64 SINF = std::numeric_limits<i64>::max() / 10;
constexpr i64 MOD = 1000000007;
constexpr i64 dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
//const i64 dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//const i64 dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//const i64 dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main() {
    i64 k, m;
    cin >> k >> m;
    for (int i = 0; i < 2 * k - 1; ++i) {
        cout << m - k + 1 + i << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX=100000;
static const int NIL=-1;

int n,color[MAX];
vector<int>G[MAX];

void dfs(int r,int c){
  stack<int> S;
  int u,i,v;
  
  S.push(r);
  color[r]=c;

  
  while(!S.empty()){
    u=S.top();
    S.pop();
    for(i=0;i<G[u].size();i++){
      v=G[u][i];
      if(color[v]==NIL){
	color[v]=c;
	S.push(v);
      }
    }
  }
}

void assignColor(){
  int id=1;
  int i,u;
  for(i=0;i<n;i++)color[i]=NIL;
  for(u=0;u<n;u++){
    if(color[u]==NIL)dfs(u,id++);
  }
}

int main(){
  int s,t,m,q;
  int i;
  cin>>n>>m;
  for(i=0;i<m;i++){
    cin>>s>>t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  assignColor();

  cin>>q;

  for(i=0;i<q;i++){
    cin>>s>>t;
    if(color[s]==color[t]){
      cout<< "yes" <<endl;
    }else {
      cout<< "no" <<endl;
    }
  }
  
  return 0;
}

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

int n;
struct Point{double x,y;};

void fluctal(Point p1,Point p2,int i){
    if(i<n){//n以下で動く。
        Point p3,p4,p5;
        p3.x=(p1.x*2+p2.x)/3;
        p3.y=(p1.y*2+p2.y)/3;
        p5.x=(p2.x*2+p1.x)/3;
        p5.y=(p2.y*2+p1.y)/3;
        p4.x=p3.x+(0.5)*(p5.x-p3.x)+(pow(3,0.5)/2)*(p3.y-p5.y);
        p4.y=p3.y+(0.5)*(p5.y-p3.y)+(pow(3,0.5)/2)*(p5.x-p3.x);
        //出力する順番もきちんと考えればソートいらずになる。
        fluctal(p1,p3,i+1);
        cout<<p3.x<<' '<<p3.y<<endl;
        fluctal(p3,p4,i+1);
        cout<<p4.x<<' '<<p4.y<<endl;
        fluctal(p4,p5,i+1);
        cout<<p5.x<<' '<<p5.y<<endl;
        fluctal(p5,p2,i+1);
    }
}

int main(){
    cin>>n;
    Point a,b;
    a.x=0;a.y=0;b.x=100;b.y=0;
    cout<<a.x<<' '<<a.y<<endl;
    fluctal(a,b,0);
    cout<<b.x<<' '<<b.y<<endl;
    return 0;
}


Measured memory_bytes: 3292
MOD = 10**9+7
n,k = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
b = Array.new(n,0)
n.times do |i|
  x = a[i]
  (n-1).times do |j|
    if x > a[(i+j+1)%n]
      b[i] += 1
    end
  end
end
ans = 0
n.times do |i|
  ans += (b[i] * (k-1) * k / 2) % MOD
  ans %= MOD
end
for i in 0..n-2
  for j in (i+1)..n-1
    if a[i] > a[j]
      ans += k
      ans %= MOD
    end
  end
end
puts ans

Measured memory_bytes: 14376
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int A = in.nextInt();
        int B = in.nextInt();
        if((B-A) %2 == 0){
            System.out.println("Alice");
        } else {
            System.out.println("Borys");
        }
        in.close();
    }
}


Measured memory_bytes: 23892
#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() {
    vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
    int k;
    cin >> k; k--;

    cout << v[k] << endl;

    return 0;
}

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i ,a, b) for (int i = a ; i <= b ; i++)
#define sz(a) int(a.size())
#define cuti(a) cout << a << endl;
#define cutii(a,b) cout << a << " " << b << endl;
#define cutiii(a,b,c) cout << a << " " << b << " " << c << endl;
#define vec(a) vector<int > a;

template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }

typedef long long LL;
typedef pair<int ,int > pii;
typedef pair<string ,int > psi;
typedef pair<string ,string > pss;
typedef pair<LL, LL> pLL;

const long long oo = 1e9 + 7;
const double PI = acos(-1.0);

double DEG_to_RAD(double d) { return d * PI / 180.0; }

int n,M;
int m[123456];

int main(){
  //  freopen("test.txt","r",stdin);
    cin >> n >> M;
    m[0] = 1;
    for (int i =1 ; i <= n ; i++) {
        m[i] = m[i-1] * 2;
    }
    long long ans = 0;
    ans = 1LL*m[M]* ((n-M) * 100 + M * 1900);
    cout << ans << endl;
}


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

#define SZ(x) (((int)x.size()))
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

using namespace std;

const int maxn = 110;
string s[maxn];
int dis[maxn][maxn], h, w, nx, ny, cx, cy, dx[2] = {0, 1}, dy[2] = {1, 0};
bool b[maxn][maxn];
deque<pair<int, int>> d;

bool is(int x, int y)
{
	return x >= 1 && x <= h && y >= 1 && y <= w;
}

int cw(int u0, int v0, int u1, int v1)
{
	if (!b[u0][v0] && b[u1][v1])
		return 1;
	return 0;
}

void bfs()
{
	while (!d.empty())
	{
		cx = d.front().first;
		cy = d.front().second;
		d.pop_front();
		for (int i = 0; i < 2; i++)
		{
			nx = cx + dx[i];
			ny = cy + dy[i];
			if (is(nx, ny) && dis[cx][cy] + cw(cx, cy, nx, ny) < dis[nx][ny])
			{
				dis[nx][ny] = dis[cx][cy] + cw(cx, cy, nx, ny);
				if (cw(cx, cy, nx, ny) == 1)
					d.push_back({nx, ny});
				else
					d.push_front({nx, ny});
			}
		}
	}
}

int main()
{
	memset(dis, 31, sizeof dis);
	cin >> h >> w;
	for (int i = 0; i < h; i++)
	{
		cin >> s[i];
		for (int j = 0; j < w; j++)
		{
			if (s[i][j] == '#')
				b[i + 1][j + 1] = 1;
		}
	}
	dis[1][0] = 0;
	d.push_back({1, 0});
	bfs();
	cout << dis[h][w];
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
 
int main(){
    int value;
    double quantity;
    char c;
    int total = 0;
    double count = 0;
    double sales = 0;
    while(cin >> value >> c >> quantity){
        total += value * quantity;
        sales += quantity;
        count++;
    }
    if(count != 0){
        cout << total << endl;
        cout << (int)((sales / count) + 0.5) << endl;
    }else {
        cout << 0 << endl;
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 1224
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int main() {
	string s;
	cin >> s;
	int k;
	cin >> k;
	set<string> already;
	vector<string> gogo;
	REP(i, s.length()) {
		string hoge;
		for (int q = 0; q < k; ++q) {
			if (i + q >= s.length())break;
			hoge.push_back(s[i + q]);
			if (already.find(hoge) == already.end()) {
				already.insert(hoge);
				gogo.push_back(hoge);
			}
		}
	}
	sort(gogo.begin(), gogo.end());
	cout << gogo[k - 1] << endl;
	return 0;
}

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

int main() {
    int abcd;
    cin >> abcd;

    int a = abcd / 1000;
    abcd -= abcd/1000 * 1000;
    int b = abcd / 100;
    abcd -= abcd/100 * 100;
    int c = abcd/10;
    int d = abcd - (abcd/10 * 10);

    for (int i = -1; i <= 1; i+=2) {
        for (int j = -1; j <= 1; j+=2) {
            for (int k = -1; k <= 1; k+=2) {
                if (a + b*i + c*j + d*k == 7) {
                    cout << a;
                    if (i == -1) {
                        cout << "-";
                    } else {
                        cout << "+";
                    }
                    cout << b;
                    if (j == -1) {
                        cout << "-";
                    } else {
                        cout << "+";
                    }
                    cout << c;
                    if (k == -1) {
                        cout << "-";
                    } else {
                        cout << "+";
                    }
                    cout << d << "=" << 7 << endl;
                    return 0;
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b,c,x,y,ans=1001001001;
  cin>>a>>b>>c>>x>>y;
  for(int i=0;i<=x+y;i++){
    long long int min=i*2*c+max(0,x-i)*a+b*max(0,y-i);
    if(min<ans) ans=min;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;cin>>s;int ans=0,n=s.size();
	for (int i=0,j=s.size()-1;j>i;i++,j--){
		if (s[i]!=s[j]) ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 256
// AOJ 0583
#include <iostream>
#include <map>

using namespace std;

int main()
{
	int n;
	int num[5], ma = 0;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> num[i];
		ma = max(ma, num[i]);
	}

	for (int a = 1; a <= ma; a++){
		if (ma % a == 0){
			bool f = true;
			for (int i = 0; i < n; i++){
				if (num[i] % a != 0) {
					f = false;
					break;
				}
			}
			if (f){
				cout << a << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;


public class Main {
	 static class FastReader 
	    { 
	        BufferedReader br; 
	        StringTokenizer st; 
	       
	  
	        public FastReader() 
	        { 
	            br = new BufferedReader(new
	                     InputStreamReader(System.in)); 
	        } 
	  
	        String next() 
	        { 
	            while (st == null || !st.hasMoreTokens()) 
	            { 
	                try
	                { 
	                    st = new StringTokenizer(br.readLine()); 
	                } 
	                catch (IOException  e) 
	                { 
	                    e.printStackTrace(); 
	                } 
	            } 
	            return st.nextToken();
	            
	        } 
	  
	        int nextInt() 
	        { 
	            return Integer.parseInt(next()); 
	        } 
	  
	        long nextLong() 
	        { 
	            return Long.parseLong(next()); 
	        } 
	  
	        double nextDouble() 
	        { 
	            return Double.parseDouble(next()); 
	        } 
	  
	        String nextLine() 
	        { 
	            String str = ""; 
	            try
	            { 
	                str = br.readLine(); 
	            } 
	            catch (IOException e) 
	            { 
	                e.printStackTrace(); 
	            } 
	            return str; 
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 
	
	public static void main(String[] args)throws IOException  {
		FastReader s=new FastReader();		
		int n = s.nextInt();
		int a[] = new int[50];
		int b[] = new int[50];
		int c[] = new int[n];
		for(int i=1;i<=n;i++) {
			a[i]=s.nextInt();
			
		}
		for(int i=1;i<=n;i++) {
			b[i]=s.nextInt();
		
		}
		for(int i=1;i<=n-1;i++) {
			c[i]=s.nextInt();
			
		}
		int c1=0,j=0;
		for(int i=1;i<=n;i++) {
			c1+=b[a[i]];
			
			if(a[i]-j==1) {
				
				c1+=c[a[i]-1];
				
			}
			j=a[i];
		}
		System.out.println(c1);
	}
}

Measured memory_bytes: 32772
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n);i>0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+5  
using ll = long long;
using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
using PPI = pair<P, int>;
//ll const mod=998244353;
ll const mod = 1e9 + 7;
const ll MAX = 1000005;
using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vd = vector<double>;
using vs = vector<string>;
using vp = vector<P>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<double>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
using vvb = vector<vector<bool>>;
template <typename T>
bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; }


//////////////////////////////////////
int bit_cnt(int n) {
    int ret = 0;
    while (n > 0) {
        ret += n % 2;
        n /= 2;
    }
    return ret;
}
void get_sum(vi &a, vi b) {
    int n = a.size();
    rep(i, n) {
        a[i] += b[i];
    }

}
void init(vi &a) {
    int n = a.size();
    rep(i, n)a[i] = 0;
}
bool f(vi a, int t) {
    int n = a.size();
    rep(i, n) {
        if (a[i] > t)return true;
    }
    return false;
}
int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vs tmp(h);
    rep(i, h)cin >> tmp[i];

    vvi s((h), vi(w));

    rep(i, h)rep(j, w)s[i][j] = (tmp[i][j] - '0');
    int ans = INF;




    rep(i, 1 << (h-1)) {
        int ni = i + (1 << (h-1));
        vi sum(w);
        int si = bit_cnt(ni);
        vvi rv(si, vi(w));
        int index = 0;
        rep(j, h) {
            get_sum(sum, s[j]);
            if (ni >> j & 1) {
                swap(sum, rv[index++]);
            }
            
        }
        sum.clear();
        sum.resize(si, 0);
        int res = 0;



        rep(j, w) {
            rep(i, si) {
                sum[i] += rv[i][j];
            }
            if (f(sum,k)) {
                res++;
                init(sum);
                j--;
            }
            if (res > w) {
                res = INF;
                break;
            }
        }
        chmin(ans, res + si - 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3688
#include <iostream>
#include <string>
#include <algorithm>

int main() {
	int n;

	std::cin >> n;

	std::string upper = "", lower = "";

	std::string uq = "..##", lq = ".#.#";
	bool back = false;
	while (true) {
		int before_length = upper.length();
		for (int i = 0; i < 4; i++) {
			std::string result;

			if (back) {
				std::cout << uq[i] << upper << std::endl;
				std::cout << lq[i] << lower << std::endl;
				std::cin >> result;
				if (result == "end") return 0;
				if (result == "T") {
					upper = uq[i] + upper;
					lower = lq[i] + lower;
					break;
				}
			} else {
				std::cout << upper << uq[i] << std::endl;
				std::cout << lower << lq[i] << std::endl;
				std::cin >> result;

				if (result == "end") return 0;
				if (result == "T") {
					upper += uq[i];
					lower += lq[i];
					break;
				}
			}
		}
		if (before_length == upper.length()) {
			back = true;
		}
	}

	return 0;
}

Measured memory_bytes: 596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            StringTokenizer st = new StringTokenizer(br.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            int c = Integer.parseInt(st.nextToken());
            if (a < b && b < c) {
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}



Measured memory_bytes: 24376
# +1/-1の折れ線で表したとき
# 「0で終わる」かつ「途中で0未満にならない」を満たせば良い

# あとは貪欲を上手い事使う


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a = []
    b = []
    for _ in range(n):
        s = input().rstrip()
        # 最終的に上がる量/最下点
        up, down = 0, 0
        for i in s:
            if i == ')':
                up -= 1
                if down > up:
                    down = up
            else:
                up += 1
        if up >= 0:
            a.append((down, up))
        else:
            b.append((down-up, -up))

    a.sort(key=lambda a: a[0],reverse=True)
    b.sort(key=lambda a: a[0],reverse=True)

    left, right = 0, 0

    for d, u in a:
        if left+d < 0:
            print('No')
            break
        else:
            left += u
    else:
        for d, u in b:
            if right+d < 0:
                print('No')
                break
            else:
                right += u
        else:
            if left == right:
                print('Yes')
            else:
                print('No')
    
if __name__ == '__main__':
    main()

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    rep (i, n) cin >> a[i];
    rep (i, n) {
        if (a[i] % 2) {
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
    
    return 0;
}



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

int main() {
	int m = 1;
	for (int i = 0; i < m; i++)
	{
		char line[1000];
		char t = getchar();
		int cnt = 0;
		while(t != '\n') {
		    line[cnt] = t;
		    t = getchar();
		    cnt++;
		}
		int mark = 0, exception = 0, negative = 0;
		int array[1000];
		for (int j = 0; j < 1000; j++) array[j] = 0;
		for (int j = 0; j < 1000; j++)
		{
			if (line[j] == 0) break;
			if (line[j] == ' ') continue;
		    if (line[j] == '+') 
		    {
			    array[mark - 1] = array[mark] + array[mark - 1];
			    mark = mark - 1;
		    }
		    else if (line[j] == '-') 
		    {
		    	if (line[j+1] == ' ' || line[j+1] == 0)
			    {
			    	array[mark - 1] = array[mark - 1] - array[mark];
			        mark = mark - 1;
			    }
			    else negative = 1;
		    }
		    else if (line[j] == '*') 
		    {
			    array[mark - 1] = array[mark] * array[mark - 1];
			    mark = mark - 1;
		    }
		    else if (line[j] == '/') 
		    {
		    	if (array[mark] == 0)
		    	{
		    		exception = 1;
		    		break;
		    	}
			    array[mark - 1] = array[mark - 1] / array[mark];
			    mark = mark - 1;
		    }
		    else if (line[j] == '!') 
		    {
		    	if (array[mark] < 0)
		    	{
		    		exception = 2;
		    		break;
		    	}
		    	for (int k = array[mark] - 1; k > 0; k--) array[mark] = array[mark] * k;
		    }
		    else
		    {
		    	mark = mark + 1;
		    	array[mark] = 0;
		    	while(1)
		    	{
		    		if (line[j] == ' ') break;
		    		array[mark] = array[mark] * 10 + (line[j] - 48);
		    		j++;
		    	}
		    	if (negative == 1)
		    	{
		    		array[mark] = 0 - array[mark];
		    	    negative = 0;
		    	}
		    }
		}
		if (exception == 0) printf("%d\n", array[mark]);
		if (exception == 1) printf("division by zero\n");
		if (exception == 2) printf("factorial of an negative number\n");
	}
	return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define  clr(v,val)      memset(v,val,sizeof(v))
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
typedef  long long     ll ;
typedef  unsigned long long     ull ;
const double eps= (1e-9);
using namespace std;
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
ll setBit1(ll num, ll idx) {return num | (1ll<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
void GO(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
const int N=500000+5,mod=1e9+7;
map<string ,int> mb;
int main(){
    int T;
    cin>>T;
    while(T--){
        string ss;
        cin>>ss;
        mb[ss]++;
    }
    cout<<"AC x "<<mb["AC"]<<endl<<"WA x "<<mb["WA"]<<endl<<"TLE x "<<mb["TLE"]<<endl<<"RE x "<<mb["RE"]<<endl;
}


















































































































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

namespace arc096_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            var A = l[0];
            var B = l[1];
            var C = l[2];
            var X = l[3];
            var Y = l[4];
            
            // ABの方がコスパ悪い時
            if (A + B < C * 2)
                Console.WriteLine(A * X + B * Y);
            else
            {
                int r1 = 0; //少ない方をAB
                int r2 = 0; //すべてAB

                if (X >= Y) 
                {
                    r1 = C * Y * 2 + A * (X - Y);
                    r2 = C * X * 2;
                }
                else
                {
                    r1 = C * X * 2 + B * (Y - X);
                    r2 = C * Y * 2;
                }
                Console.WriteLine(Math.Min(r1, r2));
            }
          
        }
    }
}


Measured memory_bytes: 11348
#define _USE_MATH_DEFINES
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main() {
	 double a;
	cin >> a;
	printf("%.6f %.6f\n",M_PI*a*a,2*M_PI*a);
	return 0;
}

Measured memory_bytes: 3172
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int N,ans=0;
  cin>>N;
  int A[N-1];
  REP(i,N-1) cin>>A[i];
  
  if(N>=3){
  for(int i=0; i<N-2; ++i) ans+=min(A[i],A[i+1]);
  ans+=A[0];
  ans+=A[N-2];
  }
  
  else if(N==2) ans=2*A[0];
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string A,B;
    cin >> A >> B;
    if(A.size() > B.size()) {
        cout << "GREATER" << endl;
        return 0;
    }
    if(A.size() < B.size()) {
        cout << "LESS" << endl;
        return 0;
    }
    for(int i = 0; i < A.size(); i++) {
        if(A[i]-'0' > B[i]-'0') {
            cout << "GREATER" << endl;
            return 0;
        }
        else if(A[i]-'0' < B[i]-'0') {
            cout << "LESS" << endl;
            return 0;
        }
    }
    cout << "EQUAL" << endl;
}


Measured memory_bytes: 256
N = gets.to_i
edges = Hash.new{|h,k| h[k] = []}
(N-1).times do
  a, b = gets.split.map(&:to_i)
  edges[a-1] << b-1
  edges[b-1] << a-1
end

#0,N-1をつなぐパスを見つける
stack = [0]
prev = Hash.new
visited = Array.new(N, false)
while from = stack.pop do
  visited[from] = true
  edges[from].each do |to|
    if !visited[to]
      stack << to
      prev[to] = from
    end
  end
end

path = [N-1]
cur = -1
l = 0
while cur != 0 do
  cur = path[l]
  path << prev[cur] if prev[cur]
  l += 1
end

#黒く塗られるノードをDFSで列挙する
visited = Array.new(N, false)
bound = path[l-2-(l-1)/2]
visited[0] = true
stack = [0]
while from = stack.pop do
  edges[from].each do |j|
    if !visited[j] && j != bound
      stack << j
      visited[j] = true
    end
  end
end

puts 2*visited.count{|e| e} > N ? "Fennec":"Snuke"


Measured memory_bytes: 24828
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
LL fac[N];
void init(){
    fac[0]=1;
    fac[1]=1;
    for(int i=2;i<=1E5;i++)
        fac[i]=fac[i-1]*i%MOD;
}
int main(){
    init();
    int n,m;
    scanf("%d%d",&n,&m);
    if(abs(n-m)>1)
        printf("0\n");
    else if(abs(n-m)==0){
        LL res=((fac[n]%MOD*fac[m]%MOD)%MOD)*2%MOD;
        printf("%lld\n",res);
    }
    else{
        LL res=(fac[n]%MOD*fac[m]%MOD)%MOD;
        printf("%lld\n",res);
    }
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int m = Integer.parseInt(str[1]);
    int X = Integer.parseInt(str[2]);
    int Y = Integer.parseInt(str[3]);
    int[] x = new int[n];
    int[] y = new int[m];
    
    str = in.readLine().split(" ");
    for(int i=0; i<n; i++) {
      x[i] = Integer.parseInt(str[i]);
    }
    
    str = in.readLine().split(" ");
    for(int i=0; i<m; i++) {
      y[i] = Integer.parseInt(str[i]);
    }
    
    Arrays.parallelSort(x);
    Arrays.parallelSort(y);
    
    for(int i=X+1; i<Y; i++) {
      if(i>x[n-1] && i<=y[0]) {
        System.out.println("No War");
        return;
      }
    }
    
    System.out.println("War");
  }
}

Measured memory_bytes: 32748
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n';

typedef long long ll;

using namespace std;

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

    int a = N / 100;
    int ans = a + a * 10 + a * 100;
    if (ans >= N)
    {
        cout << ans << endl;
    }
    else
    {
        cout << (a + 1) + (a + 1) * 10 + (a + 1) * 100 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
// 作者：杨成瑞先生
import java.io.*;
import java.util.*;

public class Main {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

        public int nextInt() {return Integer.parseInt(next());}

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

	public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        long[] h = new long[n];
        for(int i=0;i<n;i++) h[i] = sc.nextLong();
        //pw.println(Arrays.toString(h));

        long[] dp = new long[n];
        dp[n-2] = Math.abs(h[n-2] - h[n-1]);
        for(int i=n-3;i>=0;i--) {
            dp[i] = Math.min(Math.abs(h[i] - h[i+1]) + dp[i+1], Math.abs(h[i] - h[i+2]) + dp[i+2]);
        }
        
        pw.println(dp[0]);
        pw.close();
	}

}

Measured memory_bytes: 32344
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H, W = MAP()
s = [input() for _ in range(H)]

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
for i in range(H):
	for j in range(W):
		if s[i][j] == '#':
			for sx, sy in zip(dx, dy):
				y = i+sy
				x = j+sx
				if 0 <= y <= H-1 and 0 <= x <= W-1:
					if s[y][x] == '#':
						break
			else:
				print("No")
				sys.exit()
else:
	print("Yes")


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

int cmp(const void * a, const void * b) {
	return (*(const int*)a - *(const int*) b);
}

int main () {
	int n;
	cin >> n;
	int S[n];
	for (int i = 0; i < n; i++) {
		cin >> S[i];
	}
	int q, cnt = 0;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int x;
		cin >> x;
		if (bsearch(&x, S, n, sizeof(int), cmp)) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1548
a,b,c,d,e,f=list(map(int,input().split()))
for g in input():
 if g=='N':a,e,f,b=b,a,e,f
 if g=='E':a,c,f,d=d,a,c,f
 if g=='W':a,c,f,d=c,f,d,a
 if g=='S':a,e,f,b=e,f,b,a
print(a)


Measured memory_bytes: 5600
#include <iostream>
#include <algorithm>

using namespace std;

class SelectionSort
{
 public:
  void solve( int n, int a[] );
};

void SelectionSort::solve( int n, int a[] )
{
  int cnt = 0;
  int mini;

  for( int i = 0; i < n; i++)
    {
      mini = i;
      for( int j = i; j < n; j++)
        {
          if( a[j] < a[mini] )
            mini = j;
        }
      if( i != mini )
        {
          swap(a[i], a[mini]);
          cnt++;
        }
    }

  cout << a[0];
  for( int i = 1; i < n; i++ )
    {
      cout << " " << a[i] ;
    }
  cout << endl;
  cout << cnt << endl;
}

int main( void )
{
  int n;
  int a[100];

  SelectionSort *ss = new SelectionSort();

  cin >> n;

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

  ss -> solve( n, a );

  delete ss;

  return 0;
}

Measured memory_bytes: 1192
w,h,n = map(int,input().split(" "))

s = [[0 for i in range(w)] for j in range(h)]
for k in range(n):
    a,b,c = map(int,input().split(" "))
    if c == 1:
        for i in range(h):
            for j in range(a):
                if s[i][j] == 0:
                    s[i][j] = 1                 
    elif c == 2:
        for i in range(h):
            for j in range(a,w):
                if s[i][j] == 0:
                    s[i][j] = 1   
    elif c == 3:
        for j in range(b):
            for i in range(w):
                if s[j][i] == 0:
                    s[j][i] = 1   
    else:
        for j in range(b,h):
            for i in range(w):
                if s[j][i] == 0:
                    s[j][i] = 1   

counter = 0
for i in range(w):
    for j in range(h):
        if s[j][i] == 0:
            counter += 1
print(counter)


Measured memory_bytes: 3188
from collections import deque, defaultdict
from copy import deepcopy
import sys
import resource

sys.setrecursionlimit(10**5)

N ,u, v = map(int,input().split())
graph = defaultdict(deque)
for _ in range(1,N):
    a, b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)

depth = dict(zip(list(range(1,N+1)),[-1]*N))

def bfs(s):
    if graph[s]:
        for v in graph[s]:
            if depth[v] == -1:
                depth[v] = depth[s] + 1
                bfs(v)

depth = dict(zip(list(range(1,N+1)),[-1]*N))
depth[v] = 0
bfs(v)
depth_v = deepcopy(depth)

depth = dict(zip(list(range(1,N+1)),[-1]*N))
depth[u] = 0
bfs(u)
depth_u = depth
depth_v = sorted(depth_v.items(), key = lambda x:x[0])
depth_u = sorted(depth_u.items(), key= lambda x:x[0])

MAX = 0
for v,u in zip(depth_v, depth_u):
    if u[1] < v[1]:
        MAX = max(MAX,v[1])
print(MAX-1)


Measured memory_bytes: 186640
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=5e5;
int n,K,w[N];
int main()
{
    scanf("%d%d",&n,&K);
    for(int i=1;i<=n;i++)scanf("%d",w+i);
    long long presum=0,sufsum=0,sum=0;
    for(int i=K;i<=n;i++)if(w[i]>0)sufsum+=w[i];
    for(int i=1;i<K;i++)sum+=w[i];long long ans=0;
    for(int i=K;i<=n;i++)
    {
        sum+=w[i]-w[i-K];if(w[i]>0)sufsum-=w[i];
        if(w[i-K]>0)presum+=w[i-K];
        ans=max(ans,max(sum,0ll)+sufsum+presum);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4136
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

/*
 * Union-Find tree
 * header requirement: vector
 */
class UnionFind {
private:
  std::vector<int> disj;
  std::vector<int> rank;
public:
  UnionFind(int n) : disj(n), rank(n) {
    for (int i = 0; i < n; ++i) {
      disj[i] = i;
      rank[i] = 0;
    }
  }
  int root(int x) {
    if (disj[x] == x) {
      return x;
    }
    return disj[x] = root(disj[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }
    if (rank[x] < rank[y]) {
      disj[x] = y;
    } else {
      disj[y] = x;
      if (rank[x] == rank[y]) {
	++rank[x];
      }
    }
  }
  bool is_same_set(int x, int y) {
    return root(x) == root(y);
  }
};


using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;


int gcd(int x, int y) {
  while (y != 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}


const int B = 46;


int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll k;
  cin >> k;
  while (gcd(k, 10) != 1) {
    k /= gcd(k, 10);
  }
  UnionFind uf(k);
  REP(i, 0, k) {
    uf.unite(i, (10 * i) % k);
  }
  vector<vector<bool> > dp(B, vector<bool>(k, false));
  dp[0][0] = true;
  REP(u, 1, B) {
    REP(b, 1, 10) {
      int d = k * b % 10;
      int c = k * b / 10;
      if (u >= d) {
	REP(i, 0, k) {
	  int teni = uf.root(i);
	  dp[u][teni] = dp[u][teni] || dp[u - d][uf.root((i + c) % k)];
	}
      }
    }
    if (0) {
      cerr << "u = " << u << endl;
      cerr << "dp";
      REP(i, 0, k) {
	if (uf.root(i) == i) {
	  cerr << i << ": " << dp[u][i] << endl;
	}
      }
      cerr << endl;
    }
  }
  int mi = 1e8;
  REP(u, 1, B) {
    if (dp[u][0]) {
      mi = min(mi, u);
    }
  }
  cout << mi << "\n";
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define prl(x) cout<<(x)<<endl

int main(void){
  string s,t;map<char,vl>c;cin>>s>>t;ll n=s.length(),cur=0;
  rep(i,n)c[s[i]].push_back(i);
  for(char a:t){
    vl& v=c[a];if(!v.size()){prl(-1);return 0;}
    auto it=lower_bound(v.begin(),v.end(),cur%n);
    (cur=cur/n*n+1)+=it==v.end()?*(v.begin())+n:*it;
  }
  prl(cur);return 0;
}


Measured memory_bytes: 4588
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll X[3];
    cin >> X[0] >> X[1] >> X[2];

    sort(X, X + 3);
    
    ll ans = 0;
    while(X[2] - X[1] > 1){
        ans++;
        X[1] += 2;
    }
    while(X[2] - X[0] > 1){
        ans++;
        X[0] += 2;
    }
    if(X[2] - X[1] == 1 && X[2] - X[0] == 1){
        ans++;
    }else if(X[2] - X[1] == 1 || X[2] - X[0] == 1){
        ans += 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
const int N=15;
const int inf=0x3f3f3f3f;
int n,m,x,c[N],a[N][N],ans=inf,t[N];
void dfs(int cur,int cost)
{
    if(cur==n+1){
        for(int i=1;i<=m;i++)if(t[i]<x)return ;
        ans=min(ans,cost);
        return ;
    }
    for(int i=1;i<=m;i++)t[i]+=a[cur][i];
    dfs(cur+1,cost+c[cur]);
    for(int i=1;i<=m;i++)t[i]-=a[cur][i];
    dfs(cur+1,cost);
}
int main()
{
    cin>>n>>m>>x;
    for(int i=1;i<=n;i++){
        cin>>c[i];
        for(int j=1;j<=m;j++)cin>>a[i][j];
    }
    dfs(1,0);
    if(ans==inf)ans=-1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int d, n; cin >> d >> n;
	int sum = 0;
	for(int i=0; i<n; i++) {
		int t; cin >> t;
		sum += t;
	}
	if(sum > d) cout << -1 << endl;
	else cout << d-sum << endl;
}

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

using namespace std;

int n, dp[3], a[3];

int main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    while (n --) {
        int tmp[3];
        for (int i = 0; i < 3; ++i) cin >> a[i];
        tmp[0] = max(dp[1], dp[2]) + a[0];
        tmp[1] = max(dp[0], dp[2]) + a[1];
        tmp[2] = max(dp[0], dp[1]) + a[2];
        for (int i = 0; i < 3; ++i) dp[i] = tmp[i];
    }

    cout << max(dp[0], max(dp[1], dp[2]) );

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define double long double
#define vi vector<int>
#define vpi vector<pair<int,int> >
#define mii map<int,int>
#define mpi map<pair<int,int>,int>
#define msi map<string,int>
#define set set<int>
#define u_set unordered_set<int>
#define pb push_back
#define endl "\n"
#define ll long long int
#define vll vector<long long int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define umap unordered_map 
#define mod 1000000007
#define fori(a,n) for(int i=a;i<n;i++)
#define forj(a,n) for(int j=a;j<n;j++)
#define MAX 300303
#define V vector
using namespace std;
int H,W;
char a;
V<V<char>> grid(1001,V<char>(1001));
vvi dp(1001,vi(1001,-1));
int rec(int i,int j){
    if(i >= H || j >= W || grid[i][j] == '#')return 0;
    if(i == H-1 && j == W-1)return 1;
    if(dp[i][j] != -1)return dp[i][j];
    dp[i][j] = (rec(i+1,j) + rec(i,j+1));
    if(dp[i][j] > mod)dp[i][j] -= mod;
    return dp[i][j];
}
signed main()
{
    io
    cin >> H >> W;
    fori(0,H)
        forj(0,W)
            cin >> grid[i][j];
    cout << rec(0,0) << endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  vector<bool> dp(K + 1, false);
  for (int i = 1; i <= K; i++) {
    for (int j : a) {
      if (i - j >= 0) {
        if (dp.at(i) || !(dp.at(i - j))) {
          dp.at(i) = true;
        }
      }

    }
  }
  if (dp.at(K)) {
    cout << "First" << endl;
  }
  else {
    cout << "Second" << endl;
  }
  return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#define all(x) (x).begin(),(x).end()
typedef long long ll;

using namespace std;

int main()
{
    int N,ans,a;    cin >> N;
    ans = 0;
    for(int i=1;i<=N;i++){
        cin >> a;
        if(i%2==1 && a%2==1)    ans++;
    }
    cout << ans;
}

Measured memory_bytes: 3632