akhauriyash/Code-Regression huggingface dataset:
N, M = list(map(int, input().split()))
S = [0]*M
answer = 0

for i in range(M):
    S[i] = list(map(int, input().split()))

P = list(map(int, input().split()))

for i in range(2**N):
    mb = '0' + str(N) + 'b'
    bi = format(i, mb)
    count = 0
    for j in range(M):
        on = 0
        for k in range(S[j][0]):
            on += int(bi[-S[j][k+1]])
        if on%2 == P[j]:
            count += 1
    if count == M:
        answer += 1

print(answer)

Measured memory_bytes: 9228
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int H = sc.nextInt();
		int W = sc.nextInt();
		int h = sc.nextInt();
		int w = sc.nextInt();

		System.out.println((H-h)*(W-w));

	}

}



Measured memory_bytes: 22868
S = input()
N = len(S)
prev = S[0]
ans = 1
i = 1
while i < N:
  ans += 1
  if len(prev) == 2:
    prev = S[i]
    i += 1
    continue
  if prev == S[i] and i < N-1:
    prev = S[i] + S[i+1]
    i += 2
  elif prev == S[i]:
    ans -= 1
    break
  else:
    prev = S[i]
    i += 1
print(ans)

Measured memory_bytes: 3500
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████   
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬╬╬██╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓▓█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████  
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF 1LL<<60
#define fs first
#define sc second
#define pb push_back
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define debug(x)  cout << #x << " = " << (x) << endl;
typedef pair<int,int> P;
typedef vector<vector<P>> Graph;

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

  string s;
  cin >> s;

  int ans = 753;
  REP(i,s.size()-2){
    int x = 0;
    x = 100*(s[i]-'0') + 10*(s[i+1]-'0') + (s[i+2]-'0');
    //debug(x);
    ans = min(ans,abs(753-x));
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>

using namespace std;

/*迷路
const int INF = 50;

typedef pair<int,int> P;
char field[52][52];
int d[51][51];
int r,c;
int sx,sy;
int gx,gy;

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

int bfs(){
    queue<P> que;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            d[i+1][j+1] = INF;
        }
    }
    que.push(P(sy,sx));
    d[sy][sx]=0;
while(que.size()){
    P p=que.front();
    que.pop();
    if(p.second==gx&&p.first==gy) break;
    for(int i=0;i<4;i++){
        int nx=p.second+dx[i];
        int ny=p.first+dy[i];

        if(1<=nx&&nx<=c&&1<=ny&&ny<=r&&field[ny][nx]!='#'&&d[ny][nx]==INF){
            que.push(P(ny,nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }
}
return d[gy][gx];
}
*/
int main(){
    int a,b;
    cin >> a >> b;
    int sum=0;
    if(a<b) {
        sum +=b;
        b--;
    }
    else{
        sum+=a;
        a--;
    }
    if(a<b) {
        sum +=b;
        b--;
    }
    else{
        sum+=a;
        a--;
    }
    cout <<sum<<'\n';
    return 0;  
}

Measured memory_bytes: 256
s=input()
s1=s[0:2]
s2=s[2:4]
a=["01","02","03","04","05","06","07","08","09","10","11","12"]

if (s1 in a) and (s2 in a):
    print("AMBIGUOUS")
elif s1 in a:
    print("MMYY")
elif s2 in a:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
N, M, S = gets.split.map(&:to_i)
@g, amax = Array.new(N + 1){[]}, 0
M.times do
  u, v, a, b = gets.split.map(&:to_i)
  @g[u] << [v, a, b]; @g[v] << [u, a, b]
  amax = a if a > amax
end
CDs = [nil]
N.times{CDs << gets.split.map(&:to_i)}
MAX = amax*(N - 1)

class Stop
  include Comparable
  attr_accessor :i, :t, :m

  def initialize(i, t, m)
    @i, @t, @m = i, t, [m, MAX].min
  end

  def <=>(other)
    @t <=> other.t
  end
end

class PriorityQueue
  def initialize
    @q = [nil]
  end

  def bubble_up(i)
    pi = i / 2
    return if i <= 1 || @q[pi] <= @q[i]
    @q[i], @q[pi] = @q[pi], @q[i]
    bubble_up(pi)
  end

  def add(e)
    @q << e
    bubble_up(@q.size - 1)
  end

  def bubble_down(i)
    ci = i * 2
    return if ci > @q.size - 1
    ci += 1 if ci != @q.size - 1 && @q[ci] > @q[ci + 1]
    return if @q[i] <= @q[ci]
    @q[i], @q[ci] = @q[ci], @q[i]
    bubble_down(ci)
  end

  def pop
    @q[1], @q[-1] = @q[-1], @q[1]
    ret = @q.pop
    bubble_down(1)
    ret
  end

  def empty?
    @q.size == 1
  end
end

class City
  attr_accessor :mi_t, :mx_m, :mi_m
  def initialize
    @mi_t, @mx_m, @mi_m = nil, -1, 0
  end
end

f = ->(x, y, a, b){t = (y - x + a - 1)/a; [t*a, t*b]}
cs, cs0 = [nil] + N.times.map{City.new}, Array.new(N + 1, nil)
q = PriorityQueue.new; q.add(Stop.new(1, 0, S))
ct = 0
while !q.empty?
  c = q.pop
  i, t, m = c.i, c.t, c.m
  next if m <= cs[i].mx_m
  cs[i].mx_m = m
  unless cs[i].mi_t
    ct += 1
    cs[i].mi_t = t
    break if ct == N
  end
  m0 = MAX
  @g[i].each do |j, a, b|
    if m - a > cs[j].mx_m
      t1, m1 = t + b, m - a
      if m1 < cs[j].mi_m
        dm, dt = f[m1, cs[j].mi_m, *CDs[j]]
        t1 += dt; m1 += dm
      end
      unless cs0[j] == [t1, m1]
        cs0[j] = [t1, m1]
        q.add(Stop.new(j, t1, m1))
      end
    end
    m0 = [m0, [m, cs[j].mx_m + a].max + 1].min
  end
  cs[i].mi_m = m0
  dm, dt = f[m, m0, *CDs[i]]
  t += dt; m += dm
  unless cs0[i] == [t, m]
    cs0[i] = [t, m]
    q.add(Stop.new(i, t, m))
  end
end
(2 .. N).each{|i| puts cs[i].mi_t}

Measured memory_bytes: 14736
#C

n =int(input())
b = list(map(int,input().split()))
b.insert(0,10 ** 5)
b.append(10 ** 5)
a=[]

for i in range(n):
    kari = min(b[i],b[i+1])
    a.append(kari)
print(sum(a))

Measured memory_bytes: 3064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill((T*)array, (T*)(array+N), val);
}
template<typename T> void vdeb(T v){
    cout << "#vector set debug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


class Math {
    ll mod = 1e9+7;
  public:
    template<typename T1, typename T2>
    ll gcd(T1 a, T2 b){
        if(b==0) return a;
        return gcd(b, a%b);
    }

    template<typename T1, typename T2>
    ll lcm(T1 a, T2 b){
        return a*(b/gcd(a, b));
    }

    template<typename T>
    int keta(T num){
        T k=0;
        while(num>0){
            num/=10;
            k++;
        }
        return k;
    }

    template<typename T1, typename T2>
    ll powmod(T1 num1, T2 num2){
        ll res = 1;
        while(num2 > 0){
            res *= num1;
            res %= mod;
            num2--;
        }
        return res%mod;
    }

    template<typename T1, typename T2>
    ll powl(T1 a, T2 b){
        ll res = 1;
        while(b > 0){
            res *= a;
            b--;
        }
        return res;
    }
};


class DHandstand2 {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int n;
	    in >> n;
	    Math mt;
	    int c[10][10];
	    Fill(c, 0);
        reps(i, 1, n){
            int k = mt.keta(i);
            int s = i / pow(10, k-1);
            int e = i % 10;
            c[s][e]++;
        }

        ll res = 0;
        rep(i, 10){
            rep(j, 10){
                res += c[i][j] * c[j][i];
            }
        }

        out << res << endl;
	}
};


