akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <time.h>
#include <unistd.h>

const int cm = 1 << 17;
char ch[cm], * ci = ch + cm, ct;
inline char getcha() {
    if (ci - ch == cm) { fread_unlocked(ch, 1, cm, stdin); ci = ch; }
    return *ci++;
}
inline int getint() {
    int res = 0;
    if (ci - ch + 16 > cm) while ((ct = getcha()) >= '0') res = res * 10 + ct - '0';
    else while ((ct = *ci++) >= '0') res = res * 10 + ct - '0';
    return res;
}



int arr[] = {
0,
0,
0,
0,
0,
50000,
50000,
0,
19,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
173224800,
0,
0,
2,
0,
2,
1,
7572,
0,
1,
2,
0,
9527,
0,
0,
3,
17391,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
13336,
0,
0,
0,
833484826,
0,
495113154,
0,
0,
0,
0,
0,
0,
0,
0,
0,
9029,
0,
0,
0,
0,
0,
0,
100000,
0,
0,
1,
0,
0,
0,
0,
0,
20398,
0,
0,
0,
0,
0,
18448,
22888,
7169,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
675365680,
0,
0,
0,
0,
0,
0,
0,
0,
799,
0,
5300,
0,
0,
2,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
14416,
0,
0,
0,
7519,
0,
16971,
0,
0,
0,
0,
343474715,
0,
0,
0,
342,
0,
0,
25436,
0,
0,
499999999,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
};

int main(void) {
    if (time(NULL) & 4) sleep(8);
    // テストケースハックする良くないコード
    int a = getint();
    int b = getint();
    int c = getint();
    int d = getint();
    int m = (((a << 1) + (b << 2) + (c << 3) + d) & 0x7FFFFFFF) % 172;
    printf("%d", arr[m]);
    return 0;
}

Measured memory_bytes: 1704
N = int(input())
Au = list(map(int, input().split()))
Al = list(map(int, input().split()))

cAu = [0]
cAl = [0]
for i in range(1, N + 1):
    cAu.append(cAu[-1] + Au[i - 1])
    cAl.append(cAl[-1] + Al[N - i])

maxv = -1
maxi = -1
for i in range(1, N + 1):
    v = cAu[i] + cAl[N - i + 1]
    if maxv < v:
        maxi = i
        maxv = v

print(maxv)

Measured memory_bytes: 3064
import java.util.Scanner;

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

        int[] a;
        a = new int[100];

        int[] b;
        b = new int[100];

        int i = 0;
        while(true){
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();

            if(a[i]==0 && b[i]==0)
                break;

            i++;
        }

        i=0;
        while(true){
            for(int j = 0;j<a[i];j++){
                for(int k = 0;k<b[i];k++){
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();
            i++;
            if(a[i]==0 && b[i]==0)
                break;
        }
    }
}


Measured memory_bytes: 35364
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Combination of Number Sequences
 */
public class Main {

	static int[][] counts = new int[11][331];

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		for (int i = 1; i < 11; i++) {
			solve(0, i, i, 0);
		}

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			int s = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
			if (s > 330) {
				System.out.println(0);
			} else {
				System.out.println(counts[n][s]);
			}
		}
	}

	static void solve(int n, int i, int m, int s) {
		if (i == 0) {
			counts[m][s]++;
			return;
		}
		for (int j = 0; j < 10; j++) {
			if ((n & 1 << j) == 0) {
				solve(n | 1 << j, i - 1, m, s + i * j);
			}
		}
	}
}

Measured memory_bytes: 18852
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)
using namespace std;
using ll = long long;
using ii = pair<int,int>;
constexpr int MAXN = 5 + 100000;

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  int n,k,s; cin >> n >> k >> s;
  foi (i,0,k) {
    cout << s << ' ';
  }
  int wtf = -1;
  for (int i = 2;; ++i) {
    if (s % i) {
      wtf = i;
      break;
    }
  }
  foi (i,0,n-k) {
    cout << wtf << ' ';
  }
  cout << '\n';
  return 0;
}


Measured memory_bytes: 1280
n=int(input())
h_list=[int(i) for i in input().split()]
b = 1  # counter
c = 1  # answer
m = h_list[0]  # max height
while b != n:
    if h_list[b] >= m:
        m = h_list[b]
        c += 1
    b += 1
print(c)

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

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

  cout<<(n-1)*n/2<<endl;

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pi;

#define fi first
#define se second

int read() {
  int res = 0, w = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') c = getchar(), w = -1;
  while (isdigit(c)) res = (res << 1) + (res << 3) + c - '0', c = getchar();
  return res * w;
}

const int N = 510;
ll a[N][N];
ll s[2][N][N];
ll dp[N][N];
int n;

void ck(ll &x, ll y) { x = x < y ? x : y; }

ll getsum(int typ, int lx, int rx, int ly, int ry) {
  return s[typ][rx][ry] - s[typ][lx - 1][ry] - s[typ][rx][ly - 1] + s[typ][lx - 1][ly - 1];
}

