akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/numeric>
#define     __        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define     pi        acos(-1)
#define     ll        long long int
#define     mem(a)    memset(a,0,sizeof(a))
#define     mems(a)   memset(a,-1,sizeof(a))
#define     pii       pair<int,int>
#define     N         100005
using namespace std;

vector < int > g[N];
vector < pii > vp;

int ar[N];
bool color[N];

void bfs(int s, int a[])
{
    int n=0;
    color[s]=true;
    queue<int>q;
    q.push(s);

    while(!q.empty())
    {
        int v,u=q.front();
        ar[u]=a[n];
        n++;
        q.pop();

        for(int i=0;i<g[u].size();i++)
        {
            v=g[u][i];

            if(!color[v]){
                q.push(v);
                color[v]=true;
            }
        }

    }

    return;
}


int main(){
    __;
/*
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
*/
    ll sum=0;
    int m,t=1e9,s=0;

    cin >> m;

    int a[m+5];

    for(int u,v,i=0;i<m-1;i++)
    {
        cin >> u >>v;

        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }

    for(int i=1;i<=m;i++)
    {
        if(g[i].size()<t){
            t=g[i].size();
            s=i;
        }
    }

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

    sort(a,a+m,greater<int>());

    bfs(s,a);

    for(int i=1;i<m;i++) sum+=a[i];

    cout << sum << endl;

    for(int i=1;i<=m;i++)
        cout << ar[i] << " ";


   return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <string>

#define llt long long int

using namespace std;
int main()
{
    llt n;

    string s;
    cin >> s;

    s[0] = '2';
    s[1] = '0';
    s[2] = '1';
    s[3] = '8';

    cout << s << endl;
}


Measured memory_bytes: 888
bingo = []
b = []

for i in range(3):
  tmp = list(map(int,input().split()))
  bingo.append(tmp)

n = int(input())

while True:
  try:
    b.append(int(input()))
  except EOFError:
    break

lis1 = [bingo[0][0],bingo[0][1],bingo[0][2]]
lis2 = [bingo[1][0],bingo[1][1],bingo[1][2]]
lis3 = [bingo[2][0],bingo[2][1],bingo[2][2]]

lis4 = [bingo[0][0],bingo[1][0],bingo[2][0]]
lis5 = [bingo[0][1],bingo[1][1],bingo[2][1]]
lis6 = [bingo[0][2],bingo[1][2],bingo[2][2]]

lis7 = [bingo[0][0],bingo[1][1],bingo[2][2]]
lis8 = [bingo[0][2],bingo[1][1],bingo[2][0]]

allList = [lis1,lis2,lis3,lis4,lis5,lis6,lis7,lis8]

for i in allList:
  cnt = 0
  for _ in range(3):
    if i[_] in b:
      cnt +=1
  if cnt ==3:
    print("Yes")
    exit()
print("No")

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

using namespace std;

int main()
{
	  #ifndef ONLINE_JUDGE
	  freopen("input.txt", "r", stdin);
	  freopen("output.txt", "w", stdout);

	  #endif
	  int n;
	  cin>>n;
	  long long arr[n];
	  long long sum=0;
	  for(int i=0;i<n;i++)
	  {
	  	cin>>arr[i];
	  	sum+=arr[i];
	  }
	  int t;
	  cin>>t;
	  while(t--)
	  {
	  		long long a,b;
	  		cin>>a>>b;
	  		cout<<sum-arr[a-1]+b<<"\n";
	  }
}

Measured memory_bytes: 3532
#include <iostream>
#include <cstdio>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
int main(void){
    int A,B,C;
    cin >> A >> B >>C;
    if(A<=C && C <= B){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int k;
    vector<int>c(m,0);
    for(auto i = 0; i < n; ++i){
        cin >> k;
        for(auto j = 0; j < k; ++j){
            int idx;
            cin >> idx;
            c[idx - 1]++;
        }
    }
    auto ans = 0;
    for(auto j = 0; j < m; ++j){
        if(c[j] == n){
            ans++;
        }
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define fill(a,k) memset(a,k,sizeof(a))

using namespace std;


int main(){

    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    // #endif    
        int n;
        cin >> n;
        
        if(n%1000==0)cout << 0;
        else{
            int x = n/1000;
            cout << ((x+1)*1000)-n;
        }
       
}    


Measured memory_bytes: 3632
import itertools

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

gen = []
for i in range(1, N+1):
    gen.append(i)


for pos, v in enumerate(itertools.permutations(gen)):
    for i, comp in enumerate(v):
        if P[i] == comp:
            continue
        else:
            break
    else:
        Pp = pos + 1

    for i, comp in enumerate(v):
        if Q[i] == comp:
            continue
        else:
            break
    else:
        Qp = pos + 1

print(abs(Pp - Qp))


Measured memory_bytes: 3064
#define mod 1000000007
#define INF 1000000000
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	char a;
	cin >> a;
	if (isupper(a)) {
		cout << "A" << '\n';
	} else {
		cout << "a" << '\n';
	}
	
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    int count[100010]={};
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        count[a-1]++;
        count[a]++;
        count[a+1]++;
    }
    int ans = 0;
    for(int i=1; i<=100000; i++){
        ans = max(ans, count[i]);
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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 int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;
const ll mod = 1e9 + 7;

int main(){
    int n, k;
    cin >> n >> k;

    ll res = 0;
    for (ll i = k; i <= n + 1; ++i) {
        res += i * (n - i + 1) + 1;
        res %= mod;
    }
    cout << res << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VS = vector<string>;
using graph = vector<vector<int>>;
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main()
{
int k;
ll ans=0;
cin>>k;
for (int i = 0; i < k; i++)
{
    for (int j = 0; j < k; j++)
    {
        for (int l = 0; l < k; l++)
        {
          int a,b;
          a=gcd(i+1,j+1);
          b=gcd(a,l+1);
          ans+=b; 
        }
        
    }
    
}
cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3596
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <list>
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
using namespace std;
typedef pair<int,int> P;

int main(void){
    int x,y,z;
    cin>>x>>y>>z;
    cout<<(x-z)/(y+z)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int a;
  string s;
  
  cin >> a;
  cin >> s;
  
  if(a>=3200){
   cout << s << endl; 
  }
  
  else{
   cout << "red" << endl; 
  }
  
  
}


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

int main(){
    ll n,h;
    cin>>n>>h;
    vector<ll> pa(n),pb(n);
    for(int i=0;i<n;i++){
        cin>>pa[i]>>pb[i];
    }
    sort(pa.rbegin(),pa.rend());//斬る方で降順ソート
    sort(pb.rbegin(),pb.rend());//投げる方で降順ソート
    ll ans=0,j=0;
    while(pa[0]<pb[j]){
        ans++;
        h-=pb[j];
        j++;
        if(j>=n || h<=0){
            break;
        }
    }
    if(h>0){
        if(h%pa[0]==0){
            ans+=h/pa[0];
        }else{
            ans+=(h/pa[0]+1);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void) {
    int N, K, Q;
    scanf("%d %d %d", &N, &K, &Q);

    int A[Q];
    int score[N];
    for (int i = 0; i < Q; i++) {
        scanf("%d", &A[i]);
    }

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

    for (int i = 0; i < Q; i++) {
        int a = A[i];
        score[a - 1]++;
    }

    for (int i = 0; i < N; i++) {
        if ((K - (Q - score[i])) < 1) {
            printf("No\n");
        } else {
            printf("Yes\n");
        }
    }

    return 0;
}

Measured memory_bytes: 1280
N, K = map(int, input().split()) #N回ジャンケン, K回前と同じ手を出せない
R, S, P = map(int, input().split())
T = input()

t_k = [[] for i in range(K)]

for i in range(N):
    t_k[i%K].append(T[i])

hand = ['r', 's', 'p']
ans = 0
for i_k in t_k:
    n = len(i_k)
    dp = [[0,0,0] for i in range(n+1)]
    cnt = 1
    for s in i_k:
        a = hand.index(s) #相手の手
        if a==0:
            point = [0, 0, P]
        elif a==1:
            point = [R, 0, 0]
        else:
            point = [0, S, 0]
        dp[cnt][0] = max(dp[cnt-1][1]+point[0], dp[cnt-1][2]+point[0])
        dp[cnt][1] = max(dp[cnt-1][0]+point[1], dp[cnt-1][2]+point[1])
        dp[cnt][2] = max(dp[cnt-1][0]+point[2], dp[cnt-1][1]+point[2])
        cnt += 1
    ans += max(dp[n])


print(ans)

Measured memory_bytes: 23452
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt(), k = in.nextInt();
		int[] a=new int[n];
		for (int i=0;i<n;++i) a[i]=in.nextInt();
		int[] dp = new int[n];
        dp[1] = Math.abs(a[1] - a[0]);
		for (int i=2;i<n;++i) {
          dp[i] = dp[i-1] + Math.abs(a[i] - a[i-1]);
          for(int j = 2; j <=k; j++) {
            if(i - j < 0) {
              break;
            }
            dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(a[i] - a[i-j]));
          }
		}
		System.out.println(dp[n-1]);
	}
}

Measured memory_bytes: 50124
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n, m, q;
	cin >> n >> m >> q;
	int tavolo[n+1][n+1];
	int stapel[n+1][n+1];
	// initialisation
	for( int i = 0; i <= n; ++i ){
		for( int j = 0; j <= n; ++j ){
			tavolo[i][j] = 0;
			stapel[i][j] = 0;
		}
	}
	for( int i = 0; i < m; ++i ){
		int l, r;
		cin >> l >> r;
		++tavolo[l][r];
	}
	// accumuler
	for( int i = 1; i <= n; ++i ){
		for( int j = 1; j <= n; ++j ){
			stapel[i][j] = stapel[i][j-1] + tavolo[i][j];
		}
	}
	for( int i = 1; i <= n; ++i ){
		for( int j = 1; j <= n; ++j ){
			stapel[j][i] = stapel[j-1][i] + stapel[j][i];
		}
	}
	/*
	for( int i = 0; i <= n; ++i ){
		for( int j = 0; j <= n; ++j ){
			cout << stapel[i][j] << " ";
		}
		cout << endl;
	}
	*/
	for( int i = 0; i < q; ++i ){
		int p, q;
		cin >> p >> q;
		--p;
		cout << stapel[p][p] + stapel[q][q] - stapel[p][q] - stapel[q][p] << endl;
	}
	return 0;
}

Measured memory_bytes: 2944
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
typedef long long ll;
int main(){    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    for(int i=1;i<=5;i++){
        int x;
        cin>>x;
        if(!x)cout<<i;
    }
    return 0;
}


Measured memory_bytes: 3580
unittest
{
	assert( [ "2", "3 1 2", "6 1 1" ].parse.expand.solve == "Yes" );
	assert( [ "1", "2 100 100" ].parse.expand.solve == "No" );
	assert( [ "2", "5 1 1", "100 1 1" ].parse.expand.solve == "No" );
}



import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	auto txys = new long[ 3 ][ n ];
	foreach( ref txy; txys )
	{
		input.popFront;
		txy = input.front.split.to!( long[] );
	}
	return tuple( txys );
}

auto solve( long[ 3 ][] txys )
{
	auto txy_p = [ 0L, 0L, 0L ];
	
	foreach( txy; txys )
	{
		auto dd = ( txy[ 1 ] - txy_p[ 1 ] ).abs + ( txy[ 2 ] - txy_p[ 2 ] ).abs;
		auto dt = txy[ 0 ] - txy_p[ 0 ];
		
		if( dt < dd || ( dt - dd ) % 2 == 1 ) return "No";
		
		txy_p[] = txy[];
	}
	
	return "Yes";
}


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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int A=read(),B=read(),C=read();
	int time=0;
	bool sleep=false;
	int t=0;
	int i=0;
	while(i<10000){
		time += A;
		if(time >= C){
			cout << C << endl;
			return 0;
		}
		time += B;
		if(time > C) C += 60;
		
		if(time == 60){
			cout << -1 << endl;
			return 0;
		}
		i++;
	}
	
	cout << -1 << endl;

}

Measured memory_bytes: 3216
#pragma region Macros

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
ostream &operator<<(ostream &out, vector<T> const &v) {
    for (auto &&a : v) out << a << " ";
    out << endl;
    return out;
}

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main() {
    int N;
    cin >> N;

    int a = 100;
    int count = 0;
    while (a < N) {
        a += a / 100;
        count++;
    }
    cout << count;
}

#pragma region main
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    cout << flush;
}
#pragma endregion


Measured memory_bytes: 3624
a,b=map(int,input().split())
wa={i:0 for i in range(1,a+1)}
ac={i:0 for i in range(1,a+1)}
g=0
pe=0
if b==0:
    print("0 0")
    g=1
for i in range(b):
    c,d=input().split()
    
    if d=="WA" and ac[int(c)]==0:
        wa[int(c)]+=1
        
    if d=="AC" and ac[int(c)]==0:
        pe+=wa[int(c)]
        ac[int(c)]=1
    
        
f=0
h=0
if g==0:
    
    print(str(sum(ac.values()))+" "+str(pe))

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

using namespace std;
const int maxn=3011;
int R, C, K;
int v[maxn][maxn];
long long dp[maxn][maxn][4];


int main(){
    scanf("%d%d%d", &R, &C, &K);
    for (int i=0; i<K; i++){
        int r, c, vi;
        scanf("%d%d%d", &r, &c, &vi);
        v[r][c]=vi;
    }
    dp[1][1][0]=0;
    dp[1][1][1]=v[1][1];
    for (int i=1; i<=R; i++){
        for (int j=1; j<=C; j++){
            if (i==1&&j==1) continue;
            if (j-1>0){
                for (int k=0; k<4; k++) dp[i][j][k]=dp[i][j-1][k];
                for (int k=1; k<4; k++) dp[i][j][k]=max(dp[i][j][k], dp[i][j-1][k-1]+v[i][j]);
            }
            if (i-1>0){
                for (int k=0; k<4; k++) dp[i][j][0]=max(dp[i][j][0], dp[i-1][j][k]);
                for (int k=0; k<4; k++) dp[i][j][1]=max(dp[i][j][1], dp[i-1][j][k]+v[i][j]);
            }
        }
    }
    printf("%lld\n", max(dp[R][C][0], max(dp[R][C][1], max(dp[R][C][2], dp[R][C][3]))));
}


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<ll> a(n);
  vector<ll> no = {-1};
  vector<ll> sub = {0};
  ll keep = 0;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    if (a.at(i) > keep) {
      no.emplace_back(i);
      sub.emplace_back(a.at(i));
      keep = a.at(i);
    }
  }
  
  vector<ll> all(no.size()), rem(no.size());
  for (int i = 0; i < n; i++) {
    ll it = lower_bound(sub.begin(), sub.end(), a.at(i)) - sub.begin();
    all.at(it - 1)++;
    rem.at(it) += a.at(i) - sub.at(it - 1);
  }
  
  for (int i = no.size() - 2; i >= 0; i--) all.at(i) += all.at(i + 1);
  
  vector<ll> ans(n);
  for (int i = 1; i < no.size(); i++) {
    ans.at(no.at(i)) = all.at(i) * (sub.at(i) - sub.at(i - 1)) + rem.at(i);
  }
  
  for (int i = 0; i < n; i++) cout << ans.at(i) << '\n';
}

