akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<static_cast<int>(n);++i)
#define per(i, n) for(int i=static_cast<int>(n)-1;i>=0;--i)
#define eee(a) (cerr<<"[@"<<__LINE__<<"] "<<(#a)<<": "<<(a)<<'\n');
#define ppp(a) (cout<<(a)<<'\n'); 
#define cop(a) for(auto x:(a)){cerr<<(x)<<'\n';}
using ll = long long;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n,ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}
template<class T>inline bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename T>inline int bs(int g,int k,T c){while(abs(k-g)>1){int m=(g+k)/2;(c(m)?k:g)=m;}return k;}
template<typename T1,typename T2>ostream& operator<<(ostream& s,const pair<T1, T2>& p){return s <<"("<<p.first<<", "<<p.second<<")";}
template<typename T> ostream& operator<<(ostream& s,const vector<T>& v){s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i<v.size()-1)s<<", ";}s<<']';return s;}
template<typename T> istream& operator>>(istream& s,vector<T>& v){for(T& x:v)s>>x;return s;}

int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    int x = 0;
    for(int i = 0; i < n; ++i)
        x ^= a[i];
    for(int i = 0; i < n; ++i)
        cout << (x^a[i]) << ' ';
    cout << '\n';
    
    return 0;
}


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

#define REMNUM 1000000007
// x+y
static inline long modadd(long x, long y) {
  return (long)((long long)(x + y) % REMNUM);
}
// x*y
static inline long modmul(long x, long y) {
  return (long)(((long long)(x * y)) % REMNUM);
}
// x^y
static long modpow(long x, long y) {
  long res = 1;
  while (y > 0) {
    if (y & 1) {
      res = modmul(res, x);
    }
    x = modmul(x, x);
    y >>= 1;
  }

  return res;
}
static inline long modinv(long x) { return modpow(x, REMNUM - 2); }
// x/y
static inline long moddiv(long x, long y) { return modmul(x, modinv(y)); }
// xCy => x*(x-1)*...*(x-y+1)/y*(y-1)*...*1
static long modcombination(long x, long y) {
  long divided = 1;
  long divisor = 1;

  for (int i = 0; i < y; i++) {
    divided = modmul(divided, (x - i));
    divisor = modmul(divisor, (y - i));
  }

  return moddiv(divided, divisor);
}

