akhauriyash/Code-Regression huggingface dataset:
from math import ceil,floor,comb,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
s = input()
a = [0]*(n+1)
b = [0]*(n+1)
# a[i]: s[:i-1]を白とするための変更個数
# b[i]: s[i:]を黒とするための変更個数

for i in range(1, n+1):
    a[i] = a[i-1] + (1 if s[i-1] == '#' else 0)

for i in range(n-1, -1, -1):
    b[i] = b[i+1] + (0 if s[i] == '#' else 1)

c = [0]*(n+1)
for i in range(n+1):
    c[i] = a[i] + b[i]

print(min(c))

Measured memory_bytes: 33932
import sys
N, A, B = map(int, input().split())

if A > B:
    print(0)
    sys.exit(0)
if N == 1:
    if A == B:
        print(1)
    else:
        print(0)
    sys.exit(0)

x = B*(N-1)+A
n = A*(N-1)+B
print(x-n+1)

Measured memory_bytes: 9064
n_=input()
n=int(n_)
l=len(n_)
for i in range(1,17):
    if n+1==(int(n_[0])+1)*10**(l-1):
        ans=0
        while n>0:
            ans+=n%10
            n//=10
        print(ans)
        exit()

n = int(n_[0])*10**(l-1)-1
ans=0
while n>0:
    ans+=n%10
    n//=10
print(ans)

Measured memory_bytes: 3064
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

int main() {
	string s;
	int arr[4];
	cin >> s;
	rep(i, 4){
		arr[i] = s[i] - '0';
	}
	rep(i, 8){
		int curr = i;
		int ans = arr[0];
		rep(j, 3){
			if(curr%2 == 0){
				ans += arr[j+1];
			}else{
				ans -= arr[j+1];
			}
			curr /= 2;
		}
		if(ans == 7){
			cout << arr[0];
			curr = i;
			rep(j, 3){
				if(curr%2 == 0){
					cout << '+';
				}else{
					cout << '-';
				}
				cout << arr[j+1];
				curr /= 2;
			}
			cout << "=7";
			return 0;
		}
	}
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int n,k;
  cin >> n >> k;
  vector<int> po,ne;
  rep(i,n){
    int x;cin >> x;
    x >= 0 ? po.push_back(x) : ne.push_back(-x);
  }
  reverse(ALL(ne));
  ll res = (1ll << 60);
  for(int i = 1;i < k;i++){
    if(i > po.size())break;
    ll neg = k-i;
    if(neg > ne.size())continue;
    res = min(res,min(po[i-1],ne[neg-1])*2ll+max(po[i-1],ne[neg-1]));
  }
  if(po.size() >= k)res = min(res,po[k-1]*1ll);
  if(ne.size() >= k)res = min(res,ne[k-1]*1ll);
  cout << res << endl;





  

  return 0;
}

Measured memory_bytes: 1020
def main():
    ini_inp=list(map(lambda x:int(x),input().split()))
    N=ini_inp[0]
    M=ini_inp[1]

    L=[]
    R=[]
    for i in range(M):
        sec_inp=list(map(lambda x:int(x),input().split()))
        L.append(sec_inp[0])
        R.append(sec_inp[1])

    low=L[0]
    up=R[0]
    flag=0
    for i in range(1,M):
        if L[i]>up:
            flag=1
            break
        elif L[i]>=low:
            low=L[i]
        elif R[i]<=up:
            up=R[i]

    if flag==0:
        print(up-low+1)
    else:
        print(0)

if __name__=="__main__":
    main()
        


