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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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

template<typename T>
struct SegTree{
    int num,bt;
    vector<T> node;
    T _init;

    void init(int num,T n){
        int i = 0,j=1;
        this->num = num;
        for (i = 0; j < num+1;i++)
            j*=2;
        j *= 2;
        bt = j / 2 - 1;
        _init = n;
        node.resize((j - 1),n);
        for (int i = 0; i < num; i++){
            node[bt + i] = n;
        }
        for (int i = bt - 1; i >= 0;i--){
            node[i]=calc(node[i * 2 + 1], node[i * 2 + 2]);
        }
    }
    inline T calc(T& a,T& b){
        return min(a, b);
    }
    void sett(int x,T n){
        int i = bt+x;
        node[i] = n;
        while(i!=0){
            i = (i - 1) / 2;
            node[i] = calc(node[i * 2 + 1],node[i * 2 + 2]);
        }
    }
    inline T gett(int x){
        return node[bt + x];
    }
    T gett(int x,int y){
        int i = bt+x;
        T sss = _init;
        if(x==0&&y==num-1){
            return node[0];
        }
        if(x!=0){
            int i = bt + x-1;
            int j = 1,l=x-1,r=x-1;
            while(i!=0){
                if(i%2&&x<=l+j&&r+j<=y){
                    sss = calc(node[i + 1],sss);
                }
                i = (i - 1) / 2;
                j *= 2;
                l = l / j*j;
                r = r / j*j+j-1;
            }
        }

        i = bt + y+1;
        int j = 1,l=y+1,r=y+1;
        while(i!=0){
            if(i%2==0&&x<=l-j&&r-j<=y){
                sss = calc(node[i - 1],sss);
            }
            i = (i - 1) / 2;
            j *= 2;
            l = l / j*j;
            r = r / j*j+j-1;
        }
        return sss;
    }
};

ll N,M;
vector<pair<pll,ll>> LRC;
ll dp[101010];
deque<pll> sld;
SegTree<ll> sg;
ll i, j, k, l;

int main(){
    scanf("%lld%lld", &N,&M);
    fornum(i,0,M){
        ll l, r, c;
        scanf("%lld%lld%lld", &l, &r, &c);
        LRC.push_back({{l, r}, c});
    }
    sort(LRC.begin(), LRC.end());
    j = 0;
    ll ans = 0;
    sg.init(N + 1, 1e17);
    sg.sett(1, 0);
    fornum(i,1,N){
        //printf("%lld,%lld\n", i, dp[i]);
        while(j<M&&LRC[j].first.first==i){
            //printf("%lld,%lld,%lld\n", 
            //LRC[j].first.first, LRC[j].first.second, LRC[j].second);
            sld.push_back({LRC[j].first.second, LRC[j].second});
            j++;
        }
        if(sg.gett(i)==1e17)
            continue;
        while(sld.size()){
            pll a = sld.front();
            //printf("%lld %lld\n", a.first, a.second);
            sg.sett(a.first, min(sg.gett(a.first), sg.gett(i, a.first - 1) + a.second));
            sld.pop_front();
        }
        
    }
    if(sg.gett(N)==1e17){
        printf("-1");
    }else
    printf("%lld", sg.gett(N));

    return 0;
}

Measured memory_bytes: 6512
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  printFrame(sc.nextInt(), sc.nextInt())

  def printFrame(h: Int, w: Int): Unit = {
    (h, w) match {
      case (0, 0) => sc.close()
      case _ =>
        for (i <- 1 to h) i match {
          case i if i == 1 || i == h => println("#" * w)
          case _ => println("#" + ("." * (w - 2)) + "#")
        }
        println()
        printFrame(sc.nextInt(),sc.nextInt())
    }
  }
}

Measured memory_bytes: 46704
// LNU_Algotesters
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <fstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;
const int MAX = 1000 * 3 + 47;



int A[MAX];
int D[MAX];

int main()
{
    //freopen("input.txt", "r", stdin);
    int n, x;
    scanf("%d%d", &n, &x);
    FOR(i, 0, n)scanf("%d", A + i);
    FOR(i, 0, n)D[i] = INF;
    LL res = LINF;
    FOR(i, 0, n)
    {
        FOR(j, 0, n)
        D[j] = min(D[j], A[(j - i + n) % n]);
        LL s = 0;
        FOR(j, 0, n)
            s += D[j];
        res = min(res, s + i * (LL)x);
    }
    cout << res << endl;
    return 0;
}



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

using namespace std;

