akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll n;
    cin >> n;
    vec num;
    while (n > 0)
    {
        ll x = n % 26;
        num.push_back(x);
        n /= 26;
    }
    ll siz = num.size();
    vec dight(siz);
    loop(i, siz) dight[i] = num[siz - 1 - i];
    //dight[0]以外に0があればout
    bool check = true;
    while (check)
    {
        check = false;
        Loop(i, 1, siz)
        {
            if (dight[i] == 0)
                check = true;
        }
        pool(i, siz - 2)
        {
            if (dight[i] > 0 && dight[i + 1] == 0)
            {
                dight[i]--;
                dight[i + 1] = 26;
            }
        }
    }
    loop(i, siz)
    {
        if (dight[i] > 0)
        {
            cout << (char)('a' + (dight[i] - 1));
        }
    }
    putout("");
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


signed main(void) 
{
    ll n, k;
    cin >>n >>k;
    vll a(n);
    
    rep(i, n) {
        cin >>a[i];
            
            if (i > k-1) {
                if (a[i] <= a[i-(k)]) {
                    mes("No");
                } else {
                    mes("Yes");
                }
            }
    }
    
    
    
    
    
    
    


}


Measured memory_bytes: 4844
import Control.Monad
import Control.Applicative

slice from to str = take (to - from + 1) (drop from str)

applyOp ["print", as, bs] (str, prt) = (str, prt ++ [result])
    where a = read as
          b = read bs
          result = slice a b str

applyOp ["replace", as, bs, newStr] (str, prt) = (replace a b str newStr, prt)
    where a = read as
          b = read bs
          replace from to str newStr = take from str ++ newStr ++ drop (to + 1) str