Measured memory_bytes: 11052
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#define ll long long
#define out(a) printf("%d",a)
#define ln printf("\n")
const int N=1e5+50;
using namespace std;
int n;
int sum=0;
int p[N];
int read()
{
	int s=0,t=1; char c=getchar();
	while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
	return s*t;
}
ll readl()
{
	ll s=0,t=1; char c=getchar();
	while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
	return s*t;
}
int main()
{
	n=read();
	for (int i=1;i<=n;i++){
	  p[i]=read();
	}
	sort(p+1,p+n+1);
	for (int i=1;i<n;i++)
	  sum+=p[i];
	sum+=p[n]>>1;
	out(sum);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 60;
const ll MOD = 1e9+7;

int main(){
    int N; cin >> N;
    ll A[N];
    for(int i = 0; i < N; i++) cin >> A[i];
    ll ans = 0;
    for(int bit = 0; bit < MAX; bit++){
        ll num[2] = {0, 0};
        for(int i = 0; i < N; i++){
            if((1LL << bit) & A[i]) num[0]++;
            else num[1]++;
        }
        ans = (ans + (num[0] * num[1] % MOD) * ((1LL << bit) % MOD)) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  int n;
  cin>>n;
  int l[n];
  rep(i,n) cin>>l[i];
  sort(l, l + n);
  int sum = 0;
  rep(i,n-1) {
    sum += l[i];
  }
  if(l[n-1] < sum) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 201010;

// 組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] / (fac[k] * fac[n - k]);
}


ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
char c[310][310];
ll dp[101];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	vector<ll>a(n);
	vector<ll>sum(n);
	rep(i, n) {
		cin >> a[i];
		sum[i] = a[i];
	}
	rep(i, n - 1) {
		sum[i + 1] += sum[i];
	}
	map<ll, ll>mp;
	ll ans = 0;
	rep(i, n) {
		mp[sum[i]]++;
		if (sum[i] == 0)ans++;
	}
	COMinit();
	for (auto p : mp) {
		ll x = p.second;
		if (x > 1) {
			ans += x * (x - 1) / 2;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 20236
#include<stdio.h>
#include<string.h>

const int N =259;

int main(void)
{
   char a[N],b[N];
   int k =0 ,go=0;
   
   while(fgets(a,259,stdin))
   {
   	int c = strlen(a)-1;
   	
   	for(int i=c ,j =0 ;j<c ;i++,j++)
   	{
   		a[i]=a[j];
	}
	
   	fgets(b ,259 ,stdin);
   	for(int i =0 ;i<strlen(a) ; i++)
   	{
   		k =0;
   	   for(int j =0 ;j<strlen(b)-1 ; j ++)
   	   {
   		if(a[i+j]==b[j])
   		{
   			k++;
		}
		else
		{
			break;
		}   
      	}
     
		if(k==strlen(b)-1)
		{
			go =1;
			break;
	    }
    }
	if(go==1)
	{
		printf("Yes\n");
	}
    else
    {
    	printf("No\n");
	}
   	
   }
   
}


Measured memory_bytes: 2100
#include <iostream>
#include <cmath>

using namespace std;

int dp[101][10001];

int main(int argc, char const* argv[])
{
	int n, W;
	cin >> n >> W;
	int *v = new int[n];
	int *w = new int[n];
	for(int i = 0; i < n; i++){
			cin >> v[i] >> w[i];
	}
	for(int i = 0; i < n; i++){
			for(int j = 1; j < W + 1; j++){
					if(j >= w[i]){
							dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
					}else{
							dp[i + 1][j] = dp[i][j];
					}
			}
	}
	cout << dp[n][W] << endl;
	return 0;
}



Measured memory_bytes: 6984
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Multiplication_B
{
    class Class2
    {
        static void Main()
        {

            int n = int.Parse(Console.ReadLine());

            if (n == 0)
            {
                Console.WriteLine(0);
                return;
            }

            string[] strArray = Console.ReadLine().Split(" ");
            Array.Resize(ref strArray, n);
            ulong[] longArray = strArray.Select(ulong.Parse).ToArray();

            if (strArray.Contains("0"))
            {
                Console.WriteLine(0);
                return;
            }

            ulong value = 1;
            ulong max = (ulong)Math.Pow(10, 18);

            if (n == 1)
            {
                Console.WriteLine(value);
            }

            try
            {
                checked
                {
                    foreach (ulong arrayMirror in longArray)
                    {
                        value *= arrayMirror;
                    }
                }
            }
            catch (OverflowException ex)
            {
                Console.WriteLine(-1);
                return;
            }

            if (value > max)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine(value);
            }



        }
    }
}


Measured memory_bytes: 42884
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int>G[100];
int n,m;
vector<pair<int,int> >s[100][2];
int color[100];
bool dfs(int u)
{
	color[u]=1;
	bool ans=1;
	for(int v:G[u])
	{
		if(!color[v])ans&=dfs(v);
		else
		{
			ans&=color[v]==2;
		}
	}
	color[u]=2;
	return ans;
}
main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		int k;cin>>k;
		for(;k--;)
		{
			int a,b;string t;
			cin>>a>>t>>b;
			a--;
			s[a][t==">="].push_back(make_pair(b,i));
		}
	}
	for(int i=0;i<m;i++)
	{
		sort(s[i][0].begin(),s[i][0].end());
		sort(s[i][1].begin(),s[i][1].end());
		for(int j=0;j<s[i][0].size();j++)
		{
			for(int k=0;k<s[i][1].size();k++)
			{
				if(s[i][0][j].first<s[i][1][k].first)
				{
					G[s[i][0][j].second].push_back(s[i][1][k].second);
				}
			}
		}
	}
	bool flag=1;
	for(int i=0;i<n;i++)
	{
		if(!color[i])flag&=dfs(i);
	}
	cout<<(flag?"Yes":"No")<<endl;
}



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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define INF 2000000000000000000LL
#define EPS 1e-9
#define debug(a) cerr<<#a<<"="<<(a)<<"\n"
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL);

typedef long long ll;
typedef unsigned long long ull;
typedef complex<double> cd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll mod = 1e9+7;
const double PI = acos(-1);

int n,i,j,k,t;
char s[3005];
int dp[3003][3003];
int sum[3003];


int main(){
    memset(dp, 0, sizeof dp);
    scanf("%d", &n);
    scanf("%s", s+2);
    dp[1][1] = 1;
    for(i=2;i<=n;++i){
        sum[0] = 0;
        for(j=1;j<=n;++j)
            sum[j] = (sum[j-1] + dp[i-1][j]) % mod;
        for(j=1;j<=i;++j){
            if(s[i] == '>')
                dp[i][j] = (mod + sum[n] - sum[j-1]) % mod;
            else
                dp[i][j] = sum[j-1];
        }
    }
    sum[0] = 0;
    for(i=1;i<=n;++i)
        sum[i] = (sum[i-1] + dp[n][i]) % mod;
    printf("%d\n", sum[n]);
    return 0;
}

Measured memory_bytes: 35456
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

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

    ll n,k,ans1=0,ans2=0;
	cin >> n;
	ll h[n];
	rep(i,n){
		cin >> h[i];
	}

	rep(i,n-1){
		if(h[i]>=h[i+1]){
			ans2++;
			if(ans2>ans1){
				ans1=ans2;
			}
		}
		else{
			ans2=0;
		}
	}

	cout << ans1 << endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,a,c[100009];
