akhauriyash/Code-Regression huggingface dataset:
mod = 10**9+7

# N = 15
N = int(input())
xx = list(map(int, input().split()))

a = 1
for i in range(2,N):
    a *= i
    a %= mod

aa = [a]
for i in range(N-2):
    aa.append((aa[-1]+a*pow(i+2,mod-2,mod))%mod)


dx = [xx[i]-xx[i-1] for i in range(1,N)]

ans = 0
for a,d in zip(aa,dx):
    ans += a*d
    ans %= mod

print(ans%mod)


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

int ryuka(int64_t x, vector<int64_t> &vec){
  if (x == 0 || x == 1){
    return vec.at(x);
  }
  else {
    for (int i = 2; i < x+1; i++){
      vec.at(i) = (int64_t)vec.at(i-1) + (int64_t)vec.at(i-2);
    }
    return vec.at(x);
  }
}

int main(){
  int64_t n;
  cin >> n;
  vector<int64_t> vec(n+1);
  vec.at(0) = 2LL;
  vec.at(1) = 1LL;
  ryuka(n, vec);
  cout << vec.at(n) << endl;
}

Measured memory_bytes: 3580
n,m = map(int,input().split())

aL = []
for _ in range(n):
    kal = list(map(int,input().split()))
    al = kal[1:]
    aL.append(al)


tmp = aL[0]
for al in aL:
    tmp = set(al) & set(tmp)
    
print(len(tmp))

Measured memory_bytes: 38256
import math
import sys
def gcd(a,b):
    if b==0:
        return a
    return gcd(b, a%b)
def lcm(a,b):
    return a/gcd(a,b)*b
for l in sys.stdin:
    a=list(map(int,l.split()))
    print("%d %d"%(gcd(a[0],a[1]),lcm(a[0],a[1])))


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define int long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

const int N=1e5+5;

int32_t main()
{
    IOS;

    int n;
    
    cin>>n;
    
    if(n==1)
    {
         cout<<"Yes\n";
         cout<<"2\n";
         cout<<"1 1\n";
         cout<<"1 1\n";
         return 0;
    }
    
    bool check=false;
    
    int idx;
    
    for(int i=1;i<=(1e4);i++)
    {
         if(i*(i+1)==2*n)
         {
              check=true;
              idx=i;
              break;
         }
    }
    
    if(!check)
    {
         cout<<"No";
         return 0;
    }
    
    cout<<"Yes"<<endl;
    
    cout<<idx+1<<endl;

     int cnt=idx;
     int curr=1;
     
     vector <int> v[N];
     
    for(int i=1;i<=idx;i++)
    {
         int temp=cnt;
         
         int var=curr;
         
         while(temp)
         {
              v[i].pb(curr);
              curr++;
              temp--;
         }
         
         for(int j=i+1;j<=idx+1;j++)
         {
              v[j].pb(var);
              var++;
         }
         
         cnt--;
    }
    
    for(int i=1;i<=idx+1;i++)
    {
         cout<<v[i].size()<<" ";
         for(int j=0;j<v[i].size();j++)
          cout<<v[i][j]<<" ";
          
          cout<<endl;
          
    }
    
    return 0;

}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
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;}
const int inf = 1001001001;

