akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long int
#define ff first
#define ss second
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int cmod = 998244353;
const int N = 3e5 + 5;
const int inf = 1e18 + 2;


void solve(int Case) {
    int n ;
    cin >> n ;
    int cnt = 0 , f = 0;
    while(n --) {
        int a , b ;
        cin >> a >> b ;
        if(a == b) cnt ++ ;
        else cnt = 0 ;
        if(cnt >= 3) f = 1;
    }
    if(f) cout << "Yes" << '\n';
    else cout << "No" << '\n';
}
/*
 */

int32_t main()
{
    fastio
    int testcase = 1;
    //cin >> testcase;
    int Case = 1;
    while(testcase --) {
        solve(Case);
    }
    return 0;
}


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

  static long n, m;
  static long ans;

  public static void main(String[] args) throws Exception {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(System.out);

    String[] in = br.readLine().split(" ");
    n = Long.parseLong(in[0]);
    m = (in[1].charAt(0) - '0') * 100 + (in[1].charAt(2) - '0') * 10 + (in[1].charAt(3) - '0');

    br.close();

    out.println((m * n) / 100);

    out.flush();
  }
}


Measured memory_bytes: 32904
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k;
  cin >> n >> k;
  long long ans = 0;
  vector<int> h(n);
  for(int i=0;i<n;i++){
    cin >> h.at(i);
  }
  sort(h.begin(),h.end());
  reverse(h.begin(),h.end());
  for(int i=k;i<n;i++){
    ans += h.at(i);
  }
  cout << ans << endl;
}

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

void mergesort(std::vector<std::vector<long> > &A, std::vector<std::vector<long> > &B, long left, long right){
  int i, j;
  
  if(left >= right) return;

  long mid = (left + right) / 2;
  mergesort(A, B, left ,mid);
  mergesort(A, B, mid+1 ,right);
  i = left;
  j = mid + 1;
  int k = 0;
  while(i <= mid && j <= right){
    if(A[0][i] <= A[0][j]){
      B[0][left + k] = A[0][i];
      B[1][left + k] = A[1][i];
      i++; k++;
    }else{
      B[0][left + k] = A[0][j];
      B[1][left + k] = A[1][j];
      j++; k++;
    }
  }
  if(i == mid + 1){
    while(j <= right ){
      B[0][left + k] = A[0][j];
      B[1][left + k] = A[1][j];
      j++; k++;
    }
  }
  if(j == right + 1){
    while(i <= mid ){
      B[0][left + k] = A[0][i];
      B[1][left + k] = A[1][i];
      i++; k++;
    }
  }
  for(int l = left ; l <= right ; l++ ){
    A[0][l] = B[0][l];
    A[1][l] = B[1][l];
  }
}
  
int main(){
  long N, M;
  std::cin>>N>>M;
  std::vector<std::vector<long> > A(2, std::vector<long>(N));
  std::vector<std::vector<long> > B(2, std::vector<long>(N));

  for(int i = 0 ; i < N ; i++ ){
    std::cin>>A[0][i]>>A[1][i];
  }

  mergesort(A, B, 0, N-1);
  long Num = 0;
  long Cost = 0;
  long Shop_num = 0;
  long result = 0;
  while(Num <= M){
    if(M - Num >= A[1][Shop_num]){
      result += A[0][Shop_num] * A[1][Shop_num];
      Num += A[1][Shop_num];
    }else{
      result += A[0][Shop_num] * (M - Num);
      Num += M - Num;
    }
    Shop_num++;
    if(Num == M) break;
  }
  std::cout<<result<<std::endl;
  return 0;
}


Measured memory_bytes: 4208
n=int(input())
x=[int(x) for x in input().split()]
x.sort(reverse=True)
ans=x[0]
c=1
for i in range(1,n):
    if c+2<n:
        c+=2
        ans+=2*x[i]
    else:break
if c<n-1:
    ans+=x[i]
print(ans)

Measured memory_bytes: 94220
#include<stdio.h>
#include<string.h>
int main(){
  int i=0,n=0,m=0,h=0,m2=0,m3=1;
  char s[4];
  scanf("%d",&n);
for(i=1;i<=n;i++){
  h=i;
  m=0;
  do{
    if(h%2==0){
      h=h/2;
      m++;
    }
    if(h%2==1)
      break;
  }while(1);
  if(m2<m){
    m2=m;
    m3=i;
}
}
  
    printf("%d",m3);
  return 0; 
}

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

#define ll long long
#define inf 0x3f3f3f3f
const int maxn=1e5+5;
#define mod 1000000007
/*int head[maxn],ver[maxn],nxt[maxn],tot,edge[maxn];
bool vis[maxn];
int d[maxn],ans;
void add(int x,int y)
{
    ver[++tot]=y;
    edge[tot]=1;
    nxt[tot]=head[x];
    head[x]=tot;
}
void dp(int x)
{
    vis[x]=1;
    for(int i=head[x];i;i=nxt[i])
    {
        int y=ver[i];
        if(vis[y])continue;
        dp(y);
        ans=max(ans,d[x]+d[y]+edge[i]);
        d[x]=max(d[x],d[y]+edge[i]);
    }
}*/

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

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

int main() {
  string s, t;
  cin >> s >> t;

  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());

  if (s < t) {
    cout << "Yes" << endl;
  } else {
        cout << "No" << endl;
  }

  return 0;
}

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

