akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
int i[5][5];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d,e,f,g;
  for(int n=0;n<3;n++){
    for(int m=0;m<3;m++){
      cin >>i[n][m];
    }
  }
  while(1){
    if(i[0][0]>0&&i[0][1]>0&&i[0][2]>0) i[0][0]--,i[0][1]--,i[0][2]--;
    else break;
  }
  while(1){
    if(i[1][0]>0&&i[1][1]>0&&i[1][2]>0) i[1][0]--,i[1][1]--,i[1][2]--;
    else break;
  }
  while(1){
    if(i[2][0]>0&&i[2][1]>0&&i[2][2]>0) i[2][0]--,i[2][1]--,i[2][2]--;
    else break;
  }
  while(1){
    if(i[0][0]>0&&i[1][0]>0&&i[2][0]>0) i[0][0]--,i[1][0]--,i[2][0]--;
    else break;
  }
  while(1){
    if(i[0][1]>0&&i[1][1]>0&&i[2][1]>0) i[0][1]--,i[1][1]--,i[2][1]--;
    else break;
  }
  while(1){
    if(i[0][2]>0&&i[1][2]>0&&i[2][2]>0) i[0][2]--,i[1][2]--,i[2][2]--;
    else break;
  }
  b=0;
  for(int n=0;n<3;n++){
    for(int m=0;m<3;m++){
      b+=i[n][m];
    }
  }
  if(b==0) cout <<"Yes\n";
  else cout <<"No\n";
  return(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
using namespace std;
main()
{	
int n;
cin>>n;
int a[n];
int sum=0;
for(int i=0;i<n;i++)
{
	cin>>a[i];
	sum+=a[i];
		sum%=(1000000000+7);
	}
	int ans=0;
	for(int i=0;i<n;i++)
{
	sum-=a[i];
	if(sum<0)
	sum+=1000000000+7;
	;ans+=a[i]*sum;
	ans%=(1000000000+7);
}
		cout<<ans<<endl;		
}

Measured memory_bytes: 5192
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define f first 
#define s second
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mp make_pair
#define pb push_back
int par[100001];
vector<pair<int,int>>v[100001];
int c[100001],vis[100001];
void bfs()
{
	queue<int>q;
	q.push(0);
	c[0] = 0;
	vis[0] = 1;
	while(!q.empty())
	{
		int node = q.front();
		q.pop();
		for (int i = 0; i < v[node].size(); ++i)
		{
			if(vis[v[node][i].f]==0)
			{
				if(((v[node][i].s)%2) == 1)
					c[v[node][i].f] = 1-c[node];
				else
					c[v[node][i].f] = c[node];
				vis[v[node][i].f] = 1;
				q.push(v[node][i].f);
			}
		}
	}
}
int main(){
  int n;
  FIO;  
  cin >> n;
  int u,v1,w;
  memset(vis,0,sizeof(vis));
  memset(c,0,sizeof(c));
  for (int i = 0; i < n-1; ++i)
  {
  	cin >> u >> v1 >> w;
  	u--;v1--;
  	v[u].pb({v1,w});
  	v[v1].pb({u,w});
  }
  bfs();
  for (int i = 0; i < n; ++i)
  {
  	cout <<  c[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 7168
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def power_func(a,n,p):
    bi = str(format(n,"b"))#2進表現に
    res = 1
    for i in range(len(bi)):
        res = (res*res) %p
        if bi[i] == "1":
            res = (res*a) %p
    return res

def solve(N: int):
    if N==1:
        print(0)
    elif N==2:
        print(2)
    else :
        tmp=(power_func(10,N,MOD))+(power_func(8,N,MOD))
        tmp=tmp%MOD
        tmp2=(2*power_func(9,N,MOD))%MOD
        if tmp-tmp2<0:
            print(tmp-tmp2+MOD)
        else :
            print(tmp-tmp2)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9256
#include <bits/stdc++.h>
using namespace std;
long long res,l,i;
int main()
{
	string s;
	cin>>s;
	l=s.size();
	for(;i<l;i++)res+=((9*pow(10,l-1-i)-pow(2,l-1-i))/8)*pow(2,i)*(s[i]-'0');
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
using namespace std;
typedef long long ll;

const ll MOD_CONST = 1000000007;



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

	ll ans = (n / (a + b)) * a;
	n %= a + b;
	ans += min(a, n);
	cout << ans << endl;

}  



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,a,b;
    scanf("%lld %lld %lld",&n,&a,&b);
    if(a==0)
    cout<<0;
    else if(b==0)
    printf("%lld",n);
    else
    {
        ll temp=(n/(a+b))*a;
        ll k=n%(a+b);
        if(k<a)
        temp+=k;
        else
        temp+=a;
        printf("%lld",temp);
    }
    
}

Measured memory_bytes: 256
n,q = map(int,input().split())
s = input()
ac = [0 for _ in range(n+1)]
a = 0
for i in range(n):
    if s[i] == "C" and a:
        ac[i] = 1
    if s[i] == "A":
        a = 1
    else:
        a = 0
for i in range(n):
    ac[i+1] += ac[i]
for i in range(q):
    l,r = map(int,input().split())
    print(ac[r-1]-ac[l-1])

Measured memory_bytes: 7692
#include <iostream>
#include <sstream>
#include <stdio.h>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#include <map>
#define FORi(N) for(int i=0;i<N;++i)
#define FORj(N) for(int j=0;j<N;++j)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
void putYN(bool b){
  if(b){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
void swap(ll &a,ll &b){
  ll tmp=a;
  a=b;
  b=tmp;
}
int main(){
  ll A,B;
  cin>>A>>B;
  if(A>=13){
    cout<<B<<endl;
  }else if(A>=6){
    cout<<B/2<<endl;
  }else{
    cout<<0<<endl;
  }
  return 0;
}


Measured memory_bytes: 888
#include<iostream>
using namespace std;
int main(){
  char color[1000][1000];
  int n,m,i,j,ans=0,num=0,k,o;
  cin>>n>>m;
  for(i=1;i<=n;i++){
    for(j=1;j<=m;j++){
        cin>>color[i][j];
    }
  }
    for(i=1;i<n-1;i++){
      for(j=1;j<n-i;j++){
        for(k=1;k<=i;k++){
          for(o=1;o<=m;o++) if(color[k][o]!='W') num++;
        }
        for(k=i+1;k<=n-j;k++){
          for(o=1;o<=m;o++) if(color[k][o]!='B') num++;
        }
        for(k=n-j+1;k<=n;k++){
          for(o=1;o<=m;o++) if(color[k][o]!='R') num++;
        }
        //cout<<num<<endl;
        if(i==1&&j==1) ans=num;
        else if(ans>num) ans=num;
        num=0;
      }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3068
MOD = 10**9+7

def fact(n)
  @facts ||= [1]
  (@facts.size).upto(n){|i| @facts << @facts[-1]*i % MOD}
  return @facts[n]
end

def modpow(x,n)
  ret = 1
  while n > 0
    ret = (ret * x) % MOD if n&1 == 1
    x = (x*x) % MOD
    n >>= 1
  end
  return ret
end

def modinv(x)
  return modpow(x,MOD-2)
end

N,K = gets.split.map(&:to_i)
G = Array.new(N){[]}
size = [0]*N
(N-1).times do |i|
  a,b = gets.split.map(&:to_i)
  a,b = a-1,b-1
  G[a] << b
  G[b] << a
  size[a] += 1
  size[b] += 1
end

visited = [false]*N

visited[0] = true
ans = K * fact(K-1) * modinv(fact(K-1-size[0])) % MOD
q = G[0].dup

while v = q.shift
  if !visited[v]
    G[v].each do |u|
      q << u
    end

    if K < size[v]+1
      ans = 0
    else
      ans = ans * fact(K-2) * modinv(fact(K-1-size[v])) % MOD
    end
    visited[v] = true
  end
end
p ans

Measured memory_bytes: 13752
#include<iostream>
using namespace std;
typedef long long int ll;
int main()
{
	ll arr[5];
	int ans = 0;
	for(int i =0; i<5; i++)
	{
		cin>>arr[i];
		if(arr[i] ==0)
		{
			ans = i+1;
			break;
		}else
		{
			ans = 0;
		}
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3580
package main
import (
  "fmt"
)
func main() {
  var n int
  var s string
  fmt.Scan(&n, &s)
  leftNum := 0
  stock := 0
  for _, char := range s {
    if char == ')' {
      if 0 < stock {
        stock--
        continue
      }
      leftNum++
    } else {
      stock++
    }
  }
  rightNum := 0
  stock = 0
  for i := n-1; 0 <= i; i-- {
    char := s[i]
     if char == '(' {
      if 0 < stock {
        stock--
        continue
      }
      rightNum++
    } else {
      stock++
    }
  }
  result := s
  for i := 0; i < leftNum; i++ {
    result = "(" + result
  }
  for i := 0; i < rightNum; i++ {
    result = result + ")"
  }
  
  fmt.Println(result)
}

Measured memory_bytes: 512
#![allow(unused_imports)]
#![allow(dead_code)]

mod reader {
    use std;

    macro_rules! read_line((  ) => {
                           {
                           let mut input = String :: new (  ) ; std :: io ::
                           stdin (  ) . read_line ( & mut input ) . unwrap (
                           ) ; input } } ;);

    pub fn read_str() -> String { read_line!().trim().to_owned() }
}
use reader::*;

fn main() {
    let b = read_str();

    println!("{}" , match & b [ .. ] {
             "A" => "T" , "T" => "A" , "G" => "C" , "C" => "G" , _ => "" , })
}


Measured memory_bytes: 4352
#pragma once

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ull mod = 1000000007;
int INF = 1e8;
ll n;
vector<int> distToLast;
vector<bool> visit;

int dfs(int id, const vector<vector<int>>& m) {
	if (distToLast[id] >= 0) return distToLast[id];

	if (visit[id] > 0) return INF;
	visit[id] = true;
	int dist = 0;
	for (auto e : m[id]) {
		dist = max(dist, dfs(e, m));
	}
	visit[id] = false;
	distToLast[id] = min(INF, dist+1);
	return distToLast[id];
}

int main(void)
{
	cin >> n;
	vector<vector<int>> input(n*n);
	vector<int> s;
	rep(i, n) {
		vector<int> ps(n - 1);
		rep(j, n - 1) {
			int t;
			cin >> t;
			t--;
			auto p = min(t, i) * n + max(t, i);
			ps[j] = p;
		}
		rep(j, n - 2) {
			input[ps[j]].push_back(ps[j + 1]);
		}
		s.push_back(ps[0]);
	}
	int d = 0;
	visit.assign(n* n, false);
	distToLast.assign(n * n, -1);
	for (auto e : s) {
		d = max(d, dfs(e, input));
	}
	if (d == INF) {
		cout << -1 << endl;
		return 0;
	}
	cout << d << endl;
	return 0;
}


Measured memory_bytes: 43520
n, a, b = map(int, input().split())
mod = int(1e9+7)

def comb(r):
    bunshi = 1
    for i in range(n-r+1,n+1):
        bunshi = bunshi*i%mod
    bunbo = 1
    for i in range(1,r+1):
        bunbo = bunbo * i %mod
    return bunshi*pow(bunbo, mod-2,mod)%mod

ans = pow(2,n,mod) -1 - comb(b)-comb(a)
ans = (ans +2*mod)%mod
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
bool used[50];
typedef pair<int,int>P;
int dx[]={-1,1};
int main(){
  string s;
  int c=0;
  cin>>s;
  r(i,3)c+=s[i]-'0';
  cout<<c<<endl;
}

Measured memory_bytes: 384
n = int(input())
x = [[0, 0]]
for _ in range(n):
    a, b = map(int, input().split())
    x.append([b, a])
x.sort()
for i in range(1, n + 1):
    x[i][1] += x[i - 1][1]
    if x[i][0] < x[i][1]:
        print("No")
        exit()
print("Yes")

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

int main(){
	int N;
	cin >> N;
	long long L, L2, L1;

	L2 = 2;
	L1 = 1;

	if(N==1) {
		cout << L1 << endl;
		return 0;
	}

	for( int i=2; i<N+1; i++){
		L = L1 + L2;
		L2 = L1;
		L1 = L;
	}
	
	printf("%lld\n", L);
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

toInts :: IO [Int]
toInts = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

solver :: [Int] -> Int
solver [] = 0
solver (x:[]) = 0
solver (x:y:[]) = 0
solver (x:y:z:rest) =
  (if (x < y && y < z) || (x > y && y > z)
     then 1
     else 0) +
  solver (y : z : rest)

main :: IO ()
main = do
  _ <- getLine
  dat <- toInts
  print $ solver dat


Measured memory_bytes: 380
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n, ans;
int main(){
    scanf("%d", &n);
    for(int x = 1; x <= n; x += 2)
    {
        int y = x, cnt = 0;
        for(int i = 1; i * i <= y; ++i)
        {
            if(y % i == 0)
            {
                if(i == y / i) cnt++;
                else cnt += 2;
            }
        }
        ans += cnt == 8;
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }


int N, M;
vector<int> _link[200001];
bool flg[200001];

signed main()
{
	cin >> N >> M;
	REP(i, M)
	{
		int a, b;
		cin >> a >> b;
		_link[a].push_back(b);
		_link[b].push_back(a);
	}


	int ma = 0;

	for (int i = 1; i <= N; i++)
	{
		int cnt = 1;
		if (flg[i]) continue;

		queue<int> q;
		q.push(i);
		
		while (q.size() > 0)
		{
			int n = q.front();
			q.pop();

			flg[n] = true;

			for (int l : _link[n])
			{
				if (!flg[l])
				{
					flg[l] = true;
					q.push(l);
					cnt++;
				}
			}
		}

		ma = max(ma, cnt);
	}

	cout << ma << endl;
}



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

using namespace std;

int main(void) {
	int a1 = 0;
	int a2 = 0;
	int a3 = 0;
	int b = 0;
	scanf("%d", &a1);
	scanf("%d", &a2);
	scanf("%d", &a3);
	if (a1 <= a2) {
		if (a3 <= a1) {
			b = a2 - a3;
		}
		else if(a2 <= a3){
			b = a3 - a1;
		}
		else {
			b = a2 - a1;
		}
	}
	else {
		if (a3 <= a2) {
			b = a1 - a3;
		}
		else if (a1 <= a3) {
			b = a3 - a2;
		}
		else {
			b = a1 - a2;
		}
	}
	printf("%d", b);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s; cin >> s;
  string t = s;
  reverse(t.begin(), t.end());
  if (s != t) {
    cout << "No\n";
    return 0;
  }
  int len = s.size() / 2;
  string a1 = s.substr(0, len);
  string b1 = s.substr(s.size() - len, len);
  string a2 = a1;
  string b2 = b1;
  reverse(a2.begin(), a2.end());
  reverse(b2.begin(), b2.end());
  if (a1 != a2 || b1 != b2) {
    cout << "No\n";
    return 0;
  }
  cout << "Yes\n";
    
}

Measured memory_bytes: 256
s = input()
answer = True
for i in range(len(s)):
    if (i + 1) % 2 == 0:
        # 偶数文字目
        if s[i] == 'R':
            answer = False
    else:
        # 奇数文字目
        if s[i] == 'L':
            answer = False
    if answer == False:
        break
print('Yes' if answer else 'No')

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
const int pi=3.1415926535897932384626433832795;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
#define ll long long
#define inf int(1e9+7)
#define pb push_back
#define mp make_pair
int n;
string s;
bool res[100005];
int main()
{
	cin>>n>>s;
	for(int a=0;a<2;a++)
		for(int b=0;b<2;b++)
		{
			res[0]=a;
			res[1]=b;
			for(int j=2;j<n;j++)
				res[j]=((s[j-1]!='o')^res[j-1])^res[j-2];
			bool flag=1;
			for(int x=0;x<n;x++)
			{
				int pr=(x-1+n)%n;
				int nx=(x+1+n)%n;
				if(((s[x]=='o')^res[x])!=(res[pr]==res[nx]))
					flag=0;
			}
			if(flag)
			{
				for(int j=0;j<n;j++)
					cout<<(!res[j]?'S':'W');
				return 0;
			}
		}
	puts("-1");
	return 0;
}

Measured memory_bytes: 640
using System;

public class Program{
    public static void Main(){
         string[] input=Console.ReadLine().Split(' ');
         int N=int.Parse(input[0]);
         int A=int.Parse(input[1]);
         int B=int.Parse(input[2]);
         
         int AllSum=0;
         for(int i=1;i<=N;i++) {
             if(A<=SomeSum(i) && SomeSum(i)<=B) {
                 AllSum+=i;
             }
        }
        
        Console.WriteLine(AllSum);
    }
    
    
    
    public static int SomeSum(int number) {
        int sum=0;
     
        while(number>0) {
            sum+=number%10;
            number/=10;
        }
    
        return sum;
    }
    
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K,X,Y,sum=0;
    cin >> N >> K >> X >> Y;
    for(int i=1; i<=N; i++){
        if(i <= K){
            sum = sum + X;
        }else{
            sum = sum + Y;
        }
    }
    cout << sum << endl;
}

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

int main()
{
  int N ;
  cin>>N ;
  vector<int>a(N) ;
  for(int i=0;i<N;i++) cin>>a.at(i) ;
  
  int sum=0 ;
  for(int i=0;i<N;i++) sum+=a.at(i)-1 ;
  
  cout<<sum<<endl ;
  
  return 0 ;
}

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

int main()
{
  int i;
  cin >> i;
  if(i == 1)
  {
    cout << "Hello World";
    return 0;
  }

  int a, b;
  cin >> a >> b;
  int  c = a + b;

  cout << c;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n,k;
  int p=0;
  cin >> n >> k;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n-i;j++){
      int l=k-10000*i-5000*j;
      if(l==1000*(n-i-j)){
        cout << i<<' ' << j<<' ' << l/1000 <<endl;
        p++;
        goto label;
      }
    }
  }
  label:
  if(p==0){
    cout << -1<<' '<<-1<<' '<<-1 << endl;
  }
}


Measured memory_bytes: 256
import math
n=int(input())
for i in range(n):
  x1,y1,x2,y2,x3,y3=map(float,input().split())
  a=(x3-x1)*(x1**2+y1**2-x2**2-y2**2)-(x2-x1)*(x1**2+y1**2-x3**2-y3**2)
  b=2*(x3-x1)*(y1-y2)-2*(x2-x1)*(y1-y3)
  py=a/b
  if x2-x1!=0:
    px=(2*(y1-y2)*py-x1**2-y1**2+x2**2+y2**2)/(2*(x2-x1))
  else:
    px=(2*(y1-y3)*py-x1**2-y1**2+x3**2+y3**2)/(2*(x3-x1))
  r=math.sqrt((px-x1)**2+(py-y1)**2)
  print(f"{px:.3f}",f"{py:.3f}",f"{r:.3f}")


Measured memory_bytes: 5704
n = int(input())
a = input().split()
ans = 0
hi = int(a[0])
for i in range(1, n):
	a[i] = int(a[i])
	if a[i] - hi >= 0:
		hi = a[i]
	else:
		ans += hi - a[i]
print(ans)


			
	
	

Measured memory_bytes: 25036
#include <stdio.h>
int main(void) {
	int cnt = 0;
	int N, A;
	scanf("%d", &N);

	for (int i = 0; i < N;i++) {
		scanf("%d", & A);
		cnt += A & 1;
	}
		
	printf("%s\n", cnt & 1 ? "NO" : "YES");
	return 0;
}

Measured memory_bytes: 256
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    if 0 in a:
        print(0)
        exit()
    ans = 1
    for i in range(len(a)):
        ans *= a[i]
        if ans > 10**18:
            print(-1)
            exit()
    print(ans)
resolve()

Measured memory_bytes: 84764
from heapq import heappop, heappush

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

task_list = []

for _ in range(n):
  a, b = map(int, input().split())
  task_list.append((a, b))

task_list = sorted(task_list, key = lambda x: x[0])

hq = []
ans, j = 0, 0

for i in range(1, m+1):
  while j < n and task_list[j][0] <= i:
    heappush(hq, -task_list[j][1])
    j += 1
  if len(hq):
    ans += -heappop(hq)
  
print(ans)

Measured memory_bytes: 20424
#include<iostream>
#include<vector>
#include<cstdlib>
#include <math.h>

using namespace std;

int main(){
  int ans=0,d,i,j,k,n,a[10][10],b[3000],x,y,s;
  float t,dist,sqr;
  cin >>n>>d;

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

  for(i=1;i<300;i++){
    b[i]=i*i;
   }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      dist=0;
      if(j<=i)continue;
      else{
	for(k=0;k<d;k++){
	  dist+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
	}
      }
      for(k=1;k<300;k++)if(dist==b[k])ans++;
    }
  }

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

Measured memory_bytes: 256
//default
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed _main(){
  string S_,T; cin >> S_ >> T;
  v<string> ans;
  rep(i,S_.size()){
    bool flag=false;
    if(i+T.size()>S_.size()) break;
    for(int j=i;j<i+T.size();j++){
      if(S_[j]=='?' || S_[j]==T[j-i]);
      else{
        flag=true;
        break;
      }
    }
    if(flag) continue;
    string S="";
    rep(j,S_.size()){
      if(j>=i && j<i+T.size()) S=S+T[j-i];
      else if(S_[j]=='?') S=S+'a';
      else S=S+S_[j];
    }
    ans.push_back(S);
  }
  sort(ans.begin(),ans.end());
  if(ans.size()==0) cout << "UNRESTORABLE" << endl;
  else cout << ans[0] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define PI  3.14159265358979323846
#define lp(i,n) for(int i = 0; i <n;i++)
#define rlp(i,n) for(int i = int(n);i >= 0;i--)
#define range1(i,a,b,c) for(int i = int(a);i <= int(b);i+=int(c))
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define fr first
#define sc second
#define sz(v) ((int)((v).size()))
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef pair<int, int> pii;
template<class T> using ordered_set=tree<T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;
const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)100000+5;
int dx[] = {0,0,-1,1};
int dy[] = {1,-1,0,0};
void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int num[11];
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int n,k;
    scanf("%d %d",&n,&k);
    int x;
    lp(i,k){
        scanf("%d",&x);
        num[x]=1;
    }
    for(int i=n;i<N;i++){
        bool ok = 1;
        int temp=i;
        while(temp){
            int rem = temp%10;
            temp/=10;
            if(num[rem]){
                ok = 0;
            }
        }
        if(ok){
            printf("%d",i);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3768
if __name__ == '__main__':
	N,M = map(int, input().split())
	H = [int(a) for a in input().split()]
	ne = [1] * N

	c = 0
	for _ in range(M):
		A,B = map(int, input().split())
		if H[A-1] > H[B-1]:
			if ne[B-1] == 1:
				ne[B-1] = 0

		elif H[A-1] < H[B-1]:
			if ne[A-1] == 1:
				ne[A-1] = 0

		elif H[A-1] == H[B-1]:
			if ne[A-1] == 1:
				ne[A-1] = 0
			if ne[B-1] == 1:
				ne[B-1] = 0


	print(ne.count(1))

Measured memory_bytes: 84776
/* ex 6-2
    kas056 */

#include <stdio.h>

#define SIZE 1000

int main(void){
    int mid = -2;//間の数は入力した文字の長さ－2
    char omission[SIZE];
    int i;
    scanf("%s", omission);

    for(i = 0; i<SIZE; i++){//ヌル文字にたどり着くまでmidを増やし続ける
        if(omission[i] == '\0'){
            break;
        }
        else{
            mid += 1;
        }
    }
    if(mid < 1){//midが0以下ならエラー
        fprintf(stderr, "unexpected characters: %s", omission);
    }

    else{//最後の文字は、omission[mid+1]に入っている。
        printf("%c%d%c\n",omission[0], mid, omission[mid + 1]);
        
    }

    return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N, M;
      cin >> N >>M;
      int a[51],b[51], sum;
      for(int i=0;i<M;i++) {
        cin >> a[i] >> b[i];
      }
      
      for(int i=0;i<N;i++) {
        sum=0;
        for(int j=0;j<M;j++) {
          if(a[j]==i+1 || b[j]==i+1) {
            sum += 1;
          }
        }
        cout << sum << endl;
      }
    }

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int T;
    cin >> T;

    for (int t = 0; t < T; t++) {
        int N;
        cin >> N;

        // {K, L, R}
        vector<tuple<int, int, int>> alls;
        vector<tuple<int, int, int>> ls;
        vector<tuple<int, int, int>> rs;

        for (int i = 0; i < N; i++) {
            int K, L, R;
            cin >> K >> L >> R;
            alls.push_back(make_tuple(K, L, R));
            if (L >= R) {
                ls.push_back(make_tuple(K, L, R));
            } else {
                rs.push_back(make_tuple(N - K, R, L));
            }
        }
        sort(alls.rbegin(), alls.rend());
        sort(ls.rbegin(), ls.rend());
        sort(rs.rbegin(), rs.rend());

        auto f = [](const vector<tuple<int, int, int>> &camels) {
            const int N = (int) camels.size();
            ll acc = 0;

            // {L - R, L, R}
            priority_queue<tuple<int, int, int>> que;
            int ind = 0;
            for (int pos = N; pos > 0; pos--) {
                while (ind < N) {
                    int K, L, R;
                    tie(K, L, R) = camels[ind];
                    if (K >= pos) {
                        que.push(make_tuple(L - R, L, R));
                        ind++;
                    } else {
                        break;
                    }
                }

                if (que.empty()) {
                    continue;
                }

                {
                    int a, b, c;
                    tie(a, b, c) = que.top();
                    acc += b;
                    que.pop();
                }
            }

            while (ind < (int) camels.size()) {
                int K, L, R;
                tie(K, L, R) = camels[ind];
                que.push(make_tuple(L - R, L, R));
                ind++;
            }

            while (!que.empty()) {
                int a, b, c;
                tie(a, b, c) = que.top();
                acc += c;
                que.pop();
            }

            return acc;
        };

        ll ans = f(ls);
        // printf("f(ls): %lld\n", f(ls));
        ans += f(rs);
        // printf("f(rs): %lld\n", f(rs));
        cout << ans << endl;

    }

    return 0;
}


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

int main() {
	long n,m,i,j,k,ans,cur,res;
	cin >> n;
	vector<string> a(n);
	for(i=0; i<n; i++){
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	ans=1;
	for(i=1; i<n; i++){
		if(a[i]!=a[i-1]){
			ans++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 9500
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	getline(cin,s);
	int lens=s.length();
	for(int i=0;i<lens;i++)
		for(int j=i;j<lens;j++)
			if(s[i]=='C'&&s[j]=='F')
				{
					cout<<"Yes";
					return 0;
				 } 
	cout<<"No";			 
	return 0;
}


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

using namespace std;

#define dump(n) cerr<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define all(c) begin(c),end(c)

typedef vector<string> vs;

template<typename T>
void update_max(T& a,const T& b)
{
	a=max(a,b);
}

void dfs(vs& grid,int i,int j)
{
	int h=grid.size(),w=grid[0].size();
	if(i<0 || h<=i || j<0 || w<=j || grid[i][j]=='.')
		return;
	grid[i][j]='.';
	rep(k,4)
		dfs(grid,i+"\xff\x1\0\0"[k],j+"\0\0\xff\x1"[k]);
}

bool can_connect(const vs& _grid)
{
	vs grid=_grid;
	int cnt=0;
	rep(i,grid.size()) rep(j,grid[i].size())
		if(grid[i][j]=='#'){
			dfs(grid,i,j);
			cnt++;
		}
	return cnt<=1;
}

bool can_place(const string& key,int i,char c)
{
	if(c=='#')
		return !(i>0 && isdigit(key[i]) && key[i]==key[i-1]);
	else{
		if(key[i]=='.' || (i>0 && key[i-1]=='.'))
			return false;
		if(isdigit(key[i]) && count(all(key),key[i])==1)
			return false;
		return true;
	}
}

string adjust(string s)
{
	vector<int> m(10,-1);
	int k=0;
	rep(i,s.size())
		if(isdigit(s[i]) && m[s[i]-'0']==-1)
			m[s[i]-'0']=k++;
	rep(i,s.size())
		if(isdigit(s[i]))
			s[i]=m[s[i]-'0']+'0';
	return s;
}

string place(const string& key,int i,char c)
{
	string res=key;
	if(c=='#'){
		if(isdigit(key[i]) && i>0 && isdigit(key[i-1]))
			replace(all(res),max(key[i-1],key[i]),min(key[i-1],key[i]));
		else if(isdigit(key[i]))
			;
		else if(i>0 && isdigit(key[i-1]))
			res[i]=key[i-1];
		else
			res[i]=max<char>(*max_element(all(key))+1,'0');
	}
	else
		res[i]='.';
	return adjust(res);
}

int solve(vs& grid)
{
	if(!can_connect(grid))
		return -1;
	
	int h=grid.size(),w=grid[0].size();
	
	unordered_map<string,int> dp;
	dp[string(w,'$')]=0;
	rep(i,h) rep(j,w){
		unordered_map<string,int> dp2;
		for(auto keyval:dp){
			string key=keyval.first;
			if(grid[i][j]!='.' && can_place(key,j,'#'))
				update_max(dp2[place(key,j,'#')],keyval.second+1);
			if(grid[i][j]!='#' && can_place(key,j,'.'))
				update_max(dp2[place(key,j,'.')],keyval.second);
		}
		dp=dp2;
	}
	
	int res=-1;
	for(auto keyval:dp)
		if(all_of(all(keyval.first),[](char c){return c=='0'||c=='.';}))
			update_max(res,keyval.second);
	
	return res;
}

int main()
{
	for(int h,w;cin>>h>>w && h|w;){
		vs grid(h,string(w,' '));
		rep(i,h) cin>>grid[i];
		if(h>w){
			vs temp(w);
			rep(i,h) rep(j,w)
				temp[j]+=grid[i][j];
			grid=temp;
		}
		cout<<solve(grid)<<endl;
	}
	return 0;
}

Measured memory_bytes: 2080
#include<iostream>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
int w,h,s,sum;
P pmax(P a,P b){
	if(a>b)return a;
	return b;
}
int u[33][33];
P dp[33][33][33][33];
P ret(P a,P b,int cnt){
	if(dp[a.first][a.second][b.first][b.second].first!=-1)
		return dp[a.first][a.second][b.first][b.second];
	P ans(1,cnt);
	int s1=0,s2=0;
	for(int i=a.first;i<b.first;i++){
		for(int j=a.second;j<=b.second;j++){
			s1+=u[i][j];
		}
		if(sum-s1>s)
			continue;
		if(sum-(cnt-s1)>s)
			break;
		P x=ret(a,P(i,b.second),s1),y=ret(P(i+1,a.second),b,cnt-s1);
		ans=pmax(ans,P(x.first+y.first,min(x.second,y.second)));
	}
	for(int i=a.second;i<b.second;i++){
		for(int j=a.first;j<=b.first;j++){
			s2+=u[j][i];
		}
		if(sum-s2>s)
			continue;
		if(sum-(cnt-s2)>s)
			break;
		P x=ret(a,P(b.first,i),s2),y=ret(P(a.first,i+1),b,cnt-s2);
		ans=pmax(ans,P(x.first+y.first,min(x.second,y.second)));
	}
	return dp[a.first][a.second][b.first][b.second]=ans;
}
int main(){
	while(cin>>h>>w>>s,h||w||s){
		sum=0;
		rep(i,h)rep(j,w)rep(k,h)rep(l,w)
		dp[i][j][k][l]=P(-1,0);
		rep(i,h)rep(j,w){
			cin>>u[i][j];
			sum+=u[i][j];
		}
		P ans=ret(P(0,0),P(h-1,w-1),sum);
		cout<<ans.first<<" "<<s-(sum-ans.second)<<endl;
	}
	return 0;
}

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

using ll = long long;

ll n;
ll ans;
std::string orig_s;
std::string s;

int main() {
    std::cin >> n;
    orig_s = std::to_string(n);
    if (orig_s.size() == 1) {
        std::cout << n << std::endl;
        return 0;
    }
    for (int i = 0; i < orig_s.size()-1; i++) {
        s += '9';
    }
    ll base_ans = (orig_s.size()-1) * 9;
    ans = base_ans;
    for (int i = 1; i <= 9; i++) {
        std::string p = s;
        p.insert(0, std::to_string(i));
        ll new_ans = base_ans + i;
        ll x = std::stoll(p);
        if (x <= n && new_ans > ans) {
            ans = new_ans;
        }
    }
    std::cout << ans << std::endl;

    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef		 long long int    ll;
typedef		vector<ll>      vll;
#define     fi              first
#define     print(v)        for(ll i:v) cout<<i<<ss
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;



int main()
{
    ll ar[4]= {0};
    ll a,b;
    cin>>a>>b;
    ar[a]=1;
    ar[b]=1;
    for(ll i=1; i<4; i++)
    {
        if(!ar[i])
        {
            cout<<i<<nn;
            return 0;
        }
    }




}


/* Final check before submit :

1. array size or integer overflow,like uninitialised 0 index.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***
4. minus mod ans=(ans-k+mod)%mod;

*/






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

int main(){
	int a, b, k;
	cin >> a >> b >> k;
	int cnt = 0;
	int i;
	for (i = min(a,b); i >=1; i-- ) {
		if (a % i == 0 && b % i == 0 ) {
			cnt++;
		}
		if (cnt == k) {
			break;
		}
	}
	cout << i << endl;
}

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

const int MOD = 1e9 + 7;

using namespace std;

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

long dp[101][5][5][5];

//-------------------------↓↓↓↓↓↓------------------------

bool check(int l, int k, int j){
    if(l == 0 && k == 2 && j == 1)return false;
    else if(l == 0 && k == 1 && j == 2)return false;
    else if(l == 2 && k == 0 && j == 1)return false;
    else return true;
}
 
bool check2(int z, int l, int k, int j){
    if(z == 0 && l == 2 && k == 1)return false;
    else if(z == 0 && l == 1 && k == 2)return false;
    else if(z == 2 && l == 0 && k == 1)return false;
    else if(l == 0 && k == 2 && j == 1)return false;
    else if(l == 0 && k == 1 && j == 2)return false;
    else if(l == 2 && k == 0 && j == 1)return false;
    else if(z == 0 && k == 2 && j == 1)return false;
    else if(z == 0 && l == 2 && j == 1)return false;
    else return true;
}

int main(void){

    int n; cin >> n;
    rep(i, 4){
        rep(j, 4){
            rep(k, 4){
                if(!check(k, j, i))continue;
                dp[3][i][j][k] = 1;
            }
        }
    }

    rrep(i, 4, n + 1){
        rep(j, 4){
            rep(k, 4){
                rep(l, 4){
                    long cnt = 0;
                    rep(z, 4){
                        if(!check2(z, l, k, j))continue;
                        (cnt += dp[i - 1][k][l][z]) %= MOD;
                    }
                    (dp[i][j][k][l] += cnt) %= MOD;
                }
            }
        }
    }

    long ans = 0;
    rep(i, 4){
        rep(j, 4){
            rep(k, 4){
                (ans += dp[n][i][j][k]) %= MOD;
            }
        }
    }

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


Measured memory_bytes: 384
import math

n,d = list(map(int, input().split()))
x = []
for i in range(n):
  x.append(list(map(int, input().split())))

cnt = 0
for i in range(0, n-1):
  for j in range(i+1, n):
    sum = 0
    for k in range(0, d):
      sum += (x[i][k] - x[j][k]) ** 2
    if math.sqrt(sum).is_integer():
      cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,r) RFOR(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define lower(a,x) lower_bound(all(a), x) - a.begin();
#define COUNT(a,x)  upper_bound(all(a), x) - lower_bound(all(a), x);
#define MCOUNT(a,x,y) upper_bound(all(a), y) - lower_bound(all(a), x);
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end());
#define scan(x) scanf("%lld",&x);
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
typedef double D;
const ll inf = 5555555555555555555;
const ll mod = 1000000007;
const D pi = acos(-1);
const D eps = 1e-10;

ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool ok, flag;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111

ll cost[2222][2222], a[2222];
int main(void) {
  ll x;
  cin >> n >> x;
  rep(i, n) cin >> a[i];
  rep(i, n)rep(j, n) cost[i][j] = inf;
  rep(i, n) cost[i][0] = a[i];
  rep(i, n) FOR(j,1,n) {
	cost[i][j] = min(cost[i][j - 1], a[(i - j + n) % n]);
  }
  //rep(i, n)rep(j, n) cout << i << " " << j << " " << cost[i][j] << endl;
  ans = inf;
  rep(i, n) {
	tmp = 0;
	rep(j, n) tmp += cost[j][i];
	tmp += x*i;
	ans = min(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 35072
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
vvi G;
pii dp[50][50][50][50];
int n,m,q,sum;
pii f(int a,int b,int c,int d){
	if(dp[a][b][c][d].first!=inf)return dp[a][b][c][d];
	dp[a][b][c][d]=pii(0,0);
	loop(i,a,c)loop(j,b,d)dp[a][b][c][d].second+=G[i][j];
	rep(i,c-a-1){
		pii ta=f(a,b,a+i+1,d);
		pii tb=f(a+i+1,b,c,d);
		if(min(ta.second,tb.second)==-inf)continue;
		if(dp[a][b][c][d].first<1+ta.first+tb.first){
			dp[a][b][c][d].first=1+ta.first+tb.first;
			dp[a][b][c][d].second=min(ta.second,tb.second);
		}else if(dp[a][b][c][d].first==1+ta.first+tb.first){
			dp[a][b][c][d].second=max(dp[a][b][c][d].second,min(ta.second,tb.second));
		}
	}
	rep(i,d-b-1){
		pii ta=f(a,b,c,b+i+1);
		pii tb=f(a,b+i+1,c,d);
		if(min(ta.second,tb.second)==-inf)continue;
		if(dp[a][b][c][d].first<1+ta.first+tb.first){
			dp[a][b][c][d].first=1+ta.first+tb.first;
			dp[a][b][c][d].second=min(ta.second,tb.second);
		}else if(dp[a][b][c][d].first==1+ta.first+tb.first){
			dp[a][b][c][d].second=max(dp[a][b][c][d].second,min(ta.second,tb.second));
		}
	}
	if(dp[a][b][c][d].second<sum)dp[a][b][c][d]=pii(-inf,-inf);
//	cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
//	cout<<dp[a][b][c][d].first<<" "<<dp[a][b][c][d].second<<endl;
	return dp[a][b][c][d];
}
int main(){
	while(cin>>n>>m>>q,n+m+q){
		sum=-q;
		G=vvi(n,vi(m));
		rep(i,n)rep(j,m)cin>>G[i][j];
		rep(i,n)rep(j,m)sum+=G[i][j];
		rep(i,50)rep(j,50)rep(k,50)rep(l,50)
			dp[i][j][k][l]=pii(inf,inf);
		f(0,0,n,m);
		cout<<1+dp[0][0][n][m].first<<" "<<dp[0][0][n][m].second-sum<<endl;
	}
}

Measured memory_bytes: 51952
import numpy as np

D=int(input())
*c,=map(int,input().split())
c=np.array(c,dtype=int)
s=[]
for i in range(D):
    *x,=map(int,input().split())
    s.append(x)

s=np.array(s,dtype=int).reshape((D,26))
dt=[]
cnt=np.array([0]*26)

for d in range(D):
    x=s[d]-c*(d-cnt)
    y=np.argmax(x)
    cnt[y]=d+1
    dt.append(y+1)

def score(T):
    last=[-1]*26
    v=0
    for d in range(D):
        v+=s[d][T[d]-1]
        last[T[d]-1]=d
        for i in range(26):
            v-=c[i]*(d-last[i])
    return v

v0=score(dt)
newt=dt+[]

import random

for _ in range(1):
    for d in range(D):
        q=0
        while True:
            q=random.randint(1,26)
            if q!=newt[d]: break
        newt[d]=q
        v=score(newt)
        if v>v0:
            dt=newt
        else:
            newt=dt+[]
for i in dt:
    print(i)

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

int main()
{
    short n, count[1001] = {}, buf;
    long long answer = 1;
    cin >> n;

    for (int j = n; j >= 2; j--)
    {
        buf = j;
        for (int i = 2; i <= j;)
        {
            if (buf % i == 0)
            {
                buf /= i;
                count[i]++;
            }
            else
            {
                i++;
            }
        }
    }
    for (int i = 2; i <= n; i++)
    {
        answer = (answer * (count[i] + 1)) % 1000000007;
    }
    cout << answer;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int h = S / (60 * 60);
        int M = S % (60 * 60);
        int m = M / 60;
        int s = M % 60;
        System.out.println(h + ":" + m + ":" + s);
    }
}


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

using namespace std;

int main(){
	string str;
	cin >> str;
	vector<string> s;
	s.emplace_back("SUN");
	s.emplace_back("MON");
	s.emplace_back("TUE");
	s.emplace_back("WED");
	s.emplace_back("THU");
	s.emplace_back("FRI");
	s.emplace_back("SAT");
	for(int i=0;i<7;i++){
		if (str == s[i]){
			cout << 7 - i << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
 
#include<bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
 
#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int
#define pp pair<pii,pii>
const int hell =1e9+7;
 


int power(int a,int b)
{
  if(b==0)return 1;
  if(b==1)return a;
  int t=power(a,b/2);
  t%=hell;
  t*=t;
  t%=hell;
  if(b%2)return (t*a)%hell;
  else
     return t;
}
  
int solve( ){


int a,b;
cin>>a>>b;
a*=3;
cout<<(b+a)/2;

return 0;
 
}
 
 
signed main()
{  int t=1;
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin.exceptions(cin.failbit);                                                                    
 
  
 
  clock_t time_req;
 
    // Without using pow function
                                                                                                                   
 
    //cin>>t;
 
    int k=1;
   while(t--)
     {
       //cout<<"case #"<<k<<":"<<" ";k++;
      solve();
     }
 
         time_req = clock() - time_req;
    //cout <<endl<< "Processor time taken is "
      //<< (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;
 
 
    return 0;
  }

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}



int main(){
    ll n,m;
    cin >> n >> m;
    if (n==1 and m==1){
        cout << 1 << endl;
    }else if(n==1 or m==1){
        cout << max(n,m)-2 << endl;
    }else{
        cout << (n-2)*(m-2) << endl;
    }
    return 0;
}



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

int log_two(int n) {
	int count = 0;
	while (n % 2 == 0) {
		n /= 2; count++;
	}
	return count;
}

int main() {
	int n; cin >> n;
	long long a[n];
	long long ans = 0;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) ans += log_two(a[i]);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
N = int(input())
*A, = map(int,input().split())
ans1 = 0
S = A[0]
if S <= 0:
    ans1 = abs(S)+1
    S = 1
for a in A[1:]:
    S1 = S+a
    if S1*S >= 0:
        ans1 += abs(S1)+1
        S1 = -S//abs(S)
    S = S1
ans2 = 0
S = A[0]
if S >= 0:
    ans2 = abs(S)+1
    S = -1
for a in A[1:]:
    S1 = S+a
    if S1*S >= 0:
        ans2 += abs(S1)+1
        S1 = -S//abs(S)
    S = S1
print(min(ans1,ans2))

Measured memory_bytes: 14468
import numpy as np
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
s = np.array(s)
s[s == '#'] = 1
s[s == '.'] = 0
s = s.astype(np.int)
S = np.pad(s, [1, 1], 'constant')

ans = 'Yes'
for i in range(H):
    for j in range(W):
        if s[i, j] == 1:
            if np.sum(S[i:i+3, j+1]) + np.sum(S[i+1, j:j+3]) == 2:
                ans = 'No'
    if ans == 'No':
        break
                
print(ans)

Measured memory_bytes: 12504
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> h(n);
  for(int i=0;i<n;i++)
    cin>>h.at(i);
  vector<int> dp(n,0);
  dp[1]=abs(h.at(0)-h.at(1));
  for(int i=2;i<n;i++)
    dp[i]=min(dp[i-2]+abs(h.at(i-2)-h.at(i)),dp[i-1]+abs(h.at(i-1)-h.at(i)));
  cout<<dp.at(n-1)<<endl;
}

Measured memory_bytes: 1024