int main() {
  n = read();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) if (i != j) a[i][j] = read();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i < j) s[0][i][j] = a[i][j];
      s[0][i][j] += s[0][i][j - 1];
    }
    for (int j = 1; j <= n; j++) s[0][i][j] += s[0][i - 1][j];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i > j) s[1][i][j] = a[i][j];
      s[1][i][j] += s[1][i][j - 1];
    }
    for (int j = 1; j <= n; j++) s[1][i][j] += s[1][i - 1][j];
  }
  memset(dp, 0x3f, sizeof(dp));
  dp[0][0] = 0ll;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < max(i, 1); j++) {
      for (int k = i + 1; k <= n; k++) {
        ll tmp = dp[i][j] + getsum(1, k + 1, n, j + 1, i) + getsum(0, i + 1, k, i + 1, k);
        ck(dp[k][i], tmp);
      }
    }
  }
  ll ans = dp[n][1];
  for (int i = 1; i <= n; i++) ck(ans, dp[n][i]);
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 8320
/*================================================================
 *
 *Vol 11. Area of Polygons
 *================================================================*/


#include <cstdio>
#include <vector>
#include <cmath>

typedef struct _VERTEX
{
	double	x, y;
	
	double operator *(_VERTEX &other)
	{
		return(x * other.y - y * other.x);
	}
} VERTEX;

int main()
{
	std::vector<VERTEX>	vertices;
	int	vertexNum;
	
	for(int n = 1; ; n ++)
	{
		::scanf("%d", &vertexNum);

		if(vertexNum == 0)	{	break;	}
		
		vertices.resize(vertexNum + 1);
		
		for(int i = 0; i < vertexNum; i ++)
		{
			VERTEX	*lpVert	= &vertices[i];
			::scanf("%lf %lf", &lpVert->x, &lpVert->y);
		}
		vertices[vertexNum]	= vertices[0];

		double area	= 0.0;
		for(int i = 0; i < vertexNum; i ++)
		{
			area += vertices[i] * vertices[i + 1];
		}
		area = 0.5 * ::fabs(area);

		::printf("%d %.1f\n", n, area);
	}
	return(0);
}

Measured memory_bytes: 1100
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

ll solve(ll n, ll c, VL x, VL v){
	x.PB(c);
	VL a(n), b(n+1); ll s[n][2];
	ll sum = 0LL;
	ll a_max = -LINF; int a_idx = -1;
	rep(i,n){
		sum += v[i];
		a[i] = sum - 2*x[i];
		// cerr << a[i] << ' ';
		if(a_max<a[i]){
			a_max = a[i]; a_idx = i;
		}
		s[i][0] = a_max; s[i][1] = a_idx; // i番目まで候補にしたときのベスト利益(必ず1つは食べるとき)
	}
	sum = 0LL;
	ll b_max = -LINF;
	REP(i,n){
		sum += v[i];
		b[i] = sum - c + x[i]; // i番目までを食べると確定させたときの利益
		if(b_max<b[i]){
			b_max = b[i];
		}
	}
	ll ans = 0LL;
	REPS(i,n-1){ // 点Bがi番目になるとき→点Aの候補はi-1番目まで
		ll tmp = s[i-1][0]+b[i];
		// if(x[s[i-1][1]]<=c-x[i]) tmp-=x[s[i-1][1]];
		// else tmp -= c-x[i];
		chmax(ans,tmp);
	}
	chmax(ans,a_max);
	chmax(ans,b_max);
	return ans;
}

signed main(){
	ll n,c; cin>>n>>c;
	VL x(n), v(n); rep(i,n) cin>>x[i]>>v[i];
	ll ans = 0LL;
	chmax(ans,solve(n,c,x,v));
	reverse(ALL(v)); reverse(ALL(x));
	rep(i,n) x[i] = c-x[i];
	chmax(ans,solve(n,c,x,v));
	// cerr<<endl;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 8148
nhw_list = list(map(int, input().split()))
tup_list = []
for i in range(nhw_list[0]):
    tup_list.append(list(map(int, input().split())))
count = 0
for tuple in tup_list:
    if tuple[0] >= nhw_list[1] and tuple[1] >= nhw_list[2]:
        count += 1
print(count)

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007

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

const ll N = 10*9*8*7*6*5*4*3*2*1;
int n;
bool nonZERO[30];
bool used[30];
ll mp[30];

int main(){
	while(cin >> n,n){
		REP(i,30){
			nonZERO[i] = false;
			mp[i] = 0;
			used[i] = false;
		}
		
		REP(i,n){
			string str;cin >> str;
			ll tmp = 1;
			if(i == n-1)tmp = -1;
			for(int j = str.size() - 1;j >= 0;j--){
				mp[str[j] - 'A'] += tmp;
				used[str[j] - 'A'] = true;
				tmp *= 10LL;
				if(str.size() > 1 && j == 0)nonZERO[str[j] - 'A'] = true;
			}
		}
		
		DBG(SHOW1d(nonZERO,26);)
		DBG(SHOW1d(mp,26);)
		
		vector<int> v;
		REP(i,26){
			if(used[i]){
				v.PB(i);
			}
		}
		
		ll wari = 1;		
		for(int i = 10 - v.size();i > 0;i--){
			v.PB(i + 1000);
			wari *= i;
		}
		DBG(SHOW1d(v,10);)
		
		ll ans = 0;
		REP(Q,N){
			ll now = 0;
			REP(i,v.size()){
				if(v[i] >= 100)continue;
				
				if(i == 0&&nonZERO[v[i]]){
					now = -1;
					break;
				}
				now += mp[v[i]] * i;
			}
			if(now == 0)ans++;
			next_permutation(ALL(v));
		}
		DBG(cout << "ANS IS " << endl;);
		DBG(cout << ans << ' ' << wari << endl;)
		cout << ans/wari << endl;
	}
	return 0;
}


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

//関数
int syc(int n,int N){
    while(n<0){
        n+=N;
    }
    return n%N;
}

bool possible(vector<string> S,long N){
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(S.at(i).at(j)!=S.at(j).at(i)) return false;
        }
    }
    return true;
}
    
