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

typedef long long ll;
 
int main(){
  ll n, w;
  cin >> n >> w;
  vector<vector<ll>> val(4);
  ll w_b;
  for(int i=0; i<n; i++){
    ll wi, vi;
    cin >> wi >> vi;
    if(i==0) w_b = wi;
    val[wi-w_b].push_back(vi);
  }
  for(int i=0; i<4; i++){
    sort(val[i].begin(), val[i].end(), greater<int>());
    val[i].insert(val[i].begin(),0);
    for(int j=1; j<val[i].size(); j++){
      val[i][j] += val[i][j-1];
    }
  }
  ll ans = 0;
  for(ll i=0; i<val[0].size(); i++){
    for(ll j=0; j<val[1].size(); j++){
      for(ll k=0; k<val[2].size(); k++){
        for(ll l=0; l<val[3].size(); l++){
          if(i*w_b + j*(w_b+1) + k*(w_b+2) + l*(w_b+3) > w) continue;
          ans = max(ans, val[0][i]+val[1][j]+val[2][k]+val[3][l]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) {
        System.out.println(process(readAll(System.in)));
    }

    protected static String process(String data) {
        final String[] lines = splitForLines(data);

        StringBuilder sb = new StringBuilder();

        for (String line : lines) {
            final int[] split = split(line);

            int height = split[0];
            int width = split[1];

            if (height == 0 && width == 0) {
                break;
            }

            if (sb.length() > 0) {
                sb.append("\n");
            }

            sb.append(rectangle(width, height));
        }

        return sb.toString();
    }

    static String rectangle(int width, int height) {
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {

                if (i != 0 && i != (height - 1) && j != 0 && j != (width - 1)) {
                    sb.append('.');
                    continue;
                }

                sb.append('#');
            }
            sb.append('\n');
        }

        return sb.toString();
    }

    private static String readAll(InputStream is) {
        InputStreamReader r = null;
        BufferedReader br = null;

        try {
            r = new InputStreamReader(is);
            br = new BufferedReader(r);
            StringBuilder sb = new StringBuilder();
            String s;

            while ((s = br.readLine()) != null) {
                sb.append(s).append('\n');
            }

            return sb.toString();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                }
            }
            if (r != null) {
                try {
                    r.close();
                } catch (IOException e) {
                }
            }
        }
    }

    private static int[] split(String s) {
        final String[] s0 = s.split(" ");
        int[] ia = new int[s0.length];

        for (int i = 0; i < s0.length; i++) {
            ia[i] = Integer.parseInt(s0[i]);
        }

        return ia;
    }

    private static String[] splitForLines(String lines) {
        return lines.split("\\n");
    }

}

Measured memory_bytes: 23156
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<int> suzu(10);
    for(int i=0; i<10; i++){
        cin >> suzu[i];
    }
    sort(suzu.begin(),suzu.end());
    vector<int> ken(10);
    for(int i=0; i<10; i++){
        cin >> ken[i];
    }
    sort(ken.begin(),ken.end());
    int sum1=0,sum2=0;
    for(int i=9; i>=7; i--){
        sum1 += suzu[i];
        sum2 += ken[i];
    }
    cout << sum1 << " " << sum2 << enld;
    return 0;
}



Measured memory_bytes: 3176
import java.awt.*;
import java.io.*;
import java.util.*;
 
public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new TestA().doIt();
	}
	class TestA{
		void doIt() {
			int D = sc.nextInt();
			int T = sc.nextInt();
			int S = sc.nextInt();
			int ans = (int)Math.ceil(1.0*D / S);
			if(ans <= T) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 35632
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

const int dy[] = {-1, 0, 0, 1};
const int dx[] = {0, -1, 1, 0};
int w, h;
string a[50];
int isW[50][50], isB[50][50];

void dfs1(int y, int x) {
    isW[y][x] = 1;
    REP (i, 4) {
        int ny = y + dy[i];
        int nx = x + dx[i];
        if (ny >= 0 && ny < h && nx >= 0 && nx < w && !isW[ny][nx] && a[ny][nx] != 'B') {
            dfs1(ny, nx);
        }
    }
}

void dfs2(int y, int x) {
    isB[y][x] = 1;
    REP (i, 4) {
        int ny = y + dy[i];
        int nx = x + dx[i];
        if (ny >= 0 && ny < h && nx >= 0 && nx < w && !isB[ny][nx] && a[ny][nx] != 'W') {
            dfs2(ny, nx);
        }
    }
}

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

    while (cin >> w >> h, w) {
        memset(isW, 0, sizeof(isW));
        memset(isB, 0, sizeof(isB));
        REP (i, h) cin >> a[i];
        REP (i, h) REP (j, w) if (a[i][j] == 'W') {
            dfs1(i, j);
        }
        REP (i, h) REP (j, w) if (a[i][j] == 'B') {
            dfs2(i, j);
        }
        int numW = 0, numB = 0;
        REP (i, h) REP (j, w) if (a[i][j] == '.') {
            if (isW[i][j] && !isB[i][j]) numW++;
            if (!isW[i][j] && isB[i][j]) numB++;
        }
        cout << numB << " " << numW << endl;
    }
}


Measured memory_bytes: 3288
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
//ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll X, Y;
	cin >> X >> Y;
	for(ll i = 0;; i++) {
		if(Y < powl(2, i + 1) * X) {
			cout << i + 1 << endl;
			return 0;
		}
	}
}


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