ll ans=1ll;
int main(){
    cin>>n;
    c[0]=3;
    for(int i=0;i<n;i++){
        cin>>a;
        (ans*=c[a])%=1000000007;
        c[a]--;
        c[a+1]++;
    }
    cout<<ans<<endl;
}

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

int main(){
  string S;
  cin >> S;
  char first = S[0];
  int first_count = 0;
  int second_count = 0;
  char second;
  if(S[0] != S[1]){
    second = S[1];
  }else{
    second = S[2];
  }
  for(int i=0;i<S.size();i++){
    if(S[i] == first){
      first_count++;
    }else if(S[i]==second){
      second_count++;
    }
  }
  if(first_count==2&&second_count==2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


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

using namespace std;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
//  --------------------------------------
    
    double W, H, x, y, S;

    cin >> W >> H >> x >> y;

    S = double(W) * double(H) / 2.0;

    cout << S << " ";

    if (x == W / 2.0 && y == H / 2.0){
        cout << 1 << "\n";
    }else{
        cout << 0 << "\n";
    }
}


Measured memory_bytes: 256
#!/bin/sh
read aa
read bb
read cc
cnta=0
cntb=0
cntc=0

a ()
{
	check=${aa:0:1}
	aa=${aa/?/}
	now=A
}
b ()
{
	check=${bb:0:1}
	bb=${bb/?/}
	now=B
}
c ()
{
	check=${cc:0:1}
	cc=${cc/?/}
	now=C
}

a

while :
do
	ans=$now
	case ${check} in
		a)
			a
		;;
		b)
			b
		;;
		c)
			c
		;;
		*)
			break
		;;
	esac
done
echo $ans


Measured memory_bytes: 1396
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

void call(int n)
{
	int i = 1;
	int x;

	do {
		x = i;
		if (x % 3 == 0) {
			printf(" %d", i);
		}
		else {
			do {
				if (x % 10 == 3) {
					printf(" %d", i);
					x = 0;
				}
				else x /= 10;
			} while (x);
		}
	} while (++i <= n);
	putchar('\n');
}

#if 1
int main()
{
	int n;

	scanf("%d", &n);
	call(n);
	return 0;
}
#endif



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

using namespace std;

typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[a[i]] == i) ans++;
    }
    cout << ans / 2 << "\n";
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner a = new Scanner(System.in);
		String b = a.nextLine();
		byte c = Byte.parseByte(b);
		boolean e = false;
		for(byte d = 1;d < 10;d++) {
			if(c % d == 0 && (c / d) < 10) e = true;
		}
		if(e) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		a.close();
	}
}


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

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

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

const ll MAXN = 1000001;
bool P[1001];
bool S[MAXN];

template<typename T> T gcdraw(T a, T b) { return a ? gcdraw(b%a, a) : b; }
template<typename T> T gcd(T a, T b)
{
    const auto aa = abs(a), bb = abs(b);
    return aa > bb ? gcdraw(aa, bb) : gcdraw(bb, aa);
}

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

    vector<ll> A(N);
    rep (i, N) { cin >> A[i]; }

    vector<ll> PS = { 1, 2 };
    for (ll i=3;i*i<=MAXN;i+=2) if (!P[i])
    {
        for (ll j=2*i;j*j<=MAXN;j+=i) { P[j] = true; }
        PS.emplace_back(i);
    }

    const auto isPairwise = [&]()
    {
        for (const auto& a: A)
        for (const auto& p: PS)
        {
            if (a < p * p) { break; }

            if (a % p) { continue; }
            const auto q = a / p;

            if (p != 1 && S[p]) { return false; }
            if (q != 1 && S[q]) { return false; }

            S[p] = S[q] = true;
        }

        return true;
    };

    if (isPairwise())
    {
        cout << "pairwise coprime" << endl;
        return 0;
    }

    ll setwise = A[0];
    for (ll i=1;i<N;++i) { setwise = gcd(setwise, A[i]); }

    if (setwise == 1)
    {
        cout << "setwise coprime" << endl;
        return 0;
    }

    cout << "not coprime" << endl;
    return 0;
}


