akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(ll i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define j1 j1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  int Q; cin>>Q;

  ll sumb=0;
  ll fx=0;
  ll ct1=0;
  priority_queue<ll> st1; //xが小さい方、大きい方から出る
  priority_queue<ll,vector<ll>, greater<ll>> st2; //xが大きい方、小さい方から出る
  ll center;
  ll center1=INF;
  ll center2=INF;
  rep(i,Q){
    int qu; cin>>qu;
    if(qu==1){
      ll a,b; cin>>a>>b;
      sumb+=b;

      if(ct1==0){
        center=a;
        ct1++;
        continue;
      }
      if(ct1%2==0){
        if(a<center1){
          fx+=center1-a;
          center=center1;
          st1.push(a);
          st2.push(center2);
        }
        else if(a>center2){
          fx+=a-center2;
          center=center2;
          st1.push(center1);
          st2.push(a);
        }
        else{
          center=a;
          st1.push(center1);
          st2.push(center2);
        }
      }
      if(ct1%2==1){
        fx+= abs(center-a);
        if(a>=center){
          st2.push(a);
          center1=center;
          center2=st2.top();
          st2.pop();
        }
        else{
          st1.push(a);
          center2=center;
          center1=st1.top();
          st1.pop();
        }
      }
      ct1++;
    }
    else{
      if(ct1%2==0){
        cout<< center1<<" "<< fx+sumb <<"\n";
      }
      else{
        cout<< center<<" "<< fx+sumb <<"\n";
      }
    }
  }

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


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

int main() {
  string s;
  cin >> s;
  string ans=s;
  if(s.size()==26) {
    if(!next_permutation(ans.begin(),ans.end())) {
      cout << -1 << endl;
      return 0;
    }
    else {
      ll flag=0;
      for(ll i=0;i<s.size();i++) {
        if(s[i]!=ans[i]) {
          flag=i;
          break;
        }
      }
      ans=ans.substr(0,flag+1);
    }
  }
  else {
    set<char> check;
    for(ll i=0;i<s.size();i++) {
      check.insert(s[i]);
    }
    for(ll i=0;i<26;i++) {
      if(!check.count(char('a'+i))) {
        ans=s+char('a'+i);
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    vec x(n);
    rep(i, n) cin >> x[i];

    vector<P> y(n);
    rep(i, n) y[i] = make_pair(x[i], i);

    sort(all(y));

    vec res(n);

    rep(i, n) {
        res[y[i].second] = (i < n/2 ? y[n/2].first : y[n/2-1].first);
    }

    rep(i, n) cout << res[i] << endl;
    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

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

    ll n;
    cin >> n;
    ll a[n];
    for(int i=0;i<n;i++)cin >> a[i];

    bool maki = true;
    for(int i=n-2;i>=0;i--){
    	if(a[i] > a[i+1]){
    		a[i]--;
    		if(a[i] > a[i+1]) maki = false;
    	}
    }
    if(maki) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 4396
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll n; ll x; ll t;
  cin>>n>>x>>t;
  ll ans=n/x;
  if(n%x!=0)
    ans+=1;
  cout<<ans*t;
  return 0;
}
  


Measured memory_bytes: 3608
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <stack>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <iterator>
#include <sstream>
#define popcount(x) __builtin_popcount(x)
#define oddparity(x) __builtin_parity(x)
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
#define sf scanf
#define pf printf
using namespace std;

int i, n, k, ans;
vector<int>up, down;

int main()
{
    sf("%d%d", &n, &k);
    for (i = 1; i <= n; i++) {
        if (i == 1) {
            ans += k;
        }
        else {
            ans *= (k-1);
        }
    }
    pf("%d\n", ans);
    return 0;
}

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

int main(void){
	int x[3];
	cin >> x[1];
	string n = "NO", y = "YES";
	while(cin >> x[0] >> x[1] >> x[2]){
		sort(x,x + 3);
		if(x[2] * x[2] == x[1] * x[1] + x[0] * x[0])
			cout << y << endl;
		else
			cout << n << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n  = Integer.parseInt(in.nextLine());
		int mealPrice = 800;
		int discount = 200;
		int discountPoint = 15;
		
		int x = n * mealPrice;
		int y = (n / discountPoint) * discount;
		System.out.println(x - y);
	}

}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define INF 1000000000
#define INFLL 1000000000000000010ll
#define UQ(x) (x).resize(distance((x).begin(),unique(all((x)))))
#define mid(x,y) (((x)+(y))>>1)
int n;
ll s[100005],p[100005];
bool can(int i) {
	ll cur=p[i];
	for (int j=i+1;j<n;j++) {
		if (s[j]>2ll*cur) return 0;
		cur+=s[j];
	}
	return 1;
}
int main() {
	scanf("%d",&n);
	int x,y;
	for (int i=0;i<n;i++) {
		scanf("%lld",&s[i]);
	}
	sort(s,s+n);
	p[0]=s[0];
	for (int i=1;i<n;i++) p[i]=p[i-1]+s[i];
	int b=0,e=n-1,ans=n;
	while(b<e+1) {
		int m=(b+e)/2;
		if (can(m)) {
			ans=min(ans,m);
			e=m-1;
		} else b=m+1;
	}
	printf("%d\n", n-ans);
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
vector<int>dp;
vector<vector<int> > chi,par;
int find(int i){
    int len = 0 ;
    if(dp[i]!=-1)return dp[i];
    for(auto x:chi[i]){
        len=max(len,find(x)+1);
    }
    dp[i]=len;
    return dp[i];
}
int main(){
    int n, m ;
    cin>>n>>m;
    chi.resize(n+1);
    par.resize(n+1);
    dp.resize(n+1,-1);
    for(int i = 0 ; i < m ; i ++ ) {
        int a, b;
        cin>>a>>b;
        chi[a].push_back(b);
        par[b].push_back(a);
    }int ans=0;
    for(int i = 1 ; i <= n ; i++ ){
            dp[i]=find(i);
            ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 16600
def mul(x,y):
    q=[[0]*n for i in xrange(n)]
    for i in xrange(n):
        for j in xrange(n):
            for k in xrange(n):
                q[i][j]+=x[i][k]*y[k][j]
    for i in xrange(n):
        for j in xrange(n):
            x[i][j]=q[i][j]%mod
n,k=map(int,raw_input().split())
a=[map(int,raw_input().split()) for _ in xrange(n)]
mod=pow(10,9)+7
z=[[int(i==j) for j in xrange(n)] for i in xrange(n)]
while k:
    if k%2:
        mul(z,a)
    mul(a,a)
    k/=2
print sum(sum(i) for i in z)%mod

Measured memory_bytes: 124960
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    bool fla = true;
    int ss = s.size();

    for(int i = 0;i < ss;i += 2){
        if(s.at(i) != s.at(i+1)){
            fla = false;
            break;
        }
        else if(i == 2 and s.at(i) == s.at(i-2)){
            fla = false;
            break;
        }
    }

    if(fla)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

int main()
{
  int N;
  string S;
  cin >> N >> S;
  int cnt = 0;
  for (int i = 0; i < N - 2; ++i)
    if (S.substr(i, 3) == "ABC")
      ++cnt;
  cout << cnt;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int x=0;
	int c=0;
	int i=0;
	
	while(i == 0){
	scanf("%d",&x);
		
		if(x == 0){
			break;
		}
		
		c++;
		printf("Case %d: %d\n",c,x);
	}
	return 0;
}

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

int a[4], b[4];

void solve(void)
{
    int hit = 0;
    for (int i = 0; i < 4; i++) {
        if (a[i] == b[i]) {
            a[i] = 0;
            hit++;
        }
    }

    int blow = 0;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            if (a[i] == b[j]) {
                a[i] = 0;
                blow++;
            }
        }
    }

    cout << hit << ' ' << blow << endl;
}

int main()
{
    while (cin >> a[0] >> a[1] >> a[2] >> a[3]
               >> b[0] >> b[1] >> b[2] >> b[3]) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
#define INF 1e9

static const int seed=6;
static const int D=365;
static const int ntype=26;
static int ans[D+1];
static int max_score=0;
static int t=3e5;

class Contest{
public:
    Contest(){
        last=0;
    }
    int s[D+1];
    int c;
    int last;
};

static Contest contest[ntype+1];

void Input(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int d;
    cin>>d;
    for(int i=1;i<=ntype;++i){
        int t;
        cin>>t;
        contest[i].c=t;
    }
    for(int day=1;day<=D;++day){
        for(int type=1;type<=ntype;++type){
            int t;
            cin>>t;
            contest[type].s[day]=t;
        }
    }
}

int Score(int type){
    int sum=0;
    contest[type].last=0;
    for(int day=1;day<=D;++day){
        if(ans[day]==type){
            sum+=contest[type].s[day];
            int n=day-contest[type].last;
            sum-=contest[type].c*(n*(n-1)/2);
            contest[type].last=day;
        }
    }
    if(ans[D]!=type){
        int n=D-contest[type].last;
        sum-=contest[type].c*(n*(n+1)/2);
    }
    return sum;   
}

void Output(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    for(int d=1;d<=D;++d) cout<<ans[d]<<'\n';
}

void Init(){
    for(int d=1;d<=D;++d) ans[d]=rand()%ntype+1;
}

void Greedy(){
    vector<int> l(ntype+1,0);
    int score=0;
    for(int d=1;d<=D;++d){
        for(int i=1;i<=ntype;++i) score-=contest[i].c*(d-l[i]);
        int temp=score;
        int t=-1;
        for(int i=1;i<=ntype;++i){
            int k=contest[i].s[d]+contest[i].c*(d-l[i])+score;
            if(k>temp){
                temp=k;
                t=i;
            }
        }
        ans[d]=t;
        l[t]=d;
    }
}

void change(){
    int p=rand()%D+1;
    int before=ans[p];
    int after=rand()%ntype+1;
    int before_score=Score(before)+Score(after);
    ans[p]=after;
    //cout<<"p: "<<p<<" from: "<<temp<<" to: "<<ans[p]<<endl;
    int delta=Score(before)+Score(after)-before_score;
    if(delta>0){ 
        max_score+=delta;
    }
    else ans[p]=before;
}

void swap(){
    int p1=rand()%D+1;
    int p2=rand()%D+1;
    while(p1==p2) p2=rand()%D+1;
    int temp_score=Score(ans[p1])+Score(ans[p2]);
    int temp=ans[p1];
    ans[p1]=ans[p2];
    ans[p2]=temp;
    int delta=Score(ans[p2])+Score(ans[p1])-temp_score;
    if(delta>0){
        max_score+=delta;
    }
    else{
        ans[p2]=ans[p1];
        ans[p1]=temp;
    }
}

void Solve(int times){
    Greedy();
    for(int i=1;i<=ntype;++i) max_score+=Score(i);
    //cout<<max_score<<endl;
    for(int i=0;i<times;++i){
        swap();
        change();
    }
}

int main(){
    srand(seed);
    Input();
    Solve(t);
    Output();
}


Measured memory_bytes: 3568
//Heaplax
//别让自己后悔
#include<bits/stdc++.h>
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
int A,B,C;
int main()
{
	re(A),re(B),re(C);
	printf("%d\n",B+min(A+B+1,C));
}


Measured memory_bytes: 256
using System;
using System.Text;

namespace _088_TheCodeADoctorLoved
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;
			StringBuilder output = new StringBuilder (100 * 200);

			while ((inputStr = Console.ReadLine ()) != null)
			{
				StringBuilder data = new StringBuilder (inputStr.Length * 8);

				//encode
				foreach (var item in inputStr)
				{
					data.Append (EncodeData (item));
				}

				//padding zero
				if (data.Length % 5 != 0)
				{
					int zeroCount = 5 - data.Length % 5;
					data.Append ('0', zeroCount);
				}

				//decode
				for (int lp = 0; lp < data.Length; lp += 5)
				{
					output.Append (DecodeData (data.ToString (lp, 5)));
				}
				output.AppendLine ();
			}

			Console.Write (output);
		}

		static string EncodeData ( char ch )
		{
			switch (ch)
			{
				case ' ': return "101";
				case '\'': return "000000";
				case ',': return "000011";
				case '-': return "10010001";
				case '.': return "010001";
				case '?': return "000001";

				case 'A': return "100101";
				case 'B': return "10011010";
				case 'C': return "0101";
				case 'D': return "0001";
				case 'E': return "110";
				case 'F': return "01001";
				case 'G': return "10011011";
				case 'H': return "010000";
				case 'I': return "0111";
				case 'J': return "10011000";
				case 'K': return "0110";
				case 'L': return "00100";
				case 'M': return "10011001";
				case 'N': return "10011110";
				case 'O': return "00101";
				case 'P': return "111";
				case 'Q': return "10011111";
				case 'R': return "1000";
				case 'S': return "00110";
				case 'T': return "00111";
				case 'U': return "10011100";
				case 'V': return "10011101";
				case 'W': return "000010";
				case 'X': return "10010010";
				case 'Y': return "10010011";
				case 'Z': return "10010000";
			}
			return null;
		}

		static char DecodeData ( string str )
		{
			switch (str)
			{
				case "00000": return 'A';
				case "00001": return 'B';
				case "00010": return 'C';
				case "00011": return 'D';
				case "00100": return 'E';
				case "00101": return 'F';
				case "00110": return 'G';
				case "00111": return 'H';
				case "01000": return 'I';
				case "01001": return 'J';
				case "01010": return 'K';
				case "01011": return 'L';
				case "01100": return 'M';
				case "01101": return 'N';
				case "01110": return 'O';
				case "01111": return 'P';
				case "10000": return 'Q';
				case "10001": return 'R';
				case "10010": return 'S';
				case "10011": return 'T';
				case "10100": return 'U';
				case "10101": return 'V';
				case "10110": return 'W';
				case "10111": return 'X';
				case "11000": return 'Y';
				case "11001": return 'Z';
				case "11010": return ' ';
				case "11011": return '.';
				case "11100": return ',';
				case "11101": return '-';
				case "11110": return '\'';
				case "11111": return '?';
			}
			return '0';
		}
	}
}

Measured memory_bytes: 9072
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <bitset>
#include <time.h>
#include <set>
#include <algorithm>
#define ll long long
#define Inf 123372036854775806ll
using namespace std;

vector<int> edges[10];
int dfs(int u,int mask,int N) {
    mask |= (1<<(u-1));
    if (mask == (1<<N)-1) {
        return 1;
    }
    int ans=0;
    for(int i=0;i<edges[u].size();i++) {
        int v=edges[u][i];
        if ((mask>>(v-1))&1)
            continue;
        ans+=dfs(v,mask,N);
    }
    return ans;
    
}

int main() {
    int N,M;
    cin>>N>>M;
    for(int i=1;i<=M;i++) {
        int a,b;
        cin>>a>>b;
        
        edges[a].push_back(b);
        edges[b].push_back(a);
        
    }
    
    cout << dfs(1,0,N) << endl;
    
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {

	int A, B, T;

	cin >> A >> B >> T;

	int ans = 0;
	int tmp = 0;
	for (int i = 1;; i++) {
		tmp += A;
		if (1.0*(T + 0.5) < tmp) { break; }
		ans += B;
	}

	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))

int main()
{
    string s;
    cin>>s;
    ll n;
    sll(n);
    ll sum=0;
    ll tou=1,wei=1;
    int touend=-1,weiend=-1;
    ll len=s.length();
    for(int i=1; i<s.length(); i++)
    {
        if(s[i]==s[i-1])
            tou++;
        else
        {
            touend=i;
            break;
        }
    }
    for(int i=s.length()-2; i>=0; i--)
    {
        if(s[i]==s[i+1])
            wei++;
        else
        {
            weiend=i;
            break;
        }
    }
    //cout<<touend<<" "<<weiend<<endl;
    //cout<<s[touend]<<" "<<s[weiend]<<endl;
    if(tou==wei&&tou==len)
        printf("%lld\n",len*n/2);
    else
    {
        ll sum1=0;
          for(int i=1; i<s.length(); i++)
            if(s[i-1]==s[i])
            {
                sum++;
                i++;
            }
        if(n>1)
        {
            s+=s;
            for(int i=1; i<s.length(); i++)
            {
                if(s[i-1]==s[i])
                {
                    sum1++;
                    i++;
                }
            }
            sum1=sum1-sum;
            sum=sum+sum1*(n-1);
        }
        printf("%lld",sum);

    }
    return 0;
}


Measured memory_bytes: 256
#147_D
n = int(input())
A = list(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7

for i in range(60):
    s = sum([(a >> i) & 1 for a in A])
    ans = (ans + s * (n-s) * pow(2,i,mod)) % mod
print(ans)

Measured memory_bytes: 138168
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i<N; i++)
#define RVROOP(i, N) for(int i=N; i>=0; i--)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  int P, Q, R; cin>>P>>Q>>R;
  cout<<min(min(P+Q,Q+R),R+P)<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define DEBUG(x) cerr << #x << ": " << x << "\n"

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    string S, T;
    cin >> S >> T;
    int N = S.size();
    int s[26], g[26];
    memset(s, -1, sizeof(s));
    memset(g, -1, sizeof(g));
    REP(i, N) {
        int c1 = S[i] - 'a';
        int c2 = T[i] - 'a';

        if (s[c1] != -1 || g[c2] != -1) {
            if (s[c1] != c2 || g[c2] != c1) {
                cout << "No" << endl;
                return 0;
            }
        }
        s[c1] = c2;
        g[c2] = c1;
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 776
($a,$b,$c,$x)=<>;
for($i=0;$i<=int($x/500);$i++){
	for($j=0;$j<=int(($x-500*$i)/100);$j++){
		$k=$x-500*$i-100*$j;
		$r+=$k%50==0&&$c>=int($k/50)&&$a>=$i&&$b>=$j
	}
}
print$r

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, a, b;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> a >> b;
    cout << min(n*a, b) << "\n";
    //system("pause");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define repf(i, n) for(int i=1; i<(int)(n+1); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    string s;
    int ans;
    cin >> s;
    if(s == "SUN") ans = 7;
    else if(s == "MON") ans = 6;
    else if(s == "TUE") ans = 5;
    else if(s == "WED") ans = 4;
    else if(s == "THU") ans = 3;
    else if(s == "FRI") ans = 2;
    else if(s == "SAT") ans = 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define dfor(i,a,b) for(int i=(a);i>=(b);i--)
#define ll long long
#define ull unsigned long long

int main() {
	
	string s,t;
	int n=0;
	cin>>s>>t;
	rep(i,3){
		if(s[i]==t[i]) n++;
	}

	cout<<n;
	
}

Measured memory_bytes: 256
//go:generate echo "https://atcoder.jp/contests/dp/tasks/dp_c"
package main

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

type scanner struct{ *bufio.Scanner }

func newScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 100000000)
	return &scanner{s}
}

func (s *scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *scanner) IntSlice(l int) []int {
	if l == 0 {
		return []int{}
	}
	sl := make([]int, l, l)
	for i := range sl {
		sl[i] = s.Int()
	}
	return sl
}

func (s *scanner) IntSlice2(l, n int) []int {
	if l == 0 {
		return []int{}
	}
	sl := make([]int, l, l)
	for i := 0; i < n; i++ {
		sl[i] = s.Int()
	}
	return sl
}

func solve(n int, u [][]int) int {
	t := make([][]int, n+1, n+1)
	for i := range t {
		t[i] = make([]int, 3, 3)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < 3; j++ {
			for k := 0; k < 3; k++ {
				if j == k {
					continue
				}
				if v := t[i][j] + u[i][k]; t[i+1][k] < v {
					t[i+1][k] = v
				}
			}
		}
	}
	max := math.MinInt64
	for _, v := range t[n] {
		if max < v {
			max = v
		}
	}
	return max
}

func main() {
	scan := newScanner(os.Stdin)
	n := scan.Int()
	u := make([][]int, n+1, n+1)
	for i := 0; i <= n; i++ {
		u[i] = []int{scan.Int(), scan.Int(), scan.Int()}
	}
	fmt.Println(solve(n, u))
}


Measured memory_bytes: 13700
n,m=map(int,input().split())
v=[]
for i in range(n):
  p=list(map(int,input().split()))
  v.append(p)
v.sort()
sum=0
num=0
for i in range(n):
  if m>num+v[i][1]:
    num+=v[i][1]
    sum+=v[i][0]*v[i][1]
  else:
    sum+=v[i][0]*(m-num)
    break
print(sum)

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

#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;
typedef long double ld;
using namespace std;
#define endl "\n"
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
const int N=100+5, mxN=(1<<22);
int mod=1e9+7;
 int ans[N][N];
 int arr[N*N];

int main()
{
    FIO
    int row,col;
    cin>>row>>col;
    int n;
    cin>>n;
    int x=0,y=0;
    for(int i=0;i<n;i++)
    {
        int t;
        cin>>t;
        while(t--)
        {
            ans[x][y]=i;
            if(x%2==0)
            {
                if(y<col-1)
                {
                    y++;
                }
                else x++;

            }
            else
            {
                if(y>0)
                    y--;
                else
                    x++;

            }

        }

    }
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            cout<<ans[i][j]+1<< " ";
        }
        cout<<endl;


    }

    return 0;

}






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

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> H(n);
  for(int i = 0; i < n; i++){
  H[i] = true;
  }
  int count = 0;
  for(int i = 0; i < n; i++){
    cin >> h[i];
  }
  pair<int,int> p[m-1];
  for(int i = 0; i < m; i++){
    cin >> p[i].first >> p[i].second;
  }
  
  for(int i = 0; i < m; i++){
    if(h[p[i].first-1]>h[p[i].second-1]){
      H[p[i].second-1] = false;
    }
    else if(h[p[i].first-1]<h[p[i].second-1]){
      H[p[i].first-1] = false;
    }
    else{
      H[p[i].second-1] = false;
    H[p[i].first-1] = false;
    }
  }
  for(int i = 0; i < n; i++){
    if(H[i]){
      count++;
    }
  }
