akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000009
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
typedef long long ll;
typedef unsigned long long ull;

inline int scan() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
inline void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}
using namespace std;
const int maxn = 200005;
int a[maxn], b[maxn];
int main()
{
    int n;
    cin >> n;
    ll sum = 0;
    int mins = INF;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i] >> b[i];
        sum += a[i];
        if(a[i] > b[i])mins = min(mins, b[i]);
    }
    if(mins == INF)cout << 0 << endl;
    else cout << sum -mins << endl;
    return 0;
}
/*
                 ___====-_  _-====___
           _--^^^#####//      \\#####^^^--_
        _-^##########// (    ) \\##########^-_
       -############//  |\^^/|  \\############-
     _/############//   (@::@)   \\############\_
    /#############((     \\//     ))#############\
   -###############\\    (oo)    //###############-
  -#################\\  / VV \  //#################-
 -###################\\/      \//###################-
_#/|##########/\######(   /\   )######/\##########|\#_
|/ |#/\#/\#/\/  \#/\##\  |  |  /##/\#/  \/\#/\#/\#| \|
`  |/  V  V  `   V  \#\| |  | |/#/  V   '  V  V  \|  '
   `   `  `      `   / | |  | | \   '      '  '   '
                    (  | |  | |  )
                   __\ | |  | | /__
                  (vvv(VVV)(VVV)vvv)
                  ÁúÉñ±£ÓÓ ÓÀÎÞbug
*/


Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
#include<cassert>

using namespace std;

#define N 4
#define N2 16
#define LIMIT 100

static const int dx[4]={0,-1,0,1};
static const int dy[4]={1,0,-1,0};
static const char dir[4]={'r','u','l','d'};

int MDT[N2][N2];

struct Puzzle
{
  int f[N2];
  int space;
  int MD;
};

Puzzle state;
int limit;
int path[LIMIT];

int getAllMD(Puzzle pz);
bool isSolved();
bool dfs(int depth,int prev);
string iterative_deepening(Puzzle in);

int main(void)
{
  for(int i=0;i<N2;i++)
    {
      for(int j=0;j<N2;j++)
	{
	  MDT[i][j]=abs(i/N-j/N)+abs(i%N-j%N);
	}
    }
    
  Puzzle in;
    
  for(int i=0;i<N2;i++)
    {
      cin>>in.f[i];
      if(in.f[i]==0)
	{
	  in.f[i]=N2;
	  in.space=i;
        }
    }
    
  string ans=iterative_deepening(in);
    
  cout<<ans.size()<<endl;
    
  return 0;
}

int getAllMD(Puzzle pz)
{
  int sum=0;
  for(int i=0;i<N2;i++)
    {
      if(pz.f[i]==N2)
	{
	  continue;
	}
	
      sum+=MDT[i][pz.f[i]-1];
    }
    
  return sum;
}

bool isSolved()
{
  for(int i=0;i<N2;i++)
    {
      if(state.f[i]!=i+1)
	{
	  return false;
	}
    }
    
  return true;
}

bool dfs(int depth,int prev)
{
  if(state.MD==0)
    {
      return true;
    }
    
  if(depth+state.MD>limit)
    {
      return false;
    }
    
  int sx=state.space/N;
  int sy=state.space%N;
    
  Puzzle tmp;
    
  for(int r=0;r<4;r++)
    {
      int tx=sx+dx[r];
      int ty=sy+dy[r];
	
      if(tx<0||ty<0||tx>=N||ty>=N)
	{
	  continue;
	}
	
      if(max(prev,r)-min(prev,r)==2)
	{
	  continue;
	}
	
      tmp=state;
	
      state.MD-=MDT[tx*N+ty][state.f[tx*N+ty]-1];
      state.MD+=MDT[sx*N+sy][state.f[tx*N+ty]-1];
	
      swap(state.f[tx*N+ty],state.f[sx*N+sy]);
	
      state.space=tx*N+ty;
	
      if(dfs(depth+1,r))
	{
	  path[depth]=r;
	  return true;
	}
	
      state = tmp;
    }
    
  return false;
}

string iterative_deepening(Puzzle in)
{
  in.MD=getAllMD(in);
    
  for(limit=in.MD;limit<=LIMIT;limit++)
    {
      state=in;
      if(dfs(0,-100))
	{
	  string ans="";
	    
	  for(int i=0;i<limit;i++)
	    {
	      ans += dir[path[i]];
	    }
	    
	  return ans;
        }
    }
    
  return "unsolvable";
}



Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
using namespace std;
typedef pair<int,int>pii;
int n,a,b;
int main(){
	cin>>n>>a>>b;
	cout<<min(n,min(a,b))<<' '<<max(0,a+b-n)<<endl;
	return 0;
}


Measured memory_bytes: 764
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int n,a[100010],i;
long long b,c,mmax;
int main(){
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    sort(a,a+n);
    for(i=n-1;i>=0;i--)
        if(a[i]==a[i-1]){
            b=c;
            c=a[i];
            if(b*c>mmax) mmax=b*c;
            i--;
        }
    printf("%lld\n",mmax);
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<String> week = Arrays.asList("SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT");
        System.out.println(7 - week.indexOf(sc.next()));
    }
}

