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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

constexpr ll MOD = 1'000'000'007;
ll N, K;
ll A[2100];

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

  std::cin >> N >> K;

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

  ll res = 0;
  
  for(int i=0;i<N;++i){
      ll n = 0, m = 0;

      for(int j=0;j<i;++j){
          if(A[j] > A[i]){
              m += 1;
          }
      }

      for(int j=0;j<N;++j){
          if(j == i){
              continue;
          }

          if(A[j] > A[i]){
              n += 1;
          }
      }

      res = (res + (K - 1) * K / 2 % MOD * n % MOD) % MOD;
      res = (res + K * m % MOD) % MOD;
  }

  std::cout << res << std::endl;
}


Measured memory_bytes: 256
n = gets.to_i
as = gets.split.map(&:to_i)

ans = n.times.with_object([]) do |i, a|
  if i.even?
    a.push(as[i])
  else
    a.unshift(as[i])
  end
end

ans.reverse! if n.odd?
puts ans.join(" ")


Measured memory_bytes: 27484
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

const int nax=5555;
ll dp[nax][nax];
const int mod=1e9+7;

ll pp(ll a,ll b)
{
    if(b==0) return 1;
    ll res=pp(a,b/2);
    res*=res;
    res%=mod;
    if(b%2==1) res*=a;
    res%=mod;
    return res;
}

ll inv(ll a)
{
    return pp(a,mod-2);
}

ll reku(int akt,int mv)
{
    if(dp[akt][mv]!=0) return dp[akt][mv];
    if(max(akt,mv)>5111) return 0;
    if(akt<0 || mv<0) return 0;
    if(akt>mv) return 0;
    if(akt)
    {
        dp[akt][mv]=reku(akt-1,mv-1)*2+reku(akt+1,mv-1);
        dp[akt][mv]%=mod;
        return dp[akt][mv];
    }
    else
    {
        dp[akt][mv]=reku(akt,mv-1)+reku(akt+1,mv-1);
        dp[akt][mv]%=mod;
        return dp[akt][mv];
    }
}

int main()
{
    dp[0][0]=1;
    int n; cin>>n;
    string s; cin>>s;
    ll res=reku(s.length(),n);
    res*=inv(pp(2,s.length()));
    res%=mod; cout<<res;
    return 0;
}


Measured memory_bytes: 215680
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long int ll;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

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

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main() {
  int k;
  cin >> k;
  vector<int> v;
  v.push_back(1);
  v.push_back(1);
  v.push_back(1);
  v.push_back(2);
  v.push_back(1);
  v.push_back(2);
  v.push_back(1);
  v.push_back(5);
  v.push_back(2);
  v.push_back(2);
  v.push_back(1);
  v.push_back(5);
  v.push_back(1);
  v.push_back(2);
  v.push_back(1);
  v.push_back(14);
  v.push_back(1);
  v.push_back(5);
  v.push_back(1);
  v.push_back(5);
  v.push_back(2);
  v.push_back(2);
  v.push_back(1);
  v.push_back(15);
  v.push_back(2);
  v.push_back(2);
  v.push_back(5);
  v.push_back(4);
  v.push_back(1);
  v.push_back(4);
  v.push_back(1);
  v.push_back(51);

  cout << v[k - 1] << endl;
  return 0;
}

Measured memory_bytes: 256
N=int(input())
p=list(map(int,input().split()))
buf=0
ans=p.copy()
count=0
list2=[]
#print(ans==pdash)
ans.sort()
#print(ans)
#print(ans==pdash)
flag=0

for i in range(N):
    if not(ans[i]==p[i]):
       count=count+1

