akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(){
 
    unsigned long a,b,c,d;
    scanf("%ld %ld %ld %ld",&a,&b,&c,&d);
    
    unsigned long count=0;
    count += b - a + 1;
    long x = c * d;
    count -= (b / c)-((a - 1) / c) + (b / d) - ((a - 1) / d);
 
    long r = d % c;
    while(r != 0){
        d = c;
        c = r;
        r = d % c;
    }
 
    count += (b / (x / c)) - ((a - 1) / (x / c));
        
    printf("%ld\n",count);
 
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int A,B;

void input(void){
	scanf("%d %d",&A,&B);

}

int main(void){
	input();	

	if (A == 1) A = 14;
	if (B == 1) B = 14;

	if(A==B){printf("Draw");
	}else if(A>B){printf("Alice");
	}else{printf("Bob");
	}
	
	return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define MOD 1000000007

signed main(){

	lli n;
	cin>>n;
	lli k;
	cin>>k;
	vector<lli> v(n);
	REP(i,0,n)cin>>v[i];


	lli INF = (1LL)<<50;

	/*詰める操作をする理由は手元の宝石を減らしたいから*/
	/*マイナスを手に入れてでも、k回以内でプラスにできるか？*/
	/*プラスをとる回数をm回としたとき、マイナスを放出する回数はq回*/
	/*m+q<=kにできるか?*/
	/*また左からとるのがいいのか、右からとるのがいいのかも気になる*/

	/*左から何個取った数の最大を取ればよさそう？*/
	/*マイナスのでかいものを確保しておく配列を準備*/
	/*dp[i] i:取得、もしくは吐き出しの操作回数の合計*/
	/*dp[i]=その際の最大値*/

	/*かしこくやらずに、どこまでとるかを全部やってしまう*/
	lli ans=-INF;
	for(lli i=0;i<n;i++){
		vector<lli> p;
		lli left=i;
		lli sum=0;
		lli flag[100];
		REP(g,0,100)flag[g]=0;
		for(lli ii=0;ii<left;ii++){
			sum += v[ii];
			if(v[ii]<0)p.push_back(v[ii]);
			flag[ii]++;
		}
		if(DEBUG)cout<<"i="<<i<<"sum="<<sum<<endl;
		for(lli j=0;j<=n;j++){
			if(i+j>k)continue;
			lli right=n-j-1;
			if(right<-1)continue;
			if(flag[right+1])continue;
			vector<lli> pp;
			lli nextSum=sum;
			REP(g,0,p.size())pp.push_back(p[g]);
			for(lli jj=n-1;jj>right;jj--){
				nextSum+= v[jj];
				if(v[jj]<0)pp.push_back(v[jj]);
			}
			sort(pp.begin(),pp.end());
			lli allowCnt = k-(i+j);
			if(DEBUG)cout<<"j="<<j<<"allowCnt="<<allowCnt<<"nextSum="<<nextSum<<endl;
			for(lli g=0;(g<allowCnt && g<pp.size());g++){
				if(DEBUG)cout<<"g="<<g<<"pp[g]="<<pp[g]<<endl;
				if(pp[g]>=0)break;
				nextSum -= pp[g];
			}
			if(DEBUG)cout<<"allowNextSum="<<nextSum<<endl;
			ans = max(ans,nextSum);
			if(DEBUG)cout<<ans<<endl;
		}
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl;

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

    int n, m;
    cin >> n >> m;

    vector<vector<int>> g(n+1);
    int x, y;
    for (int i=0; i<m; i++) {
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    vector<int> vis(n+1);
    vis[1] = 1;
    queue<int> q;
    q.push(1);

    while (!q.empty()) {
        int cur = q.front();
        q.pop();
        for (int e : g[cur]) {
            if (!vis[e]) {
                vis[e] = cur;
                q.push(e);
            }
        }
    }

    bool flag = true;
    for (int i=1; i<=n; i++) {
        if (!vis[i]) {
            flag = false;
            break;
        }
    }
    if (flag) {
        cout << "Yes\n";
        for (int i=2; i<=n; i++) cout << vis[i] << "\n";
    } else
        cout << "No\n";
}


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

int main()
{
    int N;
    cin >> N;
    int A, t,result;
    result = 50;
    for(int i=0; i<N; i++){
        cin >> A;
        t = 0;
        while(A % 2 == 0){
            A /= 2;
            t++;
        }
        result = min(t,result);
    }
    cout << result << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, k;  
  cin >> n >> k ;

  int ans = 1;

  for (int i=0; i<n; i++) {
    
    if (ans<=k) {
      ans *= 2;
    }else {
      ans += k;
    }
  }
  cout << ans << endl;

}

Measured memory_bytes: 384
public class Main {


  private static void solve() {
    double w = ni();
    double h = ni();
    int x = ni();
    int y = ni();
    
    if (x * 2 == w && y * 2 == h) {
      System.out.println(w * h / 2.0 + " " + 1);
    } else {
      System.out.println(w * h / 2.0 + " " + 0);
      
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9 + 7, A = 1e6 + 2;
ll gcd(ll x, ll y)
{
	return (!y) ? x : gcd(y, x % y);
}

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    ll l, r, c, d;
    cin >> l >> r >> c >> d;
    ll lcm = c * d / gcd(c, d);
    l--;
    ll taken = (r / c - l / c) + (r / d - l / d) - (r / lcm - l / lcm);
    cout << (r - l) - taken;
    return 0;
}

Measured memory_bytes: 256
#[allow(dead_code)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(dead_code)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(dead_code)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: u64,
        b: u64,
    }
    let diff = b - a;
    let mut price = diff * 50;

    let small = |p| (((p as f64) * 0.08) as u64) < a || (((p as f64) * 0.10) as u64) < b;

    while small(price) {
        price += 1;
    }

    
    let large = |p| (((p as f64) * 0.08) as u64) >= a && (((p as f64) * 0.10) as u64) >= b;
    while price > 0 && large(price) {
        price -= 1;
    }
    price += 1;
    

    let enable = |p| (((p as f64) * 0.08) as u64) == a && (((p as f64) * 0.10) as u64) == b;
    if enable(price) {
        println!("{}", price);
    } else {
        println!("-1");
    }
}


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

using namespace std;

struct UnionFind {
  vector<int> par;
  vector<int> count;

  UnionFind(int N) : par(N), count(N) {
    for (int i = 0; i < N; i++) {
      par[i] = i;
      count[i] = 1;
    }
  }

  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  int getCount(int x) {
    return count[x];
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    if (count[rx] < count[ry]) {
      count[ry] += count[rx];
      par[rx] = ry;
    } else {
      count[rx] += count[ry];
      par[ry] = rx;
    }
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> parents(n, -1);
  vector<int> counter(n, 0);
  auto uf = UnionFind(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    uf.unite(a, b);
  }
  int total = 0;
  for (int i = 0; i < n; i++) {
    total = max(total, uf.getCount(i));
  }
  cout << total << endl;
}


Measured memory_bytes: 6388
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define e "\n"
#define MaRiaMa { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
#define fix(n) cout << fixed << setprecision(n);
using namespace std;
int main()
{
	MaRiaMa;
	int n, m, x,k=0,l=0;
	cin >> n >> m >> x;
	int ar[100];
	set<int> p;
	while (m--)
	{
		int x;
		cin >> x;
		p.emplace(x);
	}
	for (int i = 0; i <= n; i++)
	{
		if (p.count(i) == 1)
			ar[i] = -1;
		else
			ar[i]=i;
	}
	for (int i=0;i<x;i++)
	{
		if (ar[i] == -1)
			k++;
	}
	for (int i = x+1; i <= n; i++)
	{
		if (ar[i] == -1)
			l++;
	}
	cout << min(k, l);
}





Measured memory_bytes: 3564
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main() {
    
    int a,b;
    cin >> a >> b;
    if(a >= b){
        for(int i=0;i<a;i++) cout << b;
    }else{
        for(int i=0;i<b;i++) cout << a;
    }
    cout <<  endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll x;
  R x;
  pr(x^1);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3660
#include<iostream>

using namespace std;
int main(){
  int x;
  cin >> x;
  if(x==3||x==5){
    cout << "YES\n";
  }
  else{
    if(x==7){
      cout << "YES\n";
    }
    else{
      cout << "NO\n";
    }
  }
  return 0;
}


Measured memory_bytes: 256
a=list(input())
b =len(a)


if  int(a[b-1])==2 or int(a[b-1])==4 or int(a[b-1])==5 or int(a[b-1])==7 or int(a[b-1])==9 :  #abが２で割り切れたら、Evenと入力
    print('hon')  

elif int(a[b-1])==0 or int(a[b-1])==1 or int(a[b-1])==6 or int(a[b-1])==8  :
    print('pon')
    
else :           #それ以外なら,Oddと入力
    print('bon')



Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}

int main(){
  string s; cin >> s;
  ll N = s.size();
  ll r = 0;
  REP(i,pow(2,N-1)){
    ll temp = i;
    ll buf = ctoi(s[0]);
    ll e = 0;
    REP(j,N-1){
      ll x = ctoi(s[j+1]);
      if(temp&1){e += buf; buf= x;}
      else{ buf = buf*10+x;}
      temp = temp>>1;
    }
    e += buf;
    r += e;
  }
  printf("%Ld\n",r);
}

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


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

    int N;
    cin >> N;
    int P[N],Q[N];
    rep(i,N){
        cin >> P[i];
    }
    rep(i,N){
        cin >> Q[i];
    }
    int v[N];
    rep(i,N){
        v[i]=i+1;
    }
    int W=0,M=0,Y,Z;
    bool ans1=false,ans2=false;
    do {
        rep(i,N){
            if(v[i]!= P[i]){
                ans1=true;
                break;
            }
        }
    if(ans1) {
        W++;
    }
    else Y=W;
    ans1=false;
    }while(next_permutation(v,v+N));

    do {
        rep(i,N){
            if(v[i]!= Q[i]){
                ans2=true;
                break;
            }
        }
    if(ans2) {
        M++;
    }
    else Z=M;
    ans2=false;
    }while(next_permutation(v,v+N));

    cout << abs(Y-Z) << endl;
}


Measured memory_bytes: 256
import collections
n = int(input())
s = input()

score = 0
for i in range(n):
    left = s[:i]
    right = s[i:]
    left_c = list(collections.Counter(left).keys())
    right_c = list(collections.Counter(right).keys())
    tmp_score = 0
    for c in left_c:
        if c in right_c:
            tmp_score += 1
    if score < tmp_score:
        score = tmp_score
print(score)


Measured memory_bytes: 3316
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    m, d = list(map(int, readline().split()))
    cnt = 0
    for i in range(1, m + 1):
        for j in range(22, d + 1):
            t = 1
            for v in str(j):
                t *= int(v) if int(v) >= 2 else -1
            if i == t:
                cnt += 1
    print(cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 39280
r, c = map(int, input().split())   #r, cを読み込む
l = [[0 for i in range(c + 1)] for i in range(r + 1)]
#0 for i in range(n)   n個の要素を0で初期化
for i in range(r) :
  l[i] = list(map(int, input().split()))   #行ごとに読み込み
   
for i in range(r) :
  s = sum(l[i])   #行ごとの和を求める
  l[i].append(s)   #sをi行目の最後に追加
   
for j in range(c) :   #列ごとの和を求める 横に1つずつ動く
  s = 0
  for i in range(r) :   #1行ずつ進む
    s += l[i][j]
  l[r][j] = s   #0行目から始まってる→r(r+1)行目にc列目の和
   
l[r][c] = sum(l[r])   #l[r][c] = l[r]の和
 
for i in range(r + 1) :   #range→(r+1)回
  for j in range(c + 1) :
    if(j == c) :
      print(l[i][j])
    else :
      print(str(l[i][j]) + " ", end = "")


Measured memory_bytes: 6220
#include<stdio.h>

int main()
{
  int x, y, key1, key2;

  scanf("%d%d",&x,&y);

  if(x < y)
    {
      key1 = x;
      x = y;
      y = key1;
    }

  key2 = x % y;

  while(key2 != 0)
    {
      x = y;
      y = key2;
      key2 = x % y;
    }

  printf("%d\n",y);

  return 0;
}

Measured memory_bytes: 592
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int i;
  int ans=0;
  for(i=1;ans<n;++i){
    ans+=i;
  }
  int temp;
  temp=ans-n;
  ans=0;
  for(i=1;ans<n;++i){
    if(i!=temp){
      ans+=i;
      cout << i << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
from collections import Counter
c = Counter()
count = [0,0,0,0]
for i in range(3):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    c[a] += 1
    c[b] += 1
for i in c:
    count[c[i]-1] += 1

if count == [2,2,0,0]:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3564
s = input()
k = 'R'
g = 'L'

result = 'Yes'

for i, j in enumerate(s):
    if i % 2 == 0:
        if j == g:
            result = 'No'
            break
    else:
        if j == k:
            result = 'No'
            break
print(result)


Measured memory_bytes: 2940
N,Y = map(int,input().split())
count = 0
for l in range(N+1):
    for m in range(N+1):
        n = N-l-m
        if 0<=n<=N:
            y = 10000*l+5000*m+1000*n
            if y==Y:
                list = [l,m,n]
                count = count+1
if count>=1:
    print(list[0], list[1], list[2])
else:
    print(-1, -1, -1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n; cin >> n;
  vector<int> a(n+1),b(n+1);
  REP(i,n) cin >> a[i+1];

  vector<int> ans;
  for (int i=n; i>0; i--) {
    int sum = 0;
    for(int j=i*2; j<=n; j+=i) sum+=b[j];
    if (sum%2 != a[i]) { b[i]++; ans.push_back(i); }
  }

  reverse(ALL(ans));
  COUT(ans.size());
  REP(i,ans.size()) {
    if (i > 0) cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 5360
N = int(input())
res = dict()
for i in range(N):
  word = input()
  if word not in res:
    res[word] = 0
  res[word] += 1
MAX = max(res.values())
max_word = [word[0] for word in res.items() if word[1] == MAX]
max_word.sort()
for el in max_word:
    print(el)

Measured memory_bytes: 32096
fun main(args: Array<String>) {
    val a = IntArray(50) { 0 }
    (2..readLine()!!.toInt()).forEach {
        var n = it
        for (i in 2..47) {
            while (n % i == 0) {
                a[i]++
                n /= i
            }
            if (n == 1) break
        }
    }
    val b = a.filter { it > 1 }
    var count = 0
    for (i in 0 until b.size) {
        if (b[i] >= 74) count++
        for (j in 0 until b.size) {
            if (i == j) continue
            if (b[i] >= 2 && b[j] >= 24) count++
            if (b[i] >= 4 && b[j] >= 14) count++
            for (k in j + 1 until b.size) {
                if (j == k || k == i) continue
                if (b[i] >= 2 && b[j] >= 4 && b[k] >= 4) count++
            }
        }
    }
    print(count)
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

int get_random(int l, int r) {
  int k = r - l + 1;
  return l + rng() % k;
}

const int N = 365 + 7;
const int K = 26 + 7;
int n;
int c[K], s[N][K], t[N], last[K], sol[N], best = -(int) 2e9;

int get() {
  for (int j = 1; j <= 26; j++) {
    last[j] = 0;
  }
  int sol = 0, grow = 0;
  for (int i = 1; i <= n; i++) {
    sol += s[i][t[i]];
    grow += c[t[i]] * (i - last[t[i]]);
    last[t[i]] = i;
    sol += grow;
  }
  return sol;
}

void upd() {
  int cur = get();
  if (cur > best) {
    best = cur;
    for (int i = 1; i <= n; i++) {
      sol[i] = t[i];
    }
  }
}

void make_better(double seconds) {
  time_t bg = clock();
  int c = 0;
  int cur = get();
  while (1) {
    c++;
    if (c % 10 == 0) {
      time_t nd = clock();
      if ((double) (nd - bg) / CLOCKS_PER_SEC > seconds) {
        break;
      }
    }
    int i = get_random(1, n), x = get_random(1, 26);
    while (x == t[i]) {
      x = get_random(1, 26);
    }
    int init = t[i];
    t[i] = x;
    int after = get();
    if (after > cur) {
      cur = after;
    } else {
      t[i] = init;
    }
  }
  upd();
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= 26; i++) {
    cin >> c[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 26; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 1; i <= 150; i++) {
    for (int i = 1; i <= n; i++) {
      t[i] = get_random(1, 26);
    }
    make_better(0.01);
    upd();
  }
  for (int i = 1; i <= n; i++) {
    cout << sol[i] << "\n";
  }
  return 0;
}


Measured memory_bytes: 3720
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int x, a, b;
  cin >> x >> a >> b;
  int diff = x - a;
  diff -= b * (diff / b);
  cout << diff << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define INF 100000000

int h=0,T=2000000,A[2000000];

void insert(int);
int extra(void);

int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}

void maxHeapify(int i){
  int l = left(i);
  int r = right(i);
  int large;
  int tmp;

  if(l <= h && A[l] > A[i]){
    large = l;
  }else{
    large = i;
  }
  if(r <= h && A[r] > A[large]){
    large = r;
  }

  if(large != i){
    tmp = A[i];
    A[i] = A[large];
    A[large] = tmp;
    maxHeapify(large);
  }
}


int extra(){
  int max;
  if(h<1)return -INF;

  max = A[1];
  A[1] = A[h--];
  maxHeapify(1);

  return max;
}


void heapIncreaseKey(int i,int k){
  int tmp;
  if(k < A[i])return;

  A[i] = k;

  while(i > 1 && A[i/2] < A[i]){
    tmp = A[i];
    A[i] = A[i/2];
    A[i/2] = tmp;
    i = i/2;
  }
}

void insert(int k){
  h++;
  A[h] = -INF;
  heapIncreaseKey(h,k);
}

int main(){
	int i,n,k;
	char s[10];
	scanf("%s",s);
	while(s[2]!='d' ){
		if(s[0]=='i'){
			scanf("%d",&n);
			insert(n);
		}else{
			k=extra();
			printf("%d\n",k);
		}
		scanf("%s",s);
	}
	return 0;
}



Measured memory_bytes: 5760
import sys
input=sys.stdin.readline
def main():
    N, K = map(int, input().split())
    lst_a = list(map(int, input().split()))
    # 石の個数が残りi個の局面で勝ちTrue 負け False　
    dp = [False] * (K+1)
    for i in range(1, K+1):
        for j in range(N):
            if i - lst_a[j] >= 0:
                dp[i] |= not(dp[i - lst_a[j]])
    
    if dp[K]:
        print('First')
    else:
        print('Second')
main()

Measured memory_bytes: 40304
#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[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

typedef string::const_iterator State;

int factor(State &begin);
int number(State &begin);

int factor(State &begin){
    if(isdigit(*begin)) return number(begin);
    vector<int> vec;
    while(1){
        if(*begin == '['){
            begin++;
            vec.push_back(factor(begin));
            begin++;
        }else{
            break;
        }
    }
    int sum = 0;
    // for(int i=0; i<vec.size(); i++){
    //     cout << vec[i] << " ";
    // }
    // cout << enld;
    sort(vec.begin(),vec.end());
    for(int i=0; i<(vec.size()+1)/2; i++){
        sum += vec[i];
    }
    return sum;
}

int number(State &begin){
    int ret = 0;
    while(isdigit(*begin)){
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }
    return (ret+1)/2;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    cin.ignore();
    while(N--){
        string S;
        getline(cin,S);
        State begin = S.begin();
        begin++;
        cout << factor(begin) << enld;
        begin++;
    }
    return 0;
}


Measured memory_bytes: 3232
#include<stdio.h>
int main(){
  int a, b, n;
  scanf("%d %d",&a,&b);
  if( a < b ){
    n = a;
    a = b;
    b = n;
  }
  while( b > 0 ){
    n = a % b;
    a = b;
    b = n;
  }
  printf("%d\n",a);
  return 0;
}



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

int main()
{
    ll n,k;
    cin>>n>>k;ll l1[n+1],x,s=0,a,b;
    for(int i=1;i<=n;i++){
        cin>>x;
        a=x*2;
        b=abs(k-x)*2;
        s+=min(a,b);
    }
    cout<<s;
}


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

bool FIELD[8][8];

void init() {
  rep(i, 8) rep(j, 8) FIELD[i][j]=false; 
}

int main() {
  int n; cin>>n;
  vector<int> x(n),y(n);
  rep(i, n) cin>>x[i]>>y[i];
  int A[8];
  rep(i, 8) A[i]=i;

  do {
    /*与えられた配置と矛盾しないか*/
    
    bool ok=true;
    rep(i, 8) {
      int nx=i;
      int ny=A[i];
      rep(j, n) {
        if (nx==x[j]) {
          if (ny!=y[j]) ok=false;
        }
      }
    }

    /*探検*/
    init();

    rep(i, 8) {
      int X=i;
      int Y=A[i];
      if (FIELD[X][Y]) ok=false;

      /*8近傍チェック*/
      for (int dx=-1; dx<=1; dx++) {
        for (int dy=-1; dy<=1; dy++) {
          int nx=X+dx;
          int ny=Y+dy;
          if ((0>nx)||(0>ny))continue;
          if ((8<=nx)||(8<=ny)) continue;
          FIELD[nx][ny]=true;
        }
      }
      /*斜めチェック*/
      for (int d=-7; d<=7; d++) {
        int nx=X+d;
        int ny=Y+d;
        if ((0>nx)||(0>ny))continue;
        if ((8<=nx)||(8<=ny)) continue;
        FIELD[nx][ny]=true;
      }
      for (int d=-7; d<=7; d++) {
        int nx=X+d;
        int ny=Y-d;
        if ((0>nx)||(0>ny))continue;
        if ((8<=nx)||(8<=ny)) continue;
        FIELD[nx][ny]=true;
      }
    }
    if (ok) {
      rep(i, 8) {
        rep(j, 8) {
          if (A[i]==j) cout<<'Q';
          else cout<<'.';
        }
        cout<<endl;
      }
      break;
    }
  } while (next_permutation(A, A+8));

  return 0;
}



Measured memory_bytes: 3100
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

long long N, Ans;

int main() {
	scanf("%lld", &N);
	for(++N; N > 9; N /= 10) Ans += 9;
	printf("%lld\n", Ans + N - 1);
	return 0;
}

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep1(i, N) for (int i = 1; i <= N; i++)
const int intinf = numeric_limits<int>::max();

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define MOD 1000000007

void solve()
{
    int N;
    cin >> N;
    cout << (N + 1) / 2 << endl;
}

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

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

int main(){
    char c;
    cin>>c;
    cout<<('a'<=c&&c<='z'?'a':'A')<<endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
int a[maxn];
int main()
{
   double x,y,z,w;
     cin>>x>>y>>z>>w;
     printf("%.6f ",(double)(x*y)/2);
     if(z==x/2.0&&w==y/2.0)
        cout<<1<<endl;
     else
        cout<<0<<endl;


    return 0;
}


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

int main() {
    int64_t K, N;
    std::cin >> K >> N;

    int64_t A[N];
    int64_t diff_max = 0;
    for (int i = 0; i < N; ++i) {
        std::cin >> A[i];
        if (i != 0) {
            diff_max = std::max(diff_max, A[i] - A[i-1]);
        }
    }

    diff_max = std::max(diff_max, (K - A[N-1]) + A[0]);

    std::cout << K - diff_max << std::endl;

    return 0;
}


Measured memory_bytes: 1792
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>

using namespace std;

using namespace std;

int main(void)
{
	int n, h;
	int a, b;
	int res = 0;
	int wield = 0;
	vector <int> v;

	scanf("%d %d", &n, &h);

	for (int i = 0; i < n; i++)
	{
		scanf("%d %d", &a, &b);
		wield = max(wield, a);
		v.push_back(b);
	}

	sort(v.rbegin(), v.rend());


	//throw
	for (int i = 0; i < v.size(); i++)
	{
		if (wield > v[i] || h<=0)
		{
			break;
		}
		h -= v[i];
		res++;
	}

	//wield
	if (h > 0)
	{
		res += ceil(h*1.0 / wield);
	}
	cout << res << '\n';
	return 0;

}

Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>
#include <map>

using namespace std;

int main(){

    int N, P;
    cin >> N >> P;
    string S;
    cin >> S;

    if(P == 2 || P == 5){
        long long ans = 0;
        for(int i = 0; i < N; i++){
            int num = S[i] - '0';
            if(num % P == 0){
                ans += (i + 1);
            }
        }

        cout << ans << endl;
    }
    else{
        reverse(S.begin(), S.end());
        vector<int> acc(N + 1);
        acc[0] = 0;
        int temp = 1;
        for(int i = 1; i <= N; i++){
            int num = S[i - 1] - '0';
            acc[i] = (acc[i - 1] + num * temp) % P;
            temp = (temp * 10) % P;
        } 

        long long ans = 0;
        map<int, int> m;
        for(int i = 0; i <= N; i++){
            m[acc[i]]++;
        }

        for(auto p: m){
            long long cnt = p.second;
            ans += cnt * (cnt - 1) / 2;
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M = 1e9 + 7;
int main() {
    ll N;
    cin >> N;
    vector<ll> T(N), A(N);
    for (int i = 0; i < N; i++) {
        cin >> T[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    ll maxl = max_element(T.begin(), T.end()) - T.begin();
    reverse(A.begin(), A.end());
    ll maxr = max_element(A.begin(), A.end()) - A.begin();
    maxr = N - 1 - maxr;
    reverse(A.begin(), A.end());

    bool flag = true;
    if (maxl > maxr) {
        flag = false;
    }

    if (T[maxl] != A[maxr]) {
        flag = false;
    }

    ll sum = 1;
    for (int i = 1; i < maxl; i++) {
        if (T[i] == T[i - 1]) {
            sum *= T[i];
            sum %= M;
        }
    }
    for (int i = N - 2; i > maxr; i--) {
        if (A[i] == A[i + 1]) {
            sum *= A[i];
            sum %= M;
        }
    }

    ll gap = maxr - maxl - 1;
    while (gap > 0) {
        sum *= T[N - 1];
        sum %= M;
        gap--;
    }

    cout << (flag ? sum : 0) << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long int ll;

int main(){
    string a;
    cin >> a;
    int n = a.length();
    int  dp[2][n+1];
    memset(dp,INF,sizeof(dp));
    dp[0][0] = a[0] -'0';
    dp[1][0] = 10 - (a[0] - '0') + 1;
    for(int i =1;i<n;i++){
        for(int j =0;j<2;j++){
            if( j == 0){
                dp[0][i] = min(dp[0][i-1] + (a[i]-'0'),dp[1][i-1] + (a[i]-'0'));
            }
            else{
            	dp[1][i] = min(dp[0][i-1] + 11 -(a[i] -'0'),dp[1][i-1] + (10- (a[i]-'0') -1));
            }
        }
    }
   	cout << min(dp[0][n-1],dp[1][n-1]) << endl;
  	return 0;
}


Measured memory_bytes: 9220
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, M;
    cin >> N >> M;
    VEC(string) A(N), B(M);
    READVEC(A);
    READVEC(B);
    int good = 0;
    FOR(i, 0, N - M + 1)
        FOR(j, 0, N - M + 1) {
            int good2 = 1;
            FOR(y, 0, M)
                FOR(x, 0, M)
                    if (B[y][x] != A[y + i][x + j])
                        good2 = 0;
            if (good2)
                good = 1;
        }

    cout << (good ? "Yes" : "No") << endl;
    return 0;
};


Measured memory_bytes: 256
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
constexpr int R=5e6+69, INF=2e9+6969;

int qq;

int main()
{
	int x;
	cin >> x;
	x = 2000-x-1;
	x/=200;
	cout << x + 1 << "\n";
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

#define INF 1e9
#define MOD 1e9 + 7
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()

int main(){
    string S;
    cin >> S;
    int ans = 0;
    for(int i = 1; i < S.size(); i++){
        if(S[i -1 ] != S[i] ) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
while 1:
    H , W = map( int,raw_input().split() )
    if ( H , W ) == ( 0 , 0 ):
        break
    for k in range(H):
        if k%2 == 0 and W%2 == 0:
            print "#." * ( W/2 )
        elif k % 2 == 0 and W % 2 == 1:
            print "#." * ( W/2 ) + "#"
        elif k%2 == 1 and W%2 == 0:
            print ".#" * ( W/2 )
        elif k%2 == 1 and W%2 == 1:
            print ".#" * ( W/2 ) + "."
    print ''

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

using namespace std;

const int N = 50;
const int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

char g[N][N];
int ans[N][N];

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", g[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (g[i][j] == '#') {
        continue;
      }
      for (int k = 0; k < 8; k++) {
        int xk = i + dx[k];
        int yk = j + dy[k];
        if (0 <= xk && xk < n && 0 <= yk && yk < m) {
          ans[i][j] += (g[xk][yk] == '#');
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (g[i][j] == '#') {
        putchar('#');
      } else {
        printf("%d", ans[i][j]);
      }
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int p = sc.nextInt();
		int ans  = (a * 3 + p) / 2;
		out.println(ans);

	}
}

Measured memory_bytes: 23892
/*
 *
 */
#include <cstdio>
#include <iostream>

using namespace std;

#define INF 1e9;

int a[100005];
int N, T;
int maxDiff = 0;

int main(){
    //freopen("d3.in", "r", stdin);

    scanf("%d %d", &N, &T);
    int tmpmin = INF;
    for (int i = 0; i < N; ++i) {
        scanf("%d", &a[i]);
        if (tmpmin > a[i]) tmpmin = a[i];
        int diff = a[i] - tmpmin;
        if (diff > maxDiff) maxDiff = diff;
    }

    int minCount = 0, maxCount = 0;
    tmpmin = INF;
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        if (tmpmin + maxDiff == a[i]) maxCount++;
        if (tmpmin == a[i]) {
            minCount++;
        } else if (tmpmin > a[i]) {
            // update
            tmpmin = a[i];
            ans += min(minCount, maxCount);
            // re-init
            minCount = 1;
            maxCount = 0;
        }
    }
    ans += min(minCount, maxCount);
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 640
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
checked = set()
now = 1
while(True):
    if a[now-1] == 2:
        print(len(checked)+1)
        break
    elif a[now-1] in checked:
        print(-1)
        break
    else:
        checked.add(a[now-1])
        now = a[now-1]

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

int N, M;
bool flag[10] = {};
bool edge[10][10] = {};

int dfs(int v);

int main()
{
    int ans = 0;

    cin >> N >> M;

    for(int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        edge[A][B] = true;
        edge[B][A] = true;
    }
    flag[1] = true;
    cout << dfs(1) << endl;

    return (0);
}

int dfs(int v)
{
    int ans = 0;
    int f = 1;

    for(int i = 1; i <= N; i++) {
        if(!flag[i]) {
            f = 0;
            if(edge[v][i]) {
                flag[i] = true;
                ans += dfs(i);
                flag[i] = false;
            }
        }
    }

    return (ans + f);
}


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

int main() {
	long long x, k, d;
	cin >> x >> k >> d;
	long long dst = abs(x);
	long long t = dst / d;
	if (abs(t * d - dst) > abs(t * d - dst + d)) t++;
	long long t_d = k - t;
	if (t > k) cout << dst - k * d;
	else if (t_d % 2 == 0) cout << abs(t * d - dst);
	else cout << d - abs(t * d - dst);
	return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

const int di[]={-1,-1,0,0,1,1};
const int dj[]={-1,0,-1,1,0,1};

bool test(const vvi& b,int i,int j,int c,vvi& vis)
{
	if(i<0 || b.size()<=i || j<0 || i<j || vis[i][j]) return true;
	if(b[i][j]==0) return false;
	if(b[i][j]!=c) return true;
	vis[i][j]=1;
	bool res=true;
	rep(k,6) res&=test(b,i+di[k],j+dj[k],c,vis);
	return res;
}

void remove(vvi& b,int i,int j,int c)
{
	if(i<0 || b.size()<=i || j<0 || i<j || b[i][j]!=c) return;
	b[i][j]=0;
	rep(k,6) remove(b,i+di[k],j+dj[k],c);
}

int calc(const vvi& b,int c)
{
	int n=b.size();
	vvi vis(n); rep(i,n) vis[i].resize(i+1);
	vvi b2=b;
	rep(i,n) rep(j,i+1){
		if(!b[i][j] || vis[i][j]) continue;
		if(test(b,i,j,b[i][j],vis)) remove(b2,i,j,b[i][j]);
		//dump(mp(i,j)); dump(vis); dump(b2);
	}
	int res=0;
	rep(i,n) rep(j,i+1) if(b[i][j]!=b2[i][j])
		if(b[i][j]==c) res--;
		else           res++;
	return res;
}

int main()
{
	for(int n,c;cin>>n>>c && n|c;){
		vvi board(n);
		rep(i,n){
			board[i].resize(i+1);
			rep(j,i+1) cin>>board[i][j];
		}
		int res=-INFTY;
		rep(i,n) rep(j,i+1) if(board[i][j]==0){
			board[i][j]=c;
			res=max(res,calc(board,c));
			board[i][j]=0;
		}
		cout<<res<<endl;
	}
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
ll n, t;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    vector< pair<int, int> >v(n);
    for(int i = 0;i < n;++i)
        cin >> v[i].S >> v[i].F;
    sort(v.begin(), v.end());
    for(auto it : v)
    {
        t += it.S;
        if(t > it.F)
            return cout << "No", 0;
    }
    cout << "Yes";
    return 0;
}


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

using ll = long long;

int N; // 店の数
int F[111][11]; // 営業時間
int P[111][11]; // 利益

int main() {
   // 入力
   cin >> N;
   for (int i = 0; i < N; i++) {
      for (int j = 0; j < 10; j++) {
         cin >> F[i][j];
      }
   }
   for (int i = 0; i < N; i++) {
      for (int j = 0; j < 11; j++) { // 0個~10個なので1列の入力は11個ある
         cin >> P[i][j];
      }
   }

   ll ans = -1e15;
   for (int mask = 1; mask < (1<<10); mask++) {
      ll sum = 0;
      for (int i = 0; i < N; i++) {
         int cnt = 0;
         for (int j = 0; j < 10; j++) {
            if (((mask>>j)&1) && F[i][j]) cnt++;
         }
         sum += P[i][cnt];
      }
      ans = max(ans, sum);
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    rep(i,s.size()-8) cout << s[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N = 300000;
     
    int n, cnt = 0, son[N][2]; ll l;
    string s;
     
    ll dfs( int u, int dep )
    {
    ll x = l - dep + 1;
    if( !u && dep ) return x & -x;
    return dfs( son[u][0], dep+1 ) ^ dfs( son[u][1], dep+1 );
    }
     
    int main()
    {
    scanf( "%d%lld", &n, &l );
    for( int i = 1; i <= n; i ++ )
    {
    cin>> s;
    int u = 0, len = s.size();
    for( int j = 0; j < len; j ++ )
    {
    int w = s[j] - '0';
    if( !son[u][w] )
    son[u][w] = ++ cnt;
    u = son[u][w];
    }
    }
    if( dfs( 0, 0 ) ) puts( "Alice" );
    else puts( "Bob" );
    return 0;
    }

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int gcd(int a,int b)
{
	if(b==0)
	return a;
	
	return gcd(b,a%b);
}
int power(int x,int y,int p)
{
	int res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		res=(res*x)%p;
		
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
struct Matrix{ 
	int a[2][2] = {{0,0},{0,0}};
	Matrix operator *(const Matrix& other){
		Matrix product;
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				for(int k=0;k<2;k++){
						product.a[i][k] =product.a[i][k] + (ll)a[i][j]*other.a[j][k];
				}
			}
		}
		return product;
	}
};
int modInverse(int n,int p)
{
	return power(n,p-2,p);
}
int main() {
	
	// your code goes here
	 ios_base::sync_with_stdio(0);
	 cin.tie(0);
	 int n;
	 cin>>n;
	 ll ans = 0;
	 int ma = 0;
	 for(int i=0;i<n;i++)
	 {
		 int x;
		 cin>>x;
		 if(i == 0)
		 ma = x;
		 else
		 {
			 if(x>ma)
			 ma = x;
			 else
			 ans+=(ma-x);
		 }
	 }
	 cout<<ans<<'\n';
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <time.h>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

long long dp[100010][13];
//先頭i文字目のうち13で割った余りがjとなるものの個数

int main(){
    string s; cin >> s;
    int n = s.size();
    dp[0][0] = 1;
    for (int i = 0; i < n; i++){
        int tmp;
        if (s[i] == '?') tmp = -1;
        else tmp = s[i]-'0';

        for (int j = 0; j < 10; j++){
            if (tmp != -1 && tmp != j) continue;
            for (int k = 0; k < 13; k++){
                dp[i+1][(k*10 + j) % 13] += dp[i][k];
            }
        }
        for (int j = 0; j < 13; j++){
            dp[i+1][j] %= MOD;
        }
    }
    cout << dp[n][5] << endl;
}





Measured memory_bytes: 10624