Measured memory_bytes: 11100
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int upper_division(int a,int b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lupper_division(long a,long b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lmax(long a,long b) {return Math.max(a, b);}
	static long lmin(long a,long b) {return Math.min(a, b);}
	static int[] setArray(int a) {
		int b[]=new int[a];
		for(int i=0;i<a;i++) {
			b[i]=scan.nextInt();
		}
		return b;
	}
	public static void main(String[] args) {
		String str=scan.next();
		int ans=1;
		String str1=String.valueOf(str.charAt(0));
		String str2="";
		for(int i=1;i<str.length();i++) {
			char ch=str.charAt(i);
			str2+=ch;
			if(!str1.equals(str2)) {
				str1=str2;
				str2="";
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 46892
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int64_t comb(int64_t N, int64_t R)
{
    if (R < 0 || R > N)
        return 0;
    if (R == 1)
        return N;
    else if (R == 2)
        return N * (N - 1) / 2;
    else
        return N * (N - 1) * (N - 2) / 6;
}

int64_t pow(int64_t N, int64_t k)
{
    int64_t res = 1;
    for (int i = 0; i < k; ++i)
        res *= N;
    return res;
}

int64_t solve(string& n, int i, int k, bool smaller)
{
    if (k == 0)
    {
        return 1;
    }
    if (i == n.size())
    {
        return 0;
    }

    if (smaller)
    {
        return comb(n.size() - i, k) * pow(9, k);
    }
    else
    {
        if (n[i] == '0')
        {
            return solve(n, i + 1, k, false);
        }
        else
        {
            auto zero = solve(n, i + 1, k, true);
            auto mid = solve(n, i + 1, k - 1, true) * (n[i] - '1');
            auto same = solve(n, i + 1, k - 1, false);
            return zero + mid + same;
        }
    }
}

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

    cout << solve(n, 0, k, false) << endl;
}


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


int main(){
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;

  vector<int> result(N);

  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      // 最短距離を計算
      int r1 = j - i;
      int r2 = abs(i-X) + abs(j-Y) + 1;
      int d = min(r1, r2);
      result[d]++;
    }
  }

  for(int i=1; i<N; i++){
    cout << result[i] << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
C = []
S = []
F = []
for _ in range(N-1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)
for i in range(N):
    if i == N - 1:
        print(0)
        break
    time = 0
    for j in range(i, N-1):
        if time < S[j]:
            time = S[j]
        if time % F[j] == 0:
            time += C[j]
        else:
            time += (F[j] - (time % F[j])) + C[j]
    print(time)


Measured memory_bytes: 9028
/**
    Sweet!
**/
#include <bits/stdc++.h>

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define pp pop_back()
#define ll long long
#define ld long double
#define OK puts("OK");
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;

inline int min(int a, int b) {
    return (a > b) ? b : a;
}

inline int max(int a, int b) {
    return (a > b) ? a : b;
}

const int N = 5e3 + 10;
const int inf = 1e9+10;
const ll linf = 1e18+9;

int n, s;
int a[N], k[N][N], k2[N];

int main() {
    scanf("%d%d", &n, &s);
    for(int i = 1; i <= n; i++)
        scanf("%d", a + i);
    sort(a + 1, a + n + 1);
    while(n > 0 && a[n] >= s) n --;

    if(!n) {puts("0");return 0;}

    k[n + 1][0] = 1;
    for(int i = n; i >= 1; i--)
        for(int j = 0; j <= s; j++){
            k[i][j] = k[i + 1][j];
            if(j >= a[i])
                k[i][j] |= k[i + 1][j - a[i]];
        }

    k2[0] = 1;

    for(int i = 1; i <= n; i++) {
        int l = 0, r = 0, c = 1;
        for(int j = s - 1; j >= 0; j--){
            while(l < max(0, s - a[i] - j))
                c -= k[i + 1][l], l ++;
            while(r < max(0, s - 1 - j))
                r ++, c += k[i + 1][r];
            if(!k2[j]) continue;
            if(c) {
                printf("%d\n", i - 1);
                return 0;
            }
        }
        for(int j = s; j >= a[i]; j --)
            k2[j] |= k2[j - a[i]];
    }
    printf("%d\n", n);
}


Measured memory_bytes: 98176
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<vector>

double getHypotenuse( double a , double b )
{
	return sqrt( pow(a , 2) + pow(b , 2) );
}

double getMin( double a , double b , double c )
{
	double min = a;
	if( b < min ){
		min = b;
	}
	if( c < min ){
		min = c;
	}
	return min;
}

int main(void)
{
	int x, y, z;

	while(1){
		std::cin >> x >> y >> z;
		if( x == 0 && y == 0 && z == 0 ){
			break;
		}
		double hypoXY = getHypotenuse( x , y );
		double hypoYZ = getHypotenuse( y , z );
		double hypoZX = getHypotenuse( z , x );

		double hypoMin = getMin( hypoXY , hypoYZ , hypoZX );

		int n;
		std::cin >> n;
		for( int i = 0 ; i < n ; i++ ){
			int radius;
			std::cin >> radius;
			std::cout << (hypoMin < 2 * radius ? "OK":"NA") << std::endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1152
fun main(args: Array<String>) = abc155c()
private inline fun printAnswer(function: StringBuilder.() -> StringBuilder) = print(StringBuilder().let(function))

fun abc155c() = printAnswer {
    val n = readLine()!!.toInt()
    val list = (1..n).map { readLine()!! }

    val map = list.groupBy { it }.map { it.key to it.value.size }
    val max = map.maxBy { it.second }!!.second

    val answer = map.filter { it.second == max }.map { it.first }.sorted().toTypedArray()

    for (a in answer) appendln(a)

    return@printAnswer this
}


Measured memory_bytes: 111604
#include<iostream>
using namespace std;
int N,S,A[3000];
const long mod=998244353;
long dp[6030];
main()
{
	cin>>N>>S;
	for(int i=0;i<N;i++)cin>>A[i];
	dp[0]=1;
	for(int i=0;i<N;i++)
	{
		for(int j=S;j>=0;j--)
		{
			(dp[j+A[i]]+=dp[j])%=mod;
			(dp[j]*=2)%=mod;
		}
	}
	cout<<dp[S]<<endl;
}


Measured memory_bytes: 3656
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
 
#define int long long
#define REP(i,n) for(int i=0;(i)<(n);(i)++)
#define ll long long
 
signed main() {
	int Q, H, S, D, N;
	cin >> Q >> H >> S >> D >> N;
	
	int min1 = min(min(Q * 4, H * 2), S);
	int min2 = min(min1 * 2, D);
 
	ll ans = N / 2 * min2 + (N % 2)*min1;
 
	cout << ans << endl;
	return 0;
}


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

int main() {
	int n;
	string s[200000];
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> s[i];
	sort(s, s + n);
	int m = 0, tm = 0;
	string ts("");
	for(int i = 0; i < n; i++) {
		if (s[i] != ts) {
			if (tm > m) m = tm;
			ts = s[i];
			tm = 1;
		} else {
			tm += 1;
		}
	}
	if (tm > m) m = tm;
	tm = 0;
	ts = "";
	for(int i = 0; i < n; i++) {
		if (s[i] != ts) {
			ts = s[i];
			tm = 1;
		} else {
			tm += 1;
		}
		if (tm == m) {
			cout << s[i] << endl;
		}
	}
}






Measured memory_bytes: 14208
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a[][] = new int[2][n];
    int ans = 0;

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

    for (int i = 0; i < n; i++) {
      int tmp = 0;
      for (int j = 0; j < (n - i); j++) {
        tmp += a[0][j];
      }
      for (int j = n - i - 1; j < n; j++) {
        tmp += a[1][j];
      }
      ans = Math.max(tmp, ans);
    }

    System.out.println(ans);

  }
}

Measured memory_bytes: 36056
#include <cstdio>

const int MN = 200005;

int N, K, A[MN], B[MN];

int main() {
	scanf("%d%d", &N, &K);
	for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
	while (K--) {
		for (int i = 1; i <= N; ++i) B[i] = 0;
		for (int i = 1; i <= N; ++i) {
			int l = i - A[i], r = i + A[i];
			l = l < 1 ? 1 : l;
			r = r > N ? N : r;
			++B[l], --B[r + 1];
		}
		for (int i = 1; i <= N; ++i) A[i] = A[i - 1] + B[i];
		int ok = 1;
		for (int i = 1; i <= N; ++i) if (A[i] != N) ok = 0;
		if (ok) break;
	}
	for (int i = 1; i <= N; ++i) printf("%d%c", A[i], " \n"[i == N]);
	return 0;
}

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


string s;



int main()
{
    cin >> s;
    for (int i = 0; i < s.size(); i+=2)
    if (s[i] == 'h' && s[i+1] == 'i')
    {

    }
    else
    {
        cout << "No";
        return 0;
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define M 1000000007
using namespace std;

int h,w;
char a[1001][1001];
long long dp[1001][1001];

long long fun(int i,int j){
    if(i>=h || j>=w){
        return 0;
    }
    if(i==h-1 && j==w-1){
        return 1;
    }
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    if(a[i+1][j]=='#' && a[i][j+1]=='#'){
        return dp[i][j] = 0;
    }
    else if(a[i+1][j]=='#'){
        return dp[i][j] = fun(i,j+1);
    }
    else if(a[i][j+1]=='#'){
        return dp[i][j] = fun(i+1,j);
    }
    else{
        return dp[i][j] = (fun(i+1,j)%M+fun(i,j+1)%M)%M;
    }
}

int main(){
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
        }
    }
    memset(dp,-1,sizeof(dp));
    cout<<fun(0,0)<<endl;
    return 0;
}

Measured memory_bytes: 9088
package main

import "fmt"

func main() {
	var resultX, resultY [100]float32
	var count int
	for {
		var a, b, c, d, e, f, x, y float32
		fmt.Scanf("%f %f %f %f %f %f", &a, &b, &c, &d, &e, &f)
		if a == 0 {
			break
		}
		//Simultaneous equation
		y = (((a * f) - (d * c)) / ((a * e) - (b * d)))
		x = ((c - (b * y)) / a)
		resultX[count] = x
		resultY[count] = y
		count++
	}
	for i := 0; i < count; i++ {
		fmt.Printf("%.3f %.3f\n", resultX[i], resultY[i])
	}
}


Measured memory_bytes: 1128
/*  HARD WORK FOREVER PAYS  */
#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define turbo(){	\
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL); \
}
using namespace std;
typedef long long ll;
typedef pair<int,int> PII; 
int main() 
{ 
	turbo();
	int j,i,n,l;
	cin>>n;
	vector<char> v;
	string s[n];
	for(i=0;i<n;i++){
		cin>>s[i];
	}
	for(i=0;i<s[0].size();i++){
		int cnt=1;
		char c=s[0][i];
		for(j=1;j<n;j++){
			for(l=0;l<s[j].size();l++){
				if(s[j][l]==c){
					cnt++;
					s[j][l]='0';
					break;
				}
			}
		}
		if(cnt==n){
			v.pb(c);
		}
	}
	sort(v.begin(),v.end());
	for(i=0;i<v.size();i++){
		cout<<v[i];
	}
	cout<<"\n";
	return 0; 
} 

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

int main()
{
	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(a.begin(), a.end());
	a.erase(unique(a.begin(), a.end()), a.end());
	cout << a.size() << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
xy = []
for i in range(N):
    xy.append(list(map(int,input().split())))

from itertools import permutations
a=range(1,N+1)
ps = list(permutations(a))
#print(ps)

dammy=0
for p in ps:
    #print('p:',p)
    for j in range(1,N):
        dammy += ((xy[p[j-1]-1][0] - xy[p[j]-1][0])**2 + (xy[p[j-1]-1][1] - xy[p[j]-1][1])**2) ** (1/2)
        #print(dammy)
print(dammy/len(ps))



Measured memory_bytes: 80892
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
#define N 1000000
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
int a[N],b[N],c[N]; ll s[N];
int main()
{	int n,t=0; ll s1=0,s2=0,ans; cin>>n;
	for(rint i=1;i<=n;i++)
	scanf("%d%d",&a[i],&b[i]),c[++t]=a[i],c[++t]=b[i],s1+=a[i],s2+=b[i];
	ans=min(s1,s2); sort(c+1,c+t+1);
	for(rint i=1;i<=n;s[i]=s[i-1]+c[i],i++)
	a[i]=lower_bound(c+1,c+t+1,a[i])-c,b[i]=lower_bound(c+1,c+t+1,b[i])-c;
	for(rint i=1;i<=n;i++)
	{	if(a[i]>b[i]) swap(a[i],b[i]);
		if(a[i]<=n-2&&b[i]<=n-1) ans=min(ans,s[n]);
		else if(a[i]<=n-1) ans=min(ans,c[b[i]]+s[n-1]);
		else ans=min(ans,c[a[i]]+c[b[i]]+s[n-2]);
	}
	cout<<ans;
	return 0;
}


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

int main() {
  int n;
  cin>>n;
  vector<string>a(n);
  map<string,int>memo;
  string s="Yes";
  char c;
  cin>>a[0];
  memo[a[0]]++;
  c=a[0].at(a[0].size()-1);
  rep2(i,1,n) {
    cin>>a[i];
    if(memo[a[i]]!=0){
      s="No";
    }
    memo[a[i]]++;
    if(c!=a[i].at(0)){
      s="No";
    }
    c=a[i].at(a[i].size()-1);
  }
  cout<<s<<endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

const ll MOD = 1000000007;

ll n;
string s1, s2;
bool f[100];

int main(int argc, char **argv) {
	cin >> n >> s1 >> s2;
	int m = 0;
	REP(i, n) {
		f[m] = (s1[i] == s2[i]);
		if (!f[m]) ++i;
		++m;
	}
	ll res = f[0] ? 3 : 6;
	FOR(i, 1, m) {
		if (f[i] && f[i - 1]) res = res * 2 % MOD;
		if (!f[i] && f[i - 1]) res = res * 2 % MOD;
		if (!f[i] && !f[i - 1]) res = res * 3 % MOD;
	}
	cout << res << 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);
        int n = sc.nextInt();
        sc.nextLine();
        double ans = 0;
        for(int i = 0;i<n;i++){
            double x = sc.nextDouble();
            String s = sc.nextLine();
            if(s.equals(" JPY")){
                ans += x;
            }else{
                ans += (x*380000);
            }
        }

        System.out.format("%.4f",ans);
    }
}

Measured memory_bytes: 24660
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()

def main():
  A, B, C, K = map(int, input().split())

  if A >= K:
    print(K)
    return
  elif (A + B) >= K:
    print(A)
    return
  else:
    print(A-(K-B-A))

if __name__ == '__main__':
  main()

Measured memory_bytes: 9184
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int insertionSort(int *, int, int);
void shellSort(int *, int);

int main() {
	int n;
	scanf("%d", &n);
	int *A = (int *)malloc(n * sizeof(int));
	for (int i = 0; i < n; i++) scanf("%d", &A[i]);

	shellSort(A, n);
	return 0;
}

int insertionSort(int *a, int max, int g) {
	int i, j;
	int count = 0;
	for (i = g; i < max; i++) {
		int key = a[i];
		for (j = i - g; j >= 0 && a[j] > key; count++) {
			a[j + g] = a[j];
			j -= g;
		}
		a[j + g] = key;
	}
	return count;
}

void shellSort(int *a, int max) {
	int count = 0, m = 0;
	int i;
	int *g = (int *)malloc(max * sizeof(int));

	int denom = 2;
	if (max == 1) {
		g[m] = max;
		m++;
	}
	else {
		while (max / denom > 0) {
			g[m] = max / denom;
			denom *= 2;
			m++;
		}
	}

	for (i = 0; i < m; i++) {
		count += insertionSort(a, max, g[i]);
	}

	printf("%d\n", m);
	
	for (i = 0; i < m - 1; i++) printf("%d ", g[i]);
	printf("%d\n", g[i]);
	
	printf("%d\n", count);
	
	for (i = 0; i < max - 1; i++) printf("%d ", a[i]);
	printf("%d\n", a[i]);
}



Measured memory_bytes: 5640
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

string s;
ll cnt;
int main(){
    cin>>s;
    
    REP(i, 0, s.size()){
        if(s[i]=='2') cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int main() {
    int x[3];

    for(int i = 0; i < 3; i++) {
        scanf("%d", &x[i]);
    }
    
    if((x[0] + x[1] == x[2]) || (x[1] + x[2] == x[0]) || (x[0] + x[2] == x[1])) {
        printf("Yes");
    } else {
        printf("No");
    }

    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

void OutputError(std::string s) {
  cerr << "\033[93m" << s << "\033[m" << endl;
  return;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int cum = 0, max = 0;
  for (int i = 0; i < n; i++) {
    int m1;
    cin >> m1;
    cum += m1;
    max = std::max(max, m1);
  }
  cum -= max;
  if (cum > max) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    s = list(input())
    t = list(input())

    cnt = 0
    for i in range(N):
        stmp = s[N-i-1:]
        ttmp = t[:i+1]
        if stmp == ttmp:
            cnt = i+1
        
    ans = 2*N - cnt
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func main() {
	ins := strings.Split(readLine(), " ")

	n, _ := strconv.Atoi(ins[0])
	l, _ := strconv.Atoi(ins[1])

	var a []int

	for i := 1; i <= n; i++ {
		a = append(a, l+i-1)
	}

	min := 10000
	for _, v := range a {
		if math.Abs(float64(min)) > math.Abs(float64(v)) {
			min = v
		}
	}

	var sum int

	for _, v := range a {
		sum += v
	}

	fmt.Println(sum - min)

}


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

namespace AtCoder.Question
{
    public class QuestionD
    {
        public static void Main(string[] args)
        {
            var n = ReadValue<long>();
            var primes = EnumeratePrimes(n).ToArray();
            var soinsuCount = new Dictionary<long, long>();

            foreach (var prime in primes)
            {
                if (!soinsuCount.ContainsKey(prime))
                {
                    soinsuCount.Add(prime, 0);
                }
                soinsuCount[prime]++;
            }

            var ans = 0L;

            foreach (var kv in soinsuCount)
            {
                ans += (long)Math.Floor(-0.5 + (Math.Sqrt(1 + 8 * kv.Value) / 2));
            }
            Console.WriteLine(ans);
        }

        static T ReadValue<T>()
        {
            return (T)Convert.ChangeType(Console.ReadLine(), typeof(T));
        }
        static (T1, T2) ReadValue<T1, T2>()
        {
            var input = Console.ReadLine().Split(' ');
            return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)));
        }
        static (T1, T2, T3) ReadValue<T1, T2, T3>()
        {
            var input = Console.ReadLine().Split(' ');
            return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)));
        }
        static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>()
        {
            var input = Console.ReadLine().Split(' ');
            return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)), (T4)Convert.ChangeType(input[3], typeof(T4)));
        }
        static T[] ReadValues<T>()
        {
            var input = Console.ReadLine().Split(' ');
            return input.Select(x => (T)Convert.ChangeType(x, typeof(T))).ToArray();
        }
        static bool IsPrime(long n)
        {
            if (n == 2) return true;
            if (n < 2 || n % 2 == 0) return false;
            var sqrt = Math.Sqrt(n);
            for (int i = 3; i <= sqrt; i += 2) if (n % i == 0) return false;
            return true;
        }
        static IEnumerable<long> EnumeratePrimes(long n)
        {
            var i = 2L;
            var tmp = n;
            while (i * i <= tmp)
            {
                if (tmp % i == 0)
                {
                    tmp /= i;
                    yield return i;
                }
                else
                {
                    if (i > 2) i++;
                    i++;
                }
            }
            if (tmp != 1) yield return tmp;
        }
    }
}


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

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

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

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

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

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

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

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

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

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<vector<ll>> F(N, vector<ll>(10));
    vector<vector<ll>> P(N, vector<ll>(11));

    REP(i, N){
        REP(j, 10){
            cin >> F[i][j];
        }
    }

    REP(i, N){
        REP(j, 11){
            cin >> P[i][j];
        }
    }

    // ll n = N;
    ll n = 10;
    ll ans = -1*INF;
    for (ll bit = 0; bit < (1<<n); ++bit){
        // cout << bit << endl;
        if(bit == 0) continue;
        vector<ll> C(N, 0);
        // bool flag = true;
        for (ll i = 0; i < n; ++i) {
            // 午前も午後も営業しないパターンは除外
            // if(i%2 == 1){
            //     if((bit & (1<<i)) || (bit & (1<<(i-1)))){
                    
            //     }
            //     else{
            //         flag = false;
            //         // break;
            //     }
            // }

            if (bit & (1<<i)){
                REP(j, N){
                    C[j] += F[j][i];
                }
            }
        }
        ll temp = 0;
        // cout << C[0] << endl;
        REP(j, N){
            temp += P[j][C[j]];
        }

        // if(flag){
            // cout << bit << endl;
        ans = max(ans, temp);
        // }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mr make_pair
#define N 100010
#define INF 1e18
using namespace std;
vector<pair<int,int> > a[N];
int m,n,x,y,z;
struct seg{int l,r;ll ta;}t[N*4];
void build(int nu,int l,int r){
	t[nu].l=l;t[nu].r=r;
	if (l==r){if (l==1)t[nu].ta=0;else t[nu].ta=INF;}
	else{
		t[nu].ta=-1;build(nu*2,l,(l+r)/2);build(nu*2+1,(l+r)/2+1,r);
	}
}
void ya(int nu){
	if (t[nu].l==t[nu].r||t[nu].ta==-1) return ;
	t[nu*2].ta=t[nu].ta;t[nu*2+1].ta=t[nu].ta;
	t[nu].ta=-1;return ;
}
ll que(int nu,int x){
	ya(nu);
	if (t[nu].l==t[nu].r) return t[nu].ta;
	if (x<=(t[nu].l+t[nu].r)/2) return que(nu*2,x);else return que(nu*2+1,x);
}
void fu(int nu,int l,int r,ll x){
	ya(nu);
	if (t[nu].l==l&&t[nu].r==r){t[nu].ta=x;return ;}
	int mid=(t[nu].l+t[nu].r)/2;
	if (l<=mid) fu(nu*2,l,min(mid,r),x);
	if (r>mid) fu(nu*2+1,max(mid+1,l),r,x);
}
int main(){
	cin>>n>>m;
	for (int i=1;i<=m;i++){cin>>x>>y>>z;a[x].pb(mr(y,z));}
	build(1,1,n);
	for (int i=1;i<=n;i++){
		ll no=que(1,i);
		for (auto k:a[i]){
			ll y=que(1,k.first);
			if (y>no+k.second){
				int l=i+1,r=k.first,mid;
				while (l<r){
					mid=(l+r)/2;
					if (que(1,mid)>no+k.second) r=mid;else l=mid+1;
				}
				fu(1,l,k.first,no+k.second);
			}
		}
	}
	if (que(1,n)==INF)puts("-1");else cout<<que(1,n)<<endl;
	return 0;
}

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

h, w = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(h)]
direction = 1
x, y = 0, 0


