akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ull MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
ll digitPoor(ll n)
{
    assert(INT_MAX == 2147483647);
    assert(n >= 0);

    if (n < 10)         return 1;
    if (n < 100)        return 2;
    if (n < 1000)       return 3;
    if (n < 10000)      return 4;
    if (n < 100000)     return 5;
    if (n < 1000000)    return 6;
    if (n < 10000000)   return 7;
    if (n < 100000000)  return 8;
    if (n < 1000000000) return 9;
    return 10;
}
int main(){
    string S;
    cin>>S;
    
    cout<<S[0]<<S[1]<<S[2];
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
    int k,t;
    cin >> k >> t;
    vector<int> l(t);
    for ( auto &i:l ){cin >> i;}
    sort(l.begin(),l.end(),greater<int>());
    int a=0,b=0;
    for ( auto i:l ){
        if (a <= b) {a+=i;}
        else {b+=i;}
    }
    cout << max(0,max(a,b) - min(a,b) - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
h,w,n = list(map(int,input().split()))
sr,sc = list(map(int,input().split()))
s = input()
t = input()
kijyun = "LRUD"
ruisekiS = [{v:0 for v in kijyun} for i in range(n+1)]
ruisekiT = [{v:0 for v in kijyun} for i in range(n+1)]

for i in range(n):
    for c in kijyun:
        if s[i] == c:
            ruisekiS[i+1][c] = ruisekiS[i][c] + 1
        else:
            ruisekiS[i+1][c] = ruisekiS[i][c]
        if t[i] == c:
            ruisekiT[i+1][c] = ruisekiT[i][c] + 1
        else:
            ruisekiT[i+1][c] = ruisekiT[i][c]
kyori = {"L":sc,"R":w-sc+1,"U":sr,"D":h-sr+1}
gyaku = {"L":"R","R":"L","U":"D","D":"U"}

check = 0
for i in range(n):
    for c in kijyun:
        if s[i] == c:
            ruisekiS[i+1][c] = ruisekiS[i][c] + 1
        else:
            ruisekiS[i+1][c] = ruisekiS[i][c]
        if t[i] == c and (ruisekiT[i][c] + 1 - ruisekiS[i][gyaku[c]]) < kyori[c] :
            ruisekiT[i+1][c] = ruisekiT[i][c] + 1
        else:
            ruisekiT[i+1][c] = ruisekiT[i][c]
    if ruisekiS[i+1]["L"] - ruisekiT[i]["R"] >= kyori["L"]:
        check = 1
    if ruisekiS[i+1]["R"] - ruisekiT[i]["L"] >= kyori["R"]:
        check = 1
    if ruisekiS[i+1]["U"] - ruisekiT[i]["D"] >= kyori["U"]:
        check = 1
    if ruisekiS[i+1]["D"] - ruisekiT[i]["U"] >= kyori["D"]:
        check = 1
#print(ruisekiS)
#print(ruisekiT)
if check == 0:
    print('YES')
else:
    print('NO')
    


Measured memory_bytes: 196404
#include<bits/stdc++.h>
using namespace std;
 
void dot_to_minenumber(vector<string>& map);
 
int main(){
  //入力
  int H, W;
  cin >> H >> W;
  vector<string> map(H);
  for ( int i = 0; i < map.size() ; i++) cin >> map.at(i);
  
  //処理
  dot_to_minenumber(map);
  
  //出力
  for ( string x : map ) cout << x << endl;
}
 
void dot_to_minenumber(vector<string>& map){
  vector<int> row = { -1 , 0 , 1};
  vector<int> column = { -1 , 0 , 1};//ある点の周辺を調べる用
  for ( int i = 0 ; i < map.size(); i++){
    for ( int j = 0 ; j < map.at(0).size(); j++){//マップの全探索
      if ( map.at(i).at(j) == '.'){//その点が地雷ではないとき
        int count = 0;
      	for ( int x : row ){
       	 for ( int y : column){
          	if (0 <= (i + x) && (i + x) < map.size() && 
                0 <= (j + y) && (j + y ) < map.at(0).size() &&
                map.at(i + x).at(j + y) == '#' ) count++;//その点回りに文字が存在し、かつ地雷ならcount++
                   map.at(i).at(j) = '0' + count;//(1)よく知らないけどこれでintをcharで代入できる
       	 }
      	}
        /*(1)の代わりにこれでも代入できる
        string s = to_string(count);
        map.at(i).at(j) = s.at(0);
        */
      }//if文終了
    }
  }//ループ終了
}

Measured memory_bytes: 256
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
using namespace std;
#define fastestiointhewest   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll          long long
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define mii         map<int,int>
#define vi          vector<int>
#define vll         vector<long long>
#define all(a)      (a).begin(),(a).end()
#define clz(a)      __builtin_clz(a) // count leading zeroes
#define ctz(a)      __builtin_ctz(a) // count trailing zeroes
#define popc(a)     __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define SIZE        1000005
#define F           first
#define S           second
#define debug(x)    cerr << #x << " = " << x << endl;
#define mod         998244353

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define endl        '\n'
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;

void solve()
{
   int a,b,c,d,e,k; cin>>a>>b>>c>>d>>e>>k;
   if((e-a)>k) cout<<":(";
   else cout<<"Yay!";
} 
int main()
{   
    fastestiointhewest;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    while(t--){
       solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<string> S(N);
  string tmp;
  int counter1 = 0;
  int counter2 = 0;
  int counter3 = 0;
  int counter4 = 0;
  for(int i =0;i < N;i++){
    cin >> S.at(i);
    if(S.at(i).back() == 'A'){
      counter2 ++;
      if(S.at(i).front() == 'B'){
	counter4 ++;
      }
    }
    if(S.at(i).front() == 'B'){
      counter3 ++;
    }

  }

  for(int i = 0;i < N; i ++){
    tmp = S.at(i);
    for(int j = 0; j < tmp.size() - 1; j ++){
      if(tmp.at(j) == 'A'&&tmp.at(j + 1) == 'B'){
	counter1 ++;
      }
    }
  }
  if(counter2 == counter3 && counter3 == counter4 && counter2 > 0){
    cout << counter1 + counter2 - 1<< endl;
  }else{
    cout << counter1 + min(counter2, counter3)<< endl;
  }
}


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

// 入力
int N;
pair<int, string> S[1 << 18];

// Trie 木
int M;
int nex[1 << 21][26];
int val[1 << 21][26];

int add(string str) {
	int cx = 0, ret = 0, v[26];
	for (int i = 0; i < 26; i++) v[i] = (1 << 30);
	for (int i = (int)str.size() - 1; i >= 0; i--) v[str[i] - 'a'] = i;

	for (int i = (int)str.size() - 1; i >= 0; i--) {
		if (nex[cx][str[i] - 'a'] == -1) { nex[cx][str[i] - 'a'] = M; M++; }
		for (int j = 0; j < 26; j++) {
			if (v[j] <= i) val[cx][j] += 1;
		}
		if (i == 0) ret = cx;
		cx = nex[cx][str[i] - 'a'];
	}
	return ret;
}

int main() {
	// Step #1. 入力
	cin >> N;
	for (int i = 1; i <= N; i++) {
		string T; cin >> T;
		S[i] = make_pair(T.size(), T);
	}
	sort(S + 1, S + N + 1);
	reverse(S + 1, S + N + 1);

	// Step #2. Trie の構築
	M = 1;
	for (int i = 0; i < (1 << 21); i++) {
		for (int j = 0; j < 26; j++) nex[i][j] = -1;
	}

	// Step #3. 計算
	long long Answer = 0;
	for (int i = 1; i <= N; i++) {
		int pos = add(S[i].second);
		Answer += 1LL * (val[pos][S[i].second[0] - 'a'] - 1LL);
	}
	cout << Answer << endl;
	return 0;
}

Measured memory_bytes: 329228
#include<bits/stdc++.h>
#define ll long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define fo(i, x, y)   for (__typeof(x) i = x; i < y; ++i)
#define fr(i, x, y)   for (__typeof(x) i = x; i > y; i--)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define first F
#define second S
#define vdp(n,x) vector<vector<ll>>dp(n+1,vector<ll>(x+1));
const ll mod=1000000007;
const ll AM=2e5+5;
using namespace std;
int main()
{
	ll k,a,b; cin>>k>>a>>b;
	ll q=a/k,w=b/k;
	q++;
	if(a%k==0 || b%k==0 || q*k<=b )
		cout<<"OK";
	else cout<<"NG";
	
}

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

#define int long long
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
#define rep(i,a,n) for(int i=a; i<n; i++)
#define endl "\n"
#define E "\n"
#define show(arr) REP(i,arr.size()){cout<<arr[i]<<" ";}
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;
const int MAX = 1e18;

#define N 5010

int sum(int x){
    int s=0;
    while(x>0){
        s+=x%10;
        x/=10;
    }
    return s;
}

void solve()
{
    int n,a,b;
    cin>>n>>a>>b;
    int x = (n-2)*b+(2-n)*a+1;
    if (x<0) x=0;
    cout<<x;
}

signed main()
{
    int t=1;
    //cin>>t;
    WL(t)solve();

    return 0;
}




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

int main()
{
	int N, K;
	cin >> N >> K;
	long ans;
	if (K % 2 == 1) {
		long a = N / K;
		ans = a * a * a ;
	}
	else {
		long a = N / K;
          	long b = (N+K/2) / K ;
		ans = a * a * a+ b * b * b ;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;


int N, Q;
vector< int > g[100000];
vector< int > query[100001];
int sz[100000];

int lca[100000];
bool buf[100000];

int sub(int idx)
{
  sz[idx] = 1;
  for(auto &to : g[idx]) sz[idx] += sub(to);
  return (sz[idx]);
}

void dfs(int idx, bool keep)
{
  if(g[idx].empty()) {
    if(keep) for(int &v : query[idx]) buf[v] = true;
    return;
  }

  int heavy = g[idx][0];
  for(auto &to : g[idx]) if(sz[to] > sz[heavy]) heavy = to;
  for(auto &to : g[idx]) if(heavy != to) dfs(to, false);
  dfs(heavy, true);
  query[idx].swap(query[heavy]);

  for(auto &to : g[idx]) {
    for(int &v : query[to]) {
      if(buf[v]) lca[v] = idx;
    }
    for(int &v : query[to]) {
      if(~lca[v]) continue;
      buf[v] = true;
      query[idx].push_back(v);
    }
  }

  if(!keep) {
    for(auto &v : query[idx]) buf[v] = false;
  }
}

int main()
{
  scanf("%d", &N);
  for(int i = 0; i < N; i++) {
    int K;
    scanf("%d", &K);
    while(K--) {
      int U;
      scanf("%d", &U);
      g[i].push_back(U);
    }
  }
  scanf("%d", &Q);

  memset(lca, -1, sizeof(lca));

  for(int i = 0; i < Q; i++) {
    int U, V;
    scanf("%d %d", &U, &V);
    if(U == V) {
      lca[i] = V;
    } else {
      query[U].push_back(i);
      query[V].push_back(i);
    }
  }

  sub(0);
  dfs(0, false);
  for(int i = 0; i < Q; i++) {
    printf("%d\n", lca[i]);
  }
}

Measured memory_bytes: 25292
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
#define pb push_back
#define INF 1e5
#define REP(i,a,b) for(int i=a;i<b;++i)
#define REPN(i,a,b) for(int i=a;i<=b;++i)

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    
    int n;
    cin>>n;
    int A[n];
	REP(i,0,n) cin>>A[i];
	REP(i,0,n)
	{
		if(A[i]%2==0)
		{
			if(A[i]%3==0 || A[i]%5==0)
			continue;
			else
			{
				cout<<"DENIED\n";
				return 0;
			}
		}
	}
	cout<<"APPROVED\n";
	    
	return 0;
    
}


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

int main() {
  bool Ans=-1;
  //int A; cin >>A;
  //int B; cin >>B;
  string S; cin >> S;
  //cout << Ans << '\n';
  sort(S.begin(),S.end());
  Ans = (S == "abc")? true : false ;
  cout << (Ans==true ? "Yes" : "No" ) << "\n";
  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b,c;
  /*cin>>a>>b>>c;
  if(a>b) cout<<"NO"<<'\n';
  else if(a+b>=c) cout<<"YES"<<'\n';
  else cout<<"NO"<<'\n';*/
  cin>>a>>b>>c;
  cout<<a*b/2<<'\n';
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = []
for n in range(N):
  A.append(int(input()))

A_no1 = max(A)
Index_A_no1 = [i for i, x in enumerate(A) if x == A_no1]

if len(Index_A_no1) > 1:
  for n in range(N):
    print(A_no1)

else:
  AA = [a for a in A if a != A_no1]
  A_no2 = max(AA)
  Index_A_no1 = [i for i, x in enumerate(A) if x == A_no1]
  
  for n in range(N):
    if n in Index_A_no1:
      print(A_no2)
    else:
      print(A_no1)

Measured memory_bytes: 20456
#include<bits/stdc++.h>
typedef int LL;
typedef double dl;
#define opt operator
#define pb push_back
const LL maxn=1e6+9,mod=998244353;
LL Read(){
	LL x(0),f(1); char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') f=-1; c=getchar();
	}
	while(c>='0' && c<='9'){
		x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar();
	}return x*f;
}
char s[maxn],t[maxn];
int main(){
    scanf(" %s",s+1);
    scanf(" %s",t+1);
    LL n=strlen(s+1),ans(0);
    for(LL i=1;i<=n;++i) ans+=(s[i]!=t[i]);
    printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 4200
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include <ctime>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x,y) (((x)+(y)-1)/(y))
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; }
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	int N;
	cin >> N;
	vector<int>A(N);
	rep(i, N)cin >> A[i];
	int ans = 0;
	for (int i = 1; i < N; i++) {
		if (A[i - 1] < A[i])continue;
		ans += A[i - 1] - A[i];
		A[i] = A[i - 1];
	}
	cout << ans;
}

Measured memory_bytes: 4764
# 2019/07/07
# AtCoder Beginner Contest 133 - C

# Input
l, r = map(int,input().split())

# Calc
wans = 10 ** 10
for i in range(l, r):
    for j in range(i+1, r+1):
        wans = min(i * j % 2019, wans)
        if wans == 0:
            break
    if wans == 0:
        break
ans = wans

# Output
print(ans)


Measured memory_bytes: 2940
#แบ่งครึ่งข้อมูลในการ search
n=int(input())
s=list(map(int,input().split()))
q=int(input())
count=0
t=list(map(int,input().split()))
for i in range(q):
	l=0
	r=n
	while r>l:
                #แบ่งข้อมูลตรงกลาง
		mid=(l+r)//2
		#ถ้ามีข้อมูลตัวนั้นในลิสข้อมูล count +=1
		if s[mid]==t[i]: 
			count+=1
			break
		#ขยับไปตัวซ้ายถัดไป
		elif s[mid]>t[i]:
			r=mid
                #ขยับไปตัวขวาถัดไป			
		else:
			l=mid+1
print(count)



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

class solution{
private:
    string S,T;
public:
    solution(string s, string t){
        S=s;
        T=t;
    }
    int changeSub(){
        int ans=INT_MAX;
        for(int i=0; i<S.size()-T.size()+1; ++i){
            int temp=0;
            for(int j=0; j<T.size(); ++j){
                if(S[i+j]!=T[j]) ++temp;
            }
            ans = min(ans,temp);
        }
        return ans;
    }
};

int main(){
    string S,T;
    cin>>S>>T;
    solution solve(S,T);
    int ans = solve.changeSub();
    cout<<ans<<'\n';
}

Measured memory_bytes: 3588
L, R = map(int, input().split())

if R-L >= 2019:
    print(0)
else:
    L, R = L%2019, R%2019
    if L > R:
        R += 2019
    ans = 2019
    for i in range(L, R+1):
        for j in range(i+1, R+1):
            ans = min(ans, i*j%2019)
    print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;


int main() {
    int a,b;
    cin >> a >> b;
    int c=a/0.08,d=b/0.1;
    int m=min(c,d);
    int flag=-1;
    repr(i,m,m+100) {
        // cout << int(i*0.08) << " " << int(i*0.1) << endl;
        if (int(i*0.08)==a && int(i*0.1)==b) {
            flag=i;
            break;
        }
    }
    cout << flag << endl;
}

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

#define    ll     long long int

const int N = 2004;
ll ans[N];
int n;

void make(int x, int sign)
{
    int i;
    for (i = 1; i < x; i++) {
        ans[i] += sign * (x - i);
    }
}

int main( )
{
    int x, y;
    cin >> n >> x >> y;
    int i, j, k;
    int n1 = (x - 1) + (n - y) + 2;
    make(n1, +1);
    for (i = y - 1; i > x; i--) {
        for (j = x; j >= 1; j--) {
            k = min(abs(i - j), (x - j + 1) + (y - i));
            ans[k]++;
            //cout << i << ' ' << j << ' ' << k << '\n';
        }
        for (j = y; j <= n; j++) {
            k = min(abs(i - j), j - y + 1 + (i - x));
            ans[k]++;
            //cout << i << ' ' << j << ' ' << k << '\n';
        }
        for (j = i - 1; j > x; j--) {
            k = min(abs(i - j), j - x + y - i + 1);
            ans[k]++;
        }
    }
    for (i = 1; i < n; i++) {
        cout << ans[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())

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

# plus -> minus -> plus ...
p = 0
now = 0
for i in range(N):
    if  i % 2 == 0:
        if now + a[i] >= 1:
            now += a[i]
        else:
            p += 1 - (now + a[i])
            now = 1
    else:
        if now + a[i] <= -1:
            now += a[i]
        else:
            p += 1 + (now + a[i])
            now = -1

# minus -> plus -> minus ...
m = 0
now = 0
for i in range(N):
    if  i % 2 == 0:
        if now + a[i] <= -1:
            now += a[i]
        else:
            m += 1 + (now + a[i])
            now = -1
    else:
        if now + a[i] >= 1:
            now += a[i]
        else:
            m += 1 - (now + a[i])
            now = 1

print(min(p,m))


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

using namespace std;

int main() {
  int n;
  cin >> n;
  
  vector<int> l(2*n);
  for (auto&& ll : l) {
    cin >> ll;
  }
  
  sort(l.begin(), l.end());
  
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += l[2 * i];
  }
  
  cout << ans << endl;

  return 0;
}

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

int main()
{
    string S; 
    cin >> S;
    if(S == "Sunny") cout << "Cloudy" << endl;
    if(S == "Cloudy") cout << "Rainy" << endl;
    if(S == "Rainy") cout << "Sunny" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int A, B, C;
  cin >> A >> B >> C;
  int result;
  if(B <= A && C <= A){
    cout << (10 * A + B + C) << endl;
    return 0;
    
  }
  if(A <= B && C <= B){
    cout << (10 * B + C + A) << endl;
    return 0;
    
  }
  cout << (10 * C + A + B) << endl;
  return 0;
}

Measured memory_bytes: 256
m=6**8
c=[0]*m
n,a=open(0)
for a in a.split():c[int(a)]+=1
print(('not','psaeitr'[any(c:=[max(0,sum(c[i::i])-1)for i in range(2,m)])::2]+'wise')[max(c)+1<int(n)],'coprime')

Measured memory_bytes: 101160
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

typedef long long ll, lint;
typedef long double ldouble;

#define sz(v) ((int) (v).size())
#define FOR(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define For(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()

#define mp make_pair
#define pb push_back
#define fst first
#define snd second

template<class T>
string to_string(T arr, int len = 1e9) {
    stringstream ss;
    int i = 0;
    for (auto item : arr) {
        ss << item << ' ';
        if (++i == len)
            break;
    }
    return ss.str();
}

#ifdef LOCAL
    #define dbg(expr) cout << "[line " << __LINE__ << "] " << (#expr) << ": " << (expr) << endl;
#else
    #define dbg(expr) (void) 0;
#endif


int main() {
#ifndef LOCAL
    cin.tie(0);
    ios_base::sync_with_stdio(false);
#endif

    string s;
    cin >> s;
    int n = s.length();
    if (s[0] == '0' || s[n - 1] == '1') {
        cout << -1 << endl;
        return 0;
    }
    For (i, n - 1) {
        if (s[i] != s[n - i - 2]) {
            cout << -1 << endl;
            return 0;
        }
    }
    int q = 1;
    int cur = 0;
    for (int i = 1; i < n - 1; i++) {
        if (s[i] == '0')
            continue;
        int nxt = q++;
        cout << cur + 1 << ' ' << nxt + 1 << endl;
        cur = nxt;
        while (q < i + 1)
            cout << cur + 1 << ' ' << ++q << endl;
    }
    int nxt = q++;
    cout << cur + 1 << ' ' << nxt + 1 << endl;
    cur = nxt;
    while (q < n)
        cout << cur + 1 << ' ' << ++q << endl;
}


Measured memory_bytes: 1616
//list index out of rangeエラー表示用
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep1(i, n) for (int i = 0; i < (int)(n); i++)


int main(){
  int n;
  cin >> n;
  long long ans = 0;
  vector<int> A(n);
  rep1(i, n){
    cin >> A[i];
  }
  int tem = A[0];
  rep1(i, n){
    if(tem < A[i]){
      tem = A[i];
    }
    else{
      ans += tem - A[i];
    }
  }
  cout << ans;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second


int n,m,x;
vector<vector<int>> a;
vector<int> c;



int main(int argc, char const *argv[]) {
    cin >> n >> m >> x; // n 本の数　m アルゴリズムの数　x 目標のスキル
    a.resize(n); c.resize(n);

    REP(i,n) {
        cin >> c[i];
        REP(j,m) {
            int temp;
            cin >> temp;
            a[i].PB(temp);
        }
    }

    ll ans = INF;
    REP(i, pow(2,n)) { //　本の組み合わせをbitシフトで計算
        ll temp[m] = {0};
        ll temp_money = 0;
        REP(j,n) { // j番目の本を買うか買わないかを判定
            if (i & (1<<j)) {
                REP(k,m) temp[k] += a[j][k];
                temp_money+= c[j];
            }
        }
        // cout << "temp ";
        // REP(i,m) cout << temp[i] << " ";
        // cout << temp_money << "\n";
        
        bool flag = true;
        REP(i,m) {
            if (temp[i] < x) {
                // cout << "here " << temp[i] << "\n";
                flag = false;
            }
        }
        if (flag && ans > temp_money) ans = temp_money;
    }
    
    if (ans != INF ) cout << ans << "\n";
    else cout << -1 << "\n";

    return 0;
}


Measured memory_bytes: 4108
package main

import (
  "fmt"
)

func main() {
  var s string
  fmt.Scan(&s)
  res := make(map[rune]int)
  for _, c := range s {
    res[c]++
  }
  ans := "Yes"
  if len(res) == 1 {
    ans = "No"
  }
  fmt.Println(ans)
}

Measured memory_bytes: 512
my $s = <STDIN>;
my @dat =  split(/ /,$s);

my $A = $dat[0];
my $B = $dat[1];
my $M = int($A/2);
my $N = int($B/2);

if($A==1){ print "1"; exit}
if($B==1){ print "1"; exit}

if( ($B%2)==0){
  $ans = $N * $A;
}else{
  if( ($A%2)==0){
    $ans = ($M * ($N+1)) + ($M * $N);
  }else{
    $ans = ($M * $N) + (($M+1) * ($N+1));
  }
}

print "$ans";

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a;
  a="keyence";
  int j=0;
  string s;
  cin >> s;
  bool eee=false;
  for (int i=0;i<=7;i++){
   if(s.substr(0,7-i)+s.substr(s.size()-i,i)=="keyence")eee=true;
  }
  if (eee==true)cout <<"YES"<<endl;
  else cout <<"NO"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	string a, b;
  	cin>> a;
  	cin>> b;
  	
  	int counter = 0;
  	for(int i = 0; i < a.length(); i++){
    	if(a[i] != b[i])
          	counter++;
    }
  
  	cout<< counter;
}

Measured memory_bytes: 3916
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include<sstream>
using namespace std;

int abs(int a, int b) {
	return (a > b ? a - b : b - a);
}

int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	vector<int> v(3);
	for (int i = 0; i < 3; i++) {
		v[i] = abs(a[i % 3], a[(i + 1) % 3]);
	}
	sort(v.begin(), v.end());
	cout << v[0] + v[1] << endl;

	return 0;
}

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

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

    int K[35];
    int A[35][35];
    for (int i = 0; i < N; i++) {
        cin >> K[i];
        for (int j = 0; j < K[i]; j++) {
            cin >> A[i][j];
        }
    }

    int fav[35] = {0}; //好きと答えた人数を格納する配列
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < K[i]; j++) {
            fav[A[i][j]]++;
        }
    }

    int ans; //答え
    for (int i = 1; i <= M; i++) {
        if (fav[i] == N) ans++;
    }

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

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

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