applyOp ["reverse", as, bs] (str, prt)= (reverse' a b str, prt)
    where a = read as
          b = read bs
          reverse' from to str = take from str ++ (reverse (slice a b str)) ++ drop (to + 1) str

main = do
    str <- getLine
    nops <- read <$> getLine
    opsStr <- replicateM nops $ words <$> getLine
    let (_, prt) = foldl (flip applyOp) (str, []) opsStr
    mapM_ putStrLn prt

Measured memory_bytes: 5692
m,d=map(int,input().split())
def make_divisors(n):
    divisors=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            divisors.append(i)
            if i!=n//i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

ans=0
for i in range(1,m+1):
    Div=make_divisors(i)
    D=[]
    for k in Div:
        if 1<k<10:
            D.append(k)
    for k in D:
        day=k*10+(i//k)
        if 1<i//k<10 and day<=d:
            ans+=1
print(ans)

Measured memory_bytes: 38412
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <assert.h>

typedef struct node {
    struct node *prev;
    struct node *next;
    int v;
} Node;

int main()
{
    int i, n, q,x;
    Node *z;
    fscanf(stdin, "%d", &n);
    Node *root = NULL;
    Node END;
    END.next=NULL;
    END.prev=NULL;
    Node *cursor = &END;
    Node *tmp;
    root = &END;

    for (i=0; i<n; i++) {
        fscanf(stdin, "%d", &q);
        switch (q) {
            case 0:  // insert
               fscanf(stdin, "%d", &x);
                z = (Node*)malloc(sizeof(Node));
                z->prev = cursor->prev;
                if (cursor->prev==NULL) {
                    root = z;
                } else {
                    cursor->prev->next = z;
                }
                cursor->prev=z;
                z->next = cursor;
                z->v = x;
                cursor = z;
                break;
            case 1:  // move
                fscanf(stdin, "%d", &x);
                if (x>0)
                    for (int j=0; j<x; j++) {
                        cursor = cursor->next;
                        if (cursor==NULL) break;
                    }
                else
                    for (int j=0; j<-x; j++)
                        cursor = cursor->prev;
                break;
            case 2:  //erase
                cursor->next->prev = cursor->prev;
                if (cursor->prev!=NULL)
                    cursor->prev->next = cursor->next;
                else
                    root = cursor->next;
                tmp = cursor;
                cursor = cursor->next;
                free(tmp);
        }
    }

    tmp = root;
    do {
        printf("%d\n", tmp->v);
        tmp = tmp->next;
    } while (tmp->next);
    return 0;
}


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

int main(){
 string s;
  bool flag = true;
  cin >> s;
  r(i,s.length()){
    if(i%2==0){
      if(s.at(i)=='L')flag=false;
    }
      else {
        if(s.at(i)=='R')flag=false;
      }
  }
  if(flag)cout << "Yes"<<endl;
  else cout << "No"<<endl;
}

Measured memory_bytes: 256
function Main(input) {
	input = input.split("\n");
	
	var a = parseInt(input[0], 10);
	
	if  (400 <= a && a < 600) {
	var result = 8;
	
	} else if (600 <= a && a < 800) {
	var result = 7;

	
	} else if (800 <= a && a < 1000) {
	var result = 6;

	
	} else if (1000 <= a && a < 1200) {
	var result = 5;

	
	} else if (1200 <= a && a < 1400) {
	var result = 4;

	
	} else if (1400 <= a && a < 1600) {
	var result = 3;

	
	} else if (1600 <= a && a < 1800) {
	var result = 2;

	
	} else if (1800 <= a && a < 2000) {
	var result = 1;

	
	} else {
	}
	
	
	
	console.log(result);
	}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29660
N, M = map(int, input().split())
conditions = [tuple(map(int, input().split())) for _ in range(M)]
num = [0] * N
checked = [None] * N
if N == 1:
    if M == 0: print(0)
    else:
        conditions = list(set(conditions))
        if len(conditions) == 1: print(conditions[0][1])
        else: print(-1)
else:
    for s, c in conditions:
        s -= 1
        if checked[s] is None:
            checked[s] = c
            num[s] = c
        else:
            if checked[s] == c: continue
            else:
                print(-1)
                break
    else:
        if checked[0] is None and num[0] == 0: num[0] = 1
        print(''.join(str(n) for n in num) if num[0] != 0 else -1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N;cin>>N;
    N--;
    string S;
    while(N>=0){
        S+=char('a'+N%26);
        N/=26;
        N--;
    }
    reverse(all(S));
    if(si(S)==0) S="a";
    cout<<S<<endl;
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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; }
typedef pair<int,int> P;

int main(){
  int n,m;
  cin >> n >> m;
  int l=1;
  int r=n;
  rep(i,m){
    int lt,rt;
    cin >> lt >> rt;
    chmax(l,lt),chmin(r,rt);
  }
  if(l<=r)cout << r-l+1 << endl;
  else cout << 0 << endl;
  return 0;
}


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

int main()
{
    int N;
    cin >> N;
    string si;
    map<string, unsigned long long> s_map;
    for(int i=0;i<N;i++){
        cin >> si;
        sort(si.begin(), si.end());
        if(s_map.count(si)==0) s_map[si]=0;
        s_map[si]++;
    }
    unsigned long long res = 0;
    for(auto m : s_map){
        res += m.second * (m.second -1) / 2;
    }
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 11136
#include<stdio.h>
int main()
{
    long long int a,b;
    char c;
    scanf("%lld %c %lld", &a,&c,&b);
    if(c=='+')
    {
        printf("%lld", a+b);
    }
    else if(c=='-')
    {
        printf("%lld", a-b);
    }
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main()
{
   int N;
   cin >> N;
   int L[101];
   for (int i = 0; i < N; i++)
   {
      cin >> L[i];
   }
   int ans = 0;
   for (int i = 0; i < N; i++)
   {
      for (int j = i + 1; j < N; j++)
      {
         for (int k = j + 1; k < N; k++)
         {
            ll a = L[i];
            ll b = L[j];
            ll c = L[k];
            ll s = a + b + c;
            if (a == b || b == c || c == a)
               continue;
            ll m = max(max(a, b), c);
            if (s - m > m)
            {
               ans++;
            }
         }
      }
   }
   cout << ans << endl;

   return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, K;
    cin >> N >> K;
 
    map<ll, ll> M;
    REP(i, N){
        ll a;
        cin >> a;
        
        M[a]++;
    }

    vector<ll> V;
    
    if(M.size() <= K){
        cout << 0 << endl;
        return 0;
    }

    for(auto iter=M.begin(); iter!=M.end(); iter++){
        V.push_back(iter->second);
    }
    
    sort(V.begin(), V.end());

    ll ans = 0;
    REP(i , M.size()-K){
        ans += V[i];
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

using ll = long long;

int main(){
  ll w, h, x, y;
  cin >> w >> h >> x >> y;
  cin.ignore();

  // 要は、2等分でしかない
  double s;
  s = w * h / ((double) 2);
  printf("%.6f ", s);

  // 0は別
  if((w == 0) && (h == 0)){
    printf("0\n");
    return 0;
  } else if((w == 0) || (h == 0)){
    printf("1\n");
    return 0;
  }

  // x, yがそれぞれw, hの半分であればよさそう
  if(((x == w/2) && (w % 2 == 0)) && ((y == h / 2) && (h % 2 == 0))){
    printf("1\n");
  } else {
    printf("0\n");
  }
  return 0;
}


Measured memory_bytes: 256
using System;

public static class aaa{
  public static int Main(string[] args){
    var a = Console.ReadLine().Split(' ');
    if(a[1] == "+") Console.WriteLine(int.Parse(a[0]) + int.Parse(a[2]));
    else Console.WriteLine(int.Parse(a[0]) - int.Parse(a[2]));
    return 0;
  }
}


Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mt make_tuple
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	int ma=0,to;
	loop(i,1,n){
		cout<<"? 1 "<<i+1<<endl;
		int a;cin>>a;
		if(ma<a){
			ma=a;
			to=i;
		}
	}
	vi out(n);
	out[0]=to;
	rep(i,n)if(to!=i){
		cout<<"? "<<to+1<<" "<<i+1<<endl;
		int a;cin>>a;
		out[a]=i;
	}
	cout<<"!";
	rep(i,n)cout<<" "<<out[i]+1;cout<<endl;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    vector<int> vec(3);
    for(int i;i<3;i++){
        cin>>vec.at(i);
    }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    cout<<vec.at(0)*10+vec.at(1)+vec.at(2)<<endl;
}

Measured memory_bytes: 256
// AOJ 2729 Delete Files
// 2018.2.7 bal4u
 
#include <stdio.h>
#include <string.h>

#define QMAX 1002
typedef struct { int k, t; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i]; que[i] = que[min]; que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
//	if (qsize == 0) return 0;
//	*a = que[0].a, *b = que[0].b, *c = que[0].c;
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int k, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].t = t, que[i].k = k;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i]; que[i] = que[min]; que[min] = qt;
		i = min;
	}
}

char d[1002]; int w[1002];
char mk[1002];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	while (c < '0') c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, i, k, f, len, ans;

    n = in();
	qsize = 0;
	for (i = 0; i < n; i++) {
		f = getchar_unlocked() == 'y', getchar_unlocked();
		d[i] = f, w[i] = in();
		if (f) enq(i, w[i]);
	}

	ans = 0;
	while (qsize) {
		k = que[0].k, len = que[0].t, deq();
		if (mk[k]) continue;

		ans++;
		mk[k] = 1;
		for (i = k-1; i >= 0; i--) {
			if (!d[i] && w[i] >= len) break;
			mk[i] = 1;
		}
		for (i = k+1; i < n; i++) {
			if (!d[i] && w[i] >= len) break;
			mk[i] = 1;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2108
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<int, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

int h, w, n;
string t, s;
int si, sj;

bool inr(int ci, int cj){
    if(ci >= 1 && cj >= 1 && ci <= h && cj <= w)
        return true;
    return false;
}

bool whoWins(char d1, char d2){
    int ci = si;
    int cj = sj;
    for(int i = 0 ; i < n; i ++ ){
        if(t[i] == d1){
            if(d1 == 'U')ci--;
            else if(d1 == 'D') ci++;
            else if(d1 == 'L') cj -- ;
            else if(d1 == 'R') cj ++ ;
            if(!inr(ci, cj))
                return true;
        }
        if(s[i] == d2){
            if(d2 == 'U'){
                if(inr(ci-1, cj)) ci -- ;
            }
            else if(d2 == 'D'){
                if(inr(ci+1, cj)) ci ++ ;
            }
            else if(d2 == 'L'){
                if(inr(ci, cj-1)) cj -- ;
            }
            else if(d2 == 'R'){
                if(inr(ci, cj+1)) cj ++ ;
            }
        }
    }
    return false;
}

int main(){
    fastIO;
    cin >> h >> w >> n;
    cin >> si >> sj;
    cin >> t >> s;  
    if(whoWins('R', 'L') || whoWins('L', 'R') || whoWins('U', 'D') || whoWins('D', 'U')){
        cout << "NO\n";
    }
    else{
        cout << "YES\n";
    }
    return 0;
}



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


int main(){
    ll h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    REP(i, h){
        cin >> s.at(i);
    }

    ll ans = h * w;
    REP(i, (1 << (h - 1))){
        bitset<9> cut(i);
        const ll numseg = cut.count() + 1;
        vector<vector<ll>> numwhite(numseg, vector<ll>(w, 0));
        ll idx = 0;
        REP(u, h){
            REP(j, w){
                if(s.at(u).at(j) == '1'){
                    numwhite.at(idx).at(j)++;
                }
            }
            if(u < h - 1 && cut[u]){ idx++; }
        }

        bool fail = false;
        REP(u, numseg){
            REP(j, w){
                fail |= (numwhite.at(u).at(j) > k);
            }
        }
        if(fail){ continue; }

        ll tmp = 0;
        vector<ll> cs(numseg, 0);
        REP(j, w){
            bool should_cut = false;
            REP(u, numseg){
                should_cut |= (cs.at(u) + numwhite.at(u).at(j) > k);
            }
            if(should_cut){
                tmp++;
                fill(cs.begin(), cs.end(), 0);
            }
            REP(u, numseg){
                cs.at(u) += numwhite.at(u).at(j);
            }
        }
        ans = min(ans, tmp + static_cast<ll>(cut.count()));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXN 100005
#define X first
#define Y second
#define MOD 1000000007
#define inf 1e18
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
ll n,i,j,t;

int main()
{
    fastio;
    ll a,b;
    cin>>a>>b;
    if(a>=1 && a<=9 && b>=1 && b<=9) cout<<a*b<<endl;
    else cout<<"-1"<<endl;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as BS
import Control.Monad

data Counter = Counter { cD :: {-# UNPACK #-} !Int,
                         cM :: {-# UNPACK #-} !Int,
                         cDM :: {-# UNPACK #-} !Int,
                         cAcc :: {-# UNPACK #-} !Int }

query :: VU.Vector Char -> Int -> Int
query vec k = cAcc $ VU.foldl' update cInit padded
  where
    cInit = Counter 0 0 0 0
    padded = VU.zip vec $ VU.replicate (k-1) 'X' VU.++ vec
    update c0 (now,old) = c2
      where
        c1 = case now of
          'D' -> c0 { cD = cD c0 + 1 }
          'M' -> c0 { cM = cM c0 + 1, cDM = cDM c0 + cD c0 }
          'C' -> c0 { cAcc = cAcc c0 + cDM c0 }
          _   -> c0
        c2 = case old of
          'D' -> c1 { cD = cD c1 - 1, cDM = cDM c1 - cM c1 }
          'M' -> c1 { cM = cM c1 - 1 }
          _   -> c1

main :: IO ()
main = do
  n <- read <$> getLine
  vec <- VU.unfoldrN n BS.uncons <$> BS.getLine
  q <- read <$> getLine
  ks <- VU.unfoldrN q (BS.readInt . BS.dropWhile (==' ')) <$> BS.getLine
  VU.mapM_ (putStrLn . show . query vec) ks


Measured memory_bytes: 14204
#include <bits/stdc++.h>
//#pragma GCC optimize(2)

using namespace std;

#define LL long long
#define Rint register int
#define U unsigned
#define forn(i,a,b) for(int i = a;i <= b;++i)
#define nfor(i,a,b) for(int i = a;i >= b;--i)
#define pii pair<int ,int>
#define MS0(X) memset(X,0,sizeof(X))
#define MSf(X) memset(X,false,sizeof(X))
#define MS1(X) memset(X,-1,sizeof(X))
#define BR printf("--------------------\n")
#define pb push_back
#define rep(i,a,b) for(Rint i=a;i<=b;++i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dirx[8]={1,0,-1,0,1,-1,-1,1};
int diry[8]={0,1,0,-1,1,1,-1,-1};
LL a[maxn];
LL l[maxn];
LL sum[maxn];
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
   	cout.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        l[a[i]]++;
    }
    for(int i=1;i<=3005;i++)
    {
        sum[i]=sum[i-1]+l[i];
    }
    LL ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            int l=max(a[i],a[j])-min(a[i],a[j])+1;
            int r=a[i]+a[j]-1;
            //DEBUG(l);DEBUG(r);
            if(l<=r)
            {
                ans+=sum[r]-sum[l-1];
                if(a[i]>=l&&a[i]<=r)
                    ans--;
                if(a[j]>=l&&a[j]<=r)
                    ans--;
                //DEBUG(ans);
            }
        }
    }
    cout<<ans/3<<endl;
	return 0;
}


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

typedef long long ll;
typedef long double ld;

#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    ll A, B, T;

    cin >> A >> B >> T;

    cout << T / A * B << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int w = 0;
int h = 0;
vector<vector<int>> island;
vector<vector<bool>> reached;

void go(int x_pos, int y_pos);

int main()
{
    while(1){
        cin >> w >> h;
        if(w == 0) break;
        
        island.resize(h);        
        for(int i = 0; i < h; i++){
            island[i].resize(w);
        }
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                cin >> island[i][j];
            }
        }

        reached.resize(h);
        for(int i = 0; i < h; i++){
            reached[i].resize(w);
        }
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                reached[i][j] = false;
            }
        }


        int count = 0;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(island[i][j] == 1 && !reached[i][j]){
                    count++;
                    go(j, i);
                }
            }
        }
        
        cout << count << endl;
        
    }
    return 0;
}

void go(int x_pos, int y_pos)
{
    reached[y_pos][x_pos] = true;
    for(int dx = -1; dx <= 1; dx++){
        for(int dy = -1; dy <= 1; dy++){
            if(x_pos + dx >= 0 && x_pos + dx < w && y_pos + dy >= 0 && y_pos + dy < h){
                if(island[y_pos+dy][x_pos+dx] == 1 && !reached[y_pos+dy][x_pos+dx]){
                    go(x_pos+dx, y_pos+dy);
                }
            }
        }
    }
}

Measured memory_bytes: 1528
n = int(input())
AB = []
for _ in range(n):
    a, b = map(int, input().split())
    AB.append((a,b))

AB = sorted(AB, key=lambda x:x[1])

tota = 0
ans = 'Yes'
for i in range(n):
    tota += AB[i][0]
    if tota > AB[i][1]:
        ans = 'No'
print(ans)
    

Measured memory_bytes: 33396
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    int v[n];
    for(int i=0;i<n;i++)cin>>v[i];
    int maxv=v[1]-v[0];
    int minv=v[0];
    for(int i=1;i<n;i++){
        minv=min(minv,v[i-1]);
        maxv=max(maxv,v[i]-minv);
    }
    cout<<maxv<<endl;
    return 0;
}