Measured memory_bytes: 5996
K, N =map(int,input().split())
A_n =list(map(int,input().split()))

A_n.sort()

maxd =K -A_n[N-1]+ A_n[0]
for i in range(N-1):
    maxd =max(maxd,A_n[i+1]-A_n[i])
    
print(K-maxd)

Measured memory_bytes: 26060
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    int n; cin >> n;
    string s; cin >> s;
    vector<int> E(n);
    vector<int> W(n);
    vector<int> E_sum(n + 1);
    vector<int> W_sum(n + 1);

    E_sum[0] = 0, W_sum[0] = 0;
    rep(i,n){
        if(s[i] == 'E'){
            E[i] = 1;
            W[i] = 0;
        }else{
            E[i] = 0;
            W[i] = 1;
        }
    }
    _rep(i, 1, n + 1){
        E_sum[i] = E_sum[i - 1] + E[i - 1];
        W_sum[i] = W_sum[i - 1] + W[i - 1];
    }
    int ans;
    int ans_min = INFINITY;
    rep(i, n + 1){
        ans = W_sum[i - 1] + (E_sum[n] - E_sum[i]);
        ans_min = min(ans, ans_min);
    }
    cout << ans_min << endl;
}

Measured memory_bytes: 5380
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#define rep(i, n) for(int i = 0; i < (n); i++)
int n;
int S[100005];
int q;