// N, E, S, W
const int dx[4] = { 1, 0, -1, 0};
const int dy[4] = { 0, 1, 0, -1};

using LL = long long int;
using LD = long double;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;

//==============================================

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

	int v, e;
	cin >> v >> e;

	vvi G(v);
	vi indeg(v);
	REP(i, e) {
		int s, t;
		cin >> s >> t;

		G[s].push_back(t);
		indeg[t]++;
	}


	vi ans;
	queue<int> q;
	REP(i, v) {
		if (indeg[i] == 0) q.push(i);
	}

	while (!q.empty()) {
		int u = q.front(); q.pop();

		ans.push_back(u);

		for (int v : G[u]) {
			indeg[v]--;

			if (indeg[v] == 0) q.push(v);
		}
	}

	for (int a : ans) cout << a << endl;
	return 0;
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

// constexpr int INF = 1e9;
// constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

int H, W;
vector<int> cnt(26, 0), block(4, 0);
int main(){
  cin >> H >> W;
  vector<string> a(H);
  REP(i, H){
    cin >> a[i];
    REP(j, W){
      cnt[a[i][j]-'a']++;
    }
  }
  sort(cnt.begin(), cnt.end());
  REP(i, (H+1)/2){
    REP(j, (W+1)/2){
      int r = 1;
      if((i+1)*2 <= H){
        r*=2;
      }
      if((j+1)*2 <= W){
        r*=2;
      }
      block[r-1]++;
    }
  }
  REPR(i, 25){
    REPR(j, 3){
      int diff = cnt[i] / (j+1);
      int sa = min(diff, block[j]);
      cnt[i] -= sa*(j+1);
      block[j] -= sa;
    }
  }
  REP(i, 4){
    if(block[i]){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 3656
#75=3*5*5 
n=int(input())
a=[0]*100
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct
for i in range(n):
	for j in range(len(factorize(i+1))):
		a[factorize(i+1)[j]]+=1
def comb(a,b):
	p=1
	for i in range(b):
		p*=a-i
	for j in range(b):
		p//=j+1
	return p
cnt_74=cnt_24=cnt_14=cnt_4=cnt_2=0
for i in range(100):
	if a[i]>=74:
		cnt_74+=1
	elif a[i]>=24:
		cnt_24+=1
	elif a[i]>=14:
		cnt_14+=1
	elif a[i]>=4:
		cnt_4+=1
	elif a[i]>=2:
		cnt_2+=1
cnt_24+=cnt_74
cnt_14+=cnt_24
cnt_4+=cnt_14
cnt_2+=cnt_4
ans=0
#3*5*5
ans+=max(comb(cnt_4,2)*(cnt_2-2),0)
#3*25
ans+=(cnt_24)*(cnt_2-1)
#5*15
ans+=(cnt_4-1)*cnt_14
#75
ans+=cnt_74
print(ans)


Measured memory_bytes: 3064
n=int(input())
a=list(map(int,input().split()))

for i in range(n):
    if a[i]%2==1:
        if i==n-1:
            print("APPROVED")        
        else:
            continue
    if a[i]%2==0:
        if a[i]%3==0 or a[i]%5==0:
            if i==n-1:
                print("APPROVED")
            else:
                continue
        else:
            print("DENIED")
            break


Measured memory_bytes: 38444
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    string c[2];
    cin >> c[0] >> c[1];
    bool ok = true;
    int n = 3;
    for (int i = 0; i < n; i++){
        if (c[0][i] != c[1][n-1-i]){
            ok = false;
        }
    }
    if (ok){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2008;
int read(){
    int f=1,g=0;char ch=getchar();
    for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
    for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
    return f*g;
}
int n;
int main(){
	n=read();
	if (n==(n&(-n))){puts("No");return 0;}
	puts("Yes");
	printf("%d %d\n",n+1,n+2);
	printf("%d %d\n",n+2,3);
	printf("%d %d\n",3,1);
	printf("%d %d\n",1,2);
	printf("%d %d\n",2,n+3);
	for (int i=4;i<n;i+=2){
		printf("%d %d\n",i,1);
		printf("%d %d\n",i,n+i+1);
		printf("%d %d\n",i+1,1);
		printf("%d %d\n",n+i,i+1);
	}
	if (!(n&1))
	for (int i=2;i<n;i++){
		int j=n^1^i;
		if ((j>1)&&(j<n)){
			printf("%d %d\n",i,n);
			printf("%d %d\n",j,n+n);
			return 0;
		}
	}
	return 0;
}


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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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; }
template<class T>
T GCD(T a, T b) {if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }
template<class T>
inline T upper(T a, T b) {return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int a[51][26];

int main() {
	char a, b;
	cin >> a >> b;

	if (a == 'H' && b == 'H') cout << "H" << endl;
	else if (a == 'D' && b == 'H') cout << "D" << endl;
	else if (a == 'D' && b == 'D') cout << "H" << endl;
	else cout << "D" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n, a[], key = -1;
		
		n = sc.nextInt();
		
		a = new int[n + 1];
		
		for(int i = 1; i < n + 1; ++i) {
			a[i] = sc.nextInt();
			if(a[i] == 2)key = i;
		}
		sc.close();
		
		int ans = -1;
		
		boolean light[];
		light = new boolean[n + 1];//have already lighted
		
		if(key == 1) {
			ans = 1;
		}
		else if(key != -1) {
			ans = 0;
			int b = 1;//first light == 1
			light[1] = true;
			
			while(true) {
				b = a[b];//push button No.b & present light == b
				++ans;//counting
				
				if(b == 2) break;//present light == 2
				if(light[b]) {
					ans = -1;
					break;
				}
				light[b] = true;
			}
			
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 51960
S = input()


while True:
    if len(S) == 0:
        print('YES')
        break
    else:
        # if S[-5:]=='dream':
        if S.endswith('dream'):
            S = S[:-5]
        # elif S[-7:] == 'dreamer':
        elif S.endswith('dreamer'):
            S = S[:-7]
        # elif S[-5:]== 'erase':
        elif S.endswith('erase'):
            S = S[:-5]
        # elif S[-6:] == 'eraser':
        elif S.endswith('eraser'):
            S = S[:-6]
        else:
            print('NO')
            break

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;
ll k;

bool subok(ll a, ll b, ll c, ll y){
  if (y == k){
    if (a < b && b < c){
      return true;
    }

    return false;
  }

  bool d = subok(2*a, b, c, y+1);
  bool e = subok(a, 2*b, c, y+1);
  bool f = subok(a, b, 2*c, y+1);

  return d || e || f;
}

bool ok(ll a, ll b, ll c){
  return subok(a, b, c, 0);
}

int main(void){
  ll a, b, c;
  cin >> a >> b >> c;
  cin >> k;
  
  
  
  if (ok(a, b, c))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
    

  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  ll k;
  cin >> s >> k;
  ll n = s.size();
  ll dp[n + 1][k + 2][2] = {};
  rep(i, n + 1) rep(j, k + 1) rep(lt, 2) dp[i][j][lt] = 0;
  dp[0][0][0] = 1;
  rep(i, n) rep(j, k + 1) rep(lt, 2) {
    ll d = s[i] - '0';
    if(lt) {
      dp[i + 1][j + 1][1] += dp[i][j][lt] * 9;
      dp[i + 1][j][1] += dp[i][j][lt];
    } else {
      if(d > 0) {
        dp[i + 1][j + 1][0] += dp[i][j][lt];
        dp[i + 1][j + 1][1] += dp[i][j][lt] * (d - 1);
      }
      dp[i + 1][j][d != 0] += dp[i][j][lt];
    }
  }
  cout << dp[n][k][0] + dp[n][k][1] << endl;
}

Measured memory_bytes: 3588
// finish date: 2019/11/09

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 998244353;
const int INF = 1000000007;
const long long INFll = 100000000000000000;

//足し算
int add(int a, int b) {
    return (int) (((ll) a + b + bigmod) % bigmod);
}

//引き算
int sub(int a, int b) {
    return (int) (((ll) a - b + bigmod) % bigmod);
}

//掛け算
int mul(int a, int b) {
    return (int) (((ll) (a % bigmod) * (b % bigmod)) % bigmod);
}

int modpow(int a, int b) {
    if (b == 0) return 1;
    int temp = modpow(a, b / 2);
    if (b % 2 == 1) return mul(mul(temp, temp), a);
    else {
        return mul(temp, temp);
    }
}

int main() {
    int N;
    cin >> N;
    vi D(N);
    int ma = 0;
    map<int, int> cnt;
    rep(i, N) {
        cin >> D[i];
        cnt[D[i]]++;
        ma = max(ma, D[i]);
    }
    if (D[0] != 0) {
        cout << 0 << endl;
        return 0;
    }
    FOR(i, 1, N) {
        if (D[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i, ma + 1) {
        if (cnt[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    int ans = 1;
    FOR(i, 1, ma + 1) {
        ans = mul(ans, modpow(cnt[i - 1], cnt[i]));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5376
import java.util.Scanner;

public class Main{


    public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	
    	int end_val = scan.nextInt();//end

		for(int cnt = 1; cnt <= end_val; cnt++){//1~end?????§?????°?????????3???????????°?????¨3????????°?????¢???
			if(cnt % 3 == 0){//3???????????°?????§?????????
				System.out.print(" " + cnt);
			}else{
				for(int i = cnt; i > 0;){//i????¨??????¨
					if(i % 10 == 3){//3???????????°?????§?????????????????§??????
							System.out.print(" " + cnt);
							break;
					 }
					 i /= 10;//??????1????????????
				}
			}
		}
		System.out.println();
	    scan.close();
    }
}

Measured memory_bytes: 28472
#include <iostream>

int max(int a,int b);
int minn(int n, int a, int b);
int main(){

	int N,A,B;

	std::cin>>N>>A>>B;
	std::cout<<max(A,B)<<" "<<minn(N,A,B)<<std::endl;
	
	return 0;
}

int max(int a,int b){

	if(a>b){
		return b;
	}else{
		return a;
	}
}

int minn(int n,int a,int b){
	int temp = a+b-n;
	if(temp>0){
		return temp;
	}else{
		return 0;
	}
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	private ArrayList<Building> building;

	final int BUILDING = 4;
	final int FLOOR = 3;
	final int ROOM = 10;

	public static void main(String[] args) throws Exception {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	    Main main = new Main();
	    main.init();

	    int n = Integer.parseInt(br.readLine());

	    for (int i = 0; i < n; i++) {
		    String line = br.readLine();
		    // ?£?
		    int b = Integer.parseInt(line.split(" ")[0]);
		    // ???
		    int f = Integer.parseInt(line.split(" ")[1]);
		    // ??¨?±???????
		    int r = Integer.parseInt(line.split(" ")[2]);
		    // ?¢?????????°
		    int v = Integer.parseInt(line.split(" ")[3]);

		    main.movePeople(b, f, r, v);
	    }
	    main.disp();
	}

	private void init() {
		this.building = new ArrayList<Building>();

		for (int i = 1; i <= BUILDING; i++) {
			building.add(new Building(i));
		}
	}

	private void disp() {
		for (int b = 0; b < this.building.size(); b++) {

			Building building = this.building.get(b);
			for (int f = 0; f < building.getFloorCount(); f++) {

				Floor floor = building.getFloor(f);
				for (int r = 0; r < floor.getRoomCount(); r++) {
					Room room = floor.getRoom(r);
					System.out.print(" " + room.getNinzu());
				}
				System.out.println("");
			}

			if (b != this.building.size() - 1) {
				System.out.println("####################");
			}
		}
	}

	private void movePeople(int b, int f, int r, int v) {
		Building building = this.building.get(b - 1);
		Floor floor = building.getFloor(f - 1);
		Room room = floor.getRoom(r - 1);

		room.setNinzu(v);
	}

	class Building {
		private int num;

		private ArrayList<Floor> floor;

		Building(int buildingNo) {
			this.num = buildingNo;

			floor = new ArrayList<Floor>();
			for (int i = 1; i <= FLOOR; i++) {
				floor.add(new Floor(i));
			}
		}

		public int getFloorCount() {
			return this.floor.size();
		}

		public Floor getFloor(int floorNo) {
			return floor.get(floorNo);
		}
	}

	class Floor {
		private int num;

		private ArrayList<Room> room;

		Floor(int floorNo) {
			this.num = floorNo;

			room = new ArrayList<Room>();
			for (int i = 1; i <= ROOM; i++) {
				room.add(new Room(i));
			}
		}

		public Room getRoom(int roomNo) {
			return room.get(roomNo);
		}

		public int getRoomCount() {
			return this.room.size();
		}
	}

	class Room {
		private int num;

		private int ninzu;

		Room(int roomNo) {
			this.num = roomNo;
		}

		public int getNinzu() {
			return ninzu;
		}

		public void setNinzu(int ninzu) {
			this.ninzu += ninzu;

			if (this.ninzu < 0) this.ninzu = 0;
		}
	}
}

Measured memory_bytes: 25876
w,h,n=map(int,input().split())
x=[]
y=[]
a=[]
maxx=0
minx=w
maxy=0
miny=h

for i in range(n):
    x1,y1,a1=map(int,input().split())
    x.append(x1)
    y.append(y1)
    a.append(a1)

for j in range(n):
    if(a[j]==1):
        maxx=max(maxx,x[j])
    elif(a[j]==2):
        minx=min(minx,x[j])
    elif(a[j]==3):
        maxy=max(maxy,y[j])
    else:
        miny=min(miny,y[j])

if(maxx>=minx):
    print('0')
    exit()

elif(maxy>=miny):
    print('0')
    exit()

if(maxx<minx or maxy<miny):
    print((minx-maxx) * (miny-maxy))

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

#define MOD 1000000007

int main () {
  int c[26], N;
  char s[100001];
  for (int i=0; i<26; i++)
    c[i] = 0;
  cin >> N;
  cin >> s;
  for (int i=0; i<N; i++)
    c[s[i]-'a']++;
  long long sum = 1;
  for (int i=0; i<26; i++) {
    sum *= (c[i]+1);
    sum %= MOD;
  }
  printf ("%lld\n", sum-1);
  return 0;
}
  

Measured memory_bytes: 384
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
int d[100005];
int order[100005];
struct Edge{
	int u,v;
	int id;
	Edge(int u = 0,int v = 0,int id = 0):u(u),v(v),id(id){}
};
std::vector<Edge>g[100005];
Edge allEdge[200005];
int color[100005],weight[200005];
//edge[i]: the id of edge that is touch it
int parent[100005], edge[100005];
struct Node{
	int u;
	Node(int u):u(u){}
	bool operator < (const Node& other)const{
		return d[u]>d[other.u];
	}
};

int cmp(int u,int v){ return d[u]<d[v]; }

int solve(int n){
	//for(int i = 1; i <= n; i++) printf("%d ",order[i]);
	//printf("\n");
	int p = 1, ok = 1;
	while(p<=n){
		int nextP = p, value = d[order[p]];
		while(nextP+1<=n && d[order[nextP+1]]==value) nextP++;
		for(int i = p; i <= nextP; i++){
			int u = order[i];
			if(parent[u]!=0) color[u] = !color[parent[u]];
		}
		for(int i = p; i <= nextP; i++){
			int u = order[i];
			for(int j = 0; j < (int)g[u].size(); j++){
				int v = g[u][j].v;
				if(d[v]==value && edge[u]==0){
					//printf("u = %d, v = %d\n",u,v);
					edge[u] = g[u][j].id;
					if(edge[v]==0) edge[v] = g[u][j].id, color[v] = 1;
					color[u] = !color[v];
				}
				else if(d[v]!=value && edge[v]==0){ 
					//printf("u = %d, v = %d\n",u,v);
					edge[v] = g[u][j].id;
					parent[v] = u;
				}
			}
		}
		for(int i = p; i <= nextP; i++){
			int u = order[i];
			if(edge[u]==0){
				//printf("u = %d\n",u);
				ok = 0;
			}
			else weight[edge[u]] = value;
		}
		if(!ok) break;
		else p = nextP+1;
	}
	return ok;
}

void outputTest(int n,int m){
	printf("%d %d\n",n,m);
	for(int i = 1; i <= n; i++) printf("%d %d ",color[i],d[i]);
	printf("\n");
	for(int i = 1; i <= m; i++) printf("%d %d %d\n",allEdge[i].u,allEdge[i].v,weight[allEdge[i].id]);
}

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i = 1; i <= n; i++) scanf("%d",&d[i]), order[i] = i;
	for(int i = 1; i <= m; i++){
		int u,v;
		scanf("%d%d",&u,&v);
		g[u].push_back(Edge(u,v,i));
		g[v].push_back(Edge(v,u,i));
		allEdge[i] = Edge(u,v,i);
	}
	std::sort(order+1,order+1+n,cmp);
	int res = solve(n);
	if(res==0) printf("-1\n");
	else {
		for(int i = 1; i <= m; i++) if(weight[i]==0) weight[i] = 1000000000;
		//outputTest(n,m);
		for(int i = 1; i <= n; i++) printf("%c",color[i]?'B':'W');
		printf("\n");
		for(int i = 1; i <= m; i++) printf("%d\n",weight[i]);
	}
	return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

template<int_fast64_t m=MOD>
struct Mcomb{
  using i64=int_fast64_t;
  vector<i64>f;  //$B3,>h(B
  vector<i64>finv; //$B3,>h$N5U85(B
  vector<i64>inv;  //$B5U85(B

  Mcomb(i64 max){
    f.resize(max+1,0);
    finv.resize(max+1,0);
    inv.resize(max+1,0);
    f[0]=f[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(i64 i=2;i<=max;i++){
      f[i]=f[i-1]*i%m;
      inv[i]=m-inv[m%i]*(m/i)%m;
      finv[i]=finv[i-1]*inv[i]%m;
    }
  }

  //nCr=n!/r!(n-r)!
  i64 slove(i64 n,i64 r){
    if(n<r)return 0;
    if(n<0||r<0)return 0;
    return (f[n]*(finv[r]*finv[n-r]%m)%m)%m;
  }
};

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

  int n;
  cin>>n;
  //重複一個
  vector<int>a(n+1);
  for(int i=0;i<=n;i++)cin>>a[i];
  int num;
  map<int,int>m;
  for(auto it:a){
    if(m[it])num=it;
    m[it]++;
  }
  int l=-1,r=-1;
  for(int i=0;i<=n;i++){
    if(a[i]==num){
      if(l==-1)l=i;
      else r=i;
    }
  }
  Mcomb<>c(200000);
  for(int i=1;i<=n+1;i++){
    cout<<((c.slove(n+1,i)-c.slove(l+n-r,i-1))%MOD+MOD)%MOD<<endl;
  }
  return 0;
}


Measured memory_bytes: 11008