if (count==0)or(count==2):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		String[] A = new String[N];
		String[] B = new String[M];
		for(int i = 0 ; i < N ; i++) {
			A[i] = sc.next();
		}
		for(int i = 0 ; i < M ; i++) {
			B[i] = sc.next();
		}
		for(int i = 0 ; i <= N - M ; i++) {
			for(int j = 0 ; j <= N - M ; j++) {
				boolean match = true;
				for(int k = 0 ; k < M ; k++) {
					for(int l = 0; l < M ; l++) {
						if(A[i + k].charAt(j + l) != B[k].charAt(l)) {
							match = false;
						}
					}
				}
				if(match == true) {
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");
	}
}


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

#define dump(x) cout << (x) << endl
#define Int int64_t
#define fi first
#define se second

Int mod = 1e9 + 7;
Int INF = 1e18;

int main() {
    Int n;
    cin >> n;
    vector<Int> v(n);
    for (Int i = 0; i < n; i++) {
        cin >> v[i];
    }
    Int res = 0;
    for (Int i = 0; i < n - 1; i++) {
        for (Int j = i + 1; j < n; j++) {
            res += v[i] * v[j];
        }
    }
    dump(res);
    return 0;
}

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

using namespace std;

#define pb push_back
#define pp pop_back
#define F first
#define S second
#define endl "\n"
#define m_p make_pair

typedef long long ll;
typedef long double ld;

void INeedIt() {
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int main() {
	INeedIt();
	string s;
	map <char, int> m;
	cin>>s;
	for (int i=0;i<s.size();i++) {
		m[s[i]]++;
	}
	for (int i=0;i<s.size();i++) {
		if (m[s[i]]%2!=0) {
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M=2e5+5;
ll a[M],pref[M],suf[M];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		a[i]-=i;
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
		pref[i]=pref[i-1]+a[i];
	for(int i=n;i;i--)
		suf[i]=suf[i+1]+a[i];
	ll ans=1e18;
	for(ll i=1;i<=n;i++)
		ans=min(ans,i*a[i]-pref[i]+suf[i]-(n-i+1)*a[i]);
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std; 
int main() {
    int n, x; cin >> n >> x;
    vector<int> l(n+1);
    for (int i = 1; i <= n; i++) {
        cin >> l[i];
    }
    
    int cnt = 1; //０から始まるので、最小でも１
    int d = 0;
    for (int i = 1; i <= n; i++) {
        d += l[i];
        if (d <= x) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 2000000
#define INFTY 2000000000

int H, A[MAX+1];

void maxHeapify( int i )
{
  int l, r, largest, temp;
  l = 2 * i;
  r = 2 * i + 1;

  if( l <= H && A[l] > A[i] ) largest = l;
  else largest = i;

  if( r <= H && A[r] > A[largest] ) largest = r;

  if( largest != i )
    {
      temp = A[i];
      A[i] = A[largest];
      A[largest] = temp;
      maxHeapify(largest);
    }
}

int extract()
{
  int max_key;

  if( H < 1 ) return -INFTY;
  max_key = A[1];
  A[1] = A[H];
  H--;
  maxHeapify(1);
  return max_key;
}

void increasekey( int i, int key )
{
  int temp;

  if( key < A[i] ) return;
  A[i] = key;
  while( i > 1 && A[i/2] < A[i] )
    {
      temp = A[i];
      A[i] = A[i/2];
      A[i/2] = temp;
      i = i/2;
    }
}

void insert( int key )
{
  H++;
  A[H] = -INFTY;
  increasekey(H,key);
}

int main()
{
  int key;
  char com[10];

  while(1)
    {
      scanf("%s", com);

      if( com[0] == 'e' && com[1] == 'n' ) break;
      if( com[0] == 'i' )
	{
	  scanf("%d", &key);
	  insert(key);
	}
      if( com[0] == 'e' && com[1] == 'x' )
	{
	  printf("%d\n", extract());
	}
    }

  return 0;
}
			      



Measured memory_bytes: 5640
def solve(sup,rest,digit,used1,used2):
    if rest<0:
        return 0
    if digit==0:
        if rest==0:
            return 1
        else:
            return 0
    sum=0
    for i in range(1,sup+1):
        if i!=used1 and i!=used2:
            if used1==0:
                sum+=solve(sup,rest-i,digit-1,i,used2)
            elif used2==0:
                sum+=solve(sup,rest-i,digit-1,used1,i)
            else:
                sum+=solve(sup,rest-i,digit-1,used1,used2)
    return sum

N=[]
X=[]
while True:
    n,x=map(int,raw_input().split())
    if (n,x)==(0,0):
        break
    N.append(n)
    X.append(x)
for i in range(len(N)):
    print('%d'%(solve(N[i],X[i],3,0,0)/6))

Measured memory_bytes: 6396
n = int(input())
x = list(map(int, input().split()))

l = min(x)
r = max(x)
ans = 100 ** 3
for i in range(l, r + 1):
    vit = sum(abs(xi - i) ** 2 for xi in x)
    ans = min(ans, vit)
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std; 
int main() {
  int N;
  cin>>N;
  int c=1;
  int d=99999;
  vector<int>result;
    for(int j=0;j<(d-c)/2+1;j++){
      int e=c+2*j;
      int f=0;
      if(e==1){
        f=1;
      }
      if(f==0){
        for(int k=1;k<(sqrt(e)+1)/2;k++){
          if(e%(2*k+1)==0){
            f=1;
          	break;
          }
        }
      }
      int g=(e+1)/2;
        if(g%2==0){
          f=1;
        }
      if(f==0){
        for(int l=1;l<sqrt(g)/2+1;l++){
          if(g%(2*l+1)==0){
            f=1;
          	break;
          }
        } 
      }
      if(e==3||e==5){
        f=0;
      }
      if(f==0){
        result.push_back(e);        
      }
    }
  int co=result.size();
  
  for(int i=0;i<N;i++){
    int g;
    int h;
    cin>>g;
    cin>>h;
    int count=0;
    
    for(int j=0;j<co;j++){
      
      if(g<=result.at(j)&result.at(j)<=h){
        count+=1;
        
      }
    }
    cout<<count<<endl;
  }
}

      

        
        
        


Measured memory_bytes: 640
import sys
import math
import copy
import random
import itertools
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 21
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def solve(n=None, s1=None, s2=None):
    n, k = getList()
    pli = getList()
    cli = getList()

    ans = max(cli)
    for i in range(n):
        cycle = [i]
        pts = [cli[i]]
        pos = i
        while True:
            pos = pli[pos] - 1
            if pos != i:
                cycle.append(pos)
                pts.append(cli[pos])
            else:
                break
        lc = len(cycle)
        acc = 0
        sumpts = sum(pts)
        for j in range(lc):
            acc += pts[j]

            if sumpts > 0:
                around = (k - j - 1) // lc
                tmp = acc + sumpts * around
            else:
                tmp = acc
            ans = max(ans, tmp)

    print(ans)

def main():
    n = getN()
    for _ in range(n):
        solve()
    return


if __name__ == "__main__":
    # main()
    solve()



Measured memory_bytes: 134184
#include <stdio.h>
int main(void){
    int n,cnt=1;
    scanf("%d",&n);
    while(n!=4 && n!=2 && n!=1){
        if(n%2==0) n/=2;
        else n= n*3+1;
        cnt++;
    }
    printf("%d",cnt+3);
}


Measured memory_bytes: 1704
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007
#define PI 3.1415926
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int x, y;
	cin >> x >> y;

	cout << x + y/2 << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] a = new long[N];
        long sum = 0;
        int count_negative = 0;
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextLong();
            sum += a[i];
            if (a[i] < 0) {
                count_negative += 1;
            }
        }
        int count_positive = N - count_negative;
        Arrays.sort(a);
        if (count_negative == 0) {
            count_negative = 1;
            count_positive -= 1;
        }
        if (count_positive == 0) {
            count_negative -= 1;
            count_positive = 1;
        }
        long x = a[0];
        for (int i = count_negative; i < N - 1; i++) {
            x = x - a[i];
        }
        long y = a[N-1];
        for (int i = 1; i < count_negative; i++) {
            y = y - a[i];
        }
        long answer = y - x;
        System.out.println(answer);
        x = a[0];
        for (int i = count_negative; i < N - 1; i++) {
            System.out.println(x + " " + a[i]);
            x = x - a[i];
        }
        y = a[N-1];
        for (int i = 1; i < count_negative; i++) {
            System.out.println(y + " " + a[i]);
            y = y - a[i];
        }
        System.out.println(y + " " + x);
    }
}

Measured memory_bytes: 77792
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
#input = sys.stdin.readline
#文字列のときはうまく行かないのでコメントアウトすること
sys.setrecursionlimit(2147483647)

def main():
  s = input()
  if s[2]==s[3] and s[4]==s[5]:
    print('Yes')
  else:
    print('No')

if __name__ == '__main__':
  main()

Measured memory_bytes: 5076
#include<cstdio>
using namespace std;
int main()
{
	int a,b,c,d;
	int cnt=0;
	scanf("%1d%1d%1d%1d",&a,&b,&c,&d);
	if(a==2)
	cnt++;
	if(b==2)
	cnt++;
	if(c==2)
	cnt++;
	if(d==2)
	cnt++;
	printf("%d",cnt);
	
	return 0;
}

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

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    int score = 0;
    for(int day = 1; ; day++) {
        score += a;
        if(day % 7 == 0) {
            score += b;    
        }
        if (score >= c) {
            cout << (day) << endl;
            break;
        }
    }
}



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

int main() {
  unsigned int N;
  std::cin >> N;

  std::vector<unsigned int> A_array;
  for (unsigned int i = 0; i < N; ++i) {
    unsigned int A;
    std::cin >> A;
    A_array.push_back(A);
  }

  std::vector<long> x_array(N, 0);
  // x_array.at(0)
  for (unsigned int i = 0; i < N; ++i) {
    if (i % 2 == 0) {
      x_array.at(0) += A_array.at(i);
    } else {
      x_array.at(0) -= A_array.at(i);
    }
  }
  for (unsigned int i = 1; i < N; ++i) {
    x_array.at(i) = x_array.at(i - 1) * -1 + 2 * A_array.at(i - 1);
  }

  for (unsigned int i = 0; i < N; ++i) {
    if (i != N - 1) {
      std::cout << x_array.at(i) << " ";
    } else {
      std::cout << x_array.at(i) << std::endl;
    }
  }

  return 0;
}


Measured memory_bytes: 2680
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
using namespace std;
int n, h[200000], a[200000];
long long dp[200001], bit[200001];
void update(int i, long long v) {
	for (; i <= n; i += i & -i) bit[i] = max(bit[i], v);
}
long long query(int i) {
	long long res = 0;
	for (; i > 0; i -= i & -i) res = max(res, bit[i]);
	return res;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &h[i]);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	memset(bit, 0, sizeof(bit));
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		dp[h[i]] = query(h[i] - 1) + a[i];
		ans = max(ans, dp[h[i]]);
		update(h[i], dp[h[i]]);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;	
ll n,T,a[200020],k,b[200020],flag=1,p[200020],pos,pos1;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
//		cout<<a[i]<<endl;
//		if(b[a[i]]==1&&flag){
//			pos1=i;
//			for(int j=0;j<i;j++){
//				if(a[j]==a[i]){
//					pos=j;
//					break;
//				}
//			}
//			T=pos1-pos;
//			flag=0;
//		}
//		b[a[i]]++;
	}
	p[0]=1;
	for(int i=1;i<=n;i++){
		p[i]=a[p[i-1]];
//		cout<<p[i]<<endl;
		if(b[p[i]]==1&&flag){
			pos1=i;
			for(int j=0;j<i;j++){
				if(p[j]==p[i]){
					pos=j;
					break;
				}
			}
			T=pos1-pos;
			flag=0;
		}
		b[p[i]]++;
//		cout<<pos<<" "<<pos1<<endl;
	}
//	for(int i=pos;i<=pos1;i++)cout<<p[i]<<" ";
	if(k<=pos1){
		cout<<p[k]<<endl;
		return 0;
	}else{
		k-=pos1;
		k%=T;
		cout<<p[pos+k]<<endl;
	}
//	cout<<a[pos1+k]<<endl; 
} 

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  vector<vector<pair<int, int> > > xy(N, vector<pair<int, int> >(N));
  for(int i = 0; i < N; i++){
    cin >> A[i];
    for(int j = 0; j < A[i]; j++) cin >> xy[i][j].first >> xy[i][j].second;
  }
  vector<int> N2(N);
  N2[0] = 2;
  for(int i = 1; i < N; i++){
    N2[i] = N2[i-1]*2;
  }
  int ans = 0;
  for(int i = 0; i < N2[N-1]; i++){
    vector<int> HU(N, 0);
    bool enable = true;
    for(int j = 0; j < N; j++){
      if((i%N2[j] / (N2[j]/2)) == 1) HU[j] = 1;
      // cout << i << " HU[j] = " << HU[j] << endl;
    }
    for(int j = 0; j < N; j++){
      if(HU[j] == 0) continue;
      else{
        for(int k = 0; k < A[j]; k++){
          // cout << j << k << xy[j][k].first << xy[j][k].second << endl;
          if(HU[xy[j][k].first-1] != xy[j][k].second){
            enable = false;
            break;
          }
        }//k
        if(!enable) break;
      }
    }//j
    if(!enable) continue;
    else{
      int tmp = 0;
      for(int j = 0; j < N; j++) tmp += HU[j];
      ans = max(ans, tmp);
    }
  }//i
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3+7;
const ll mod = 1e9+7;
const int sz = 62;
#define afdafafafdafaf y1;
int n,m;
int ar[maxn];