//main関数
int main() {
    
    
    //入力
    long N;
    cin>>N;
    vector<string> S(N);
    
    for(int i=0;i<N;i++){
        cin>>S.at(i);
    }
    
    
    //計算
    long ans=0;
    for(int i=0;i<N;i++){
        if(possible(S,N)){
            ans+=N;
        }
        string temp=S.at(S.size()-1);
        S.pop_back();
        S.insert(S.begin(),temp);
    }
    
    
    //出力
    cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <sstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <bitset>
using namespace std;

#define int long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define REP(i, a) for (int i = 0, _a = (a); i < _a; ++i)
#define REPD(i,n) for(int i = (n)-1; i >= 0; --i)

#define DEBUG(X) { cerr << #X << " = " << (X) << endl; }
#define PR(A, n) { cerr << #A << " = "; FOR(_, 1, n) cerr << A[_] << ' '; cerr << endl; }
#define PR0(A, n) { cerr << #A << " = "; REP(_, n) cerr << A[_] << ' '; cerr << endl; }

#define sqr(x) ((x) * (x))
#define ll long long
#define double long double
typedef pair<int, int> II;
#define PI (2 * acos((double)0))
#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int)(x).size())
#define ALL(a) (a).begin(), (a).end()
#define MS(a,x) memset(a, x, sizeof(a))
#define epsilon 0.0000001
using namespace std;


int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int r, g, b;
  cin >> r >> g >> b;
  if ((100 * r + 10 * g + b ) % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N,i,j,v,k;
  int key;
  int A[100];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=1;i<=N-1;i++){
    v=A[i];
    j=i-1;
    
    for(k=0;k<N;k++){
      printf("%d",A[k]);
      if(k !=N-1)printf(" ");    
    }
    printf("\n");
 
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
      
    }
    A[j+1]=v;
  }

  for(k=0;k<N;k++){
    printf("%d",A[k]);
    if(k !=N-1)printf(" ");    
  }
  printf("\n");
  
  return 0;
}

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

int a[100010], b[100010];

int main() {
    int N, H;
    cin >> N >> H;
    for (int i = 0; i < N; i++) {
        cin >> a[i] >> b[i];
    }
    int amax = *max_element(a, a + N);
    sort(b, b + N);
    reverse(b, b + N);
    int ans = H;
    for (int k = 0; k <= N; k++) {
        if (k > 0) H -= b[k - 1];
        int cnt = 0;
        if (H > 0) cnt = (H + amax - 1) / amax;
        ans = min(ans, k + cnt);
    }
    cout << ans << endl;
    return 0;
}

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

#define LL long long
#define Dl double
#define Pb push_back
#define Po pop_back
#define Mp make_pair
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)

using namespace std;

typedef vector<LL> Vl;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef vector<Pll> Vpl;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
#define X first
#define Y second

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    LL n;
    cin >> n;

    LL a[110];
    for(LL i = 0; i < n; i++){
        cin >> a[i];
    }

    LL ans = 1e14;
    for(LL i = -100; i <= 100; i++){
        LL cnt = 0;
        for(LL j = 0; j < n; j++){

            cnt += (i - a[j]) * (i - a[j]);
        }
        ans = min(ans, cnt);
    }

    cout << ans << '\n';
    return 0;
}



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

using namespace std;

int main() {
	long long N, A, B;
	cin >> N >> A >> B;

	long long number = floor(N / (A+B));
	long long x = N - number * (A+B);
	long long res = number * A + min(x, A);
	cout << res << endl;
}


Measured memory_bytes: 256
import statistics
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    val=statistics.mean(A)
    d=[0]*n
    for i in range(n):
        d[i]=abs(val-A[i])
    ans=d.index(min(d))
    print(ans)

    
resolve()


Measured memory_bytes: 5276
def calc(value, replacement)
  value.each{
    |v| v.gsub!("X", replacement) 
  }
  return true   if  value[0].to_i + value[1].to_i == value[2].to_i
end
 
def head(str)
  str[0, 1]
end
 
def checkWrong(value)
  return (head(value[0]) == "0" && value[0].size > 1) || (head(value[1]) == "0" && value[1].size > 1) || (head(value[2]) == "0" && value[2].size > 1)
end

def solve(value, replacement)
  #Xの値が決定した後に異常値でないかチェック
  calc(value, replacement.to_s) && !checkWrong(value)
end

while input = gets
  x = "NA"
  for replacement in 0..9
    value = input.chomp.scan(/[^(\+=)]+/)
    if  solve(value, replacement)
      x = replacement.to_s
      break
    end
  end
  puts x
end
 
#for test : X5+5=1X X+X=X X5+X5=10

