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

int main(){
	int n;
	cin >> n;
	vector<int>a(n+2);
	a[0] = 0;
	a[n + 1] = 0;
	for (int i = 1;i <= n;i++) {
		cin >> a[i];
	}
	vector<int> sum(n + 2);
	sum[0] = 0;
	for (int i = 1;i <= n + 1;i++) {
		sum[i] = sum[i - 1] + abs(a[i] - a[i - 1]);
	}

	for (int i = 1;i <= n;i++) {
		int ans = sum[i - 1] + abs(a[i - 1] - a[i + 1]) + sum[n + 1] - sum[i+1];
		cout << ans << endl;
	}


	return 0;
}

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

bool isPrime(int num) {
    if (num < 2) return false;
    if (num == 2) return true;
    if (num%2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i=3; i<=sqrtNum; i++) {
        if (num % i == 0) return false;
    }
    return true;
}

int main() {
    const int maxR = 1E+5 + 10;
    bool Prime[maxR], like2017[maxR];
    int accSum[maxR];
    // rep(i, maxR) Prime[i] = isPrime(i);
    rep(i, maxR) Prime[i] = true;
    Prime[0] = Prime[1] = false;
    for (int i=2; i<maxR; i++) {
        if (Prime[i])  for (int j=i+i; j < maxR; j+=i) Prime[j] = false;
    }
    rep(i, maxR) {
        if ((i%2 == 1) && (Prime[i]) && (Prime[(i+1)/2])) like2017[i] = true;
        else like2017[i] = false;
    }
    accSum[0] = 0;
    for (int i= 1; i<maxR; i++) {
        accSum[i] = accSum[i-1] + like2017[i];
    }

    int Q, li, ri;
    cin >> Q;
    rep(i, Q) {
        cin >> li >> ri;
        cout << accSum[ri] - accSum[li-1] << endl;
    }

    return 0;
}

 

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

