akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch GoToJail | diff GoToJail.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address GoToJail.cpp && ./a.out

/*

 9/19/2020

 5:02-

 */

const int MAX_N=1e6+1;
bool A[MAX_N];
int N;

bool solve() {
  REP(i,N-2) if(A[i]&&A[i+1]&&A[i+2]) return true;
  return false;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>N;
  REP(i,N) {
    int a,b; cin>>a>>b;
    A[i]=(a==b);
  }
  cout<<(solve()?"Yes":"No")<<endl;

  return 0;
}


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

using namespace std;
typedef long long ll;

int main(void) {
	int n;
	cin >> n;
	if (n == 0) {
		return 0;
	}
	vector<ll> dp(n, 0);
	vector<vector<bool> > sc(n, vector<bool>(31, false));
	for (int i = 0; i < n; i++) {
		int m, f;
		cin >> m;
		for (int j = 0; j < m; j++) {
			cin >> f;
			sc[i][f] = true;
		}
		dp[i] = 1LL << i;
	}
	int ans = -1;
	for (int i = 1; i <= 30; i++) {
		ll b = 0;
		for (int j = 0; j < n; j++) {
			if (sc[j][i]) {
				b |= dp[j];
			}
		}
		/*
		for (int j = 0; j < n; j++) {
			cout << ((b >> j) & 1);
		}
		cout << endl;
		*/
		if (b == (1LL << n) - 1) {
			ans = i;
			break;
		}
		for (int j = 0; j < n; j++) {
			if (sc[j][i]) {
				dp[j] = b;
			}
		}
	}
	cout << ans << endl;
	return main();
}

Measured memory_bytes: 2604
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

int main() {
  ll h,w;
  cin >> h >> w;
  ll ans=0;
  if(h==1 || w==1){ cout << 1 << endl; return 0; }
  if(h%2==0 || w%2==0){
    ans = h*w/2;
  } else {
    ans = (w/2)*h + (h+1)/2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N, W = [int(i) for i in input().split()]
dp = [[0 for j in range(W + 1)] for i in range(N + 1)]
for i in range(N - 1, -1, -1):
    v, w = [int(i) for i in input().split()]
    for j in range(0, W + 1):
        if j < w :
            dp[i][j] = dp[i + 1][j]
        else :
            dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w] + v)
print(dp[0][W])

Measured memory_bytes: 28044
#include<cstdio>
#include<algorithm>

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

using namespace std;

typedef long long ll;

#define f(i,j,k) (a[i]+a[j]>a[k])

int main(){
	int n; scanf("%d",&n);
	static ll a[100000];
	rep(i,n) scanf("%lld",a+i);

	sort(a,a+n);

	static ll dp[100000];
	rep(i,n-2){
		if(f(i,i+1,i+2)) dp[i+2]=a[i]+a[i+1]+a[i+2]; else dp[i+2]=dp[i+1];
	}

	ll ans=0;
	rep(i,n-5){
		if(f(i+3,i+4,i+5) && dp[i+2]>0){
			ans=max(ans,dp[i+2]+a[i+3]+a[i+4]+a[i+5]);
		}
		if(f(i+0,i+2,i+3) && f(i+1,i+4,i+5)
		|| f(i+0,i+3,i+4) && f(i+1,i+2,i+5)
		|| f(i+1,i+2,i+3) && f(i+0,i+4,i+5)
		|| f(i+1,i+3,i+4) && f(i+0,i+2,i+5)
		|| f(i+2,i+3,i+4) && f(i+0,i+1,i+5)){
			ans=max(ans,a[i]+a[i+1]+a[i+2]+a[i+3]+a[i+4]+a[i+5]);
		}
	}
	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 2280
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;


int main()
{
	string S, T;
	cin >> S >> T;
	int N = S.size();
	S += S;
	for (int i = 0; i < N; i++) {
		if (S.substr(i, N) == T) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n, a, b;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> a >> b;
  cout << min(a, b) << " " << max(0, a+b-n) << endl;
}

Measured memory_bytes: 256
n = int(input())
A = 0
B = 0
C = 0
D = 0
for i in range(n):
  x = input()
  if x == "AC":
    A += 1
  elif x == "WA":
    B += 1
  elif x == "TLE":
    C += 1
  else:
    D += 1
print("AC x " + str(A))
print("WA x " + str(B))
print("TLE x " + str(C))
print("RE x " + str(D))

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

// definitions
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define pb push_back
#define mod1 998244353
#define mod 1000000007
#define MAX_CHAR 256

using namespace std;
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef vector<tuple<long long , long long , long long> > vtup;
typedef deque <long long> dq;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;


// standard functions
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
} 
 


ll modexp(ll x, ll ex, ll modp) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x)%modp;
        ex >>= 1ll;
        x = (x * x)%modp;
    }
    return ans;
} 
 