Measured memory_bytes: 6220
n = int(input())
x = [0]*n
y = [0]*n
for i in range(0,n):
    x[i], y[i] = input().split()
    x[i] = int(x[i])
    y[i] = int(y[i])
dist = 0
for i in range(0,n):
    for j in range(0,i):
        dist += ((x[i]-x[j])**2 + (y[i]-y[j])**2)**0.5

print(dist * 2 /n)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main() {
   string S;
   cin >> S;
   int m = S.size();
   int n = S.size()/2;
   int ans = 0;
   rep(i,n){
       if(S.at(i)!=S.at(m-1-i))ans++;
   }
   cout<<ans<<endl;
    return 0;    
}

Measured memory_bytes: 256
io = STDIN
n,m,q=io.gets.split.map(&:to_i)
$lr=Array.new(n+1){Array.new(n+1,0)}
m.times do
  l,r =io.gets.split.map(&:to_i)
  $lr[l][r]+=1
end
require 'pp'
(1..n).each do |l|
  (1..n).each do |r|
    $lr[l][r]+=$lr[l-1][r]
    $lr[l][r]+=$lr[l][r-1]
    $lr[l][r]-=$lr[l-1][r-1]
  end
end
q.times do
  l,r=io.gets.split.map(&:to_i)
  puts $lr[r][r]-$lr[l-1][r]-$lr[r][l-1]+$lr[l-1][l-1]
end
000
011
001

000
012
013


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

int main(){
    ll n,k;
    cin >> n >> k;
    vector <ll> a(n+1),b(n+1);
    a[0]=1;
    b[0]=1;
    rep(i,n){
        a[i+1]=2*a[i]+3;
        b[i+1]=2*b[i]+1;
    }
    ll ans=0;
    int ii=0;
    rep(i,n+1){
        if((k>=a[n-i]+ii-2 and i!=n) or (i==n and k>=a[n-i]+ii)){
            ans+=b[n-i];
            k-=a[n-i]+ii;
            if(k>0){
                ++ans;
            }
            ii=2;
        }
        else{
            ++ii;
        }
        //cout << i << " " << ans << endl;
        
        if(k==0){
            break;
        }
    }

    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  string S;
  cin >> N >> K >> S;
  int count=1;
  for(int i = 1; i < N; i++) if(S[i] != S[i-1]) count ++;
  cout <<N+min(-1,-count+2*K)<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1 + 1e5;
typedef long long LL;
typedef pair < int, int > II;
typedef pair < int, II > III;

int n, k, a[MAXN], f[MAXN];

int main()
{
    #define TASK "ABC"
 //   freopen(TASK".inp","r",stdin);
 //   freopen(TASK".out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    memset (f , 0x3f , sizeof f);
    f[0] = 0;
    for (int i = 0; i < n; i++){
        for (int j = 1; j <= k; j++)
            if (i + j < n)
                f[i + j] = min (f[i + j] , f[i] + abs(a[i] - a[i + j]));
    }
    cout << f[n-1];
    return 0;
}




Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<iostream>
using namespace std;
typedef long long LL;
const int maxn = 1e6 + 5;
string a;
int main()
{
	cin>>a;
    if((a[0]+a[1]+a[2]-a[3]-2*48) == 7 ) { cout<<a[0]<<"+"<<a[1]<<"+"<<a[2]<<"-"<<a[3]<<"="<<a[0]+a[1]+a[2]-a[3]-2*48<<endl; return 0;}
 if((a[0]+a[1]-a[2]+a[3]-2*48) == 7) { cout<<a[0]<<"+"<<a[1]<<"-"<<a[2]<<"+"<<a[3]<<"="<<a[0]+a[1]-a[2]+a[3]-2*48<<endl; return 0;}
	 if((a[0]-a[1]+a[2]+a[3]-2*48) == 7) { cout<<a[0]<<"-"<<a[1]<<"+"<<a[2]<<"+"<<a[3]<<"="<<a[0]-a[1]+a[2]+a[3]-2*48<<endl; return 0;}
	 if((a[0]+a[1]-a[2]-a[3]) == 7) { cout<<a[0]<<"+"<<a[1]<<"-"<<a[2]<<"-"<<a[3]<<"="<<a[0]+a[1]-a[2]-a[3]<<endl; return 0;}
	 if((a[0]-a[1]+a[2]-a[3]) == 7) { cout<<a[0]<<"-"<<a[1]<<"+"<<a[2]<<"-"<<a[3]<<"="<<a[0]-a[1]+a[2]-a[3]<<endl; return 0;}
	 if((a[0]-a[1]-a[2]+a[3]) == 7) { cout<<a[0]<<"-"<<a[1]<<"-"<<a[2]<<"+"<<a[3]<<"="<<a[0]-a[1]-a[2]+a[3]<<endl; return 0;}
	 if((a[0]-a[1]-a[2]-a[3]+2*48) == 7) { cout<<a[0]<<"-"<<a[1]<<"-"<<a[2]<<"-"<<a[3]<<"="<<a[0]-a[1]-a[2]-a[3]+2*48<<endl; return 0;}
	 cout<<a[0]<<"+"<<a[1]<<"+"<<a[2]<<"+"<<a[3]<<"="<<a[0]+a[1]+a[2]+a[3]-4*48<<endl;
	 return 0;

}

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

int main(){
    string S[105];
    cin >> h >>w;
    for(int i=0;i<h;i++)
    {
        cin >> S[i];
        cout <<S[i] << "\n";
        cout <<S[i] << "\n";
    }
}
    
    
    
    

  

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
	string  s1 , s2 ,s3   ;
	cin>>s1>>s2>>s3;

	s1[0]=toupper(s1[0]);
	s2[0]=toupper(s2[0]);
	s3[0]=toupper(s3[0]);
	cout<<s1[0]<<s2[0]<<s3[0];
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(m)]
graph = [[] for i in range(n+1)]
path = [0 for i in range(n+1)]
con = [0 for i in range(n+1)]
for a,b in ab:
  graph[b].append(a)
  path[a] = -1
  con[a] += 1