Measured memory_bytes: 21844
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

const ll mod=1e9+7;


int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    ll sum=0;
    rep(i,n){
        cin >> a[i];
        sum+=a[i];
    }
    vector<ll> p;
    for(ll i=1;i*i<=sum;i++){
        if(sum%i==0){
            if(i*i==sum){
                p.push_back(i);
            }
            else{
                p.push_back(i);
                p.push_back(sum/i);
            }
        }
    }
    ll ans=0;
    for(ll x:p){
        ll tot=0;
        ll cnt=0;
        vector<ll> r;
        rep(i,n){
            ll s=a[i]%x;
            ll t=x-(a[i]%x);
            tot+=min(s,t);
            if(s<t){
                cnt+=(a[i]/x)*x;
                r.push_back(s);
            }
            else{
                cnt+=(a[i]/x+1)*x;
                r.push_back(-t);
            }
        }
        sort(r.begin(),r.end());
        if(cnt>sum){
            ll times=(cnt-sum)/x;
            rep(j,times){
                tot-=abs(r[j]);
                tot+=x-abs(r[j]);
            }
        }
        if(cnt<sum){
            ll times=(sum-cnt)/x;
            rep(j,times){
                tot-=abs(r[n-1-j]);
                tot+=x-abs(r[n-1-j]);
            }
        }
        if(tot<=2*k) ans=max(ans,x);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
S = input()
N = len(S)

s = list()
for i in range(N):
    if S[i] == "A" or S[i] == "T" or S[i] == "G" or S[i] == "C":
        s.append(1)
    else:
        s.append(0)
#print(s)

lz = list()
cnt = 0
for i in range(N):
    if s[i] == 1:
        if cnt == 0:
            cnt = 1
        else:
            cnt += 1
    else:
        lz.append(cnt)
        cnt = 0
lz.append(cnt)
print(max(lz))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;
typedef pair<lint,lint> P;

int main()
{

    int N;
    cin >> N;

    lint a,b;
    vector<P> ba;

    REP(i,N){
    	cin >> a >> b;
    	ba.push_back(P(b,a));
    }

    sort(ALL(ba));


    string ans="Yes";

    lint time=0;
    REP(i,N){
    	time+=ba[i].second;
    	if(time>ba[i].first){
    		ans="No";
    		break;
    	}
    }


    cout << ans << endl;



}


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

int main()
{
    int N,M;
    cin>>N; cin>>M;
    vector<vector<int>> info(N+1);

    int a, b;
    rep(i,M)
    {
        cin>>a; cin>>b;
        info.at(a).push_back(b);
        info.at(b).push_back(a);
    }

    vector<int> ls(N+1, 0);
    for (int i=1; i<N+1; i++)
    {
        if (ls.at(i)==0)
            ls.at(i)=i;
        
        vector<int> &i_info=info.at(i);
        while (!i_info.empty())
        {
            int fr=i_info.back();
            i_info.pop_back();
            if (fr==i) continue;
            ls.at(fr)=i;
            i_info.insert(i_info.end(), info.at(fr).begin(), info.at(fr).end());
            info.at(fr).clear();
        } 
    }

    vector<int> ans(N+1);
    for (const auto &e: ls)
        ans.at(e)++;

    std::cout << *std::max_element(++ans.begin(), ans.end());
}

Measured memory_bytes: 16892
my $s =<>;
chomp $s;
my ($N,$A,$B) = split(/ /,$s);

my $mod = $N %($A+$B);
my $c = ($N -$mod)/($A+$B);
my $ans = 0;
if( $mod >$A ){
    $ans = $A * ($c +1);
}else{
    $ans = $A * $c + $mod;
}
print "$ans";

Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>

using namespace std;


int main(){
  string s;
  cin >> s;
  int p = 700;
  for(int i =0;i<3;i++){
    if(s[i] == 'o'){
      p+=100;
    }
  }


cout << p <<endl;

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    using lint = long long;
     
    signed main(){
    	lint n; cin >> n;
    	vector<lint> a(n);
    	for(lint i = 0; i < n; i++) cin >> a[i];
    	lint ans1 = 0, ans2 = 0, sum1 = 0,sum2 = 0;
    	for(lint i = 0; i < n; i++){
    		sum1 += a[i];
    		if(i % 2 == 0 && sum1 <= 0) ans1 += (1 - sum1), sum1 = 1;
    		if(i % 2 == 1 && sum1 >= 0) ans1 += (sum1 + 1), sum1 = -1;  
    	}
    	for(lint i = 0; i < n; i++){
    		sum2 += a[i];
    		if(i % 2 == 1 && sum2 <= 0) ans2 += (1 - sum2), sum2 = 1;
    		if(i % 2 == 0 && sum2 >= 0) ans2 += (sum2 + 1), sum2 = -1;  
    	}
    	cout << min(ans1, ans2) << endl;
    }
    	

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll n, k;
    cin >> n >> k;
    vector<bool> judge(n);
    rep(i, k) {
        ll d;
        cin >> d;
        rep(j, d) {
            ll a;
            cin >> a;
            a--;
            judge[a] = true;
        }
    }
    ll ans = 0;
    rep(i, n) {
        if (!judge[i]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3628
import bisect
import collections
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


#
N, M, Q = lmi()
#
ABDC = llmi(Q)


def gen(arr=tuple()):
    score = 0
    if len(arr) == N:
        for a, b, c, d in ABDC:
            if arr[b - 1] - arr[a - 1] == c:
                score += d
        return score
    start = 0 if not arr else arr[-1]
    for i in range(start, M):
        score = max(score, gen(arr + (i,)))
    return score


print(gen())
#
# dp = [[-INF]*M for i in range(N+1)]
#
# for n in range(N):
#     for v in range(M):
#         # target: dp[n+1][v]


Measured memory_bytes: 71732
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int main()
{
    int A, B;
    cin >> A >> B;
    if (B % A == 0)
    {
        cout << A + B << endl;
    }
    else
    {
        cout << B - A << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int a,b,c;
  cin>>a>>b>>c;
  int ans=0;

  ans=c-(a-b);
  if(ans<0){
    cout<<0<<endl;
  }else{
  cout<<ans<<endl;
  }
}

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

const long long INF = (1LL<<60);
const int MAX_NUM = 100000;

int N, K;
int h[MAX_NUM];

// dp[i] := インデックスi(0起算)の足場までの最小コスト
long long dp[MAX_NUM];

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

	dp[0] = 0;

	for ( int i = 0; i < N; ++i ) {
		long long res = INF;
		for ( int j = 0; j < K && j <= i; ++j ) {
			res = ::min( res,
						 dp[i - j] + ::abs( h[i + 1] - h[i - j] ) );
		}
		dp[i + 1] = res;
	}

	cout << dp[N - 1] << endl;
	return 0;
}

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

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

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

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

    int ans = 0, mn = MOD;
    for(int i=0;i<n;i++)
    {
        if( a[i] <= mn )
            ans++;
        mn = min( mn, a[i] );
    }
    cout<<ans,nl;

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

#define MAX 100
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];

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

  for(i=0;i<n;i++){ 
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      M[u][v]=c;
    }
  }
  dijkstra(); 

  return 0;
}
 
void dijkstra(){
  int i,j,u,v,p,minv;
  int d[MAX],color[MAX];
 
  for(i=0;i<n;i++){ 
    d[i]=INFTY;
    color[i]=WHITE;
  }
 
  d[0]=0;
color[0]=GRAY;

  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i] && color[i]!=BLACK){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1){
      break;
    }
    color[u]=BLACK;
    for(v=0;v<n;v++){ 
      if(M[u][v]!=INFTY && color[v]!=BLACK){
	if(d[v]>d[u]+M[u][v]){
	  d[v]=d[u]+M[u][v];
	  color[v]=GRAY;
	}
      }
    }
  }
  for(i=0;i<n;i++){ 
    printf("%d %d\n",i,(d[i]==INFTY?-1:d[i]));
  }
}