int arr[maxn][maxn];
int r[maxn], c[maxn];
int main()
{
    int a,b;
    scanf("%d%d", &n, &m);
    scanf("%d%d", &a, &b);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(j<=a)arr[i][j] = 0;
            else arr[i][j] = 1;
        }
    }
    for(int i=1;i<=b;i++){
        for(int j=1;j<=m;j++)arr[i][j] ^= 1;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            r[i] += arr[i][j];
            c[j] += arr[i][j];
        }
    }
    for(int i=1;i<=n;i++){
        assert(min(r[i], m-r[i]) == a);
    }
    for(int i=1;i<=m;i++){
        assert(min(c[i], n-c[i]) == b);
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++)printf("%d", arr[i][j]);
        printf("\n");
    }



    return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  int n;
  cin>>n;

  rep(i,n){
    ll a,b;
    cin>>a>>b;
    if(a>b) swap(a,b);
    ll ans=0;
    ll c=sqrt(a*b);
    if(c*c==a*b){
      if(c==a) ans=2*c-2;
      else ans=2*c-3;
    }
    else {
      if(c*(c+1)<a*b) ans=2*c-1;
      else ans=2*c-2;
    }
    cout << ans << endl;
  }

}


Measured memory_bytes: 3564
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
for _ in range(N):
    b = int(input())
    for x in range(3):
        for y in range(3):
            if A[x][y] == b:
                A[x][y] = -1