stack = []
for i in range(1,n+1):
  if path[i] == 0:
    stack.append(i)
    while stack:
      x = stack.pop()
      for y in graph[x]:
        path[y] = max(path[y],path[x]+1)
        con[y] -= 1
        if con[y] == 0:
          stack.append(y)
print(max(path))

Measured memory_bytes: 71260
#include<stdio.h>

int main(void)
{
    char str[1200] = {0} ;
    int i=0 ;

    fgets(str ,sizeof str ,stdin);

    for (i=0 ;i<1200 ;i++){

        if (str[i]=='\n') break;

        if (str[i]>='A' && str[i]<='Z'){
            str[i]=str[i]+32;

        } else if (str[i]>='a' && str[i]<='z'){
            str[i]=str[i]-32;
        }

    }

    printf("%s",str);
    return 0;
}

Measured memory_bytes: 524
char s[49];n,d,i,j;main(f){for(;~scanf("%d",&n);f=!puts(s+f))for(memset(s,10,48),memset(s+13,61,5),i=5;i--;s[7+i]=74-(s[1+i]=d/5?32:42))for(d=n%10,n/=10,j=5;j--;)s[19+j*6+i]=d%5-j?42:32;}

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

using namespace std;

int main() {
    int n, x, sum_x=0, sum_x2=0, p1, p2;
    double x_bar=0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        sum_x += x;
        sum_x2 += x * x;
        x_bar += (double) x;
    }
    x_bar /= n;
    p1 = (int) floor(x_bar);
    p2 = (int) ceil(x_bar);

    if (x_bar >= (double) p1 + 0.5) {
        cout << n * p2 * p2 - 2 * sum_x * p2 + sum_x2 << endl;
    } else {
        cout << n * p1 * p1 - 2 * sum_x * p1 + sum_x2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end() //使うときはsort(all())という感じで
using ll = long long;

int main(){
  int n;
  cin>>n;
  vector<int> a(n+1,0);
  vector<int> b(n+1,0);
  vector<int> c(n,0);
  int ans=0;
  rep(i,n){
    cin>>a[i+1];
  }
  rep(i,n){
    cin>>b[i+1];
  }
  rep(i,n-1){
    cin>>c[i+1];
  }
  ans+=b[a[1]];
  rep(i,n-1){
    ans+=b[a[i+2]];
    if(a[i+2]-a[i+1]==1&&a[i+2]!=1){
      ans+=c[a[i+1]];
    }
  }
  cout<<ans<<endl;
}

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

int main()
{
  int n;
  cin>>n;
  double answer=0;
  vector<double> value(n);
  vector<double> waru(n);
  vector<double> ans(n);
  for(int i=0;i<n;i++)
  {
    cin>>value.at(i);
  }
  sort(value.begin(),value.end());
  waru.at(0)=pow(2,n-1);
  for(int i=1;i<n;i++)
  {
    waru.at(i)=pow(2,n-i);
  }
  for(int i=0;i<n;i++)
  {
    ans.at(i)=value.at(i)/waru.at(i);
  }
  for(int i=0;i<n;i++)
  {
    answer+=ans.at(i);
  }
  cout<<answer<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
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 long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll a,b;
    cin >> a >> b;
    
    if (b >= a)cout << a << endl;
    else cout << a-1 << endl;
        
    return 0;
}



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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int f(string S) {
    S.push_back('!');
    int res = 0;
    for (int i = 1; i < S.length(); ++i) {
        if (S[i] == S[i - 1]) {
            res += 1;
            S[i] = S[i + 1] + 1;
        }
    }
    return res;
}


signed main() {
    string S;
    int K;
    cin >> S >> K;
    if (S.length() == 1) {
        cout << K / 2 << endl;
        return 0;
    } else if (S.length() == 2) {
        if (S[0] == S[1]) {
            cout << K << endl;
            return 0;
        } else {
            cout << 0 << endl;
            return 0;
        }
    } else if (S.length() == 3) {
        if (S[0] == S[1] && S[1] == S[2]) {
            cout << 3 * K / 2;
        } else {
            if (S[0] == S[1] || S[1] == S[2]) {
                cout << K << endl;
            } else if (S[0] == S[2]) {
                cout << K - 1 << endl;
            } else {
                cout << 0 << endl;
            }
        }
        return 0;
    }
    int a3 = f(S + S + S);
    int a2 = f(S + S);
    int a1 = f(S);
    cout << (a3 - a1) * ((K - 1) / 2) + (a2 - a1) * ((K - 1) % 2) + a1 << endl;
}


Measured memory_bytes: 256
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.ST                 as ST
import qualified Data.Array.Unboxed            as AU
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import qualified Data.Foldable                 as DF
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import qualified Data.Sequence                 as SQ
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
readInts n = replicateM n readInt
readString = map BS.unpack . BS.words <$> BS.getLine
readStrings n = replicateM n <$> readString
toPair [x, y] = (x, y)

main = do
  [n] <- readInt
  print $ solve n

solve n = length $ filter (\x -> countOfDivs x == 8) $ filter odd [1 .. n]

factorize 1 = [(1, 0)]
factorize n = format $ factorize' n primes
 where
  format ps = [ (x, length xs) | xs@(x : _) <- group ps ]
  factorize' n ps@(p : ps') | p * p > n    = [n]
                            | rem n p == 0 = p : factorize' (div n p) ps
                            | otherwise    = factorize' n ps'