int main() {
	DHandstand2 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
from collections import Counter

N = int(input())

p = []
for _ in range(N):
    p.append(tuple(map(int, input().split())))

if N == 1:
    print(1)
    exit()

d = []
for i, p1 in enumerate(p):
    for j, p2 in enumerate(p):
        if i == j:
            continue
        x = p1[0] - p2[0]
        y = p1[1] - p2[1]
        d.append((x, y))

c = Counter(d)
# print(c)
print(N - c.most_common()[0][1])


Measured memory_bytes: 3948
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip	;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
int dp[300][300][4];
int main(){
	int n;
	while(cin>>n,n){
		vp out(n);
		rep(i,n){
			int a,b;
			cin>>a;
			out[i].second=a;
			vi co(10);
			int sum=0;
			rep(j,10){
				cin>>a;
				sum+=a;
				rep(k,j)if(co[k]){
					sum+=a;
					co[k]--;
				}
				if(a!=10){
					cin>>b;
					sum+=b;
					rep(k,j)if(co[k]){
						sum+=b;
						co[k]--;
					}
					if(a+b==10)co[j]=1;
				}else co[j]=2;
			}
			rep(j,co[9]){
				cin>>a;
				sum+=a;
				if(co[8]){
					sum+=a;
					co[8]--;
				}
			}
			out[i].first=-sum;
		}
		sort(all(out));
		rep(i,n)cout<<out[i].second<<" "<<-out[i].first<<endl;
	}
}

Measured memory_bytes: 1204
from fractions import gcd

N=int(input())
A=list(map(int,input().split()))

g=A[0]
l=A[0]
for i in range(N):
    g=gcd(l,A[i])
    l=l*A[i]//g
    
ans=0
mod=10**9+7

for i in range(N):
    ans+=l//A[i]
    
print(ans%mod)
    


Measured memory_bytes: 6072
import java.util.*;
import java.math.*;

class Main{       
   public static void main(String[] args){

     Scanner sc = new Scanner(System.in);  
      
     int N = sc.nextInt();
    
     HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
     
     for(int i = 0;i < N;i++){
         int a = sc.nextInt();
         if(map.containsKey(a)){
             map.put(a,(map.get(a)+1)%2);
         }else{
            map.put(a,1);
         }         
     }
     
     int count = 0;
     for(int key:map.keySet()){
         if(map.get(key) > 0){
             count++;
         }
     }
     
     System.out.println(count);
      
   }
}
        

Measured memory_bytes: 62684
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using f80 = __float80;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define pb push_back
#define rng(a) a.begin(),a.end()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (i64)(x).size()
#define bit(n) (1LL<<(n))
#define fi first
#define se second
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
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;}