vector<long long> num_divisors_table(long long n){
    vector<long long> table(n+1, 0);

    for(long long i = 1; i <= n; i++){
        for(long long j = i; j <= n; j = j+ i){
            table[j] += 1;
        }
    }
    return table;
}

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

    vector<long long> table;
    table = num_divisors_table(n);

    long long ans = 0;
    for(long long i = 1; i <= n-1; i++){
        //printf("i %lld %lld\n", i, table[i]);
        ans += table[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11172
# -*- coding: utf-8 -*-
from collections import deque
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

N, M, P = inpl()
INF = 10**12
G = [[] for _ in range(N)]
E = []
G2 = [[] for _ in range(N)]
rG2 = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = inpl()
    G[a-1].append([b-1, -c+P])
    G2[a-1].append(b-1)
    rG2[b-1].append(a-1)
    E.append([a-1, b-1, -c+P])


def SCC(G, rG):
    N = len(G)
    def dfs(i):
        nonlocal t, rorder, searched
        searched[i] = True
        for j in G[i]:
            if not searched[j]:
                dfs(j)
        rorder[t] = i
        t += 1

    def rdfs(i):
        nonlocal t, group, g
        group[i] = g
        for j in rG[i]:
            if group[j] == -1:
                rdfs(j)

    t = 0
    rorder = [-1]*N
    searched = [0]*N
    group = [-1]*N

    for i in range(N):
        if not searched[i]:
            dfs(i)
    g = 0
    for i in range(N-1, -1, -1):
        if group[rorder[i]] == -1:
            rdfs(rorder[i])
            g += 1
    return group, g


def belman_ford(V, edges, r):
    "If glaph contains negative cycles then return True"
    D = [INF]*(V)
    D[r] = 0
    if V == 1:
        return False, [0]
    OK = True
    for _ in range(V-1):
        update = False
        for s, t, d in edges:
            if D[t] > D[s] + d:
                D[t] = D[s] + d
                update = True
        if not update:
            OK = False
    return OK, D

group, gsize = SCC(G2, rG2)
groups = [[] for _ in range(gsize)]
for i in range(N):
    groups[group[i]].append(i)

score = [10**12 for _ in range(N)]
negative_groups = [0]*N


for g in range(gsize):
    ggs = set(groups[g])
    s = groups[g][0]
    score[s] = 0
    Q = deque([s])
    while Q:
        p = Q.popleft()
        for q, c in G[p]:
            if not q in ggs:
                continue
            if score[p] + c < score[q]:
                score[q] = score[p] + c
                Q.append(q)
        if score[s] < 0:
            for g in ggs:
                negative_groups[g] = 1
            break

s = 0
Q = deque([s])
reach1 = [0]*N
reach1[0] = 1

while Q:
    p = Q.popleft()
    for q in G2[p]:
        if not reach1[q]:
            reach1[q] = 1
            Q.append(q)

s = N-1
Q = deque([s])
reachN = [0]*N
reachN[-1] = 1

while Q:
    p = Q.popleft()
    for q in rG2[p]:
        if not reachN[q]:
            reachN[q] = 1
            Q.append(q)

NEGATIVE, D = belman_ford(N, E, 0)

if any([reach1[i]&reachN[i]&negative_groups[i] for i in range(N)]) or reach1[-1]==0:
    print(-1)
else:
    print(max(0, -D[-1]))


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


int main() {
	int N, X, Y;
	cin >> N >> X >> Y;
	vector<int> ans(N, 0);

	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if ((j + 1 > X)) {
				int num1 = j - i;
				int num2 = abs(X - i - 1) + 1 + abs(Y - j - 1);
				/*cout << "unko2" << endl;
				cout << i << "," << j << endl;
				cout << num1 << "," << num2 << endl;*/
				if (num1 >= num2) {
					ans[num2 - 1]++;
					//cout << num2 << "加算" << endl;
				}
				else {
					ans[num1 - 1]++;
					//cout << num1 << "加算" << endl;
				}
			}
			else {
				/*cout << "unko" << endl;
				cout << i << "," << j << endl;*/
				ans[j - i - 1]++;
				//cout << j - i << "加算" << endl;
			}
		 }
	}

	for (int i = 0; i < N - 1; i++)cout << ans[i] <<  endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i=0; i<n; i++)
#define loop(i, j, n) for(int i=j; i<n; i++)
using namespace std;