Measured memory_bytes: 636
#include <iostream>

using namespace std;
static const int MOD = 1e9 + 7;


//modの逆元、つまり
//a/b ≡ a*(b') (mod p)となるようなb'を求める
//拡張Euclid互除法
long long modinv(long long a, long long m) {
  long long b = m;
  long long u = 1;
  long long v = 0;

  while (b){
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) {
    u += m;
  }
  return u;
}
long long comb(int n, int k){
  long long c = 1; //denominator
  long long d = 1;//numerator

  for (int i = 0; i < k; i++) {
    c = (c * (n-i)) % MOD;
    d = (d * (k-i)) % MOD;
    //逆元

    //cout << (n-i) << " " << (k-i) << endl;
  }
  //これだとダメだった
  //理由: modしたものの割り算は計算できない
  //return c/d;
  return (c * modinv(d, MOD)) % MOD;
}

int main() {

  int k, n;
  cin >> n >> k;
  long long cnt;

  for (int i = 0; i < k; i++) {
    cnt = (comb(k-1, i) * comb(n-k+1, i+1)) % MOD;
    cout << cnt << endl;
  }
  return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    int a[100];
    int b[100][100];
    int snuke[n] = {};
    int ans = 0;
    for(int i=0; i<k; i++){
        cin>>a[i];
        for(int j=0; j<a[i]; j++){
            cin>>b[i][j];
            if(!snuke[b[i][j]-1]){
                snuke[b[i][j]-1]++;
                ans++;
            }
        }
    }
    cout<<n-ans;
    return 0;
}


Measured memory_bytes: 3648
n = int(input())

ans = [0] * n

for x in range(1, 101):
    for y in range(1,101):
        for z in range(1,101):
            X = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if X <= n:
                ans[X-1] += 1

for ansi in ans:
    print(ansi)

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