i64 pow_mod(i64 n, i64 k, i64 m){
  i64 r = 1;
  for(;k;k>>=1){
    if(k&1) r=(r*n)%m;
    n=(n*n)%m;
  }
  return r;
}

void Main()
{
  i64 n,r;
  cin >> n >> r;
  if(n>=10)
    cout << r << endl;
  else
    cout << r + 100 * (10 - n) << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}


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

int coin[4] = {10, 50, 100, 500};

int main() {
    int n;
    bool flag = false;
    while (cin >> n, n) {
        vector<int> num(4);
        int change = -n;
        for (int i = 0; i < 4; i++) {
            cin >> num[i];
            change += num[i] * coin[i];     // とりあえず渡す
        }
        for (int i = 3; i >= 0; i--) {
            num[i] -= change / coin[i];
            change %= coin[i];
        }
        if (flag) cout << endl; flag = true;
        for (int i = 0; i < 4; i++) if (num[i] > 0) {
            cout << coin[i] << " " << num[i] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3048
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

lint solve(vector<lint> a, int dep) {
  int n = a.size();
  int m = n / 2;
  vector<vector<lint>> dp(m + 1, vector<lint> (dep, -INF));
  dp[0][0] = 0;

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < dep; j++) {
      if (dp[i][j] == -INF) continue;
      // cerr << "curState: " << i << " " << j << endl;
      for (int nj = j; nj < dep; nj++) {
        int takeId = i * 2 + nj;
        // cerr << "nextState: " << i + 1 << " " << nj << " takeId: " << takeId << endl;
        if (takeId < n) {
          dp[i + 1][nj] = max(dp[i + 1][nj], dp[i][j] + a[takeId]);
        }
      }

      // cerr << endl;
    }
  }

  lint ans = -INF;
  for (int j = 0; j < dep; j++)
    ans = max(ans, dp[m][j]);
  
  return ans;
}


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

  int dep;
  if (n % 2 == 0) {
    dep = 2;
  } else {
    dep = 3;
  }
  
  lint ans = solve(a, dep);
  cout << ans << endl;
  return 0;
}


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

const ll INF = 1LL << 60;