int main(){ 
  string s;
  long k;
  cin >> s >> k;
  int i;
  for(i = 0;i < s.size();i++){
    if(s.at(i) != '1'){
      break;
    }
  }
  if(i > k-1){
    cout << '1' << endl;
  }
  else{
    cout << s.at(i)  << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    string A, B, C;
    cin >> A >> B >> C;
    if (A.back() != B.front()) {
        cout << "NO" << endl;
    } else if (B.back() != C.front()) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (){
	int bi[3][3];
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			scanf("%d", &bi[i][j]);
		}
	}
	int ce[3][3] = {};
	int n;
	scanf("%d", &n);
	int in[n];
	for(int i = 0; i < n; i++){
		scanf("%d", &in[i]);
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 3; k++){
				if(in[i] == bi[j][k]){
					ce[j][k]++;
					if((ce[0][0] > 0 && ce[0][1] > 0 && ce[0][2] > 0) || (ce[1][0] > 0 && ce[1][1] > 0 && ce[1][2] > 0) || (ce[2][0] > 0 && ce[2][1] > 0 && ce[2][2] > 0) || (ce[0][0] > 0 && ce[1][0] > 0 && ce[2][0] > 0) || (ce[0][1] > 0 && ce[1][1] > 0 && ce[2][1] > 0) || (ce[0][2] > 0 && ce[1][2] > 0 && ce[2][2] > 0) || (ce[0][2] > 0 && ce[1][1] > 0 && ce[2][0] > 0) || (ce[0][0] > 0 && ce[1][1] > 0 && ce[2][2] > 0)){
						puts("Yes");
						return 0;
					} 
				}
			}
		}
	}
	puts("No");	


	return 0;
}


Measured memory_bytes: 1644
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7

def main():
    n,a,b = map(int,ipt().split())
    h = [int(ipt()) for i in range(n)]
    l = 1
    r = 10**10
    while l != r:
        mid = l + (r-l)//2
        nm = 0
        for i in h:
            nm += max(0,math.ceil((i-b*mid)/(a-b)))
        if nm > mid:
            l = mid+1
        else:
            r = mid

    print(l)
    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 80260
#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)++)

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

    int n;
    string a, b, c;
    cin >> n;
    cin >> a >> b >> c;

    int sol = 0;
    FOR(i, n){
        set<char> S;
        S.insert(a[i]);
        S.insert(b[i]);
        S.insert(c[i]);

        if (S.size() == 3)
            sol += 2;
        else if (S.size() == 2)
            sol += 1;
    }
    cout << sol;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;

class Main {
  
  static int H,W;
  static String[][] map;
  static int[][] breadth;
  static Deque<Integer[]> que;
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    H = sc.nextInt();
    W = sc.nextInt();
    map = new String[H][W];
    breadth = new int[H][W];
    que = new ArrayDeque<>();
    for (int i = 0; i < H; i++) map[i] = sc.next().split("");
    que.add(new Integer[]{0, 0});
    int b = 1;
    breadth[0][0] = b;
    while (!que.isEmpty()) {
      int n = que.size();
      b++;
      for (int i = 0; i < n; i++) {
        Integer[] p = que.poll();
        search(b, p[0]-1, p[1]);
        search(b, p[0], p[1]+1);
        search(b, p[0], p[1]-1);
        search(b, p[0]+1, p[1]);
      }
    }
    long wallNum = Arrays.stream(map).flatMap(e -> Arrays.stream(e))
      .filter(e -> e.equals("#"))
      .count();
    System.out.println(breadth[H-1][W-1] == 0 ? -1 : H*W-wallNum-breadth[H-1][W-1]);
    //for (int i = 0; i < H; i++) System.out.println(Arrays.toString(breadth[i]));
  }
  
  static void search(int b, int h, int w) {
    if (h < 0 | h >= H | w < 0 | w >= W) return;
    if (map[h][w].equals("#")) return;
    if (breadth[h][w] != 0) return;
    breadth[h][w] = b;
    que.add(new Integer[]{h, w});
  }
}