Measured memory_bytes: 3900
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

int a,b;

int main()
{
	scanf("%d%d",&a,&b);
	if(a<=5) puts("0");
	if(a>=6&&a<=12) printf("%d",b/2);
	if(a>=13) printf("%d",b);
	
	return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    if ((a + b) % 2 == 0) {
        cout << (a + b) / 2 << endl;
    } else {
        cout << (a + b) / 2 + 1 << endl;
    }
}


Measured memory_bytes: 256
fn chmin<T: PartialOrd>(x: &mut T, a: T) {
    if *x > a {
        *x = a;
    }
}

fn main() {
    proconio::input! {
        n: usize,
        k: usize,
        h: [i32; n],
    }
    let mut dp = vec![std::i32::MAX; n];
    dp[0] = 0;
    for (i, a) in h.iter().enumerate() {
        let d = dp[i];
        for (b, x) in h.iter().zip(dp.iter_mut()).skip(i + 1).take(k) {
            chmin(x, d + (*a - *b).abs());
        }
    }
    let ans = dp[n - 1];
    println!("{}", ans);
}

Measured memory_bytes: 3212
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
	vector<pair<int,int> >a[5000];
	int b[5010];
	int d[5010];
	for (int i = 0; i < 5010; i++){
		b[i] = 0;
		d[i] = 0;
	}
	int c;
	int n, m;
	int x, y, z;
	c = 0;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++){
		scanf("%d %d %d", &x, &y, &z);
		a[x-1].push_back(make_pair(y-1, z+1));
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < i+1; j++){
			if (b[j] > 0){
				if (d[j] < b[j] - 1)d[j] = b[j] - 1;
				d[j + 1] = b[j] - 1;
			}
		}
		for (int j = 0; j < a[i].size(); j++){	
			if (d[a[i][j].first] < a[i][j].second){
				d[a[i][j].first] = a[i][j].second;

			}
		}
		for (int j = 0; j < i+1; j++){
			b[j] = d[j];
			if (b[j] > 0){
				c++;
			}
			d[j] = 0;
		}
	}
	printf("%d\n", c);

	return 0;
}

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