ll nCrModp(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (ll i = 1; i <= n; i++) 
    { 
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
}
 
bool isPrime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true;  
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
 


ll binarySearch(ll arr[], ll l, ll r, ll x) 
{ 
    while (l <= r) 
    { 
        ll m = l + (r - l) / 2; 
        if (arr[m] == x) 
            return m; 
        if (arr[m] < x) 
            l = m + 1; 
        else
            r = m - 1; 
    }
    return -1; 
}

const ll MAXSIEVE=(1e3);
ll spf[MAXSIEVE];
void sieve() 
{ 
    spf[1] = 1; 
    for (ll i=2; i<MAXSIEVE; i++) 
        spf[i] = i; 

    for (ll i=4; i<MAXSIEVE; i+=2) 
        spf[i] = 2; 
  
    for (ll i=3; i*i<MAXSIEVE; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (ll j=i*i; j<MAXSIEVE; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
}

// code beigns in main
int main()
{

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;
    
    while(t--)
    {
        ll n;
        cin >> n;

        ll arr[n];
        ll pos[n+1]={0};
        rep(i,0,n)
        {
            cin >> arr[i];
            pos[arr[i]]++;
        }

        ll tot=0;
        rep(i,1,n+1)
        tot+=(pos[i]*(pos[i]-1))/2;

        rep(i,1,n+1)
        {
            ll temp=tot;
            ll num=arr[i-1];

            ll c=pos[num];
            temp-=c*(c-1)/2;
            c--;
            temp+=c*(c-1)/2;
            cout << temp << endl;
        }
    }
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int main()
{
#ifdef TarekHasan
    freopen("input.txt","r",stdin);
#endif // TarekHasan
    int x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;

    vector< int > A(a);
    vector< int > B(b);
    vector< int > C(c);

    for(int i=0; i<a; i++)
        cin >> A[i];
    for(int i=0; i<b; i++)
        cin >> B[i];
    for(int i=0; i<c; i++)
        cin >> C[i];


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

    vector< int > Final;

    for(int i=0;i<x;i++)
        Final.push_back(A[i]);
    for(int i=0;i<y;i++)
        Final.push_back(B[i]);
    for(int i=0;i!=C.size();i++)
        Final.push_back(C[i]);

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

    long long int result = 0;

    for(int i=0;i<x+y;i++)
        result+=Final[i];
    cout << result << endl;




    return 0;
}


Measured memory_bytes: 6548
import java.util.Scanner;
class Main{
    public static void main(String[]arge){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int []A=new int[n];
        for(int i=0; i<n; i++){
            A[i]=sc.nextInt();
        }
        int flag,hozon,count=0;
        flag=1;
        while(flag==1){
            flag = 0;
            for(int j=n-1; j>0; j--){
                if(A[j]<A[j-1]){
                hozon=A[j];
                A[j]=A[j-1];
                A[j-1]=hozon;
                flag=1;
                count+=1;
                }
                
            }        
            
     }
        for(int k=0; k<n; k++){
            
            if(k==n-1)System.out.print(A[k]);          
            if(k!=n-1)System.out.print(A[k]+" "); 
        }
            System.out.println("");
            System.out.println(count);   
   }
}    

Measured memory_bytes: 17560
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////

int main() {
	
	ll L;
	cin >> L;

	vector<ll> A(L + 1, 0);

	repn(i, L) cin >> A[i];

	vector<vector<ll>> dp(L + 1, vector<ll>(5, 0));

	repn(i, L) {

		ll e;
		if (A[i] == 0) { e = 2; }
		else { e = A[i] % 2; }

		dp[i][0] = dp[i - 1][0] + A[i];

		dp[i][1] = min(dp[i][0], dp[i - 1][1] + e);

		dp[i][2] = min(dp[i][1], dp[i - 1][2] + (A[i] + 1) % 2);

		dp[i][3] = min(dp[i][2], dp[i - 1][3] + e);

		dp[i][4] = min(dp[i][3], dp[i - 1][4] + A[i]);
	}

	cout << dp[L][4];

	system("PAUSE");
}


Measured memory_bytes: 16120
///
// File:  b.cpp
// Author: ymiyamoto
//
// Created on Tue Nov 21 23:18:32 2017
//

#include <array>
#include <cstdint>
#include <iostream>

using namespace std;

static array<uint64_t, 100> mem{
    0,
};

uint64_t luca(uint32_t n)
{
  if (n == 0)
    return mem[0] = 2;
  else if (n == 1)
    return mem[1] = 1;
  else {
    if (mem[n - 1] == 0) {
      mem[n - 1] = luca(n - 1);
    }
    if (mem[n - 2] == 0) {
      mem[n - 2] = luca(n - 2);
    }

    return mem[n] = mem[n - 1] + mem[n - 2];
  }
}

int32_t main()
{
  uint32_t N;
  cin >> N;

  cout << luca(N) << endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

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

  string s; cin >> s;
  int n = s.size();
  if (s.at(0) != '1' || s.at(n-2) != '1' || s.at(n-1) != '0') {
    cout << -1 << endl;
    return 0;
  }

  for(int i=1; i<=n/2; i++) {
    if (s.at(i) != s.at(n-i-2)) {
      cout << -1 << endl;
      return 0;
    }
  }

  int pos = 1;
  for(int i=1; i<n; i++) {
    cout << pos << ' ' << i+1 << '\n';
    if (i <= n/2 && s.at(i-1) == '1') {
      pos = i+1;
    }
  }
}

Measured memory_bytes: 1616
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using ll = long long;
using lli = long long int;

lli n, m, p;
std::string s;

int main() {
    std::cin >> n >> m;
    std::vector<ll> vec;
    std::vector<ll> wa;
    vec.assign(n+1, 0);
    wa.assign(n+1, 0);
    for (int i = 0; i < m; i++) {
        std::cin >> p >> s;
        if (s == "AC") {
            vec[p] = 1;
        }
        else if (s == "WA" && vec[p] == 0) {
            wa[p]++;
        }
    }
    ll sum_wa = 0;
    for (int i = 1; i < wa.size(); i++) {
        if (vec[i] == 1) {
            sum_wa += wa[i];
        }
    }
    ll num_ac = std::count(vec.begin()+1, vec.end(), 1);
    std::cout << num_ac << " " << sum_wa << std::endl;

}


Measured memory_bytes: 4776
/*input
9 5
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<int,int>
#define f first
#define s second
#define pb emplace_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n) memset(n,0,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int arr[maxn];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	double n,k;
	cin>>n>>k;
	cout<<ceil(n/(2*k+1));
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args) throws IOException{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] strArr = br.readLine().split(" ");

        double a = Integer.parseInt(strArr[0]);
        double b = Integer.parseInt(strArr[1]);

        int div = (int)a / (int)b;
        int rem = (int)a % (int)b;
        double divDbl = a / b;

        System.out.printf("%d %d %.5f", div,rem,divDbl);

    }
}

Measured memory_bytes: 24804
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dumpi(x1) fprintf(stderr, "#%s.%d (%s) = (%d)\n", __func__, __LINE__, #x1, x1);
#define dumpii(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%d, %d)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpiii(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%d, %d, %d)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

struct Solver {
  long k, s;
  Solver() {
    S002 r;
    r >= k >= s;
  }
  void solve() {
    long res = 0;
    for(long i = 0; i <= k; ++i) {
      for(long j = 0; j <= k; ++j) {
        long t = s - i - j;
        if( 0 <= t and t <= k ) res += 1;
      }
    }
    printf("%ld\n", res);
  }
};
 
int main() {
  for(;;) std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

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

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

void rec(ll i,vector<vector<ll>>& g,vector<bool>& seen,vector<ll>& f){
    seen[i]=true;
    ll j;
    for(j=0;j<g[i].size();j++){
        if(seen[g[i][j]]==false){
            rec(g[i][j],g,seen,f);
        }
    }
    f.push_back(i);
}

int main() {
    ll n,m;cin>>n>>m;
    ll x[m],y[m];
    vector<vector<ll>> g(n);
    vector<bool> seen(n,0);
    vector<ll> f;
    for(ll i=0;i<m;i++){
        cin>>x[i]>>y[i];
        g[x[i]-1].push_back(y[i]-1);
    }
    ll dp[n];
    for(ll i=0;i<n;i++){
        dp[i]=0;
        if(seen[i]==false){
            rec(i,g,seen,f);
        }
    }
    for(ll i=n-1;i>=0;i--){
        for(ll j=0;j<g[f[i]].size();j++){
            dp[g[f[i]][j]]=max(dp[g[f[i]][j]],dp[f[i]]+1);
        }
    }
    ll ans;ans=0;
    for(ll i=0;i<n;i++){
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11764
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <cstdio>
#include<iomanip>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;

int main() {
  string s;
  cin >> s;
  int a = 0;
  rep(i, s.length()/2) {
    if (s[i] != s[s.length() - i-1]) {
      a++;
    }
  }
  cout << a;
  return 0;
}

/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
//配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int n;
  cin >> n;
  vii cnt(10,vi(10));
  REP(i,n+1) {
    string s = to_string(i);
    cnt[s[0]-'0'][s.back()-'0']++;
  }
  ll ans = 0;
  for(int i = 1; i <= 9; i++) {
    for(int j = 1; j <= 9; j++) {
      ans += cnt[i][j] * cnt[j][i];
    }
  }
  cout << ans << endl;
}

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


void solve(long long H, long long A){
    int cnt = 0;
    while(H > 0){
        H = H - A;
        cnt += 1;
    }
    cout << cnt << endl;
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long A;
    scanf("%lld",&A);
    solve(H, A);
    return 0;
}


Measured memory_bytes: 3624
def bb
    n = gets.chomp.to_i
    an = gets.chomp.split(/\s/).map{|x| x.to_i}
    bn = gets.chomp.split(/\s/).map{|x| x.to_i}
    cn = gets.chomp.split(/\s/).map{|x| x.to_i}

    sc = 0
    j0 = an[0]
    for i in 1..n
        j = an[i-1]
        sc += bn[j-1]
        next if i == 1
        if j == j0+1
            sc += cn[j0-1]
        end
        j0 = j
    end

    puts sc
end

bb

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

int main (){
  
  int len;
  char str[50];
  
  scanf("%s",str);
  
  len = strlen(str);
  
  if(str[0]=='x' && str[len-1]=='x')printf("x\n");
  else printf("o\n");
  
  return 0;
  
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;

const ll MOD = 1e9 + 7;

ll a[3][2];
ll na[3][2];

int main() {
#ifdef PAUNSVOKNO
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); cout.tie(nullptr); cin.tie(nullptr);
    string s;
    cin >> s;
    s = s + "10";
    a[0][1] = 1;
    int x = 0;
    for (char c : s) {
        memset(na, 0, sizeof(na));

        if (c != '1') {
            for (int i = 0; i < 3; ++i) {
                for (int l = 0; l < 2; ++l) {
                    na[i][0] += a[i][l];
                }
            }
        }

        if (c != '0') {
            for (int i = 0; i < 3; ++i) {
                for (int j = 0; j < 2; ++j) {
                    int ni = i + (j && (i == x));
                    na[ni][1] += a[i][j];
                }
            }
        }

        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 2; ++j) {
                a[i][j] = na[i][j] % MOD;
            }
        }

        x = 1 - x;
    }

    cout << a[2][0] << "\n";
}

Measured memory_bytes: 916
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using i128 = __int128_t;
int main() {
  ll x, k, d; cin >> x >> k >> d;
  i128 X = abs(x);
  while (k != 1) {
    ll k2 = k / 2;
    X = abs(X - i128(k2) * d);
    k -= k2;
  }
  cout << ll(abs(X - d)) << endl;
}


Measured memory_bytes: 3632
function twoMax(arr) {
    var first = 0;
    var firstKey = -1
    var second = 0;
    var secondKey = -1;
    for (var i = 0; i < arr.length; i++) {
        if (arr[i] >= first) {
            second = first;
            secondKey = firstKey;
            first = arr[i];
            firstKey = i;
        } else if (arr[i] >= second) {
            second = arr[i];
            secondKey = i;
        }
    }
    return [first, firstKey, second, secondKey];
}
function Main(input) {
    input = input.split("\n");
    var n = parseInt(input[0], 10);
    var V = input[1].split(" ").map(x => parseInt(x, 10));
    var freqEven = new Array(100001).fill(0);
    var freqOdd = new Array(100001).fill(0);
    for (var i = 0; i < n; i++) {
        if (i % 2 == 0) {
            freqEven[V[i]]++;
        } else {
            freqOdd[V[i]]++;
        }
    }
    var evenTwoMax = twoMax(freqEven);
    var evenFirst = evenTwoMax[0];
    var evenFirstKey = evenTwoMax[1]; 
    var evenSecond = evenTwoMax[2];
    var oddTwoMax = twoMax(freqOdd);
    var oddFirst = oddTwoMax[0];
    var oddFirstKey = oddTwoMax[1];
    var oddSecond = oddTwoMax[2];
    var minus = 0;
    if (evenFirstKey == oddFirstKey) {
        minus = Math.max(evenFirst+oddSecond, oddFirst + evenSecond);
    } else {
        minus = evenFirst + oddFirst;
    }
    console.log(n-minus);
}

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

Measured memory_bytes: 27968
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
char s[10][10];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),m=gi();
	for(int i=1;i<=n;++i)scanf("%s",s[i]+1);
	int x=1,y=1;
	while((x<n||y<m)&&(x<=n&&y<=m)){
		s[x][y]='%';
		if(s[x+1][y]=='#')++x;
		else++y;
	}
	s[n][m]='%';
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			if(s[i][j]=='#')return puts("Impossible"),0;
	puts("Possible");
	return 0;
}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int out[]={11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,761,811,821,881,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381};
int main(){
	int n;
	cin>>n;
	rep(i,n)cout<<out[i]<<" \n"[i==n-1];
}






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

int main() { 
	double A,B;
  	cin>>A>>B;
  	int ans=-1;
	for(int i=1; i<=100000; i++){
      
      if(floor(i*0.08)==A && floor(i*0.1)==B){
        ans=i;
        break;
      }
    }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a,b,c;
    
    scanf("%d %d %d",&a,&b,&c);
    
    if(a!=b && a!=c){
        printf("%d\n",a);
    }
    
    else if(b!=a && b!=c){
        printf("%d\n",b);
    }
    else if(c!=a && c!=b){
        printf("%d\n",c);
    }
    
    
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] srgs){
        Scanner sc = new Scanner(System.in);
        for(int i = 1; ; i++){
            int x = sc.nextInt();
            if(x == 0){
                break;
            }else{
                System.out.println("Case "+ i +": "+x);
            }
        }
    }
}


Measured memory_bytes: 41212
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val t = (1..3).map { (1..3).map { sc.nextInt() }.toMutableList() }
    val n = sc.nextInt()
    val s = (1..n).map { sc.nextInt() }
    for (i in 0..2) {
        for (j in 0..2) {
            if (s.contains(t[i][j])) {
                t[i][j] = 0
            }
        }
    }
    if (t[0][0] == 0 && t[0][1] == 0 && t[0][2] == 0 ||
        t[1][0] == 0 && t[1][1] == 0 && t[1][2] == 0 ||
        t[2][0] == 0 && t[2][1] == 0 && t[2][2] == 0 ||
        t[0][0] == 0 && t[1][0] == 0 && t[2][0] == 0 ||
        t[0][1] == 0 && t[1][1] == 0 && t[2][1] == 0 ||
        t[0][2] == 0 && t[1][2] == 0 && t[2][2] == 0 ||
        t[0][0] == 0 && t[1][1] == 0 && t[2][2] == 0 || 
        t[2][0] == 0 && t[1][1] == 0 && t[0][2] == 0) {
        println("Yes")
    } else {

        println("No")
    }
}

Measured memory_bytes: 29728
#include<stdio.h>
int main(void)
{
	int n,i,j,k,l,cnt;
	while(scanf("%d",&n)!=EOF){
		cnt=0;
		for(i=0;i<10;i++){
			for(j=0;j<10;j++){
				for(k=0;k<10;k++){
					for(l=0;l<10;l++){
						if(i+j+k+l==n){
							cnt+=1;
						}
					}
				}
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}


Measured memory_bytes: 2044
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_sum = [0]
B_sum = [0]
A_now = 0
B_now = 0
for i in range(N):
    A_now = A[i] + A_now
    A_sum.append(A_now)
for i in range(M):
    B_now = B[i] + B_now
    B_sum.append(B_now)


ans = 0
for i in range(N+1):
    book_count = i
    remain_time = K - A_sum[i]

    ok = 0
    ng = M

    if remain_time >= B_sum[M]:
        ans = book_count + M

    while ng - ok > 1:
        mid = (ok+ng)//2
        if remain_time >= B_sum[mid]:
            ok = mid
        else:
            ng = mid

    book_count += ok
    if remain_time >= 0:
        if book_count > ans:
            ans = book_count
#            print(mid,remain_time,B_sum[ok])                                                       

print(ans)


Measured memory_bytes: 47388
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(int i=m;i<n;i++)
#define OKawaiiKoto ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const ll INF=2*1e18;
const ld PI=3.14159265358979323846;
int main()
{
    OKawaiiKoto
    ll n,q,sum=0;
    map<ll,ll> m;
    set<ll> s;
    cin>>n;
    rep(i,n)
    {
        ll a;
        cin>>a;
        m[a]++;
        s.insert(a);
        sum+=a;
    }
    cin>>q;
    while(q--)
    {
        ll b,c;
        cin>>b>>c;
        if(s.count(b))
        {
            s.erase(b),s.insert(c);
            sum+=m[b]*(c-b);
            m[c]+=m[b];
            m[b]=0;
        }
        cout<<sum<<"\n";
    }

}


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

const ll X=1000000007;

int main() {
  ll T1,T2,A1,A2,B1,B2,TA,TB,AA,AB,D;
  cin>>T1>>T2>>A1>>A2>>B1>>B2;
  TA=T1*A1;
  TB=T2*A2;
  AA=T1*B1;
  AB=T2*B2;//高橋青木の前後半で進む距離
  D=TA+TB-AA-AB;
  if(TA+TB==AA+AB){
  cout<<"infinity"<<endl;
  }
  else{
    if(D<0){swap(TA,AA);swap(TB,AB);D=-D;}
    //以降は高橋の方が先に進む場合のみ
    if(TA>AA){cout<<0<<endl;}
    else{
      ll d=AA-TA;
      if(d%D==0){
        cout<<2*(d/D)<<endl;
      }
      else{
        cout<<2*(d/D)+1<<endl;
      }
    }
  }
}



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

int main(){
    int n, cnt[26] = {};
    string s;
    cin >> s;
    n = s.size();
    for(int i=0;i<n;i++){
        cnt[s[i]-'a']++;
    }
    bool ok = true;
    for(int i=0;i<26;i++){
        if(cnt[i]>1) ok = false;
    }
    if(ok){
        cout << "yes" << endl;
    }
    else{
        cout << "no" << endl;
    }
    return 0;
}

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

using namespace std;

using ll = long long int;
const ll MOD = 1000000007;

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

    vector<ll> allNum;
    vector<ll> oddNum;

    ll n = 1;

    while(true){
        ll tmp = (n*(n+1)*(n+2))/6;
        if(tmp > 1000000){
            break;
        }
        allNum.push_back(tmp);
        if(tmp&1){
            oddNum.push_back(tmp);
        }
        ++n;
    }

    vector<ll> allDP(1000001,-1);
    vector<ll> oddDP(1000001,-1);

    allDP[0] = 0;
    oddDP[0] = 0;

    for(int i = 0; i < allNum.size(); i++){
        for(int j = 0; j < 1000001; j++) {
            if (j - allNum[i] >= 0 && allDP[j - allNum[i]] >= 0) {
                if (allDP[j] >= 0) {
                    allDP[j] = min(allDP[j], allDP[j - allNum[i]] + 1);
                } else {
                    allDP[j] = allDP[j - allNum[i]] + 1;
                }
            }
        }
    }

    for(int i = 0; i < oddNum.size(); i++){
        for(int j = 0; j < 1000001; j++) {
            if (j - oddNum[i] >= 0 && oddDP[j - oddNum[i]] >= 0) {
                if (oddDP[j] >= 0) {
                    oddDP[j] = min(oddDP[j], oddDP[j - oddNum[i]] + 1);
                } else {
                    oddDP[j] = oddDP[j - oddNum[i]] + 1;
                }
            }
        }
    }

    while(true){
        ll a;
        cin >> a;
        if(a == 0){
            break;
        }
        cout << allDP[a] << " ";
        cout << oddDP[a] << endl;
    }
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int64_t> a(n + 1);
  a.at(0) = 2;
  a.at(1) = 1;
  rep(i, n - 1) a.at(i + 2) = a.at(i + 1) + a.at(i);
  cout << a.at(n) << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>       // for next_permutation
#include <vector>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  if(A != 1 && B != 1) cout << 1 << endl;
  else if(A != 2 && B != 2) cout << 2 << endl;
  else cout << 3 << endl;
  return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
#define PI acos(-1)
using namespace std;
int main(){
  int a,b,c;
  int x=0,y=0,z=0,w=0;
  while(cin>>a>>b>>c){
    vector<int>in(3);
    in[0]=a;in[1]=b;in[2]=c;
    sort(all(in));
    if(in[0]+in[1]<=in[2])break;
    x++;    
    if(in[0]*in[0]+in[1]*in[1]==in[2]*in[2])y++;
    if(in[0]*in[0]+in[1]*in[1]>in[2]*in[2])z++;
    if(in[0]*in[0]+in[1]*in[1]<in[2]*in[2])w++;
  }
  cout<<x<<" "<<y<<" "<<z<<" "<<w<<endl;
}

Measured memory_bytes: 1212
const MOD: u64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let mut ab = Vec::new();
    for _ in 0..n {
        let a: u64 = sc.read();
        ab.push((a, 0));
    }
    for _ in 0..n {
        let a: u64 = sc.read();
        ab.push((a, 1));
    }
    ab.sort();

    let mut m = 0;
    let mut c = 0;
    let mut ans = 1;
    for &t in &ab {
        let (_, k) = t;
        if k == 0 {
            if m == 0 { c += 1; } else {
                ans *= m;
                ans %= MOD;
                m -= 1;
            }
        } else {
            if c == 0 { m += 1; } else {
                ans *= c;
                ans %= MOD;
                c -= 1;
            }
        }
    }

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

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner { ptr: 0, length: 0, buf: vec![0; 1024], small_cache: vec![0; 1024] }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool { b == b'\n' || b == b'\r' || b == b'\t' || b == b' ' }

    fn read<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)]).parse().unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}



Measured memory_bytes: 9464
fun main() {
    val mod = 1000000007
    val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
    val factorial = LongArray(m + 1){1L}
    val div = LongArray(m + 1) {1L}
    val inverse = LongArray(m + 1) {1L}

    for (i in 2 .. m) {
        factorial[i] = i * factorial[i - 1] % mod
        div[i] = (mod - mod / i) * div[mod % i] % mod
        inverse[i] = div[i] * inverse[i - 1] % mod
    }
    fun combination(n: Int, r: Int): Long {
        return factorial[n] * inverse[n - r] % mod * inverse[r] % mod
    }
    fun permutation(n: Int, r: Int): Long {
        return factorial[n] * inverse[n - r] % mod
    }
    var result = permutation(m, n)
    for (i in 1 .. n) {
        if ((i and 1) == 1) {
            result = (result + mod - combination(n, i) * permutation(m - i, n - i) % mod) % mod
        }else {
            result = (result + combination(n, i) * permutation(m - i, n - i)) % mod
        }
    }
    result = result * permutation(m, n) % mod
    println(result)
}


Measured memory_bytes: 49208
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

int f(int x) {
  
  int res = 0;
  while(x > 0) {
    res += x & 1;
    x >>= 1;
  }
  return res;
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<vector<P>> xy(n);
  rep(i, n) {
    cin >> a[i];
    rep(j, a[i]){
      int x, y;
      cin >> x >> y;
      --x;
      xy[i].push_back(P(x, y));
    }
  }
  int ans = 0;
  rep(bit, 1<<n) {
    
    bool ok = true;
    rep(i, n) {
      if(!(bit>>i&1)) continue;

      rep(j, a[i]) {
        
        int x = xy[i][j].first;
        int y = xy[i][j].second;
        int t = bit>>x&1;
        if(t != y) ok = false;
      }
    }
    int cnt = f(bit);
    if(ok) ans = max(ans, cnt);
  }
  cout << ans << endl;
}

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

A = []
for _ in range(n):
    A.append(list(map(int, input().split())))

B = []
for _ in range(m):
    B.append(list(map(int, input().split())))

C = [ [ 0 for _ in range(l) ] for _ in range(n) ]
for i in range(n):
    for j in range(l):
        for k in range(m):
            C[i][j] += A[i][k]*B[k][j]

for i in range(n):
    sep = ''
    for j in range(l):
        print(sep+str(C[i][j]), end='')
        sep = ' '
    print()


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

using namespace std;

using int64 = long long;

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

  int n;
  cin >> n;
  vector<int> as(n);
  for (int i = 0; i < n; i++) {
    cin >> as[i];
    as[i]--;
  }
  vector<int> bs(n);
  for (int i = 0; i < n; i++) {
    cin >> bs[i];
  }
  vector<int> cs(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> cs[i];
  }

  int score = 0;
  for (int i = 0; i < n; i++) {
    score += bs[i];
  }

  for (int i = 0; i < n - 1; i++) {
    if (as[i] + 1 == as[i + 1]) {
      score += cs[as[i]];
    }
  }
  cout << score << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;
// ------------------------------

int main() {
    string S;
    cin >> S;
    vector<string> vec;
    int idx = 0;
    bool over = false;
    int ans = 0;
    rep(i, S.size()) {
        if (i == 0) {
            vec.push_back(string() + S[i]);
            ans += 1;
            continue;
        }
        string now = string() + S[i];
        while (vec[idx] == now) {
            if (i == S.size() - 1) {
                over = true;
                break;
            }
            i += 1;
            now = now + S[i];
        }
        if (over) break;
        vec.push_back(now);
        idx += 1;
        ans += 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11832
from collections import defaultdict
N,K=map(int,input().split())

dtlist=[]
tset_all=set()
for i in range(N):
  t,d=map(int,input().split())
  dtlist.append((d,t))
  tset_all.add(t)
dtlist.sort()
#print(heapq)

dtlist_Krev=[]
dsum=0
tdic=defaultdict(int)
for i in range(K):
  d,t=dtlist.pop()
  dtlist_Krev.append((d,t))
  dsum+=d
  tdic[t]+=1
#dtlist_Krev.sort(reverse=True)

t0=len(tdic)
max_answer=dsum+(t0**2)
#print(t0,max_answer)

for i in range(t0+1,min(K,len(tset_all))+1):
  while(True):    
    d1,t1=dtlist_Krev.pop()
    if tdic[t1]>1:
      tdic[t1]-=1
      dsum-=d1
      break
      
  while(True):        
    d2,t2=dtlist.pop()
    if tdic[t2]==0:
      tdic[t2]=1
      dsum+=d2      
      break
          
  answer_i=dsum+(i**2)
  #print(i,answer_i)
  max_answer=max(max_answer,answer_i)
  
print(max_answer)

Measured memory_bytes: 26984
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
  string str;
  cin >> str;

for(int i = 0; i < 4; i++) cout << str[i];
cout << " ";
for(int i = 4; i < str.size(); i++) cout << str[i];
cout << endl;  

  return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  int sum=1;
  
  for(int i=0; i<N; i++){
   cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  for(int j=0;j<N-1;j++){
    if(vec.at(j) > vec.at(j+1)){
      sum += 1;
    }
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a,b,c,d,e=0;
	scanf("%d %d %d",&a,&b,&c);
	for(d=a;d<=b;d++){
		if(c%d==0){
			e++;
		}
			
		
	}
	printf("%d\n",e);

	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

unsigned long long combi(int a,int b)
{
    int i;
    unsigned long long C=1;
    for(i=1;i<=b;i++) C = C*(a-i+1)/i;
    return C;
}

int main()
{
    int N,A,B,i,j,sum=0,sub=0;
    unsigned long long v[50],max,C=0,ave=0;
    scanf("%d %d %d",&N,&A,&B);
    for(i=0;i<N;i++){
        scanf("%lld",&v[i]);
        for(j=i;j>0;j--){
            if(v[j]>v[j-1]){
                max=v[j];
                v[j]=v[j-1];
                v[j-1]=max;
            }
        }
    }
    if(v[0]==v[A-1]){
        sum=A;
        for(i=A;i<N;i++){
            if(v[0]==v[i]) sum++;
            else break;
        }
        for(i=A;i<=B;i++){
            C+=combi(sum,i);
            if(i==sum) break;
        }
        printf("%lf\n%lld\n",(double)v[0],C);
    }
    else{
        for(i=0;i<A;i++) ave+=v[i];
        for(i=0;i<N;i++){
            if(v[A-1]==v[i]){
                sum++;
                if(i<A) sub++;
            }
            else if(i>=A && v[A-1]!=v[i]) break;
        }
        printf("%lf\n%lld\n",(double)ave/A,combi(sum,sub));
    }
    return 0;
}

Measured memory_bytes: 128