using namespace std;

bool bin_search(int t) {
    int lb = 0, ub = n + 1;
    
    while(ub - lb > 1) {
        // printf("%d %d\n", lb, ub);
        int mid = (lb + ub) / 2;
        if (S[mid] == t) return true;
        if (t < S[mid]) ub = mid;
        else lb = mid;
    }
    return false;
}

int main()
{
    cin >> n;
    rep(i, n) cin >> S[i];
    cin >> q;
    int ans = 0;
    rep(i, q) {
        int t;
        cin >> t;
        if(bin_search(t)) ans++;
    }
    
    cout << ans << endl;
    
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://msdn.microsoft.com/library/3bstk3k5.aspx
//   http://www.cplusplus.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   http://www.boost.org/doc/

Measured memory_bytes: 3384
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int M, N, res;
  rd(N);
  rd(M);
  res = (N-1) * (M-1);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// {
//   int N, M, res;
//   rd(N, M);
//   res = (N-1) * (M-1);
//   wt(res);
// }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>

//using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

using ll =  long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

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

using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}

	template<typename T>
	void Dump(T t) {
		std::cout << t << std::endl;
	}

	void Yes(bool b) {
		if (b) std::cout << "Yes" << std::endl;
		else std::cout << "No" << std::endl;
	}

	void YES(bool b) {
		if (b) std::cout << "YES" << std::endl;
		else std::cout << "NO" << std::endl;
	}
}