cout << count << endl;
}
 

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    string s; cin >> s;
    if(s == "ABC")
        cout << "ARC" << endl;
    else
        cout << "ABC" << endl;
    return 0;
}


Measured memory_bytes: 3596
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define mem0(a)       memset((a),0,sizeof((a)))

const int INF = 1e9;

using ull = unsigned long long;
using ll = long long;

// code
// ------------------------------------------------
int main() {

  int n;
  cin >> n;

  int a[2][n];
  int b[3][n];

  memset(a,0,sizeof(a));
  memset(b,0,sizeof(b));

  rep(i,2) rep(j,n) cin >> a[i][j];

  rep(i,n)
  {
    if(i == 0)
    {
      b[0][i] = a[0][i];
    }
    else
    {
      b[0][i] = a[0][i] + b[0][i - 1];  
    }
  } 

  b[1][0] = a[1][0] + a[0][0];

  for(int i = 1;i < n;i++)
  {
    b[1][i] = max(b[1][i-1], b[0][i]) + a[1][i];
  }

  cout << b[1][n - 1] << endl;


  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}

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

using namespace std;

int main()
{
  int H, W; cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; ++i) {
    cin >> S[i];
  }

  vector<vector<int>> ans(H, vector<int>(W, 0));
  for (int h_i = 0; h_i < H; ++h_i) {
    for (int w_i = 0; w_i < W; ++w_i) {
      if (S[h_i][w_i] == '#') {
        if (h_i-1 >= 0 and w_i-1 >= 0) ans[h_i-1][w_i-1]++;
        if (h_i-1 >= 0) ans[h_i-1][w_i]++;
        if (h_i-1 >= 0 and w_i+1 < W) ans[h_i-1][w_i+1]++;
        if (w_i-1 >= 0) ans[h_i][w_i-1]++;
        if (w_i+1 < W) ans[h_i][w_i+1]++;
        if (h_i+1 < H and w_i-1 >= 0) ans[h_i+1][w_i-1]++;
        if (h_i+1 < H) ans[h_i+1][w_i]++;
        if (h_i+1 < H and w_i+1 < W)ans[h_i+1][w_i+1]++;
      }
    }
  }

  for (int h_i = 0; h_i < H; ++h_i) {
    for (int w_i = 0; w_i < W; ++w_i) {
      if (S[h_i][w_i] == '#') {
        cout << "#";
      } else {
        cout << ans[h_i][w_i];
      }
    }
    cout << endl;
  }
}

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

