akhauriyash/Code-Regression huggingface dataset:
import numpy as np

def check_surrounding(array, h, w):
    count = 0
    if array[h, w] == "#":
        count+=1
    if array[h, w+1] == "#":
        count+=1
    if array[h, w+2] == "#":
        count+=1
    if array[h+1, w] == "#":
        count+=1
    if array[h+1, w+2] == "#":
        count+=1
    if array[h+2, w] == "#":
        count+=1
    if array[h+2, w+1] == "#":
        count+=1
    if array[h+2, w+2] == "#":
        count+=1
        
    return count


H, W = map(int, input().split())
grid = np.array([["0"]*(W+2)]*(H+2))
for h in range(H+2):
    if (h == 0) or (h==(H+1)):
        for w in range(W+2):
            grid[h, w] = "-"
        continue
    inputs =  input()
    for w in range(W+2):
        if (w == 0) or (w==(W+1)):
            grid[h, w] = "-"
        else:
            grid[h, w] = inputs[w-1]
            
# print(grid)

for h in range(H):
    for w in range(W):
        if grid[h+1, w+1] == "#":
            print("#", end="")
        else:
            print(check_surrounding(grid, h, w), end="")
    print()

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

int main(){
	int i,n,ans,sum=0;
  	scanf("%d",&n);
  	int x[n];
  	for(i=1;i<=n;i++){
    	scanf("%d",&x[i]);
    }
  	int R=x[1],L=x[1];
  	for(i=1;i<=n;i++){
    	L=min(L,x[i]);
        R=max(R,x[i]);  
    }
  	for(i=1;i<=n;i++){
        	sum=sum+(x[i]-L)*(x[i]-L);
        }
  	ans=sum;
  	for(int j=L+1;j<=R;j++){
      	sum=0;
      	for(i=1;i<=n;i++){
        	sum=sum+(x[i]-j)*(x[i]-j);
        }
    	ans=min(ans,sum);
    }
  	cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    string S;
    int64_t ans=0, sA=0, Bs=0,BsA=0;
    rep(n,0,N){
        cin>>S;
        rep(i,0,S.size()-1){
            if(S.at(i)=='A' && S.at(i+1)=='B') ans++;
        }

        if(S.front()=='B' && S.back()=='A') BsA++;
        else if(S.front()=='B') Bs++;
        else if(S.back()=='A') sA++;
    }

    if(BsA) ans+=BsA-1;
    if(sA>Bs) ans+=Bs+(BsA>0);
    else ans+=sA+(BsA>0 && Bs>0);

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{

    
   
    for(;;)
    {
        int n=0;; int sum=0;

    
    scanf("%d",&n);
    if(n==0)
    {
        break;
    }
     int hit[n/4];

    for(int i=0; i<n/4; i++)
    {
        scanf("%d",&hit[i]);
        sum +=hit[i];
    }
    printf("%d\n",sum);

    }
}


Measured memory_bytes: 2668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}
const int MOD = 1000000007;

//while(c){
//    total += c%10;
//    c/=10;
//}

int main() {
    int a,b,c,x;cin >> a >> b >> c >> x;
    int cnt = 0;
    for(int i = 0;i <= a;i++){
        for(int j = 0;j <= b;j++){
            for(int k = 0;k <= c;k++){
                if(i * 500 + j * 100 + k * 50 == x){
                    cnt++;
                }
            }
        }
    }
    cout << cnt;
}




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

int main() {
 int a,b,c,f=0;
 cin>>a>>b>>c;
 
 ll x=c%b;
 for(int i=1;i<200;i++)
 {
   int temp=a*i;
   if(temp%b==x)

   {
        f=1;break;
   }
 }
 if(f)
 {
   cout<<"YES"<<endl;
 }
 else
 {
   cout<<"NO"<<endl;
 }
}

Measured memory_bytes: 256
N,K=map(int,input().split())
*X,=map(int,input().split())
A=[]
B=[]
for x in X:
    if x>=0:
        A.append(x)
    else:
        B.append(abs(x))
B.sort()
i=min(K,len(A))
j=K-i
ans=[]
while i>=0 and j<=len(B):
    if i==0:
        ans.append(B[j-1])
    elif j==0:
        ans.append(A[i-1])
    else:
        a,b=A[i-1],B[j-1]
        ans.append(a+b+min(a,b))
    i-=1
    j+=1
print(min(ans))

Measured memory_bytes: 20364
//Aleksander Łukasiewicz
#include<bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair

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

const int INF = 1000000009;

