akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int K,S,ans;

int main(){
    scanf("%d%d",&K,&S);
    for (int i=0;i<=K;i++){
        for (int j=0;j<=K;j++){
            if (S-i-j<=K && S-i-j>=0){
                ans++;
            }
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define po pop_back
#define mp make_pair
#define fi first
#define se second
#define hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MOD 1000000007  
using namespace std;
bool comp(ll a,ll b){if(a>b)return true;else return false;}
int isP(ll n){if(n==1)return 0;if(n==2 || n==3)return 1;for(ll i=2;i<=sqrt(n);i++){if(n%i==0)return 0;}return 1;}
ll power(ll a,ll b){if(b==0)return 1;if(b==1) return a;ll t=power(a,b/2);if(b%2==1) return t*t*a;else return t*t;}
ll powMOD(ll x,ll y){if(y==0)return 1;if(y==1)return x;ll t=powMOD(x,y/2);if(y%2==1)return t*t%MOD*x%MOD;else return t*t%MOD;}
bool cmp(pair<ll,ll> p1,pair<ll,ll> p2){if(p1.fi>p2.fi) return true;if(p1.fi==p2.fi && p1.se>p2.se) return true;return false;}


ll f[1000001];
ll nc(ll n,ll r)
{
	ll v=f[n];
	ll v1=f[n-r]*f[r]%MOD;
	v=v*powMOD(v1,MOD-2)%MOD;
	return v;
}
int main()
{
    hello;
    
    ll t;
//    cin>>t;
	t=1;
	f[0]=1;
	for(ll i=1;i<=1000000;i++) f[i]=f[i-1]*i%MOD;
	while(t--){
		ll ans=0;
		ll n;
		cin>>n;
		if(n==1){
			cout<<0<<"\n";
		}
		else if(n==2){
			cout<<2<<"\n";
		}
		else{
			ll v1=powMOD(8ll,n)%MOD;
			ll v2=0;
			for(ll i=1;i<=n;i++){
				v2=(v2+nc(n,i)*powMOD(8ll,n-i)%MOD)%MOD;
			}
			v2=v2*2%MOD;
			ans=(powMOD(10ll,n)-v1+MOD)%MOD;
			ans=(ans-v2+MOD)%MOD;
			cout<<ans<<"\n";
		}
	}
    
    return 0;  
} 

Measured memory_bytes: 11504
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  bitset<100000> b;
  ll t, n;std::cin >> n;
  re(i, n){
    std::cin >> t;
    b |= (b<<t);
    b.set(t);
  }
  ll ans = 0;
  re(i, 100000) if(b[i]&&(i%10!=0)) ans = i;
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
S=input()
S=sorted(set(S))
if S.count("N")==1:
	if S.count("S")==0:
		print("No")
		exit()
if S.count("S")==1:
	if S.count("N")==0:
		print("No")
		exit()
if S.count("E")==1:
	if S.count("W")==0:
		print("No")
		exit()
if S.count("W")==1:
	if S.count("E")==0:
		print("No")
		exit()
print("Yes")

Measured memory_bytes: 9072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main() {
  ll N; cin >> N;
  ll k;
  vector<int> a(N,0); 
  for(int i=0; i<N-1; i++){
    cin >> k ;
    a[k-1] += 1;
  }  
  for(int i=0; i<N; i++){
    cout << a[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 4052
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

struct RollingHash {
	vector<ll>hash;
	vector<ll>base_pow;
	ll base, mod;
	const ll DEFAULT_BASE = 1009, DEFAULT_MOD = 1e9 + 7;
	RollingHash(string S = "", ll base_ = -1, ll mod_ = -1) {
		base = (base_ > 0) ? base_ : DEFAULT_BASE;
		mod = (mod_ > 0) ? mod_ : DEFAULT_MOD;
		if (S.size() > 0)initialize(S);
	}
	void initialize(string& S) {
		int N = S.size();
		vector<int>s(N);
		for (int i = 0; i < N; i++)s[i] = S[i];
		initialize2(s);
	}

	void initialize2(vector<int>& S) {
		hash.resize(S.size() + 1);
		base_pow.resize(S.size() + 1);
		hash[0] = 0;
		base_pow[0] = 1;
		for (int i = 1; i <= S.size(); i++) {
			hash[i] = (hash[i - 1]*base + S[i-1]) % mod;
			base_pow[i] = base_pow[i - 1] * base % mod;
		}
	}

	//[a,b)
	ll between(int a,int b) {
		return (mod + hash[b] - hash[a] * base_pow[b - a] % mod)%mod;
	}
};

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

	int N;
	string S;
	cin >> N >> S;
	int ok = 0, ng = N + 1;
	RollingHash rh1(S,1007,1e9 + 7), rh2(S,1009,1e9 + 9);

	while (ng - ok > 1) {
		int mid = (ng + ok) / 2;
		set<pair<ll, ll>>val;
		vector<pair<ll, ll>>v(N);
		int check = 0;
		for (int i = 0; i + mid <= N; i++) {
			if (i >= mid) {
				val.insert(v[i - mid]);
			}
			v[i] = {rh1.between(i,i+mid),rh2.between(i,i+mid)};
			if (val.count(v[i])) {
				check = 1;
				break;
			}
		}
		if (check)ok = mid;
		else ng = mid;
	}
	puts(ok);

	return 0;
}

Measured memory_bytes: 844
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define PER(i, x, y) for(ll i = x; i > y; i--)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

int main() {
    ll A, B, C;
    cin >> A >> B >> C;
    ll ans = 0;
    if (B >= C - 1) {
        ans = B + C;
    } else if (A + B >= C - 1) {
        ans = B + C;
    } else {
        ans = B + (A + B + 1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	
	int matrix[3][3];
	int bingo [3][3] = {0};
	
	for(int i=0; i<3; i++){
		for(int j=0; j<3; j++){
			scanf("%d", &matrix[i][j]);
		}
	}
	
	int N;
	scanf("%d", &N);
	
	for(int k=0; k<N; k++){
		int a;
		scanf("%d", &a);
		for(int i= 0; i<3; i++){
			for(int j = 0; j<3; j++){
				if(matrix[i][j] == a){
					bingo[i][j] = 1;
				}
			}
		}
	}
	
	if(bingo[0][0] + bingo[1][1] + bingo[2][2] == 3 || bingo[0][2] +bingo[1][1] +bingo[2][0] == 3){
		printf("Yes\n");
		return 0;
	}for(int i = 0; i < 3;i++){
	if(bingo[i][0]+bingo[i][1]+bingo[i][2]==3||bingo[0][i]+bingo[1][i]+bingo[2][i]== 3){
		printf("Yes\n");
		return 0;
	}
}
printf("No\n");	
	return 0;
}

Measured memory_bytes: 1648
#include <bits/stdc++.h>
using namespace std;
const int INF = 2100100100;

int main() {
    string s,t;
    cin >> s;
    cin >> t;
    int m = min ( s.size() , t.size() );
    vector<char> newS = vector<char>(s.size());
    vector<char> newT = vector<char>(t.size());
    for (int i=0;i<s.size();i++){
        newS.at(i) = s.at(i);
    }
    for (int i=0;i<t.size();i++){
        newT.at(i) = t.at(i);
    }
    sort(newS.begin(),newS.end());
    sort(newT.begin(),newT.end(),greater<char>());
    bool can = false;
    bool end = false;
    for (int i=0;i<m;i++){
        if(newS.at(i) == newT.at(i)){
            continue;
        }
        else if(newS.at(i) < newT.at(i)){
            can = true;
            end = true;
            break;
        }
        else {
            end = true;
            break;
        }
    }
    if (end == false){
        if (s.size()<t.size())
            can = 1;
    }
    if (can)
        cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll a,b;
	scanf("%lld%lld",&a,&b);
	if(a+b<10)printf("%lld",a+b);
	else puts("error");
}

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

void reverse(string &s, int m, int n){
    int i;
    string tmp;
	for (i=m;i<=(m+n)/2;i++){
		tmp[0] = s[i];
		s[i] = s[m+n-i];
		s[m+n-i] = tmp[0];
	}
}

int main(){
    string s,t;
    cin>>s>>t;
    int ls,i=0,flag=0;
    ls=s.length();
    while(i<ls){
        if(s!=t){
            reverse(s,0,ls-2);
            reverse(s,0,ls-1);
        }
        else{
            cout<<"Yes";
            flag=1;
            break;
        }
        i++;
    }
    if(!flag){
        cout<<"No";
    }


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	string S, T;
	cin >> S >> T;
	string s = S;
	int i = 1;
	while (i!=(S.size()+1)) {
		if (s == T) {
			cout << "Yes";
			return 0;
		}
		rep(j, S.size())s[j] = S[(j + i) % S.size()];
		i++;
	}
	cout << "No";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <queue>
#include <vector>
#define mod 1000000007
#define ll long long
#define pi acos(-1)
using namespace std;
const double INF = 1e20;

int main(){
	ios::sync_with_stdio(false);
	int a,b,c;
	cin>>a>>b>>c;
	a^=b^=a^=b;
	a^=c^=a^=c;
	cout<<a<<" "<<b<<" "<<c;
	
	return 0;
}

Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn input_vec() -> Vec<u128> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let n: usize = input();
    let a_vec = input_vec();
    let mut ans = 1u128;
    for a in &a_vec {
        if *a == 0 {
            println!("0");
            return;
        }
    }
    for a in a_vec {
        if a * ans > 1_000_000_000_000_000_000 {
            println!("-1");
            return;
        }
        ans *= a;
    }
    println!("{}", ans);
}


Measured memory_bytes: 5640
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

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

    int a1,a2,a3; cin >> a1 >> a2 >> a3;
    if(a1+a2+a3 >= 22) COUT("bust");
    else COUT("win");
}



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

int main(){
  vector<int> A(3);
  cin>>A.at(0)>>A.at(1)>>A.at(2);
  sort(A.begin(),A.end());
  if((A.at(0)+A.at(1))%2==0){
    cout<<A.at(2)-((A.at(0)+A.at(1))/2)<<endl;
  }
  else{
    cout<<(2*A.at(2)+3-A.at(0)-A.at(1))/2<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;

int main(){
        double a,b,theta;
        cin >> a >> b >> theta;
        cout << setprecision(20);
        cout << (a*b*sin(( theta/360) * 2*M_PI))/2 << endl;
        cout << a+b+pow(a*a + b*b - 2*a*b*cos( (theta/360) * (2*M_PI)),0.5) << endl;
        cout << ((a*b*sin(( theta/360) * 2*M_PI)))/a << endl;

return 0;
}

Measured memory_bytes: 3552
N = int(input())
A = [0] * N
B = [0] * N
for i in range(N):
	A[i], B[i] = map(int, input().split())

ans = 0
for i in range(N - 1, -1, -1):
    a = (A[i] + ans) % B[i]
    if a > 0:
    	ans += B[i] - a
print(ans)


Measured memory_bytes: 10868
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

const ll X=2001;

bool check[X];
ll ans[X] = {};
ll dis[X] = {};
vector <ll> v[X];

ll n;
void bfs(ll x){
    for(ll i=1;i<=n;i++){
        dis[i] = -1;
        check[i] = false;
    }
    dis[x] = 0;
    check[x] = true;
    queue <ll> q;
    q.push(x);
    while(!q.empty()){
        ll u = q.front();
        q.pop();
        for(ll i=0;i<v[u].size();i++){
            ll tmp = v[u][i];
            if(check[tmp] == false){
                check[tmp] = true;
                q.push(tmp);
                dis[tmp] = dis[u] + 1;
            }
        }
    }
    for(ll i=1;i<=n;i++){
        ans[dis[i]]++;
    }

}

int main() {
    

    ll x,y;
    cin >> n >> x >> y;
//    for(ll i=1;i<=n;i++){
//        check[i] = false;
//    }
    v[1].push_back(2);
    v[n].push_back(n-1);
    for(ll i=2;i<n;i++){
        v[i].push_back(i-1);
        v[i].push_back(i+1);
    }
    v[x].push_back(y);
    v[y].push_back(x);
    for(ll i=1;i<=n;i++){
        bfs(i);
    }
    for(ll i=1;i<n;i++){
        cout << ans[i]/2 << endl;
    }

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const  int mod = 1000000007;
void add(ll& a, ll b)
{
    a+=b;
    while(a>=mod)
        a-=mod;
    while(a<0)
        a+=mod;
    
}

int main()
{
	int a,b,c; cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b<<endl;
	
  	return 0;
}

Measured memory_bytes: 256
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
n = ip()                                     #入力整数1つ
#a,b,c= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
dp = [-1 for i in range(n+1)]
dp[0] = 0
dp[1] = 0
dp[2] = abs(a[0]-a[1])
#dp[3]  =     min(dp[2] +  abs(a[2] - a[1]) ,     dp[1] +   abs(a[2] - a[0]))

for i in range(3,n+1):
    dp[i] = min(dp[i-1] + abs(a[i-1] - a[i-2]) , dp[i-2] + abs(a[i-1]-a[i-3]) )
 #   print(dp)
print(dp[n])

Measured memory_bytes: 24108
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

int main() {
    char x, y;
    cin >> x >> y;
    if(x - y > 0) cout << ">" << endl;
    else if(x - y == 0) cout << "=" << endl;
    else cout << "<" << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll h,w;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>h>>w;
    ll ans = INF;
    ll tmp,tmp2,tmp3;
    rep(i,h){
        if(i==0)continue;
        tmp = i * w;
        tmp2 =  (w/2)*(h-i);
        chmin(ans,max(tmp,max(tmp2,(h-i)*w-tmp2)) - min(tmp,min(tmp2,(h-i)*w-tmp2)));
        tmp3 = w*((h-i)/2);
        chmin(ans,max(tmp,max(tmp3,w*(h-i)-tmp3)) - min(tmp,min(tmp3,w*(h-i)-tmp3)));
    }
    swap(h,w);
    rep(i,h){
        if(i==0)continue;
        tmp = i * w;
        tmp2 =  (w/2)*(h-i);
        chmin(ans,max(tmp,max(tmp2,(h-i)*w-tmp2)) - min(tmp,min(tmp2,(h-i)*w-tmp2)));
        tmp3 = w*((h-i)/2);
        chmin(ans,max(tmp,max(tmp3,w*(h-i)-tmp3)) - min(tmp,min(tmp3,w*(h-i)-tmp3)));
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 256
s = input();n = len(s)
dp = [[0 for i in range(4)] for j in range(len(s)+1)]
dp[0][0] = 1;string = ["A","B","C"];num = 10**9+7
for i in range(n):
    for j in range(4):
        m = 0;b = 1
        if '?' == s[i]:b = 3
        if j == 0:
            if '?' == s[i]:dp[i+1][j] = (dp[i][j] * 3)%num
            else:dp[i+1][j] = (dp[i][j])%num
            continue
        if s[i] == string[j-1]or s[i] == '?':m = 1
        dp[i+1][j] = (m*dp[i][j-1] + b*dp[i][j])%num
print(dp[-1][3])

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

string to_string(string s) {
	return '"' + s + '"';
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#ifndef D
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

vector<long long> sz, p;

long long solve(int lvl, long long rem) {
	if (rem <= 1) {
		return 0;
	}
	--rem;
	long long ans = 0;
	if (sz[lvl - 1] <= rem) {
		rem -= sz[lvl - 1];
		ans += p[lvl - 1];
	} else {
		return solve(lvl - 1, rem);
	}
	if (rem == 0) {
		return ans;
	}
	++ans;
	--rem;
	if (rem == 0) {
		return ans;
	}
	if (sz[lvl - 1] <= rem) {
		rem -= sz[lvl - 1];
		ans += p[lvl - 1];
	} else {
		return ans + solve(lvl - 1, rem);
	}
	--rem;
	return ans;
}

void test_case() {
	int n;
	long long x;
	cin >> n >> x;
	sz.resize(n + 1);
	p.resize(n + 1);
	sz[0] = 1, p[0] = 1;
	for (int i = 1; i <= n; ++i) {
		sz[i] = 3 + 2 * sz[i - 1];
		p[i] = 1 + 2 * p[i - 1];
	}
	cout << solve(n, x) << "\n";
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	return 0;
}

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

int main() {
  int N,K;
  cin >>N>>K;
  long long ans;
  ans=0;
  vector<long long>a(N);
for(int i=0;i<N;i++){
  cin>>a[i];
}
  sort(a.begin(),a.end());
for(int i=0;i<N;i++){
 if(N-K>i){
   ans+=a[i];
 }
}
  

  cout <<ans<< endl;
}


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

int main() {
  int n;cin>>n;
  ll an[n];rep(i,n)cin>>an[i];
  sort(an, an+n);
  reverse(an, an+n);
  
  ll sum=an[0];
  rep(i,(n-1)/2){
    sum += an[i+1]*2;
    //cout<<an[i+1]<<endl;
  }
  if (n%2==1) {
    sum -= an[n/2];
    //cout<<an[n/2]<<endl;
  }
  cout<<sum;
}


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

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

int main() {
	long long N, M;
	string S, T;
	bool check = true;
	cin >> N >> M >> S >> T;
	long long G = gcd(N, M), L = N * M / G, Si = N / G, Ti = M / G;
	for (int i = 0; i < G; i++) {
		if (S[i * Si] != T[i * Ti]) check = false;
	}
	if (check) cout << L;
	else cout << -1;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
using namespace std;
 main()
{
    int a,b;
    cin>>a>>b;
    for(int i =1; i<=1e7; i++){
        double cura = ((double)i) *(0.08);
        double curb = ((double)i) *(0.1);
        if((int)cura == a && (int)curb == b)return cout<<i<<endl,0;

    }
    cout<<-1<<endl;

    return 0;
}


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


int main() {
  int64_t A,B;
  cin >> A >> B;
  //最小公倍数出力
  int64_t x=A*B;
  if(A<B){
    int64_t tmp = A;
    A=B;
    B=tmp;
  }
  int64_t r=A%B;
  while(r!=0){
    A=B;
    B=r;
    r=A%B;
  }
  cout << x/B << endl;
  
}

// int型の2次元配列(3×4要素の)の宣言
  //vector<vector<int>> data(3, vector<int>(4));

  // 入力 (2重ループを用いる)
  //for (int i = 0; i < 3; i++) {
    //for (int j = 0; j < 4; j++) {
      //cin >> data.at(i).at(j);
    //}
  //}

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

int a[100][100], b[100][100];
signed main() {
	int n, m, l; cin >> n >> m >> l;
	rep(i, n)rep(j, m)cin >> a[i][j];
	rep(i, m)rep(j, l)cin >> b[i][j];
	rep(i, n) {
		rep(j, l) {
			int sum = 0;
			rep(k, m)sum += a[i][k] * b[k][j];
			if (j)cout << ' ';
			cout << sum;
		}
		cout << endl;
	}
}

Measured memory_bytes: 3160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0510
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int[] lineA = ReadIntAr();
            int[] lineB = ReadIntAr();
            Console.WriteLine(Math.Max(lineA.Sum(),lineB.Sum()));
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
        static string WriteAr(int[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(double[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(long[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }

    }

}



Measured memory_bytes: 16248
#include <bits/stdc++.h>
#include <stdlib.h>
#define rep(i,l,r) for((i)=(l);(i)<(r);(i)++)
#define erep(i,l,r) for((i)=(l);(i)<=(r);(i)++)
#define drep(i,l,r) for((i)=(l);(i)>=(r);(i)--)
#define MOD 1000000007
#define ll long long
using namespace std;
int pa[200001];
int num[200001];
int main(){
    int n,m,a,b,p,x,i;
    cin>>n>>m;
    rep(i,1,n){ 
        cin>>a>>b;
        pa[b]=a;
    }
    rep(i,0,m){
        cin>>p>>x;
    	num[p]+=x;
	}
	erep(i,1,n){
		num[i]+=num[pa[i]];
		cout<<num[i]<<" ";
	}
  cout<<endl;
}

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

int H, W, K;
#define MAX_H 800
#define MAX_W 800
int SI, SJ;
bool U[MAX_H][MAX_W];
int DI[4] = {-1, 0, 1, 0};
int DJ[4] = {0, -1, 0, 1};
int R = INT_MAX;

int main() {
  cin >> H >> W >> K;
  for(int i = 0; i < H; ++i) for(int j = 0; j < W; ++j) {
    char c; cin >> c;
    U[i][j] = c != '.';
    if(c == 'S') { SI = i; SJ = j; }
  }
  queue<tuple<int, int, int>> q; q.push(make_tuple(SI, SJ, 0));
  while(!q.empty()) {
    auto t = q.front(); q.pop(); int i = get<0>(t), j = get<1>(t), d = get<2>(t);
    R = min({R, i, H - 1 - i, j, W - 1 - j});
    if(d == K) continue;
    for(int x = 0; x < 4; ++x) {
      int di = DI[x], dj = DJ[x];
      if(i + di < 0 || i + di >= H || j + dj < 0 || j + dj >= W) continue;
      if(U[i + di][j + dj]) continue;
      U[i + di][j + dj] = true; q.push(make_tuple(i + di, j + dj, d + 1));
    }
  }
  cout << 1 + (R + K - 1) / K << endl;
  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll s[25][25];
ll s1[25];
ll min1;
int n,m,x;
void dfs(int g,ll sum)
{
	int flag=1;
	for(int i=1;i<=m;i++)
	{
		if(s1[i]<x)
		{
			flag=0;
			break;
		}
	}
	if(flag)
	{
		min1=min(min1,sum);
	}
	if(g>=n)
	{
		return ;
	}
	dfs(g+1,sum);
	for(int i=1;i<=m;i++)
	{
		s1[i]+=s[g][i];
	}
	dfs(g+1,sum+s[g][0]);
	for(int i=1;i<=m;i++)
	{
		s1[i]-=s[g][i];
	}
	return ;
}
int main()
{
	min1=1000000000000000;
	cin>>n>>m>>x;
	for(int i=0;i<n;i++)
	{
		cin>>s[i][0];
		for(int j=1;j<=m;j++)
		{
			cin>>s[i][j];
		}
	}
	dfs(0,0);
	if(min1!=1000000000000000)
		cout<<min1<<endl;
	else
		cout<<-1<<endl;
	
	return 0;	
}

Measured memory_bytes: 3632
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] num_lst = new int[n];
    for (int i = 0; i < n; i++){
      num_lst[i] = sc.nextInt();
    }
    insertion_sort(num_lst, n);
  }

  public static void insertion_sort(int[] lst, int n){
    for (int i = 0; i < n; i++){
      int current = lst[i];
      int j = i - 1;
      while (j >= 0 && lst[j] > current){
        lst[j + 1] = lst[j];
        j --;
      }
      lst[j + 1] = current;
      show(lst, n);
    }
  }

  public static void show(int[] lst, int n){
    for (int i = 0; i < n; i++){
      if (i == n - 1){
        System.out.println(lst[i]);
      }else{
        System.out.print(lst[i] + " ");
      }
    }
  }
}



Measured memory_bytes: 30684
#include<iostream>
using namespace std;
int n,a[100001],x,ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(x>100000) ans++;
		else a[x]++;
	}
	for(int i=1;i<=100000;i++)
	{
		if(a[i]==0) continue;
		if(a[i]<i) ans+=a[i];
		else if(a[i]>i) ans+=a[i]-i;
	}
	cout<<ans;
	return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  sort(p.begin(),p.end());
  int sum = 0;
  rep(i,k) sum += p[i];
  cout << sum << endl;
}

Measured memory_bytes: 3632
package main

import (
	"fmt"
	"math"
)

func intMax(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

func main() {
	var N int
	fmt.Scan(&N)

	h := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&h[i])
	}

	ans := h[0]
	for i := 1; i < N; i++ {
		ans += intMax(h[i]-h[i-1], 0)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1780
#include <stdio.h>
int main()
{
  int a,b,c;
  int t;
  scanf("%d",&a); scanf("%d",&b); scanf("%d",&c);
  t=a;
  a=b;
  b=t;
  t=a;
  a=c;
  c=t;
  printf("%d ",a); printf("%d ",b); printf("%d ",c);
  return 0;
}

Measured memory_bytes: 1656
fun main (args : Array<String>) {
	val n = readLine()
	val l = readLine()!!.split(" ")
	var list : MutableList<Int> = mutableListOf()
	var result : Int = 0
	for (i in l) {
		list.add(i.toInt())
	}
	for (i in 0..list.size - 2) {
		for (j in i + 1..list.size - 1) {
			result += (list[i] * list[j])
		}
	}
	println("${result}")
}

Measured memory_bytes: 37816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll t;
    t=1;
    while(t--)
    {
        ll arr[3];
        for(int i=0;i<3;i++)
            cin>>arr[i];
        sort(arr,arr+3);
        if((arr[0]!=arr[2] && arr[0]==arr[1]) || (arr[1]==arr[2] && arr[1]!=arr[0]))
            cout<<"Yes";
        else
            cout<<"No";
    }
}


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


int main() {
    int n; cin >> n;
    vector<int> d(n);
    rep(i,n){
        cin >> d.at(i);
    }
    sort(d.begin(),d.end());
    int M=d.at(n/2);
    int m=d.at(n/2-1);
    if(M==m) cout << 0 ;
    else cout << M-m;

    cout << endl;
}

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

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

// chmax, chmin
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const string YES = "Yes";
const string NO = "No";

void solve(std::string S) {
    string t = "";
    while( t.size() < S.size() ){
        t += "hi";
    }
    if( t == S ) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main() {
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[10000];
for (int i=0;i<n;i++) cin >> a[i];
int mn=a[0], mx =a[0];
long long sum = 0;
for (int i=0;i<n;i++){
mn = min (mn,a[i]);
mx = max (mx,a[i]);
sum += a[i];
}
cout <<mn<<" "<<mx<<" "<<sum<<endl;
return 0;
}


Measured memory_bytes: 3120
x, y = map(int, input().split())

a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]

if x in a and y in a:
  print('Yes')
elif x in b and y in b:
  print('Yes')
elif x in c and y in c:
  print('Yes')
else:
  print('No')

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

int sum(int n){
	int ret = 0;
	while(n){
		ret += n % 10;
		n /= 10;
	}
	return ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int N;
	cin >> N;

	int ans = 1e9;
	for(int i = 1; i <= N - 1; i++){
		ans = min(ans, sum(i) + sum(N - i));
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
use proconio::{fastout, input};
use std::io::*;
use std::str::FromStr;

use std::cmp::{max, min};
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};

const MOD: i64 = 1_000_000_007;

fn main() {
    input! {
        n: usize,
    }
    if n < 2 {
        println!("0");
        return;
    }

    let mut dp: Vec<Vec<i64>> = vec![vec![0; 4]; n + 1];
    dp[0][0] = 1;

    // for  in 0..n {
    //     dfs(cn + 1, map, limit);

    // }
    let mut cnt = 1;
    loop {
        if cnt == n + 1 {
            break;
        }
        dfs(cnt, &mut dp);
        cnt += 1;
    }
    
    // println!("{:?}", dp);

    println!("{}", dp[n][3] % MOD);
}

fn dfs(cn: usize, map: &mut Vec<Vec<i64>>) {

    // not 0, and not 9
    map[cn][0] += map[cn-1][0] * 8;
    map[cn][0] %= MOD;
    map[cn][1] += map[cn-1][0];
    map[cn][1] %= MOD;
    map[cn][2] += map[cn-1][0];
    map[cn][2] %= MOD;

    // 0, and not 9
    map[cn][1] += map[cn-1][1] * 9;
    map[cn][1] %= MOD;
    map[cn][3] += map[cn-1][1];
    map[cn][3] %= MOD;

    // not 0, and 9
    map[cn][2] += map[cn-1][2] * 9;
    map[cn][2] %= MOD;
    map[cn][3] += map[cn-1][2];
    map[cn][3] %= MOD;

    // 0, and 9
    map[cn][3] += map[cn-1][3] * 10;
    map[cn][3] %= MOD;
}


Measured memory_bytes: 72240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
#define mp make_pair
#define pb push_back
#define debug(x) cerr << #x << " = " << x << " "

int main()
{
  int n;
  while (~scanf("%d", &n))
    {
      vector<int> v(n);
      map<int, int> ma;
      for (auto & e : v) scanf("%d", &e), ++ma[e];
      int diameter = ma.rbegin()->first;
      int mini = (diameter + 1) >> 1;
      bool ans = true;
      if (ma.begin()->first != mini || ma.size() != (diameter - mini + 1)) ans = false;
      else if ((diameter % 2 == 0) && ma[mini] != 1) ans = false;
      else if ((diameter % 2 == 1) && ma[mini] != 2) ans = false;
									    
      puts(ans?"Possible":"Impossible");
    }
}


Measured memory_bytes: 256
using System;

namespace CODE_FESTIVAL_2016_Grand_Final_Parallel__A___1D_Matching
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            long MOD = 1000000007;

            var computers = new int[N];
            for (int i = 0; i < N; i++) computers[i] = int.Parse(Console.ReadLine());
            Array.Sort(computers);

            var powers = new int[N];
            for (int i = 0; i < N; i++) powers[i] = int.Parse(Console.ReadLine());
            Array.Sort(powers);

            var isPower = new bool[2 * N];
            var p = 0; var c = 0;
            for (int i = 0; i < 2 * N; i++)
            {
                if (p == N)
                {
                    isPower[i] = false;
                    continue;
                }
                if (c == N)
                {
                    isPower[i] = true;
                    continue;
                }

                if (powers[p] < computers[c])
                {
                    isPower[i] = true;
                    p++;
                }
                else
                {
                    isPower[i] = false;
                    c++;
                }
            }

            long match = 1;
            var pow = 0; var comp = 0;
            for (int i = 0; i < 2 * N; i++)
            {
                if (isPower[i])
                {
                    if (pow < comp) match = match * (comp - pow) % MOD;
                    pow++;
                }
                else
                {
                    if (comp < pow) match = match * (pow - comp) % MOD;
                    comp++;
                }
            }
            Console.WriteLine(match);
        }
    }
}


Measured memory_bytes: 15960
#!/usr/bin/env python3
import bisect
import collections
import sys
import math

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62


def solve(A: int, B: int, H: int, M: int):
    m_deg = M / 60 * 2*math.pi
    h_deg = (H + M / 60) / 12 * 2*math.pi

    a_x, a_y = A * math.cos(h_deg), A * math.sin(h_deg)
    b_x, b_y = B * math.cos(m_deg), B * math.sin(m_deg)

    print(((a_x - b_x) ** 2 + (a_y - b_y) ** 2) ** 0.5)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(A, B, H, M)


if __name__ == '__main__':
    main()


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

int main() {
    int n;cin>>n;
    long long dp[n];
    for(int i=0;i<n;i++) dp[i]=1000000000000;
    int h[n];
    for(int i=0;i<n;i++) cin>>h[i];
    dp[0]=0;
    for(int i=1;i<n;i++){
        dp[i]=min(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
        if(i>1) dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;


int main(){
    long long int N; scanf("%llu",&N);
    long long int Q; scanf("%llu",&Q);
    vector<pair<ll,pair<ll,ll> > > vec;
    vector<ll> start(Q);
    set<ll> st;
    for(int i = 0; i<N;i++){
            ll s, t, x;
            scanf("%llu %llu %llu",&s,&t,&x);
            vec.push_back( {s-x,{1,x}} );
            vec.push_back( {t-x,{-1,x}});
    }

    for(int i = 0;i<Q;i++){
        ll temp;
        scanf("%llu",&temp);
        vec.push_back( {temp,{2,0}} );
    }
    vector<long long int> output(Q,-1);
    // bool ok = true;
    // pair<ll,pair<int,ll>> man;
    sort(vec.begin(),vec.end());

    // auto itr_lb = lower_bound(ALL(vec), vec.first);
    // for(auto itr = vec.begin();itr!=itr_lb;itr++){
    //     if(itr*.second.first==1)
    //         st.insert(*itr);
    //     else
    //         st.erase
    // }
    int man = 0;
    for(int i = 0;i<vec.size();i++){
        
        if(vec[i].second.first == 1 ){
            st.insert(vec[i].second.second);
        }
        else if(vec[i].second.first == -1){
            st.erase(vec[i].second.second);
        }
        else{
            if(*st.begin() != 0 ){
                output.at(man) = *st.begin();
            }
            man++;
        }
    }
    for(int i = 0;i < Q;i++){
        cout << output.at(i) << "\n";
    }
    return 0;
}

Measured memory_bytes: 29156
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int n;
ll dfs(vvl &dp, vvi &v, int i, int b) {
	if (i == n)return 1;
	if (dp[i][b] != -1)return dp[i][b];
	ll ret = 0;
	REP(j, n) {
		if (v[i][j] && ((1 << j)&b)) {
			ret += dfs(dp, v, i + 1, b ^ (1 << j));
			ret %= MOD;
		}
	}
	return dp[i][b] = ret;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> n;
	vvi v(n,vi(n));
	REP(i, n)REP(j, n)cin >> v[i][j];
	vvl dp(n, vl(1 << n, -1));

	dfs(dp, v, 0, (1 << n) - 1);
	cout << dp[0][(1 << n) - 1] << endl;
}

Measured memory_bytes: 360832
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

int main() {
    INIT;
    ll H, W;
    cin >> H >> W;
    ll h, w;
    cin >> h >> w;

    cout << H * W - (h * W + w * H) + h * w << endl;

    return 0;
}

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

int main(){
  int n,t,p,c=0;
  string s;
  cin>>n>>t;
  queue<pair<string,int> >a;
  while(n--){
    cin>>s>>p;
    a.push(make_pair(s,p));
  }
  while(!a.empty()){
    pair<string,int>b=a.front();
    a.pop();
    if(b.second<=t){
      c+=b.second;
      cout<<b.first<<' '<<c<<endl;
    }
    else{
      b.second-=t;
      c+=t;
      a.push(b);
    }
  }
}



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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<ll> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
//typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;



int main() {
    int n, k;
    cin >> n >> k;
    vector<int> prev(n);
    rep(i, n) cin >> prev[i];

    rep(_, k) {
        vector<int> next(n, 0);
        rep(j, n) {
            int d = prev[j];
            int l = max(j - d, 0);
            next[l]++;
            int r = j + d + 1;
            if (r < n) next[r]--;
        }
        rep(i, n - 1) next[i + 1] += next[i];

        if (next == prev) break;
        prev = next;
    }

    for (ll l : prev) cout << l << ' ';

}

Measured memory_bytes: 4844
#include <cstdio>

using namespace std;

int a[100010];

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


Measured memory_bytes: 512
a = input().split()
H = int(a[0])
W = int(a[1])
adj = int(0)
s = []
p = []

for k in range(H):
    m = input()
    for i in range(W):
        p.append(m[i])
    s.append(p)
    p = []

for i in range(W):
    i = i - adj
    temp = int(0)
    for k in range(H):
        if s[k][i] == "#":
            temp = 1
            break
        else:
            pass
    if temp == 0:
        for k in range(H):
            del s[k][i]
        adj += 1
    else:
        pass

W = W - adj
adj = 0

for i in range(H):
    i = i - adj
    temp = int(0)
    for k in range(W):
        if s[i][k] == "#":
            temp = 1
            break
        else:
            pass
    if temp == 0:
        del s[i]
        adj += 1
    else:
        pass

H = H - adj

for i in range(H):
    tinpo = ''.join(s[i])
    print(tinpo)

Measured memory_bytes: 9316
import java.io.BufferedReader;
import java.util.Scanner;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        int a,b,c,d,sum;
        Scanner sn=new Scanner(System.in);
        a=sn.nextInt();
        b=sn.nextInt();
        c=sn.nextInt();
        d=sn.nextInt();
        if(a<=b) sum=a;
        else sum=b;
        if(c<=d) sum+=c;
        else sum+=d;
        System.out.println(sum);
    }
}

Measured memory_bytes: 23764
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)
#define REP(i,n) for(long long i(0);(i)<(n);(i)++)
ll INF = 1LL << 60;

void solve(long long N, long long A, long long B, long long C, std::vector<long long> l){
    ll best = INF;
    REP(S, 1LL<<N){ //* loop on used items
        //* get item info
        vll items;
        REP(i, N){
            if(S>>i & 1)
                items.push_back(i);
        }
        if(items.size()==0){
            best = min(best,A+B+C);
            continue;
        }
        ll M = items.size();
        do{
            for(ll jA = 0; jA <= M; jA++){
                for(ll jB=jA; jB <= M; jB++){
                    ll mA=0, mB=0, mC=0;
                    ll tmp = 10*(max(0LL, jA-1)+max(0LL, jB-jA-1)+max(0LL, M-jB-1));
                    //* [0, jA), [jA, jB), [jB, M)
                    for(ll k=0; k< jA; k++){
                        mA += l[items[k]];
                    }
                    for(ll k=jA; k< jB; k++){
                        mB += l[items[k]];
                    }
                    for(ll k=jB; k< M; k++){
                        mC += l[items[k]];
                    }
                    if(mA == 0 || mB ==0 || mC == 0)
                        continue;
                    tmp += abs(mA-A)+abs(mB-B)+abs(mC-C);
                    best = min(best, tmp);
                }
            }
        }while(next_permutation(items.begin(), items.end()));
    }
    cout << best << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    std::vector<long long> l(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&l[i]);
    }
    solve(N, A, B, C, std::move(l));
    return 0;
}


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

int main(){
  int A, B, C, X;
  cin >> A;
  cin >> B;
  cin >> C;
  cin >> X;
  int count = 0;
  for(int i=0; X-i*500>=0 && i<=A; i++){
    for(int j=0; X-i*500-j*100>=0 && j<=B; j++){
      if(X-i*500-j*100-C*50<=0){
        count += 1;
      }
    }
  }  
  cout << count;
}

Measured memory_bytes: 256
s[50],j,p,q;main(i){for(;j=i=atoi(gets(s));printf("%d\n",i)){for(;i;s[j-i--]=strlen(gets(s+j)));for(;j;)for(p=i++,j=q=6;q>0;)for(q=6842496>>--j*4&15;q>1;)q-=s[p++];}}

Measured memory_bytes: 532
K = int(input())

ai =0
ans = 0
# i = 1
l = set()

if K %2 == 0:
    ans = -1
else:
    for i in range(K):
        ai = (ai * 10 + 7) % K
        if ai == 0:
            ans = i+1
            break
        else:
            if ai in l:
                ans = -1
                break
            else:
                l.add(ai)
print(ans)

Measured memory_bytes: 78004