for x in range(3):
    f = True
    for y in range(3):
        if A[x][y] != -1:
            f = False
    if f:
        print("Yes")
        exit()

for x in range(3):
    f = True
    for y in range(3):
        if A[y][x] != -1:
            f = False
    if f:
        print("Yes")
        exit()

f = True
for x in range(3):
    if A[x][x] != -1:
        f = False

if f:
    print("Yes")
    exit()

f = True
for x in range(3):
    if A[2 - x][x] != -1:
        f = False

if f:
    print("Yes")
    exit()

print("No")

Measured memory_bytes: 3188
#include <iostream>
#include <string>
using namespace std;
string s[8];
char f(){
	for(int i=0;i<8;i++){
		for(int j=0;j<8;j++){
			if(s[i][j]=='1'){
				if(i<5)
					if(s[i+3][j]=='1')return 'B';
				if(j<5)
					if(s[i][j+3]=='1')return 'C';
				if(i<6&&j>0)
					if(s[i+2][j-1]=='1')return 'D';
				if(i<7&&j<6)
					if(s[i+1][j+2]=='1')return 'E';
				if(i<6&&j<7)
					if(s[i+2][j+1]=='1')return 'F';
				if(i<7&&j>0)
					if(s[i+1][j-1]=='1'&&s[i][j+1])return 'G';
				return 'A';
			}
		}
	}
}

int main(){
	while(cin>>s[0]){
		for(int i=1;i<8;i++)cin>>s[i];
		cout <<f() <<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    for (int i = 0; i < N; i++) cin >> h[i];

    vector<int> dp(N+K, INF);
    dp[0] = 0;
    for (int i = 0; i < N; i++)
        for (int j = 1; j <= K; j++)
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]));
    cout << dp[N-1] << '\n';
}


