akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    S = readline().decode('utf-8')
    L = len(S)
    A = [0]*L
    for i in range(L):
        if S[i] == 'E':
            if i == 0:
                A[i] = 1
            else:
                A[i]=A[i-1]+1
        else:
            if i == 0:
                continue
            else:
                A[i]=A[i-1]
    ans = INF
    for i in range(N):
        tmp = 0
        if i>0:
            tmp += i - A[i-1]
        if i<N-1:
            tmp += A[N-1]-A[i]
        ans = min(ans,tmp)
    print(ans)






if __name__ == '__main__':
    main()


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

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

    int ans = 1001;
    for(int i=0; i<n; i++){
        int c, t;
        cin >> c >> t;
        if(t <= T){
            ans = min(ans, c);
        }
    }

    if(ans == 1001) cout << "TLE" <<endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N,M,K=map(int,input().split())
MOD=998244353

MAX = 10**6
def COMinit():
    """
    逆元テーブルをつくる前処理
    計算量はO(n)
    1 <= k <= n <= 1e7程度
    p: 素数
    """
    fac = [0]*MAX
    finv = [0]*MAX
    inv = [0]*MAX

    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[0], inv[1] = 1, 1
    for i in range(2, MAX):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD
    return fac, finv, inv



def comb(n, k):
    """
    nCk mod MODを求める.
    この部分はO(1)
    """
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return int(fac[n] * (finv[k] * finv[n-k] % MOD) % MOD)


fac, finv, inv = COMinit()
ans = 0
for L in range(N-K, N+1):
    tmp = M*pow(M-1, L-1, MOD)%MOD
    tmp *= comb(N-1, L-1)
    ans += tmp % MOD
    ans %= MOD
print(ans%MOD)

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