int main()
{
	string s, t;
	cin >> s >> t;
	int ans = t.size();

	for (int start = 0; start <= s.size() - t.size(); start++) {
		int diff = 0;
		for (int i = 0; i < t.size(); i++) {
			if (t[i] != s[start + i]) {
				diff++;
			}
		}
		ans = min(ans, diff);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3168
#include <stdio.h>
int main (void){
    char s[19];
    for (int i = 0; i < 19; i++){
        scanf("%c", &s[i]);
    }

    for (int i = 0; i < 19; i++){
        if (s[i] == ','){
            printf("%c", ' ');
        }
        else {
            printf("%c", s[i]);
        }
    }

    return 0;
}


Measured memory_bytes: 128
$n = <>; chomp $n;

@adj = ();
push @adj, [] for (0..$n);

for (0..$n-2) {
    $input = <>; chomp $input;
    @p = split / /, $input;

    push $adj[$p[0]], $p[1];
    push $adj[$p[1]], $p[0];
}

# 訪問判別フラグ
push @F, 0 for (0..$n);

# Stack
@S = ();

# 距離
push @dist, 0 for (0..$n);

# 先頭から深さ優先探索
push @S, 1;

while (scalar @S != 0) {
    my $v = pop @S;

    if ($F[$v] == 0) {
        $F[$v] = 1;

        for my $u (@{$adj[$v]}) {
            if ($F[$u] == 0)  {
                push @S, $u;
                $dist[$u] = $dist[$v] + 1;
            }
        }
    }
}


# 訪問判別フラグ
@F = ();
push @F, 0 for (0..$n);

# Stack
@S = ();

# 距離
push @dist2, 0 for (0..$n);

# 最後から深さ優先探索
push @S, $n;

while (scalar @S != 0) {
    my $v = pop @S;

    if ($F[$v] == 0) {
        $F[$v] = 1;

        for my $u (@{$adj[$v]}) {
            if ($F[$u] == 0)  {
                push @S, $u;
                $dist2[$u] = $dist2[$v] + 1;
            }
        }
    }
}

$fennec = 0;
$sunuke = 0;

for (1..$n) {
    if ($dist[$_] <= $dist2[$_]) {
        $fennec += 1;
    }
    else {
        $sunuke += 1;
    }
}

$fennec > $sunuke ? print 'Fennec' : print 'Snuke';


Measured memory_bytes: 41600
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <string>
#include <tuple>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  string s;
  cin >> s;
  int cnt = 0;
  for (int i = 0; i < s.size(); ++i)
    if (s[i] == 'o')
      cnt++;
  if (15 - s.size() >= 8 - cnt)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#define MOD 1000000007
int f[100005],t[100005],n,m;
int main()
{
 scanf("%d%d",&n,&m);
 for(int i=1;i<=m;i++)
 {
  int x;
  scanf("%d",&x);
  t[x]=1;
 }
 f[0]=1;
 if(!t[1])f[1]=1;
 for(int i=2;i<=n;i++)
  if(!t[i])f[i]=(f[i-1]+f[i-2])%MOD;
 printf("%d\n",f[n]);
 return 0;
}

Measured memory_bytes: 896
//According to all known laws of aviation, there is no way that a bee should be able to fly.
//Its wings are too small to get its fat little body off the ground. The bee, of course, flies anyway.
//Because bees don't care what humans think is impossible.
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;
  
int main(){
    bigint N ; cin >> N ;
    bigint ans = 0 ;
    for( int i = 1 ; i <= N ; i++ ){
        bigint K = N / i ;
        bigint M = (K * ( K + 1 )) / 2 ;
        ans += ( M * i ) ;
    }
    cout << ans << endl ;
    return 0 ;
}


Measured memory_bytes: 3612
n = int(input())
ans =[0]*4
for i in range(n):
  s = input()
  if s == 'AC':
    ans[0] += 1
  elif s == 'WA':
    ans[1] += 1
  elif s == 'TLE':
    ans[2] += 1
  else:
    ans[3] += 1
    
print('AC x '+ str(ans[0]))
print('WA x '+str(ans[1]))
print('TLE x '+ str(ans[2]))
print('RE x '+ str(ans[3]))
    

Measured memory_bytes: 9200
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    lint N;
    lint ans=0;
    cin >> N;
    plint Q[N];
    rep(i,N) cin >> Q[i].first >> Q[i].second;
    lint dis=0,point=0;
    rep(i,N){
        if(dis<Q[i].second-Q[i].first) point=i;
        dis=max(dis,Q[i].second-Q[i].first+1);
    }
    lint ma=INF,mi=-INF;
    rep(i,N){
        if(i!=point){
        mi=max(mi,Q[i].first);
        ma=min(ma,Q[i].second);
        }
    }
    multiset<lint> minsave1,maxsave1,minsave2,maxsave2;
    sort(Q,Q+N);
    minsave1.insert(Q[0].first);
    maxsave1.insert(Q[0].second);
    for(int i=1;i<N;i++){
        minsave2.insert(Q[i].first);
        maxsave2.insert(Q[i].second);
    }
    lint min1=Q[0].first,max1=Q[0].second;
    lint min2=Q[N-1].first,max2=*maxsave2.begin();
    ans=max(0LL,max1-min1+1)+max(0LL,max2-min2+1);
    minsave1.insert(Q[1].first);
    maxsave1.insert(Q[1].second);
    auto itr=minsave2.find(Q[1].first),itr2=maxsave2.find(Q[1].second);
    minsave2.erase(itr);
    maxsave2.erase(itr2);
    for(int i=1;i<N-1;i++){
        max1=*maxsave1.begin();
        max2=*maxsave2.begin();
        auto itr1=minsave1.end();
        auto itr2=minsave2.end();
        itr1--,itr2--;
        min1=*itr1;
        min2=*itr2;
        ans=max(ans,max(0LL,max1-min1+1)+max(0LL,max2-min2+1));
        auto it=minsave2.find(Q[i+1].first),it2=maxsave2.find(Q[i+1].second);
        minsave1.insert(Q[i+1].first);
        maxsave1.insert(Q[i+1].second);
        minsave2.erase(it);
        maxsave2.erase(it2);
    }
    cout << max(ans,dis+max(0LL,ma-mi+1)) << endl;
}

Measured memory_bytes: 11264
N = int(input())


def dfs(s):
    if int(s) > N:
        return 0
    if s.count("7") > 0 and s.count("5") > 0 and s.count("3") > 0:
        ret = 1
        # print(s)
    else:
        ret = 0
    ret += dfs(s + "7")
    ret += dfs(s + "5")
    ret += dfs(s + "3")
    return ret


print(dfs("0"))



Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define inf 1e16
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define mx 100010

int main(){
	IOS;
	ll n;cin>>n;
	ll a[n];rep(i,0,n)cin>>a[i];
	int flag=0,t;
	rep(i,0,n)rep(j,0,n){
		t=a[j];a[j]=a[i];a[i]=t;
		int f=1;
		// rep(k,0,n)cout<<a[k]<<" ";cout<<"\n";
		rep(k,0,n-1)if(a[k]>a[k+1])f=0;
		if(f){flag=1;break;}
		t=a[j];a[j]=a[i];a[i]=t;
	}
	if(flag)cout<<"YES";
	else cout<<"NO";
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fast ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define pi 3.14159265358979323846264338327950LD
#define modd 1000000000
#define k 100000000

int main()
{
        fast;
        int t=1;
        //cin>>t;
        while(t--)
        {
                int a,b,c,d;
                cin>>a>>b>>c>>d;
                int taka=ceil((double)a/d);
                int aoki=ceil((double)c/b);
                if(taka>=aoki)
                        cout<<"Yes"<<endl;
                else
                        cout<<"No"<<endl;
        }
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }

    int ans = 1e9;
    for (int i = 1; i <= 100; ++i) {
        int sum = 0;
        for (int j = 0; j < n; ++j) {
            int tmp = x[j] - i;
            sum += tmp * tmp;
        }
        ans = min(ans, sum);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;

//#[proconio::fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        ch: Usize1,
        cw: Usize1,
        dh: Usize1,
        dw: Usize1,
        s: [Bytes;h],
    }
    const MAX_WARP: usize = 1000000;

    let mut warp_ct = vec![vec![MAX_WARP; w]; h];

    let mut q: VecDeque<(usize, usize)> = VecDeque::new();
    let mut q2: VecDeque<(usize, usize)> = VecDeque::new();
    q.push_back((ch, cw));
    let mut warped = 0;
    warp_ct[ch][cw] = warped;

    loop {
        // ワープを使わずに移動できる範囲を塗りつぶす
        while let Some((i, j)) = q.pop_front() {
            //println!("{} {} {}", i, j, warped);
            if i == dh && j == dw {
                // ゴールに到達した
                println!("{}", warp_ct[i][j]);
                return;
            }
            if s[i][j] == b'.' {
                let mut f = |i: usize, j: usize, use_warp: bool| {
                    if s[i][j] == b'.' {
                        if use_warp {
                            if warp_ct[i][j] > warped + 1 {
                                q2.push_back((i, j));
                                warp_ct[i][j] = warped + 1;
                            }
                        } else {
                            if warp_ct[i][j] > warped {
                                q.push_back((i, j));
                                warp_ct[i][j] = warped;
                            }
                        }
                    }
                };

                for di in -2..=2 {
                    for dj in -2..=2 {
                        if di == 0 && dj == 0 {
                            continue;
                        }
                        let no_warp = (di == 0 && dj == -1)
                            || (di == 0 && dj == 1)
                            || (di == -1 && dj == 0)
                            || (di == 1 && dj == 0);
                        let ii = i as i64 + di;
                        let jj = j as i64 + dj;
                        if 0 <= ii && ii < h as i64 && 0 <= jj && jj < w as i64 {
                            f(ii as usize, jj as usize, !no_warp);
                        }
                    }
                }
            }
        }

        // println!("--");
        // for i in 0..h {
        //     for j in 0..w {
        //         if warp_ct[i][j] == MAX_WARP {
        //             print!("X");
        //         } else {
        //             print!("{}", warp_ct[i][j]);
        //         }
        //     }
        //     println!("");
        // }

        q = q2.clone();
        q2.clear();

        if q.is_empty() {
            println!("{}", -1);
            return;
        }
        warped += 1;
    }
}


Measured memory_bytes: 12664
#include <bits/stdc++.h>
#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];
    a[i] = a[i]-i-1;
  }
  sort(a.begin(),a.end());
  
  int b;
  if(n%2==0){
    b = (a[n/2-1]+a[n/2])/2;
  }else{
    b = a[(n+1)/2-1];
  }
  
  long long ans=0;
  REP(i,n){
    ans += abs(a[i]-b);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
n=int(input())
a=list(map(int,input().split()))

#icnt=0
#for i in range(n):
#    for j in range(i+1,n):
#        if j-i==a[j]+a[i]:
#            icnt+=1

ip=[0]*n
jm=dict()
for i in range(n):
    ip[i]=i+a[i]
    if i-a[i] in jm:
        jm[i-a[i]]+=1
    else:
        jm[i-a[i]]=1

icnt=0
for i in range(n):
    if ip[i] in jm:
        icnt+=jm[ip[i]]
            
print(icnt)


Measured memory_bytes: 47612
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    ll n, x;
    cin >> n >> x;
    vl a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    rep(i, n-1) a[i+1] += a[i];
    if(a.back() < x) {
        cout << n-1 << endl;
        return 0;
    }
    repr(i, n) {
        if(a[i] <= x) {
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}

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

public class Main {

  public static void main(String[] args) {

    new Main().run();
  }
  public void run() {
    
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(in.readLine());
      String line = in.readLine();
      int[] ax = new int[n];
      long sum = 0;

      int m;
      int offset=0,next=0;
      char regex = ' ';
      boolean isContinue = true;
      for(int i=0; isContinue; i++) {
        if((next = line.indexOf(regex,offset)) == -1) {
          next = line.length();
          isContinue = false;
        }
        m = Integer.parseInt(line.substring(offset,next));
        m -= i;
        ax[i] = --m;
        offset = ++next;
      }

      Arrays.parallelSort(ax);
      int b = ax[n/2];

      for (int i : ax) {
        sum += Math.abs(i-b);
      }

      System.out.println(sum);

    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 45564
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    int n;
    cin>>n;
    set<string> st;
    while(n--)
    {
        string s;
        cin>>s;
        st.insert(s);
    }
    cout<<st.size()<<"\n";

}

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

int main(){
    int x, i;
    char c;
    int flag = 0;
    scanf("%d", &x);

    for(i = 0; i < x; i++){
        scanf(" %c", &c);
        if (c == 'Y') flag = 1;
    }

    flag ? printf("Four\n") : printf("Three\n");

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

template<typename T> vector<pair<T, LL>> cc(vector<T> v) {
	vector<pair<T, LL>> a;
	inc(i, v.size()) {
		if(i == 0 || v[i] != v[i - 1]) { a.EB(v[i], 1); } else { a.back().SE++; }
	}
	return a;
}

int main() {
	int n;
	cin >> n;
	vector<LL> z(1 << n);
	inc(i, 1 << n) { cin >> z[i]; }
	sort(RALL(z));
	
	auto c = cc(z);
	vector<LL> v, w;
	RF(e, c) { v.PB(e.SE); w.PB(0); }
	w[0] = 1;
	
	inc(x, n) {
		LL s = 0;
		inc(i, SI(v)) {
			LL t = w[i];
			LL u = min(v[i] - w[i], s);
			w[i] += u;
			s -= u;
			s += t;
		}
	}
	
	cout << (v == w ? "Yes" : "No") << endl;
	
	return 0;
}


Measured memory_bytes: 11880
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function (chunk) {
  var lines = chunk.split('\n');
  var h = Number(lines[0].split(' ')[0]),
      w = Number(lines[0].split(' ')[1]);
  var canvas = [];
  
  canvas.push('.'.repeat(w + 2).split(''));
  for(var i=0; i<h; i++) {
    var line = lines[i+1].slice(0, w).split('');
    line.unshift('.');
    line.push('.');
    canvas.push(line);
  }
  canvas.push('.'.repeat(w + 2).split(''));

  var result = 'Yes';
  for(var y=1; y<h; y++) {
    for(var x=1; x<w; x++) {
      if(canvas[y][x] == '#' && !isDraw(canvas, y, x)) {
        result = 'No'
      }
    }
  }
  console.log(result);
});

// canvasは周りに1行、1列無駄にあることに注意
// y, xはそれを考慮した値を入れること
function isDraw(canvas, y, x) {
  var eval = evaluateMass(canvas[y][x])
    + evaluateMass(canvas[y - 1][x])
    + evaluateMass(canvas[y + 1][x])
    + evaluateMass(canvas[y][x - 1])
    + evaluateMass(canvas[y][x + 1]);
  return eval >= 2;
}

function evaluateMass(mass) {
  return mass == '#' ? 1 : 0;
}

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

#define LOOP(a,b,c) for(a=b;a<=c;a++)
#define ll long long


ll getmaxpow(ll a,ll sosu);
ll getyakusu(ll a,ll sosu);


int main() {
    int n,j,k;
    ll i,baisu9=0,baisu6count=0,temp,temp2,temp3,ans=10000000000;
    ll insu3,insu2;
    cin>>n;



    LOOP(i,0,n){
        temp2=0;
        temp=i;
        while(temp>=6){
            temp-=getmaxpow(temp,6);
            temp2++;
        }
        temp3=n-i+temp;
        while(temp3>=9){
            temp3-=getmaxpow(temp3,9);
            temp2++;
        }
        temp2+=temp3;

        if(temp2<ans)ans=temp2;
    }

    cout << ans << endl;

    return 0;
}

ll getmaxpow(ll a,ll sosu){
    ll ans=0;
    while(a>=pow(sosu,ans)){
        ans++;
    }
    return pow(sosu,ans-1);
}

ll getyakusu(ll a,ll sosu){
    ll ans=0;
    while(a>=sosu){
        a/=sosu;
        ans++;
    }
    return ans;
}

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

int main(void){
    
    int N;
    string S, T;
    cin >> N;
    cin >> S >> T;
    
    string ans;
    for(int i = 0; i < N; i++){
        ans.push_back(S[i]);
        ans.push_back(T[i]);
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007

long int combination(long int n, long int r);

//qsort用、昇順
int compare_int(const void *a, const void *b)
{
	return *(int*)a-*(int*)b;
}
//qsort(data, 10, sizeof(int), compare_int)

long int combination(long int n, long int r)
{
	if(r>n-r) r = n-r;
	if(r == 0) return 1;
	else if(r == 1) return n;
	return (combination(n-1, r) + combination(n-1, r-1));
	//大きくなるとき
	/*
	long int tmp1, tmp2, tmp3;
	tmp1 = combination(n-1, r);
	if(tmp1>=MOD) tmp1 = tmp1%MOD;
	tmp2 = combination(n-1, r-1);
	if(tmp2>=MOD) tmp2 = tmp2%MOD;
	tmp3 = tmp1+tmp2;
	if(tmp3>=MOD) tmp3 = tmp3%MOD;
	return (tmp3);
	*/
}


int main(){
	char str[101];
	char key[] = "keyence";
	scanf("%s", str);
	int len = strlen(str);

	int ok=0, count, k;
	for(int i=0; i<7; i++){
		count=0, k=0;
		for(int j=0; j<i; j++){
			if(str[j] == key[k]){
				count++;
			}
			k++;
		}
		if(count!=i) continue;
		for(int j=i+len-7; j<len; j++){
			if(str[j] == key[k]){
				count++;
			}
			k++;
		}
		if(count == 7){
			ok=1;
			break;
		}
	}
	if(ok==1) printf("YES\n");
	else printf("NO\n");
		
	return 0;
}

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

using namespace std;

int main(){
	int n; cin >> n;
	vector<int> s,ss;
	for(int i =0; i < n; i++) {
		int x,y; cin >> x >> y;
		s.push_back(x+y);
		ss.push_back(x-y);
	}
	sort(s.begin(), s.end());
	sort(ss.begin(), ss.end());
	cout << max(s[n-1] - s[0],  ss[n-1] - ss[0]) << endl;
	
	return 0;
}


Measured memory_bytes: 4964
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(int argc, char const* argv[])
{
    long N, P;
    cin >> N >> P;
    vector<long> v(N);
    for(int i=0; i<N; i++) cin >> v[i];

    int even = 0, odd = 0, sum;
    for(int i=0; i<N; i++){
        sum += v[i];
        if(v[i]%2 == 0) even++;
        else odd++;
    }


    if(even == N) {
        if(P == 0) {
            cout << (long)pow(2,N);
        }else {
            cout << 0 << endl;
        }
        return 0;
    }

    cout << (long)pow(2,N-1) << endl;
}



Measured memory_bytes: 1016
#!/usr/bin/python3

import sys
from bisect import bisect_left

sys.setrecursionlimit(1000000)

n = int(input())
a = [int(i) for i in input().split()]

nbs = [ [] for _ in range(n) ]

for _ in range(n - 1):
    (u, v) = map(int, input().split())
    nbs[u - 1].append(v - 1)
    nbs[v - 1].append(u - 1)


mlen =  [ 0 ] * n
dp = [ float('inf') ] * n

def getmlen(cur, p, ctail):
    for ch in nbs[cur]:
        if ch == p:
            continue

        idx = bisect_left(dp, a[ch])
        ov = dp[idx]

        ntail = max(ctail, idx)
        dp[idx] = a[ch]
        mlen[ch] = ntail + 1
        getmlen(ch, cur, ntail)
        dp[idx] = ov

        

dp[0] = a[0]
mlen[0] = 1
getmlen(0, -1, 0)

for i in range(n):
    print(mlen[i])


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

int main() {
  
  char w;
  
  cin >> w;

  if( ('a'<=w)&&(w<='z') ) {
    
    cout << 'a' << endl;
    
  }
  
  if( ('A'<=w)&&(w<='Z') ) {
    
    cout << 'A' << endl;
    
  }
  
}

Measured memory_bytes: 3660
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <utility>

using namespace std;

int main() {

	int N, W;
	scanf("%d %d", &N, &W);

	pair<int, int> items[N + 1];
	for (int i = 1; i <= N; ++i) {
		int v, w;
		scanf("%d %d", &v, &w);
		items[i] = make_pair(v, w);
	}

	int V[N + 1][W + 1];
	for (int i = 0; i <= N; ++i) {
		V[i][0] = 0;
	}
	for (int i = 0; i <= W; ++i) {
		V[0][i] = 0;
	}

	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= W; ++j) {
			if (items[i].second <= j) {
				V[i][j] = max(V[i - 1][j], V[i - 1][j - items[i].second] + items[i].first);
			} else {
				V[i][j] = V[i - 1][j];
			}
		}
	}
	int maxv = 0;
	for (int i = 1; i <= W; ++i) {
		maxv = max(maxv, V[N][i]);
	}
	cout << maxv << endl;

	return 0;
}

Measured memory_bytes: 7164
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
using namespace std;
#define INF (2147483647)
#define mod (1000000007)

int main(void){
  char a,b;
  cin >> a >> b;
  if(a==b){
    cout << 'H' << endl;
  }else{
    cout << 'D' << endl;
  }
}


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

using namespace std;

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

    int rest = 32, i = 0, j = 0;
    while (rest) {
      int sub;
      if (i % 2) {
        rest -= min(rest, a[j++ % n]);
      } else {
        rest -= min(rest, (rest - 1) % 5);
      }
      cout << rest << endl;
      i++;
    }
  }
  
  return 0;
}


Measured memory_bytes: 2960
/**
 *   author: sahushivam
 *   created: 17 August 2019 (Saturday)  17:50:01
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    string s;
    cin>>s;
    int n=s.length();
    int c=0;
    set<char> se;
    string prev="",curr="";
    for(int i=0;i<n;i++)
    {
        if(prev!=curr && curr!="")
        {
            c++;
            prev=curr;
            curr="";

        }
        
            curr+=s[i];
    }
    if(prev!=curr && curr!="")
    {
            c++;
            prev=curr;
            curr="";

    }
    int cc=0;
    prev="",curr="";
    for(int i=0;i<n;i++)
    {
        if(prev!=curr && curr!="")
        {
            cc++;
            prev=curr;
            curr="";

        }
        
            curr+=s[i];
    }
    if(prev!=curr && curr!="")
    {
            cc++;
            prev=curr;
            curr="";

    }
    cout<<max(cc,c);
return 0;
}

Measured memory_bytes: 720
N = int(input())

size_list = [int(i) for i in input().split()]
size_list.sort(reverse=True)

cnt = 1
compare = sum(size_list)

for i in range(N):
    compare -= size_list[i]
    if compare * 2 < size_list[i]:
        break
    cnt += 1

print(cnt)

Measured memory_bytes: 14308
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] data = new int[n];
    int count = 0;

    for(int i = 0;i < n;i++) {
      data[i] = sc.nextInt();
    }

    Arrays.sort(data);

    for(int i = 0;i < n;i++) {
      for(int j = i+1;j < n;j++) {
        for(int k = j+1;k < n;k++) {
          if(data[k] < data[i] + data[j]) count++;
        }
      }
    }

    System.out.println(count);

  }

}


Measured memory_bytes: 26796
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

typedef pair<int, int> Pii;

#define MP make_pair
#define F first
#define S second

int main() {
  
  int n, m, a;
  while(cin >> n >> m >> a, (n|m|a)) {
    vector<pair<int, Pii> > vec(m);
    for(int i=0; i<m; i++) {
      int h, p, q; cin >> h >> p >> q;
      vec[i] = MP(h, Pii(p, q));
    }
    
    sort(vec.begin(), vec.end());
    vector<int> ans(n+1);
    iota(ans.begin(), ans.end(), 0);
    
    for(int i=0; i<m; i++)
      swap(ans[vec[i].S.F], ans[vec[i].S.S]);
    
    cout << ans[a] << endl;
  }
  
  return 0;
}

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

int main(){
    string s;
    cin >> s;
    if(s=="ABC"){
        cout<< "ARC"<<endl;
    }else{
        cout<< "ABC"<<endl;
    }
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }


void compute() {

}

int main() {
  int a,b;
  cin >> a >> b;
  int cnt = 0;
  int cur = 1;
  while( cur < b ) {
    cur--;
    cur += a;
    ++cnt;
  }
  cout << cnt << endl;
  compute();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <cstring>
 
#define pb push_back
#define mp make_pair
 
using namespace std;
 
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;
 
bool dp[100005];
 
int main() {
  memset(dp, false, sizeof dp);
 
  int x;
  cin >> x;
 
  vi denom = {100, 101, 102, 103, 104, 105};
  dp[0] = true;
  dp[100] = dp[101] = dp[102] = dp[103] = dp[104] = dp[105] = true;
  for (int i = 106; i <= x; ++i) {
    for (int d : denom) {
      if (dp[i-d]) {
        dp[i] = true;
        break;
      }
    }
  }
 
  cout << dp[x] << endl;
  return 0;
}

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

#define rep(i,a) for(int i = 0; i < a; i++)
#define repi(i,a,b) for(int i = a; i < b; i++)
#define pb push_back
#define mp make_pair
#define INF 1e9

using namespace std;

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

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

int main(){
  int N;
  while(cin>>N,N){
    vector<pii> field;
    field.pb(mp(0,0));
    int mx = 0, my = 0;
    int Mx = 0, My = 0;
    rep(i,N-1){
      int n, d;
      cin >> n >> d;
      int x = field[n].first+dx[d];
      int y = field[n].second+dy[d];
      mx = min(mx, x);
      my = min(my, y);
      Mx = max(Mx, x);
      My = max(My, y);
      field.pb(mp(x,y));
    }
    cout << Mx-mx+1 << ' ' << My-my+1 << endl;
  }
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
#define mt make_tuple
#define mp make_pair
#define int long long

int N, X, Y, D[2005], dist[2005];
vector<int> adj[2005];

main() {
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	cin >> N >> X >> Y;
	for (int i = 1; i <= N - 1; i++) adj[i].push_back(i + 1), adj[i + 1].push_back(i);
	adj[X].push_back(Y);
	adj[Y].push_back(X);
	for (int i = 1; i <= N; i++) {
		memset(dist, 127, sizeof dist);
		queue<pair<int, int> > Q;
		Q.emplace(i, 0);
		dist[i] = 0;
		while (!Q.empty()) {
			auto ii = Q.front();
			Q.pop();
			if (dist[ii.first] != ii.second) continue;
			for (auto u : adj[ii.first]) {
				if (dist[u] > ii.second + 1) {
					dist[u] = ii.second + 1;
					Q.emplace(u, dist[u]);
				}
			}
		}
		for (int j = 1; j <= N; j++)
			D[dist[j]]++;
	}
	for (int i = 1; i <= N - 1; i++) cout << D[i] / 2 << '\n';
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <sstream>

#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>

#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

#include <chrono>
#include <random>

using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<i64>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<i64, i64>;

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

int C(int n, int r){
  if(r < 0) return 0;
  int ret = 1;
  for(int i=1;i<=r;i++){
    ret *= n-i+1;
    ret /= i;
  }
  return ret;
}

int main(){
  int n, k;
  cin >> n >> k;
  if(k == 0){
    cout << n * (n - 1) / 2 << endl;
    for(int i=1;i<=n;i++){
      for(int j=i+1;j<=n;j++){
        cout << i << " " << j << endl;
      }
    }
  }else if(k > C(n-1, 2)){
    cout << -1 << endl;
  }else{
    cout << n - 1 + C(n-1, 2) - k << endl;
    for(int i=2;i<=n;i++){
      cout << 1 << " " << i << endl;
    }
    int f = C(n-1, 2) - k;
    for(int i=2;i<n;i++){
      for(int j=i+1;j<=n;j++){
        if(f == 0)break;
        cout << i << " " << j << endl;
        f--;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <cstdio>
#include <utility>
#define EPS (1e-10)
#define X real()
#define Y imag()
using namespace std;
typedef complex<double> P;
typedef pair<P, double> C;



int main(){
  int n;
  cin >> n;
  double r[n], p[n];
  for(int i = 0; i < n; ++i){
    cin >> r[i];
    p[i] = r[i];
  }

  for(int i = 0; i < n; ++i){
    for(int j = 0; j < i; ++j){
      p[i] = max(p[i],
		 p[j]+sqrt((r[i]+r[j])*(r[i]+r[j])-(r[i]-r[j])*(r[i]-r[j])));
    }
  }
  double ans = 0;
  for(int i = 0; i < n; ++i)
    ans = max(ans, p[i]+r[i]);
  printf("%.10lf\n", ans);
  return 0;
}

Measured memory_bytes: 3276
n, c = map(int, input().split())
a = [None] * n
for i in range(n):
    x, v = map(int, input().split())
    a[i] = (x, v)
l1 = [None] * n
l2 = [None] * n
r1 = [None] * n
r2 = [None] * n
b = 0
m = 0
for i in range(n):
    x, v = a[i]
    b += v - x
    m = max(m, b)
    r1[i] = m
    r2[i] = max(0, b - x)
    b += x
b = 0
m = 0
for i in range(n - 1, -1, -1):
    x, v = a[i]
    x = c - x
    b += v - x
    m = max(m, b)
    l1[n - i - 1] = m
    l2[n - i - 1] = max(0, b - x)
    b += x
m = max(r1[n - 1], l1[n - 1])
for i in range(n - 1): m = max(m, max(r2[n - i - 2] + l1[i], l2[n - i - 2] + r1[i]))
print(m)


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

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

    uint sum = 0;
    vector<uint> ai;
    for (int i = 0; i < n; i++) {
        uint a;
        cin >> a;
        ai.push_back(a);
        sum = sum ^ a;
    }

    for (auto aiIter = ai.begin(); aiIter != ai.end(); aiIter++) {
        if (aiIter != ai.begin()) {
            cout << " ";
        }
        cout << (sum ^ *aiIter);
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 4316
#include<stdio.h>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>

using namespace std;
typedef long long ll;
 
#define REP(i,n) for(int i=0;i<(int)(n);i++)
 
int main()
{
    int n,ans;
    while(1==1)
    {
        ans=0;
        scanf("%d\n",&n);
        if(n==0)return 0;
        n*=2;
        for(int i=2;i<n;i++)
        {
            if(n%i==0 && i<n/i &&(i%2==1||(n/i)%2==1))
            {
                ans++;
                //printf("##%d##\n",i);
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 3204
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
ans=0
if x==sum(a):
    ans=n
elif x>sum(a):
    ans=n-1
else:
    for i in range(n):
        if x>=a[i]:
            ans+=1
            x-=a[i]
        else:
            break
print(ans)

Measured memory_bytes: 3064
def hantei(st):
    if 0<int(st)<=12:
        return True
    else:
        return False

S =input()
if hantei(S[0:2])and hantei(S[2:]):
    print("AMBIGUOUS")
elif hantei(S[0:2])and not hantei(S[2:]):
    print("MMYY")
elif not hantei(S[0:2])and hantei(S[2:]):
    print("YYMM")
else:
    print("NA")

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

int main(){
  string S;
  cin >> S;
  int flag=0;
  int numc=0;
  int numa=0;
  if(S.at(0)=='A') flag++;
  for(int i=2; i<S.size()-1; i++){
    if(S.at(i)=='C') numc++;
  }
  if(numc==1) flag++;
  for(int i=1; i<S.size(); i++){
    if(S.at(i)>='a' && S.at(i)<='z') numa++;
  }
  if(numa==S.size()-2) flag++;
  if(flag==3) cout << "AC" << endl;
  else cout << "WA" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w; cin >> h >> w;
  vector<int> cnt(26);
  rep(i, h) {
    string s;
    cin >> s;
    rep(j, w) cnt[s[j]-'a']++;
  }
  int cnt2=0, cnt4=0, cntOdd=0;
  rep(i, 26) {
    cntOdd += cnt[i]%2;
    cnt4 += cnt[i]/4;
    cnt2 += cnt[i]%4/2;
  }
  if(h%2==0 && w%2==0) {
    if(cntOdd || cnt2) cout << "No" << endk;
    else cout << "Yes" << endk;
  } else if(h%2==0) {
    if(cntOdd || cnt2 > h/2) cout << "No" << endk;
    else cout << "Yes" << endk;
  } else if(w%2==0) {
    if(cntOdd || cnt2 > w/2) cout << "No" << endk;
    else cout << "Yes" << endk;
  } else {
    if(cntOdd != 1 || cnt2 > w/2+h/2) cout << "No" << endk;
    else cout << "Yes" << endk;
  }
  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1; i <= n; i += 2){
    int cnt = 0;
    REP(j, i+1){
      if(i % j == 0) cnt++;
    }
    if(cnt == 8) ans ++;
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
H,N=map(int,input().split())
dp=[10**12 for _ in range(H+1)]
dp[0]=0
for i in range(N):
  h,n=map(int,input().split())
  for j in range(H+1):
    dp[j]=min(dp[j],dp[max(0,j-h)]+n)
print(dp[H])

Measured memory_bytes: 44520
#include <stdio.h>

int main(void) {
	int m, f, r;
	while (scanf("%d%d%d", &m, &f, &r) == 3 && (m != -1 || f != -1 || r != -1)) {
		int grade;
		int total = m + f;
		if (m < 0 || f < 0) grade = 'F';
		else if (total >= 80) grade = 'A';
		else if (total >= 65) grade = 'B';
		else if (total >= 50) grade = 'C';
		else if (total >= 30) grade = (r >= 50 ? 'C' : 'D');
		else  grade = 'F';
		printf("%c\n", grade);
	}
	return 0;
}




Measured memory_bytes: 2056
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=1)}([function(e,t,r){"use strict";e.exports=class{constructor(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=e.length,this.items=e,this.ind=0}enq(e){this.size+=1,this.items.push(e)}deq(){var e=this.items[this.ind];return this.size-=1,this.ind+=1,e}clear(){this.items=[],this.size=0,this.ind=0}}},function(e,t,r){"use strict";var n=r(2);r(3)(n.readFileSync("/dev/stdin","utf8"))},function(e,t){e.exports=require("fs")},function(e,t,r){"use strict";var n=r(4),i=r(5);e.exports=function(e){var t=new n(e);i(t)}},function(e,t,r){"use strict";var n=r(0);e.exports=class{constructor(e){var t=e.trim().split(/\s+/g);this.inp=new n(t)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(e,t,r){"use strict";var n=r(0);e.exports=function(e){for(var t=e.in(),r=new Array(t),i=0;i<t;i++)r[i]=[];for(var o=0;o<t-1;o++){var s=e.in()-1,u=e.in()-1,c=e.in();r[s].push({v:u,c:c}),r[u].push({v:s,c:c})}var a=new Array(t).fill(-1);a[0]=0;var f=new n;for(f.enq(0);f.size>0;)for(var l=f.deq(),p=r[l].length,v=0;v<p;v++){var d=r[l][v];-1==a[d.v]&&(a[d.v]=a[l]+d.c,f.enq(d.v))}for(var h=new Array(t),y=0;y<t;y++)h[y]=a[y]%2?0:1;console.log(h.join("\n"))}}]);

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N + 1), b(N + 1), c(N + 1);
  vector<vector<int> > dp(N + 1, vector<int>(3));
  for (int i = 1; i <= N; i++) cin >> a[i] >> b[i] >> c[i];
  dp[1][0] = a[1], dp[1][1] = b[1], dp[1][2] = c[1];
  for (int i = 2; i <= N; i++) {
    dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i]);
    dp[i][1] = max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i]);
    dp[i][2] = max(dp[i - 1][0] + c[i], dp[i - 1][1] + c[i]);
  }

  cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;
  return 0;
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(6) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n;

signed main(){

    while(1){
        int h,w;
        cin >> h >> w;
        if(h==0 && w==0){
            break;
        }
        REP(i,h){
            REP(j,w){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}



Measured memory_bytes: 3120