int main() {

	int n;
	std::cin >> n;
	std::vector<int> l(n);
	rep(i, n) std::cin >> l[i];

	std::sort(allof(l));

	int max_len = l[n - 1];
	int sum_len = 0;
	rep(i, n - 1) sum_len += l[i];

	::Yes(max_len < sum_len);

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int mod = (int)1e9+7;
        long all = 1;
        long non= 1;
        long one=1;
        for (int i =0;i<n;i++){
            all*=10;
            non*=8;
            one*=9;
            all%=mod;
            non%=mod;
            one%=mod;
        }
        non=(2*one)-non;
        non+=2*mod;
        non%=mod;
        pw.println((all-non+mod)%mod);
        pw.flush();
    }
    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader f) {
            br = new BufferedReader(f);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public int[] nextIntArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = Integer.parseInt(next());
            }
            return arr;
        }

    }

}

Measured memory_bytes: 32860
def main():
    x, n = map(int, input().split())
    p = set(list(map(int, input().split())))

    for i in range(x, x+200):
        if i not in p:
            m = i
            break
    for i in range(x, x-200, -1):
        if i not in p:
            M = i
            break
    if abs(m-x) < abs(M-x):
        print(m)
    else:
        print(M)


main()


Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(long long i=a;i<n;i++)
typedef long long ll;
const ll INF=1LL << 40;

vector<ll> S(200020),T(200020),X(200020);

ll nearS(ll x){
    ll res;
    ll a,b;

    auto itr=lower_bound(S.begin(),S.end(),x);
    a = *itr;
    b = S[itr-S.begin()-1];
    if(a == INF)res = b;
    else if(b == -INF)res = a;
    else min(abs(a-x),abs(b-x))==abs(a-x) ? res=a : res=b;

    return res;
}

ll nearT(ll x){
    ll res;
    ll a,b;

    auto itr=lower_bound(T.begin(),T.end(),x);
    a = *itr;
    b = T[itr-T.begin()-1];
    if(a == INF)res = b;
    else if(b == -INF)res = a;
    else min(abs(a-x),abs(b-x))==abs(a-x) ? res=a : res=b;

    return res;
}