int a[400000];
int main(){
	int n;scanf("%d",&n);
	rep(i,n){
		scanf("%d",&a[i]);
		a[i]-=i+1;
	}
	sort(a,a+n);
	ll ans=0;
	rep(i,n){
		ans+=abs(a[i]-a[n/2]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
function Main(input) {
    var a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
  var i = parseInt(input, 10);
  console.log(a[i -1]);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
 
int main(){
  ll i, j;
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll buf;
  for(i = 0; i < n;i++){
    cin >> buf;
    a[i] = buf - i;
  }
  
  ll sum = 0;
  for(i = 0; i < n; i++){
    sum += a[i];
  }
  sort(ALL(a));
  ll med = a[n / 2];
  ll result = 0;
  for(i = 0; i < n; i++){
    result += abs(med - a[i]);
  }
  cout << result << endl; 
 
  return 0;
  /**/
  
}




Measured memory_bytes: 1792
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    ll dp[1001][1001];
    char ar[1001][1001];
    int n,m;

    ll func(int i,int j)
    {
        if(i<=0 || j<=0 || i>n || j>m)
            return 0;
        if(dp[i][j]!=-1)
            return dp[i][j];
        if(ar[i][j]=='#')
            return dp[i][j]=0;
        if(i==n && j==m)
            return dp[i][j]=1;
        return dp[i][j]=(func(i+1,j)+func(i,j+1))%mod;
    }

    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            mem(dp,-1);
            int i,j;
            cin>>n>>m;
            for(i=1;i<=n;++i)
            {
                for(j=1;j<=m;++j)
                    cin>>ar[i][j];
            }
            cout<<func(1,1)<<endl;
        }
        return 0;
    }


Measured memory_bytes: 9216
n = gets.to_i
ng_words = []
ans = 'Yes'
n.times do
  word = gets.chomp
  ans = 'No' if (!ng_words.empty? && ng_words[-1][-1] != word[0]) || !ng_words.find { |s| s == word }.nil?
  ng_words << word
end
puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char **argv)
{
	int a[5];
	while(scanf("%d,%d,%d,%d,%d", &a[0], &a[1], &a[2], &a[3], &a[4])!=EOF){
		sort(a, a+5);
		if(a[0]==a[1]&&a[0]==a[2]&&a[0]==a[3] || a[4]==a[1]&&a[4]==a[2]&&a[4]==a[3]){
			cout << "four card" << endl;
		} else if(a[0]==a[1]&&a[1]==a[2]){
			if(a[3]==a[4]){
				cout << "full house" << endl;
			} else {
				cout << "three card" << endl;
			}
		} else if(a[4]==a[3]&&a[2]==a[4]){
			if(a[0]==a[1]){
				cout << "full house" << endl;
			} else {
				cout << "three card" << endl;
			}
		} else if(a[1]==a[2]&&a[1]==a[3]){
			cout << "three card" << endl;
		} else if(a[0]==a[1]&&(a[2]==a[3]||a[3]==a[4])){
			cout << "two pair" << endl;
		} else if(a[1]==a[2] && a[3]==a[4]){
			cout << "two pair" << endl;
		} else if(a[0]==a[1]||a[1]==a[2]||a[2]==a[3]||a[3]==a[4]){
			cout << "one pair" << endl;
		} else if(a[0]==1&&a[1]==10&&a[2]==11&&a[3]==12&&a[4]==13){
			cout << "straight" << endl;
		} else if(a[0]+1==a[1]&&a[0]+2==a[2]&&a[0]+3==a[3]&&a[0]+4==a[4]){
			cout << "straight" << endl;
		} else {
			cout << "null" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#Educational DP Contest
#H-Grid1


h,w = map(int,input().split())
maze = [list(list(input())) for i in range(h)]
mod = 10**9+7


#dp table
#座標をそのままdpテーブルとして見立てることができる。
#要素はその場所まで行ける手順の数
dp = [[0]*w for _ in range(h)]
dp[0][0] = 1

#process1
#移動は→↓の２通りのみなので、その方向に探索していけば良い。
for i in range(h):
    for j in range(w):
        if maze[i][j] == "#":
            continue
        if i > 0: #i-1を参照するため端っこは除く
            dp[i][j] += dp[i-1][j]
        if j > 0:
            dp[i][j] += dp[i][j-1]
        dp[i][j] %= mod


#output process
print(dp[-1][-1])

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

using namespace std;
const long long MAX=1e15;

int main(){
  long long k, a[100009];
  cin >> k;
  for(int i=0;i<k;i++)cin >> a[i];
  long long l=2, r=2;
  for(int i=k-1;i>=0;i--){
    long long x=((l-1)/a[i]+1)*a[i];
    long long y=r/a[i]*a[i];
    if(y<x){
      cout << -1 << endl;
      return 0;
    }
    l=x;
    r=y+a[i]-1;
  }
  cout << l << ' ' << r << endl;
}



Measured memory_bytes: 4392
#include <iostream>
#include <set>

using namespace std;

int main() {
    int n, m; cin >> n >> m;
    int arr[1001];
    float sum = 0;
    for (int i = 0; i < n; i ++){
        cin >> arr[i];
        sum += arr[i];
    }

    int cnt = 0;
    float res = (float)sum / (4*m);
    for (int i = 0; i < n; i ++){
        if (arr[i] >= res) cnt++;
    }

    if (cnt >= m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}



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

using namespace std;

int main(){
    int n;
    cin >> n;
    string S;
    cin >> S;
    auto T = S;
    sort(T.begin(), T.end());

    int ans = 0;
    for (int i = 0; i < n; i++){
        if (S[i] != T[i])
            ans++;
    }
    cout << ans / 2 << endl;
}

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

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    pair<int, int> p[5];

    int N, M;
    cin >> N >> M;
    rep(i, M)
    {
        cin >> p[i].first >> p[i].second;
    }

    int ans = -1;
    int i=pow(10, N-1);
    i = i==1?0:i;
    for(; i<pow(10,N);++i)
    {
        string s = to_string(i);
        int len = s.length();
        bool judge = true;
        rep(j, M)
        {
            if(s[p[j].first-1] != (p[j].second + '0'))
            {
                judge = false;
                break;
            }
        }
        if(judge)
        {
            ans = i;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
N=int(input())
S=[input() for i in range(N)]



a=0
w=0
t=0
r=0
for s in S:
  if s=='AC':
    a+=1
  if s=='WA':
    w+=1
  if s=='TLE':
    t+=1
  if s=='RE':
    r+=1

print('AC x',a)
print('WA x',w)
print('TLE x',t)
print('RE x',r)

Measured memory_bytes: 16176
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            var X = GetInt();

            var max = 1;
            for (int i = 2; i <= X; i++)
            {
                for(int j = 2; j <= 10; j++)
                {
                    if (Math.Pow(i, j) > X) break;
                    max = Math.Max(max, (int)Math.Pow(i, j));
                }
            }

            Console.WriteLine(max);
            Console.ReadKey();
        }

        static void Solve()
        {
        }


        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c, out V d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<V>(ar[3]);
        }
    }
}

Measured memory_bytes: 11220
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,m,v,p,a[100010];
vector<int> res;

inline bool check(int x)
{
	int val=n-x+1;
	int cnt=max(0ll,v-val);
	if(cnt<p) return a[x]+m>=a[p];
	if(a[x]+m<a[p]) return false;
	cnt-=p-1;
	int sum=0ll;
	for(int i=p;i<x;i++) sum+=(a[x]+m-a[i]);
	if(sum<m*cnt) return false;
	return true;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m>>v>>p;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	int l=p+1,r=n,ans=p;
	while(l<=r){
		int mid=(l+r)/2;
		if(check(mid)){
			ans=mid;
			l=mid+1;
		}
		else r=mid-1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
#define MP make_pair
#define PB push_back
typedef long long ll;

int N, K;
ll ans = 1;

ll inv (ll a) {
        ll e = MOD-2, r = 1ll;
        while (e) {
                if (e&1) r = r * a % MOD;
                e /= 2, a = a * a % MOD;
        }
        return r;
}

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

        ll x = (ll) N-K+1;

        if (K != 1) {


                ans = x % MOD;
                for (ll i = (ll) K; i < (ll) K + (K-2); i++) {
                        ans = ans * (x+i) % MOD;
                }
                for (ll i = 1ll; i < (ll) K; i++) ans = ans * inv(i) % MOD;

        }
        if (x > 2) {
                for (ll i = 0; i < x-2; i++) ans = ans * 2 % MOD;
        }


        printf("%lld\n", ans);

        return 0;
}



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

bit = [0] * 62

for a in al:
    for i in range(62):
        bit[i] += (a % 2)
        a = a // 2

ans = 0
p = 1
for i in range(62):
    ans += bit[i] * (n - bit[i]) * p
    ans %= 10**9 + 7
    p *= 2

print(ans)

Measured memory_bytes: 122936
#include<stdio.h>
#include<stdlib.h>

int comp(const void *a, const void *b){
  return *(int *)a - *(int *)b;
}

int main(void){
  int n, sumEdge = 0;
  int *e;
  scanf("%d", &n);
  e = malloc(sizeof(int)*n);
  for(int i=0;i<n;i++){
    scanf("%d", e+i);
  }
  qsort(e, n, sizeof(int), comp);
  for(int i=0;i<n-1;i++) sumEdge += e[i];
  if(sumEdge > e[n-1]) printf("Yes\n");
  else printf("No\n");

  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstring>
#include <cassert>


typedef long long ll;
using namespace std;

#define mod 1000000007
#define INF 1000000000 //(int)1e9
#define LLINF 8000000000000000000 //(ll)2e18
#define PI  3.1415926536

#define SIZE 510



int main(){
    int n,m;
    int k,s,h,sum_h;
    int pot[210][410];
    int dp[210][210];
    int dp2[210];
    
    scanf("%d%d",&n,&m);
    
    for(int i=0;i<n;i++){
        pot[i][0] = 0;
        for(int j=1;j<=400;j++){
            pot[i][j] = INF;
        }
        
        
    }
    
    for(int i=0;i<=n;i++){
        for(int j=0;j<=210;j++){
            dp[i][j] = INF;
            dp2[j] = INF;
        }
    }
    
    for(int i=0;i<n;i++){
        sum_h = 0;
        
        scanf("%d",&k);
        
        for(int j=0;j<k;j++){
            scanf("%d%d",&s,&h);
            
            for(int l=0;l<h;l++){
                pot[i][l+sum_h+1] = pot[i][l+sum_h] + s;
            }
            
            sum_h += h;
        }
    }
    
    dp[0][0]=0;
    
    for(int i=0;i<n;i++){
        
        
        for(int j=0;j<=200;j++){
            if(pot[i][j]==INF) continue;
            
            for(int l=200-j;l>=0;l--){
                dp[i+1][l+j] = min(dp[i+1][l+j],dp[i][l]+pot[i][j]);
            }
        }
    }
    
    for(int i=0;i<=m+1;i++){
        for(int j=0;j<=n;j++){
            dp2[i] = min(dp2[i],dp[j][i]);
        }
    }
    
    int ans=0;
    
    for(int i=0;i<=m+1;i++){
        if(dp2[i]<=m){
            ans = i;
        }
    }
    
    double ans2;
    
    if(dp2[ans]==m || dp2[ans+1]==INF || dp[ans+1]-dp[ans]==0)
        ans2 = ans;
    else
        ans2 = ans + (double)(m-dp2[ans])/(dp2[ans+1]-dp2[ans]);
    
    printf("%.10lf\n",ans2);
    
}

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

int main() {
    int n;
    cin >> n;
    int max_h = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int h;
        cin >> h;
        if (max_h <= h) {
            max_h = h;
            ans++;
        }
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
const int INF = (1LL<<30);
const ll LLINF = (1LL<<60);
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

string str = "codefestival2017";
signed main(void)
{
  string s;
  cin >> s;
  if(s.substr(0, 4) == "YAKI") cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int n, h, w; cin >> n >> h >> w;
    cout << (n-h+1)*(n-w+1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
	long long N;
	cin >> N;
	int max = int(sqrt(N));

	int fmin_other = 1; 
	for (int i = 2; i < max + 1; i++) {
		if (N % i == 0) {
			fmin_other = i;
		}
	}

	int fmin = N / fmin_other;
	int keta = 0;
	for (int i = 1; i < N * 10 + 1; i = i * 10) {
		keta++;
		if (fmin / i == 0) {
			cout << keta - 1 << endl;
			break;
		}
	}
	return 0;
}



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

typedef long long ll;

#define REP(i, n) for(int i=0; i<(n); i++)
#define REPS(i, n) for(int i=0; i<=(n); i++)
#define FOR(i, a, b) for(int i=a; i<(b); i++)
#define FORS(i, a, b) for(int i=a; i<=(b); i++)
// for container x
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int main(){
    int N, A, B;
    cin >> N >> A >> B;

    cout << min(A*N, B) << endl;
    return 0;
}

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

int main(){
    int N;
    int top[110], bottom[110];
    int temp;
    int high = 0;

    cin >> N;
    for(int i=0; i<2; i++){
        for(int j=0; j<N; j++){
            if(i == 0) cin >> top[j];
            else cin >> bottom[j];
        }
    }

    for(int i=0; i<N; i++){
        temp = 0;
        for(int T=0; T<=i; T++){
            temp += top[T];
        }
        for(int B=i; B<N; B++){
            temp += bottom[B];
        }
        high = max(high, temp);
    }

    cout << high << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

import numpy as np

N, W = map(int, input().rstrip().split(' '))

dp = np.zeros(W+1)
for i in range(N):
    w, v = map(int, input().rstrip().split(' '))
    dp[w:] = np.max(np.vstack([dp[w:], dp[:-w] + v]), axis=0)
    
    
print(int(max(dp)))


Measured memory_bytes: 16980
#include<iostream>
#include<string>
//#include<cmath>
//#include<array>
#include<algorithm>
//#include<deque>
#include<vector>
//#include<utility>
//#include<set>
//#include<map>
//#include<list>
//#include<bitset>

using namespace std;
using LLI = long long int;
LLI N;

//array<int, 8>dir_x = { 0,0,1,1,1,-1,-1,-1 };
//array<int, 8>dir_y = { 1,-1,1,0,-1,1,0,-1 };
//array<int, 4>dir_x2 = { 0,0,1,-1 };
//array<int, 4>dir_y2 = { 1,-1,0,0 };
//char alp[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

LLI gcd(LLI x, LLI y) {
	LLI  r;
	if (x < y) {
		swap(x, y);
	}
	r = x % y;
	while (r != 0) {
		x = y;
		y = r;
		r = x % y;
	}
	return y;
}
LLI lcm(LLI x, LLI y) {
	return x / gcd(x, y) * y;
}

long nCr(int n, int r) {
	long ans = 1;
	for (int i = n; i > n - r; i--) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; i++) {
		ans = ans / i;
	}
	return ans;
}

//const int n_max = 8;
//array<array<bool, n_max>, n_max>graph;
//int dfs(int v,int N,array<bool,n_max>visited) {
//	int ret = 0;
//	bool all_visited = true;
//	for (int i = 0; i < N;i++) {
//		if (visited[i] == false) {
//			all_visited = false;
//		}
//	}	
//	if (all_visited) {
//		return 1;
//	}
//	for (int i = 0; i < N;i++) {
//		if (graph[v][i] == false) {
//			continue;
//		}
//		if (visited[i] == true) {
//			continue;
//		}
//		visited[i] = true;
//		ret += dfs(i,N,visited);
//		visited[i] = false;
//	}
//	return ret;
//}

//vector<vector<int>>sub;
//int dfs(int id) {
//	if (sub[id].size() == 0) {
//		return 1;
//	}
//	int minP = (int)1e9;
//	int maxP = 0;
//	for (int i : sub[id]) {
//		int P = dfs(i);
//		minP = min(minP, P);
//		maxP = max(maxP, P);
//	}
//	return minP + maxP + 1;
//}

//#define debug(x) cerr << #x << " : " << x << endl
//#define debugv(x) cerr << #x << " : "; for(auto i:x) cerr << i << ", "; cerr<<endl

int main(void) {
	string S;
	LLI sum = 0, MAX, MIN;
	cin >> N;
	LLI fir = 0, sec = 0, firsec = 0;
	for (int i = 0; i < N; i++) {
		cin >> S;
		for (int j = 0; j < S.size() - 1; j++) {
			if (S[j] == 'A' && S[j + 1] == 'B') {
				sum++;
			}
		}
		if (S[S.size() - 1] == 'A' && S[0] == 'B') {
			firsec++;
		}
		if (S[0] == 'B') {
			sec++;
		}
		if (S[S.size() - 1] == 'A') {
			fir++;
		}
	}
	MIN = min(fir, sec);
	MAX = max(fir, sec);
	if (MAX == firsec && MAX != 0) {
		sum--;
	}
	sum += MIN;
	cout << sum << endl;
}

Measured memory_bytes: 256
a=input()
l=len(a)
if(l<=3):
    b=abs(753-int(a))
    print(b)
else:
    b=[0]*(l-2)
    for i in range(0,l-2):
        b[i]=abs(753-int(a[i]+a[i+1]+a[i+2]))
    print(min(b))


Measured memory_bytes: 3060
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        
        ArrayDeque<Integer>[] a = new ArrayDeque[n];
        for(int i=0; i<n; i++){
            a[i] = new ArrayDeque<>();
            for(int j=0; j<n-1; j++){
                a[i].offer(Integer.parseInt(sc.next())-1);
            }
        }
        
        int[] step = new int[n];
        Arrays.fill(step, -1);
        ArrayDeque<Integer> q = new ArrayDeque<>();
        for(int i=0; i<n; i++){
            q.add(a[i].peek());
        }
        
        int ans = 0;
        int cnt = 0;
        while(q.size()!=0){
            ArrayDeque<Integer> q2 = new ArrayDeque<>();
            while(q.size()!=0){
                int idx = q.poll();
                if(step[idx]<ans && !a[idx].isEmpty()){
                    int idx2 = a[idx].peek();
                    if(a[idx2].peek() == idx && step[idx2]<ans){
                        step[idx] = ans;
                        step[idx2] = ans;
                        q2.add(idx);
                        q2.add(idx2);
                        a[idx].poll();
                        a[idx2].poll();
                        cnt++;
                    }
                }
            }
            q = q2;
            ans++;
            if(cnt==n*(n-1)/2){
                break;
            }
        }
        
        if(cnt==n*(n-1)/2){
            System.out.println(ans);
        }else{
            System.out.println(-1);
        }
    }
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin >> k;
    string s;
    cin >> s;
    if(s.length() <= k) {
        cout << s;
    } else {
        for(int i=0; i<k; i++) {
            cout << s[i];
        }
        cout << "...";
    }
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <queue>
#include <vector>
#include <limits>
using namespace std;
template <typename T, bool directed>
class Dinic
{
public:
  Dinic(int n) : n(n), capacity(n, vector<T>(n)) {}
  void add_edge(int src, int dst, T cap)
  {
    capacity[src][dst] = cap;
    capacity[dst][src] = directed ? 0 : cap;
  }

  T max_flow(int s, int t)
  {
    T flow = 0;
    while (bfs(s, t))
    {
      start.assign(n, 0);
      flow += dfs(t, s, numeric_limits<T>::max());
    }
    return flow;
  }

private:
  int n;
  vector<int> level, start;
  vector<vector<T>> capacity;
  bool bfs(int s, int t)
  {
    level.assign(n, -1);
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while (!que.empty())
    {
      int v = que.front();
      que.pop();
      for (int nv = 0; nv < n; ++nv)
        if (capacity[v][nv] > 0 && level[nv] < 0)
        {
          level[nv] = level[v] + 1;
          que.push(nv);
        }
    }
    return level[t] != -1;
  }

  T dfs(int v, int s, T limit)
  {
    if (v == s)
      return limit;

    T res = 0;
    for (int &nv = start[v]; nv < n; ++nv)
    {
      if (capacity[nv][v] > 0 && level[v] == level[nv] + 1)
      {
        T d = dfs(nv, s, min(limit, capacity[nv][v]));
        if (d > 0)
        {
          capacity[nv][v] -= d;
          capacity[v][nv] += d;
          res += d;
          limit -= d;
          if (limit == 0)
            break;
        }
      }
    }
    return res;
  }
};

int main()
{
  int N;
  cin >> N;
  int a[100], b[100], c[100], d[100];
  Dinic<int, true> dn(N * 2 + 2); // 二部グラフ + 始点(N*2) + 終点(N*2+1)
  for (int i = 0; i < N; ++i)
    cin >> a[i] >> b[i];
  for (int i = 0; i < N; ++i)
    cin >> c[i] >> d[i];
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < N; ++j)
      if (a[i] < c[j] && b[i] < d[j])
        dn.add_edge(i, N + j, 1);
  for (int i = 0; i < N; ++i)
  {
    dn.add_edge(N * 2, i, 1);
    dn.add_edge(N + i, N * 2 + 1, 1);
  }
  cout << dn.max_flow(N * 2, N * 2 + 1) << endl;
  return 0;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n = int(input())
memo = [[0 for _ in range(10)] for j in range(10)]

for i in range(1, n + 1):
    s = str(i)
    le = len(s)
    t1 = s[0]
    t2 = s[le - 1]
    memo[int(t1)][int(t2)] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += memo[i][j] * memo[j][i]

print(ans)


Measured memory_bytes: 73516
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int x,y,z;
  cin>>x>>y>>z;
  vector<string> vs;
  for(int i=0;i<x;i++) vs.emplace_back("a");
  for(int i=0;i<y;i++) vs.emplace_back("b");
  for(int i=0;i<z;i++) vs.emplace_back("c");
  while(vs.size()>1u){
    sort(vs.begin(),vs.end());
    vs.front()+=vs.back();
    vs.pop_back();
  }
  cout<<vs.front()<<endl;
  return 0;
}


Measured memory_bytes: 256
func LI() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func I() -> Int {
    return Int(readLine()!)!
}

func S() -> String {
    return readLine()!
}

let line = LI()
print(max(0,line[0]-2*line[1]))

Measured memory_bytes: 8240
import math

def a():
    x = int(input())
    
    if x < 600:
        print(8)
    elif x<800:
        print(7)
    elif x<1000:
        print(6)
    elif x<1200:
        print(5)
    elif x<1400:
        print(4)
    elif x<1600:
        print(3)
    elif x<1800:
        print(2)
    else:
        print(1)

def b():
    a,b,c = map(int,input().split())
    k = int(input())
    count = 0
    
    while b<= a:
        b *= 2
        count += 1
    
    while c<=b:
        c *= 2
        count += 1
    if count <= k:
        print('Yes')
    else:
        print('No')
    


def c():
    n,k=map(int,input().split())
    a=list(map(int,input().split()))

    for i in range(k,n):
        if a[i] > a[i-k]:
            print('Yes')
        else:
            print('No')



def d():
    pass


# a()
# b()
c()
# d()

Measured memory_bytes: 31852
MOD = 10**9 + 7
N, K = map(int, input().split())
arr = list(map(int, input().split()))
tmp = 0
for i in range(N):
    for k in range(i,N):
        if i == k:
            continue
        if arr[i] > arr[k]:
            tmp += 1
tmp2 = 0
for i in range(N):
    for k in range(N):
        if i == k:
            continue
        if arr[i] > arr[k]:
            tmp2 += 1
print((tmp*K+(((K-1)*K)//2)*tmp2)%MOD)

Measured memory_bytes: 3188
#include<stdio.h>
int main()
{
    int a[33]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51},n,i;
    scanf("%d",&n);
    printf("%d\n",a[n-1]);
    return 0;

}


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

template <class t>
using vc = vector<t>;
template <class t>
using vvc = vector<vector<t>>;
typedef long long ll;
typedef vc<int> vi;
typedef vvc<int> vvi;
typedef pair<int, int> pi;

#define uset unordered_set
#define umap unordered_map

#define endl "\n"

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()

#define all(a) a.bg, a.ed

template <class t, class u>
ostream &operator<<(ostream &os, const pair<t, u> &p) {
    return os << "( " << p.first << ", " << p.second << " )";
}

template <class t>
ostream &operator<<(ostream &os, const vc<t> &v) {
    os << "[ ";
    for (int i = 0; i < v.size(); i++) {
        os << v[i];
        if (i != v.size() - 1) {
            os << ", ";
        }
    }
    return os << " ]";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // cout << fixed << setprecision(18);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution

    // TODO had to look at editorial

    long long q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    long long best_1_price = min(min(4 * q, 2 * h), s);
    if (2 * best_1_price <= d) {
        cout << best_1_price * n;
    } else {
        if (n % 2) {
            cout << ((n - 1) / 2) * d + best_1_price;
        } else {
            // Even
            cout << (n / 2) * d;
        }
    }
}


Measured memory_bytes: 3624
#include <iostream>

int main(){
	int size;
	int *array;
	std::cin>>size;
	array=new int[size];
	for(int i=0;i<size;i++){
		std::cin>>array[i];
	}
	for(int i=size-1;i>=0;i--){
		std::cout<<array[i]<<(i?" ":"");
	}
	std::cout<<std::endl;
	delete[] array;
	return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {
    int N; cin >> N;
    int K; cin >> K;

    vector<int> d(K);

    vector<vector<int>> A(100, vector<int>(100));

    rep(i, K) {
        cin >> d[i];
        rep (j, d[i]) cin >> A[i][j];
    }

    vector<int> B(N);
    rep(i, N) B[i] = 0;

    rep(i, K) rep(j, d[i]) {
        B[A[i][j] - 1]++; 
    }

    int count = 0;
    rep(i, N) {
        if (B[i] != 0) count++;
    }

    int ans = N - count;
    cout << ans << endl;
    return 0;
}


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

int N, M;

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    cin >> N >> M;
    vector<int> Lang[M+1];
    for (int i = 0; i < N; i++) {
        int K;
        cin >> K;
        for (int j = 0; j < K; j++) {
            int L;
            cin >> L;
            Lang[L].push_back(i);
        }
    }

    UnionFind uf(N);
    for (int i = 1; i <= M; i++) {
        for (int j = 1; j < Lang[i].size(); j++) {
            uf.unite(Lang[i][0], Lang[i][j]);
        }
    }

    bool f = true;
    for (int i = 1; i < N; i++) {
        if (!uf.same(0, i)) {
            f = false;
            break;
        }
    }

    cout << (f ? "YES" : "NO") << endl;

    
    return 0;
}


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

int main() {
  int n, k, ans = 1;
  cin >> n >> k;
  while (n / k != 0) {
    n /= k;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] line = Console.ReadLine().Split(' ');
            string ans = "";
            for(int i = 0; i < 3; i++)
            {
                ans += line[i][0];
            }
            Console.WriteLine(ans.ToUpper());
        }
    }
}

Measured memory_bytes: 13140
def check(a,b):
  if a<b:
    return 'up'
  if a>b:
    return 'down'
  return ''

def solve():
  ans = 1
  N = int(input())
  A = list(map(int, input().split()))
  ud = ''
  for i in range(N-1):
    a = check(A[i],A[i+1])
    if ud=='' or ud==a:
      ud = a
      continue
    if a=='':
      continue
    ans += 1
    ud = ''
  return ans
print(solve())

Measured memory_bytes: 19992
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  long long sum=0;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    if(i%3!=0 && i%5!=0)
    {

      sum=sum+i;
    }
  }
  cout<<sum;
}

Measured memory_bytes: 3636
import java.util.Arrays;
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 = new int[N];
        for (int i = 0; i < A.length; ++i) {
            A[i] = sc.nextInt();
        }

        System.out.println(solve(A));

        sc.close();
    }

    static int solve(int[] A) {
        return Arrays.stream(A).max().getAsInt() - Arrays.stream(A).min().getAsInt();
    }
}

Measured memory_bytes: 28244
/*
                                Author: Ankit Kaul
**********************Code Belongs to Respective Author Only************************************
*/
 
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/

#include <bits/stdc++.h>

#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define inf         INT_MAX
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
 
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x) % M;
        x=(x*x)% M;
        n=n/2;
    }
    return result % M;
}
signed main()
{   jaldi
	int n;
	cin>>n;
	string str;
	cin>>str;
	if(n>=3200)
	cout<<str;
	else
	cout<<"red";
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static Stack<Integer> stack = new Stack<Integer>();
	static int train_number;
	static int How_many_trains = 0;
	public static void main(String[] args) {
		read();
	}
	
	static boolean read(){
		train_number = sc.nextInt();
		stack.push(train_number);
		while(sc.hasNextInt()){
			train_number = sc.nextInt();
			if(train_number == 0){
				System.out.println(stack.pop());
			}else{
				stack.push(train_number);
			}
		}
		return true;
	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vll = vector<ll>;
using vdouble = vector<double>;
using vstr = vector<string>;
typedef pair<int,int> P;
int dx[4] = {1, 0, -1, 0},dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
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 ll INF = 1LL << 60;
const ll mod = 1000000007;

int main(){
	//入力
	ll H,W,ans;
	cin>>H>>W;
    if(H==1||W==1){
      cout<<1<<endl;
      return 0;
    }
	if(H%2==0){
        ans=W*H/2;
	}
	else{
		if(W%2==0){
          ans=H*W/2;
		}
		else{
          ans=H*(W+1)/2-(H-1)/2;
		}
	}
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>	//cin, cout
#include <vector>	//vector
#include <algorithm> //sort,min,max,count
#include <string>	//string,getline, to_string
#include <ios>		//fixed
#include <iomanip>	//setprecision
#include <utility> //swap, pair
#include <cstdlib>	//abs(int)
#include <cmath>	//sqrt,ceil,M_PI, pow, sin
#include <sstream>	//stringstream,getline
#include <numeric>	//gcd, accumlate
#include <deque>	//deque
#include <random>	//randam_device

using namespace std;
constexpr long long int D_MOD = 1000000007;

int main() {

	int a, b;
	cin >> a >> b;

	if (a >= 13) {
		cout << b << endl;
	}
	else if (a >= 6) {
		cout << b / 2 << endl;
	}
	else {
		cout << 0 << endl;
	}

	return 0;

}

Measured memory_bytes: 3584
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int main ()
{
    int N, M;
    cin >> N >> M;
    vector<int> a (M);
    int64_t sum = 0;
    for (int i = 0; i < M; i++) {
        cin >> a[i];
        sum += a[i];
    }
    if (N < sum) {
        cout << -1;
    } else {
        cout << N - sum;
    }
}


Measured memory_bytes: 3636
inputto = input().split()
x1 = int(inputto[0])
y1 = int(inputto[1])
x2 = int(inputto[2])
y2 = int(inputto[3])
x3=str(x2-(y2-y1))
y3=str(y2-(x1-x2))
x4=str(int(x3)+(x1-x2))
y4=str(int(y3)-(y2-y1))
print(x3+" "+y3+" "+x4+" "+y4)

Measured memory_bytes: 3064
n, c, k = list(map(int, input().split()))
t = [int(input()) for i in range(n)]
t.sort()

limit = t[0] + k
num = 1
cnt = 1
for i in range(1, n):
  if limit < t[i] or num == c:
    num = 1
    limit = t[i] + k
    cnt += 1
  
  else:
    num += 1
print(cnt)

Measured memory_bytes: 13380
n,m,l = [int(x) for x in input().split()]
A = [[int(x) for x in input().split()] for _ in range(n)]
B = [[int(x) for x in input().split()] for _ in range(m)]
ans = []
for i in range(n):
    blocks = []
    for j in range(l):
        block = 0
        for k in range(m):
            block += A[i][k]*B[k][j]
        blocks.append(block)
    ans.append(blocks)
for _ in ans:
    print(*_)



Measured memory_bytes: 7056
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int dp[k+1]={0};
    for(int i=0;i<=k;i++)
    {
        int target=-1,flag=0;
        for(int j=0;j<n;j++)
        {
            if(i<arr[j])
            {
                target=j-1;
                flag=1;
                break;
            }
        }
        if(!flag)
         target=n-1;
        int j;
        for(j=0;j<=target;j++)
        {
            if(dp[i-arr[j]]==0)
            {
                dp[i]=1;
                break;
            }
        }
        if(j==target+1)
        {
            dp[i]=0;
        }
    }
    // for(int i=0;i<=k;i++)
    // {
    //     cout<<dp[i]<<" ";
    // }
    // cout<<endl;
    dp[k]==1?cout<<"First"<<endl:cout<<"Second"<<endl;
    //cout<<"Hello World!";
}


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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

template<int mod> struct modulo {
	int w;
	operator int&() { return w; }
	operator int() const { return w; }
	
	modulo() {}
	modulo(int w, bool f = 0) { this->w = w; if (f) fix(); }
	void inline fix() { if (w >= mod || w < -mod) w %= mod; if (w < 0) w += mod; }
	
	inline modulo  operator -  () { w = -w + mod; return *this; }
	inline modulo  operator +  (const modulo &b) { modulo r = *this; return r += b; }
	inline modulo  operator -  (const modulo &b) { modulo r = *this; return r -= b; }
	inline modulo  operator *  (const modulo &b) { return (num) w * b.w % mod; }
	inline modulo  operator /  (const modulo &b) { return *this * inv(b); }
	inline modulo& operator += (const modulo &b) { if ((w += b.w) >= mod) w -= mod; return *this; }
	inline modulo& operator -= (const modulo &b) { if ((w -= b.w) < 0) w += mod; return *this; }
	inline modulo& operator *= (const modulo &b) { return *this = *this * b; }
	inline modulo& operator /= (const modulo &b) { return *this /= inv(b); }
	
	friend inline modulo inv(const modulo &w) {
		int a = w, m = mod, u = 0, v = 1, t;
		for (; a != 0; t = m / a, m -= t * a, swap(a, m), u -= t * v, swap(u, v));
		return modulo(u, 1);
	}
	
	friend inline modulo pow(const modulo &w, int p) {
		if (!w)  return 0;
		modulo a = w, r = 1;
		for (; p > 0; a *= a, p >>= 1) if (p & 1) r *= a;
		return r;
	}
};
const int mod = int(1e9) + 7;
typedef modulo<mod> rem;

const int nsz = 5e5;
int n, dm, a[nsz + 5], pre[nsz + 5], c0[nsz + 5];
rem dp[nsz + 5][2], ans;
vector<int> p[1 << 21];

void inline init() {
	cont (i, n) pre[i] = pre[i - 1] ^ a[i], dm = max(dm, pre[i]);
	c0[0] = 1;
	cont (i, n) p[pre[i]].push_back(i);
	cont (i, n) {
		c0[i] = c0[i - 1] + (pre[i] == 0);
	}
}

int main() {
	scanf("%d", &n);
	cont (i, n) scanf("%d", &a[i]);
	init();
	
	if (pre[n] == 0) {
		cont (w, dm) {
			rem f0 = 1, f1 = 0;
			int p, pp = 0;
			loop (k, ::p[w].size()) {
				int p = ::p[w][k];
				f0 += f1 * rem(c0[p] - c0[pp]);
				f1 += f0;
				pp = p;
			}
			ans += f1;
		}
		ans += pow(rem(2), int(p[0].size()) - 1);
	} else {
		int w = pre[n];
		rem f0 = 1, f1 = 0;
		cont (i, n) {
			if (pre[i] == 0) f0 += f1;
			else if (pre[i] == w) f1 += f0;
		}
		ans = f0;
	}
	printf("%d\n", ans.w);
	return 0;
}

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

int main(){
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    cout<<(a[0]==5&&a[1]==5&&a[2]==7?"YES":"NO")<<endl;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
hm = list(map(int, input().split()))

# 夏休みはN日間です。
# 夏休みの宿題が M個 出されており、i番目の宿題をやるには Ai日間 かかります。
# 高橋君が遊ぶことのできる日数、または、-1 を出力せよ。

if N - sum(hm) < 0:
    print("-1")
else:
    print(N - sum(hm))

Measured memory_bytes: 9908
import copy
N = int(input())
A = [int(input()) for _ in range(N)]
a_copy = copy.deepcopy(A)
a_max = max(a_copy)
a_copy.remove(a_max)
b_max = max(a_copy)

for i in A:
    if i == a_max:
        print(b_max)
    else:
        print(a_max)

Measured memory_bytes: 14568
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const int INF = 1 << 30;
const uint64_t MOD = 1000000000 + 7;

struct Info
{
	int id;
	int p;
	int y;
	int s;

	Info()
	{

	}

	Info(int a, int b, int c)
	{
		id = a;
		p = b;
		y = c;
	}
};

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

	vector<Info> a(m);
	for (int i = 0; i < m; i++)
	{
		int p, y;
		cin >> p >> y;
		a.at(i) = Info(i, p, y);
	}

	sort(a.begin(), a.end(), [](const Info &a, const Info &b)
	{
		return a.y < b.y;
	});

	vector<int> p(n);
	for (int i = 0; i < m; i++)
	{
		a.at(i).s = ++p.at(a.at(i).p - 1);
	}

	sort(a.begin(), a.end(), [](const Info &a, const Info &b)
	{
		return a.id < b.id;
	});

	
	for (int i = 0; i < m; i++)
	{
		cout << setw(6) << setfill('0') << a.at(i).p;
		cout << setw(6) << setfill('0') << a.at(i).s << endl;
	}
}

Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

long long int L, R;

int main(void) {

	cin >> L >> R;

	if (R - L >= 2019) { cout << 0 << endl; return 0; }


	long long int ans = 9999;
	for (long long int i = L; i <= R; i++) {
		for (long long int j = i + 1; j <= R; j++) {
			ans = min(ans, (i*j) % 2019);
		}
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
	ll A, B, C;
	scanf("%lld%lld%lld", &A, &B, &C);
	if(A * B * C % 2 == 0) { puts("0"); return 0; }
	printf("%lld\n", min(A * min(B, C), B * C));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>

using namespace std;

constexpr long long mod = static_cast<long long>(1e9 + 7);

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

    long long ans = 0;
    if (N == 0)ans = 2;
    else if(N == 1)ans = 1;
    else {
        long long a = 2, b = 1;
        while(N-- > 1) {
            ans = a + b;
            a = b;
            b = ans;
        }
    }

    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S1 = readline().strip()
    S2 = readline().strip()

    if S1[0] == S2[0]:
        ans = 3
        i = 1
    else:
        ans = 6
        i = 2

    while i < N:
        if S1[i] == S2[i]:
            if S1[i - 1] == S2[i - 1]:
                ans = ans * 2 % MOD
            i += 1
        else:
            if S1[i - 1] == S2[i - 1]:
                ans = ans * 2 % MOD
            else:
                ans = ans * 3 % MOD
            i += 2

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9224