void solve() {
	string s; cin >> s;
	while (s.size()) {
		s.pop_back(); s.pop_back();
		int n = s.size()/2;
		bool f = true;
		for (int i = 0; f && i < n; ++i) {
			if (s[i] != s[i+n]) f = false;
		}
		if (f) {
			cout << s.size();
			return;
		}
	}
	cout << 0;
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int K[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};
int main() {
	int k;
	scanf("%d", &k);
	printf("%d\n", K[k - 1]);
}


Measured memory_bytes: 256
$n = gets.to_i

def test(s)
	return 0 if s.to_i > $n
	cnt = %w(7 5 3).all?{|w| s.count(w) > 0} ? 1 : 0
	%w(7 5 3).each{|w| cnt += test(s + w)}
	cnt
end

puts test("")


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

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

int main(){
	string s;
	cin >> s;
	int n = s.size();
	
	vector<int> ans(n, 0);
	
	int count = 0;
	for(int i = 0; i < n; ++i){
		if(s[i] == 'R'){
			count++;
		}
		else{
			if(i == 0) continue;
			ans[i - 1] += (count + 1) / 2;
			ans[i] += count / 2;
			count = 0;
		}
	}
	
	reverse(s.begin(), s.end());
	reverse(ans.begin(), ans.end());
	
	count = 0;
	for(int i = 0; i < n; ++i){
		if(s[i] == 'L'){
			count++;
		}
		else{
			if(i == 0) continue;
			ans[i - 1] += (count + 1) / 2;
			ans[i] += count / 2;
			count = 0;
		}
	}
	
	reverse(ans.begin(), ans.end());
	
	for(int i = 0; i < n; ++i){
		cout << ans[i] << " ";
	}
	cout << endl;
	
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;cin >> n >> k;
	ll ans=0;
	for(int i=k+1;i<=n;++i){
		ll p=n/i,r=n%i;
		ans+=p*(i-k)+max((ll)0,r+1-k);
	}
	if(k==0) ans-=n;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
    int N,time=0;
    bool f=true;
    cin >>N;
    vector<pair<int,int>> task;
    for(int i=0;i<N;i++){
        int a,b;
        cin>>a>>b;
        task.emplace_back(b,a);
    }
    sort(task.begin(),task.end());
    for(int i=0;i<N;i++){
      	time+=task[i].second;
        if(time>task[i].first){
            f=false;
            break;
        }
    }
    if(f) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 5348
n,m=map(int,input().split())
ans=1
for i in range(1,int(m**0.5)+1):
  if m%i==0:
    y=m//i
    if m//i>=n and ans<i:
      ans=i
    if m//y>=n and ans<y:
      ans=y
print(ans)

Measured memory_bytes: 3064
//kruskal tree
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
#define M 9999
int parent[M],a[M],b[M];
pair<double,int>node[M];
int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);}
int unite(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	parent[x]=y;
	return 1;
}
int main(){
	int i,j,k,m,n;
	double x,y,z,r;
	for(;cin>>n,n;){
		vector<vector<double> >v;
		for(i=0;i<n;i++)cin>>x>>y>>z>>r,v.push_back({x,y,z,r});
		for(i=0;i<n;i++)parent[i]=i;
		for(m=i=0;i<n;i++)for(j=i+1;j<n;j++){
			for(x=k=0;k<3;k++)x+=(v[i][k]-v[j][k])*(v[i][k]-v[j][k]);
			x=sqrt(x)-v[i][3]-v[j][3];
			if(x<=0)unite(i,j);
			else a[m]=i,b[m]=j,node[m].first=x,node[m++].second=m;
		}
		sort(node,node+m);
		for(x=i=0;i<m;i++)if(unite(a[node[i].second],b[node[i].second]))x+=node[i].first;
		printf("%.3f\n",x);
	}
}