int main(){
    ll A,B,Q;cin >> A >> B >> Q;
    REP(i,1,A+1)cin >> S[i];S[0]=-INF;S[A+1]=INF;
    REP(i,1,B+1)cin >> T[i];T[0]=-INF;T[B+1]=INF;
    REP(i,1,Q+1)cin >> X[i];
    S.resize(A+2);T.resize(B+2);

    sort(S.begin(),S.end());sort(T.begin(),T.end());
    REP(i,1,Q+1){
        ll a,b;
        ll c=nearS(X[i]),d=nearT(X[i]);
        ll x=X[i];
        a=abs(x-c)+abs(c-nearT(c));
        b=abs(x-d)+abs(d-nearS(d));

        auto itr=lower_bound(S.begin(),S.end(),c);
        ll aa=INF;
        ll tar=S[itr-S.begin()-1];
        if(tar!=-INF)aa=abs(x-tar)+abs(tar-nearT(tar));
        tar = S[itr-S.begin()+1];
        if(tar!=INF)aa=min(aa, abs(x-tar)+abs(tar-nearT(tar)));

        itr=lower_bound(T.begin(),T.end(),d);
        ll bb=INF;
        tar=T[itr-T.begin()-1];
        if(tar!=-INF)bb=abs(x-tar)+abs(tar-nearS(tar));
        tar=T[itr-T.begin()+1];
        if(tar!=INF)bb=min(bb, abs(x-tar)+abs(tar-nearS(tar)) );

        a=min(a,aa);b=min(b,bb);

        cout << min(a,b) << endl;
    }
}

Measured memory_bytes: 6016
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n;
    cin >> n;
    cout << 24 + (24-n) << endl;
    return 0;
}



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

num = 0

for i in range(1,n-1):
    if (p[i-1] < p[i] and p[i]<p[i+1]) or (p[i-1]>p[i] and p[i]>p[i+1]):
        num += 1
        
print(num)

Measured memory_bytes: 3064
from itertools import product
N, K = list(map(int, input().split()))


ans = 0

count = N // K

ans += count ** 3

if K % 2 == 0:
    count = 0
    k = K // 2
    while True:
        if k <= N:
            count += 1
            k += K
        else:
            break
    ans += count ** 3

print(ans)


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:

const int limit = 100010;
int a[limit], b[limit];

int num[limit];

int main(void) {
	int n;
	cin >> n;

	using pii = pair<int, int>;
	vector<pii> ary;

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

	rep(i, n) num[b[i]]++;


	rep(i, n) {
		if (num[a[i]] == 0) {
			puts("No");
			rep(j, n) cout << (j ? " " : "") << 1 + 1;
			cout << endl;
			rep(j, n) cout << (j ? " " : "") << 1 + (j != i);
			cout << endl;
			return 0;
		}
	}


	puts("Yes");

	return 0;
}


Measured memory_bytes: 4272
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	ll n,m,res=0;
	cin>>n>>m;
	if(n>m)
	{
		ll c=m;
		m=n;
		n=c;
	}
	if(n==1)
	{
		if(m==1)res=1;
		else if(m==2)res=0;
		else res=m-2;
	}
	else if(n==2)res=0;
	else res=(n*m)-(2*n+2*m-4);
	cout<<res<<endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
const int INF = 1e9;
const llint llINF = 1e18;

int main () {
    int n; cin >> n;
    int s1, s2 = 0, ans = INF;
    vint w(n);
    rep(i,n) {
        cin >> w[i];
        s1 += w[i];
    }
    for (int i = 0; i < n; i++) {
        int min_temp;
        min_temp = abs(s1 - s2);
        ans = min(ans, min_temp);
        s1 -= w[i];
        s2 += w[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 2000000
#define MOD 1000000007

int main(){
  int N;
  cin>>N;
  vector<double> p(N);
  for(int i=0;i<N;i++){
    cin>>p.at(i);
  }

  vector<vector<double>> dp(N+1,vector<double>(N+1,0.0));
  dp.at(0).at(0)=1.0;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      dp.at(i+1).at(j)+=dp.at(i).at(j)*(1.0-p.at(i));
      dp.at(i+1).at(j+1)+=dp.at(i).at(j)*p.at(i);
    }
  }

  double ans=0.0;
  for(int i=N/2+1;i<=N;i++){
    ans+=dp.at(N).at(i);
  }
  printf("%.10lf\n",ans);
}


Measured memory_bytes: 70656
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int main()
{
	int a, b;
	cin >> a >> b;
	cout << (a + b) % 24 << endl;
	//printf((a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) ? "Possible\n" : "Impossible\n");
}

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

int main(){
    ll n,a,b; cin >> n >> a >> b;
    ll ans = n/(a+b)*a+min(a,n%(a+b));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n;
bool data[255][255];    
int dp[4][255][255];

int check(int mode,int i,int j)
{
  if(i<0 || i>=n ||
     j<0 || j>=n)
    return 0;
  if(dp[mode][i][j]!=-1)
    return dp[mode][i][j];
  if(!data[i][j])
    return 0;
  if(mode==1)
    dp[mode][i][j]=check(1,i+1,j)+1;
  else if(mode==2)
    dp[mode][i][j]=check(2,i+1,j-1)+1;
  else if(mode==3)
    dp[mode][i][j]=check(3,i+1,j+1)+1;
  
  return dp[mode][i][j];
}

int main()
{

  for(;cin>>n,n;)
    {

      memset(dp,-1,sizeof(dp));
      //<->0, up-down,1,hidarisita2,migisita3
      int ans=0;
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  {
	    char tmp;
	    cin>>tmp;
	    data[i][j]=(tmp=='1');
	    if(data[i][j])
	      {
		if(j==0)
		  dp[0][i][j]=1;
		else
		  dp[0][i][j]=dp[0][i][j-1]+1;
	      }
	    else
	      dp[0][i][j]=0;
	    ans=max(ans,dp[0][i][j]);	    
	  }
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  {
	    for(int k=1;k<4;k++)
	      ans=max(ans,check(k,i,j));
	  }
      cout<<ans<<endl;
    }
}

Measured memory_bytes: 2248
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int answer = 0;
		for(int i =1;i <=n;i++) {
			int ketaGokei = getKetaGokei(i);
			if(a <=ketaGokei &&ketaGokei <=b ) {
				answer += i;
			}
		}
		System.out.println(answer);
	}

	private static int getKetaGokei(int i) {
		String[] numberArray = String.valueOf(i).split("");
		int ketaGokei = 0;
		for(String number : numberArray) {
			ketaGokei += Integer.parseInt(number);
		}
		return ketaGokei;
	}
}