def forward(a, b):
    if direction > 0:
        if b != w-1:
            return [a, b+1, False]
        else:
            return [a+1, b, True]
    elif direction < 0:
        if b != 0:
            return [a, b-1, False]
        else:
            return [a+1, b, True]


count = 0
ans = []
# xとy問題文と逆だけど許して
while x < h and y < w:
    if A[x][y] % 2 == 0:
        x, y, turn = forward(x, y)
        if turn:
            direction *= -1
    else:
        if forward(x, y)[0] < h and forward(x, y)[1] < w:
            ans.append([x+1, y+1, forward(x, y)[0]+1, forward(x, y)[1]+1])
            count += 1
            x, y, turn = forward(x, y)
            A[x][y] += 1
            if turn:
                direction *= -1
        else:
            break

print(count)
for line in ans:
    print(' '.join(map(str, line)))


Measured memory_bytes: 30520
(n, m) = tuple(map(int, input().split()))
(a, b) = zip(*list([input().split() for _ in range(m)]))

pt_c_ns = {}
for i in range(1, n + 1):
    pt_c_ns[str(i)] = []
for i in range(m):
    pt_c_ns[a[i]].append(b[i])
    pt_c_ns[b[i]].append(a[i])

paths_c = ["1"]
for _ in range(n - 1):
    paths_n = []
    for path in paths_c:
        pt_c = path[-1]
        pt_ns = pt_c_ns[pt_c]
        for pt_n in pt_ns:
            if pt_n not in path:
                paths_n.append(path + pt_n)
    paths_c = paths_n[:]