int main() {
  int N, K, X, Y;
  int sum;

  cin >> N >> K >> X >> Y;

  if (N > K)
  {
    sum = K * X + (N-K) * Y;
  }
  else
  {
    sum = N * X; 
  }

  cout << sum << endl;
}

Measured memory_bytes: 1016
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
long long modpow(long long m, long long n, long long modvalue) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2, modvalue);
        return t * t % modvalue;
    } else {
        return modpow(m, n - 1, modvalue) * m % modvalue;
    }
}

long long moddiv(long long a, long long b, ll modvalue) { return (a * modpow(b, mod - 2, modvalue)) % modvalue; }

const ll INF = 1LL << 60;

string change_binary(long long a) {
    string ret;
    for (int i = 31; i >= 0; i--) {
        ret += (a >> i & 1) + '0';
    }
    return ret;
}

ll nCkmod(ll n, ll k, ll modvalue) {
    ll numera = 1;
    for (int i = n; i > n - k; i--) {
        numera *= i;
        numera %= modvalue;
    }
    ll denomi = 1;
    REP(i, k) {
        denomi *= (i + 1);
        denomi %= modvalue;
    }
    return moddiv(numera, denomi, modvalue);
}

map<ll, ll> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}
vector<ll> dijkstra(vector<vector<P>> graph, ll s) {
    vector<ll> ans(graph.size(), -1);
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push({0, s});
    while (pq.size() > 0) {
        ll cur1 = 0;
        ll cur2 = 0;
        if (ans[pq.top().second] != -1) {
            pq.pop();
        } else {
            cur1 = pq.top().first;
            cur2 = pq.top().second;
            pq.pop();
            ans[cur2] = cur1;
            for (ll i = 0; i < graph[cur2].size(); i++) {
                pq.push({cur1 + graph[cur2][i].first, graph[cur2][i].second});
            }
        }
    }
    return ans;
}
vector<string> maze;
ll h, w;
bool check(ll y, ll x) {
    if (x < 0 || x >= w || y < 0 || y >= h || maze[y][x] == '#') {
        return false;
    }
    return true;
}
double p;
long double f(long double x) { return x + p / (pow(2, x / 1.5)); }
ll gcd(ll a, ll b) {
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}
int main() {
    ll a, b;
    cin >> a;
    REP(i, a) { cout << "ACL"; }
}