Measured memory_bytes: 38800
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
int main() {
	int n, a[100001], l[100001];
	cin >> n;
	for (int i = 0; i < n; i++) 
		cin >> a[i + 1];
	l[1] = a[1];
	int le = 1;
	for (int i = 1; i <= n; i++) {
		if (a[i] > l[le]) {
			l[++le] = a[i];
		 }
		else *lower_bound(l + 1, l + le + 1, a[i]) = a[i];
	}
	cout << le << endl;
	return 0;
}

Measured memory_bytes: 3788
n,m = map(int,input().split())
c = list(map(int,input().split()))
dp = [[10000000000]*m for _ in range(n+1)]
dp[0] = [0]*m

"""
m i 枚数
n j 金額

"""

for j in range(1,n+1):
  for i in range(m):
    v = c[i]
    if j >= v:
      dp[j][i] = min(dp[j][i-1],dp[j-v][i-1]+1,dp[j-v][i]+1)
    else:
      dp[j][i] = dp[j][i-1]
      
print(dp[n][m-1])


Measured memory_bytes: 19924
n,*t=map(int,open(0).read().split());A=t[:n];c=B=t[n:];r=0
while c:
 c=0
 for i in range(n):b=B[~-i%n]+B[-~i%n];t=(A[i]<B[i]>b)*(B[i]-A[i])//b;c+=t;B[i]-=t*b
 r+=c
print([-1,r][A==B])

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