int main() {
	int n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	ll ans = INF;
	rep(bit, (1 << n)) {
		vector<int> s;
		rep(i, n) {
			if (bit & (1 << i)) {
				s.push_back(i);
			}
		}
		if (s.size() < k) continue;
		vector<ll> t(n);
		rep(i, s.size()) {
			int u = s[i];
			rep(j, u) {
				if (a[j] + t[j] >= a[u] + t[u]) {
					t[u] = a[j] + t[j] - a[u] + 1;
				}
			}
		}
		ll mn = 0;
		rep(i, n) mn += t[i];
		ans = min(ans, mn);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ld long double
#define mx 200005
#define fr first
#define se second
#define End cout<<"\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

int main()
{
   fast;
   string s1,s2="",s3="";
   cin >> s1;
   int n = s1.size();
   int left=0, right=n-1;
   int sum=0;
   while(left<right){
      if(s1[left]!=s1[right]){
         sum++;
      }
      left++,right--;
   }
   cout << sum << "\n";

   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int N, K, Q;
	cin >> N >> K >> Q;
	vector<int> cnt_A(N);
	for (int i = 0; i < Q; i++)
	{
		int A;
		cin >> A;
		cnt_A[A-1]++;
	}
	for (int i = 0; i < N; i++)
	{
		int sum = K - Q + cnt_A[i];
		if (sum > 0)
			cout  << "Yes" << endl;
		else
			cout << "No" << endl;
	}
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define MAX_C 30
#define MAX_T 100001

int imos[MAX_C][MAX_T + 1];

signed main(){
    int N,C;
    cin >> N >> C;
    int s,t,c;
    REP(i,N){
        cin >> s >> t >> c;
        c--;
        imos[c][s]++;
        imos[c][t]--;
    }
    REP(i,C){
        for(int j = 1; j < MAX_T; j++){
            imos[i][j] += imos[i][j - 1];
            if(imos[i][j - 1] == 0 && imos[i][j] != 0){
                imos[i][j - 1] = imos[i][j];
            }
        }
    }
    int ans = 0;
    REP(i,MAX_T){
        int sum = 0;
        REP(j,C){
            sum += imos[j][i];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11904
#include<iostream>
#include<cstdio>
#include<cstring>
#include<bitset>
using namespace std;
#define N 2002
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,a[N],sum;
bitset<N*N> dp;
int main(){
	n=read();
	for(int i=1;i<=n;++i){
		sum+=(a[i]=read());
	}
	sum=(sum+1)>>1;
	dp[0]=1;
	for(int i=1;i<=n;++i){
		dp|=dp<<a[i];
	}
	for(int i=sum;;++i){
		if(dp[i]){
			printf("%d\n",i);
			return 0;
		}
	}
	return 0;
}



Measured memory_bytes: 5240
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  string s; cin>>s;
  int n = s.size();
  cout << s.substr(0, n-8) << endl;

  return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n500,n100,n50,x,sum=0;
	scanf("%d%d%d%d",&n500,&n100,&n50,&x);
	for (int i=0;i<=n500;i++)
	    for (int j=0;j<=n100;j++)
	        for (int k=0;k<=n50;k++)
	            if (i*500+j*100+k*50==x)
	                sum++;
	printf("%d",sum);
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  priority_queue <double> pq;
  for(int i = 0; i < N; i++){
    long long a;
    cin >> a;
    pq.push(a);
  }
  while(M--){
    int d;
    d = pq.top();
    pq.pop();
    d /= 2;
    pq.push(d);
  }
  long long counter = 0;
  for(int i = 0; i < N;i++){
    counter += pq.top();
    pq.pop();
  }
  cout << counter << endl;

}

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

int main() {
	string str;
	cin >> str;
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		string command;
		cin >> command;
		int a, b;
		cin >> a >> b;
		if (command == "print") {
			for (int j = a; j < b + 1; ++j) {
				cout << str[j];
			}
			cout << endl;
		}
		else if (command == "reverse") {
			string rts = str;
			for (int k = a; k < b + 1; ++k) {
				str[k] = rts[b + a - k];
			}
		}
		else if (command == "replace") {
			string p;
			cin >> p;
			int count = 0;
			for (int l = a; l < b + 1; ++l) {
				str[l] = p[count];
				count++;
			}
		}
	}
	return 0;
}

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

int main()
{
	int n = 0, m = 0, l = 0, a[100][100] = { 0 }, b[100][100] = { 0 };

	cin >> n >> m >> l;

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

	for (int i = 0; i < m; i++) {
		for (int j = 0; j < l; j++)
			cin >> b[i][j];
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			long t = 0;
			if (j > 0)
				cout << " ";
			for (int k = 0; k < m; k++)
				t += a[i][k] * b[k][j];
			cout << t;
		}
		cout << endl;
	}

    return 0;
}

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

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		Main app = new Main();
		String string;
		
		while((string = reader.readLine()) != null){
			String[] source = string.split(",");
			double[] p = app.map(source);
			
			if(app.check(p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]) < 0.0 ||
			   app.check(p[4], p[5], p[6], p[7], p[0], p[1], p[2], p[3]) < 0.0)
				System.out.println("NO");
			else
				System.out.println("YES");
		}
		
		reader.close();
	}
	
	public double[] map(String[] source){
		double[] hoge = new double[8];
		for(int i = 0; i < 8; i++){
			if(source[i].equals("0.0")) hoge[i] = 0.0;
			else hoge[i] = Double.parseDouble(source[i]);
		}
		return hoge;
	}
	
	public double check(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4){
		return ((x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3)) * ((x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4));
	}
	
}

Measured memory_bytes: 23868
#include <stdio.h>

int main (void)
{
	int a,b,c,d,e,f,g,h,A,B;

	scanf	("%d%d%d%d",&a,&b,&c,&d);
	scanf	("%d%d%d%d",&e,&f,&g,&h);

	A = a+b+c+d ;
	B = e+f+g+h ;

	if (A>B)
	{
		printf	("%d\n",A);
	}
	else if (B>A)
	{
		printf	("%d\n",B);
	}
	else if (A==B)
	{
		printf	("%d\n",A);
	}

	return 0;
}

Measured memory_bytes: 588
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int calc(int k){
    int ret=0;
    while(k>0){
        ret++; k/=10;
    }
    return ret;
}

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

    int ans=100;
    for(int a=1;a*a<=N;a++){
        if(N%a==0){
            ans=min(ans,calc(N/a));
        }
    }
    cout<<ans<<endl;
 
}


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

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

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> 
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


vector<int> dice(VI cr, int i){
	auto nc = cr;
	if(i==0){  //right
		nc[0] = 7 - cr[1]; nc[1] = cr[0];
	}else if(i==1){ //down
		nc[0] = 7 - cr[2];  nc[2] = cr[0];
	}else if(i==2){ //left
		nc[0] = cr[1]; nc[1] = 7 - cr[0];
	}else{  //up
		nc[0] = cr[2]; nc[2] = 7 - cr[0];
	}
	return nc;
}