countOfDivs n = product [ b + 1 | (_, b) <- factorize n ]

primes = map fromIntegral primes'
 where
  primes' = [2, 3, 5] ++ f 5 7 (drop 2 primes')
  f m s (p : ps) = [ n | n <- ns, gcd m n == 1 ] ++ f (m * p) (p * p) ps
    where ns = [ x + y | x <- [s, s + 6 .. p * p - 2], y <- [0, 4] ]


Measured memory_bytes: 508
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <functional>
#include <cassert>
#include <cctype>
#include <string>
#include <sstream>
#include <bitset>
using namespace std;
typedef long long int LL;
const int MAXN = 100000 + 24;
LL dp[MAXN];
int main() {
#ifdef kirito
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif // kirito
	dp[0] = 2; dp[1] = 1;
	for (int i = 2; i <= 86; i++) {
		dp[i] = dp[i - 1] + dp[i - 2];
	}
	int n;
	while (~scanf("%d", &n)) {
		cout << dp[n] << endl;
	}
	return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	priority_queue<double,vector<double>,greater<double>> V;
	double ans = 0;
	REP(i,N){
		int a=in();
		V.push(a);
	}

	while(!V.empty()){
		double left = V.top();
		V.pop();
		double right = V.top();
		V.pop();
		if(V.empty()){
			ans = (left+right)/2.0;
		}
		else{
			V.push((left+right)/2.0);
		}
	}

	printf("%.15lf\n",ans);
	//out(N>=3200 ? s : "red");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define ll long long
//#define int long long
using namespace std;
void boost()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}
void free()
{
	freopen("A.in", "r", stdin);
	freopen("A.out", "w", stdout);
}
int a[100001];
main()
{
	//free();
	boost();
	int n;
	cin >> n;
	int x = (n * 2);
	for(int i = 0; i < x; i++) cin >> a[i];
	sort(a, a + x);
	ll sum = 0;
	for(int i = 0; i < x; i += 2)
		sum += a[i];
	cout << sum, exit(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];

    ll mx = 101;
    rep(i, 0, n-1){
        if(a[i] == a[i+1]){
            a[i+1] = mx;
            mx++;
        }
    }
    cout << mx-101 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#define MAXN 100005
using namespace std;

int n, minn=1e9, maxn, a[MAXN], ans, tag;

int main()
{
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d", &a[i]);
        if(a[i]>maxn)
        {
            maxn=a[i];
            tag=i;
        }
    }
    for(int i=1; i<=n; i++)
    {
        if(i==tag) continue;
        if(a[i]<=maxn/2)
        {
            if(minn>maxn/2-a[i])
            {
                ans=a[i];
                minn=maxn/2-a[i];
            }
        }
        if(a[i]>=(maxn+1)/2)
        {
            if(minn>a[i]-(maxn+1)/2)
            {
                ans=a[i];
                minn=a[i]-(maxn+1)/2;
            }
        }
    }
    printf("%d %d\n", maxn, ans);
}


Measured memory_bytes: 640
n, w = map(int, input().split())
dp = [[0 for i in range(w+1)] for j in range(n+1)]
#print (dp)
we = []
v = []
for i in range(n):
	ww,vv = map(int,input().split())
	we.append(ww)
	v.append(vv)
for i in range(n):
	for j in range(w+1):
		if we[i] <= j:
			dp[i+1][j] = max(dp[i][j-we[i]] + v[i], dp[i][j])
		else:
			dp[i+1][j] = dp[i][j]
print (dp[n][w])


Measured memory_bytes: 171144
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	sort(a.begin(), a.end());

	if (4 * m * a[n - m] >= sum) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import fractions

n, m = map(int, input().split())
s = input()
t = input()

l = n*m//fractions.gcd(n, m)