int main() {
	int a, b, c;

	cin >> a >> b >> c;

	if (c >= a) {
		if (c <= b) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main() {
	IN(int, n);
	IN(string, s);
	
	vector<int> f(n + 1);
	inc1(i, n) {
		int c = 0, x = i;
		while(x % 2 == 0) { c++; x /= 2; }
		f[i] = f[i - 1] + c;
	}
	
	auto comb = [&](int x, int y) { return (f[x] - f[x - y] - f[y] == 0 ? 1 : 0); };
	
	RF(e, s) { e--; }
	bool no1 = true;
	RF(e, s) { no1 &= (e != '1'); }
	
	int ans = 0;
	inc(i, n) {
		if((no1 && s[i] == '2') || (s[i] == '1')) {
			ans += comb(n - 1, i);
		}
	}
	
	OUT(ans % 2 == 0 ? 0 : (no1 ? 2 : 1));
}


Measured memory_bytes: 5252
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		Uf uf=new Uf(s[0]);
		for(int i = 0;i<s[1];i++) {
			var e=sc.Ia;
			uf.Union(e[0]-1,e[1]-1);
		}
		int p=0;
		for(int i = 0;i<s[0];i++) {
			p=Max(p,uf.Size(i));
		}
		Console.WriteLine("{0}",p);
	}
}
public class Uf{
	private int[] arr,hi;
	public int all;
	public Uf(int n){
		arr=new int[n];
		hi=new int[n];
		all=n;
		for(int i=0;i<n;i++){arr[i]=-1;}
	}
	public void Union(int a,int b){
		a=Root(a);
		b=Root(b);
		if(a!=b){
			if(hi[a]<hi[b]){(a,b)=(b,a);}
			arr[a]+=arr[b];
			hi[a]=Max(hi[a],hi[b]+1);
			arr[b]=a;
			all--;
		}
	}
	public bool Same(int a,int b){return Root(a)==Root(b);}
	public int Size(int a){return -arr[Root(a)];}
	public int Root(int a){return arr[a]<0?a:arr[a]=Root(arr[a]);}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 41900
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

int main(void){
	string s; cin >> s;
	int nums=0,ans=s.length();
	for(int i=0; i<s.length(); i++){
		if(s[i]=='S'){
			nums++;
		}else if(s[i]=='T'){
			if(nums){
				ans-=2;nums--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	
	int a, b, c;
	cin >> a >> b >> c;
	int ans;
	if(a == b) ans = c;
	if(c == b) ans = a;
	if(c == a) ans = b;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  CppTest
//
//  Created by Ryu on 2017/02/08.
//  Copyright ?? 2017??´ Ryu. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    long a[200];
    long b[200];
    int keta[200];
    
    int now = 0;
    long p;
    while(cin >> a[now] >> b[now]){
        p = a[now] + b[now];
        int k = 0;
        while(p >= pow(10, k)){
            k++;
        }
        keta[now] = k;
        now++;
        if( !cin.peek() ){
            break;
        }
    }
    
    
    //printf("finished");
    
    for (int i = 0; i < now; i++) {
        cout << keta[i] << endl;
    }
    
    
    return 0;
}

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

int main(void){
	string a, b;
	int c;
	cin >> a >> b;
	c = stoi(a + b);
	for (int i = 1; i <= 1000; i++){
		if (i*i == c){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

ll powmod(ll n, ll k) {
    ll r = 1, t = n % P;
    for (; k != 0; k /= 2) {
        if (k & 1) r = r * t % P;
        t = t * t % P;
    }
    return r;
}
ll modinv(ll n) {
    return powmod(n, P - 2);
}

vector<int> f0, f1;
void init(int n) {
    f0.resize(n + 1);
    f0[0] = 1;
    for (int i = 1; i <= n; i++) {
        f0[i] = (ll)f0[i - 1] * i % P;
    }
    f1.resize(n + 1);
    f1[n] = modinv(f0[n]);
    for (int i = n; i > 0; i--) {
        f1[i - 1] = (ll)f1[i] * i % P;
    }
}
ll fact(int k) {
    return f0[k];
}
ll comb(int n, int k) {
    if (n < k || k < 0) return 0;
    return (ll)f0[n] * f1[k] % P * f1[n - k] % P;
}

struct UnionFind {
    UnionFind(int n) : p(n, -1) {}
    int root(int u) {
        return p[u] < 0 ? u : p[u] = root(p[u]);
    }
    int size(int u) {
        return -p[root(u)];
    }
    bool same(int u, int v) {
        return root(u) == root(v);
    }
    void unite(int u, int v) {
        u = root(u);
        v = root(v);
        if (u == v) return;
        if (p[u] > p[v]) swap(u, v);
        p[u] += p[v];
        p[v] = u;
    }
    vector<int> p;
};

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

    int n;
    cin >> n;

    UnionFind uf(n);
    vector<int> p(n);

    int l = 0, k = n;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        if (p[i] < 0) continue;
        p[i]--;

        k--;
        if (!uf.same(i, p[i])) {
            uf.unite(i, p[i]);
            l++;
        }
    }
    l += k;

    vector<int> b(k + 1, 0);
    b[0] = 1;
    for (int i = 0; i < n; i++) {
        if (p[i] < 0) {
            int a = uf.size(i);
            for (int j = k; j > 0; j--) {
                b[j] = ((ll)b[j - 1] * a + b[j]) % P;
            }
        }
    }
    if (k > 0) b[1] -= k;

    init(k);

    ll r = l * powmod(n - 1, k) % P;
    for (int j = 1; j <= k; j++) {
        (r -= b[j] * fact(j - 1) % P * powmod(n - 1, k - j)) %= P;
    }
    if (r < 0) r += P;

    cout << r << endl;

    return 0;
}

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

using namespace std;

#define min3(a, b, c)           min((a), min((b), (c)))
#define max3(a, b, c)           max((a), max((b), (c)))
#define lcm(a,b)                (a / __gcd(a,b) ) *b
#define gcd(a,b)                __gcd(a,b)
#define dist(x1,y1,x2,y2)       sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define distl(x1,y1,x2,y2)      sqrtl((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define sqr(a)                  ((a)*(a))
#define FOR(a, b)               for(int i=a; i<b; i++)
#define fRead(x)                freopen(x,"r",stdin)
#define fWrite(x)               freopen (x,"w",stdout)
#define pb                      push_back
#define mk                      make_pair
#define ff                      first
#define ss                      second
#define lb                      lower_bound
#define ub                      upper_bound
#define all(a)                  a.begin(),a.end()
#define FASTIO                  ios_base::sync_with_stdio(0);cin.tie(NULL);

int main()
{
    FASTIO

    int n;
    cin >> n;

    vector <int> monstar, hero;

    FOR (0, n+1)
    {
        long long buf;
        cin >> buf;
        monstar.push_back(buf);
    }

    FOR (0, n)
    {
        long long buf;
        cin >> buf;
        hero.push_back(buf);
    }

    long long ans = 0;

    FOR (0,n)
    {

        if (hero[i] >= monstar[i])
        {
            ans += monstar[i];
            hero[i] -= monstar[i];
            monstar[i] = 0;
            if (hero[i] >= monstar[i+1])
            {
                ans += monstar[i+1];
                monstar[i+1] = 0;
            }
            else
            {
                ans += hero[i];
                monstar [i+1] = monstar[i+1] - hero[i];
            }
        }
        else
        {
            ans += hero[i];
        }
    }

    cout << ans;

}




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

typedef long long ll;

int main() {
    ll N, M, V, P;
    cin >> N >> M >> V >> P;
    vector<ll> A(N), s(N + 1, 0);
    rep(i, N) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    rep(i, N) {
        s[i + 1] = s[i] + A[i];
    }
    ll lo = 0, hi = N;
    while (lo + 1 < hi) {
        ll mi = (lo + hi) / 2;
        if (mi > N - P) {
            hi = mi;
            continue;
        }
        if (A[mi - 1] + M < A[N - P]) {
            lo = mi;
            continue;
        }
        if (V <= P - 1 + mi) {
            hi = mi;
            continue;
        }
        ll s2 = s[N - P + 1] - s[mi] + M * max(0LL, V - P + 1 - mi);
        if (s2 <= (A[mi - 1] + M) * (N - P + 1 - mi)) hi = mi;
        else lo = mi;
    }
    cout << N - hi + 1 << "\n";
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S; cin>>S;
    int a=S.size();
    int count=0;
    for(int i=0;i<a/2;i++){
        if(S[i]!=S[a-1-i]){
            count++;
        }
    }
    cout<<count;
    return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

int main(){
    ll n;
    cin >> n;
    ll l[n];
    rep(i,0,n){
        cin >> l[i];
    }

    ll cnt = 0;
    rep(i,0,n){
        rep(j,i+1,n){
            rep(k,j+1,n){
                vector<ll> vec;
                vec.push_back(l[i]);
                vec.push_back(l[j]);
                vec.push_back(l[k]);
                sort(vec.begin(),vec.end());
                vec.erase(unique(vec.begin(),vec.end()),vec.end());

                if(vec.size() != 3) continue;
                if(vec[0] < vec[1] + vec[2]){
                    if(vec[1] < vec[2] + vec[0]){
                        if(vec[2] < vec[0] + vec[1]){
                            cnt++;
                        }
                    }
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int N = 1e5+5;
char s[N];
int main(){
    int n, k, ans = 0, blo = 1; cin >> n >> k;
    scanf("%s", s + 1);
    bool flag = s[1] == 'L';
    for(int i = 1; i <= n; ++i){
        if(s[i] == 'L'){
            ans += s[i-1] == 'L';
            if(!flag) flag = 1, ++blo;
        }
        else{
            ans += s[i+1] == 'R';
            if (flag) flag = 0, ++blo;
        }
    }
    blo -= k << 1;
    if(blo <= 1)ans = n - 1;
    else ans += k << 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

int light[SIZE];
int p[SIZE];

int main(){
  int N, M;

  cin >> N >> M;

  for(int i=0; i<M; i++) {
    int k;
    cin >> k;

    for(int j=0;j<k;j++){
      int s;
      cin >> s;
      light[i] |= 1 << (s - 1);
    }
  }

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

  int ans = 0;

  for(int i=0; i<(1<<N); i++) {
    bool ok = true;

    for(int j=0;j<M;j++){
      ok &= __builtin_popcount(light[j] & i) % 2 == p[j];
    }

    ans += ok;
  }

  cout << ans << endl;

  return 0;
}


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

int calc(int n,int k,int s)
{
	if(s<0) return 0;
	if(k==0) return s==0;
	int res=0;
	while(--n>0) res+=calc(n,k-1,s-n);
	return res;
}

int main()
{
	for(int n,k,s;cin>>n>>k>>s && n|k|s;)
		cout<<calc(n+1,k,s)<<endl;
}

Measured memory_bytes: 1156
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int, K: int):
    seq = list(range(N + 1))
    cumsum = [0] * (N + 2)
    for i in range(N+1):
        cumsum[i+1] = cumsum[i] + seq[i]
    c = [0] * (N + 2)
    for i in range(1, N + 2):
        #[N + 1 - i, N+1) - [0, i)
        c[i] = (cumsum[N+1] - cumsum[N+1-i] - cumsum[i] + 1) % MOD
    print(sum(c[K:]) % MOD)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)


if __name__ == "__main__":
    main()


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

int main(){
  string a;
  cin >> a;
  if(a=="SSS"){
    cout << 0 << endl;
  }
  else if(a=="RRR"){
    cout << 3 << endl;
  }
  else if(a=="RRS" || a=="SRR"){
    cout << 2 << endl;
  }
  else cout << 1 << endl;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int mod=1e9+7;
const int N=1e5+5;

struct node
{
    int l,r;
} da[N];
int cmp(node a,node b)
{
    return a.r<b.r;
}
int main()
{
    int n,x,l;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%d%d",&x,&l);
        da[i].l=x-l;
        da[i].r=x+l;
    }
    sort(da,da+n,cmp);
    int ans=1,tmp=da[0].r;
    for(int i=1; i<n; i++)
        if(da[i].l>=tmp)
        {
            ans++;
            tmp=da[i].r;
        }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;

const int N = 100001;
int dp[N];

int solve(int h[], int n){
	if(n == 0) return 0;
	if(n == 1) return dp[n] = abs(h[1] - h[0]);
	if(dp[n] != -1) return dp[n];
	return dp[n] = min(abs(h[n - 1] - h[n]) + solve(h, n - 1), abs(h[n - 2] - h[n]) + solve(h, n - 2));
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	memset(dp, -1, sizeof(dp));
	int h[n];
	for(int i = 0; i < n; i++) cin >> h[i];
	cout << solve(h, n-1) << endl;
	return 0;
}


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n;
	cin >> n;
	int a[3*n];
	FOR(i,0,3*n)cin >> a[i];
	ll left[n+1],right[n+1];
	priority_queue<int> pq;
	left[0] = 0;
	FOR(i,0,n){
		pq.push(-a[i]);
		left[0] += a[i];
	}
	FOR(i,0,n){
		pq.push(-a[n+i]);
		left[i+1] = left[i] + a[n+i] + pq.top();
		pq.pop();
	}
	right[0] = 0;
	FOR(i,0,n){
		pq.push(a[3*n-1-i]);
		right[0] += a[3*n-1-i];
	}
	FOR(i,0,n){
		pq.push(a[2*n-1-i]);
		right[i+1] = right[i] + a[2*n-1-i] - pq.top();
		pq.pop();
	}
	ll ans = -LLINF;
	FOR(i,0,n+1){
		ans = max(ans, left[i] - right[n-i]);
	}
	ANS(ans);
	return 0;
}


Measured memory_bytes: 3828
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(M)]
c=[[0]*N for i in range(N)]
for a,b in AB:
    c[a-1][b-1]=c[b-1][a-1]=1
from itertools import permutations
r=0
for n in permutations(range(1,N)):
    n=[0]+list(n)
    x=1
    for i in range(N-1):
        if not c[n[i]][n[i+1]]:
            x=0
    r+=x
print(r)

Measured memory_bytes: 3064
/**
 * Created by Wangzhe on 2020/1/12 19:56.
 * Description: 
 **/


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define fi first
#define se second
#define MEM(a, b) memset((a),(b),sizeof(a))
#define mod(x) ((x)%MOD)
#define pii pair<int,int>
#define wz cout<<"-----"<<endl;

const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;

const ll maxn = 1e5 + 10, MOD = 1e9 + 7;

void init() {

}

int a[maxn];
int b[maxn];

void solve() {
    int n,m; cin >> n >> m;
    int sum = 0,cnt = 0;
    for (int i = 0; i < m; i++) {
        int x; cin >> x;
        string s; cin >> s;
        if (a[x]) continue;
        if (s == "AC") {
            a[x] = 1;
            cnt++;
            sum += b[x];
        } else {
            b[x]++;
        }
    }
    cout << cnt << ' ' << sum << endl;
}

int main() {
    init();
    solve();

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	String worm;

	void run(){
		for(;;){
			worm=sc.next();
			if(worm.equals("0")){
				break;
			}
			solve();
		}
	}

	void solve(){
		LinkedList<String> que=new LinkedList<String>();
		TreeSet<String> set=new TreeSet<String>();
		HashMap<String, Integer> map=new HashMap<String, Integer>();
		que.add(worm);
		set.add(worm);
		map.put(worm, 0);
		for(; !que.isEmpty();){
			String s=que.poll();
			boolean f=true;
			for(int i=0; i<s.length(); i++){
				f&=s.charAt(0)==s.charAt(i);
			}
			// debug(s,map.get(s));
			if(f){
				println(""+map.get(s));
				return;
			}
			for(String t : next(s)){
				if(!set.contains(t)){
					que.offer(t);
					set.add(t);
					map.put(t, map.get(s)+1);
				}
			}
		}
		println("NA");
	}

	LinkedList<String> next(String s){
		LinkedList<String> list=new LinkedList<String>();
		for(int i=0; i<s.length()-1; i++){
			if(s.charAt(i)!=s.charAt(i+1)){
				char c='*';
				switch(s.charAt(i)+s.charAt(i+1)){
				case 'r'+'g':
					c='b';
					break;
				case 'g'+'b':
					c='r';
					break;
				case 'b'+'r':
					c='g';
					break;
				}
				list.add(s.substring(0, i)+c+c
						+(i<s.length()-2?s.substring(i+2, s.length()):""));
			}
		}
		return list;
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 17000
def main():
    n, d = map(int, input().split(' '))
    l = [list(map(int, input().split(' '))) for _ in range(n)]
    a = [distance(d, l[i], l[j]) for i in range(n) for j in range(i+1, n)]
    ans = [1 if i == i//1 else 0 for i in a]
    print(sum(ans))


def distance(d, x, y):
    x_y = [x[i] - y[i] for i in range(d)]
    return sum([i ** 2 for i in x_y]) ** 0.5


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <math.h>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main() {
    double x1, x2, xp, y1, y2, yp, slope, ansx, ansy;
    int    q;
    bool   X_FLG = false, Y_FLG = false;

    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    scanf("%d", &q);

    if (y1 == y2) {
        X_FLG = true;
    } else if (x1 == x2) {
        Y_FLG = true;
    } else {
        slope = (y2 - y1) / (x2 - x1);
    }

    for (int i = 0; i < q; i++) {
        scanf("%lf %lf", &xp, &yp);
        if (X_FLG) {
            ansx = xp, ansy = y1;
            printf("%.10lf %.10lf\n", 2 * ansx - xp, 2 * ansy - yp);
        } else if (Y_FLG) {
            ansx = x1, ansy = yp;
            printf("%.10lf %.10lf\n", 2 * ansx - xp, 2 * ansy - yp);
        } else {
            ansx = (yp * (x2 - x1) * (y2 - y1) + xp * (x2 - x1) * (x2 - x1) -
                    y1 * (y2 - y1) * (x2 - x1) + x1 * (y2 - y1) * (y2 - y1)) /
                   ((y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1));
            ansy = ((x1 - x2) * ansx + yp * (y2 - y1) + xp * (x2 - x1)) /
                   (y2 - y1);
            printf("%.10lf %.10lf\n", 2 * ansx - xp, 2 * ansy - yp);
        }
    }

    return 0;
}


Measured memory_bytes: 2752
program main;
var
	num, i, sum : int64;
begin
	read(num);
    
    sum := 0;
    
    for i := 1 to num do begin
    	if (frac(i/3) = 0) or (frac(i/5) = 0)
        	then sum := sum + 0
        	    else sum := sum + i;
    end;
 	writeln(sum);
end.

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

int main(){
    int K, S;
    scanf("%d %d", &K, &S);

    int cnt = 0;
    for(int i = 0; i <= K; i++){
        for(int j = 0; j <= K; j++){
            int z = S - i - j;
            if(0 <= z and z <= K){
                cnt++;
            }
        }
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 256
/*
 */

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// std::ios::sync_with_stdio(false);

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int G[10][10];

int main()
{
    int H,W;
    while (cin >> H >> W) {
        FOR(i,0,10) FOR(j,0,10)
            cin >> G[i][j];
        FOR(k,0,10) FOR(i,0,10) FOR(j,0,10)
            G[i][j] = min(G[i][j], G[i][k]+G[k][j]);
        int D[10] = {0};
        FOR(i,0,H) FOR(j,0,W) {
            int x; cin >> x;
            if (x != -1)
                D[x]++;
        }
        int ans = 0;
        FOR(i,0,10)
            ans += D[i] * G[i][1];
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math
N = int(input())

#for n in range(1,N+1):
dict = {}
for i in range(1,N+1):
    dict[i] = 0
max_n =  int(math.sqrt(N))
#cnt = 0
for i in range(1,max_n+1):
    for j in range(1,max_n+1):
        for k in range(1,max_n+1):
            val =  i*i + j*j + k*k + i*j + i*k + j*k
            if val in dict:
                dict[val] += 1
                    #cnt += 1
for i in range(1,N+1):
    print(dict[i])


Measured memory_bytes: 9752
#include<iostream>
#include <vector>
#include <algorithm>

int main() {

	using namespace std;

	int a, b, c, ans = 0;

	cin >> a >> b >> c;

	for (int i = 1; i * i <= c; i++) {

		if (c % i == 0) {

			if (i >= a && i <= b) {
				ans++;
			}
			if (c / i != i && (c / i >= a && c / i <= b)) {
				ans++;
			}

		}

	}

	cout << ans << endl;

	return 0;

}


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

using namespace std;

const int MAX_H = 100000, MAX_W = 100000;
const long long INF = (long long)(MAX_H) * (long long)(MAX_W) + 1;

long long h, w, ans = INF;

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

    cin >> h >> w;

    if (h > 2) {
        ans = min(ans, w);

        if (h % 3 == 0) {
            ans = 0;
        }
    }

    if (w > 2) {
        ans = min(ans, h);

        if (w % 3 == 0) {
            ans = 0;
        }
    }

    for (int i = 1; i < h; i++) {
        ans = min(ans, max((h - i) * w, i * ((w + 1) / 2)) - min((h - i) * w, i * (w / 2)));
    }

    for (int i = 1; i < w; i++) {
        ans = min(ans, max((w - i) * h, i * ((h + 1) / 2)) - min((w - i) * h, i * (h / 2)));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (int)(s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
constexpr long long INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}

int A,B,C,D,E,F,G,X,Y,Z,N,M,W;
string s,t;

signed main(){
	int N,K,Q;
	cin>>N>>K>>Q;
	vector<int>a(N,K-Q);
	REP(i,Q){
		int t;
		cin >> t;
		a[t-1]++;
	}
	REP(i,N){
		if(a[i]>0)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}

Measured memory_bytes: 1536
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Created: Jul, 12, 2020 18:27:48 by Nobody
# $Author$
# $Date$
# $URL$
__giturl__ = "$URL$"


from sys import stdin
input = stdin.readline


def main():
  N, M = list(map(int, input().split()))
  A = set([int(input()) for _ in range(M)])

  dp = [0]*(N+1)
  dp[0] = 1
  dp[1] = 0 if 1 in A else 1

  for i in range(2, N+1):
    if i in A:
      dp[i] = 0
      continue
    dp[i] = (dp[i-1] + dp[i-2]) % 1_000_000_007

  print(dp[N] % 1_000_000_007)


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


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

int main()
{
  int n;
  string s;
  cin >> n >> s;

  int cnt = 0, pre = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == '(') cnt++;
    else{
      cnt--;
      if(cnt < 0) pre = max(pre, -cnt);
    }
  }

  for(int i = 0; i < pre; i++) s = "(" + s;
  n += pre;

  cnt = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == '(') cnt++;
    else cnt--;
  }

  for(int i = 0; i < cnt; i++) s = s + ")";

  cout << s << endl;

  return 0;
}

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

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

using namespace std;

int main() {
    int d, t, s;
    cin >> d >> t >> s;

    if (d > t * s) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3644
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
    int k, n;
    cin >> k >> n;

    vector<int> a(n);
    for (int& e : a) {
        cin >> e;
        e %= k;
    }

    sort(a.begin(), a.end());

    vector<int> diff(n);
    diff[0] = k - a[n - 1] + a[0];
    for (int i = 1; i < n; i++) {
        diff[i] = a[i] - a[i - 1];
    }

    sort(diff.begin(), diff.end());

    ll sum = std::accumulate(diff.begin(), diff.end() - 1, 0);
    cout << sum << "\n";

    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    try {
      int a = scanner.nextInt();
      int b = scanner.nextInt();
      int k = scanner.nextInt();
      if (a + k * 2 - 1 < b) {
        for (int i = 0; i < k; i++) {
          System.out.println(a+i);
        }
        for (int i = 0; i < k; i++) {
          System.out.println(b-k+1+i);
        }
      } else {
        for (int i = a; i <= b; i++) {
          System.out.println(i);
        }
      }
    } finally {
      scanner.close();
    }
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long
#define MAX 1000001
#define mod 1000000007
#define pie 3.14159265358979323846
void solve()
{
	int n,i,mini1=MAX,mini2=MAX,j;
	cin>>n;
	int a[n+1];
	for(i=1;i<=n;i++)
	cin>>a[i];
	map<int,int> mp1;
	map<int,int> mp2;
	map<int,int> mp3;
	vector< pair<int,int> > v1;
	vector< pair<int,int> > v2;
	for(i=1;i<=n;i++){
		if(i%2!=0)
		mp1[a[i]]++;
		else
		mp2[a[i]]++;
	}
	for(i=1;i<=100000;i++){
		if(mp1[i]!=0)
		v1.push_back(make_pair(mp1[i],i));
		if(mp2[i]!=0)
		v2.push_back(make_pair(mp2[i],i));
	}
	sort(v1.begin(),v1.end(),greater< pair<int,int> >());
	sort(v2.begin(),v2.end(),greater< pair<int,int> >());
	for(i=0;i<v1.size();i++){
		int ans=0,k,f=0;
		ans+=(n/2)-v1[i].first;
		k=v1[i].second;
		for(j=0;j<v2.size();j++){
			if(v2[j].second!=k){
				ans+=(n/2)-v2[j].first;
				f=1;
				break;
			}
		}
		if(f==1)
		mini1=min(mini1,ans);
		else{
			ans+=(n/2);
			mini1=min(mini1,ans);
		}
	}
	for(i=0;i<v2.size();i++){
		int ans=0,k,f=0;
		ans+=(n/2)-v2[i].first;
		k=v2[i].second;
		for(j=0;j<v1.size();j++){
			if(v1[j].second!=k){
				ans+=(n/2)-v1[j].first;
				f=1;
				break;
			}
		}
		if(f==1)
		mini1=min(mini1,ans);
		else{
			ans+=(n/2);
			mini1=min(mini1,ans);
		}
	}
	cout<<min(mini1,mini2);
}
int main()
{ 
    cool;
    int t;
    //cin>>t;
    t=1;
    while(t--){
    	solve();
	}
    return 0;
}


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

  return 0;
}


Measured memory_bytes: 256