int main(){
	VI ds(6);
	rep(i,6) cin >>ds[i];
	string s;
	cin >>s;
	
	char dr[130]; int c=0;
	for(char x: "ESWN") dr[x] = c++;
	vector<int> cr = {1,3,2};

	for(auto x: s){
		auto rv = dice(cr, dr[x]);
		swap(cr, rv);
	}
	
	cout << ds[cr[0]-1] <<"\n";
	return 0;
}




Measured memory_bytes: 3232
s = input()

if s.count('S') == 0:
    print(3)
elif s[:2] == 'RR' or s[1:3] == 'RR':
    print(2)
elif s[0] == 'R' and s[2] == 'R':
    print(1)
elif s.count('R') == 1:
    print(1)
else:
    print(0)


Measured memory_bytes: 61636
/*zxj*/
#include<iostream> 
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
#define sf scanf
#define pf printf
#define pfn printf("\n");
#define pfk printf(" ");
#define pf0 printf("0");
#define pf1 printf("1");
#define ll long long
#define sfd(n) scanf("%d",&n);
#define sfdd(n,m) scanf("%d%d",&n,&m);
#define sfld(n) scanf("%lld",&n);
#define sfldd(n,m) scanf("%lld%lld",&n,&m);
#define sflf(n) scanf("%lf",&n);
#define sflff(n,m) scanf("%lf%lf",&n,&m);
#define sfc(n) scanf("%c",n);
#define sfcc(n,m) scanf("%c%c",n,m);
#define sfs(n) scanf("%s",n);
#define sfss(n,m) scanf("%s%s",n,m);
#define pfd(n) printf("%d",n);
#define pfld(n) printf("%lld",n);
#define pflf(n) printf("%lf",n);
#define pfc(n) printf("%c",n);
#define pfs(n) printf("%s",n);
using namespace std;
#define csh(a,n) memset(a,n,sizeof(a));
int main(){
	int n;
	cin>>n;
	map<long long,int>mp;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		mp[a]++;
	}
	map<long long,int>::iterator i=mp.end();
	i--;
	int count=0;
	ll arr[4];
	for(i;;i--){
		if(i->second>=2){
			arr[count++]=i->first;
		}
		if(i->second>=4){
			arr[count++]=i->first;
		}
		if(count>=2){
			break;
		}
		if(i==mp.begin()){
			break;
		}
	}
	if(count>=2){
		cout<<arr[1]*arr[0]<<endl;
	}
	else{
		cout<<0<<endl;
	}
}

Measured memory_bytes: 6528
import math
def eraP(n):
    if n<=1: return [False]*(n+1)
    elif n<=2: return [False, False, True]
    L = [False if i%2==0 or i%3==0 else True for i in range(n)]
    L[0] = False; L[1] = False;
    L[2] = True; L[3] = True; L[5]=True
    limit = math.sqrt(n)
    for i in range(3,n,2):
        if i >= limit: return L
        for s in range(i**2,n,i):
            L[s] = False
    return L

q = int(input())
LR = [[0,0] for _ in range(q)]
for i in range(q):
    LR[i] = list(map(int, input().split()))
P = eraP(pow(10,5)+1)[1:]