Measured memory_bytes: 32852
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int N, M;
    cin >> N >> M;
    vector<int> A(M, 0);
    
    int K, idx;
    for (int i = 0; i < N; ++i) {
        cin >> K;
        for (int j = 0; j < K; ++j) {
            cin >> idx;
            A[idx-1]++;
        }
    }
    
    int res = 0;
    for (int i = 0; i < M; ++i) {
        if (A[i] == N) ++res;
    }
    cout << res << endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define SZ(x) ((int)(x).size())

typedef long long ll;

int const MOD = 1e9 + 7;

ll KSM(ll a, ll k) {
	ll ret = 1;
	for(; k; k >>= 1) {
		if(k & 1) 
			ret = ret * a % MOD;
		a = a * a % MOD;
	}
	return ret;
}

int main() {
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	std::vector<int> inv(n + 1);
	for(int i = 0; i < n; ++i) 
		std::cin >> a[i];
	for(int i = 1; i <= n; ++i) 
		inv[i] = KSM(i, MOD - 2);
	ll C = 0;
	for(int i = 1; i <= n; ++i)
		(C += inv[i]) %= MOD;
	ll ans = 0;
	for(int i = 0; i < SZ(a); ++i) {
		ans = (ans + C * a[i] % MOD) % MOD;
		C += inv[i + 2];
		C -= inv[n - i];
		C = (C % MOD + MOD) % MOD;
	}
	for(int i = 1; i <= n; ++i) 
		ans = ans * i % MOD;
	ans = (ans % MOD + MOD) % MOD;
	std::cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1024
inline int modexp(int a, int b);
#include<cstdio>
#include<map>
#include<cassert>
#include<functional>
#include<string>
#include<cassert>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
using namespace std;
typedef long long ll;
const int MOD(1e9+7);

int n, x, a[2016];

ll d[2016][2016];
int main()
{
 scanf("%d%d", &n, &x);
 ll ans = 0;
 for (int i = 0; i < n; i++) scanf("%d", a + i), ans += a[i];

 for (int i = 0; i < n; i++) d[0][i] = a[i];
 ll base = 0;
 for (int i = 1; i < n; i++) {
  base += x;
  for (int j = 0; j < n; j++)
   d[i][j] = min(d[i-1][j], (ll)a[(j+n-i)%n]);
  ll t = 0;
  for (int j = 0; j < n; j++) t += d[i][j];
  ans = min(ans, t + base);
 }

 printf("%lld\n", ans);
 return 0;
}


inline int modexp(int a, int b)
{
 int e = a, r = 1;
 while (b > 0) {
  if (b&1) r = r *1LL* e % MOD;
  e = e *1LL* e % MOD;
  b >>= 1;
 }
 return r;
}


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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

struct edge{
	int v,id;
	edge(int v, int id):v(v),id(id){};
};

vector<edge>adj[55];
vector<int>path;

bool dfs(int u, int target, int p=-1){
	if(u==target)return 1;
	for(edge e:adj[u]){
		int v = e.v, id = e.id;
		if(v==p)continue;
		if(dfs(v,target,u)){
			path.eb(id);
			return 1;
		}
	}
	return 0;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n; cin >> n;
	for(int i=0; i<n-1; i++){
		int a,b;
		cin >> a >> b;
		a--; b--;
		adj[a].eb(b,i);
		adj[b].eb(a,i);
	}
	int m; cin >> m;
	ll idd[m];
	for(int i=0; i<m; i++){
		int u,v;
		cin >> u >> v;
		u--; v--;
		path.clear();
		dfs(u,v);
		idd[i]=0LL;
		for(int id:path)
			idd[i]|=(1LL<<id);
	}
	ll ans = 0LL;
	for(int i=0; i<(1<<m); i++){
		ll now = 0LL;
		for(int j=0; j<m; j++){
			if(i>>j&1)now|=idd[j];
		}
		now = 1LL<<(n-1-(__builtin_popcountll(now))); // cnt # of edges that're not used
		if(__builtin_popcount(i)%2)ans -= now;
		else ans += now;
	}
	cout << ans << endl;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 384
import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  var n = 0
  val b = new ArrayBuffer[Int]
  while({n=readInt;n} != 0){
    val s = readLine.split(" ").map(_.toInt).sum
    b += s/(n-1)
  }
  println(b.mkString("\n"))
}

Measured memory_bytes: 54368
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		int ac = 0;
		int wa = 0;
		int tle = 0;
		int re = 0;
		Scanner scan = new Scanner(System.in);
		String array[] = new String[scan.nextInt()];
		for(int i=0;i < array.length;i++) {
			array[i] = scan.next();
			if(array[i].equals("AC")) {
				ac += 1;
			}else if(array[i].equals("WA")) {
				wa += 1;
			}else if(array[i].equals("TLE")) {
				tle += 1;
			}else if(array[i].equals("RE")) {
				re += 1;
			}
		}
		System.out.println("AC x "+ac);
		System.out.println("WA x "+wa);
		System.out.println("TLE x "+tle);
		System.out.println("RE x "+re);

		scan.close();
	}
}

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