typedef struct{
	int c;
	int t;
}Data;
int main()
{
	int  n, T, min = 10000;
	cin >> n >> T;
	Data k[n];

	rep(i,n){
		cin>> k[i].c >> k[i].t;
	}

	rep(i,n){
		if(k[i].t <= T){
			if(k[i].c <= min) min = k[i].c;
		}
	}
	if(min == 10000){
		cout << "TLE" <<endl;
	}else{
		cout << min <<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
int F[100][5][2];
int P[100][11];
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 5; j++) {
			cin >> F[i][j][0] >> F[i][j][1];
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= 10; j++) {
			cin >> P[i][j];
		}
	}
	int ans = -(1 << 30);
	for (int bit = 1; bit < (1 << 10); bit++) {
		int sum = 0;
		for (int i = 0; i < N; i++) {
			int cnt = 0;
			for (int j = 0; j < 10; j++) {
				if ((bit&(1 << j)) && F[i][j / 2][j % 2]) cnt++;
			}
			sum += P[i][cnt];
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
}

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

using namespace std;

int N, a[109];
const int K = 10000;
int dp[2][K + 10];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    scanf ("%d", &a[i]);
for (int i=1; i<=N; i++)
{
    int curr = 2 * N;
    for (int j=1; j<=K; j++)
        dp[i & 1][j] = curr,
        curr = min (curr, dp[(i & 1) ^ 1][j]);
    curr = 2 * N;
    for (int j=K; j>=1; j--)
        dp[i & 1][j] = min (dp[i & 1][j], curr),
        curr = min (curr, dp[(i & 1) ^ 1][j]),
        dp[i & 1][j] += (j != a[i]);
}
int ans = 2 * N;
for (int i=1; i<=N; i++)
    if (dp[N & 1][i] < ans)
        ans = dp[N & 1][i];
printf ("%d\n", ans);

return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<queue>
using namespace std;
int m[1000][1000],p[1000][1000]={0};
int main(){
int i,j,w,h,n,k,b[2]={1,-1},g=0,u=0,l=0,z=0;
char s[2001];
pair<int,int> e;
queue<pair<int,int> > q;
cin>>h>>w;
for(i=0;i<h;i++){
	scanf("%s",s);
	for(j=0;j<w;j++){
		k=s[j];
		if(k>48&&k<58)m[i][j]=k-48;
		else m[i][j]=0;
	}
}
for(i=1;i<h-1;i++){
	for(j=1;j<w-1;j++){
		if(m[i][j]!=0){
		for(n=i-1;n<=i+1;n++){
			for(k=j-1;k<=j+1;k++){
				if(m[n][k]==0)p[i][j]++;
			}
		}
		if(m[i][j]<=p[i][j]){
			e.first=i;
			e.second=j;
			q.push(e);
			z++;
		}
		}
	}
}
for(i=0;i<z;i++){
e=q.front();
q.pop();
m[e.first][e.second]=0;
q.push(e);
}
while(!q.empty()){
	e=q.front();
	q.pop();
	m[e.first][e.second]=-1;
	for(i=e.first-1;i<=e.first+1;i++){
		for(j=e.second-1;j<=e.second+1;j++){
			p[i][j]++;
		}
	}
if(z==l){
	z=u;
	l=0;	u=0;
	g++;
	}
l++;
	for(i=0;i<2;i++){
		if(m[e.first+b[i]][e.second]<=p[e.first+b[i]][e.second]&&m[e.first+b[i]][e.second]>0){
			e.first+=b[i];	m[e.first][e.second]=0;
			q.push(e);
			e.first-=b[i];
			u++;
		}
		if(m[e.first+b[i]][e.second+b[i]]<=p[e.first+b[i]][e.second+b[i]]&&m[e.first+b[i]][e.second+b[i]]>0){
			e.first+=b[i];
			e.second+=b[i];	m[e.first][e.second]=0;
			q.push(e);
			e.first-=b[i];
			e.second-=b[i];
			u++;
		}
		if(m[e.first][e.second+b[i]]<=p[e.first][e.second+b[i]]&&m[e.first][e.second+b[i]]>0){
			e.second+=b[i];	m[e.first][e.second]=0;
			q.push(e);
			e.second-=b[i];
			u++;
		}
		if(m[e.first+b[i]][e.second-b[i]]<=p[e.first+b[i]][e.second-b[i]]&&m[e.first+b[i]][e.second-b[i]]>0){
			e.first+=b[i];
			e.second-=b[i];	m[e.first][e.second]=0;
			q.push(e);
			e.first-=b[i];
			e.second+=b[i];
			u++;
		}
	}
}
g++;
cout<<g<<endl;
return 0;
}

Measured memory_bytes: 11032
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 100005;

int n, a, b, w, deg[N], tab[N], res[N], i, ind, rr;
VI graf[N];
queue<int> kol;

int main() {
scanf("%d", &n);
for (i=1;i<n;i++) {
	scanf("%d %d", &a, &b);
	graf[a].pb(b);
	graf[b].pb(a);
	deg[a]++;
	deg[b]++;
}
rr = 0;
for (i=0;i<n;i++) {
	scanf("%d", &tab[i]);
	rr += tab[i];
}
ind = 0;

sort(tab, tab + n);
rr -= tab[n - 1];
while (!kol.empty()) kol.pop();
for (i=1;i<=n;i++) if (deg[i] == 1) kol.push(i);
while (!kol.empty()) {
	w = kol.front();
	kol.pop();
	res[w] = tab[ind];
	ind++;
	for (auto& d : graf[w]) {
		deg[d]--;
		deg[w]--;
		if (deg[d] == 1) kol.push(d);
	}
}
printf("%d\n", rr);
for (i=1;i<=n;i++) printf("%d ", res[i]);
printf("\n");
}




Measured memory_bytes: 3200
s = list(input())
n = len(s)
k = int(input())
flg = 1
for i in range(n - 1):
    if s[i] != s[i + 1]:
        flg = 0
if flg:
    print(n * k // 2)
    exit(0)
t = s + s
tmp1 = 0
for i in range(n * 2 - 1):
    if t[i] == t[i + 1]:
        tmp1 += 1
        t[i + 1] = 'X'
tmp2 = 0
for i in range(n - 1):
    if s[i] == s[i + 1]:
        tmp2 += 1
        s[i + 1] = 'X'
tmp3 = tmp1 - tmp2 * 2
print(tmp3 * (k - 1) + tmp2 * k)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int sw[1 << 10];
bool l[11][11];
int o[11];
int main() {
  int n,m;
  int ans = 0;
  cin >> n >> m;

  for(int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for(int j = 0; j < k; j++) {
      int s;
      cin >> s;
      s--;
      l[i][s] = true;
    }
  }

  for(int i = 0; i < m; i++) cin >> o[i];

  for(int i = 0; i < (1 << n); i++) {
    bool ok = true;
    for(int j = 0; j < m; j++) {
      int tmp = 0;
      for(int k = 0; k < n; k++) {
	if(!l[j][k]) continue;
	
	if((i >> k) & 1) tmp++;
      }
      if(tmp % 2 != o[j]) {
	ok = false;
	break;
      }
    }
    if(ok) ans++;
  }

  cout << ans << endl;
}
    
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){
    
    string S;
    int N,ans,min,tmp=0,W[300000]={},E[300000]={},T[300000]={};

    cin >> N;
    cin >> S;

    min=N;

    for(int i=0;i<N;i++){
        W[i]=tmp;

        if(S[i]=='W'){
            tmp+=1;
        }
    }
        
    tmp=0;

    for(int i=N;i>=0;i--){
        E[i]=tmp;

        if(S[i]=='E'){
            tmp+=1;
        }
    }

    for(int i=0;i<N;i++){
        T[i]=W[i]+E[i];
        if(T[i]<min){
            min=T[i];
        }
    }

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 3204
arr1 = str(input())
arr = arr1.split()
health = int(arr[0])
nAttack = int(arr[1])

totalAttack = str( input() )
tAttack = totalAttack.split()

total = 0

for i in tAttack:
    total += int(i)

if health > total:
    print("No")
else:
    print("Yes")
    

Measured memory_bytes: 52208
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
// #define first first
// #define second se
using namespace std;
typedef pair<int, int> P;
typedef vector<int> vi;

int ans = 0;
int n, s;

void dfs(int k, int used, int sum){
    if(used == n && sum == s) ans++;
    if(used == n || k >= 10) return;
    dfs(k + 1, used + 1, sum + k);
    dfs(k + 1, used, sum);
    return;
}

signed main(){
    while(1){
        cin >> n >> s;
        if(n + s == 0) break;
        ans = 0;
        dfs(0, 0, 0);
        o(ans);
    }
}

Measured memory_bytes: 2988
#include <stdio.h>
#include <string.h>
typedef long long ll;
#define rep(i,l,r) for(int i=l; i<(int)(r); i++)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)

int A[105][105];

int main(){
    int A, B, C, X ,Y;
    scanf("%d%d%d%d%d", &A, &B, &C, &X, &Y);
    
    int ans = min(A*X+B*Y, min(2*C*max(X, Y), 2*C*min(X, Y)+(X>Y?(X-Y)*A:(Y-X)*B)));

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

Measured memory_bytes: 1696
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+9;
bool vst[N]; int cnt,pr[N],num[N],ans;
signed main(){
	int n; cin>>n;
	for(int i=2;i<=1000000;i++){
		if(vst[i]) continue;
		pr[++cnt]=i;
		for(int j=2;j<=1000000/i;j++) vst[i*j]=1;
	}
	for(int i=1;i<=cnt;i++){
		int p=pr[i];
		while(n%p==0){
			n/=p,num[i]++;
		}
		int a=sqrt(num[i]*2);
		if(a*(a+1)>num[i]*2) a--;
		ans+=a;
	}
	if(n!=1) ans++;
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int S, h, l, m, s;
    cin >> S;
    h = S / 3600;
    l = S % 3600;
    m = l / 60;
    s = l % 60;
    cout << h <<":"<< m << ":" << s  << endl;
    return 0;
}


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

x = []
y = []
rdown = []
ldown = []
for i in range(n):
    i1, i2 = map(int, input().split())
    x.append(i1)
    y.append(i2)
    rdown.append(i1+i2)
    ldown.append(i1-i2)

ans1 = max(ldown)-min(ldown)
ans2 = max(rdown)-min(rdown)

ans = max(ans1,ans2)

print(ans)

Measured memory_bytes: 40912
def main():
    N = int(input())
    S = [int(input()) for _ in range(N)]
    ans = sum(S)
    if ans % 10 == 0:
        mn = ans
        for s in S:
            if s % 10 != 0 and s < mn:
                mn = s
        ans -= mn
    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

int N;
long long K;
vector<int> P;
vector<long long> C;

int main()
{
	cin >> N;
	cin >> K;
	P = vector<int>(N+1);
	C = vector<long long>(N+1);
	auto f = vector<bool>(N + 1, true);
	for (int i = 1; i <= N; i++) {
		cin >> P[i];
	}
	for (int i = 1; i <= N; i++) {
		cin >> C[i];
	}

	long long ans = C[1];

	for (int i = 1; i <= N; i++) {
		if (f[i]) {
			f[i] = false;
			int sn = 1;
			long long ss = C[i];
			int p = P[i];
			auto sa = vector<int>();
			sa.push_back(i);

			while (p != i) {
				f[p] = false;
				ss += C[p];
				sn++;
				sa.push_back(p);
				p = P[p];
			}

			long long sb = 0;
			int k = sn-1;
			if (K < k) { k = (int)K; }
			if (ss > 0) {
				sb = ss * (K / (long long)sn);
				k = K % (long long)sn;

				if (k == 0) {
					sb-=ss;
					k = sn;
				}
			}

			auto ad = vector<long long>(sn,0);
			for (int j = 1; j <= k; j++) {
				for (int n = 0; n < sn; n++) {
					ad[n] += C[sa[(n+j)%sn]];

					ans = max(ans,sb + ad[n]);
				}
			}


		}
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3812
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

struct drink {
    int price;
    int stock;
};

int asc_by_price(const void *a1, const void *a2) {
    struct drink *d1 = (struct drink*)a1;
    struct drink *d2 = (struct drink*)a2;
    return d1->price - d2->price;
}

#define NUM_MAX 100000

int main(void) {
    int num, llimit;
    static struct drink drinks[NUM_MAX];
    get_int2(&num, &llimit);
    int i;
    for(i = 0; i < num; i++) {
        get_int2(&drinks[i].price, &drinks[i].stock);
    }
    qsort(drinks, num, sizeof(struct drink), asc_by_price);

    int64_t cost = 0;
    for(i = 0; i < num; i++) {
        if(llimit <= 0) break;
        int n = min(llimit, drinks[i].stock);
        cost += (int64_t)drinks[i].price * n;
        llimit -= n;
    }
    printf("%lld\n", cost);
    return 0;
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
#define PR(x) cout << (x) << "\n"
#define PS(x) cout << (x) << " "
const long long INF = numeric_limits<long long>::max();
int main() {
    ll N;
    cin >> N;

    vector<ll> monsters(N + 1);
    REP(i, monsters.size()) {
        cin >> monsters[i];
    }

    vector<ll> heros(N);
    REP(i, N) {
        cin >> heros[i];
    }

    ll ans = 0;

    REP(i, N) {
        ll m = min(monsters[i], heros[i]);
        ans += m;
        heros[i] -= m;
        m = min(monsters[i + 1], heros[i]);
        ans += m;
        monsters[i + 1] -= m;
    }

    PR(ans);

    return 0;
}

Measured memory_bytes: 4832
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;

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

	cin >> N >> M >> L >> R;
	while (N) {
		if (M*L - N <= 0) {
			cout << "0\n";
		}
		else {
			K = (M*L - N) / R;
			if ((M*L - N) % R)K++;
			cout << K << endl;
		}
		cin >> N >> M >> L >> R;
	}
	return 0;
}

Measured memory_bytes: 3100
// Bismillahir Rahmanir Rahim .Ya Allah...
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mod = 1e9+7,INF = 1e9;
const int mx = 1e5+5;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans1=0,ans2=0;
    ans1 = a*c;
    ans2= b*d;
    ll ans3 = a*d;
    ll ans4 = b*c;
    cout<<max({ans1,ans2,ans3,ans4})<<endl;
    return 0;
}



Measured memory_bytes: 3644
n = int(input())
s = list(map(int,input().split()))

ans = 0
c = {}
for i in s:
    if i not in c:
        c[i] = 1
    elif c[i] < i:
        c[i] += 1
    else:
        ans += 1

for k,v in c.items():
    if k != v:
        ans += v
print(ans)


Measured memory_bytes: 17780
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	// fmt.Println(n)

	var i int64
	var a []int64
	for i = 1; i <= n; i++ {
		ai := nextInt()
		// fmt.Println(ai)
		if ai == 0 {
			fmt.Println(0)
			return
		}
		a = append(a, ai)
	}

	var ret int64 = 1
	for _, ai := range a {
		ret = ret * ai
		// fmt.Println(ret)
		if ret > 1000000000000000000 || ret <= 0 {
			fmt.Println(-1)
			return
		}
	}
	fmt.Println(ret)

}

func nextInt() int64 {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return int64(i)
}


Measured memory_bytes: 6948
#include <iostream>
using namespace std;
const long long mod = 1000000007LL;
long long powmod(long long x, long long y){
    long long res = 1;
    for ( long long i=0; i<y; i++ ) {
        res = res * x % mod;
    }
    return res;
}
int main(){
    long long n;
    cin >> n;
    long long ans = powmod(10,n) - powmod(9,n) - powmod(9,n) + powmod(8,n);
    ans %= mod;
    ans = (ans + mod) % mod;
    cout << ans << endl;
}

Measured memory_bytes: 3500
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include <string.h>
using namespace std;
int main(){
	int t,ans;
	for(int i=0;i<4;i++){
		cin>>t;
		ans+=t;
	}
	cout<<ans/60<<endl;
	cout<<ans%60<<endl;		
}

Measured memory_bytes: 1160
N,K=map(int,input().split())
_=input().split()
S=[]
for s in _:
    S.append((int(s)+1)/2) #初めから期待値で配列作成

maxsum=sum(S[0:K])
tempsum=maxsum

for i in range(N-K):
    tempsum=tempsum-S[i]+S[i+K]
    if maxsum<tempsum:
        maxsum=tempsum
    else:
        pass

print(maxsum)

Measured memory_bytes: 24684
N, M = map(int, input().split())
ans = 0
mod = 10**9+7
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

fac = [0]*(M+1)
fac[0] = 1
fac[1] = 1
for i in range(2,M+1):
    fac[i] = fac[i-1] * i % mod
#nCr (mod p)
def combi(n,r,mod=10**9+7):
    return( ( fac[n] * modinv(fac[r]) )%mod * modinv(fac[n-r]) % mod)

for k in range(N+1):
    ans += (fac[M-k]*modinv(fac[M-N])) % mod * combi(N, k) * (-1)**k
    ans %= mod

print(ans*fac[M]*modinv(fac[M-N]) % mod)

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

int main() {
    int x, n;
    cin >> x >> n;
    vector<int> p(n);
    for(auto& e : p) cin >> e;
    int ans = 1e9;
    for(int i = -100; i <= 101; i++){
        bool flag = true;
        for(int j = 0; j < n; j++){
            if(i == p[j]){
                flag = false;
                break;
            }
        }
        if(!flag) continue;
        if(abs(x - i) < abs(x - ans)){
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main()
{
    int n;
    cin >> n;
    vector<vector<int>> v(n);
    vector<int> ans(n);
    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        v[a - 1].push_back(b - 1);
        v[b - 1].push_back(a - 1);
    }
    vector<int> c(n);
    rep(i, n)
    {
        cin >> c[i];
    }
    sort(c.begin(), c.end());
    ll s = -c.back();
    for (int i = 0; i < n; i++)
    {
        s += c[i];
    }
    cout << s << endl;
    queue<int> que;
    for (int i = n - 1; i >= 0; i--)
    {
        que.push(c[i]);
    }
    queue<int> que2;
    que2.push(0);
    while (!que2.empty())
    {
        int it = que2.front();
        que2.pop();
        ans[it] = que.front();
        que.pop();
        for (auto i : v[it])
        {
            if (ans[i] == 0)
            {
                que2.push(i);
            }
        }
    }
    rep(i, n)
    {
        cout << ans[i] << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

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

        int nCount = 0;
        int mCount = 0;

        if (n >= 2){
           nCount = (n * (n-1))/2;
        }
        if (m >= 2){
            mCount = (m * (m-1))/2;
        }
        System.out.println(nCount + mCount +"");
    }
}

Measured memory_bytes: 22356
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<iomanip>

using namespace std;

vector<string> get_substrings(string s, int max_length=0) {
    set<string> set_substrs;
    if(max_length==0) {
        max_length = s.length();
    } else {
        max_length = min(max_length, (int)s.length());
    }
    for(int i=1; i<=max_length; ++i) {
        // 部分文字列の長さが i の文字列を作成
        for(int j=0; j<=s.length()-i; ++j) {
            string substr = s.substr(j, i);
            set_substrs.insert(substr);
        }
    }
    vector<string> substrs;
    for(auto str:set_substrs) {
        substrs.push_back(str);
    }
    return substrs;
}

int main() {
    int n;
    string s;
    cin >> n;
    cin >> s;
    int ans=0;
    for(int i=1; i<=s.length(); ++i) {
        // 部分文字列の長さが i の文字列を作成
        for(int j=0; j<=s.length()-i; ++j) {
            string substr = s.substr(j, i);
            if(substr=="ABC") {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int N, W;
int w[110], v[110];
int dp[110][110][310];

signed main() {
    cin >> N >> W;
    repq(i,1,N) cin >> w[i] >> v[i];
    int flr = w[1];
    int sum = 0;
    repq(i,1,N) {
        w[i] -= flr;
        sum += w[i];
    }
    memset(dp, 0, sizeof(dp));
    int ans = 0;
    repq(i,1,N) repq(j,1,i) repq(k,0,300) {
        dp[i][j][k] = dp[i-1][j][k];
        // printf("i = %lld, j = %lld, k = %lld, flr = %lld\n", i, j, k, flr);
        if(k-w[i] >= 0 && k + j * flr <= W)
            dp[i][j][k] = max(dp[i][j][k], dp[i-1][j-1][k-w[i]] + v[i]);
        if(i == N) ans = max(ans, dp[i][j][k]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 29568
def generateBin(m, t):
    l = list(t)
    bin_num = 0
    for i in range( m):
        if l.count(i+1) == 1:
            bin_num += 1<< i
    return bin_num

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

ans = 0
for i in range( m):
    ans += 1 << i

bin_n =0
for i in range(n):
    k,*t = tuple(map(int,input().split()))
    bin_n = generateBin(m, t)
    ans = ans & bin_n

print('{:b}'.format(ans).count('1'))



Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(ll i=0;i<n;i++)
#define PRN(n) printf("%lld\n",n)
#define PRF(f) printf("%lf\n",f)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define N 100001
typedef long long int ll;
ll x[N];
int main(){
  ll n,k,a,b,sum=0;
  scanf("%lld %lld",&n,&k);
  FOR(n){
    scanf("%lld %lld",&a,&b);
    x[a]+=b;
  }
  FOR(N){
    sum+=x[i];
    if(sum>=k){
      PRN(i);
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 896
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] a = new long[N];
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextLong();
        }
        long[][] dp = new long[N][2];
        dp[0][0] = a[0];
        dp[0][1] = -a[0];
        for (int i = 1; i < N - 1; i++) {
            dp[i][0] = Math.max(dp[i-1][0] + a[i], dp[i-1][1] - a[i]);
            dp[i][1] = Math.max(dp[i-1][0] - a[i], dp[i-1][1] + a[i]);
        }
        long answer = dp[N-2][0]+a[N-1];
        answer = Math.max(answer, dp[N-2][1]-a[N-1]);
        System.out.println(answer);
    }
}


Measured memory_bytes: 50536
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const ll N=1e5+5;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll x;cin>>x;
    for(ll sum=100,ans=1;;ans++){
        ll val = sum/100;
        sum+=val;
        if(sum>=x)return cout<<ans , 0;
    }
}


Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>

using namespace std;

int main(void){
	
	static int h,w,n,grid[1002][1002],dp[1002][1002];

	while(cin >> h >> w >> n,h|w|n){
		for(int i=1;i<=h;i++)
			for(int j=1;j<=w;j++)
				cin >> grid[i][j];
		
		fill(dp[0],dp[1002],0);
		dp[1][1]=n-1;
		
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				dp[i][j+1]+=(dp[i][j]+grid[i][j])>>1;
				dp[i+1][j]+=(dp[i][j]+!grid[i][j])>>1;
			}
		}
		
		for(int i=1;i<=h;i++){
			for(int j=0;j<=w;j++){
				if(dp[i][j]%2)grid[i][j]^=dp[i][j]&1;
			}
		}
		
		int x=1,y=1;
		while(true){
			if(y>h || x>w)break;
			if(grid[y][x])x++;
			else y++;
		}
		
		cout << y << " " << x << endl;
		
	}
	
	return 0;
}

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

class position{
public:
  int x,y;
};

int main(){
  int n,a,b,c,d;
  cin>>n>>a>>b>>c>>d;
  position A,B,C,D;
  priority_queue<long long,vector<long long>,greater<long long> > que;
  for(int w=1;w<=n;w++){
    int cnt=0;
    int check=0;
    for(int i=0;i<101;i++){
      for(int j=0;j<w;j++){
	cnt++;
	if(cnt==a){
	  A.x=j;
	  A.y=i;
	  check++;
	}
	if(cnt==b){
	  B.x=j;
	  B.y=i;
	  check++;
	}
	if(cnt==c){
	  C.x=j;
	  C.y=i;
	  check++;
	}
	if(cnt==d){
	  D.x=j;
	  D.y=i;
	  check++;
	}
	if(check==4)break;
      }
      if(check==4)break;
    }
    long long dis=fabs(A.x-B.x)+fabs(A.y-B.y)+fabs(C.x-D.x)+fabs(C.y-D.y);
    que.push(dis);
  }
  cout<<que.top()<<endl;
  return 0;
}

Measured memory_bytes: 1212
import java.util.*;


public class Main {
	
	void AOJ0150(){
		int MAX=10000;
		boolean[] list = new boolean[MAX+1];
		Arrays.fill(list, true);
		boolean[] flag = new boolean[MAX+1];
		Arrays.fill(flag, false);
		int last = -1;
		for(int i=2; i<=MAX; i++){
			if(list[i]){
				if(i-last == 2)	flag[i]=true;
				last=i;
				for(int j=i+i; j<=MAX; j+=i)	list[j]=false;
			}
		}
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			if(n==0)	break;
			for(int i=n; i>0; i--){
				if(flag[i]){
					System.out.println(i-2+" "+i);
					break;
				}
			}
			//debug
			//System.out.println(-1);
		}
	}
	
	void AOJ0053(){
		int MAX = 10000000;
		boolean[] list = new boolean[MAX+1];
		Arrays.fill(list, true);
		int count=1;
		long[] sum = new long[10001];
		sum[0]=0;
		for(int i=2; i<=MAX; i++){
			if(list[i]){
				sum[count] = sum[count-1]+(long)i;
				count++;
				for(int j=i+i; j<=MAX; j+=i)	list[j]=false;
			}
			if(count>10000) break;
		}
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			if(n==0)	System.exit(0);
			System.out.println(sum[n]);
		}
	}
	
	void AOJ0044(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			for(int i=n-1; i>1; i--){
				if(isPrime(i)){
					System.out.print(i+" ");
					break;
				}
			}
			for(int i=n+1; ; i++){
				if(isPrime(i)){
					System.out.println(i);
					break;
				}
			}
		}
	}
	
	void AOJ0009(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int count=0;
			boolean[] prime = new boolean[n+1];
			Arrays.fill(prime, true);
			for(int i=2; i<=n; i++){
				if(prime[i]){
					count++;
					for(int j=i+i; j<=n; j+=i)	prime[j]=false;
				}
			}
			System.out.println(count);
		}
	}
	
	ArrayList<Integer> Sieve(int n){
	     ArrayList<Integer> prime = new ArrayList<Integer>();
	     if(n<2)	return prime;
	     boolean[] list = new boolean[n];
	     Arrays.fill(list, true);
	     list[1]=false;
	     for (int i=2; i<n; i++) {
	          if (list[i]) {
	               prime.add(i);
	               for (int j=i+i; j<n; j+=i)	list[j] = false;
	          }
	     }
	     return prime;
	}
	
	boolean isPrime(int n){
		for(int i=2; i*i<=n; i++){
			if(n%i==0)	return false;
		}
		return true;
	}

	public static void main(String[] args) {
		new Main().AOJ0150();
	}

}

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

using namespace std;
typedef double ll;

const unsigned int MAX = (ll)1002;
ll dp[301][301][301];
ll func(int z, int a, int b, int c, int n, int s)
{
    if (z == n)
    {
        return 0;
    }
    if (a < 0 || b < 0 || c < 0)
    {
        return 0;
    }
    if (a + b + c > n)
    {
        return 0;
    }
    if (dp[a][b][c] != -1)
    {
        return dp[a][b][c];
    }
    else
    {
        return dp[a][b][c] = (1.0 + ((ll)a) * func(z + 1, a - 1, b, c, n, s - 1) / n + ((ll)b) * func(z, a + 1, b - 1, c, n, s - 1) / n + ((ll)c) * func(z, a, b + 1, c - 1, n, s - 1) / n) / (((ll)n - z) / n);
    }
}

int main()
{
    int n;
    cin >> n;
    vector<int> ar(n);
    int s = 0;
    int c1 = 0, c2 = 0, c3 = 0;
    for (int x = 0; x < n; x++)
    {
        cin >> ar[x];
        if (ar[x] == 1)
        {
            c1++;
        }
        else if (ar[x] == 2)
        {
            c2++;
        }
        else if (ar[x] == 3)
        {
            c3++;
        }
        s += ar[x];
    }
    for (int a = 0; a < 301; a++)
    {
        for (int b = 0; b < 301; b++)
        {
            for (int c = 0; c < 301; c++)
            {
                dp[a][b][c] = -1;
            }
        }
    }
    func(0, c1, c2, c3, n, s);
    cout << setprecision(12) << dp[c1][c2][c3] << endl;
}

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

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

	int a=100000;

	for(int i=0;i<n;i++){
		a*=1.05;
		if(a%1000 != 0){
			a+=(1000 - (a%1000));
		}
	}

	printf("%d\n",a);

    return 0;
}


Measured memory_bytes: 2120
(let* ((n (read))
       (a (make-array n :element-type 'integer
                        :fill-pointer 0
                        :adjustable t))
       (ans 0))
  (dotimes (i n)
    (setf (aref a i) (read))
    (if (> i 0) (setf (aref a i) (+ (aref a i) (aref a (- i 1))))))
  (setf ans (+ (aref a 0) (read)))
  (loop for i from 1 below n
        do (setf ans (+ (max ans (aref a i)) (read))))
  (format t "~A~%" ans))


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

int checkrow(vector<string>& s, int r, int c, vector<vector<int>>& v) {
  if (v.at(r).at(c) != -1) {
    return v.at(r).at(c);
  } else {
    int res1 = 0;
    if (c > 0) {
      for (int i = c - 1; i >= 0; i--) {
        if (s.at(r).at(i) == '.') {
          res1++;
        } else {
          break;
        }
      }
    }
    int res2 = 0;
    if (c < s.at(0).size() - 2) {
      for (int i = c + 1; i < s.at(0).size(); i++) {
        if (s.at(r).at(i) == '.') {
          res2++;
        } else {
          break;
        }
      }
    }
    int res = res1 + res2;
    for (int i = c - res1; i < c + res2 + 1; i++) {
      v.at(r).at(i) = res;
    }
    return res;
  }
}

int checkcol(vector<string>& s, int r, int c, vector<vector<int>>& v) {
  if (v.at(r).at(c) != -1) {
    return v.at(r).at(c);
  } else {
    int res1 = 0;
    if (r > 0) {
      for (int i = r - 1; i >= 0; i--) {
        if (s.at(i).at(c) == '.') {
          res1++;
        } else {
          break;
        }
      }
    }
    int res2 = 0;
    if (r < s.size() - 2) {
      for (int i = r + 1; i < s.size(); i++) {
        if (s.at(i).at(c) == '.') {
          res2++;
        } else {
          break;
        }
      }
    }
    int res = res1 + res2;
    for (int i = r - res1; i < r + res2 + 1; i++) {
      v.at(i).at(c) = res;
    }
    return res;
  }
}

int main() {
  int H, W;
  cin >> H >> W;

  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S.at(i);
  }

  int maximum = 0;
  vector<vector<int>> vc(H, vector<int>(W, -1));
  vector<vector<int>> vr(H, vector<int>(W, -1));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S.at(i).at(j) == '.')
        maximum =
            max(maximum, 1 + checkcol(S, i, j, vc) + checkrow(S, i, j, vr));
    }
  }

  cout << maximum << endl;
}