Measured memory_bytes: 3640
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug { 
    ($($a: expr),*) => { 
        println!(concat!($(stringify!($a)," = {:?}, "),*), $($a),*);
    } 
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

fn solve() {
    let n = get!(usize);

    let tmp = if n % 2 == 0 {
        println!("{}", n*(n-2)/2);
        n
    } else {
        println!("{}", (n-1)*(n-1)/2);
        n-1
    };
    for i in 1..tmp+1 {
        for j in (i+1)..n+1 {
            if j != tmp-i+1 {
                println!("{} {}", i, j);
            }
        }
    }
}


Measured memory_bytes: 8572
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

double solve(int &N, int &M, int &b, vector<double> &L, vector<double> &A, vector<double> &B){
  vector<int> ns;
  REP(i, N) if(b & (1 << i)) ns.push_back(i);
  double sum = 0.0;
  REP(i, M)
    FOR(j, i + 1, M)
      sum += (L[ns[i]] - L[ns[j]]) * (L[ns[i]] - L[ns[j]]) + (A[ns[i]] - A[ns[j]]) * (A[ns[i]] - A[ns[j]]) + (B[ns[i]] - B[ns[j]]) * (B[ns[i]] - B[ns[j]]);
  return sum;
}

int main() {
  int N, M; cin >>N >>M;
  vector<double> L(N), A(N), B(N);
  REP(i, N) cin >>L[i] >>A[i] >>B[i];
  double ans = 0.0;
  REP(b, (1 << N)){
    bitset<25> bs(b);
    if(bs.count() != M) continue;
    ans = max(ans, solve(N, M, b, L, A, B));
  }
  printf("%8lf\n", ans);
  return 0;
}

Measured memory_bytes: 1272
#include <iostream>

int main() {
  std::string s;
  std::cin >> s;
  int lec[256] = {0};

  for (int i = 0; i < s.length(); ++i) {
    ++lec[s.c_str()[i]];
  }

  for (int i = 0; i < 256; ++i) {
    if ((lec[i] != 0) && lec[i] != 2) {
      std::cout << "No" << std::endl;
      return 0;
    }
  }

  std::cout << "Yes" << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,temp=0;
    cin>>a>>b>>c;
     temp=a;
     a=b;
    b=temp;
    temp=a;
    a=c;
    c=temp;
    cout<<a<<" "<<b<<" "<<c<<endl;
}


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

public final class Main {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int n = fs.nextInt();
        System.out.println(dfs(n, new Integer[n + 1]));
    }

    private static int dfs(int target, Integer[] dp) {
        if (target <= 5) {
            return target;
        }
        if (dp[target] != null) {
            return dp[target];
        }
        int maxNine = 1, maxSix = 1;
        while (maxNine * 9 <= target) {
            maxNine *= 9;
        }
        while (maxSix * 6 <= target) {
            maxSix *= 6;
        }
        return Math.min(1 + dfs(target - maxNine, dp), 1 + dfs(target - maxSix, dp));
    }

    static final class Utils {
        public static void shuffleSort(int[] arr) {
            shuffle(arr);
            Arrays.sort(arr);
        }

        public static void shuffleSort(long[] arr) {
            shuffle(arr);
            Arrays.sort(arr);
        }

        public static void shuffle(int[] arr) {
            final Random r = new Random();

            for (int i = 0; i <= arr.length - 2; i++) {
                final int j = i + r.nextInt(arr.length - i);
                swap(arr, i, j);
            }
        }

        public static void shuffle(long[] arr) {
            final Random r = new Random();

            for (int i = 0; i <= arr.length - 2; i++) {
                final int j = i + r.nextInt(arr.length - i);
                swap(arr, i, j);
            }
        }

        public static void swap(int[] arr, int i, int j) {
            final int t = arr[i];
            arr[i] = arr[j];
            arr[j] = t;
        }

        public static void swap(long[] arr, int i, int j) {
            final long t = arr[i];
            arr[i] = arr[j];
            arr[j] = t;
        }

        private Utils() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> vvi;
  for (int i = 0; i < N; ++i) {
    int K;
    cin >> K;
    vector<int> A(K);
    for (int j = 0; j < K; ++j) {
      cin >> A.at(j);
    }
    vvi.push_back(A);
  }
  vector<int> vi(M);
  for (int i = 0; i < vvi.size(); ++i) {
    for (int j = 0; j < vvi.at(i).size(); ++j) {
      ++vi.at(vvi.at(i).at(j) - 1);
    }
  }
  int ans = 0;
  for (int i = 0; i < vi.size(); ++i) {
    if (vi.at(i) == N) {
      ++ans;
    }
  }
  cout << ans << endl;
}


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

int main()
{
    int n,m,sn = 0;
    cin >> n;
     
    m = n;
    while(m){
        sn += m % 10;
        m /= 10;
    }

    cout << (n % sn ? "No" : "Yes") << endl;

    return 0;
}

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

int main()
{ 
  int n, max_p = 0, p, ans = 0;

  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> p;
    max_p = max(max_p, p);
    ans += p;
  }
  cout << ans - max_p / 2 << endl;
}

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