sumP = [0,0,0]
for i in range(2,pow(10,5)):
    sumP.append(sumP[-1]+int(P[i] and P[(i+1)//2]))

for lr in LR:
    print(sumP[lr[1]]-sumP[lr[0]-1])

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

int main(){
    int n;  cin >> n;
    vector<int>a(n);
    rep(i, n)	cin >> a[i];
    vector<int>student(n);
    rep(i, n){
	student[a[i]-1] = i+1;
    }
    rep(i, n){
	printf("%d ", student[i]);
    }
    cout << endl;
}


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

#define ntest 0

using namespace std;
long long x[5], res;
void solve() {
    for (int i = 1; i <= 4; ++i) cin >> x[i];
    res = LLONG_MIN;
    for (int i = 1; i <= 2; ++i)
        for (int j = 3; j <= 4; ++j) res = max(res, x[i] * x[j]);
    cout << res;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    if(ntest){
        int t;
        cin >> t;
        while(t--) solve();
    } else {
        solve();
    }

}




Measured memory_bytes: 3660
#include<iostream>
using namespace std;
const int N=50;
int a[N],n;
int main(){
	int s=0;
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++) s+=a[i]*a[j];
	}
	cout<<s;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
const ll mo=1000000007;
ll ans=0;
ll dp[0][0];

int main()
{
ll n;
cin >> n;
ll a[5];
rep(i,5){
cin >> a[i];
}
sort(a, a + 5);

ans=n/a[0]+5;
if(n%a[0]==0){
    ans--;
}

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





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &os, const tuple<T, U, V> &t){
  os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef tuple<int, int, int> TT;
typedef pair<int, TT> PT;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);


int fib[200];
signed main(){
  fib[1] = fib[2] = 1;
  repi(i,3,200)fib[i] = fib[i-1] + fib[i-2];
  
  int x, y;cin >> x >> y;
  int bottom = 0, top = 0;
  int left = 0, right = 0;
  int color = 1;
  int n = 1;
  
  while(true){
    if(left <= x and x <= right and bottom <= y and y <= top){
      cout << color << endl;
      break;
    }
    n++;
    if(n%4 == 2)right += fib[n];
    if(n%4 == 3)top += fib[n];
    if(n%4 == 0)left -= fib[n];
    if(n%4 == 1)bottom -= fib[n];
    color++;
    if(color == 4)color = 1;
  }
  return 0;
}







Measured memory_bytes: 3080
import java.util.Arrays;
import java.util.Scanner;

// https://atcoder.jp/contests/abc167/tasks/abc167_c
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();

		int[] c = new int[n];
		int[][] array = new int[n][m];
		for (int i = 0; i < n; i++) {
			c[i] = sc.nextInt();
			for (int j = 0; j < m; j++) {
				array[i][j] = sc.nextInt();
			}
		}
		sc.close();


		int ans = Integer.MAX_VALUE;

		for (int p=0; p<(Math.pow(2,n)); p++) {
			int cost = 0;
			int[] arrayX = new int[m];
			Arrays.fill(arrayX, 0);

			for(int i=0;i<n;i++) {
				if((1 & (p >> i)) == 1){
					cost = cost + c[i];
					for(int j=0;j<m;j++) {
						arrayX[j] = arrayX[j] + array[i][j];
					}
				}
			}

			boolean flag = true;
			for(int i=0;i<m;i++) {
				if(arrayX[i]<x) {
					flag = false;
					break;
				}
			}

			if(flag) {
				ans = Math.min(ans, cost);
			}
		}

		if(ans==Integer.MAX_VALUE) {
			System.out.println(-1);
		}else {
			System.out.println(ans);
		}
	}
}


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