int main(){
    int a, b, m;
    cin >> a >> b >> m;
    vector<int> fridge(a);
    vector<int> micro(b);
    int fmin = 1e5;
    int mmin = 1e5;
    rep(i,a){
        cin >> fridge[i];
        fmin = min(fmin, fridge[i]);
    }
    rep(i,b){
        cin >> micro[i];
        mmin = min(mmin, micro[i]);
    }
    int ans = mmin + fmin;
    vector<int> x(a);
    vector<int> y(b);
    vector<int> c(m);
    int sum;
    rep(i,m){
        int x, y, c;
        cin >> x >> y >> c;
        --x; --y;
        sum = fridge[x] + micro[y] - c;
        ans = min(sum, ans);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 2176
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        long X = long.Parse(ReadLine());
        for (long i = -1000; i < 1000; i++)
        {
            for (long j = -1000; j < 1000; j++)
            {
                if (Pow(i, 5) - Pow(j, 5) == X)
                {
                    WriteLine($"{i} {j}");
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 27660
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
using namespace std;

int hard[] = {
    2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199
};

long per(long a,long b,long c,int divide){
    if(a % divide == 0 && b %divide == 0 && c % divide == 0){
        return divide;
    }else{
        return 1;
    }
}

long gcd(long a,long b,long c){
    int result = 1;
    if(a == 1){return 1;}
    long work[] = {a,b,c};
    for(int h = 0; h < 9;h++){
        long perR = 1;
        for(int i = 0;i < sizeof(hard) / sizeof(hard[0]);i++){
            if(work[2] < hard[i])break;
            perR *= per(work[0],work[1],work[2],hard[i]);   
        }
        result *= perR;
        if(perR < 2){
            //cout << perR << ':' << a << b << c << endl;
            break;
        }
        int zeroChk = 0;
        for(int i = 0;i < 3;i++){
            work[i] /= perR;
            if(work[i] < 1){
                zeroChk++;
            }
            
        }
        if(zeroChk > 0){
            //cout << work[0] << b << c << ":" << perR << endl;
            break;
        }
        
    }
    return result;
}

int main() {
    int k;
    long long sum;
    cin >> k;
    sum = (k * (k + 1)) / 2;
    for(int i = 1;i <= k;i++){//2つずつペア
        for(int j = (i + 1); j <= k;j++){
            sum += (gcd(i,j,j) * 6);
        }
    }
    for(int i = 1;i <= k;i++){
        for(int j = (i + 1);j <= k;j++){
            for(int l = (j+1);l <= k;l++){
                sum += (gcd(i,j,l) * 6);
            }
        }
    }
    cout << sum << endl;
//--------------------
    return 0;
}

Measured memory_bytes: 3596
#include<iostream> 
#include<string>
#include<bits/stdc++.h>
#define foreach(c,itr) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++)
using namespace std;
int main(){	
	int n;
	cin>>n;
	map<string,long long> mp;
	for(int i=0;i<n;i++){
		char buf[10];
		scanf("%s",buf);
		sort(buf,buf+10);
		mp[buf]++;
	}
	long long ans=0;
	foreach(mp,itr){
		if(itr->second!=0){
			ans+=itr->second*(itr->second-1)/2;
		}
	}
	cout<<ans;
    return 0;
} 

Measured memory_bytes: 11136
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

const int mod=1e9+7;

//Union-Find
const int MAX_N=1000000;
int par[MAX_N];//親
int Rank[MAX_N];//木の深さ
int size[MAX_N];//子と自身の合計数（自身が根の時には集合のサイズを表す）


void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        Rank[i]=0;
        size[i]=1;
    }
}

//木の根を求める
int find(int x){
    if(par[x]==x){
        return x;
    }else{
        return par[x]=find(par[x]);
    }
}

//xとyの属する集合を併合
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)    return ;
    if(Rank[x]<Rank[y]){
        par[x]=y;
        size[y]+=size[x];
    }else{
        par[y]=x;
        size[x]+=size[y];
        if(Rank[x]==Rank[y])    Rank[x]++;
    }
}

bool same(int x,int y){
    return find(x)==find(y);
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> x(m),y(m),z(m);
    for(int i=0;i<m;i++){
        cin >> x[i] >> y[i] >> z[i];
        x[i]--;
        y[i]--;
    }
    init(n);
    for(int i=0;i<m;i++){
        unite(x[i],y[i]);
    }
    set<int> st;
    for(int i=0;i<n;i++){
        if(st.count(find(i))==0){
            st.insert(find(i));
        }
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 14592
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var a = int.Parse(Console.ReadLine());
        var s = Console.ReadLine();

        if (a >= 3200)
        {
            Console.WriteLine(s);
        }
        else
        {
            Console.WriteLine("red");
        }
    }
}

Measured memory_bytes: 11092
base = input().split()
k = int(base[0])
n = int(base[1])
house = input().split()
lenlist = []
a = int(house[0])
b = k-int(house[-1])
one = a+b
lenlist.append(one)
for i in range(n-1):
    lenlist.append(int(house[i+1])-int(house[i]))
print(k-max(lenlist))

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

using namespace std;
typedef pair<int,int> pii;
typedef long long int lli;

const int MAXN = 110;

int n, m;

int v[MAXN];

int main()
{
	scanf("%d %d",&n,&m);

	int sum = 0;

	for(int i = 1 ; i <= n ; i++)
	{
		scanf("%d",&v[i]);
		sum += v[i];
	}

	int ans = 0;

	for(int i = 1 ; i <= n ; i++)
		if( sum <= v[i]*4*m ) ans++;

	if( ans >= m ) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int x,y,i;
	char op;
	for(i=0;;i++){
	scanf("%d %c %d",&x,&op,&y);
	if ( op == '+')
		printf("%d\n",x+y);
	else if (op == '-')
		printf("%d\n",x-y);
	else if (op =='*')
		printf("%d\n",x*y);
	else if(op =='/')
		printf("%d\n",x/y);
	else
		break;
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
 
#define IOS 		ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sd(n)       scanf("%d", &n)
#define sdd(a,b)    scanf("%d %d", &a, &b)
#define sddd(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sld(n)      scanf("%lld", &n)
#define slld(a,b)   scanf("%lld %lld", &a, &b)
#define sllld(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define slu(n)      scanf("%llu", &n)
#define sllu(a,b)   scanf("%llu %llu", &a, &b)
#define slllu(a,b,c) scanf("%llu %llu %llu", &a, &b, &c)
#define ss(a)		scanf("%s", a)
#define inStrAftInSome cin.ignore(numeric_limits<streamsize>::max(),'\n')		//input string(with whitespace) after input something(char, int, bool, str)
#define all(a) 		a.begin(),a.end()
#define unq(x)      x.erase(unique(all(x)), x.end()
#define mp 			make_pair
#define sz(av) 		int((av).size())					//return size of vec
#define CLR(arr)    memset(arr, 0, sizeof(arr))			//assign 0 to whole arr
#define SET(vec)    memset(arr, -1, sizeof(arr))		//assign -1 to whole arr
#define CLRV(vec)	fill(vec.begin(), vec.end(), 0)		//assign 0 to whole vec
#define SETV(vec,n,a) vec.assign(n, a)	
#define vtd(rowsize,colsize,type,name) 		vector < vector <type> > name(rowsize,vector <type> (colsize)); 	//assign to first n elements value a in vec
#define SETB(a)		memset(a, true, sizeof(a))			//boolean array initialize by true value
#define CLRB(a)		memset(a, false, sizeof(a))			//boolean array initialize by false value
#define vintitr 	vector<int>::iterator
#define vlnlnitr 	vector<long long>::iterator
#define sintitr 	set<int>::iterator
#define slnlnitr 	set<long long>::iterator
#define aa			first
#define bb			second
#define mod 		1000000007
#define PI 			acos(-1.00)
#define psb 		push_back
#define ppb			pop_back
#define ppb			pop_back
#define psf			push_front
#define ppf			pop_front
#define in 			inset
#define rep(i, n) 	for(int i=0; i<n; i++)
#define repi(i,j,n) for(int i=j; i<n; i++)
#define rof(i, n)   for(int i=n-1; i>=0; i--)
#define min3(a,b,c) (min((c),min((a),(b))))
#define max3(a,b,c) (max((a),max((b),(c))))
#define __lcm(a, b)	a*b / __gcd(a, b)
#define __builtin_zerocount(a)	8*sizeof(a)-__builtin_popcount(a)-__builtin_clz(a)-__builtin_ctz(a)
#define D(t)        cerr << #t " = " <<t  << '\n'
#define DBG         cerr << "Hi!" << '\n'
 
 
typedef long long	 		ll;
typedef unsigned long long	llu;
typedef long double			ld;
typedef pair<int, int> 		pii;

int main()
{
//	freopen("t.in","r",stdin);
//	freopen("t.out","w",stdout);
	IOS;
	int n;
	cin >> n;
	int a[n], b[n], c[n];
	rep(i, n)
		cin >> a[i];

	rep(i, n)
		cin >> b[i];

	rep(i, n-1)
		cin >> c[i];

	int ans = 0;
	rep(i, n){
		ans += b[a[i]-1];
		if(i != 0){
			if(a[i] == a[i-1]+1){
				ans += c[a[i]-2];
			}

		}
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for1(i, a, b) for (int i = (int)a; i < (int)(b); ++i)
#define rfor1(i, a, b) for (int i=(int)b-1;i>=(int)a;i--)
#define for2(i, a, b) for (int i = (int)a; i <= (int)(b); ++i)
#define for3(i, a, b) for (int i = (int)a; i < (int)(b); i=i+2)
#define for4(i, a, b) for (int i = (int)a; i <= (int)(b); i=i+2)
#define tc(t) int t; cin>>t; while(t--)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
//==================================================================//

int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
//=================================================================//

	int n;
	cin >> n;
	string s , ss;
	cin >> s >> ss;
	string sss = "";
	for1(i, 0, n) {
		// for1(j, 0, n) {
		sss += s[i];
		sss += ss[i];
		//}
	}

	cout << sss << endl;
}








Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	//
 int N, a, b, c, d;
  cin >> N;
  a = N / 1000;
  b = N  % 1000 / 100;
  c = N % 100 / 10;
  d = N % 10;
  if(b==c){
    if(a==b||c==d)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
   else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef long double ld;
typedef std::vector<long double> vld;
typedef std::vector<std::vector<long double>> vvld;
using namespace std;
void yesno(bool state);

void Main(){
    ll N;
    cin >> N;
    vll A(N);
    rep(i,N) cin >> A[i];
    ll max = A[0];
    ll ans = 0;
    rep(i,N-1){
        if(max < A[i+1]){
            max = A[i+1];
        }
        else
        {
            ans += max - A[i+1];
        }
    }
    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    Main();
    return 0;
}

void yesno(bool state){
    if(state)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
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; }

int main(){
    string unr="UNRESTORABLE";
    string s,t;
    vector<string> ans;
    cin>>s>>t;
    for(int i=0;i<s.size();i++){
        bool flag=false;
        string tmp=s;
        if(s[i]=='?'||s[i]==t[0]){
            for(int j=0;j<t.size()&&i+j<s.size();j++){
                if(s[i+j]=='?'||s[i+j]==t[j]){
                    tmp[i+j]=t[j];
                    if(j==t.size()-1) flag=true;
                }
                else{
                    flag=false;break;
                }
            }
        }
        else{continue;}
        if(flag){
            ans.push_back(tmp);
        }
    }
    if(ans.size()==0){cout<<unr<<endl;return 0;}
    sort(ALL(ans));
    rep(i,ans[0].size()){
        if(ans[0][i]=='?'){
            cout<<'a';
        }
        else{
            cout<<ans[0][i];
        }
    }
    cout<<endl;
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  cout << 6 - a - b << endl;
  return 0;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/abc106/tasks/abc106_b
//B - 105
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
int main() {
    ll N; cin>>N;
    ll ans=0;
    FOR(i,1,N+1){
        if(i%2==0)continue;
        auto vec = divisor(i);
        if(vec.size()==8) ++ans;
    }    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys

def insertion_sort(a, n, g):
    count = 0
    for i in range(g, n):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j+g] = a[j]
            j = j - g
            count += 1
        a[j+g] = v
    return count

def shell_sort(a, n):
    count = 0
    G = list([int((2.25**i-1)/1.25) for i in range(17, 0, -1)])
    G = [x for x in G if x <= n]
    m = len(G)
    for g in G:
        count += insertion_sort(a, n, g)
    return m, G, count, a

n = int(input())
a = list(map(int, sys.stdin))

m, G, count, a = shell_sort(a, n)
print(len(G))
print(*G)
print(count)
print("\n".join(map(str, a)))


Measured memory_bytes: 126044
#include <iostream>

using namespace std;

int main(){
  int x,y; cin>>x>>y;
  if((x==2)&&(y==2))cout<<"Yes"<<endl;
  else if((x==4||x==6||x==9||x==11)&&(y==4||y==6||y==9||y==11)) cout<<"Yes"<<endl;
  else if((x==1||x==3||x==5||x==7||x==8||x==10||x==12)&&(y==1||y==3||y==5||y==7||y==8||y==10||y==12)) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

struct edge {
   ll to, cost;
};

const ll INF = 1e18;
ll N, M;
vec<edge> G[3000];

int main() {
   cin >> N >> M;
   for (int i = 0; i < M; i++) {
      int a, b, c;
      cin >> a >> b >> c;
      a--, b--;
      G[a].push_back(edge{b, c});
   }

   vec<ll> dist(N, -INF);
   dist[0] = 0;
   for (int k = 0; k < 4*N; k++) {
      for (int i = 0; i < N; i++) {
         if (dist[i] == -INF) continue;
         for (edge e : G[i]) {
            dist[e.to] = max(dist[e.to], dist[i] + e.cost);
         }
      }
   }
   ll ans1 = dist[N-1];

   for (int k = 0; k < 4*N; k++) {
      for (int i = 0; i < N; i++) {
         if (dist[i] == -INF) continue;
         for (edge e : G[i]) {
            dist[e.to] = max(dist[e.to], dist[i] + e.cost);
         }
      }
   }
   ll ans2 = dist[N-1];

   if (ans1 != ans2) {
      puts("inf");
   } else {
      cout << ans1 << endl;
   }

   return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
ll inf = 1e18;


ll N, M;
ll dp[20010][256];
int main() {
	while (cin >> N >> M && N > 0) {
		ll C[20];
		ll x[20010];
		REP(i,0,20010){
			REP(j,0,256){
				dp[i][j] = inf;
			}
		}
		dp[0][128] = 0;
		REP(i,0,M) cin >> C[i];
		REP(j,0,N) cin >> x[j];
		REP(i,0,N){
			REP(y,0,256){
				REP(k,0,M){
					ll next_y = max(min(y + C[k], 255LL), 0LL);
					dp[i+1][next_y] = min(dp[i+1][next_y], dp[i][y] + (x[i] - next_y)*(x[i] - next_y));
				}
			}
		}
		ll ans = inf;
		REP(y,0,256){
			ans = min(ans, dp[N][y]);
		}
		p(ans);
	}

	return 0;
}


Measured memory_bytes: 43252
#include <iostream>
using namespace std;
int main(){
	long p,q;
	while(cin>>p>>q){
		int j,i=0,c=0,pr[80];
		pr[0]=p;
		while(p*=10,c++==i&&p){
			cout<<(char)(p/q+'0');
			for(i=0;i<c;i++)
				if(p%q==pr[i]){
					cout << endl;
					for(j=0;j<c;j++)cout<<(j<i?' ':'^');
					break;
				}
			pr[c]=p%=q;
		}
		if(c==1)cout<<'0';
		cout<<endl;
	}
}

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

int main(void) {
  int K, X, l, r;
  cin >> K >> X;
  
  l = X-K+1;
  r = X+K-1;
  
  for(int i=l; i<=r; i++){
    cout << i << " ";
  }
  
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
#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 inf (1<<29)
#define EPS (1e-10)
#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
#define equals(a,b) (fabs((a)-(b)) < EPS)

using namespace std;


double L;

void split(string s,vector<double> &vec)
{
  stringstream ss;
  ss << s;
  for(int i=0;!(ss >> s).fail();i++)
    {
      if(i == 0)L = (atoi)(s.c_str());
      else
	{
	  vec.push_back((atoi)(s.c_str()));
	}
    }

}

int n;
double dp[(1<<12)][12];

double getDistance(double r1,double r2)
{
  return sqrt(pow(r1+r2,2)-pow(r1-r2,2));
}

int main()
{

  string line;
  while(getline(cin,line))
    {
      vector<double> vec;
      split(line,vec);
      n = vec.size();
      rep(i,(1<<n))rep(j,n)dp[i][j] = inf;

      rep(i,(1<<n))//???????????§????????????????????¶???
	{
	  rep(j,n)//?¬??????????????????????????????????????????????
	    {
	      rep(k,n)//???????????????????????????????????????
		{
		  if(i == 0)//?????????????????????????????????????????????????????????????????????
		    {
		      dp[i|(1<<j)][j] = min(dp[i|(1<<j)][j],vec[j]);
		      continue;
		    }

		  if(dp[i][k] == inf)continue;
		  int next = i|(1<<j);

		  if(__builtin_popcount(next) == n)//????????????????????§?????¨???????????¢+??????????????????????????????
		    {
		      dp[next][j] = min(dp[next][j],
					dp[i][k]+getDistance(vec[k],vec[j])+vec[j]);
		    }
		  else
		    {
		      dp[next][j] = min(dp[next][j],
					dp[i][k]+getDistance(vec[k],vec[j]));
		    }
		}
	    }
	}

      double ans = inf;
      rep(i,n)ans = min(ans,dp[(1<<n)-1][i]);
      if(equals(ans,L) || (!equals(ans,L) && ans < L))cout << "OK" << endl;
      else        cout << "NA" << endl;
    }
  return 0;
}

Measured memory_bytes: 3476
ss = gets.split(' ')
count = 0
nums = [ss[0].to_i,ss[1].to_i]
(nums[1].to_i - nums[0].to_i+1).times do |i|
  (count += 1) if ((i+nums[0]).to_s == (i+nums[0]).to_s.reverse) 
  
end
print count

Measured memory_bytes: 1788
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int main() {
	int n; qr(n);
	printf("%.7lf\n",n*6.28318530717958623200); 
	return 0;
}



Measured memory_bytes: 3748
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
r=0
k=-9
for i,j in enumerate(a):
    r+=b[j-1]
    if j-1==k+1:
        r+=c[j-2]
    k=j-1
print(r)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int N;
    cin >> N;
    vector<int> a;
    REP(i, N){
        int x;
        cin >> x;
        a.pb(x);
    }
    int ct = 0;
    int ans[100][2];
    
    int MAbs = 0;
    REP(i, N){
        if(abs(a[MAbs]) < abs(a[i])) MAbs = i;
    }
    REP(i, N){
        ans[ct][0] = MAbs+1;
        ans[ct][1] = i+1;
        a[i] += a[MAbs];
        ct++;
    }
    if(a[MAbs] > 0){
        REP(i, N-1){
            int j = i+1;
            ans[ct][0] = i+1;
            ans[ct][1] = j+1;
            a[j] += a[i];
            ct++;
        }
    }else{
        for(int i=N-1; i>=1; i--){
            int j = i-1;
            ans[ct][0] = i+1;
            ans[ct][1] = j+1;
            a[j] += a[i];
            ct++;
        }
    }

    // REP(i, N){
    //     cout << a[i] << " ";
    // }
    // cout << "\n";

    cout << ct << "\n";
    REP(i, ct){
        cout << ans[i][0] << " " << ans[i][1] << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long 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;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main(){
  Sieve sieve(1e6);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  map<int,int> mp;
  rep(i,n) {
    auto f = sieve.factor(a[i]);
    for (auto p : f) {
      mp[p.first] = max(mp[p.first], p.second);
    }
  }

  mint lcm = 1;
  for (auto p : mp) {
    rep(i,p.second) {
      lcm *= p.first;
    }
  }

  mint ans;
  rep(i,n) {
    mint b = lcm/a[i];
    ans += b;
  }
  cout << ans.x << endl;
  return 0;
}


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

using namespace std;

void fastio() {
	cin.tie(nullptr);
	cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9+7;
const LL INF = LLONG_MAX;
const LL N = 1e6+1;

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

	vector<char> a(n);

	LL cw = 0;

	for (auto &e :a ) {
		cin >> e;
		if (e == 'W') {
			cw++;
		}
	}

	LL ans = cw;

	if (cw == n || cw == 0) {
		cout << 0 << "\n";
		return 0;
	}

	LL p1 = n-1, p2 = 0;

	for (LL i = 0; i < n; ++i) {
		if (a[i] == 'W') {
			p1 = i;
			break;
		}
	}

	for (LL i = n-1; i >= 0; --i) {
		if (a[i] == 'R') {
			p2 = i;
			break;
		}
	}

	ans = 0;
	for (LL i = p2; i >= 0; --i) {
		if (a[i] == 'W') {
			ans++;
		}
	}

	LL cnt = 0;
	while (p1 < p2 && p1 < n && p2 >= 0) {
		if (a[p1] == 'W' && a[p2] == 'R') {
			//...
		}
		else {
			break;
		}
		swap(a[p1], a[p2]);
		cnt++;
		
		p1++;
		p2--;

		while (p1 < n && a[p1] != 'W') {
			p1++;
		}
		while (p2 >= 0 && a[p2] != 'R') {
			p2--;
		}
	}


	cout << min(ans, cnt) << "\n";



}

Measured memory_bytes: 3656
//
//  respect the past, embrace the future
//

#include  <bits/stdc++.h>
#include  <algorithm>
#include  <iostream>
#include  <climits>
#include  <cstdlib>
#include  <cstring>
#include  <cmath>
#include  <cstdio>
#include  <unordered_map>
#include  <map>
#include  <set>
#include  <stack>
#include  <string>
#include  <vector>
#include  <queue>

using namespace :: std;

using vpll = vector <pair <long long, long long> >;
using pll = pair <long long, long long>;
using vll = vector <long long>;
using ll = long long;

#define W (long long) (5e3 + 7)
#define N (long long) (2e6 + 7)
#define M (long long) (1e9 + 7)
#define INF (long long) (2e18)
#define F first
#define S second

inline void fastInputOutput () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
}

inline void ReadWriteFromFile () {
  freopen("../in.txt", "r", stdin);
  freopen("../out.txt", "w", stdout);
}

ll n, m, l, r, i, cur;
char str[N];
vll v;

int32_t main (int argc, char *argv[]) {
  fastInputOutput();
  // ReadWriteFromFile();

  cin >> n >> m >> str + 1;
  n++;
  for (int i = 1; i <= n / 2; i++)
    swap (str[i], str[n - i + 1]);
  if (str[1] == '1') {
    cout << -1;
    return 0;
  }
  l = r = i = 1;
  while (i < n) {
    cur = 0;
    while (cur < m && i < n) {
      i++, cur++;
      if(str[i] != '1')
        r = i;
      // cout << cur << ' ';
    }
    // cout << l << " " << r << '\n';
    v.emplace_back (r - l);
    if (l == r) {
      cout << -1;
      return 0;
    }
    i = l = r;
  }
  reverse (v.begin(), v.end());
  for (auto i : v)
    cout << i << ' ';
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
using pll=pair<long long,long long>;
const long double pi=atan2l(0,-1);

int N;

pair<long long,long long> operator+(pair<long long,long long> &a,pair<long long,long long> &b) {
  return make_pair(a.first+b.first,a.second+b.second);
}

int main() {
  cin >> N;
  vector<pll> A(N);
  for (int i=0;i<N;i++) {
    cin >> A[i].first >> A[i].second;
  }
  vector<pair<long double,int>> arg(2*N);
  for (int i=0;i<N;i++) {
    arg[i]=make_pair(atan2(A[i].second,A[i].first),i);
    arg[i+N]=make_pair(atan2(A[i].second,A[i].first)+2*pi,i);
  }
  sort(arg.begin(),arg.end());
  long double ans=0;
  for (int i=0;i<N;i++) {
    int j=i;pair<long long,long long> X=make_pair(A[arg[i].second].first,A[arg[i].second].second);
    while (((X.first+A[arg[j+1].second].first)*A[arg[j+1].second].first+(X.second+A[arg[j+1].second].second)*A[arg[j+1].second].second>=
            -1*X.first*A[arg[j+1].second].first-X.second*A[arg[j+1].second].second && arg[j+1].first-atan2(X.second,X.first)<pi)
           || X.first*A[arg[j+1].second].first+X.second*A[arg[j+1].second].second>=0 && j+1<i+N) {
      j++;
      X=X+A[arg[j].second];
    }
    long long x=0LL,y=0LL;
    for (int k=i;k<=j;k++) {
      x+=A[arg[k].second].first;
      y+=A[arg[k].second].second;
    }
    long double d=sqrt(x*x+y*y);
    ans=max(ans,d);
  }
  cout << setprecision(20) << ans << endl;
}

Measured memory_bytes: 4144
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::prev(iter, n) n 個分デクリメントしたイテレータ
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define pll pair<ll, ll>
#define F first
#define S second
const ll INF = 1LL<<60;  // 10^18（const int inf   = 1<<29;）

template<class T> inline bool chmin(T& a, T b) {
    // chmin: change minimum
    // a より b の方が小さかったら，a の値を b の値に置き換える．
    // 書き換えた場合，true を返す
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    // input(sunippets: inpv, inpn, inps)
    ll N, K;
    cin >> N >> K;
    vector<ll> vec(N);
    REP(i, N) cin >> vec[i];
    
    // calculation
    // dp table init
    vector<ll> dp(N, INF);
    dp[0] = 0;
    dp[1] = abs(vec[0] - vec[1]);
    
    // calc
    for (ll i = 2; i < N; ++i) {
        for (ll j = 1; j <= min(i, K); ++j) {
            chmin(dp[i], dp[i-j] + abs(vec[i] - vec[i-j]));
        }
    }
    
    cout << dp[N-1] << "\n";
    
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define lim1 10000000
#define lim2 22500000
using namespace std;
typedef long long LL;
int f[lim2+10];
const LL mod = 1e9+7;
void init() {
    int l = 1, r = 10;
    for (int k = 1; k <= 7; ++k) {
        for (int i = l; i < r; ++i) f[i] = k;
        l = r; r *= 10;
    }
    for (int i = lim1; i <= lim2; ++i) f[i] = 8;
}
LL poww(LL a, LL b) {
    LL ret = 1;
    while (b) {
        if (b & 1) (ret *= a) %= mod;
        (a *= a) %= mod;
        b >>= 1;
    }
    return ret;
}
LL count1(LL x) {
    int l = 1, r = 1, ret = 0; LL sum = 0;
    while (true) {
        while (r <= lim2 && sum < x) sum += f[r++];
        if (sum < x) break;
        if (sum == x) (ret += 1) %= mod;
        sum -= f[l++];
        if (l == lim1) break;
    }
    return ret;
}
LL count2(LL x) {
    LL upp = x/8,
        ret = upp;
    for (int t = 1; t <= upp; ++t) {
        if (x % t == 0) {
            int len = x / t;
            LL sub = 9 * poww(10, len-1) % mod;
            (sub += mod - t) %= mod;
            (ret += sub) %= mod;
        }
    }
    return ret;
}
int main() {
    init();
    LL n;
    scanf("%lld", &n);
    LL ans1 = count1(n), ans2 = count2(n);
    printf("%lld\n", (ans1+ans2)%mod);
    return 0;
}

Measured memory_bytes: 88192
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    long[] enter = new long[N + 1];
    List<int[]>[] exit = new List[N + 2];
    for (int i = 0; i <= N + 1; i++) exit[i] = new ArrayList<>();

    for (int i = 0; i < M; i++) {
      int left = scanner.nextInt();
      int right = scanner.nextInt();
      int a = scanner.nextInt();
      enter[left] += a;
      exit[right + 1].add(new int[]{left, right, a});
    }

    SegmentTree st = new SegmentTree(N);
    long max = 0;
    for (int i = 1; i <= N; i++) {
      st.add(0, i, enter[i]);
      for (int[] e : exit[i]) st.add(0, e[0], -e[2]);
      long dp = st.query(0, i);
      st.add(i, i + 1, dp);
      max = Math.max(max, dp);
    }
    System.out.println(max);
  }

  private static class SegmentTree {
    private static final long INF = -1_000_000_000_000_000L;
    private final int n;
    long[] max;
    long[] add;
    public SegmentTree(int n) {
      int tmpn = 1;
      while (tmpn < n) tmpn <<= 1;
      this.n = tmpn;
      max = new long[this.n * 2 - 1];
      add = new long[this.n * 2 - 1];
    }

    public long query(int a, int b) {
      return query(a, b, 0, 0, n);
    }

    private long query(int a, int b, int k, int l, int r) {
      if (b <= l || a >= r) return INF;
      if (a <= l && r <= b) return max[k];
      long lv = query(a, b, k * 2 + 1, l, (l + r) / 2);
      long rv = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return Math.max(lv, rv) + add[k];
    }

    public void add(int a, int b, long v) {
      add(a, b, v, 0, 0, n);
    }

    private void add(int a, int b, long v, int k, int l, int r) {
      if (a <= l && r <= b) {
        add[k] += v;
        max[k] += v;
        return;
      }
      if (b <= l || a >= r) return;
      add(a, b, v, k * 2 + 1, l, (l + r) / 2);
      add(a, b, v, k * 2 + 2, (l + r) / 2, r);
      max[k] = Math.max(max[k * 2 + 1], max[k * 2 + 2]) + add[k];
    }
  }
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    cin>>n;
    string s;
    cin>>s;
    int cur = 0;
    string ret;
    for(int i=0;i<n;++i){
        if(s[i] == '(')cur--;
        else {
            if(cur >= 0)ret="(" + ret;
            else cur++;
        }
            ret+=s[i];
    }
    if(cur <0)while(cur <0 ) ret += ")",cur++;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstdio>
using namespace std;
const int MAX = 10000;
const int INF = (1 << 31) - 1;
const int WHITE = 0,GRAY = 1,BLACK = 2;

int n;
vector<pair<int,int> > adj[MAX];

void dijkstra(){
    priority_queue<pair<int,int> > PQ;
    int color[MAX];
    int d[MAX];
    for(int i = 0;i < n;++i){
        d[i] = INF;
        color[i] = WHITE;
    }
    d[0] = 0;
    PQ.push(make_pair(0,0));
    color[0] = GRAY;
    while(!PQ.empty()){
        pair<int,int> f = PQ.top();
        PQ.pop();
        int u = f.second;
        color[u] = BLACK;
        if(d[u] < f.first * (-1)) continue;
        for(int j = 0;j < adj[u].size();j++){
            int v = adj[u][j].first;
            if(color[v] == BLACK) continue;
            if(d[v] > d[u] + adj[u][j].second){
                d[v] = d[u] + adj[u][j].second;
                PQ.push(make_pair(d[v]*(-1),v));
                color[v] = GRAY;
            }
        }
    }
    for(int i =0; i <n;++i) printf("%d %d\n",i,d[i] == INF ? -1:d[i]);
}

int main(){
    int k,u,v,c;
    scanf("%d",&n);
    for(int i = 0;i < n;++i){
        scanf("%d %d",&u,&k);
        for(int j = 0;j < k;++j){
            scanf("%d %d",&v,&c);
            adj[u].push_back(make_pair(v,c));
        }
    }
    dijkstra();
}



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

void erase(bool(&field)[5000][5], int line){

	for (int i = line; i < 4999; i++){
		for (int j = 0; j < 5; j++){
			field[i][j] = field[i + 1][j];
		}
	}
}

int main(){

	int n;
	while (std::cin >> n, n){

		bool field[5000][5];

		for (int i = 0; i < 5000; i++){
			for (int j = 0; j < 5; j++){
				field[i][j] = 0;
			}
		}

		for (int i = 0; i < n; i++){
			int d, p, q;
			std::cin >> d >> p >> q;

			q--;

			int height = 0;

			for (int j = 4999; j >= 0; j--){
				if (d == 1){
					bool flg = true;
					for (int k = 0; k < p; k++){
						if (field[j][q + k]) flg = false;
					}
					if (!flg){
						height = j + 1;
						break;
					}
				}
				else{
					if (field[j][q]){
						height = j + 1;
						break;
					}
				}
			}


			for (int j = 0; j < p; j++){
				if (d == 1)field[height][q + j] = true;
				else field[height + j][q] = true;
			}

			for (int i = 0; i < 5000; i++){
				bool flg = true;
				for (int j = 0; j < 5; j++){
					if (!field[i][j]){
						flg = false;
						break;
					}
				}
				if (flg){
					erase(field, i);
					i--;
				}

			}
		}

		int cnt = 0;
		for (int i = 0; i < 5000; i++){
			for (int j = 0; j < 5; j++){
				if (field[i][j] == 1)cnt++;
			}
		}

		std::cout << cnt << std::endl;
	}

	return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    string S,T; cin >> S >> T;
    int ans = 0;
    REP(i,3) if(S[i]==T[i]) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long H = sc.nextLong();
    long W = sc.nextLong();
    long answer = 0;
    if(W==1){
      System.out.println(1);
      return;
    }
    if(H==1){
      System.out.println(1);
      return;
    }
    if(H*W%2==0){
      answer = (H*W)/2;
    }else{
      answer = ((H*W)/2)+1;
    }
    System.out.println(answer);
  }
  

  
}


Measured memory_bytes: 23764
a=input().split()
(n,m)=map(int,a)
b=input().split()
b1=list(map(int,b))
b1=sorted(b1)
for i in range(m):
    b1[len(b)-1-i]=0
    if i==len(b1)-1:
        break

print(sum(b1))

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using Pint = pair<int, int>;
const ll mod = 1e9+7;

int main(int argc, char const* argv[])
{
  int n;
  cin>>n;

  int min_ = (int)2e5+1;
  int ans = 0;
  rep(i,n) {
    int p;
    cin>>p;
    if(min_>=p) {
      min_ = p;
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    vector<int> v(3);
    REP(i,3) cin >> v[i];
    sort(ALL(v));
    if((v[0]==v[1] && v[1]!=v[2]) || (v[0]!=v[1] && v[1]==v[2])) cout << "Yes";
    else cout << "No";

    return 0;
}

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

int main() {
	// your code goes here
	int n; cin>>n; string s; cin>>s;
	int count=1;
	for(int i=1;i<n;i++){
		if(s[i]==s[i-1]) continue;
		count++;
	}
	cout<<count;
	return 0;
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*-
str = raw_input()
for _ in xrange(input()):
 ops = raw_input().split()
 na = int(ops[1])
 nb = int(ops[2]) + 1
 op = ops[0]
 if op[0]=="p": print str[na:nb]
 elif op[2]=="v":
  t = str[na:nb]
  str = str[:na] + t[::-1] + str[nb:]
 else: str = str[:na] + ops[3] + str[nb:]

Measured memory_bytes: 6456
# -*-coding:utf-8

import random

class Dice:

    def __init__(self, diceList):
        self.d1, self.d2, self.d3, self.d4, self.d5, self.d6 = diceList

    def diceRoll(self, r):
        if(r == 'N'):
            self.d1, self.d2, self.d5, self.d6 = self.d2, self.d6, self.d1, self.d5

        elif(r == 'E'):
            self.d1, self.d3, self.d4, self.d6 = self.d4, self.d1, self.d6, self.d3

        elif(r == 'W'):
            self.d1, self.d3, self.d4, self.d6 = self.d3, self.d6, self.d1, self.d4

        elif(r == 'S'):
            self.d1, self.d2, self.d5, self.d6 = self.d5, self.d1, self.d6, self.d2


def main():

    orderList = ['N', 'E', 'W', 'S']
    inputDiceList = list(map(int, input().split()))
    inputNum = int(input())
    d = Dice(inputDiceList)

    for i in range(inputNum):
        x, y = map(int, input().split())
        while True:
            if(d.d1 == x and d.d2 == y):
                print(d.d3)
                break
            else:
                r = random.randint(0, 3)
                d.diceRoll(orderList[r])

if __name__ == '__main__':
    main()

Measured memory_bytes: 11860
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n = n // 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n = n // f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

from collections import Counter

N = int(input())
c = Counter(prime_factorize(N))

ans = 0

v = list(c.values())
l = len(v)
for i in range(l):
    for j in range(40):
        if j*(j+1)//2 <= v[i] and v[i] < (j+1)*(j+2)//2:
            ans = ans + j

print(ans)


Measured memory_bytes: 9404
#include <stdio.h>

main(){
  char a;
  int data[100];
  int sum, i, p=0, temp, count;

  while(1){
    for(i=0;i<100;i++){
      scanf("%d",&data[i]);
      if(data[0]==0){
	p=1;
	break;
      }
      scanf("%c", &a);
      if(a=='\n') break;
    }
    if(p==1) break;

    data[i+1]=-1;

    sum=0;
    count=0;
    for(i=0;i<100;i++){
      if(data[i]==-1) break;
      if(data[i]>=10) data[i]=10;
      if(data[i]==1) count++;
      sum+=data[i];
    }

    for(i=0;i<count;i++){
      if(sum+10<=21) sum+=10;
    }

    if(sum>21) sum=0;

    printf("%d\n", sum);
  }
  return 0;
}

Measured memory_bytes: 0
import bisect

N,M=map(int,input().split())
p=[[0] for _ in range(M)]
y=[[0] for _ in range(M)]
d={}
for i in range(1,N+1):d[i]=[]
for i in range(M):
    p[i],y[i]=map(int,input().split())
    d[p[i]] +=[y[i]]

for i in d:
    d[i].sort()

for i,j in zip(p,y):
    print('{:06}{:06}'.format(i,bisect.bisect_right(d[i], j)))
    

Measured memory_bytes: 41312
n,x,y=map(int,input().split())
num=[0]*(n-1)
for i in range(n-1):
    for j in range(i+1,n):
        d=int(min(j-i,abs(x-j-1)+1+abs(y-1-i),abs(y-1-j)+1+abs(x-1-i)))
        num[d-1]+=1
for i in range(n-1):
    print(num[i])

Measured memory_bytes: 9224