Measured memory_bytes: 35712
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[21];
	int ans=0,t;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		t=0;
		for(int j=1;j<i;j++)
		{
			if(a[i]<a[j]) t++;
		}
		if(t==0) ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int A,B,C,X,Y;
int main(){
    cin >> A >> B >> C >> X >> Y;
    if(A + B < 2*C){
        cout << A*X + B*Y << endl;
    }else{
        if(X >= Y && A <= 2*C){
            cout << C * 2 * Y + A * (X - Y) << endl;
        }else if(Y > X && B <= 2*C){
            cout << C * 2 * X + B * (Y - X) << endl;
        }else if(X >= Y && A > 2*C){
            cout << C * 2 * X << endl;
        }else if(Y > X && B > 2*C){
            cout << C * 2 * Y << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
    
#pragma endregion library
ll n,a,b,c,d;
map<ll,ll> m; // LINF-val
ll dfs(ll x){
    if(m.count(x)) return m[x];
    if(x==1) return d;
    if(x==0) return 0;
    ll res;
    if(x<=LINF/d) res=x*d;
    else res=LINF;
    repi(i,-4,5){
        ll y=x+i;
        if(y<0) continue;
        ll dcost = abs(i)*d;
        if(y%2==0&&abs(i)<2) res=min(res,dfs(y/2)+a+dcost);
        if(y%3==0&&abs(i)<3) res=min(res,dfs(y/3)+b+dcost);
        if(y%5==0&&abs(i)<5) res=min(res,dfs(y/5)+c+dcost);
    }
    m[x]=res;
    return res;
}

int main(){
    int t; cin >> t;
    while(t--){
        cin >> n >> a >> b >> c >> d;
        m.clear();
        cout << dfs(n) << '\n';
        
    }
}

Measured memory_bytes: 4392
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int a,b,c;
 int x,y,z,e;
 cin>>a>>b>>c;
 x=max(a,b);
 y=max(x,c);
 z=min(x,c);
 e=min(a,b);
  cout<<y*10+z+e;
     return 0;
}


Measured memory_bytes: 256
#include<iostream>
    using namespace std;
    int main()
    {
      long A;
      string X;
      cin >> A;
      if(A == 0){
        X = "0";
      }
    else{
      while(A != 0){
        if (A % (-2) == 0){
          X = "0" + X;
          A/=-2;
        }
        else{
          X =  "1" + X;
       //   A --;
       	A = (A-1)/(-2);
        }
      }
    }
      cout << X  << endl;
    }

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

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	if(a[a.length()-1] == b[0] && b[b.length()-1] == c[0]){
		cout << "YES" << endl;
	}else{
		cout <<"NO" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int N = 111;
int n;
pii ab[N], cd[N];
int w[N][N];
int toleft[N], vis[N];
bool can(int i){
	for(int j = 0; j < n; j++)
		if(vis[j] == 0 && w[i][j] == 1){
			vis[j] = 1;
			if(toleft[j] == -1 || can(toleft[j])){
				toleft[j] = i;
				return true;
			}
		}
	return false;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++) cin >> ab[i].first >> ab[i].second;
	for(int i = 0; i < n; i++) cin >> cd[i].first >> cd[i].second;
	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++){
		if(ab[i].first < cd[j].first && ab[i].second < cd[j].second)
			w[i][j] = 1;
	}
	int ans = 0;
	for(int j = 0; j < n; j++) toleft[j] = -1;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++) vis[j] = 0;
		if(can(i)) ans++;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<map>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;

 

int main() {
	int n; 
	map<string, int>mp;
	scanf("%d", &n);
	getchar();
	string str;
	for (int i = 0; i < n; i++) {
		getline(cin, str);
		mp[str]++;
	}
	
	int cnt = 0;
	map<string, int>::iterator it;
	for (it = mp.begin(); it != mp.end(); it++) {
		if (it->second % 2 == 1) {
			cnt++;
			//printf("%s ", it->first);
			//cout << it->first << endl;;
		}
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const ll MOD = 998244353;

ll modpow(ll base, int p) {
    ll mul = base;
    ll ret = 1;
    while (p) {
        if (p&1) {
            ret *= mul;
            ret %= MOD;
        }
        mul *= mul;
        mul %= MOD;
        p >>= 1;
    }
    return ret;
}

int main() {
    int n; 
    cin >> n;
    unordered_map<int, int> mp;
    int maxa = 0;
    vector<int> va(n); 
    rep(i, n) {
        int as; 
        cin >> va[i];
        mp[va[i]]++;
        maxa = max(maxa, va[i]);
    }
    if (mp[0] != 1 || va[0] != 0) {
        cout << 0 << endl;
        return 0;
    } 
    ll ret = 1;
    ll pre = 1;
    for (int a = 1; a <= maxa; ++a) {
        if (mp[a] == 0) {
            ret = 0;
            break;
        }  
        ret *= modpow(pre, mp[a]);
        ret %= MOD; 
        pre = mp[a];
    }
    cout << ret << endl;
    return 0;
}

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

int ans = 0;
int N;
string S;

void solve(int l, string s) {
	if (s.size() == 1) {
		if (S.substr(l).find(s[0]) != string::npos) {
			ans++;
		}
	} else {
		if (S.substr(l).find(s[0]) != string::npos) {
			solve(l + S.substr(l).find(s[0]) + 1, s.substr(1));
		}
	}
}

int main() {
	cin >> N >> S;
	for (int i = 0; i < 1000; i++) {
		string s = to_string(i);
		while (s.size() < 3) {
			s = "0" + s;
		}
		solve(0, s);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384