print(len(paths_c))


Measured memory_bytes: 9460
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
using namespace std;

vector<int> bs[1000];
vector<int> cs[1000];
int dis[1000];
int N, M;

signed main()
{
	cin >> N >> M;
	for (int i = 0; i < M; i++)
	{
		int aa, bb, cc;
		cin >> aa >> bb >> cc;
		aa--;
		bb--;
		bs[aa].push_back(bb);
		cs[aa].push_back(cc);
	}

	for (int i = 0; i < N; i++)
	{
		dis[i] = -10000000000000;
	}

	dis[0] = 0;
	int prev = 0;
	for (int l = 0; l <= N; l++)
	{
		for (int i = 0; i < N; i++)
		{
			for (int k = 0; k < bs[i].size(); k++)
			{
				int b = bs[i][k];
				int c = cs[i][k];
				int len = dis[i] + c;
				if (dis[b] < len)
				{
					dis[b] = len;
				}
			}
		}
		if (l == N - 1)
		{
			prev = dis[N - 1];
		}
	}
	int ans = dis[N - 1];

	if (ans > prev)
		cout << "inf" << endl;
	else
		cout << ans << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

int main(){
  char a[2000000];
  char b[2000000];
  long counter = 0;

  scanf("%s", a);
  scanf("%s", b);
  for(long i = 0; i < strlen(a); i++){
    if(a[i] != b[i])
      counter++;
  }
  printf("%ld", counter);
  return 0;
}


Measured memory_bytes: 2524
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int n; cin >> n;
    vector<pair<int, P>> a(n);
    rep(i, n) {
        int x, y; cin >> x >> y;
        a[i] = {i, {x, y}};
    }
    sort(all(a), [] (pair<int, P> &x, pair<int, P> &y) {
        return x.se.fi + x.se.se > y.se.fi + y.se.se;
    });
    ll taka = 0, aoki = 0;
    rep(i, n) {
        if (i%2==0) {
            taka += a[i].se.fi;
        } else {
            aoki += a[i].se.se;
        }
    }
    cout << taka - aoki << endl;
}

Measured memory_bytes: 1408
#include<stdio.h>

int main()
{
	int n;
	scanf("%d",&n);
	
	int AC=0;
	int WA=0;
	int TLE=0;
	int RE=0;
	char S[105];
	
	while(n--)
	{
	scanf("%s", S);
		
		if(S[0]=='A')
		{
			AC++;
		}
		
		else if (S[0]=='W')
		{
			WA++;
		}
		
		else if (S[0]=='T')
		{
			TLE++;
		}
		
		else if (S[0]=='R')
		{
			RE++;
		}
	}
	
	printf("AC x %d\n", AC);
	printf("WA x %d\n", WA);
	printf("TLE x %d\n", TLE);
	printf("RE x %d\n", RE);
	
	return 0;
}

Measured memory_bytes: 1704
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int a,b;
  cin >> a >> b;
  cout << a * b << endl;
  return 0;
}

Measured memory_bytes: 3636