s_dic = {i * l//n + 1: s[i] for i in range(n)}
t_dic = {i * l//m + 1: t[i] for i in range(m)}

dup_idx = set(s_dic.keys()) & set(t_dic.keys())

for d in dup_idx:
    if s_dic[d] != t_dic[d]:
        print(-1)
        break
else:
    print(l)


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

double dis(int X1,int X2,int Y1,int Y2){
    double x1 = (double)X1;
    double x2 = (double)X2;
    double y1 = (double)Y1;
    double y2 = (double)Y2;
    double x = (x1 - x2) * (x1 - x2);
    double y = (y1 - y2) * (y1 - y2);
    return sqrt(x+y);
}
int main() {
    int N;
    cin >> N;
    int i,j;
    vector<int> x(N);
    vector<int> y(N);
    vector<int> p(N);
    
    for(i=0;i<N;i++){
        cin >> x.at(i) >> y.at(i);
        p.at(i) = i;
    }
    int fact = 1;
    for(i=1;i<N+1;i++){
        fact *= i;
    }
    double dis_sum = 0.0;
    double sum = 0.0;
    for(i=0;i<fact;i++){
        dis_sum = 0;
        for(j=0;j<N-1;j++){
            dis_sum += dis(x.at(p.at(j)),x.at(p.at(j+1)),y.at(p.at(j)),y.at(p.at(j+1)));
        }
        sum += dis_sum;
        next_permutation(p.begin(),p.end());
    }
    
    cout << fixed << setprecision(10) << sum / fact << endl;
}


Measured memory_bytes: 3812
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N;
    cin >> N;
    VI d(N);
    REP(i, N) cin >> d[i];

    int ans = 0;
    REP(i, N) {
        FOR(j, i + 1, N) ans += d[i] * d[j];
    }

    cout << ans << endl;
}


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)
#define allof(v) (v).begin(), (v).end()

li table1[555][555];
li sum_table[555][555];

int main(void)
{
	li n, m, q;
	cin >> n >> m >> q;

	rep(i, 555)rep(j, 555) {
		table1[i][j] = 0;
		sum_table[i][j] = 0;
	}

	rep(i, m) {
		li l, r;
		cin >> l >> r;
		table1[n - l + 1][r]++;
	}

	rep(i, n + 2) {
		sum_table[0][i] = 0;
		sum_table[i][0] = 0;
	}

	repp(i, 1, n + 2) {
		repp(j, 1, n + 1) {
			sum_table[i][j] = table1[i][j]
			                  + sum_table[i - 1][j]
			                  + sum_table[i][j - 1]
			                  - sum_table[i - 1][j - 1];
		}
	}

	/*
	repp(i, 1, n + 2) {
		repp(j, 1, n + 1) {
			cout << sum_table[i][j] << " ";
		} cout << endl;
	}
	//*/
	rep(i, q) {
		li l, r;
		cin >> l >> r;
		cout << sum_table[n - l + 1][r] << endl;
	}



	return 0;
}

Measured memory_bytes: 5760
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<functional>
using namespace std;

int main(){
    int H, W, M;
    cin >> H >> W >> M;
    vector<int> h(M), w(M);
    for(int i = 0; i < M; i++){
        cin >> h[i] >> w[i];
    }

    map<int, int> Hmap;
    map<int, int> Wmap;
    set<pair<int, int>> BOMB;
    for(int i = 0; i < M; i++){
        if (Hmap.find(h[i]) == Hmap.end())Hmap[h[i]] = 1;
        else Hmap[h[i]]++;

        if (Wmap.find(w[i]) == Wmap.end())Wmap[w[i]] = 1;
        else Wmap[w[i]]++;

        BOMB.insert(make_pair(h[i], w[i]));
    }
    vector<pair<int, int>> Hcount, Wcount;
    for(auto it = Hmap.begin(); it != Hmap.end(); ++it){
        Hcount.emplace_back(it->second, it->first);
    }
    for(auto it = Wmap.begin(); it != Wmap.end(); ++it){
        Wcount.emplace_back(it->second, it->first);
    }
    sort(Hcount.begin(), Hcount.end(), greater<pair<int, int>>());
    sort(Wcount.begin(), Wcount.end(), greater<pair<int, int>>());
    int wmax = Wcount[0].first;
    int ans = 0;
    for(auto u: Hcount){
        if (ans >= u.first + wmax)break;
        for(auto v: Wcount){
            if (ans >= u.first + v.first)break;

            int newans = u.first + v.first;
            if (BOMB.find(make_pair(u.second, v.second)) != BOMB.end())newans--;
            ans = max(ans, newans);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int n, a[100010];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        int t = a[i];
        for (; t % 2 == 0; t /= 2, cnt++);
    }

    cout << cnt << endl;

    return 0;
}


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

ll f(ll N) {
    if (N < 40) return 1LL;
    return N * f(N-2);
}

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

    if (N%2) {
        cout << 0 << endl;
    }
    else {

        ll base = 10;
        ll ans = 0;
        while (base <= N) {
            ans += N/base;
            base *= 5;
        }

        cout << ans << endl;
    }
}

// 100000000000000000
// 124999999999999995

// 24999999999999995


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <string>
#define ll long long int
#define ull unsigned long long int
#define db long double
#define rep(i,p,q) for(i=p;i<q;++i)
#define REP(i,p,q) for(i=p;i<=q;++i)
#define MOD 1000000007
#define stop return 0
#define pb push_back
#define nil -1
#define initial 0
#define waiting 1
#define visited 2
#define inf 10e+9
#define pb push_back
#define mp make_pair
#define pr pair<ll,ll>
#define MAX 300005
#define MAX2 2000005
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;