int main() {
    char S[10];
    cin >> S;

    int half1 = (S[0] - '0') * 10 + (S[1] - '0');
    int half2 = (S[2] - '0') * 10 + (S[3] - '0');
    if (1 <= half1 && half1 <= 12) {
        if (1 <= half2 && half2 <= 12) cout << "AMBIGUOUS" << endl;
        else cout << "MMYY" << endl;
    } else {
        if (1 <= half2 && half2 <= 12) cout << "YYMM" << endl;
        else cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = [int(s) for s in input().split()]

div_a = 2
count = 0
while 1 :
    flag = 0
    for a_i in A :
        if a_i % div_a != 0 :
            flag = 1
    if flag == 1 :
        break
    else :
        div_a = div_a * 2
        count = count + 1
print(count)

Measured memory_bytes: 3060
#include<stdio.h>

int main(){
	int N;
	int H;
	int H_max=0;
	int Ans=0;
	scanf("%d",&N);
	
	for(int i=0;i<=N-1;i++){
		scanf("%d",&H);
		if(H>=H_max){
			if(H>H_max){
				H_max=H;
			}
			Ans++;
		}
	}
	
	printf("%d",Ans);
	return(0);
}

Measured memory_bytes: 128
#include<iostream>
#include<cstring>
#include<cstdio>

using namespace std;

int a[501][501],b[501][501],n,yu=0,prime[1000001],p0=0;
bool check[1000001];

int main()
{
	scanf("%d",&n);
	if(n==2)
	{
		cout<<4<<' '<<7<<endl<<23<<' '<<10<<endl;
		return 0;
	}
	memset(check,0,sizeof(check));
	memset(a,1,sizeof(a));
	memset(b,1,sizeof(b));
	for(int i=2;i<=100000;i++)
	{
		if(!check[i]) prime[++p0]=i;
		for(int j=1;(j<=p0)&&((prime[j]*i)<=100000);j++)
		{
			check[i*prime[j]]=1;
			if(i%prime[j]==0) break;
		}
	}
	for(int i=((n%2==0)?2:1);i<=n;i+=2)
	{
		int r=1,c=i;yu++;
		while((r>0)&&(r<=n)&&(c>0)&&(c<=n)) 
		{
			a[r][c]=prime[yu];
			r++;c--;
		}
	}
	for(int i=3;i<=n;i+=2)
	{
		int r=i,c=n;yu++;
		while((r>0)&&(r<=n)&&(c>0)&&(c<=n)) 
		{
			a[r][c]=prime[yu];
			r++;c--;
		}
	}
	for(int i=((n%2==0)?2:1);i<=n;i+=2)
	{
		int r=1,c=i;yu++;
		while((r>0)&&(r<=n)&&(c>0)&&(c<=n)) 
		{
			b[r][c]=prime[yu];
			r++;c++;
		}
	}
	for(int i=n;i>1;i-=2)
	{
		int r=i,c=1;yu++;
		while((r>0)&&(r<=n)&&(c>0)&&(c<=n)) 
		{
			b[r][c]=prime[yu];
			r++;c++;
		}
	}
	for(int i=1;i<=n;i++)
	{
	    for(int j=1;j<=n;j++)
	    {
	    	if(n%2==0)
	    	{
	    		if((i%2)!=(j%2)) cout<<(1ll*a[i][j]*b[i][j])<<' ';else
				{
					if((i==1)&&(j==1)) 
		    		{
						cout<<(1ll*a[i][j+1]*b[i][j+1]*b[i+1][j]+1)<<' ';
						continue;
					}
					if((i==n)&&(j==n))
					{
					    cout<<(1ll*a[i][j-1]*b[i-1][j]*b[i][j-1]+1)<<' ';
					    continue;
					}
					if((i==n)||(i==1))
					{
						cout<<(1ll*a[i][j-1]*a[i][j+1]*b[i][j-1]*b[i][j+1]+1)<<' ';
						continue;
					}
					cout<<(1ll*a[i-1][j]*a[i+1][j]*b[i+1][j]*b[i-1][j]+1)<<' ';
				}
			}else
			{
	    		if((i%2)==(j%2)) cout<<(1ll*a[i][j]*b[i][j])<<' ';else
				{
					if((i==n)||(i==1))
					{
						cout<<(1ll*a[i][j-1]*a[i][j+1]*b[i][j-1]*b[i][j+1]+1)<<' ';
						continue;
					}
					cout<<(1ll*a[i-1][j]*a[i+1][j]*b[i+1][j]*b[i-1][j]+1)<<' ';
				}
			}
		}
		cout<<endl;
	}
	return 0;
} 

Measured memory_bytes: 6912
class Problem
  attr_accessor :a, :b, :n, :m, :h, :w, :ans
  def initialize
    @n, @m = gets.to_s.split.map{ |v| v.to_i }
    @ans = 0
  end

  def solve
    calc
    puts ans
  end

  def top
    @top ||= Math.sqrt(m).to_i
  end

  def chmax(v)
    @ans = v if @ans < v
  end

  def calc
    each_div do |i,j|
      chmax(i) if j >= n
      chmax(j) if i >= n
    end
  end

  def each_div
    1.upto(top) do |i|
      next if m % i != 0
      j = m / i
      yield i, j
      yield j, i
    end
  end
end

pb = Problem.new
pb.solve

Measured memory_bytes: 14360
#include <iostream>
using namespace std;
int main (void) {
	int n; cin >> n;
	int board[n];
	int result = 0;
	int flag = 0;
	for (int i = 0; i < n; i++) {
		cin >> board[i];
		if (board[i] % 2 == 1)
			flag = 1;
	}
	int sum0 = 0;
	while (flag == 0 && sum0 <= n) {
		sum0 = 0;
		for (int i = 0; i < n; i++) {
			board[i] /= 2;
			if (board[i] % 2 == 1)
				flag = 1;
			if (board[i] == 0)
				sum0++;
		}
		result++;
		
	}
	
	cout << result << endl;

}

Measured memory_bytes: 256
import sys
s=int(input())

cnt=0

if s==1 or s==2:
  print('4')
  sys.exit()

while s!=4:
  if s%2!=0:
    s=3*s+1
    cnt+=1
  elif s%2==0:
    s=s//2
    cnt+=1

if s==4:
  print(cnt+4)

Measured memory_bytes: 9012
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>


using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define Rep(i, n) for(int i=n; i >= 0; i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える


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

    int n = s.size();

    if(n <= k){
        cout << s << endl;
    }
    else
    {
        string t = s.substr(0, k);
        t += "...";
        cout << t << endl;
    }
    
}

Measured memory_bytes: 3628
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
int cmp3(T lhs, T rhs) { return (lhs == rhs) ? 0 : (lhs > rhs) ? 1 : -1; }

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

long long solve(vector<pair<long long,long long>> const &v, long long k) {
  long long sum = 0;
  for (auto &&t: v) {
    if (k == 0) {
      return sum;
    }
    long long n, x; tie(n, x) = t;
    long long m = min(n, k);
    sum += m * x;
    k -= m;
  }
  return sum;
}

int main() {
  // cout << fixed << setprecision(10);

  long long A, B, C, K;
  cin >> A >> B >> C >> K;
  cout << solve({
      {A, 1},
      {B, 0},
      {C, -1}
      }, K) << endl;
  return 0;
}


Measured memory_bytes: 3624
n,q = map(int, raw_input().split())
que = [map(str, raw_input().split()) for i in range(n)]
t = 0
while que:
	a = que.pop(0)
	if int(a[1]) <= q:
		t += int(a[1])
		print a[0],t				
	else:
		t += q
		que.append([a[0],int(a[1])-q])

Measured memory_bytes: 14020
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Util{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
        int N = ri();

        int i = 0;

        while(i * 1000 < N) {
            i++;
        }

        Console.WriteLine(i * 1000 - N);
        Console.ReadLine();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 27532
n = int(input())
a = [0] + list(map(int, input().split()))

b = set()
d = dict()
for i in range(n, 0, -1):
    x = i * 2
    count = 0
    while x <= n:
        count += d[x]
        x += i
    if a[i] == 0:
        if count % 2 == 1:
            b.add(i)
            d[i] = 1
        else:
            d[i] = 0
    else:
        if count % 2 == 0:
            b.add(i)
            d[i] = 1
        else:
            d[i] = 0

print(len(b))
print(' '.join(map(str, b)))


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

using namespace std;
template <typename T> void print(T vec) {for(auto d: vec) cout<<d<<' ';cout<<'\n';}
template<typename T> void print2D(T mat) {for(auto vec:mat) print(vec);}


int n, k;

void ans(vector<int> & vec) {
    vector<int> dp(k + 1, 0);
    for(int i = 0; i <= k; i++) {
        for(int a : vec) {
            if(i >= a && !dp[i - a]) dp[i] = 1;
        }
    }
    // print(dp);
    cout<<(dp[k] ? "First" :"Second")<<"\n";
}



int main() {
    cin>>n>>k;
    vector<int> A(n);
    for(int i = 0; i< n;i++) cin>>A[i];
    ans(A);
    return 0;
}

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

int main(){
    bool card[4][14];
    int n, rank;
    char suit;

    for (int s = 0; s < 4; s++)
        for (int r = 1; r <= 13; r++)
            card[s][r] = 0;

    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> suit >> rank;
        if (suit == 'S')card[0][rank] = 1;
        if (suit == 'H')card[1][rank] = 1;
        if (suit == 'C')card[2][rank] = 1;
        if (suit == 'D')card[3][rank] = 1;
    }
    
    for (int s = 0; s < 4; s++)
    {
        for (int r = 1; r <= 13; r++)
        {
            if(card[s][r])continue;
            if(s == 0)suit = 'S';
            if(s == 1)suit = 'H';
            if(s == 2)suit = 'C';
            if(s == 3)suit = 'D';
            cout << suit << " " << r << endl;
        }
    }
return 0;
}
    


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

int div(vector<int> a) {
  vector<int> beki(a.size());
  for(int i = 0; i < a.size(); i++) {
    while(a.at(i) % 2 == 0) {
      a.at(i) /= 2;
      beki.at(i)++;
    }
  }
  
  sort(beki.begin(), beki.end());
  return beki.at(0);
}

int main() {  
  int n;
  cin >> n;
  
  vector<int> a(n);
  
  for(int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  
  cout << div(a) << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

void solve()
{
	int n;
	cin>>n;
	vector<int>a(n);
	int ans=0;
	rep(i,n)cin>>a[i];
	sort(all(a));
	vector<bool>b(1e6+5),bad(1e6+5);
	rep(i,n){
		if(b[a[i]])bad[a[i]]=true;
		b[a[i]]=true;
	}
	rep(i,n){
		bool ng=false;
		if(bad[a[i]])continue;
		for(auto x:divisor(a[i])){
			if(x==a[i])continue;
			if(b[x]){
				ng=true;
			}
		}
		if(!ng)++ans;
	}
	cout<<ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 4272
#include<cstdio>
#include<cstring>
int main() {
	int n = 0;
	char w[11], t[1001];
	scanf("%s%s", w, t);
	for (int i = 0; w[i] != '\0'; i++)if (w[i] >= 'A'&&w[i] <= 'Z')w[i] -= 'A' - 'a';
	while (strcmp(t, "END_OF_TEXT") != 0) {
		for (int i = 0; t[i] != '\0'; i++)if (t[i] >= 'A'&&t[i] <= 'Z')t[i] -= 'A' - 'a';
		if (strcmp(t, w) == 0)n++;
		scanf("%s", t);
	}
	printf("%d\n", n);
	return 0;
}


Measured memory_bytes: 2744
using System;
using System.Collections.Generic;
using System.Linq;
class Ho{
  static void Main(){
    var zen  = Console.ReadLine().Split();
    var a = double.Parse(zen[0]);
    var b = double.Parse(zen[1]);
    var h = double.Parse(zen[2]);
    var m = double.Parse(zen[3]);
    double tan = m*6;
    double tyou = (h*60+m)*0.5;
   
    
    double deg = tyou-tan;
     double rad = System.Math.PI * deg / 180.0;
    var kotae = a*a+b*b-2*a*b*Math.Cos(rad); 
     double maji = Math.Sqrt(kotae);
    Console.WriteLine(maji);
  }
}

Measured memory_bytes: 18708
#include <iostream>

using namespace std;
const int N=1055;
int a[N][N];
int main()
{
    int n,m;
    cin>>n>>m;
    char c;
    int mod=1e9+7;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>c;
            if(i==1&&j==1)
            {
                a[i][j]=1;
                continue ;
            }
            if(c=='.')
            {
                a[i][j]=a[i-1][j]+a[i][j-1];
            }
            else
                a[i][j]=0;
            a[i][j]%=mod;
        }
    }
    cout<<a[n][m]<<endl;
    return 0;
}


Measured memory_bytes: 4352