int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  string s;
  cin>>s;
  int c[15];
  
  
  for(int k=0;k<15;k++){
    c[k]=0;
  }
  int j=0;
  int e=0;
  for(int i=0;i<s.length();i++){
    if((s[i]=='A' || s[i]=='G'|| s[i]=='T'|| s[i]=='C')&&(s[i+1]=='A' || s[i+1]=='G'|| s[i+1]=='T'|| s[i+1]=='C')){
       c[j]=c[j]+1;
    }else{
      j++;
    }
    if((s[i]=='A' || s[i]=='G'|| s[i]=='T'|| s[i]=='C')&&(!(s[i+1]=='A' || s[i+1]=='G'|| s[i+1]=='T'|| s[i+1]=='C'))){
       e=1;
    }
  }
  
  sort(c,c+15);
  if(c[14] !=0 && c[14]>=e){
  cout<<c[14]+1;
  }else if(c[14]<e){
    cout<<e;
  }else{
    cout<<0;
  }
}



Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int n;
vector<vector<int> > to;

void solve(vector<string> start, map<vector<string>, int>& history)
{
    queue<vector<string> > q1;
    q1.push(start);
    history[start] = 0;

    for(int a=1; a<=3; ++a){
        queue<vector<string> > q2;
        while(!q1.empty()){
            vector<string> s = q1.front();
            q1.pop();

            for(int i=0; i<n*2; ++i){
                for(unsigned j=0; j<to[i].size(); ++j){
                    vector<string> t = s;
                    while(!t[i/2].empty()){
                        char c;
                        if(i % 2 == 0){
                            c = t[i/2][0];
                            t[i/2] = t[i/2].substr(1);
                        }else{
                            c = t[i/2][t[i/2].size()-1];
                            t[i/2] = t[i/2].substr(0, t[i/2].size()-1);
                        }

                        if(to[i][j] % 2 == 0){
                            t[to[i][j]/2] = c + t[to[i][j]/2];
                        }else{
                            t[to[i][j]/2] += c;
                        }

                        if(history.find(t) == history.end()){
                            q2.push(t);
                            history[t] = a;
                        }
                    }
                }
            }
        }
        q1 = q2;
    }
}