int main(int argc, char **argv) {
  int K, N;
  long ans;

  int blue, red;

  cin >> N >> K;
  blue = K;
  red = N - K;

  long bluepat, redpat;
  for (int i = 0; i < K; i++) {

    bluepat = modcombination(K - 1, i);
    redpat = modcombination(N - K + 1, i + 1);
    ans = modmul(bluepat, redpat);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import time
st_time=time.time()

from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
ts=time.time()
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
show_flg=False
#show_flg=True

ans=0
n,k=LI()
a=LI()
f=LI()

a=sorted(a)[::-1]
f=sorted(f)
p=[a[i]*f[i] for i in range(n)]
show(a)
show(f)
show(p)

def check(z):
    c=0
    for i in range(n):
        c+=max(0,a[i]-z//f[i])
    if c<=k:
        rt=True
    else:
        rt=False
    return rt

ng=-1
ok=10**12

while ok-ng>1:
    mid=(ok+ng)//2
    fl=check(mid)
    if fl:
        ok=mid
    else:
        ng=mid
    show(ok,ng,fl)

ans=ok
print(ans)


Measured memory_bytes: 119212
#include <iostream>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int main () {
    int A, B;
    cin >> A >> B;
    if (A == 1) A = 14;
    if (B == 1) B = 14;
    if (A == B) cout <<"Draw" << endl;
    else if (A > B) cout << "Alice" << endl;
    else cout << "Bob" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<set>
#include<map>
using namespace std;
int w, h, n;
int field[4000][4000];
pair<int, int> tapes[1000][2];
set<int> width, height;
map<int, int> widmap, heimap;

void dfs(int x, int y){
  if(x < 0 || y < 0 || x >= widmap[w] || y >= heimap[h] || field[x][y] != 0)return;
  field[x][y] = 1;
  dfs(x - 1, y);
  dfs(x + 1, y);
  dfs(x, y + 1);
  dfs(x, y - 1);     
}

int main(){
  while(1){
    memset(field, 0,sizeof(field));    
    scanf("%d%d", &w, &h);
    if(w == 0 && h == 0)return 0;
    width.clear();
    height.clear();
    widmap.clear();
    heimap.clear();
    width.insert(w);
    height.insert(h);
    
    scanf("%d", &n);
    for(int i = 0;i < n;i++){
      int x1, y1, x2, y2;
      scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
      tapes[i][0] = make_pair(x1, y1);
      tapes[i][1] = make_pair(x2, y2);
      width.insert(x1);
      width.insert(x2);
      height.insert(y1);
      height.insert(y2);
    }
    set<int>::iterator it;
    int pos = !!(*width.begin());
    for(it = width.begin();it != width.end();it++, pos++){
      widmap[*it] = pos;
    }
    pos = !!(*height.begin());
    for(it = height.begin();it != height.end();it++, pos++){
      heimap[*it] = pos;
    }
    for(int i = 0;i < n;i++){
      int x1, x2, y1, y2;
      x1 = widmap[tapes[i][0].first];
      x2 = widmap[tapes[i][1].first];
      y1 = heimap[tapes[i][0].second];
      y2 = heimap[tapes[i][1].second];
      field[x1][y1]++;
      field[x2][y2]++;
      field[x1][y2]--;
      field[x2][y1]--;
    }
    for(int i = 0;i <= widmap[w];i++){
      for(int j = 1;j <= heimap[h];j++){
	field[i][j] += field[i][j - 1];
      }
    }
    for(int j = 0;j <= heimap[h];j++){
      for(int i = 1;i <= widmap[w];i++){
	field[i][j] += field[i - 1][j];
      }
    }
    int res = 0;
    for(int i = 0;i < widmap[w];i++){
      for(int j = 0;j < heimap[h];j++){
	if(field[i][j] == 0){
	  dfs(i, j);
	  res++;
	}
      }
    }
    printf("%d\n", res);
  }
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

int main (){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];

    int cnt1 = 0, cnt2 = 0;
    rep(i, 3){
        if(a[i] == 7){
            cnt1++;
        }
        if(a[i] == 5){
            cnt2++;
        }
    }


    if(cnt1 == 1 && cnt2 == 2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
typedef long double ld;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
 
#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 12
#define MM 1005
int h, w, k;
char gr[MN][MM];
int amt[MN];
int cvs[MN];

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

    cin >> h >> w >> k;
    F0R(i, h){
        F0R(j, w){
            cin >> gr[i][j];
        }
    }
    int ans = INF;
    F0R(bm, 1<<(h-1)){
        //cout << "doing " << bm << "\n";
        int cnt = __builtin_popcount(bm)+1;
        int tot = cnt-1;
        bool ok = true;
        F0R(i, w){
            int cur = 0;
            F0R(j, h){
                if(gr[j][i] == '1'){
                    //cout << j << " " << i << " counts for " << cur << "\n";
                    cvs[cur]++;
                }
                
                if(j < h-1 && (bm&(1<<j))) ++cur;
            }
            bool cok = true;
            F0R(j, cnt){
                //cout << j << " cur " << amt[j] << " add " << cvs[j] << "\n";
                if(cvs[j] > k){
                    ok = false;
                    break;
                }
                if(amt[j]+cvs[j] > k){
                    cok = false;
                }
            }
            if(!ok){
                F0R(j, cnt){ cvs[j] = 0; amt[j] = 0;}
                break;
            }
            if(!cok){
                ++tot;
                F0R(j, cnt) amt[j] = cvs[j];
            } else{
                F0R(j, cnt) amt[j] += cvs[j];
            }

            F0R(j, cnt) cvs[j] = 0;
        }
        if(ok){
            //cout << "found " << bm << " " << tot << "\n";
            ans = min(ans, tot);
        }
        F0R(j, cnt) amt[j] = 0;
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
def gojoho(a,b):
    a,b=max(a,b),min(a,b)
    while a%b!=0:
        a,b=b,a%b
    return b
def main(a,b):
    return (a*b)//gojoho(a,b)
N=int(input())
T=[int(input()) for i in range(N)]
T.sort(reverse=True)
ans=T[0]
for i in range(1,N):
    ans=main(ans,T[i])
print(ans)

Measured memory_bytes: 3064
N = int(input())
right_count = [0 for i in range(N)]
left_count = [0 for i in range(N)]
A = list(map(int, input().split()))

for i, a in enumerate(A):
    if i - a >= 0:
        left_count[i - a] += 1
    if i + a < N:
        right_count[i + a] += 1

answer = 0
for i in range(N):
    answer += left_count[i] * right_count[i]

print(answer)


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

int main() {
  string s;
  cin >> s;
  int q;
  cin >> q;
  string t;
  rep(qi, q) {
    int ty;
    cin >> ty;
    if (ty == 1) {
      swap(s, t);
    } else {
      int f;
      char c;
      cin >> f >> c;
      if (f == 1) {
        t += c;
      } else {
        s += c;
      }
    }
  }
  reverse(t.begin(), t.end());
  t += s;
  cout << t << endl;
  return 0;
}

Measured memory_bytes: 1128
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    
    bad = False
    for i in range(3):
        if S[i] == S[i+1]:
            bad = True
            break
            
    if bad:
        print('Bad')
    else:
        print('Good')
    
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9120
//This is a very good reframing
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	int n,k;cin>>n>>k;
      vector<int >h(n,0);
      for(int i=0;i<n;i++)cin>>h[i];
      sort(h.begin(),h.end());
      int mini = 1000000000;
      for(int i=0;i+k-1<n;i++){
      	mini = min(mini,h[i+k-1]-h[i]);
      }
      cout<<mini;
    }

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

const int maxn = 2005;
ll dp[maxn][maxn]; // s[i]==t[j]のとき、s[i](t[j])を末尾文字にして作れる共通部分列の個数
// s[i]==t[j]であるとき、末尾をs[i]にしてできる共通部分列の個数は(i-1,j-1)までに存在する共通部分列の個数+1となる
// 求める全体での共通部分列の個数は、dpで求めたs[i]==t[j]となるときのそれぞれの共通部分列の個数の和+1({}の場合)となる
ll sub[maxn][maxn]; // sub[i+1][j+1]: dp[i+1][j+1]までの累積和 つまり(i,j)までの共通部分列の個数

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,m; cin>>n>>m;
  vll s(n), t(m);
  rep(i,n) cin>>s[i];
  rep(i,m) cin>>t[i];
  
  rep(i,n){
    rep(j,m){
      if(s[i]==t[j]){
        (dp[i+1][j+1]=sub[i][j]+1)%=MOD;
      }else{
        dp[i+1][j+1]=0;
      }
      
      (sub[i+1][j+1]=(sub[i][j+1]+sub[i+1][j]-sub[i][j]+dp[i+1][j+1]+MOD)%MOD)%=MOD;
    }
  }
  
  ll ans=(sub[n][m]+1)%MOD;
  cout<<ans<<endl;
}

Measured memory_bytes: 66272
#include <bits/stdc++.h>  
using namespace std;  
#define INF 0x3f3f3f3f  
typedef long long ll;  
const int N = 551;  

int main()  
{  
 //   freopen("in.txt", "r", stdin);
    string a, b;
    while (cin >> a >> b)
    {
    	int i = 0, j = 0;
    	while (i < a.size() || j < b.size())
    	{
    		if (i < a.size())
    		{
    			putchar(a[i]);
    			i++;
    		}

    		if (j < b.size())
    		{
    			putchar(b[j]);
    			j++;
    		}
    	}
    	puts("");
    }
  
   return 0;  
}  

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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

	int n, h;
	cin >> n >> h;

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

	int a_id = 0;
	int b_id = 0;
	sort(a.begin(), a.end(), greater<int>());
	sort(b.begin(), b.end(), greater<int>());

	int res = 0;
	while (b[b_id] > a[a_id] && h > 0) {
		h -= b[b_id++];
		res++;

		if (b_id >= n)
			break;
	}
	if (h > 0)
		res += ceil(h / (double)a[a_id]);

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
    int n,i,m[100];
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &m[i]);
    }
    for(i = n-1; i >= 0; i--){
        printf("%d", m[i]);
        if(i != 0){
            printf(" ");
        }
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2048
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<int,int> P;
ll longinf=1ll<<60;
int inf=1<<29;


ll n;
ll k;

int main(){
      cin>>n>>k;
      if(k%2==0){
            ll a=n/k;
        ll b=((n%k)>=(k/2));
            cout<<a*a*a+(a+b)*(a+b)*(a+b)<<endl;
      }
      else{
            ll a=(n/k);
            cout<<a*a*a<<endl;
      }
      return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner vd = new Scanner(System.in);
		int a = vd.nextInt();
		int b = vd.nextInt();
		int c = vd.nextInt();
		if(a==b) System.out.println(c);
		if(c==b) System.out.println(a);
		if(a==c) System.out.println(b);
		
	}

}


Measured memory_bytes: 23764
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	ll n,ans=INFLL,i,j;
	cin >> n;
	for(i=1; i*i<=n; ++i){
		if(n%i){
			continue;
		}
		j = n/i;
		ans = min(ans,i+j-2);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <unordered_map>
#include <utility>
#include <map>
#include <set>
using namespace std;

int main(){
    long long int n;
    vector<char> s;
    cin >> n;
    long long int i = 0;
    long long int j = 0;
    
    
    if(n == 0){
        cout << 0 << endl;
    }else{
        while(n != 0){
            if(abs(n%2) == 1){
                s.push_back('1');
                n -= 1;
                n /= -2;
            }else{
                s.push_back('0');
                n /= -2;
            }
            i++;
        }
        
        for(j = i-1; j >= 0; j--){
            cout << s[j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<algorithm>
using namespace std;
const int maxn=2e5;
struct p{
    int v;
    int type;
}a[maxn];
bool operator<(p a,p b){
    return a.v>b.v;
}
int vis[maxn];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i].type>>a[i].v;
    }
    sort(a,a+n);
    stack<p>q;
    long long cnt=0;
    long long ans=0;
    for(int i=0;i<k;i++){
        if(!vis[a[i].type]){
            cnt++;
            vis[a[i].type]=1;
        }
        else
            q.push(a[i]);
        ans+=a[i].v;
    }
    long long out=ans+cnt*cnt;
    for(int i=k;i<n;i++){
        if(vis[a[i].type])continue;
        if(q.empty())break;
        cnt++;
        ans+=a[i].v-q.top().v;
        out=max(out,ans+cnt*cnt);
        vis[a[i].type]++;
        q.pop();
        //q.push(a[i]);
    }
    cout<<out;
}


Measured memory_bytes: 1664
H,N=map(int,input().split(' '))
Magics = [list(map(int,input().split(' '))) for i in range(N)]
dp=[float('inf')]*(H+1)
dp[H]=0
for i in range(H,-1,-1):
    for a,b in Magics:
        if 0<=i-a<=H:
            dp[i-a]=min(dp[i-a],dp[i]+b)
        else:
            dp[0]=min(dp[0],dp[i]+b)
print(dp[0])

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

using namespace std;
 
int main()
{
    int N;
    cin >> N;

    vector<int> P(N), Q(N);
    int pi=0, qi=0;
    for (int i = 0; i < N; i++) { cin >> P[i]; pi = 10 * pi + P[i]; }
    for (int i = 0; i < N; i++) { cin >> Q[i]; qi = 10 * qi + Q[i]; }

    sort(P.begin(), P.end());
    sort(Q.begin(), Q.end());
    
    int a=0;
    do {
        int tmp = 0;
        for (int i = 0; i < N; i++) { tmp = 10 * tmp + P[i]; }
        a++;
        if (tmp == pi) {
            break;
        }
    } while (next_permutation(P.begin(), P.end()));

    int b=0;
    do {
        int tmp = 0;
        for (int i = 0; i < N; i++) { tmp = 10 * tmp + Q[i]; }
        b++;
        if (tmp == qi) {
            break;
        }
    } while (next_permutation(Q.begin(), Q.end()));

    cout << ((a > b) ? a - b : b - a) << endl;
}


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

int main()
{
    int N;
    int d[100] = {0};

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

    std::set<int> values;

    for (int i = 0; i < N; i++){
        values.insert(d[i]);
    }

    std::cout << values.size() << std::endl;

    return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}




void _main() {
        string s; cin >> s;
        deque<char> deq(all(s));

        auto check = [&](string s) -> bool {
                if (s.size() > deq.size()) return 0;
                string t;
                for (int i = 0; i < sz(s); i++) t += deq[i];
                return s == t;
        };

        auto remove = [&](string s) {
                for (int i = 0; i < sz(s); i++) deq.pop_front();
        };


        while (deq.size()) {
                if (check("dreameraser")) remove("dreameraser");
                else if (check("dreamerase")) remove("dreamerase");
                else if (check("dreamer")) remove("dreamer");
                else if (check("dream")) remove("dream");
                else if (check("eraser")) remove("eraser");
                else if (check("erase")) remove("erase");
                else {
                        cout << "NO";
                        return;
                }
        }

        cout << "YES";
}




signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 3772
#include<stdio.h>
int main(){
        int a,b,c;
        int x=0;
	
        scanf("%d%d%d",&a,&b,&c);
        
	//aからbの間
        for(;a <= b;a++){
        	//cの約数があったとき
        	if(c % a == 0){
        		x++;
        	}
        }
        	printf("%d\n",x);
        
        return 0;
}


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

using namespace std;

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 ll INF=1e9+7;


int main(){
    ll r,g,b,n;
    cin >> r >> g >> b >> n;
    ll ans=0;
    for(ll i=0;i<=3000;i++){
        for(ll j=0;j<=3000;j++){
            ll v=n-i*r-g*j;
            if(0<=v && v%b==0) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
a = int(input())
l = []

for i in range(a-1):
    ta,tb,tc  = map(int,input().split())
    l.append([ta,tb,tc])

for i in range(a-1):
    s = 0
    s += sum(l[i][:2])
    for j in range(i+1,a-1):
        # print(i,j,s)
        if s<= l[j][1]:s = sum(l[j][:2])
        elif s%l[j][2]==0 :s+=l[j][0]
        else : s+=l[j][2]- s%l[j][2] + l[j][0]
        # print(l[j][0])
    print(s)
print(0)

Measured memory_bytes: 3188
# import sys

# n = int(input())

# result = []
# k = 26
# i = 1

# while k < n:
# 	n -= k
# 	k *= 26
# 	i += 1

# length = i
# n -= 1

# pow26 = 1
# for i in range(length):

n = int(input())
a = list(map(int, input().split()))

s = 0
for x in a:
	s = s ^ x

result = map(lambda x: str(x ^ s), a)
print(" ".join(result))


Measured memory_bytes: 33532
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl
typedef pair<int,int> Pp;

signed main(){
    int N;
    cin >> N;
    if(N==1){
        cout << "Hello World" << endl;
    }else{
        int A,B;
        cin >> A >> B;
        cout << A+B << endl;
    }
    return 0;
}   


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

int main() {
  int n,s=0;
  cin>>n;
  int m = n;
  while(m){
    s += m % 10;
    m /= 10;
  }
  cout<<(n % s ? "No" : "Yes") << endl;
}


Measured memory_bytes: 256
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).split('\n');
main();

function main(){
  var w = parseInt(input[0], 10);
  var n = parseInt(input[1], 10);

  var goto = new Int8Array(w);
  for(var i = 0, len = goto.length; i < len; i++){
    goto[i] = i;
  }

  for(var i = 2; i < n + 2; i++){
    var c = input[i].split(",");
    var from = parseInt(c[0], 10) - 1;
    var to = parseInt(c[1], 10) - 1;

    goto[from] ^= goto[to];
    goto[to] ^= goto[from];
    goto[from] ^= goto[to];
  }

  for(var i = 0; i < len; i++){
    console.log(goto[i] + 1);
  }
}

Measured memory_bytes: 7644
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	c := 1
	for i := 0; i < n; i++ {
		if c < k {
			c *= 2
		} else {
			c += k
		}
	}
	fmt.Println(c)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
#define MAXN 100100
struct hoge {
  int t, x, y;
};
hoge a[MAXN];
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  REP(i, N) { cin >> a[i].t >> a[i].x >> a[i].y; }
  //  bool ok = true;
  hoge now = {0, 0, 0};
  REP(i, N) {
    hoge diff = {a[i].t - now.t, a[i].x - now.x, a[i].y - now.y};
    int v0 = diff.x + diff.y;
    int v1 = diff.x - diff.y;
    int maxV = max(abs(v0), abs(v1));
    bool flg = maxV % 2 == diff.t % 2 && maxV <= diff.t;
    if (!flg) {
      //      cerr << i << " " << diff.x << " " << diff.y << " " << diff.t;
      print("No");
      return 0;
    }
    now = a[i];
  }
  print("Yes");
}

Measured memory_bytes: 2560
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

    ll h, w; cin>>h>>w;

    if(h == 1 || w == 1){
        cout << 1 << endl;
        return 0;
    }

    cout << (h * w + 1) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
'use strict'

function main(input) {

  const nums = input.split('\n')[1].split(' ').map(n => Number(n));
  const arr = [];

  //  27 23 76 2 3 5 62 52
  // -> [27, 50, 126, 128, 131, 136, 198, 250 ]
  for (let i = 0, cum = 0; i < nums.length; i++) {
    cum += nums[i];
    arr.push(cum);
  }
  
  const sum = arr[arr.length - 1];
  let min = sum;
  
  for (let i = 0; i < arr.length - 1; i++) {
    min = Math.min(min, Math.abs(arr[i] - (sum - arr[i])));
  }

  console.log(min);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
  [n, k] <- f
  solve k <$> replicateM n readLn >>= print
  where
    f = map read <$> words <$> getLine

solve :: Int -> [Int] -> Int
solve k xs = let ss = sort xs
             in f (10^9) ss (drop (k - 1) ss)
  where
    f mn as [] = mn
    f mn (a:as) (b:bs) = f (min mn (b - a)) as bs


Measured memory_bytes: 65916
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
#define dmp(x) cerr << __LINE__ << " " << #x << " " << x << endl;
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
template<class T,class U>
ostream& operator << (ostream& os,pair<T,U>& p){
	os << p.fi << ',' << p.sec; return os;
}
template<class T,class U>
istream& operator >> (istream& is,pair<T,U>& p){
	is >> p.fi >> p.sec; return is;
}
template<class T>
ostream& operator << (ostream &os,const vector<T> &vec){
	for(int i=0;i<vec.size();i++){
		os << vec[i];
		if(i+1<vec.size())os << ' ';
	}
	return os;
}
template<class T>
istream& operator >> (istream &is,vector<T>& vec){
	for(int i=0;i<vec.size();i++)is >> vec[i];
	return is;
}
void fastio(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
}
P a,b;
int main(){
  cin >> a.sec >> b.sec >> a.fi >> b.fi;
  if(a.fi==-1||b.fi==-1){
    if(a.sec==b.sec)cout << "Draw" << endl;
    else if(a.sec<b.sec)cout << "Alice" << endl;
    else cout << "Bob" << endl;
    return 0;
  }
  a.sec *= -1;
  b.sec *= -1;
  if(a.fi==b.fi||a==b)cout << "Draw" << endl;
  else if(a<b)cout << "Bob" << endl;
  else cout << "Alice" << endl;
	return 0;
}



Measured memory_bytes: 3100
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function moveup(x::Array{Int,1},n)
	k = length(x)
	for i in 1:k-1
		if x[k-i+1] > n-1
			x[k-i] += div(x[k-i+1],n)
			x[k-i+1] = x[k-i+1]%n
		end
	end
	if x[1] > n-1
		0
	else
		x
	end
end

function main()
    n = readline() |> parseInt
    s = readline() |> chomp
    t = Int[Int(s[i]) for i in 1:2*n]
    fh = Dict{Tuple{Int,Int,Int,Int},Int}()
	b1 = 101
	b2 = 103
	p = 10^9+7
    v = 0
    a = zeros(Int,n)
	while a!=0
		fr1 = 0
		fb1 = 0
		fr2 = 0
		fb2 = 0
		fo = 0
		fz = 0
		for i in 1:n
			if a[i]==1
				fr1 = (fr1+t[i]*b1^fo%p)%p
				fr2 = (fr2+t[i]*b2^fo%p)%p
				fo += 1
			else
				fb1 = (fb1+t[i]*b1^fz%p)%p
				fb2 = (fb2+t[i]*b2^fz%p)%p
				fz += 1
			end
		end
		if haskey(fh,(fr1,fr2,fb1,fb2))
			fh[(fr1,fr2,fb1,fb2)] += 1
		else
			fh[(fr1,fr2,fb1,fb2)] = 1
		end
		a[n]+=1
		a=moveup(a,2)
	end
	ans = 0
    a = zeros(Int,n)
	while a!=0
		lr1 = 0
		lb1 = 0
		lr2 = 0
		lb2 = 0
		lo = 0
		lz = 0
		for i in 1:n
			if a[n+1-i]==0
				lr1 = (lr1+t[2*n+1-i]*b1^lo%p)%p
				lr2 = (lr2+t[2*n+1-i]*b2^lo%p)%p
				lo += 1
			else
				lb1 = (lb1+t[2*n+1-i]*b1^lz%p)%p
				lb2 = (lb2+t[2*n+1-i]*b2^lz%p)%p
				lz += 1
			end
		end
		if haskey(fh,(lr1,lr2,lb1,lb2))
			ans += fh[(lr1,lr2,lb1,lb2)]
		end
		a[n]+=1
		a=moveup(a,2)
	end
	println(ans)
end

main()

Measured memory_bytes: 151584
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
using namespace std;

int main(){
	long long N;
	cin >> N;
	int count=0;
	for (long long i = 1; i < N ; i++)
	{
		for (long long j = 1; j < N; j++)
		{
			if (i * j < N && i * j > 0) count++;
			else break;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var dg = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToList();
            var n = dg[0];
            var m = dg[1];

            int x = m / n;
            
            for (int i = x; i > 0; --i)
            {
                if (m % i == 0)
                {
                    Console.WriteLine(i);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 13268
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner cin = new Scanner(System.in);
        String[] line = cin.nextLine().split(" ");
        long N = Long.parseLong(line[0]);
        long A = Long.parseLong(line[1]);
        long B = Long.parseLong(line[2]);

        long ans = N/(A+B) * A + Math.min(A, N%(A+B));
        System.out.println(ans);
        cin.close();
    }
}

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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define tll(n) array<long long,(int)(n)>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define vt(n) vector<array<long long,(int)(n)>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define lin(s) getline(cin,(s))
#define Ssort(v) sort((v).begin(),(v).end(),[](auto &left,auto &right){return left.second<right.second;})

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
//YES.NO
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename t>
constexpr t mypow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
        }
    return x;
}
#define pow mypow

//chmin,chmax
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;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll a,b,c;
    cin>>a>>b>>c;
    cout<<min(c,b/a)<<endl;
}

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

int n,k,sum=1; 

int main()
{
	cin >> n >> k;
	int a=k;
	while(a <= n)
	{
		a *= k;
		sum++;	
	} 
	cout << sum << endl;
	return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

typedef pair<int,int> P;

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> p(m);
  vector<int> y(m);
  vector<vector<int>> c(n+1);

  for (int i=0; i<m; i++) {
    cin >> p[i] >> y[i];
    c[p[i]].push_back(y[i]);
  }

  for (int i=1; i<=n; i++) sort(c[i].begin(), c[i].end());

  for (int i=0; i<m; i++) {
    printf("%06d%06ld\n",p[i], lower_bound(c[p[i]].begin(), c[p[i]].end(), y[i]) - c[p[i]].begin() + 1);
  }

}

Measured memory_bytes: 7808
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

int main(){
	
	int N;
	cin >> N;
	cout << (N % 2 == 0 ? N : N * 2 )<< endl;
	
	
	
	
	
	
    return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: Two Abbreviations
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef long long ll;

/* global variables */

char s0[MAX_N + 4], s1[MAX_N + 4];

/* subroutines */

int gcd(int m, int n) {
  if (m < n) swap(m, n);
  while (n > 0) {
    int r = m % n;
    m = n;
    n = r;
  }
  return m;
}

/* main */

int main() {
  int n0, n1;
  scanf("%d%d%s%s", &n0, &n1, s0, s1);

  int g = gcd(n0, n1);
  //printf("g=%d\n", g);

  int d0 = n0 / g, d1 = n1 / g;
  for (int i = 0; i < g; i++)
    if (s0[d0 * i] != s1[d1 * i]) {
      puts("-1");
      return 0;
    }

  printf("%lld\n", (ll)n0 * n1 / g);
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 33


int h, w, s, u[SIZE][SIZE] = {};
int sum_u[SIZE][SIZE] = {};
pair<int, int> dp[SIZE][SIZE][SIZE][SIZE]; //Group, rest

int rangeSum(int t, int l, int b, int r){
  return sum_u[t][l] + sum_u[b][r] - sum_u[t][r] - sum_u[b][l];
}

pair<int,int> merge(pair<int,int> a, pair<int,int> b){
  return {a.first + b.first, min(a.second, b.second)};
}

int solve(){
  
  scanf("%d%d%d", &h, &w, &s);

  int L = -s;
  
  if(h == 0) return false;
  
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      scanf("%d", u[i]+j);
      sum_u[i][j] = sum_u[i][j-1] + u[i][j];
      L += u[i][j];
    }
  }
  
  for(int i=1;i<=h;i++){
    for(int j=0;j<=w;j++){
      sum_u[i][j] += sum_u[i-1][j];
    }
  }

  for(int t=0;t<h;t++){
    for(int l=0;l<w;l++){

      for(int b=t+1;b<=h;b++){
        for(int r=l+1;r<=w;r++){
          int res = rangeSum(t,l,b,r);
          if(res >= L)
            dp[t][l][b][r] = {1, res - L};
          else
            dp[t][l][b][r] = {0, -INF};
        }
      }
      
    }
  }

  
  for(int p=1;p<=h;p++){
    for(int q=1;q<=w;q++){
      for(int t=0;t+p<=h;t++){
        for(int l=0;l+q<=w;l++){
          if(p == 1 && q == 1) continue;
          
          int b = t+p;
          int r = l+q;
          
          for(int i=t+1;i<b;i++){
            if(dp[t][l][i][r].first && dp[i][l][b][r].first){
              dp[t][l][b][r] = max(dp[t][l][b][r],
                                   merge(dp[t][l][i][r], dp[i][l][b][r]));
            }
          }

          for(int i=l+1;i<r;i++){
            if(dp[t][l][b][i].first && dp[t][i][b][r].first){
              dp[t][l][b][r] = max(dp[t][l][b][r],
                                   merge(dp[t][l][b][i], dp[t][i][b][r]));
            }
          }
        }
      }
      
    }
  }

  printf("%d %d\n", dp[0][0][h][w].first, dp[0][0][h][w].second);
  
  
  return true;
}

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



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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

Measured memory_bytes: 256
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 2000005
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); //cout.tie(0);
#define pi 3.1415926535897
#define db double
#define noop
#define flu fflush(stdout)
#define imp {cout<<"NO\n"; return 0;}
#define debug_vec(vec,n) {rep(idxi,n) cout<<vec[idxi]<<" "; cout<<"\n";}
#define debug_pvec(vec,n) {rep(idxi,n) cout<<vec[idxi].fi<<"-"<<vec[idxi].se<<"  "; cout<<"\n";}
#define debug_set(seta) {cout<<seta.size()<<"\n"; for(auto idxi:seta) cout<<idxi<<" "; cout<<"\n";}
#define debug_map(mappa) {cout<<mappa.size()<<"\n";for(auto idxi:mappa) cout<<idxi.fi<<"-"<<idxi.se<<"  "; cout<<"\n";}

ll dp[405][405];
int main() {
    
    rep(i,405) rep(j,405) dp[i][j] = INT_MAX;
    get2(n,m);
    vector<string> A(n);
    rep(i,n) {
        gets(s);
        A[i] = s;
    }

    ll mvx[4] = {1,0,-1,0};
    ll mvy[4] = {0,1,0,-1};

    rep(i,n*m) {
        ll x = i/m, y = i%m;
        if(A[x][y]=='.') {
            dp[i][i] = 0;

            rep(j,4) {
                ll nx = x+mvx[j], ny = y+mvy[j];
                if(nx<n && nx>=0 && ny<m && ny>=0 && A[nx][ny]=='.')
                    dp[i][nx*m+ny] = 1;
            }
        }
    }
    rep(k,n*m) {
        rep(i,n*m) {
            rep(j,n*m) {
                if(dp[i][k]+dp[k][j] < dp[i][j]) 
                    dp[i][j] = dp[i][k]+dp[k][j];
            }
        }
    }

    ll maxi = 0;
    rep(i,405) rep(j,405) if(dp[i][j] != INT_MAX) maxi = max(dp[i][j], maxi);
    printf("%lld\n", maxi);
    return 0;  
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);++i)
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; }
int gcd(int a,int b) { return b ? gcd(b,a%b) : a;}
int lcm(int a,int b) { return a/gcd(a,b)*b;}
void printb(unsigned int v) {
  unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1);
  do putchar(mask & v ? '1' : '0');
  while (mask >>= 1);
}
void putb(unsigned int v) {putchar('0'), putchar('b'), printb(v), putchar('\n');}
#define ALL(W) (W).begin(),(W).end()

signed main(){
  int N;
  cin >> N;
  int A[N]={};
  rep(i,N){
    int a;
    cin >> a;
    a--;
    A[a]=i+1;
  }
  rep(i,N-1) cout << A[i] << " ";
  cout << A[N-1] << endl;
  return 0;
}


Measured memory_bytes: 1536
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
int main(){
    int n;
    string str = "ai1333";
    scanf("%d", &n);
    n/=100;
    for (int i = 0; i < n; i++) str+='3';
    printf("%s\n", str.c_str());
    return 0;
}



Measured memory_bytes: 2792
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
using namespace std;

const int INF = 1 << 30;

typedef struct
{
  int x, y;
} Point;

int main()
{
  int x, y;
  while (cin >> x >> y) {
    if ((x|y) == 0)
      break;

    int sx, sy, gx, gy;
    vector<vector<Point> > path(5);
    for (int i = 0; i < y; ++i) {
      string s;
      cin >> s;
      for (int j = 0; j < x; ++j) {
	if (s[j] == 'S') {
	  sx = j;
	  sy = i;
	} else if (s[j] == 'G') {
	  gx = j;
	  gy = i;
	} else if (s[j] != '.') {
	  path[s[j]-'1'].push_back((Point){j, i});
	}
      }
    }
    
    int ans = INF, ansIndex = -1;
    for (int ele = 0; ele < 5; ++ele) {
      vector<vector<int> > dp(5, vector<int>(1000, INF));
      for (int i = 0; i < path[(ele+1)%5].size(); ++i)
	dp[0][i] = abs(sx-path[(ele+1)%5][i].x)+abs(sy-path[(ele+1)%5][i].y);

      for (int i = 0; i < 3; ++i) {
	for (unsigned int j = 0; j < path[(ele+i+1)%5].size(); ++j) {
	  for (unsigned int k = 0; k < path[(ele+i+2)%5].size(); ++k)
	    dp[i+1][k] = min(dp[i+1][k], dp[i][j] + abs(path[(ele+i+1)%5][j].x-path[(ele+i+2)%5][k].x) + abs(path[(ele+i+1)%5][j].y-path[(ele+i+2)%5][k].y));
	}
      }

      for (int i = 0; i < path[(ele+4)%5].size(); ++i)
	dp[4][0] = min(dp[4][0], dp[3][i] + abs(path[(ele+4)%5][i].x-gx) + abs(path[(ele+4)%5][i].y-gy));

      if (dp[4][0] < ans) {
	ans = dp[4][0];
	ansIndex = ele+1;
      }
    }

    if (ans == INF)
      cout << "NA" << endl;
    else
      cout << ansIndex << " " << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1000