Measured memory_bytes: 1452
#include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define PB push_back

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;

void solve(){
	map<string, int> ms;
	int n; cin >> n;
	int big = 0;
	for(int i = 0; i < n; i++){
		string ent; cin >> ent;
		ms[ent]++;
		if(ms[ent] > big) big = ms[ent];
	}
	
	for(auto it = ms.begin(); it != ms.end(); it++){
		if(it->S == big)
			cout << it->F << endl;
	}
}

int main(){
	/*
	int t;
	cin >> t;
	while(t--)
		solve();
	*/
	
	solve();
	
	return 0;
}


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

using namespace std;
int v[200001];
int main(){
    int n,m;
    int a,b;
    bool ispos=false;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin >>a>>b;
        if(a==1){
            v[b]++;
            if(v[b]==2){ispos=true;break;}
        }
        if(b==n){
            v[a]++;
            if(v[a]==2){ispos=true;break;}
        }
    }
    if(ispos)cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

map<string,ll> mp;

int main(){
	int n; cin >> n;
	vs s(n); rep(i,n) cin >> s[i];
	priority_queue<pair<ll,string>> pq;
	auto push = [&](string s, ll c){
		if(mp.find(s) != mp.end()){
			if(mp[s] > c){
				mp[s] = c;
				pq.emplace(c,s);
			}
		}else{
			mp[s] = c;
			pq.emplace(c,s);
		}
	};
	rep(i,n){
		pq.emplace(0,s[i]);
	}
	while(!pq.empty()){
		auto p = pq.top(); pq.pop();
		rep(i,n){
			if(p.first == 0 && s[i] == p.second) continue;
			int si = s[i].size(), sp = p.second.size();
			if(si < sp){
				string t = p.second.substr(0,si);
				if(t == s[i]){
					push(p.second.substr(si,sp-si), si+p.first);
				}
			}else{
				string t = s[i].substr(0,sp);
				if(t == p.second){
					push(s[i].substr(sp,si-sp), sp+p.first);
				}
			}
		}
	}
	cout << mp[""] << endl;
}