Measured memory_bytes: 4020
N = int(input())
Lis = []
for i in range(N):
	S, P = input().split()
	Lis.append([i+1, S, int(P)])
Lis = sorted(Lis, key = lambda x: (x[1], -x[2]))
for i in range(N):
	print(Lis[i][0])

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

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

using namespace std;

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

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

int main()
{
  int A, B, C, D;
  int tmp;
  cin  >> tmp;
  A = tmp/1000;
  B = (tmp/100)%10;
  C = (tmp/10)%10;
  D = tmp%10;

  
  for(int bit=0; bit<(1<<4); bit++)
    {
      for(int i=0; i<4; i++)
	{
	  ll tmp = 0;
	  char a[4];
	  tmp+=A;
	  if(bit&(1<<2))
	     {
	      tmp+=B;
	      a[1]='+';
	    }
	  else
	     {
	      tmp-=B;
	      a[1]='-';
	    }
	  if(bit&(1<<1))
	     {
	      tmp+=C;
	      a[2]='+';
	    }
	  else
	     {
	      tmp-=C;
	      a[2]='-';
	    }
	  if(bit&(1<<0))
	     {
	      tmp+=D;
	      a[3]='+';
	    }
	  else
	     {
	      tmp-=D;
	      a[3]='-';
	    }

	  if(tmp==7)
	    {
	      cout << A << a[1] << B << a[2] << C << a[3] << D  << "=7" <<endl;
	      return 0;
	    }
	}
    }


  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



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

typedef long long ll;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    rep(i, N) cin >> h[i];
    sort(h.begin(), h.end());
    int ans = 1e9;
    rep(i, N - K + 1) {
        ans = min(ans, h[i + K - 1] - h[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;
//096C
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int ans =a*x+b*y;;
		
		for (int i=0;i<=2*Math.max(x, y);i++){
			int price=2*i*c+ Math.max(x-i, 0)*a + Math.max(y-i, 0)*b ;
			ans = Math.min(ans, price);
		}
		System.out.println(ans);
		
		//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
	}
}

Measured memory_bytes: 21972
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h> 
using namespace std;
	typedef long long int lli;
	const int MaxN=200005;
	#define fst first
	#define snd second
	#define mp make_pair
	lli mcd(lli a,lli b){	
		if(a==0)return b;
		return mcd(b%a,a);
	}		
	lli arr[MaxN];
int main(){
	lli N,K,i,j,res=0,maxi=0;
	cin>>N;
	for(i=0;i<N;i++){
		cin>>arr[i];
	}
	for(i=0;i<N;i++){
		maxi=max(maxi,arr[i]);
		if(maxi==arr[i]){
			res+=1;
		}
	}	
	cout<<res;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
	using namespace std;
	int main(){
		
		//#ifndef ONLINE_JUDGE
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
		//#endif

		int n;
		cin>>n;
		int a[n];
		int dp[n+1]={0};
		for (int i = 0; i < n; ++i)
			cin>>a[i];

		dp[n-1]=0;
		dp[n-2]=abs(a[n-1]-a[n-2]);

		for(int i=n-3;i>=0;i--){

			dp[i]=min((abs(a[i]-a[i+1])+dp[i+1]),(abs(a[i]-a[i+2])+dp[i+2]));
		}
		cout<<dp[0];
		

		
		

		
	}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#define div 1000000000+7 
using namespace std;
typedef long long ll;

int main(){
  int a, b, c;
  int y;
  cin >> a >> b >> c;
  int x = max(a, max(b, c));
  if(x == a){
    y = b+c;
  }else if(x == b){
    y = a+c;
  }else{
    y = a+b;
  }
  if(x == y){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
/*
    思路：先将01234567?些数字的所有的可能的?果一一求出来，之后?入所需的字符串直接?出即可;
*/

#include<iostream>
#include<string>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
typedef pair<string, int> P;
string a;
int d[4]={-1,1,-4,4};//可?的位置;
map<string,int> m;

void  BFS()
{
    queue<P> Q;
    string S="01234567";
    Q.push(P("01234567",0));
     m[S]=0;
    while(!Q.empty())
    {
        P p1;
        p1=Q.front();
        Q.pop();
        string s=p1.first;
        int cnt=p1.second;
        int i;
        for(i=0;i<4;i++)
        {
            int next;
            string s1;
            next=cnt+d[i];
            s1=s;
            swap(s1[cnt],s1[next]);
            map<string ,int>::iterator it =m.find(s1);
            if(next>=0&&next<8&&!(cnt==3&&next==4)&&!(cnt==4&&next==3)&&it==m.end())
            // 判断next是否在0--8的范?之内，并且3和4不能相?，it==m.end()代表it?量在m中没有找到字符串s1；
            {
                Q.push(P(s1,next));
                m[s1]=m[s]+1;
               // cout<<m[s1]<<endl;
            }
        }
    }
}
void del_kg()  //?除空格;
{
    a.erase(remove(a.begin(), a.end(), ' '), a.end());
}
int main()
{
    BFS();
    //string str;
    while(getline(cin, a))
    {
        del_kg();
         cout<<m[a]<<endl;
    }
    return 0;
}

Measured memory_bytes: 5304
#include<iostream>
#include<vector>
using namespace std;
const int mod=1000000007;
vector <int> pr;
vector <int> num;
int n;
bool a[1005];
int main()
{
	cin>>n;
	for(int i=2;i<=n;i++)
	    a[i]=true;
	for(int i=2;i<=n;i++)
	    if(a[i]==true)
	        for(int j=2;j*i<=n;j++)
	        	a[j*i]=false;
    for(int i=2;i<=n;i++)
        if(a[i]==true)
        	pr.push_back(i);
    int cnt=0;
    for(int i=0;i<pr.size();i++)
    {
    	cnt=0;
    	for(int j=2;j<=n;j++)
    	{
    		int x=j;
    		while(x%pr[i]==0&&x!=0)
    		{

    			cnt++;
    			x/=pr[i];
			}
		}
		if(cnt!=0)
		    num.push_back(cnt);
	}
	long long ans=1;
	for(int i=0;i<num.size();i++)
	{
		ans*=num[i]+1;
		ans%=mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
using namespace std;
#include<algorithm>
int main(){
	for(int i=0;i<7;i++){
		int a,b;
		cin>>a>>b;
		cout<<a-b<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N;cin>>N;
    vector<int> a(N);
    REP(i,N)cin>>a[i];
    int res=1;
    int f=0;
    FOR(i,1,N){
        if(a[i]==a[i-1])continue;
        else{
            if(f==0){
                if(a[i]>a[i-1])f=1;
                else f=-1;
            }else if(f==1){
                if(a[i]>a[i-1])continue;
                else {res++;f=0;}
            }else{
                if(a[i]<a[i-1])continue;
                else {res++;f=0;}
            }
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 640
from bisect import bisect
A,B,Q = map(int,input().split())
S = [int(input()) for i in range(A)]
T = [int(input()) for i in range(B)]
qs = [int(input()) for i in range(Q)]

st = []
for s in S:
    ti = bisect(T,s)
    if ti == 0:
        st.append(abs(s-T[0]))
    elif ti == B:
        st.append(abs(s-T[-1]))
    else:
        tmp = min(abs(s-T[ti-1]), abs(s-T[ti]))
        st.append(tmp)

ts = []
for t in T:
    si = bisect(S,t)
    if si == 0:
        ts.append(abs(t-S[0]))
    elif si == A:
        ts.append(abs(t-S[-1]))
    else:
        tmp = min(abs(t-S[si-1]), abs(t-S[si]))
        ts.append(tmp)

ans = []
for q in qs:
    si = bisect(S,q)
    if si == 0:
        a = abs(q-S[0]) + st[0]
    elif si == A:
        a = abs(q-S[-1]) + st[-1]
    else:
        a = min(abs(q-S[si-1]) + st[si-1], abs(q-S[si]) + st[si])

    ti = bisect(T,q)
    if ti == 0:
        b = abs(q-T[0]) + ts[0]
    elif ti == B:
        b = abs(q-T[-1]) + ts[-1]
    else:
        b = min(abs(q-T[ti-1]) + ts[ti-1], abs(q-T[ti]) + ts[ti])

    ans.append(min(a,b))

print(*ans, sep='\n')

Measured memory_bytes: 30396
#include <stdio.h>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
const int N=1e5+10;
const ll INF=1LL<<60;
ll now=12394129385729LL;
struct node{
    node* l;
    node* r;
    int size;
    ll val;
    node(ll n){
        l=r=nullptr;
        size=1;
        val=n;
    }
    void pull(){
        size=1;
        if(l)size+=l->size;
        if(r)size+=r->size;
        return ;
    }
};
bool ran(int a,int b){
    now^=12394817923847LL;
    now+=12937417834292LL;
    return (now%=(a+b))>=b;
}
node* merge(node* a,node* b){
    if(!a)return b;
    if(!b)return a;
    if(ran(a->size,b->size)){
        a->r=merge(a->r,b);
        a->pull();
        return a;
    }
    else{
        b->l=merge(a,b->l);
        b->pull();
        return b;
    }
}
void split(node* s,ll x,node* &a,node* &b){
    if(!s){
        a=b=nullptr;
        return ;
    }
    if(x>s->val){
        a=s;
        split(s->r,x,a->r,b);
        a->pull();
    }
    else{
        b=s;
        split(s->l,x,a,b->l);
        b->pull();
    }
    return ;
}
int query(node* s,ll x){
    if(!s)return 0;
    int ans=0;
    if(s->val>=x){
        if(s->l)ans+=query(s->l,x);
        ans++;
        if(s->r)ans+=s->r->size;
    }
    else if(s->r)ans+=query(s->r,x);
    return ans;
}
int main(){
    int n,m,q,a,b,c,ans[N];
    node* root=nullptr,*l,*r;
    priority_queue<pll,vector<pll>,greater<pll>>pq;
    pll temp,s[N];
    pair<pll,int> ask[N];
    bitset<N> went;
    vector<pi>graph[N];
    scanf("%d%d",&n,&m);
    while(m--){
        scanf("%d%d%d",&a,&b,&c);
        graph[a].PB({b,c});
        graph[b].PB({a,c});
    }
    for(int i=0;i<n;i++)s[i]={INF,INF};
    s[0].F=0;
    pq.push({0,0});
    went.reset();
    while(!pq.empty()){
        temp=pq.top();
        pq.pop();
        if(went[temp.S])continue;
        went[temp.S]=true;
        for(pi i:graph[temp.S])if(!went[i.F]&&s[temp.S].F+i.S<s[i.F].F){
            s[i.F].F=s[temp.S].F+i.S;
            pq.push({s[i.F].F,i.F});
        }
    }
    went.reset();
    pq.push({0,n-1});
    s[n-1].S=0;
    while(!pq.empty()){
        temp=pq.top();
        pq.pop();
        if(went[temp.S])continue;
        went[temp.S]=true;
        for(pi i:graph[temp.S])if(!went[i.F]&&s[temp.S].S+i.S<s[i.F].S){
            s[i.F].S=s[temp.S].S+i.S;
            pq.push({s[i.F].S,i.F});
        }
    }
    sort(s,s+n);
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%lld%lld",&ask[i].F.F,&ask[i].F.S);
        ask[i].S=i;
    }
    sort(ask,ask+q);
    a=0;
    for(int i=0;i<q;i++){
        while(a<n){
            if(s[a].F<=ask[i].F.F){
                split(root,s[a].S,l,r);
                root=merge(l,new node(s[a].S));
                root=merge(root,r);
                a++;
            }
            else break;
        }
        ans[ask[i].S]=query(root,ask[i].F.S);
    }
    for(int i=0;i<q;i++)printf("%d\n",ans[i]);
}



Measured memory_bytes: 17760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n, a, b;
    cin >> n >> a >> b;
    int ans = min(a*n, b);
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
#define ff first
#define ss second
/*----------------------------------------------------------------------*/

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s; cin>>s;
    int l=0;
    FOR(i, 0, s.size()) l += (s[i] == 'x');
    cout << ((l < 8) ? ("YES") : "NO");

    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
facts = defaultdict(int)
mod=10**9+7
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
n=int(input())
a=[int(i) for i in input().split()]
for i in range(n):
  for b,p in factorization(a[i]):
    if facts[b]<p:
      facts[b]=p
ans=0
f=1
for k,v in facts.items():
  f*=pow(k,v,mod)
  f%=mod
for i in range(n):
  ans+=f*pow(a[i],mod-2,mod)
  ans%=mod
print(ans)

Measured memory_bytes: 4980
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < n; i++)
#define rep2(i,start,end) for(ll i = start; i < end; i++)
#define dwn(i,n) for(int i = n; i >= 0; i--)
#define dwn2(i,start,end) for(ll i = start; i >= end; i--)
#define pll pair<ll,ll>
#define mk(x,y) make_pair(x,y)
#define pdl pair<double, ll>
const ll N = 4e5 + 200;
const ll INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;


int main(){
	ll n,m;
	cin>>n>>m;
	ll sum = 0;
	rep(i,m){
		ll x;
		cin>>x;
		sum += x;
	}
	if(n-sum < 0){
		cout<<"-1"<<endl;
	}else
	cout<<n-sum<<endl;



	return 0;
}






Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1,0,-1,0}; 
int dy[4] = {0,1,0,-1}; 
int main(){
	int H, W; cin >> H >> W; 
	int INF = 1145141919; 
	char C[25][25] = {}; 
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cin >> C[i][j]; 
		}
	}
	queue<pair<int, int>> que; 
	int ans[25][25] = {}; 
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(C[i][j] == '#') continue;
			int D[25][25] = {};
			for(int p = 0; p < H; p++){
				for(int q = 0; q < W; q++){
					if(p != i || q != j) D[p][q] = INF; 
				}
			}
			que.push(make_pair(i, j)); 
			while(que.size()){
				pair<int, int> p = que.front(); que.pop(); 
				int a = p.first; int b = p.second; 
				for(int k = 0; k < 4; k++){
					int c = a + dx[k]; int d = b + dy[k]; 
					if(c >= 0 && c < H && d >= 0 && d < W && C[c][d] == '.' && D[c][d] == INF){
						D[c][d] = D[a][b] + 1; que.push(make_pair(c, d)); 
					}
				}
			}
			for(int p = 0; p < H; p++){
				for(int q = 0; q < W; q++){
					if(D[p][q] != INF) ans[i][j] = max(ans[i][j], D[p][q]); 
				}
			}			
		}
	}
	int kotae = 0; 
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			kotae = max(kotae, ans[i][j]); 
		}
	}
	cout << kotae << endl; 
}

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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;

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

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

  long long int ans = 0;
  if (N > K) {
    for (int i = K; i < N; i++) {
      ans += H[i];
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>

int main(){
	for(int i=0; i<4; ++i){
		int t, n;
		long p;
		scanf(" %d %d", &t, &n);
		
		switch(t){
			case 1:
				p=n*6000;
				break;
			case 2:
				p=n*4000;
				break;
			case 3:
				p=n*3000;
				break;
			case 4:
				p=n*2000;
				break;
			default:
				break;
		}
	
		printf("%ld\n", p);
	}	
	
	return 0;
}

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

s = {}
ans = 0
for i in range(n):
  _s = sorted(input())
  __s = ''
  for _ in _s:
    __s += _
  try:
    ans += s[__s]
    s[__s] += 1
  except:
    s[__s] = 1

print(ans)

Measured memory_bytes: 17892
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n,m;
  cin>>n>>m;
  ll sum=n*m;
  if(n==1 && m==1){
    cout<<1<<'\n';
  }
  else if(n==1 || m==1){
    cout<<n*m-2<<'\n';
  }
  else{
    sum=sum-(n+m)*2+4;
    cout<<sum<<'\n';
  }
  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  string s = "ACL";
  int n;
  cin >> n;
  rep(i,n)cout << s;
  cout << endl;
}

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

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

    int n;
    string s,t;
    
    cin >> n >> s >> t;
    
    int ans = 0;
    
    for(int i = 0; i < n; i++){
        int cnt = 0;
        for(int j = 0; i + j < n; j++){
            if(s[i+j] == t[j]) cnt++;
            else cnt = 0;
        }
        ans = max(ans,cnt);
    }
     
    cout << 2 * n - ans << endl;
    
}


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

int main(){
    string apple = "apple", peach = "peach";

    int n = 0;
    string str[1000];

    while(cin >> str[n]){
        for(int i=0;i<str[n].size();i++){
            if(str[n].substr(i, 5) == apple){
                for(int j=0;j<peach.size();j++){
                    str[n][i + j] = peach[j];
                }
            }else if(str[n].substr(i, 5) == peach){
                for(int j=0;j<apple.size();j++){
                    str[n][i + j] = apple[j];
                }
            }
        }
        n++;
    }
    for(int i=0;i<n-1;i++){
        cout << str[i] << " ";
    }
    cout << str[n - 1] << endl;

    return 0;
}


Measured memory_bytes: 3140
package main

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

func main() {
	var taro, hanako uint
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	for i := 0; i < n; i++ {
		sc.Scan()
		tw := sc.Text()
		sc.Scan()
		hw := sc.Text()
		if tw > hw {
			taro += 3
		} else if hw > tw {
			hanako += 3
		} else {
			taro++
			hanako++
		}
	}
	fmt.Println(taro, hanako)
	return
}



Measured memory_bytes: 1104
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a>9 || b>9)	printf("-1\n");
	else printf("%d\n",a*b);
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<string> U(N);
	for (int i = 0; i < N;i++) cin >> U[i];
	int M; cin >> M;
	bool lock = true;
	string T;
	for (int i = 0; i < M;i++) {
		cin >> T;
		if (find(U.begin(), U.end(), T) == U.end()) {
			cout << "Unknown " << T << endl;
		}
		else {
			if (!lock) {
				cout << "Closed by " << T << endl;
				lock = true;
			}
			else {
				cout << "Opened by " << T << endl;
				lock = false;
			}
		}
	}
}