int main()
{
    for(;;){
        int m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        to.assign(2*n, vector<int>());
        for(int i=0; i<m; ++i){
            string s, t;
            cin >> s >> t;
            int a = (s[0] - '0') * 2;
            int b = (t[0] - '0') * 2;
            if(s[1] == 'E')
                ++ a;
            if(t[1] == 'E')
                ++ b;
            to[a].push_back(b);
            to[b].push_back(a);
        }

        vector<string> s(n), t(n);
        for(int i=0; i<n; ++i){
            cin >> s[i];
            if(s[i] == "-")
                s[i] = "";
        }
        for(int i=0; i<n; ++i){
            cin >> t[i];
            if(t[i] == "-")
                t[i] = "";
        }

        map<vector<string>, int> history1, history2;
        solve(t, history2);
        solve(s, history1);

        int ret = INT_MAX;
        map<vector<string>, int>::iterator it1, it2;
        it1 = history1.begin();
        it2 = history2.begin();
        while(it1 != history1.end() && it2 != history2.end()){
            if(it1->first == it2->first)
                ret = min(ret, it1->second + it2->second);
            if(it1->first < it2->first)
                ++ it1;
            else
                ++ it2;
        }

        cout << ret << endl;
    }
}

Measured memory_bytes: 91652
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		String[] nl = n.split("");
		if (nl[0].equals("9") || nl[1].equals("9")) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22996