public static class P
{
    static void Main()
    {
        var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nm[0];
        var m = nm[1];
        int[] switches = Enumerable.Repeat(0, m).Select(_ =>
             Console.ReadLine().Split().Select(int.Parse).Skip(1).Aggregate(0, (x, y) => x | (1 << (y - 1)))
        ).ToArray();
        int[] mod = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var res = 0;
        for (int i = 0; i < (1 << n); i++)
        {
            for (int j = 0; j < switches.Length; j++)
            {
                if ((PopCount(switches[j] & i) & 1) != mod[j]) goto end;
            }
            res++;
            end:;
        }
        Console.WriteLine(res);
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    static int PopCount(int n)
    {
        int msb = 0;
        if (n < 0) { n &= int.MaxValue; msb = 1; }
        n = n - ((n >> 1) & 0x55555555);
        n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
        return (int)(((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24) + msb;
    }
}


Measured memory_bytes: 13396
import sys
input=sys.stdin.readline

def f(s):
    i = 0
    n = 0
    while i < len(s)-1:
        if s[i] == s[i+1]:
            n += 1
            i += 2
        else:
            i += 1
    return n

def main():
    S = input().strip()
    K = int(input())
    a1 = f(S)
    a2 = f(S*2)
    a3 = f(S*3)
    if K == 1:
        print(a1)
        return
    if K == 2:
        print(a2)
        return

    r1 = a2 - a1
    r2 = a3 - a2
    ans = a1 + r1 * (K//2) + r2 * ((K-1)//2)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b,int m) {
    if (b==0) return 1;
    ll c = power(a,b>>1,m);
    c = (c*c)%m;
    if (b&1) return (c*a)%m;
    return c;
}
ll powerwithoutmod(ll a,ll b) {
    if (b==0) return 1;
    ll c = powerwithoutmod(a,b>>1);
    c = (c*c);
    if (b&1) return (c*a);
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int Q = 301;
const int logN = 16;

unordered_map<int,int> row, col, d1, d2;
int a[11][11];
void solve() {
    int n=3,b,m;
    REP(i,1,n) {
        REP(j,1,n) {
            cin>>a[i][j];
        }
    }
    cin>>m;
    REP(i,1,m) {
        cin>>b;
        REP(i,1,n) {
            REP(j,1,n) {
                if (a[i][j]==b) {
                    a[i][j] = -1;
                    row[i]++;
                    col[j]++;
                    d1[i-j]++;
                    d2[i+j]++;
                }
            }
        }
    }
    for (auto it:row) {
        if (it.second > 2) {
            cout<<"Yes";
            return;
        }
    }
    for (auto it:col) {
        if (it.second > 2) {
            cout<<"Yes";
            return;
        }
    }
    for (auto it:d1) {
        if (it.second > 2) {
            cout<<"Yes";
            return;
        }
    }
    for (auto it:d2) {
        if (it.second > 2) {
            cout<<"Yes";
            return;
        }
    }
    cout<<"No";
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>

using namespace std;

int main(){
	int n, a, b, c, d;
	int ans;
	cin >> n >> a >> b >> c >> d;
	for (int i = 0;i<=n; i++){
		if (i*a >= n){
			ans = i*b;
			break;
		}
	}
	for (int j = 0; j <= n; j++){
		if (j*c >= n){
			if (ans > j*d){
				ans = j*d;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3116
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int a[200005];
int main(){
	int n,i;
	
	vector<int> b; 
	cin>>n;
	
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	b.push_back(a[0]);
	for(i=1;i<n;i++){
		if(a[i]!=b[i-1]){
			b.push_back(a[i]);
		}
		else{
			break;
		}
	}

	if(b.size()==n)cout<<"YES";
	else cout<<"NO";
	
	return 0;
}

Measured memory_bytes: 2168
fun main(args: Array<String>) {
	var cntFive: Int = 0
	var cntSeven: Int = 0
  	val num = readLine()!!.split(" ").map(String::toInt)
	
  	for (i in 0..2) {
      if (num[i] == 5) {
       	cntFive += 1 
      } else if (num[i] == 7) {
       	cntSeven += 1
      }
    }
  
  	if (cntFive == 2 && cntSeven == 1) {
    	println("YES")	 
    } else {
     	println("NO") 
    }
}

Measured memory_bytes: 37936
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n, k = (int(i) for i in input().split())

if n == 2:
    if k == 0:
        print(1)
        print(1, 2)
    else:
        print(-1)
else:
    total = cmb(n - 1, 2)
    
    if total < k:
        print(-1)
    else:
        dif = total - k

        print(n - 1 + dif)
        for i in range(n - 1):
            print(1, i + 2)

        p = 2
        c = 3
        while True:
            if dif == 0:
                break

            if c > n:
                p += 1
                c = p + 1
                print(p, c)
                c += 1
            else:
                print(p, c)
                c += 1

            dif -= 1

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
    ll x,k,d;
    cin>>x>>k>>d;
    if(x<0) x*=-1;
    ll kp=(x/d);
    ll ans;
    if(kp>=k)
        ans=x-(d*k);
    else
    {
        ll p1=x-(d*kp);
        ll p2=d-p1;
        k=k-kp;
        if(k%2==0)
            ans=p1;
        else
            ans=p2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3624
//https://atcoder.jp/contests/soundhound2018-summer-qual/tasks/soundhound2018_summer_qual_a
//A - F
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
    ll a,b; cin>>a>>b;
    if(a+b==15) cout<<"+"<<endl;
    else if(a*b==15) cout<<"*"<<endl;
    else cout<<"x"<<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();
		// 文字列の入力
		String s = sc.next();
		String t = sc.next();
		String u = "";
		for ( int i = 0 ; i < n ; i++) {
			String a = String.valueOf(s.charAt(i));
			u = u.concat(a);
			a = String.valueOf(t.charAt(i));
			u = u.concat(a);
		} 
		System.out.println(u);
	}
}

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

int main() {
  int n, x, cnt;
  while (cin >> n >> x) {
    if (n == 0 && x == 0) return 0;
    cnt = 0;
    for (int i = 1; i < n - 1; ++i) {
      for (int j = i + 1; j < n; ++j) {
        for (int k = j + 1; k <= n; ++k) {
          if (i + j + k == x) ++cnt;
        }
      }
    }
    cout << cnt << endl;
  }
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
const long double PI=(acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int ctoi(char c) {
	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}
int main(){
  string s;
  cin>>s;
  int ans=999;
  for(int i=0;i<s.size()-2;i++){
    int a=ctoi(s[i])*100+ctoi(s[i+1])*10+ctoi(s[i+2]);
    int b=abs(753-a);
    ans=min(ans,b);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  char o[51],e[51],pass[101]={};
  int i;

  scanf("%s",o);
  scanf("%s",e);

  for(i=0;o[i]!='\0';i++){
    pass[i*2]=o[i];
  }

  for(i=0;e[i]!='\0';i++){
    pass[i*2+1]=e[i];
  }

  printf("%s\n",pass);

  return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def solve(inp):
    (A, B) = map(int, inp.readline().strip().split(' '))

    b1 = B * 10
    b2 = (B + 1) * 10
    for i in range(b1, b2 + 1):
        if int(i * 0.08) == A and int(i * 0.1) == B:
            return str(i)

    return "-1"


def main():
    import sys
    result = solve(sys.stdin)
    if result is not None and result != '':
        print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;

int main() {
   long long n,k,cnt=0;
   cin >> n >> k;
   while(n>0){
       cnt++;
       n/=k;
   }
   cout << cnt << endl;
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i = 0;i < (n); ++i)
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int h,w;
    cin >> h >> w;
    char s[h+1][w+1];
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> s[i][j];
        }
    }
    for(int i = 1; i <= h; i++){
        bool flag = true;
        for(int j = 1; j <= w; j++){
            if(s[i][j] == '#'){
                flag = (s[i+1][j] == '#' || s[i-1][j] == '#' || s[i][j+1] == '#' || s[i][j-1] == '#');
            }
            if(!(flag)){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <vector>

using namespace std;

#define pv(val) cerr << #val << "=" << val << endl

int main(void) {
  int const none = numeric_limits<int>::lowest();

  int N, M;
  cin >> N >> M;

  vector<list<pair<int, int>>> ltor(N);
  vector<list<pair<int, int>>> rtol(N);
  vector<int> ans(N, none);

  for (int i = 0; i < M; i++) {
    int l, r, d;
    cin >> l >> r >> d;
    ltor[l-1].push_back({r - 1, d});
    rtol[r-1].push_back({l - 1, d});
  }

  vector<int> s(N);
  for (int i = 0; i < N; i++) s[i] = i;
  bool fail = false;
  while (!s.empty()) {
    int m = s.back();
    s.pop_back();

    while (!ltor[m].empty()) {
      int r = ltor[m].back().first;
      int rd = ltor[m].back().second;
      ltor[m].pop_back();

      if (ans[m] == none && ans[r] == none) {
        ans[m] = 0;
        ans[r] = rd;
      } else if (ans[m] == none) {
        ans[m] = ans[r] - rd;
      } else if (ans[r] == none) {
        ans[r] = ans[m] + rd;
      } else if (ans[r] - ans[m] != rd) {
        fail = true;
        break;
      }
      s.push_back(r);
    }

    while (!rtol[m].empty()) {
      int l = rtol[m].back().first;
      int ld = rtol[m].back().second;
      rtol[m].pop_back();

      if (ans[m] == none && ans[l] == none) {
        ans[m] = 0;
        ans[l] = -ld;
      } else if (ans[m] == none) {
        ans[m] = ans[l] + ld;
      } else if (ans[l] == none) {
        ans[l] = ans[m] - ld;
      } else if (ans[m] - ans[l] != ld) {
        fail = true;
        break;
      }
      s.push_back(l);
    }
  }

  cout << (fail ? "No" : "Yes") << endl;

  return 0;
}

Measured memory_bytes: 19448
n,k=map(int,input().split())
l=[]
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
l.sort()
sm=0 
for i in range(n):
    if sm+l[i][1]<k:
        sm+=l[i][1]
    else: 
        print(l[i][0])
        exit()

Measured memory_bytes: 58840
list=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k=int(input())
print(list[k-1])

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#define MAX 8
int main(){
	/* 入力 */
	int n,i,cnt;
	int *a;
	scanf("%d",&n);
	a = (int *)malloc(n*sizeof(a));
	for(i=0;i<n;i++){
		scanf("%d ",(a+i));
	}
	cnt = 0;
	
	/* これは、2と3が素数なので、a0,a1,..an-1が2で何回割り切れるかを求めればいい。*/
	for(i=0;i<n;i++){
		while(a[i]){
			if(a[i]%2 == 0){
				a[i] /= 2;
				cnt++;
			}
			else{
				break;
			}
		}
	}
	
	printf("%d\n",cnt);
	
	
}

Measured memory_bytes: 256
//This template belongs to Juan Carlo Vieri
#include <bits/stdc++.h>
using namespace std;

typedef int_fast64_t ll;
typedef long double ld;
typedef int_fast64_t intt;
typedef int_fast64_t tmp_m;
#define deb(x) cout << #x << ' ' << x << endl
#define rep(i, cmp1, cmp2) for (tmp_m i = cmp1; i < cmp2; ++i)
#define repp(i, cmp1, cmp2) for (tmp_m i = cmp1; i >= cmp2; --i)
#define pb push_back
#define st stack
#define pa pair
#define vc vector
#define qu queue
#define pq priority_queue
#define fr first
#define sc second
#define mp map
const ld pi = acos(-1.0);
const intt mod = 998244353;

struct pr {
  intt x;
  intt y;
  intt dst;
  pr() {}
  pr(intt x, intt y, intt dst) : x(x), y(y), dst(dst) {}
  inline bool operator<(const pr& cmp2) const {
    if (dst != cmp2.dst) return dst < cmp2.dst;
    if (x != cmp2.x) return x < cmp2.x;
    return y < cmp2.y;
  }
  inline bool operator==(const pr& cmp2) const {
    return (cmp2.dst == dst) && (cmp2.x == x) && (cmp2.y == y);
  }
  inline bool operator>(const pr& cmp2) const {
    if (dst != cmp2.dst) return dst > cmp2.dst;
    if (x != cmp2.x) return x > cmp2.x;
    return y > cmp2.y;
  }
};

struct point {
  intt x;
  intt y;
  point() {}
  point(intt x, intt y) : x(x), y(y) {}
  inline bool operator<(const point& cmp2) const {
    if (cmp2.x != x) return cmp2.x < x;
    return cmp2.y < y;
  }
  inline bool operator==(const point& cmp2) const {
    return (cmp2.x == x) && (cmp2.y == y);
  }
  inline bool operator>(const point& cmp2) const {
    if (cmp2.x != x) return cmp2.x > x;
    return cmp2.y > y;
  }
};

class prHash {
 public:
  size_t operator()(const pr& cmp1) const {
    return (hash<intt>()(cmp1.x)) ^ (hash<intt>()(cmp1.y)) ^
           (hash<intt>()(cmp1.dst));
  }
};

class pointHash {
 public:
  size_t operator()(const point& cmp1) const {
    return (hash<intt>()(cmp1.x)) ^ (hash<intt>()(cmp1.y));
  }
};

inline bool spoint(const point& cmp1, const point& cmp2) {
  // swap(cmp1, cmp2);
  if (cmp1.x != cmp2.x) return cmp1.x < cmp2.x;
  return cmp1.y < cmp2.y;
}

inline bool spr(const pr& cmp1, const pr& cmp2) {
  // swap(cmp1, cmp2);
  if (cmp1.dst != cmp2.dst) return cmp1.dst < cmp2.dst;
  if (cmp1.x != cmp2.x) return cmp1.x < cmp2.x;
  return cmp1.y < cmp2.y;
}

ll modex(ll b , ll e , ll m) {
  ll r = 1;
  while (e > 0) {
    if ((e & 1) == 1) {
      r = (r * b) % m;
    }
    e >>= 1;
    b = (b * b) % m;
  }
  return (ll) r;
}

intt fak[200005], inv[200005];

void solve() {
  intt n, m, k;
  cin >> n >> m >> k;
  fak[0] = 1;
  inv[0] = 1;
  rep(i, 1, n + 3){
    fak[i] = fak[i - 1] * i % mod;
    inv[i] = modex(fak[i], mod - 2, mod) % mod;
  }
  intt ans = 0;
  rep(i, 0, k + 1){
    intt temp = m;
    temp = temp * modex(m - 1, n - i - 1, mod) % mod;
    temp = temp * fak[n - 1] % mod * inv[i] % mod * inv[n - 1 - i] % mod;
    ans = (ans + temp) % mod;
  }
  cout << ans << endl;
}

void init() {
  // remove if interactive
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(0));
  // memset(dp, -1, sizeof dp);
}

int main() {
  init();
  solve();
  return 0;
}


Measured memory_bytes: 6784
S = input()
T = input()
ans = "UNRESTORABLE"
for i in range(len(S)-len(T)+1):
  for j in range(len(T)):
    if(T[j] == S[i+j] or S[i+j] == "?"):
      continue
    else:
      break
  else:
    ans = S[:i]+T+S[i+len(T):]
    ans = ans.replace("?", "a")
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
typedef vector<int> Vi;
typedef pair<int,int> Pii;
typedef pair<int,Pii> Pip; 
const int INF = (1<<30);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){

  int n, m;
  int a[10000], b[10000];
  while( cin >> n >> m, n + m ) {
    map<int, int> maps;
    set<int> all;
    
    for(int i=0; i<m; i++) {
      cin >> a[i] >> b[i];
      if( a[i] == 1 ) {
	maps[b[i]] = 1;
	all.insert(b[i]);
      }
    }
    
    for(int i=0; i<m; i++) {
      if( maps[a[i]] == 1 ) {
	all.insert(b[i]);
      }
      if( maps[b[i]] == 1 ) {
	if( a[i]!= 1 ) {
	  all.insert(a[i]);
	}
      }
    }
    
    cout << all.size() << endl;
  }
}

Measured memory_bytes: 1312
def e_yutori():
    # 参考: https://drken1215.hatenablog.com/entry/2020/04/05/163400
    N, K, C = [int(i) for i in input().split()]
    S = input()

    def sub_solver(string):
        """string が表す労働日時に対して、労働数が最大になるように働いたとき、
        i 日目には何回働いているかのリストを返す"""
        n = len(string)
        current, last = 0, -C - 1  # 最初に 'o' があっても動作するように設定
        ret = [0] * (n + 1)

        for i in range(n):
            if i - last > C and string[i] == 'o':
                current += 1
                last = i
            ret[i + 1] = current
        return ret

    left = sub_solver(S)
    right = sub_solver(S[::-1])
    ans = []
    for i in range(N):
        if S[i] == 'x':
            continue
        if left[i] + right[N - i - 1] < K:
            ans.append(i + 1)
    return '\n'.join(map(str, ans))

print(e_yutori())

Measured memory_bytes: 41092
N = int(input())
S = list(input())
X,Y = [0 for x in range(ord('z')-96)],[]
for i in range(ord('z')-96):
    Y += [S.count(chr(i+96+1))]

ans,temp = [],0
for i in range(0,N):
    s = ord(S[i])-97
    if X[s]==0 and Y[s]>=2:
        temp += 1
    elif X[s]>=1 and Y[s]==1:
        temp -= 1
    X[s] += 1
    Y[s] -= 1
    ans += [temp]

print(max(ans))

Measured memory_bytes: 3064
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}
import java.lang

import scala.annotation.tailrec
import scala.reflect.ClassTag

object Main {
  def get[T: ClassTag](implicit in: BufferedReader, converter: String => T): T = {
    converter(in.readLine)
  }

  def getArray[T: ClassTag](implicit in: BufferedReader, converter: String => T): Array[T] = {
    get[String].split("\\s+").map(converter)
  }

  implicit val intConverter: String => Int = s => Integer.parseInt(s)
  implicit val longConverter: String => Long = s => lang.Long.parseLong(s)

  def get[T1, T2](
                   implicit in: BufferedReader,
                   converter1: String => T1,
                   converter2: String => T2
                 ): (T1, T2) = {
    getArray[String] match {
      case Array(v1, v2) => (converter1(v1), converter2(v2))
    }
  }

  def get[T1, T2, T3](
                       implicit in: BufferedReader,
                       converter1: String => T1,
                       converter2: String => T2,
                       converter3: String => T3
                     ): (T1, T2, T3) = {
    getArray[String] match {
      case Array(v1, v2, v3) => (converter1(v1), converter2(v2), converter3(v3))
    }
  }

  implicit class TimesInt(val n: Int) {
    def times(f: Int => Unit): Unit = {
      for (i <- 0 until n) {
        f(i)
      }
    }
  }

  def main(args: Array[String]): Unit = {
    implicit val in: BufferedReader = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val (n, a, b) = get[Int, Int, Int]
    val xs = getArray[Int]

    var walk = 0L
    var teleport = 0L

    val threshold = (b + a - 1) / a

    @tailrec
    def count(xs: List[Int]): Unit = {
      xs match {
        case x1 :: x2 :: rest =>
          if (x2 - x1 < threshold) {
            walk += x2 - x1
          } else {
            teleport += 1
          }
          count(x2 :: rest)
        case x :: rest =>
          count(rest)
        case Nil =>
      }
    }

    count(xs.toList)

    out.println(walk * a + teleport * b)
    out.flush()
  }
}

Measured memory_bytes: 44388
#include<iostream>

using namespace std;

int main(){

    long long int h,w;

    cin >> h >> w ;

    if(h ==1 || w ==1)
        cout << 1 << endl;
    else if(h %2 ==1 && w%2 ==1)
        cout << (h*w)/2+1 << endl;
    else 
        cout << (h*w)/2 << endl;


}

Measured memory_bytes: 256
#include <iostream>
# include <bits/stdc++.h>
using namespace std;
int main() {
    vector<int> b;
    long long  a[200000];
    long long N;
    cin >> N ;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    if(N%2==0){
        for (int i = 0; i < N; i+=2) {
            b.push_back(a[i]);
            b.insert(b.begin(),a[i+1]);
        }
    }else{
        for (int i = 0; i < N; i+=2) {
            b.insert(b.begin(),a[i]);
            if(i==N){
                continue;
            }
            b.push_back(a[i+1]);
        }
    }
    for ( int i = 0; i <N; i++ ){
        cout << ( i ? " " : "" ) << b[i];
    }
    cout << endl;
}


Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main()
{
    int n;
    ll a,b;
    cin >>n >>a >>b;

    vector<ll> h(n);
    rep(i,n) cin >>h[i];

    ll l=0, r=1000000000;
    while(r-l>1)
    {
        ll m = (l+r)/2;
        ll ct=0;
        rep(i,n)
        {
            ll p = h[i]-b*m;
            if(p<=0) continue;

            ll q = a-b;
            p = (p+q-1)/q;
            ct += p;
        }

        if(ct<=m) r=m;
        else l=m;
    }

    cout << r << endl;
    return 0;
}


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

int F[8005];
int A[4005][16005], B[4005][16005];

int main() {
    string s;
    int x, y;
    cin >> s;
    cin >> x >> y;
    int p = 0;    
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'F') F[p]++;
        else p++;
    }
    A[0][s.size() + F[0]] = 1;
    B[0][s.size() + F[1]] = 1;
    B[0][s.size() - F[1]] = 1;
    for (int i = 1; i <= p / 2; i++) {
        for (int j = 0; j <= s.size() * 2; j++) {
            if (A[i-1][j] == 1) {
                A[i][j + F[2 * i]] = 1;
                A[i][j - F[2 * i]] = 1;
            }
            if (B[i-1][j] == 1) {
                B[i][j + F[2 * i + 1]] = 1;
                B[i][j - F[2 * i + 1]] = 1;
            }
        }
    }
    if (A[p/2][x + s.size()] == 1 && B[p/2][y + s.size()] == 1) printf("Yes\n");
    else printf("No\n");
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> w(N);
  for(int i = 0;i < N;i++){
    cin >> w[i];
  }
  int allsum = 0;
  for(int i = 0;i < N;i++){
    allsum += w[i];
  }
  int mini = 100000000;
  for(int i = 0;i < N;i++){
  int s1 = 0;
    for(int j = 0;j <= i;j++){
      s1 += w[j];
    }
    mini = min(mini, abs((allsum - s1) - s1));
  }
  cout << mini;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#define ll long long
int mark[10];
using namespace std;
int main(){
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    cout<<a[2]-a[0]<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int a,b,c,d;
	cin>>a>>b>>c>>d;
	long long int arr[4];
	arr[0]=a*c;
	arr[1]=a*d;
	arr[2]=b*c;
	arr[3]=b*d;
	sort(arr,arr+4);
	long long int ans=arr[3];
	cout<<ans;
}

Measured memory_bytes: 3648
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
typedef long long ll;

int main(){
  int count[30]={0};
  string S;
  cin>>S;
  for(int i=0;i<S.size();i++){
    if(count[S[i]-'A']==0) count[S[i]-'A']++;
  }
  if(count[4]!=count[22] || count[13]!=count[18]){
    cout<<"No"<<endl;
  }else cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

double x, y;

bool cross(double a, double b, double c, double d) {
	return (c-a) * (y-b) - (x-a) * (d-b) > 0;
}

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	double a, b, c, d, e, f;
	while(cin >> a >> b >> c >> d >> e >> f >> x >> y) {
		int cnt = 0;
		cnt += cross(a, b, c, d);
		cnt += cross(c, d, e, f);
		cnt += cross(e, f, a, b);
		if(cnt == 0 || cnt == 3) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 3296
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		long N = GetLong();

		long[,] cnt = new long[10, 10];
		for(long i = 1; i <= N; i++)
		{
			long tmp = i;
			while(tmp > 9)
				tmp /= 10;

			cnt[tmp, i % 10]++;
		}

		long ans = 0;
		for(long i = 1; i <= 9; i++)
		{
			for(long j = 1; j <= 9; j++)
				ans += cnt[i, j] * cnt[j, i];
		}
		WriteLine(ans);
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

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

#define mod 1000000007

int main() {
    int N;
    cin >> N;
    vector<int>a(N);
    for (int i = 0; i < N; ++i) {
      cin >> a[i];
    }
    vector<int>b(N);
    for (int i = 0; i < N; ++i) {
      cin >> b[i];
    }

    vector<pair<int, int>>all;
    all.reserve(2*N);
    for (int i = 0; i < N; ++i) {
        all.push_back(make_pair(a[i], 0));
        all.push_back(make_pair(b[i], 1));
    }
    sort(all.begin(), all.end());

    int num = 0;
    int flag = 0;
    ll ans = 1;
    for (int i = 0; i < N*2; ++i) {
        if(num == 0){
            num++;
            flag = all[i].second;
        } else{
            if(all[i].second != flag){
                ans *= num;
                ans %= mod;
                num--;
            } else{
                num++;
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 2688
#include "bits/stdc++.h"
using namespace std;

//40
typedef long long ll;

int main() {
	string s;
	cin >> s;
	int n = (int)s.size();
	string s1 = "";
	string s2 = "";
	int minn1 = 0;
	int minn2 = 0;
	for (int i = 0; i < n; i += 2) {
		if (i + 1 < n) {
			s1 += "10";
			s2 += "01";
		}else {
			s1 += "1";
			s2 += "0";
		}
	}
	for (int i = 0; i < n; ++i) {
		if (s1[i] != s[i]) minn1++;
		if (s2[i] != s[i]) minn2++;
	}
	cout << min(minn1,minn2);
}


Measured memory_bytes: 3976