int main() {
    double a,b,x;
    cin >> a >> b >> x;
    x /= a;
    double ans;
    if(x < a*b/2) {
        double na = x*2/b;
        ans = atan(na/b);
    } else {
        double nb = (a*b-x)*2/a;
        ans = atan(a/nb);
    }
    const double pi = acos(-1);
    ans = ans/pi*180;
    printf("%.8f",90-ans);
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, M;
    ll ans = 0;
    vector<vector<ll>> s;
    vector<ll> p;
    cin >> N >> M;
    s.resize(M);
    p.resize(M);
    rep(i, M) {
        ll k;
        cin >> k;
        s[i].resize(k);
        rep(j, k) {
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    rep(i, M) cin >> p[i];
    rep(i, 1LL << N) {
        rep(j, M) {
            ll count = 0;
            iter(k, s[j]) if(i & (1LL << k)) count++;
            if(p[j] != count % 2) goto aaa;
        }
        ans++;
        aaa:;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N;
int h[100];

void solve(){
	int ans = 0;
	while(true){
		int i = 0;
		bool start = false;
		rep(i,N){
			if(h[i] != 0) {
				start = true;
				h[i]--;
			}
			else if(start)
				break;
		}
		if(start) ans++;
		else break;
	}
	cout<<ans<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	rep(i, N) {
		cin>>h[i];
	}
		solve();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007

using namespace std;

int max(int a, int b)
{
    if(a>b) return a;
    else return b;
}
 
int min(int a,int b)
{
    if(a<b) return a;
    else return b;
}

signed main()
{
    IOS;
    int k;
    cin>>k;
    int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout<<a[k-1];
    
    return 0;
}



Measured memory_bytes: 256
using System;

namespace Ss2
{
    class Program
    {
        static void Main(string[] args)
        {
            string sWord = Console.ReadLine();
            int f = 0;
            while (true)
            {
                string S = Console.ReadLine();
                if (S == "END_OF_TEXT")
                {
                    break;
                }
                string S2 = S.Replace(" ", ",");
                string[] sc = S2.Split(',');
                foreach(string item in sc)
                {
                    if (item.ToLower() == sWord.ToLower())
                    {
                        f++;
                    }
                }
            }
            Console.WriteLine(f);
        }
    }
}

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

using namespace std;

const int N_ = int(1.1e5);

int N;
vector<int> gph[N_];

int ans;

int par[N_];

void dfs(int u, int p = -1) {
  par[u] = p;
  for(int v : gph[u]) if(v != p) dfs(v, u);
}

int stop;
int cnt;
  vector<int> pth;
void dfs2(int u, int p = -1) {
  if(u == stop) return;
  cnt += 1;
  for(int v : gph[u]) {
    if(v != p) {
      dfs2(v, u);
    }
  }
}

int main() {
  scanf("%d", &N);
  for(int i = 0; i < N-1; i++) {
    int u, v; scanf("%d%d", &u, &v);
    gph[u].push_back(v);
    gph[v].push_back(u);
  }

  dfs(1);

  for(int i = N; i > 0; i = par[i]) {
    pth.push_back(i);
  }
  reverse(pth.begin(), pth.end());

  stop = pth[(int)(pth.size() + 1) / 2];

  dfs2(1);

  puts(cnt > N - cnt ? "Fennec" : "Snuke");
  return 0;
}

Measured memory_bytes: 11644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define     FasterIO        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     bug(a,b)        cout<<a<<"\t"<<b<<"\n";
#define     Case(a,b)       cout<<"Case "<<a<<": "<<b<<"\n";
#define     watch(a)        cout<<fixed<<setprecision(a)
#define     lp(i,a,b)       for(int i=a;i<b;i++)
#define     Endl            "\n";
#define     tab             "\t"
#define     reset(a,b)      memset(a,b,sizeof(a));
#define     sf(a)           scanf(" %d", &a);
#define     srt(a)          sort(a.begin(),a.end());
#define     pi              2*acos(0.0)
#define     inf             INT_MAX
const int sz=1e5+9;
int n,w;
ll wi[109],v[109];
ll dp[109][sz];

ll re(int i,int c){
    if(c<=0 || i>n)return 0;
    if(dp[i][c]!=-1)return dp[i][c];
    ll ret1=0,ret2=0;
    ret1=re(i+1,c);
    if(c>=wi[i]){
        ret2=re(i+1,c-wi[i]);
       // cout<<"nnn\t"<<ret2<<tab<<v[i]<<endl;
        ret2+=v[i];
       // bug("ret2",ret2);
    }
   // bug(ret1,ret2);
//bug("max",max(ret1,ret2));
    return dp[i][c]=max(ret1,ret2);
}




void solve(){
    reset(dp,-1);
    cin>>n>>w;
    lp(i,1,n+1)cin>>wi[i]>>v[i];
    cout<<re(1,w)<<"\n";
}

int main(){
   // FasterIO;
   // #ifndef ONLINE_JUDGE
      //  freopen("1.txt","r",stdin);
   // #endif
 //   int t;
 //   cin>>t;
    //while(getline(cin,a)){
    //    getline(cin,b);
        solve();
   // }
}


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

#define mod 1000000007
#define all(x) (x).begin(), (x).end()

const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}

int main(){
    ll n;
    cin >> n;
    ll cnt;
    ll n4 = 0, n2 = 0, n1 = 0;
    for(ll i = 0; i < n; i++){
        ll a = 0;
        cin >> a;
        if(a % 4 == 0) n4++;
        else if(a % 2 == 0) n2++;
        else n1++;
    }

    if(n1 > n4+1){
        puts("No");
        return 0;
    }
    
    if(n1 == n4+1){
        if(n2 == 0){
            puts("Yes");
            return 0;
        }else{
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

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

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

#define pb push_back
#define fr first
#define sc second

const long double EPS = 0.00000000001;

struct BIT{
	int siz;
	int a[(1<<16)+10];
	void init(int siz_ = 1<<16){
		siz = siz_;
		for(int i = 1 ; i <= siz ; i ++){
			a[i] = 0;
		}
	}
	void add(int k,int x = 1){
		while(k <= siz){
			a[k] += x;
			k += k&-k;
		}
	}
	int sum(int k){
		int ret = 0;
		while(k > 0){
			ret += a[k];
			k -= k&-k;
		}
		return ret;
	}
}bit;

int N;
long double A[40002];
long double B[40002];
long double C[40002];

int inv(vector<pair<long double,long double>> *vec){
	/*for(int i = 0 ; i < vec->size() ; i ++){
		cout << (*vec)[i].fr << " " << (*vec)[i].sc << endl;
	}*/
	
	vector<pair<long double,int>> a;
	for(int i = 0 ; i < vec->size() ; i ++){
		a.pb(pair<long double,int>((*vec)[i].sc,i+1));
	}
	sort(a.begin(),a.end());
	int ret = 0;
	bit.init();
	for(int i = 0 ; i < a.size() ; i ++){
		ret += bit.sum(a[i].sc);
		bit.add(a[i].sc);
	}
	return N*(N-1)/2-ret;
}

long double sol(){
	long double l = -200000000.0 , r = 200000000.0;
	while(l+EPS < r){
		long double m = (l+r)/2.0;
		vector<pair<long double,long double>> vec;
		for(int i = 1 ; i <= N ; i ++){
			vec.pb(pair<long double,long double>((C[i]-A[i]*m)/B[i],-A[i]/B[i]));
		}
		sort(vec.begin(),vec.end());
		if(inv(&vec)*2 <= N*(N-1)/2)r = m;
		else l = m;
	}
	return l;
}

int main(){
	cout.precision(20);
	
	scanf("%d",&N);
	for(int i = 1 ; i <= N ; i ++){
		cin >> A[i] >> B[i] >> C[i];
	}
	long double X = sol();
	
	for(int i = 1 ; i <= N ; i ++){
		swap(A[i],B[i]);
	}
	long double Y = sol();
	
	cout << X << " " << Y << endl;
}



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

int main() {
  int N;cin>>N;
  vector<int> Ans(10100);
  for(int x=1;x<105;x++){
    for(int y=1;y<105;y++){
      for(int z=1;z<105;z++){
        int A=x*x+y*y+z*z+x*y+y*z+z*x;
        if(A<10100) Ans.at(A-1)++;
      }
    }
  }
  for(int i=0;i<N;i++) cout<<Ans.at(i)<<endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


            
int main(){
    ll h,n;cin>>h>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll sum=0;
    rep(i,0,n-1)sum+=a[i];
    if(sum>=h){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
    
    return 0;
}


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

bool check(char k) {
  if ((k == 'A') || (k == 'T') || (k == 'C') || (k == 'G')) {
    return true;
  }
  else {
    return false;
  }
}



int main() {
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 0; i < S.size(); i++) {
    int count = 0;
    while (check(S.at(i))) {
      count++;
      i++;
      if (i >= S.size()) {
        break;
      }
    }
    ans = max(count,ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static long Solve(long[] A, bool positive)
        {
            long sum = 0, ans = 0;
            foreach (var value in A)
            {
                sum += value;
                if (positive && sum <= 0)
                {
                    long add = 1 - sum;
                    ans += add;
                    sum += add;
                }
                else if (!positive && sum >= 0)
                {
                    long add = sum - (-1);
                    ans += add;
                    sum -= add;
                }

                positive = !positive;
            }

            return ans;
        }

        static void Main(string[] args)
        {
            Console.ReadLine();
            long[] A = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long ans = Min(Solve(A, true), Solve(A, false));
            Console.WriteLine(ans);
        }
    }
}

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

using namespace std;

int gcd(int a, int b) {
  return b != 0 ? gcd(b, a % b) : a;
}

int main() {
  int N, X, d;
  vector<int> x(N);
  cin >> N >> X;

  for (int i = 0; i < N; i++) {
    cin >> d;
    x.push_back(d);
  }

  int ans = abs(X - x[0]);
  for (int j = 1; j < x.size(); j++) {
    ans = gcd(ans, abs(x[j] - x[j-1]));
  }

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


Measured memory_bytes: 892
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

x,a,b=MI()
if b-a<=0:
    print("delicious")
elif b-a<=x:
    print("safe")
else:
    print("dangerous")

Measured memory_bytes: 38708
#include<stdio.h>
#include<string.h>

void swap(int* x, int* y) {
	int tmp;

	tmp = *x;
	*x = *y;
	*y = tmp;
}

void sort(int array[], int n) {
	int i, j;
	for (i = 0; i < n - 1; i++) {
		for (j = n - 1; j >= i + 1; j--) {
			if (array[j] < array[j - 1]) {
				swap(&array[j], &array[j - 1]);
			}
		}
	}
}

int main(void) {
	int a[100], i, n, x, c = 0;

	scanf("%d %d", &n, &x);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	sort(a, n);

	for (i = 0; i < n-1; i++) {
		if (x >= a[i]) {
			x -= a[i];
			c++;
		}
		else {
			break;
		}
	}
	n -= 1;

	if (a[n] == x) {
		c++;
	}
	printf("%d", c);
}


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

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

    sort(A.begin(), A.end());
    int res = 0, pre = 0, cnt = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] == pre) {
            cnt++;
        } else {
            if (cnt < pre) res += cnt;
            else res+= (cnt - pre);
            cnt = 1;
        }
        pre = A[i];
    }
    if (cnt < pre) res += cnt;
    else res+= (cnt - pre);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
#define MAX_N 100000000
using namespace std;
bool debug=false;

int main(){
  int n;
  string str;
  cin>>str>>n;
  rep(i,0,n){
    int a,b;
    string s;
    cin>>s;
    if(s=="replace"){
      string c;
      cin>>a>>b>>c;
      for(int i=a;i<=b;i++)str[i]=c[i-a];
    }else if(s=="reverse"){
      cin>>a>>b;
      reverse(str.begin()+a,str.begin()+b+1);
    }else if(s=="print"){
      cin>>a>>b;
      for(int i=a;i<=b;i++)cout<<str[i];
      cout<<endl;
    }

  }

  return 0;
}

Measured memory_bytes: 3176
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define li long
#define ll long long
#define ull unsigned long long
#define f first
#define s second
#define pb push_back
#define fori(i,k,n) for(int i = k;i<n; i++)
#define rfori(i,k,n) for(int i = k; i>=n; i--)
#define cd complex<double>

void optimize()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int power(int x, int y)
{
   int res = 1;

    //x = x % p;

    while (y > 0)
    {

        if (y & 1)
            res = (res*x) ;


        y = y>>1;
        x = (x*x) ;
    }
    return res;
}
bool check(stack<char> &a,stack<char> &b)
{
    while(!a.empty()&&(!b.empty()))
    {
        if(a.top()!=b.top())return false;
        a.pop();
        b.pop();
    }
    return true;
}
const int N = 10000000;
int lp[N+1];
unordered_set<int> st;
vector<int> pr;
void solve(){
for (int i=2; i<=N; ++i) {
    if (lp[i] == 0) {
        lp[i] = i;
        st.insert(i);
        pr.push_back(i);
    }
    for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
        lp[i * pr[j]] = pr[j];
}
}
class TrieNode
{
public:

    TrieNode* left;
    TrieNode* right;
    TrieNode()
    {
        left = NULL;
        right = NULL;
    }
};
void insert(TrieNode* head,int x)
{
    TrieNode* curr = head;
    for(int i = 31; i>=0; i--)
    {
        int b = (x>>i)&1;
        if(b == 0)
        {
            if(!curr->left)curr->left = new TrieNode();
            curr = curr->left;
        }
        else
        {
            if(!curr->right)curr->right = new TrieNode();
            curr = curr->right;
        }
    }
}
int maxXorVal(TrieNode* head,vector<int> &arr,int n)
{
    int max_xor = INT_MIN;
    for(int i = 0; i<n; i++)
    {
        int val = arr[i];
        TrieNode* curr = head;
        int curr_xor = 0;
        for(int j = 31; j>=0; j--)
        {
            int b = (val>>j)&1;
            if(b == 0)
            {
                if(curr->right)curr = curr->right,curr_xor+=power(2,j);
                else curr = curr->left;
            }
            else
            {
                if(curr->left)curr = curr->left,curr_xor += power(2,j);
                else curr = curr->right;
            }
        }
        max_xor = max(max_xor,curr_xor);
    }
    return max_xor;
}
void test_case()
{
	ull n,a,b;
	cin>>n>>a>>b;
	ll x = a,y = b;
	ll z = a,w = b;
    if((b-a)&1)
    {
        ll r1 = x;
        y-=x;
        r1+=(y-1)/2;
        ll r2 = n-w+1;
        z+=r2;
        r2+=(n-z)/2;
        ll r = min(r1,r2);
        ll ans = min(n-a,b-1);
        cout<<min(r,ans);
    }
    else cout<<(b-a)/2;
}

int main()
{
	optimize();
	test_case();

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 1e3;
const lli INF = 1e18;
const lli MOD = 1e9+7;

bool m[N];
vi primes(1,2);
ld nk[N][N];
void sieve(){
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

void pascal(){
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

// ---- コーディングはここから！ ('-')7


int main(){_
	lli a,b,c; cin>>a>>b>>c;
	cout<<b/c - (a-1)/c<<ENDL; 

}


Measured memory_bytes: 3608
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
// inputに入力データ全体が入る
function Main(input) {
  // 1行目がline1, 2行目がline2, …に入る
  var tmp = input.split("\n");
  var line0 = tmp[0].split(" ");
  //var line1 = tmp[1].split(" ");
  //var line2 = tmp[2].split(" ");
  //var line3 = tmp[3].split(" ");

  var N = Number(line0[0]); //S
  var M = Number(line0[1]); //c
  //var A = Number(line0[1]);
  //var B = Number(line0[2]);
  
  var count = 0;
  //console.log(N + " "+ M)
  if(N > M/2) console.log(Math.floor(M/2));
  else{
    M = M - N*2;
    console.log(N + Math.floor(M / 4));
  }


}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 8268
//abc119c
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i < (n);++i)
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
int INF = 1e9;

int n;
vector<pair<int,int>> now(4,pair<int,int>(0,0));
vector<int> len(3);
int ans = INF;
void dfs(int depth, vector<int> &l) {
  
  if(depth < n){
    for(int i=0;i<4;i++){    
      now[i].first+=l[depth];
      now[i].second+=1;
      dfs(depth+1,l);
      now[i].first-=l[depth];
      now[i].second-=1;
   }
  }else{
    //cost
    int tmp = 0;
    for(int i=0;i<3;i++){
      if(now[i].second == 0) return;
      //目的の長さとの差＋くっつける回数
      tmp += abs(len[i]-now[i].first)+10*(now[i].second-1);
    }
    ans = min(ans,tmp);
  }
}

int main(){
 cin >> n;
 for(int i=0;i<3;i++) cin >> len[i];
 vector<int> l(n);
 for(int i=0;i<n;i++) cin >> l[i];
 dfs(0,l);
 cout << ans << endl;
 
  
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <unordered_set>
#include <unordered_map>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<P, int> PP;
static const int INF = 1000010000;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge{
  int to;
};

int main(){
  int n, m;
  cin >> n >> m;
  bool flag[10][10];
  REP(i, 10) REP(j, 10){
    flag[i][j] = false;
  }
  REP(i, m){
    int a, b;
    cin >> a >> b;
    flag[a][b] = flag[b][a] = true;
  }
  int ans = 0;
  vector<int> v(n);
  iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
  do {
    if(v[0] != 1) continue;
    int s = v[0];
    bool f = true;
    REP(i, n - 1){
      if(!flag[v[i]][v[i + 1]]){
        f = false;
      }
    }
    if(f) ans++;
  }while(next_permutation(v.begin(), v.end()));
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
int n, p, a[50];
int main() {
	while(~scanf("%d", &n), n) {
		for(int i = 0; i < n; i++) scanf("%d", &a[i]); p = 0;
		for(int i = 1; i < n; i++) {
			if(a[i - 1] + 1 != a[i]) {
				if(i - p != 1) printf("%d-%d ", a[p], a[i - 1]);
				else printf("%d ", a[p]);
				p = i;
			}
		}
		if(n - p != 1) printf("%d-%d\n", a[p], a[n - 1]);
		else printf("%d\n", a[p]);
	}
	return 0;
}

Measured memory_bytes: 2556
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n;
		while ((n = scan.nextInt())!=0) {
			int a=0,b=0;
			for (int i = 0; i < n; i++) {
				int x = scan.nextInt();
				int y = scan.nextInt();

				if(x>y) a+=x+y;
				if(x<y) b+=x+y;
				if(x==y){
					a+=x;
					b+=y;
				}
			}

			System.out.println(a+" "+b);
		}
	}
}

Measured memory_bytes: 51696
h,w = [int(i) for i in input().split()]
p = []
for i in range(h):
  p.append(input())
for i in range(h):
  p[i] = '#'+p[i]+'#'
p.insert(0,'#'*(w+2))
p.append('#'*(w+2))
for i in range(h+2):
  print(p[i])

Measured memory_bytes: 3064
/// 12:17 am 02/08/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)

#include<bits/stdc++.h>

using namespace std;
#define endl '\n'
typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n, k;
    cin >> n >> k;
    vector<ll> v(n);
    for (auto &x:v) {
        cin >> x;
    }
    ll be = 0;
    for (ll i = k; i < n; i++) {
        if (v[be] < v[i]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
        be++;
    }
    return 0;
}

Measured memory_bytes: 4764
N,K = map(int, input().split())
S = input()

A = []
pre = S[0]
cnt = 1
for i in range(1,N):
  if pre == S[i]:
    cnt += 1
  else:
    pre = S[i]
    A.append(cnt)
    cnt = 1
A.append(cnt)
if len(A) == 1:
  print(N-1)
  exit(0)
ans = sum(A) - len(A)
# X は真ん中。Yは端っこ。引数はIndexのMOD2。
X,Y = [0,0], [0,0]
for i in range(len(A)):
  if i == 0 or i == len(A)-1:
    Y[i%2] += 1
  else:
    X[i%2] += 1
    
wk = [0,0]
for i in range(2):
  if K <=X[i]:
    wk[i] = K * 2
  elif K <= X[i] + Y[i]:
    wk[i] = X[i] * 2 + (K-X[i])
  else:
    wk[i] = X[i] * 2 + Y[i]

print(ans + max(wk))
exit(0)
print(ans, wk)
print(A)
print(X)
print(Y)

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

using ll = long long;
using ull = unsigned long long;
#define repi(n) for (int i = 0; i < (n); i++)
#define repj(n) for (int j = 0; j < (n); j++)
#define repk(n) for (int k = 0; k < (n); k++)
#define rep(i, a, b) for (auto i = (a); i < (b); i++)
#define itr(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = std::max(t, (v)))
#define updatemin(t, v) (t = std::min(t, (v)))

#include <boost/operators.hpp>

class modint : private boost::operators<modint>, private boost::equivalent<modint> {
  modint(const long long x, const bool y)
      : x(x) {}

 public:
  static long long M;
  long long x;
  modint(const long long x = 0)
      : x((x % M + M) % M) {}
  modint operator-() const { return modint(x ? M - x : 0, true); }
  modint& operator+=(const modint& b) { return ((x += b.x) >= M ? x -= M : 0), *this; }
  modint& operator++() { return (++x >= M ? x -= M : 0), *this; }
  modint& operator-=(const modint& b) { return ((x -= b.x) < 0 ? x += M : 0), *this; }
  modint& operator--() { return (--x < 0 ? x += M : 0), *this; }
  modint& operator*=(const modint& b) { return x = x * b.x % M, *this; }
  modint& operator/=(const modint& b) { return *this *= b.pow(-1); }
  modint pow(long long b) const {
    long long r = 1, a = x;
    b = (b % (M - 1) + (M - 1)) % (M - 1);
    while (b) {
      if (b & 1) r = r * a % M;
      b = b >> 1;
      a = a * a % M;
    }
    return modint(r, true);
  }
  friend bool operator<(const modint& a, const modint& b) { return a.x < b.x; }
  friend std::istream& operator>>(std::istream& s, modint& a) { return s >> a.x, a = a.x, s; }
  friend std::ostream& operator<<(std::ostream& s, const modint& a) { return s << a.x; }
};
long long modint::M = 1e9 + 7;

main() {
  modint n, m;
  cin >> n >> m;
  modint re(0), nci(1), mpi(1), mipni(1);
  repi(n) mipni *= m - i;
  repi(n + 1) {
    re += nci * pow(-1, i) * mpi * mipni.pow(2);
    nci *= n - i;
    nci /= i + 1;
    mpi *= m - i;
    mipni /= m - i;
  }
  cout << re << endl;
}


Measured memory_bytes: 3932
"use strict";
function main(input) {
    const line = input.split("\n");
    const N = parseInt(line[0]);
    let arr = line[1].split(" ");
    const S = arr[0];
    const T = arr[1];
    let ans = "";
    for (let i = 0; i < N; i++) ans = ans + S[i] + T[i];
    console.log(ans);
    return;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29632
#include<iostream>
#include<array>
#include<algorithm>
#include<cmath>

int main()
{
    std::array<int,3> input;
    int N;
    for(std::cin >> N; N > 0; --N)
    {
        std::cin >> input[0] >> input[1] >> input[2];
        std::sort(begin(input),end(input));
        if(input[2] == hypot(input[1],input[0]))
        {
            std::cout << "YES" << std::endl;
        }
        else
        {
            std::cout << "NO" << std::endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k;
	cin>>k;
	int a,b;
	cin>>a>>b;
	for(int i =a ;i<=b;i++){
		if(i%k==0){
			cout<<"OK";
			return 0;
		}
	}
	cout<<"NG";
}

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

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

vector<int> num(N) ;

for( int i = 0 ; i < N ; i++){
       cin >> num.at(i) ;
}
sort(num.begin(), num.end() );
reverse(num.begin(), num.end() );

int A = 0, B = 0 ;
for(int i = 0; i<N ; i++){
       if( i%2 == 0){
               A = A + num.at(i) ;
        }
       else {
               B = B + num.at(i) ;
        }
}
cout << A - B << endl;



}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;

	if (a == 1 && b != 1)
		cout << "Alice";
	if (b == 1 && a != 1)
		cout << "Bob";
	if (a > b && b != 1 )
		cout << "Alice";
	if (b > a && a!= 1 )
		cout << "Bob";
	if (a == b)
		cout << "Draw";
	return 0;
}

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

struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
#define int long long

signed main(){
    int n; cin >> n;
    int ans = 0;
    rep(i,n){
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
}

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

#a[i]:s[0]~s[i]までに何個ACがあったか
a = [0]*n
#end[i]:s[i]がACの'C'か
end = [False]*n
for i in range(1,n):
    if s[i] == 'C' and s[i-1] == 'A':
        a[i] = a[i-1]+1
        end[i] = True
    else:
        a[i] = a[i-1]

for i in range(q):
    L,R = map(int,input().split())
    L,R = L-1,R-1
    if L == 0:
        print(a[R])
    else:
        if end[L]:
            print(a[R]-a[L-1]-1)
        else:
            print(a[R]-a[L-1])


Measured memory_bytes: 7644
#include<bits/stdc++.h>
using namespace std;
int main(){
  int i,j=0,k=0;
  string s;cin>>s;
  for(i=0;i<s.size();i++)
    if(s[i]=='S') j++;
    else if(j>0) k++,j--;
  cout << s.size()-k*2 << endl;
  return 0;
}


Measured memory_bytes: 640
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

// ref: https://github.com/bluss/permutohedron/blob/master/src/lexical.rs
pub trait Permutation {
    fn next_permutation(&mut self) -> bool;
}

impl<T: Ord> Permutation for [T] {
    fn next_permutation(&mut self) -> bool {
        // These cases only have 1 permutation each, so we can't do anything.
        if self.len() < 2 { return false; }

        // Step 1: Identify the longest, rightmost weakly decreasing part of the vector
        let mut i = self.len() - 1;
        while i > 0 && self[i-1] >= self[i] {
            i -= 1;
        }

        // If that is the entire vector, this is the last-ordered permutation.
        if i == 0 {
            return false;
        }

        // Step 2: Find the rightmost element larger than the pivot (i-1)
        let mut j = self.len() - 1;
        while j >= i && self[j] <= self[i-1]  {
            j -= 1;
        }

        // Step 3: Swap that element with the pivot
        self.swap(j, i-1);

        // Step 4: Reverse the (previously) weakly decreasing part
        self[i..].reverse();

        true
    }
}

fn dist(p: &[(f64, f64)], arr: &[usize]) -> f64 {
    let n = arr.len();
    let mut ret = 0f64;
    for i in 1..n {
        let d2 = (p[arr[i]].0 - p[arr[i-1]].0) * (p[arr[i]].0 - p[arr[i-1]].0) +(p[arr[i]].1 - p[arr[i-1]].1) * (p[arr[i]].1 - p[arr[i-1]].1);
        ret += d2.sqrt().clone();
    }
    ret
}

fn main() {
    input! {
        n: usize,
        p: [(f64, f64); n],
    }
    let mut arr = vec![];
    for i in 0..n {
        arr.push(i);
    }

    let mut ret = 0f64;
    loop {
        ret += dist(&p, &arr);
        if !arr.next_permutation() {
            break;
        }
    }
    for i in 1..=n {
        ret /= i as f64;
    }

    println!("{}", ret);
}


Measured memory_bytes: 2212
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  cin>>n;
  rep(i,n){
    set<string> st;
    string s,s1,s2,s3,s4;
    cin>>s;
    rep(j,s.size()-1){
      s1=s2=s.substr(0,j+1);
      s3=s4=s.substr(j+1,s.size()-1-j);
      reverse(all(s2));
      reverse(all(s4));
      st.insert(s1+s3); st.insert(s1+s4);
      st.insert(s3+s1); st.insert(s4+s1);
      st.insert(s2+s3); st.insert(s2+s4);
      st.insert(s3+s2); st.insert(s4+s2);
    }
    cout<<st.size()<<endl;
  }
}

Measured memory_bytes: 3228
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int dy[] = {-1, 0, 1, 0}, dx[] = {0, -1, 0, 1};
int h, w, c, in[8][8];
bool v[8][8];

int dfs(int y, int x, int col){
	int prev = in[y][x], res = 1;
	v[y][x] = 1;
	if(col > 0) in[y][x] = col;
	rep(d, 4){
		int ny = y + dy[d], nx = x + dx[d];
		if(ny < 0 || nx < 0 || ny >= h || nx >= w || v[ny][nx]) continue;
		if(in[ny][nx] == prev) res += dfs(ny, nx, col);
	}
	return res;
}

int rec(int cnt){
	if(cnt == 0){
		memset(v, 0, sizeof(v));
		return dfs(0, 0, -1);
	}
	int res = 0, prev;
	memset(v, 0, sizeof(v));
	if(in[0][0] == c) res = prev = dfs(0, 0, -1);
	
	rep(i, 6) if(in[0][0] != i + 1){
		if(cnt == 1 && i + 1 != c) continue;
		
		int tmp[8][8];
		memset(v, 0, sizeof(v));
		memcpy(tmp, in, sizeof(in));
		dfs(0, 0, i + 1);
		res = max(res, rec(cnt - 1));
		memcpy(in, tmp, sizeof(in));
	}
	return res;
}

int main(){
	while(cin >> h >> w >> c, h){
		rep(i, h) rep(j, w) cin >> in[i][j];
		cout << rec(5) << endl;
	}
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
	int N;
	cin >> N;
	vector<int> t(N+1), x(N+1), y(N+1);
	t[0]=0;x[0]=0;y[0]=0;
	REP(i, N) cin >> t[i+1] >> x[i+1] >> y[i+1];
	bool flag = true;
	REP(i, N){
		int dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);
		if(dist>t[i+1]-t[i]){
			flag = false;
		}else{
			if ((t[i+1] - t[i] - dist)%2==1) flag = false;
		}
	}
	cout << (flag ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define N 0
#define INF 0x3f3f3f3f
#define LL long long
#define mz(x) ms(x,0)
#define ms(x,y) memset(x,y,sizeof(x))
#define mc(x,y) memcopy(x,y,sizeof(y))
#define MOD 1000000007

using namespace std ;

int a[200010], b[200010] ;
int sa[200010], sb[200010] ;

int main()
{
	int n, m, k ;
	scanf ("%d%d%d", &n, &m, &k) ;
	
	for (int i=0; i<n; i++)
	{
		scanf ("%d", a + i) ;
		sa[i] = (i > 0 ? sa[i-1] : 0) + a[i] ;
	}
		
	for (int i=0; i<m; i++)
	{
		scanf ("%d", b + i) ;
		sb[i] = (i > 0 ? sb[i-1] : 0) + b[i] ;
	}
	
	int rda = 0, rdb = 0 ;
	int ai = 0, bi = 0 ;
	while ((ai < n && k >= a[ai]) || (bi < m && k >= b[bi]))
	{
		if (ai >= n)
		{
			k -= b[bi] ;
			rdb += b[bi++] ;
		}
		else if (bi >= m)
		{
			k -= a[ai] ;
			rda += a[ai++] ;
		}
		else
		{
			int ans1 = upper_bound(sa, sa + n, k + rda) - sa - ai ;
			int ans2 = upper_bound(sb, sb + m, k + rdb) - sb - bi ;
//			cout << ans1 << " " << ans2 << endl ;
			if (ans1 > ans2)
			{
				k -= a[ai] ;
				rda += a[ai++] ;
			}
			else if (ans1 < ans2)
			{
				k -= b[bi] ;
				rdb += b[bi++] ;
			}
			else
			{
				if (a[ai] < b[bi])
				{
					k -= a[ai] ;
					rda += a[ai++] ;
				}
				else
				{
					k -= b[bi] ;
					rdb += b[bi++] ;
				}
			}
			
		}
		
//		cout << k << endl ;
	}
	
	cout << ai + bi << endl ;

	return 0 ;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
#define MAX 2100000
using ll = long long;


int main(){
  ll N; cin>>N;
  vector<ll> A(N),S(N);//S.at(i)はA.at(i)までの和
  rep(i,N){
    cin>>A.at(i);
    if(i==0)S.at(i)=A.at(i);
    else S.at(i)=S.at(i-1)+A.at(i);
  }
  map<ll,int> m;
  rep(i,N){
    if(m.count(S.at(i)))m[S.at(i)]++;
    else m[S.at(i)]=1;
  }
  ll res = 0;
  for(auto p:m){
    ll s = p.first;
    ll num = p.second;
    if(s==0)num++;
    if(num<2)continue;
    res += num*(num-1)/2;
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 15872
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
map<string,int> a;
int main()
{
	int n;
	string s;
	cin>>n;
	cin>>s;
	a[s]=1;
	char las=s[s.length()-1];
	for(int i=2;i<=n;i++)
	{
		cin>>s;
		if(a[s]==1||s[0]!=las)
		{
			cout<<"No";
			return 0;
		}
		las=s[s.length()-1];
		a[s]=1;
	}
	cout<<"Yes";
	return 0;
	
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
typedef pair<int ,P> PP;
typedef pair<int, PP> PPP;
struct edge { int to; int to2; int cost; };

signed main() {
	int n, k; cin >> n >> k;
	string s; cin >> s;
	vector<PP>V;
	int ans = 0;
	int st = 0, ed = -1;
	char now = s[0];
	s.push_back('2');
	if (now == '0')V.push_back(PP(1, P(0, 0)));
	rep(i, s.size()) {
		if (s[i] == now)ed++;
		else {
			V.push_back(PP(now - '0', P(st, ed)));
			st = i; ed = i;
			now = s[i];
		}
	}
	if (s[n - 1] == '0')V.push_back(PP(1, P(n - 1, n - 1)));
	

	if (V.size()<=2*k+1)cout << n << endl;
	else {
		int l = 0, r = 2*k;
		while (r < V.size()) {
			ans = max(ans, V[r].second.second - V[l].second.first + 1);
			l += 2; r += 2;
		}

		cout << ans << endl;
	}

}	


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

int c;
int n;

void calc(int p, int sum) {

    if (p == 0) {
        if ( sum == n )
            ++c;
        return;
    }

    int i;
    for ( i = 0; i < 10; ++i ) {
        calc(p - 1, sum + i );
    }
}

int main () {

    while ( scanf("%d", &n) != EOF ) {
        c = 0;
        calc(4, 0);
        printf("%d\n", c);
    }

    return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

int main(void){
  int n , k;
  scanf("%d %d",&n,&k);
  
  int d , a;
  int count[101] = {0} , ans = 0;
  
  for(int i = 0;i < k;i ++){
    scanf("%d",&d);
    for(int j = 0;j < d;j ++){
      scanf("%d",&a);
      count[a] ++;
    }
  }
  for(int i = 1;i <=n;i ++){
    if(count[i]==0){
      ans ++;
    }
  }
printf("%d",ans);
  
  return 0;
}


  
  

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF=1<<30;
#define vecvec(a,y,x) vector<vector<int>> a(y,vector<int>(x))
#define vec(a,n) vector<int> a(n);rep(i,n)cin>>a[i]

int main(){
int x;cin>>x;
  cout<<x*x*x;
}

Measured memory_bytes: 256
# from pprint import pprint
# import math
# import collections

# n = int(input())
R, G, B, N = map(int, input().split(' '))
# a = list(map(int, input().split(' ')))

# max_r, max_g, max_b = N // R, N // G, N // B
ans = []

r, g, b = 0, 0, 0
cnt = 0

max_r = N // R
for r in range(max_r + 1):
    if R * r > N:
        break

    max_g = (N - R * r) // G

    for g in range(max_g + 1):
        if R * r + G * g > N:
            break
        x = (N - (R * r + G * g))
        if x % B == 0 and x >= 0:
            # b = x // B
            # a = (r, g, b)
            cnt += 1
            # ans.append(a)

# print(len(ans))
print(cnt)


Measured memory_bytes: 9072