int main(){
    int X, Y, A, B, C;
    scanf("%d %d %d %d %d", &X, &Y, &A, &B, &C);
    vector<int> red, green, colorless;
    red.resize(A);
    green.resize(B);
    colorless.resize(C);
    for(int i=0; i<A; i++)
        scanf("%d", &red[i]);
    for(int i=0; i<B; i++)
        scanf("%d", &green[i]);
    for(int i=0; i<C; i++)
        scanf("%d", &colorless[i]);
    sort(red.begin(), red.end(), greater<int>());
    sort(green.begin(), green.end(), greater<int>());
    sort(colorless.begin(), colorless.end(), greater<int>());
    
    vector<int> apples;
    apples.resize(X + Y);
    for(int i=0; i<X; i++) apples[i] = red[i];
    for(int i=0; i<Y; i++) apples[i+X] = green[i];
    sort(apples.begin(), apples.end());
    for(int i=0; i<min(C, X+Y); i++)
        if(apples[i] < colorless[i])
            apples[i] = colorless[i];
        
    LL ans = 0;
    for(int i=0; i<X+Y; i++)
        ans += apples[i];
    printf("%lld\n", ans);
    
return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
long long int q[100005];
long long int p[100005];
int main(){
    int n;
    cin >> n;
    int a[n],b[n],c[n];
    for(int i=0;i<n;i++)cin >> a[i];
    for(int i=0;i<n;i++)cin >> b[i];
    for(int i=0;i<n;i++)cin >> c[i];
    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);
    int i=0,j=0;
    long long int ans=0;
    for(int k=0;k<n;k++){
        while(i<n && b[k]>=c[i])i++;
        q[k]=n-i;
    }
    for(int k=n-1;k>=0;k--)p[k]=p[k+1]+q[k];
    for(int k=0;k<n;k++){
        while(j<n && a[k]>=b[j])j++;
        ans += p[j];
    }
    cout << ans;
}

Measured memory_bytes: 6340
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
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;
}

template <typename T>
vector<T> gen_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto gen_v(size_t a, Ts... ts) {
    return vector<decltype(gen_v<T>(ts...))>(a, gen_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int M, D;
    cin >> M >> D;
    int cnt = 0;
    rep(m, 1, M + 1) {
        rep(d, 1, D + 1) {
            if (d >= 20 && (d % 10) >= 2 && (d / 10) * (d % 10) == m) { cnt++; }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int a = Integer.parseInt(scanner.next());
        int b = Integer.parseInt(scanner.next());
        int c = Integer.parseInt(scanner.next());
        int d = Integer.parseInt(scanner.next());
        scanner.close();

        System.out.println((a*b) - (((a*d)+(b*c)) - c*d));
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
using Graph = vector<vector<int>>;
using pint = pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int main(){
    ll x;cin>>x;
    for(ll i=0;i<x;i++){
        ll i5=i*i*i*i*i;
        ll y=i5-x;
        if(y>0){
            for(ll j=i-1;j>=0;j--){
                ll j5=j*j*j*j*j;
                if(j5<y) break;
                else if(j5==y){
                    cout<<i<<" "<<j<<"\n";
                    return 0;
                }
            }
        }
        else if(y==0){
            cout<<i<<" "<<0<<"\n";
            return 0;
        }
        else{
            for(ll j=-1;;j--){
                ll j5=j*j*j*j*j;
                if(j5<y) break;
                else if(j5==y){
                    cout<<i<<" "<<j<<"\n";
                    return 0;
                }
            }
        }
    }
        
    }


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

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine();
            var b = Console.ReadLine();
            var c = Console.ReadLine();

            var aa = a[0];
            var bb = b[1];
            var cc = c[2];

            Console.WriteLine("{0}{1}{2}",aa,bb,cc);

        }
    }
}


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

signed main()
{
	ios::sync_with_stdio(false);
	string t,s,u;
	int a,b;
	cin>>s>>t;
	cin>>a>>b;
	cin>>u;
	if(s==u) cout<<a-1<<" "<<b<<endl;
	else cout<<a<<" "<<b-1<<endl;	
	return 0;
}


Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int a, b;
	string s;
	cin >> a >> b >> s;
	bool ans1 = false;
	bool ans2 = false;
	if (s[a] == '-') {
		rep(i, a ) {
			if ( s[i]>='0'  && s[i] <= '9') {
				ans1 = true;
			}
			else {
				ans1 = false;
			}
		}
		REP(i, a+1, a+b+1) {
			if (s[i] >= '0' && s[i] <= '9') {
				ans2 = true;
			}
			else {
				ans2 = false;
			}
		}
	}
	string ans;
	if (ans1 && ans2) ans = "Yes";
	else ans = "No";
	cout << ans << endl;
} 

Measured memory_bytes: 256
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N,K = II()

ans = 0.0

for i in range(1,N+1):
    p = 1/N
    val = i
    while val < K:
        val = 2*val
        p = p/2
    ans += p

print(ans)    

Measured memory_bytes: 39152
N,M=map(int,input().split())
s=[0]*M
c=[0]*M
for i in range(0,M):
  s[i],c[i]=map(int,input().split())