int main () {

    string S;
    cin >> S;

    int ans = INT_MAX;
    for (int i = 0; i < (int)S.size()-2; i++) {
        int num = 0;

        for (int j = i; j < i + 3; j++) {
            num = 10 * num + (int)S[j] - '0';
        }

        ans = min(ans, abs(num - 753));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    int X = sc.nextInt();
    sc.close();
    int start = (X-K+1);
    for (int i=start;i<=X+K-1;i++){
      if (i<X+K-1){
        System.out.print(i + " ");
      }else{
        System.out.println(i);
      }
    }
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define substr(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;cin>>s;
  ll num=(s[0]==s.back())?s.size()-3:s.size()-2;
  cout<<((num%2)?"First":"Second")<<endl;
  return 0;
}


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

int n, k, a[100004];

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

	int zp = lower_bound(a, a+n, 0) - a, yp = upper_bound(a, a+n, 0) - a - 1;

	int ans = 1e9;
	for (int i=0; i+k-1<n; i++) {
		int x = max(0, -a[i]), y = max(0, a[i+k-1]);
		ans = min({ans, 2*x+y, x+2*y});
	}

	cout << ans << '\n';
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
#import numpy as np
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#S = str(input())

A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

#割引券を使う場合
ans = sys.maxsize
for _ in range(M) :
  x, y, c = map(int, input().split())
  ans = min(ans, a[x-1]+b[y-1]-c)

#その他の組み合わせ
ans = min(ans, min(a)+min(b))

print (ans)



Measured memory_bytes: 18992
N=int(input())
S=input()

r=S.count('R')
g=S.count('G')
b=S.count('B')

ans=r*g*b
for i in range(N-2):
  for j in range(i+1,N-1):
    if 2*j-i>=N:
      break
    elif S[i]!=S[j] and S[j]!=S[2*j-i] and S[2*j-i]!=S[i]:
      ans-=1
print(ans)

Measured memory_bytes: 9196
from collections import Counter
n=int(input())
l=Counter(map(int,input().split()))
o=int(1e9+7)
if n%2:
  if not (0 in l and l[0]==1):
    print(0)
  elif n//2!=list(l.values()).count(2):
    print(0)
  else:
    print(2**(n//2)%o)
else:
  if n//2!=list(l.values()).count(2):
    print(0)
  else:
    print(2**(n//2)%o)


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

int main()
{
    int n;
    cin>>n;
    
    int h[n];
    for(int i=0;i<n;i++) cin>>h[i];
    if(n==1)
    {
        cout<<"Yes";
        return 0;
    }

    for(int i=n-2;i>=0;i--)
    {
       if(h[i]-1 > h[i+1]) 
       {
           cout<<"No";
           return 0;
       } 

       if(h[i]-1 == h[i+1]) h[i]--;
    }
    cout<<"Yes";
}

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

 
using namespace std;
#define mod 1000000007
#define ll long long 
 
 
ll n,w, a[100009], b[100009];
ll dp[109][100009];
 
// map<int, map<ll, ll> > dp;
 
ll solve(int r, int idx) {
    if(idx == n)
        return r == 0 ? 0 : INT_MAX;
 
    if(dp[idx][r] != -1)
    	return dp[idx][r];
 
    ll ans = solve(r, idx + 1);
    if(b[idx] <= r)
    	ans = min(ans, a[idx] + solve(r - b[idx], idx + 1));
 
    return dp[idx][r] = ans;
}
 
int s(int v_max) {
 
	for(int i = v_max; i >= 0; i--) {
		if(solve(i, 0) <= w)
			return i;
	}
	return 0;
}
 
int main() {
 
    // int t;
    // cin>>t;
    // while(t--) {
        cin>>n>>w;
        memset(dp, -1, sizeof(dp));
 
        int v_max = 0;
 
        for(int i = 0; i < n; i++) {
            cin>>a[i]>>b[i];
            v_max += b[i];
        }
 
        cout<<s(v_max)<<endl;
 
}

Measured memory_bytes: 88364
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

const int MAXN = 1e6 + 10;
const int Mod = 1e9 + 7;
int N, M, A, B;
int fac[MAXN], ifc[MAXN];
int ans;

inline int fastpow_mod(int a, int b, int m = Mod) {
	int x = 1;
	while(b) {
		if(b & 1) x = 1ll * x * a % m;
		a = 1ll * a * a % m; b >>= 1;
	}
	return x;
}

inline int C(int n, int k) {
	if(n < k || n < 0 || k < 0) return 0;
	return 1ll * fac[n] * ifc[k] % Mod * ifc[n - k] % Mod;
}

inline void init(int n) {
	register int i;
	for(fac[0] = i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % Mod;
	for(ifc[n] = fastpow_mod(fac[n], Mod - 2), i = n; i; --i) ifc[i - 1] = 1ll * ifc[i] * i % Mod;
}

int main() {
	register int i;
	init(1000000);
	scanf("%d%d%d%d", &N, &M, &A, &B);
	for(i = 1; i <= N - A; ++i)
		(ans += 1ll * C(i + B - 2, B - 1) * C(N - i + M - B - 1, N - i) % Mod) %= Mod;
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 2e5 + 5;

void debug_out() {
    cerr << endl;
}

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

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
ll fastPow(ll x, ll b) {
    if (b == 0)
        return 1;
    else if (b%2==0) {
        return (fastPow((x * x)%MOD, b / 2))%MOD;
    } else
        return (x * fastPow((x * x)%MOD, (b - 1) / 2))%MOD;
}
ll nck(ll n,ll k)
{
    if(k>n-k)
        k=n-k;
    ll res=1;
    for(int i=1;i<=k;i++)
    {
        res=res*(n-i+1);
        res%=MOD;
        res*=fastPow(i,MOD-2)%MOD;
        res%=MOD;
    }
    return res%MOD;
}
ll arr[MAXN];
int main() {
    FAST
    ll n, m;
    cin >> n >> m;
    ll ans = 0;


    for(ll i=1;i<=n;i++)
        arr[i]=i+arr[i-1];
    for (ll i = m; i <= n+1; i++)
    {
        ll mn=arr[i-1];
        ll mx=arr[n]-arr[n-i];
        ans+=((ll)mx-(ll)mn+1ll);
        ans%=MOD;
    }
    cout<<ans%MOD<<endl;
    return 0;
}


Measured memory_bytes: 5104
// B.

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>
#include <cmath>

using namespace std;

struct Point {
	long double x;
	long double y;
	int i;
	bool operator < (const Point &p) const {
		return x < p.x || (x == p.x && y < p.y);
	}
};

long double cross(const Point &O, const Point &A, const Point &B) {
	return (A.x - O.x) * (B.y - O.y) - (A.y - O.y) * (B.x - O.x);
}

vector<Point> convex_hull(vector<Point> P)
{
	int n = (int)P.size(), k = 0;
	if (n <= 2) {
		return P;
	}
	vector<Point> H(2 * n);
	sort(P.begin(), P.end());
	for (int i = 0; i < n; ++i) {
		while (k >= 2 && cross(H[k - 2], H[k - 1], P[i]) <= 0) k--;
		H[k++] = P[i];
	}
	for (int i = n - 2, t = k + 1; i >= 0; i--) {
		while (k >= t && cross(H[k - 2], H[k - 1], P[i]) <= 0) k--;
		H[k++] = P[i];
	}
	H.resize(k - 1);
	return H;
}

long double rad(const Point &a, const Point &b, const Point &c) {
	long double a1 = a.x - b.x, a2 = a.y - b.y;
	long double b1 = c.x - b.x, b2 = c.y - b.y;
	long double cos = (a1 * b1 + a2 * b2) / (sqrt(a1 * a1 + a2 * a2) * sqrt(b1 * b1 + b2 * b2));
	return acos(cos);
}


int main(int argc, char *argv[])
{
	cout.precision(10);
	int n;
	cin >> n;
	vector<Point> p(n);
	for (int i = 0; i < n; ++i) {
		cin >> p[i].x;
		cin >> p[i].y;
		p[i].i = i;
	}
	vector<long double> res(n, 1.0 / n);
	if (n >= 3) {
		res = vector<long double>(n);
		vector<Point> ch = convex_hull(p);
		if (ch.size() <= 2) {
			for (int i = 0; i != ch.size(); ++i) {
				res[ch[i].i] = 1.0 / ch.size();
			}
		} else {
			for (int i = 0; i != ch.size(); ++i) {
				int prev = (i - 1 + ch.size()) % ch.size();
				int next = (i + 1) % ch.size();
				long double r = rad(ch[prev], ch[i], ch[next]);
				res[ch[i].i] = (M_PI - r) / (2 * M_PI);
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		cout << res[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		sc.close();

		int[] ans = new int[N - 1];
		for (int i = 1; i <= N - 1; i++) { // 始点
			for (int j = i + 1; j <= N; j++) { // 終点
				int normal = j - i;
				int warp = Math.abs(i - X) + 1 + Math.abs(j - Y);
				int min = Math.min(normal, warp);
				ans[min - 1]++;
			}
		}

		for (int i = 0; i < N - 1; i++) {
			System.out.println(ans[i]);
		}
	}
}


Measured memory_bytes: 23764
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
//#include <bitset>
typedef long long ll;
using namespace std;
int n,a;
ll dp[52][52][2555];
int num[55];
int main(){
    scanf("%d%d",&n,&a);
    for(int i=1;i<=n;i++) scanf("%d",&num[i]);
    dp[1][1][num[1]]=1;
    dp[1][0][0]=1;
    for(int i=2;i<=n;i++){
        dp[i][1][num[i]]++;
        for(int j=1;j<=i;j++){
            for(int k=1;k<=(i*50);k++){
                dp[i][j][k]+=dp[i-1][j][k];
                dp[i][j][num[i]+k]+=dp[i-1][j-1][k];
            }
        }
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        ans+=dp[n][i][i*a];
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 51456