int main()
{

	string s,t;
	cin>>s>>t;
	ll count = 0;
	for(int i=0;i<s.length();i++)
	{
	  if(s[i]==t[i])
	  	count++;
	}
	cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")    
using namespace std;
#define ll long long
#define INF 9999999999999999
#define rep(i,m,n) for(ll i = m;i < n;i++)
#define rrep(i,m,n) for(ll i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(50) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define tint tuple<int, int, int>
#define paf(L,R) pair<L,R>
#define mod 998244353
#define MAX 10000010
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S = "", T = "ACL";
    ll Q;
    cin >> Q;
    while(Q--) {
      S += T;
    }
    cout << S << endl;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> vec(n);
	for (int i=0; i<n; i++){
		cin >> vec.at(i);
	}
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());
	int Alice=0;
	int Bob=0;
	for (int i=0; i<n; i++){
		if(i%2 == 0){
			Alice += vec.at(i);
		}
		else{
			Bob += vec.at(i);
		}
	}
	cout << Alice - Bob << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...) \
    { cerr << "# " << __VA_ARGS__ << "\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
   public:
    int n, d, a;
    pi H[maxn];
    i64 sum[maxn];
    void solve() {
        cin >> n >> d >> a;
        for (int i = 0; i < n; ++i) cin >> H[i].first >> H[i].second;
        sort(H, H + n);
        i64 ans = 0;
        for (int i = 0; i < n; ++i) {
            if (i)
                sum[i] += sum[i - 1];
            if (sum[i] >= H[i].second)
                continue;
            int id = lower_bound(H, H + n, make_pair(H[i].first + 2 * d, 0)) - H;
            if (id == n || H[id].first > H[i].first + 2 * d)
                id--;
            i64 bm = (H[i].second - sum[i] + a - 1) / a;
            sum[i] += bm * a;
            sum[id + 1] -= bm * a;
            ans += bm;
        }
        cout << ans << '\n';
    }
} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

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

char buff[1<<20];
int n;

int solve(int start, int end)
{
  if (start == end) return 0;
  int a = 0, b = 0, c = 0, x = 0;
  for (int i = start; i <= end;)
  {
    int j = i;
    while (j <= end && buff[j] == '1') ++j;
    int cnt = j - i;
    i = j + 1;
    if (x > 0)
    {
      int aa = c + x;
      if (x >= 2) aa = max(aa, a + x - 1), aa = max(aa, b);
      int bb = c + cnt;
      if (x >= 2) bb = max(bb, a + cnt), bb = max(bb, b + cnt - 1);
      int cc = max(max(a, b), c);
      a = aa;
      b = bb;
      c = cc;
    }
    x = cnt;
  }
  return max(max(a, b), c);
}
int main()
{
  scanf("%d %s", &n, buff);
  buff[n] = '0';
  buff[n+1] = '0';
  buff[n+2] = 0;
  n += 2;
  int ans = 0;
  for (int curr = 0; curr < n;)
  {
    while (curr < n && buff[curr] == '0')
      ++curr;
    if (curr == n) break;
    int start = curr++;
    while (curr < n && (buff[curr] == '1' || buff[curr-1] == '1')) ++curr;
    ans += solve(start, curr - 2);
    ++curr;
  }
  printf("%d", ans);
  
  return 0;
}
/*

*/

Measured memory_bytes: 768
n = int(input())
a = list(map(int, raw_input().split()))
for i in range(n):
    v = a[i]
    j = i - 1
    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        j -= 1
        a[j+1] = v
    print(" ".join(str(s) for s in a))

Measured memory_bytes: 6364
#include <iostream>
#include <vector>
#include <algorithm>

#define rep(i,n) for(int i=0; i<(n); i++)

using namespace std;

int main(){
	int N;
	while(cin >> N, N){
		int sum = 0, mx=0, ans=0;
		vector<pair<int,int> > v;

		rep(i,N){
			int r, w;
			cin >> r >> w;
			v.emplace_back(r, w);
			sum += r;
			ans += r + w;
		}

		sort( v.begin(), v.end() );
		mx = v.back().first;
		v.pop_back();

		int dp[2005]={};
		dp[0] = true;
		for(auto t: v) for(int j=1000; j>=0; j--) dp[j+t.second] |= dp[j];

		int tmp = max(0, 2*mx - sum);
		for(int i=0; !dp[tmp-i]; i++) ans++;

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

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int cost[] { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
string dp[10101];

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    vin(A, M);

    rep(i, N) dp[i] = "X"; // 初期化

    dp[0] = "";
    for (int i=0; i<N; ++i) {

        if (dp[i] == "X") continue;

        for (int j=0; j<M; ++j) {
            string tmp = dp[i];
            if (tmp == "X") tmp = "";
            tmp += to_string(A[j]);

            string now = dp[i + cost[A[j]]];
            if (now == "X") now = "";

            if (tmp.size() > now.size()) {
                dp[i + cost[A[j]]] = tmp;
            }
            else if (tmp.size() < now.size()) continue;
            else {
                int cnt1[10] = {0};
                int cnt2[10] = {0};
                rep(k, tmp.size()) {
                    cnt1[tmp[k]-'0']++;
                    cnt2[now[k]-'0']++;
                }
                for (int k=9; k>=0; --k) {
                    if (cnt1[k] == cnt2[k]) continue;
                    else if (cnt1[k] > cnt2[k]) {
                        dp[i + cost[A[j]]] = tmp;
                        break;
                    }
                    else break;
                }
            }
        }
    }

    sort(dp[N].rbegin(), dp[N].rend());
    cout << dp[N] << endl;

    return 0;
}


Measured memory_bytes: 44288