flag=0
data=[-1 for i in range(0,N)]
for i in range(0,M):
  if data[s[i]-1]==-1:
    data[s[i]-1]=c[i]
  else:
    if data[s[i]-1]!=c[i]:
      flag=1
if data[0]==0 and N!=1:
  flag=1
if flag==1:
  print(-1)
else:
  for i in range(0,N):
    if data[i]==-1:
      if i==0 and N>1:
        data[i]=1
      else:
        data[i]=0
  ans=''
  for i in range(0,N):
    ans+=str(data[i])
  print(ans)


Measured memory_bytes: 38384
#include <cstring>
#include <vector>
#include <stack>
#include <bitset>
#include <algorithm>
#include <utility>
#include <cstring>
#include <map>
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair((a),(b))

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

const int INF=100000000;
const long long int INF_=1000000000000000000;

int N,M,H,K; //縦棒の本数、横棒の本数、縦棒の長さ、選ぶ縦棒の本数

bool isIn(int x){
	return 0<=x&&x<K;
}

int pre(const vector<int> &s,vector<int> &s_,const vector<vector<int> > &r,vector<vector<P> > &b){
	int result=0;
	rep(i,K){
		int x=i;
		rep(j,H){
			if(r[x][j]==1){
				b[x][j].first=i;
				++x;
			} else if(x!=0&&r[x-1][j]==1){
				b[x-1][j].second=i;
				 --x;
			}
		}
		s_[i]=s[x];
		result+=s[x];
	}
	return result;
}

/*
int solve(const vector<int> &s,const vector<int> &s_,const vector<vector<int> > &r,const vector<vector<P> > &b,const int X,const int Y){
	int result=0;
	result-=(isIn(b[X][Y].first)?s_[b[X][Y].first]:0)+(isIn(b[X][Y].second)?s_[b[X][Y].second]:0);
	vector<vector<int> > vvi=r;
	vvi[X][Y]=0;
	if(isIn(b[X][Y].first)){
		int x=b[X][Y].first;
		rep(i,H){
			if(vvi[x][i]==1) ++x;
			else if(x!=0&&vvi[x-1][i]==1) --x;
		}
		result+=s[x];
	}
	if(isIn(b[X][Y].second)){
		int x=b[X][Y].second;
		rep(i,H){
			if(vvi[x][i]==1) ++x;
			else if(x!=0&&vvi[x-1][i]==1) --x;
		}
		result+=s[x];
	}
	return result;
}
* */

int solve(const vector<int> &s,const vector<int> &s_,vector<vector<int> > &vvi,const vector<vector<P> > &b,const int X,const int Y){
	int result=0;
	result-=(isIn(b[X][Y].first)?s_[b[X][Y].first]:0)+(isIn(b[X][Y].second)?s_[b[X][Y].second]:0);
	vvi[X][Y]=0;
	if(isIn(b[X][Y].first)){
		int x=b[X][Y].first;
		rep(i,H){
			if(vvi[x][i]==1) ++x;
			else if(x!=0&&vvi[x-1][i]==1) --x;
		}
		result+=s[x];
	}
	if(isIn(b[X][Y].second)){
		int x=b[X][Y].second;
		rep(i,H){
			if(vvi[x][i]==1) ++x;
			else if(x!=0&&vvi[x-1][i]==1) --x;
		}
		result+=s[x];
	}
	vvi[X][Y]=1;
	return result;
}

int main(){
	while(cin >> N >> M >> H >> K){
		if(N+M+H+K==0) break;
		vector<int> score(N);
		vector<int> score_(N);
		vector<vector<int> > rail(N,vector<int>(H)); //何番の棒を結ぶか、上端からの距離、横棒が存在するなら1
		vector<P> rail_(M); //横棒のx,yを保存
		rep(i,N) cin >> score[i];
		rep(i,M){
			int a,b;
			cin >> a >> b;
			--a;
			rail_[i].first=a;
			rail_[i].second=b;
			rail[a][b]=1;
		}
		vector<vector<P> > bar(N,vector<P>(H,P(-1,-1))); //x,yにある横棒とつながっているスタート地点の番号
		int ans,sum;
		ans=sum=pre(score,score_,rail,bar);
		rep(i,M){
			ans=min(ans,sum+solve(score,score_,rail,bar,rail_[i].first,rail_[i].second));
		}
		cout << ans << endl;
	}
	return 0;
}

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

vector<vector<int>> graph(100001,vector<int>());