def make_divisors(n):
    a,b =[],[]
    i = 1
    while i*i<=n:
        if n%i == 0:
            a.append(i)
            if i != n//i:
                b.append(n//i)
        i+= 1
    return a+b[::-1]

n = int(input())
c = 0
for i in range(1,n+1):
    if len(make_divisors(i))== 8 and i%2==1:
        c+=1
print(c)

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

int main(){
	int n, d;
	vector<int> c[101];
	// poewr[i] := 国 i の戦闘力(ミサイルの数値の合計)
	int power[101];
	
	while( cin >> n >> d, n || d ){
		// 入力
		for(int i=0 ; i < n ; i++ ){
			int m;
			cin >> m;
			
			power[i] = 0;
			c[i] = vector<int>(m);
			for(int j=0 ; j < m ; j++ ){
				cin >> c[i][j];
				power[i] += c[i][j];
			}
		}
		
		bool is_remove = true;
		while( is_remove ){
			is_remove = false;
			
			for(int i=0 ; i < n ; i++ ){
				// 国 i のミサイルを除去すると仮定.
				int k = c[i].size() - 1;
				// 国 i がミサイルを持っていないとき.
				if( k < 0 ) continue;
				
				power[i] -= c[i][k];
				// 各国の最大と最小を求める.
				int max_p=0, min_p=1e+8;
				for(int j=0 ; j < n ; j++ ){
					max_p = max(max_p, power[j]);
					min_p = min(min_p, power[j]);
				}
				
				if( max_p - min_p <= d ){ // 国 i のミサイルを除去できる
					c[i].pop_back();
					is_remove = true;
					break;
				}else{ // 除去できない.
					power[i] += c[i][k];
				}
			}
		}
		bool ans = true;
		for(int i=0 ; i < n ; i++ ){
			if( !c[i].empty() ) ans = false;
		}
		cout << (ans? "Yes" : "No") << endl;
	}
}

Measured memory_bytes: 1312
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

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

    int ans = 1;
    while(ans*2 <= 2*k+1 && n > 0)ans*=2, n--;
    cout << ans + k*n;

}

Measured memory_bytes: 256
crt = 0 
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = []
for i in range(n): 
    a.append(list(map(int, input().split())))
for i in a: 
    total = 0
    for k in range(m): 
        total += i[k] * b[k]
    if total + c > 0: crt += 1
print(crt)

Measured memory_bytes: 3188
from collections import defaultdict,deque
import itertools
n,p = [int(x) for x in input().split()]
s = list(input())
if p!=2 and p!=5:
  r = defaultdict(int)
  a =[]
  s1 = s[::-1]
  for i in range(n):
    a.append((int(s1[i])%p*pow(10,i,p))%p)
  a = [0]+a[::-1]
  b = list(itertools.accumulate(a))
  for i in b:
    r[i%p]+=1
  ans = 0
  for i in r.values():
    ans+=(i*(i-1))//2
  print(ans)
elif p==2:
  ans = 0
  for i in range(n):
    if int(s[i])%2==0:
      ans +=i+1
  print(ans)
elif p==5:
  ans = 0
  for i in range(n):
    if int(s[i])%5==0:
      ans +=i+1
  print(ans)


Measured memory_bytes: 70344
import java.util.Scanner;


public class Main {
	public static void main(String[]args){
		
		//????????£????????????
		Scanner sc = new Scanner(System.in);
		
		//?????? 
		int S = sc.nextInt();
		int h = S / 3600; 
		
		//???
		int m = S % 3600 / 60;
		
		
		//?§?
		int s = S % 60;
		
		System.out.println(h + ":" + m + ":" + s);
	}
}

Measured memory_bytes: 26224
n = int(input())
a = [int(x) for x in input().split()]

cnt = [0 for _ in range(n+1)]

for i in range(n):
    cnt[a[i]] += 1

ans = 0

for i in range(n+1):
    ans += cnt[i]*(cnt[i]-1)//2

for i in range(n):
    tmp = ans - cnt[a[i]]*(cnt[a[i]]-1)//2 + (cnt[a[i]]-1)*(cnt[a[i]]-2)//2
    print(tmp)


Measured memory_bytes: 87372
def gcd(x, y):
    while y != 0:
        x, y = y, x%y
    return x
    
def lcm(x, y):
    return x * y // gcd(x, y)
    
N = int(input())
T = []
for i in range(N):
    T.append(int(input()))
temp = T[0]
for i in range(N-1):
    temp = lcm(temp, T[i+1])
print(temp)

Measured memory_bytes: 3064