Measured memory_bytes: 3168
#include<iostream>

using namespace std;

int main()
{
   int n;
   string a, b,c;
   cin >> n;
   cin >> a;
   cin >> b;
   cin >> c;
   int count = 0;
   for(int i=0;i<n;i++){
      if ( a[i] == b[i] && b[i] == c[i]){
      }else if(a[i] == b[i] || a[i] == c[i] || b[i] == c[i] ){
         count ++;
      }else{
         count += 2;
      }
   }

   cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n, t;
  cin >> n >> t;
  ll ans = INF;

  rep(i, n) {
    ll cost, time;
    cin >> cost >> time;
    if (time <= t) chmin(ans, cost);
  }

  if (ans == INF) cout << "TLE" << endl;
  else cout << ans << endl;

  return 0;
}


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

int main()
{
    int mat[3][3];
    for (int i = 0; i < 3; i++)
    {
        for(int j = 0; j< 3; j++)
        {
            std::cin>>mat[i][j];
        }
    }
    int n;
    std::cin>>n;
    int temp;
    for (int i=0;i<n;i++)
    {
        std::cin>>temp;
        for (int k = 0; k < 3; k++)
        {
           for(int j = 0; j< 3; j++)
            {
                if (temp == mat[j][k])
                mat[j][k]=0;
            }
        }
    }

    if ((mat[0][0]==0 && mat[1][1]==0 && mat[2][2]==0)||(mat[0][0]==0 && mat[0][1]==0 && mat[0][2]==0)||(mat[1][0]==0 && mat[1][1]==0 && mat[1][2]==0)||
    (mat[2][0]==0 && mat[2][1]==0 && mat[2][2]==0)||(mat[0][0]==0 && mat[1][0]==0 && mat[2][0]==0)||(mat[0][1]==0 && mat[1][1]==0 && mat[2][1]==0)||
    (mat[0][2]==0 && mat[1][2]==0 && mat[2][2]==0)||(mat[0][2]==0 && mat[1][1]==0 && mat[2][0]==0))
    std::cout<<"Yes";
    else
    std::cout<<"No";
    return 0;
}

Measured memory_bytes: 888