int main(){
  int n;cin >> n;
  long long a[n],b[n];rep{
    cin >> a[i] >> b[i];
  }
  long long ans = 0;
  for(int i = n-1;i>=0;i--){
    a[i] += ans;
    if(a[i]%b[i]!=0 && a[i]>b[i]){
      ans += b[i]-(a[i]%b[i]);
    }else if(a[i]%b[i]!= 0 && a[i]<b[i]){
      ans += b[i]-a[i];
    }
    //cout << ans << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long int  ll;
typedef pair<ll, ll> P;

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
	if(n==0) return (ll)1;
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
ll modinv(ll a, ll m) {
	if(m==0)return (ll)1;
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


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

int main() {
 ios::sync_with_stdio(false);



ll n;
cin>>n;

vector<ll> vec[n+1];
for(int i=1;i<=n-1;i++){
ll p,q;
cin>>p>>q;
if(p>q)swap(p,q);
vec[q].push_back(p);
}

ll ans=0;
for(ll i=1;i<=n;i++){
ll r=vec[i].size();
ll plus=(i-1)*(n-i)+n;
for(ll j=0;j<r;j++){
	ll mval=vec[i][j];
	plus-=mval*(n-i+1);
}
ans+=plus;
}

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


Measured memory_bytes: 14512
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

signed main(void)
{
  int n, m;
  cin >> n >> m;
  int tmp = 1LL<<m;
  cout << (m*1900 + (n-m)*100) * tmp << endl;

  return 0;
}


Measured memory_bytes: 256
a=[0]*5
b=[0]*5
ans=0
for i in range(5):
  a[i]=int(input())
  b[i]=a[i]%10
  if (b[i]==0):
    b[i]=10
  
here=b.index(min(b))
for i in range(5):
  if (i==here):
    ans+=a[i]
  else:
    if (b[i]==10):
      ans+=a[i]
    else:
      ans+=((a[i]//10)+1)*10
      
print(ans)


Measured memory_bytes: 3064
using System;

namespace test
{
    class program
    {
        static void Main()
        {
            string[] str = Console.ReadLine().Split(' ');
            int W = int.Parse(str[0]);
            int H = int.Parse(str[1]);
            int x = int.Parse(str[2]);
            int y = int.Parse(str[3]);
            int r = int.Parse(str[4]);
            if (x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H)
                Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 8968
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const ll MOD = 1e9+7;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

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

    vector<vector<ll>> v(10, vector<ll>(10));

    REP2(i, 1, n+1) {
        string s = to_string(i);
        int x = s[0] - '0';
        int y = s.back() - '0';
        v[x][y]++;
    }

    ll cnt = 0;
    REP(i, 10) REP(j, 10) {
        cnt += v[i][j]*v[j][i];
    }

    std::cout << cnt << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ssd ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug_x(x) cout<< #x <<"---> : "<<x<<endl;
#define debug_ve(x) for(auto it: x) cout<<it<<" ";
#define rep(i,a,n) for (int i=a;i<n;i++)
#define _rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef double db;
//std::mt19937 mrand(random_device{}());
//int rnd(int x) { return mrand() % x ; }
const ll mod=1e7;
ll ksm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

/***********************/

int main(){
    ssd;
    ll n ,x,y;
    cin>> n >> x >>y ;
    vector<ll> ans(n);
    for(ll i =1 ;i <=n; i++){
        for(ll j =i+1;j<=n;j++){
            ll d = min(j-i,abs(i-x)+1 + abs(y-j));
            ans[d]++;
        }
    }
    for(ll i =1;i<=n-1;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int h,w ;
    scanf  ("%d%d",&h,&w) ;
    char s[60][60];
    for (int i=0; i<h; i++) {
        scanf ("%s",s[i]) ;
    }
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            if (s[i][j]=='.') {
                int bomb=0 ;
                if (s[i-1][j-1] =='#') { bomb++ ; }
                if (s[i-1][j]   =='#') { bomb++ ; }
                if (s[i-1][j+1] =='#') { bomb++ ; }
                if (s[i][j-1]   =='#') { bomb++ ; }
                if (s[i] [j+1]  =='#') { bomb++ ; }
                if (s[i+1][j-1] =='#') { bomb++ ; }
                if (s[i+1][j]   =='#') { bomb++ ; }
                if (s[i+1][j+1] =='#') { bomb++ ; }
                char ans ='0'+bomb ;
                s[i][j] = ans ;
            }
        }
        printf ("%s\n",s[i]) ;
    }
    return 0 ;
}

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

using ll = long long;

constexpr ll INF = 1e18;

using weight = ll;

struct edge {
    int from, to;
    weight cost;
    bool operator<(edge const& rhs) const {
        return cost < rhs.cost;
    }
};

using edges = std::vector<edge>;
using graph = std::vector<edges>;

int main() {
    int N;
    cin >> N;
    vector<vector<ll>> d(N, vector<ll>(N));
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < N; ++j) {
            cin >> d[i][j];
        }
    }
    bool check = true;
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < N; ++j) {
            ll mi = INF;
            for(int k = 0; k < N; ++k) {
                mi = min(mi, d[i][k] + d[k][j]);
            }
            check &= (mi == d[i][j]);
        }
    }

    if(!check) {
        cout << -1 << endl;
    } else {
        edges es;
        for(int i = 0; i < N; ++i) {
            for(int j = i + 1; j < N; ++j) {
                es.push_back(edge{i, j, d[i][j]});
            }
        }
        sort(es.begin(), es.end());
        vector<vector<ll>> d2(N, vector<ll>(N, INF));
        for(int i = 0; i < N; ++i) {
            d2[i][i] = 0;
        }
        ll res = 0;
        for(auto& e : es) {
            if(d[e.from][e.to] != d2[e.from][e.to]) {
                res += e.cost;
                for(int i = 0; i < N; ++i) {
                    for(int j = 0; j < N; ++j) {
                        d2[i][j] = d2[i][j] = min(d2[i][j], d2[i][e.from] + d2[e.to][j] + e.cost);
                        d2[i][j] = d2[i][j] = min(d2[i][j], d2[i][e.to] + d2[e.from][j] + e.cost);
                    }
                }
            }
            //cout << "step: " << endl;
            //for(int i = 0; i < N; ++i) {
            //    for(int j = 0; j < N; ++j) {
            //        cout << d2[i][j] << ' ';
            //    }
            //    cout << endl;
            //}
        }
        cout << res << endl;
    }
}




Measured memory_bytes: 2428
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include<bits/stdc++.h>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>*/

#define sz(s) (int)(s.size())
#define all(s) s.begin(), s.end()
#define rep(a, b, c) for(int a = b; a <= c; ++a)
#define per(a, b, c) for(int a = b; a >= c; --a)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
//using namespace __gnu_pbds;

typedef unsigned long long ull;
typedef long long ll;
/*typedef tree<pair<int, int>, 
null_type, less<pair<int, int>>, 
rb_tree_tag, tree_order_statistics_node_update>
ordered_set;*/
//find_by_order() order_of_key()

const double eps = 1e-7;
const int mod = 1e9+7, MXN = 5e5+17;
const int dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0};

template<typename T>inline bool updmin(T &a, const T &b) {return a > b ? a = b,1 : 0;}
template<typename T>inline bool updmax(T &a, const T &b) {return a < b ? a = b,1 : 0;}

int32_t main() { _
#ifdef DanQQQQQ
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	int n, a; cin >> n >> a;
	ll dp[n+5][2550];
	memset(dp,0ll,sizeof dp);
	rep(i,1,n) {
		int x; cin >> x;
		per(j,i,2) rep(k,1,2500-x)
			dp[j][k+x] += dp[j-1][k];
		++dp[1][x];
	}
	ll res = 0ll;
	rep(i,1,n) res += dp[i][i*a];
	cout << res << endl;
	return 0;
}


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

//const int INF = 1001001001;

/*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 { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;

    for (int i = 0; i < s.size(); i++) {
        if (i == a) {
            if (s[i] != '-') {
                cout << "No" << endl;
                return 0;
            }
        }
        else {
            if (s[i] == '-') {
                cout << "No" << endl;
                return 0;
            }
        }
    }

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
using namespace std;
const int Tmax = 100;
int K,T,A[Tmax];

int main(){
	cin >> K >> T;
	for(int i=0; i<T; i++){
		cin >> A[i];
	}

	priority_queue<pair<int, int> > q;
	for(int i=0; i<T; i++){
		q.push(make_pair(A[i], i+1));
	}

	int ans = 0;
	int last = -1;
	for(int i=0; i<K; i++){
		int a = q.top().first;
		int n = q.top().second;
		q.pop();
		if(q.empty()){
			ans = a-1;
			break;
		}
		else if(n == last){
			int b = q.top().first;
			int m = q.top().second;
			q.pop();
			q.push(make_pair(a,n));
			if(b > 1) q.push(make_pair(b-1,m));
			//cout << m << endl;
			last = m;
		}
		else {
			if(a > 1) q.push(make_pair(a-1,n));
			//cout << n << endl;
			last = n;
		}
	}
	cout << ans << endl;

	/*
	for(int i=0; i<T; i++){
		cout << q.top().first << " " << q.top().first << endl;
		q.pop();
	}
	*/

	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc153/tasks/abc153_e
# 個数無制限ナップサック問題

H, N = read_ints()
A, B = read_col(N)


'''
dp[i][j] ... 与えられるダメージの最大。[0,i)の魔法で、魔力j以下使うとき。
更新則
dp[i+1][j] = max(dp[i][j],dp[i+1,j-B[i]] + A[i])
∵i番目を使わないとき、i番目の魔法をもう一回使うとき でダメージの最大の方を選択する
初期条件
dp[0][0] = 0 #なくても大丈夫そう


これだとjが大きすぎてTLEする
'''

'''
dp[i][j] ... 魔力の最小値。[0,i)の魔法で、ちょうどダメージjにできるとき。ちょうどjにできなければINF
更新則

dp[i+1][j] = min(dp[i][j],dp[i+1,j-A[i]] + B[i]) で良さそうじゃない？
∵i番目を使わないとき、i番目の魔法をもう一回使うとき でダメージの最大の方を選択する
初期条件
dp[i][0] = 0
'''


J = max(2 * H + 1, 2 * max(B))
dp = [[INF] * (J) for _ in range(N + 1)]  # Hの二倍も取れば十分かな？
for i in range(N + 1):
    dp[i][0] = 0

for i in range(N):
    for j in range(J):
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
        if j - A[i] >= 0:
            dp[i + 1][j] = min(dp[i + 1][j], dp[i + 1][j - A[i]] + B[i])

ans = INF
for x in dp[N][H:]:
    ans = min(ans, x)

print(ans)


Measured memory_bytes: 191640
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <deque>

using namespace std;

void show(deque<int> &deq) {
	for (auto x: deq) {
		cout << x << " ";
	}
	cout << endl;
}

bool check(int factor, vector<int> a, int k) {
// printf("check: factor %d, k %d\n", factor, k);
	if (factor == 1) {
		return true;
	}

	deque<int> deq;
	for (auto x: a) {
		int val = x % factor;
		if (val > 0) {
			deq.push_back(val);
		}
	}
	sort(deq.begin(), deq.end());

	int rest = k;
	int plus = 0;
	int minus = 0;

	while(!deq.empty()) {
// printf("rest %3d, plus %3d, minus %3d\n", rest, plus, minus);
		if (minus > 0) {
			int mini = min(deq.front(), minus);
			minus -= mini;
			deq.front() -= mini;

			if (deq.front() == 0) {
				deq.pop_front();
// printf("pop_front\n");
			}
		} else if (plus > 0) {
			int mini = min(factor - deq.back(), plus);
			plus -= mini;
			deq.back() += mini;

			if (deq.back() == factor) {
				deq.pop_back();
// printf("pop_back\n");
			}

		} else {
// show(deq);
			int mini = min(deq.front(), factor - deq.back());

			if (mini <= rest) {
				rest -= mini;
				plus += mini;
				minus += mini;
			} else {
				return false;
			}
		}
	}

	return true;
}

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

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


	vector<int> factors;

	for (int i = 1; i * i <= sum; i++) {
		if (sum % i == 0) {
			factors.emplace_back(i);
			factors.emplace_back(sum / i);
		}
	}

	sort(factors.begin(), factors.end(), greater<int>());

	for (auto factor: factors) {
		auto ret = check(factor, a, k);
		if (ret) {
			cout << factor << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <sstream>
#include <map>
using namespace std;
using ll = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

int main() {
  int N;
  while (scanf("%d", &N) != EOF) {
    map<int, int> mp;
    for (int i : range(N)) {
      int a;
      scanf("%d", &a);
      mp[a]++;
    }
    int n = mp.size();
    int parity = 0;
    for (auto p : mp) {
      if (p.second % 2 == 0) parity ^= 1;
    }
    cout << n - parity << endl;
  }
}


Measured memory_bytes: 4864
#define M 1000001
T[M];long long p[M];
main(i,j){
for(i=0;i<M;i++)p[i]=i;
for(i=2;i<M;i++)if(!T[i])for(p[i]-=p[i]/i,j=i*2;j<M;j+=i)T[j]=1,p[j]-=p[j]/i;
for(i=1;i<M;i++)p[i]+=p[i-1];
for(scanf("%d",&i);i;i--)scanf("%d",&j),printf("%lld\n",p[j]+1);
exit(0);}

Measured memory_bytes: 12312
if __name__ == '__main__':
    n, k = list(map(int, input().split(" ")))
    p = list(map(int, input().split(" ")))

    # d = deque([0])
    d = [0]
    for i in range(n):
        d.append(d[i] + p[i])

    # print(d)

    max_sum = 0
    rangeN = n - k + 1

    for i in range(rangeN):
        sum_d = d[i + k] - d[i]
        if max_sum < sum_d:
            max_sum = sum_d
    # print(max_sum)

    # r_array = [sum(p[i:i + k]) for i in range(rangeN)]
    print((max_sum + k) / 2)

Measured memory_bytes: 25060
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<utility>
#include<functional>
#include<algorithm>
#include<queue>
#include<map>
#include<string>
#include<numeric>


#define FOR(i, a, b) for(int i=a; i<b; i++)
#define COUT(a) cout << a << endl;

using namespace std;
using Int = long long;
using P = pair<Int, Int>;

vector<Int> A;

Int f(Int x){
    Int sum = 0;
    FOR(i, 0, A.size()){
        sum += abs(A[i] - x) ;
    }
    return sum;
}

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

    A = vector<Int>(N);
    
    FOR(i, 0, N){
        cin >> A[i];
    }

    Int n = 0;
    transform(begin(A),
    end(A), begin(A), [&](Int x){n++; return x-n;});

    sort(begin(A), end(A));

    Int x = A[A.size()/2];

    Int y = f(x);
    Int z = f(x+1);

    COUT(min(y, z));
    
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string n;
int main()
{
    while(cin>>n)
    {
        for(int i=0;i<n.length();i++)
        {
            if(n[i]=='1') n[i]='9';
            else if(n[i]=='9') n[i]='1';
            else continue;
        }
        cout<<n<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int inf = 1000000000;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};

int main(){
    int c;
    cin >> c;
    if(c == 0){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 3632
import math
import itertools
N = int(input())
x = [list(map(int,input().split(' '))) for i in range(N)]
length = range(N)
ans = []

for i in itertools.permutations(length): #1,2,3 231

   result = []
   for i1 in range(len(i)-1):
       result.append(math.sqrt((x[i[i1]][0]-x[i[i1+1]][0])**2 + (x[i[i1]][1]-x[i[i1+1]][1]) **2))


   ans.append(sum(result))

print(sum(ans)/len(ans))


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

using namespace std;

const int N = 1e5+100;

typedef long long ll;

#define int ll

int n, m, v, p;
int a[N], b[N];

bool check(int sz, int v){
	if(v<=0 || sz == 0)
		return true;
	int all=0;
	for(int i=0 ; i<sz ; i++)
		all += min(b[i], m);
	return all >= v * m;
}

bool can(int ind){
	int cv = v;
	cv -= p-1;
	cv -= n-ind;
	int g = a[ind] + m;
	int sz = 0;
	for(int i=p-1 ; i<ind ; i++){
		if(g < a[i])
			return false;
		b[sz ++] = g - a[i];
	}
	return check(sz, cv);
}

int32_t main(){
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n >> m >> v >> p;
    for(int i=0 ; i<n ; i++)
    	cin >> a[i];
    sort(a, a+n, greater<int>());
    int l=p-1, r=n;
    while(r-l>1){
    	int mid = (l+r)/2;
    	if(can(mid))
    		l = mid;
    	else
    		r = mid;
    }
    cout << l+1 << "\n";
}



























Measured memory_bytes: 1792
def main():
    import sys
    from collections import defaultdict
    N, M, K = map(int, sys.stdin.readline().split())

    F = [set() for _ in range(N)]
    B = [set() for _ in range(N)]
    for m in range(M):
        a, b = map(int, sys.stdin.readline().split())
        a, b = a - 1, b - 1
        F[a].add(b)
        F[b].add(a)

    for k in range(K):
        c, d = map(int, sys.stdin.readline().split())
        c, d = c - 1, d - 1
        B[c].add(d)
        B[d].add(c)

    D = defaultdict(set)
    parents = [-1] * N
    visited = set()
    for s in range(N):
        if s in visited:
            continue

        stack = [s]
        D[s].add(s)
        while stack:
            n = stack.pop()
            visited.add(n)
            parents[n] = s
            for to in F[n]:
                if to in visited:
                    continue
                D[s].add(to)
                stack.append(to)

    ans = [0] * N
    for i in range(N):
        X = D[parents[i]]
        tmp_ans = 0
        tmp_ans += len(X)
        tmp_ans -= len(F[i])
        tmp_ans -= 1
        for b in B[i]:
            if b in X:
                tmp_ans -= 1
        ans[i] = tmp_ans

    print(*ans, sep=' ')


if __name__ == '__main__':
    main()


Measured memory_bytes: 114316
#include<stdio.h>
#include<string.h>
#include<math.h>
int main() {


	int n, m, j, i, k[30], a[30][30], s[31] = { 0 };
	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++) {
		scanf("%d", &k[i]);
		for (j = 0; j < k[i]; j++) {
			scanf("%d", &a[i][j]);
			s[a[i][j]]++;
		}
	}
	int cnt = 0;
	for (i = 0; i <= m; i++)
		if (s[i] == n)cnt++;
	printf("%d", cnt);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>       // printf,scanf
#include <stdlib.h>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>  //sort,binarySearch
#include <functional> 
#include <iomanip>    // setprecision
#include <utility>    // c+11 Array
#include <set>
#include <sstream>
#include <map>
#include <bits/stdc++.h>
#define MOD 1000000007
#define PI 3.141592653589793238462643383279
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define pb(x) push_back(x)
#define debug(x) cout << #x << " = " << x << endl;
#define debret(x) debug(x) ; return 0;

using namespace std;

int main(){

    int H, W;

    cin >> H >> W;

    char a[H][W];

    REP(i,H){
        REP(j,W){
            cin >> a[i][j];
        }
    }
    int x = 0;
    int y = 0;
    while(y < H-1 || x < W-1){
        
        a[y][x] = '.';
        if((y != H -1) && a[y+1][x] == '#'){
            y++;
        }else if((x != W-1) && a[y][x+1] == '#'){
            x++;
        }else{
            break;
        }
    }
    
    a[y][x] = '.';


    REP(i,H){
        REP(j,W){
            if(a[i][j] == '#'){
                cout << "Impossible" << endl;
                return 0;
            }
        }
    }

    cout << "Possible" << endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void){
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    int x=c-a,y=d-b;
    printf("%d %d %d %d",c-y,d+x,a-y,b+x);
}


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

#define SIZE 300005
#define MOD 1000000007LL
#define INF 1 << 30
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef valarray<int> Array;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i];if(i==a.size()-1)cout<<endl;else cout<<" ";}}
int gcd(int a,int b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
int lcm(int a,int b){return a==0||b==0?0:a*b/gcd(a,b);}

int W, N;
int v[1010];
int w[1010];

void solve()
{
  int dp[1010];
  fill_n(dp,1010,0);
  REP(i,N) DOWN(j,W,w[i])
    dp[j] = max(dp[j],dp[j-w[i]]+v[i]);
  int ans1 = 0, ans2 = 0;
  DOWN(i,W,0) if(ans1 <= dp[i])
  {
    ans1 = dp[i];
    ans2 = i;
  }
  printf("%d\n%d\n",ans1,ans2);
}

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

  for(int c = 1; scanf("%d",&W), W; c++)
  {
    scanf("%d",&N);
    REP(i,N) scanf("%d,%d",&v[i],&w[i]);
    printf("Case %d:\n",c);
    solve();
  }
  return 0;
}

Measured memory_bytes: 3172
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;
    
    public static void main(String[] args) {
        long a = nl();
        long b = nl();
        int c = ni();
        int d = ni();
        long lcm = lcm(c, d);
        long countC = b/c - (a-1)/c;
        long countD = b/d - (a-1)/d;
        long countLcm = b/lcm - (a-1)/lcm;
        long countCOrD = countC + countD - countLcm;
        
        so.println((b-a+1) - (countCOrD));
    }
    
    static int gcd(int m, int n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
    
    static long lcm(int m, int n) {
        return (long) m * (long) n / gcd(m, n);
    }

    private static long nl() {
        return sc.nextLong();
    }

    private static int ni() {
        return sc.nextInt();
    }

    private static String ns() {
        return sc.next();
    }

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

    private static long[] nlongs(int n) {
        return nlongs(n, 0);
    }

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


Measured memory_bytes: 23760
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;

int main(){
  long long H,W;
  cin >> H >> W;
  long long ret=0;
  if(H==1 || W==1) ret=1;
  else if(W%2==0) ret=W/2*H;
  else{
    if(H%2==0) ret=W/2*H+H/2;
    else ret=W/2*H+H/2+1;
  }

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.HashMap;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DigitsMultiplication solver = new DigitsMultiplication();
        solver.solve(1, in, out);
        out.close();
    }

    static class DigitsMultiplication {
        HashMap<Long, Long> map;
        long diff = Long.MAX_VALUE;
        long ansA;
        long ansB;

        static HashMap<Long, Long> primeFactorize(long x) {
            HashMap<Long, Long> result = new HashMap<>();
            for (long i = 2; i * i <= x; i++) {
                if (x % i != 0) {
                    continue;
                }
                long ex = 0;
                while (x % i == 0) {
                    ex++;
                    x /= i;
                }
                result.put(i, ex);
            }
            if (x != 1) {
                result.put(x, 1L);
            }
            return result;
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();

            map = primeFactorize(n);
            List<Long> list = new ArrayList<>(map.keySet());
            List<Long> primes = new ArrayList<>();
            for (long key : list) {
                int limit = map.get(key).intValue();
                for (int i = 0; i < limit; i++) {
                    primes.add(key);
                }
            }

            dfs(primes, 0, 1, 1);

            int result = Math.max(
                    String.valueOf(ansA).length(),
                    String.valueOf(ansB).length()
            );
            out.println(result);
        }

        public void dfs(List<Long> list, int index, long a, long b) {
            if (index == list.size()) {
                if (Math.abs(a - b) < diff) {
                    diff = Math.abs(a - b);
                    ansA = a;
                    ansB = b;
                }
            } else {
                dfs(list, index + 1, a * list.get(index), b);
                dfs(list, index + 1, a, b * list.get(index));
            }
        }

    }
}



Measured memory_bytes: 37140
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();
        Console.WriteLine(s.Substring(0, n / 2) == s.Substring(n / 2) ? "Yes" : "No");
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int a[3];
    scn(3, a);

    sort(a, a + 3);
    if(a[0] == a[2])pri(1);
    else if(a[0] == a[1])pri(2);
    else if(a[1] == a[2])pri(2);
    else pri(3);


/*/

//*/ break;
  }
  return 0;
}


Measured memory_bytes: 256