Measured memory_bytes: 3476
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const long long MOD = 1e9 + 7;

int main() {
    string S, T;
    cin >> S >> T;
    int N = S.size(), c = 0;
    rep(i, N) if(S[i] != T[i]) c++;
    cout << c << endl;
}

Measured memory_bytes: 3904
#include<bits/stdc++.h>
int m,c;
long long n;
int main()
{
    scanf("%lld",&n);
    while(n>>m)++m;--m;
    c=__builtin_popcountll(n)-1;
    printf("%d\n",m+c+1<<1),n^=1ll<<m;
    for(int i=1,j=1,k=m+c;j<=m||k>m;++i)
        printf("%d ",n>>j-1&1?n^=1ll<<j-1,k--:j++);
    for(int i=1;i<=m+c;++i)printf("%d ",i);
    printf("100 100\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define eoi ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int main()
{
    eoi;
    int x,m;
    vector<int>v;
    cin>>x;
    while(x--){
        cin>>m;
        v.push_back(m);
    }
    int sum=0,s=100000000,n;
    for(int i=-100;i<=100;i++){
            sum=0;
        for(int z=0;z<v.size();z++){
            sum+=((i-v[z])*(i-v[z]));
        }
        if(sum<s){
            s=sum;
        }
    }
    cout<<s;

}







Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define Mp make_pair
#define pb push_back
#define rep(i, j, k) for (int i = (j); i <= (k); i++)
#define per(i, j, k) for (int i = (j); i >= (k); i--)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int N = 3e5+3;
int n,a[N];
ll sum[2],ans,s[N];

bool chk(int x){
    ll v=0;
    rep(i,1,n) if(s[i]-v>=x) v=min(v,s[i+1]);
    return s[n]-v>=x;
}
int main(){
    scanf("%d",&n);
    rep(i,1,n) scanf("%d",&a[i]);
    rep(i,1,n) sum[i&1]+=a[i];
    if(n%2==0){
        printf("%lld %lld\n",max(sum[0],sum[1]),min(sum[0],sum[1]));
        return 0;
    }
    rep(i,1,n) s[i]=s[i-1]+a[i]*((i&1)?1:-1);
    ll l=1,r=n*1000,mid;
    while(l<r){
        mid=(1+l+r)>>1;
        if(chk(mid)) l=mid;
        else r=mid-1;
    }
    for(int i = 2; i <= n; i+=2) l+=a[i];
    printf("%lld %lld\n",l,sum[0]+sum[1]-l);
    return 0;
}
/*
不妨设先手是 A，后手是 B。定义 i 为奇数时，ai 为"奇数位上的数"；i 为偶数时， ai 为"偶数位上的数"。定义左、右两端的数分别表示 a1 和 an。

考虑第一步：

首先，如果 A 取了左右某一个端点，那么他必然能取走和他取的点奇偶性相同的所有点。

然后，我们考虑 A 取了一个中间点后会发生什么：如果这个点左边和右边的剩余点数都是奇数，那么无论 B 取左还是右，取完某一边之后，问题规模缩小成另一边的情况，A 一定还是先手；否则 B 就可以取剩余点数为偶数的那一边，并成为先手。

考虑 n 为偶数的情况。

如果 A 取了一个中间点，那么一定有一边剩余奇数个，一边剩余偶数个。那么 B 一定先操作偶数个的那一边，然后获得奇数那一边的先手权，然后取最优策略。那么 A 还不如直接取偶数那一边的端点，这样做不仅取到了前一种方案能取到的，而且让 B 在另一边没有了先手选择权，一定不劣于前一种方案。

所以，当 n 为偶数时，先手能取到的最大值为 max(奇数位之和, 偶数位之和) 。

n 为奇数的情况较为复杂。

但是同理，A 不会去取一个位于奇数位的数，这样会导致两边剩余个数都为偶数，不如直接取两端。

于是，n 为奇数时，A 只有两种策略：

取端点，即拿走所有奇数位的数。
取某一个偶数位的数。此时，如果 B 取左边，那么 A 会继续获得右边的先手权；否则 A 获得左边的先手权。这个过程可以看作问题规模的缩小。
如果将第二种策略用二叉树的形式表示出来，那么 B 一定会选择某一个叶子，使得最终答案最小。

考虑先假设所有偶数位的贡献都已被 A 收取，那么 A 在一个区间执行“取端点”操作得到的收益就是这个区间的奇数位之和减去偶数位之和（注意这里的两端点一定都是奇数）。

我们要做的是找出一个叶子集合，使得对这些叶子“取端点”的收益的最小值尽量大。

考虑二分答案x，之后问题转化为是否可以删除某些偶数位上的数，使得剩下的序列中任意一个极大的连续段之和(奇数位之和减偶数位之和)都不小于x。

考虑暴力DP，枚举右端点，然后再暴力枚举前一个划分点。时间复杂度不可接受。

由于DP信息只有“能”和“不能”，所以我们可以考虑贪心，只保留“能”的点中前缀和最小的即可。

时间复杂度 O(nlog∑ai)。
*/

Measured memory_bytes: 3712
n, m= gets.chomp.split.map(&:to_i)
dif = n-m
ans = 0
me = 1000000007
if dif < 0
	dif = dif * -1
end
if dif > 1
	puts ans
	exit
else
	if dif == 0
		ans = 2
	else
		ans = 1
	end
	(1..n).each do |i|
		ans = ans * i % me
	end
	(1..m).each do |i|
		ans = ans * i % me
	end
	puts ans
	exit
end

Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Text;

namespace Kyoupro
{
    class Plactice
    {
        static void Main()
        {
            char[] S = new char[0];
            char[] T = new char[0];
            int N = int.Parse(Console.ReadLine());

            Array.Resize(ref S, N);
            Array.Resize(ref T, N);

            //入力文字列をスペース区切りにする
            string STR = Console.ReadLine();
            string[] str = STR.Split(' ');

            S = str[0].ToCharArray();
            T = str[1].ToCharArray();

            for (int i = 0; i < N; i++)
            {
                Console.Write(S[i]);
                Console.Write(T[i]);
            }
        }
    }
}

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

int main(void){
    int ans,a,b,c,k;  
    (void)scanf("%d %d %d %d",&a,&b,&c,&k);
    if(a>=k){
        printf("%d\n",k);
        return 0;
    }
    ans=a;
    k-=a;
    k-=b;
    if(k<=0){
        printf("%d\n",ans);
        return 0;
    }
    printf("%d\n",ans-k);

    return 0;
}

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

int main(){
    int N,T;
    cin>>N>>T;
    vector<int> V(N);
    for(auto &v:V) cin>>v;
    sort(V.begin(), V.end());
    int64_t ans=1;
    for(int i=1;i<N;i++){
        ans*=(V.begin()+i-lower_bound(V.begin(), V.begin()+i, V[i]-T)+1);
        ans%=1000000007;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3164
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,k;
    cin >> n >> k;
    VI a(n);
    REP(i,0,n) cin >> a[i];
    VVI dp(n,VI(k+1));
    VI ru(k+2);
    REP(i,0,a[0]+1) dp[0][i] = 1;
    REP(i,0,k+1) ru[i+1] = (ru[i] + dp[0][i]) % MOD;
    REP(i,1,n) {
        REP(j,0,k+1) dp[i][j] = (MOD + ru[j+1] - ru[max(0,j-a[i])]) % MOD;
        REP(j,0,k+1) ru[j+1] = (ru[j] + dp[i][j]) % MOD;
    }
    cout << dp[n-1][k] << endl;
}

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

Measured memory_bytes: 39928
#include <bits/stdc++.h>
#define i_love_u_Phuong ios_base::sync_with_stdio(0); cin.tie(0);

using ll = long long;
using namespace std;
using ld = long double;
const int MAXN=1e6 + 5;



int main()
{
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif // ONLINE_JUDGE
    i_love_u_Phuong;
    int n;
    cin >> n;
    int hmax=-1;
    int len=1;
    int res=-1;
    for(int i=0; i<n; ++i)
    {
        int k;
        cin >> k;
        if (k>hmax)
        {
            res=max(res,len);
            len=1;
            hmax=k;
        } else
        if (k<=hmax)
        {
            len++;
            hmax=k;
        }
    }
    res=max(res,len);
    cout << res-1;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
const int N = 90005;

ll h, w, d, a[N], temp, q, l, r;
pair<ll,ll> indices[N];


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> h >> w >> d;
	
	// O(N)
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> temp;
			indices[temp] = mp(i,j);
		}
	}
	
	for (int i = d+1; i <= h*w; i++) {
		a[i] = a[i-d] + abs(indices[i].first-indices[i-d].first) + abs(indices[i].second-indices[i-d].second);
	}
	
	cin >> q;
	
	while (q--) {
		cin >> l >> r;
		cout << a[r]-a[l] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3200
#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<map>
#include<cstdlib>
#include<stack>
#include<algorithm>
#include<set>
#include<cmath>
#include<vector>
using namespace std;
int gcd(int a,int b)
{
	int t;
	while(t=a%b)
	{
		a=b;
		b=t;
	}
	return b;
}
int main()
{
	#ifdef local
	freopen("1.txt","r",stdin);
	#endif
	int a,b,k;
	scanf("%d%d%d",&a,&b,&k);
	int ans=gcd(a,b);
	while(ans>0&&k>1)
	{
		ans--;
		if(a%ans==0&&b%ans==0)
		k--;
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  int a,b;
  char o;
  C3(a,o,b);
  if(o == '+')
    cout << a+b << endl;
  else
    cout << a-b << endl;
  ret 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
 
int main() {
     int a,b;
     cin >> a>>b;
     cout << a*b <<endl; 
}

Measured memory_bytes: 3636