akhauriyash/Code-Regression huggingface dataset:
import sys
read = sys.stdin.read
from collections import defaultdict
def main():
    n = int(input())
    x = list(input())
    # 0除算よけ。
    if n == 1:
        if x[0] == '1':
            print(0)
        else:
            print(1)
        sys.exit()
    # xの10進数換算と１の数カウント。
    x10 = int("".join(x), 2)
    xcount1 = x.count('1')
    # 2**i(mod 1の数)をケースごとに用意する。
    mod2plus = [0] * n
    mod2plus[0] = (1 % (xcount1+1)) # 必ず1になる。xcount1=0はありえない。
    for j1 in range(1, n):
        mod2plus[j1] = (mod2plus[j1 - 1] * 2) % (xcount1+1)
    mod2minus = [0] * n
    if xcount1 > 1:
        mod2minus[0] = 1
        for j1 in range(1, n):
            mod2minus[j1] = (mod2minus[j1 - 1] * 2) % (xcount1-1)
    # x(mod 1の数)をケースごとに用意する。
    modx_plus = x10 % (xcount1 + 1)
    if xcount1 == 1:
        modx_minus = 0
    else:
        modx_minus = x10 % (xcount1 - 1)
    popcount = defaultdict(int)
    for i1 in range(n):
        if x[i1] == '1':
            if xcount1 == 1:
                print(0)
                continue
            else:
                x3 = modx_minus - mod2minus[n - 1 - i1]
                if x3 < 0:
                    x3 += (xcount1 - 1)
                elif x3 > (xcount1 - 1):
                    x3 -= (xcount1 - 1)
                elif x3 == (xcount1 - 1):
                    print(1)
                    continue
        else:
            x3 = modx_plus + mod2plus[n - 1 - i1]
            if x3 < 0:
                x3 += (xcount1 + 1)
            elif x3 > (xcount1 + 1):
                x3 -= (xcount1 + 1)
            elif x3 == (xcount1 + 1):
                print(1)
                continue
        r = 1
        while x3:
            r += 1
            if popcount[x3] == 0:
                p = bin(x3).count('1')
                popcount[x3] = p
                x3 = x3 % p
            else:
                x3 = x3 % popcount[x3]
        print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 95208
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100001

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // int T;cin>>T;while(T--) 
    {
        ll a,b;
        cin>>a>>b;
        ll x = max((a*(100/8)),(b*10)),tim=100000;
        while(tim--) {
            if((((x*8)/100))==a && (x/10)==b) {
                cout<<x<<endl;
                return 0;
            }
            x++;
        }
        cout<<"-1\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f(a, b) for (ll i = a; i <= b; i++)
#define pb push_back
#define pf push_front
#define mp make_pair
using namespace std;
#define N 100005
const int INF = 1000000001;
const int MOD = 998244353 ; //1e9+7;

//vector< vector<ll> > g(N);
//vector< pair<ll, pair< ll, ll > > > g(N);
//ll vis[N] = {0}, par[N] = {0}, child[N] = {0}, cnt = 0;

void solve(){
    ll n, w; cin >> n >> w;
    ll wt[n], v[n];
    f(0,n -1) cin >> wt[i] >> v[i];
    ll dp[n][w+1] = {0};
    f(0,w) {
        if(i < wt[0]) dp[0][i] = 0;
        else dp[0][i] = v[0]; 
    }
    for(ll i=1 ;i<n; i++){
        for(ll j=0; j<=w; j++){
            if(j < wt[i]) dp[i][j] = dp[i-1][j];
            else {
                dp[i][j] = max(v[i] + dp[i-1][j- wt[i]] , dp[i-1][j]);
            }
        }
    }
    cout << dp[n-1][w] << "\n";
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //ll t;cin >> t;for(ll index=1; index<=t; index++){
        //cout << "Case #" << index << ": " ;
        solve();
   // }
    return 0;
}

Measured memory_bytes: 81672
for e in iter(input,'0'):
 a=sorted([list(map(int,input().split()))for _ in[0]*int(e)],key=lambda x:x[0])
 b=sorted([tuple(map(int,input().split()))for _ in[0]*int(input())],key=lambda x:x[0])
 for s,t in b:
  u,v=a[0]
  x,y=s-u,t-v
  for u,v in a:
   if (u+x,v+y)not in b:break
  else:print(x,y)


Measured memory_bytes: 5980
/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define MAX 4003
#define mod 1000000007
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) cout<<"Case #"<<i<<": "
#define pf(a) printf("%lld\n",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define pfff(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define pffff(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp1,mp;
vector<pair<ll,pair<ll,ll> > >vpp,vpp1;
vector<pair<ll,ll> >vp,fin;
vector<ll>v1,v2,dummy;
map<pair<ll,ll>,bool>mbb;
map<ll,bool>mb;
ll n,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz,maxi;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
vector<ll>power;
int main()
{
    string arr[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string s;
    cin>>s;
    FOR(i,7LL)
    {
        if(arr[i]==s)
        {
            cout<<7-i<<endl;
            return 0;
        }
    }
}
/*
5
4
3
2
3
4
4
3
3
4
2
3
*/


Measured memory_bytes: 256
// D - Bouquet
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N,A,B;
ll MOD = 1000000007;

// a^n mod m を計算する(二分累乗法:O(logn))
ll modpow(ll a, ll n, ll m) {
	ll res = 1;
	while(n > 0){
		if(n & 1) res = res * a % m;
		a = a * a % m;
		n >>= 1;
	}
	return res;
}

// a^{-1} mod m : 逆元を求める(非再帰)
ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while(b){
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if(u < 0) u += m;
	return u;
}

// nCr mod m
ll nCr(ll n, ll r, ll m){
	ll a = 1, b = 1;
	for(ll i=0; i<r; ++i){
		a = a * (n-i) % m;
		b = b * (r-i) % m;
	}
	return a * modinv(b, m) % m;
}

ll solve(){
	ll sum_nCr = modpow(2, N, MOD) - 1;
	ll nca = nCr(N, A, MOD);
	ll ncb = nCr(N, B, MOD);
	ll ans = (sum_nCr - (nca + ncb)%MOD)%MOD;
	if(ans < 0L) ans += MOD;
	return ans;
}

int main(){
	cin>>N>>A>>B;
	cout<< solve() <<endl;
}

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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {
    bool is_equals = true;
    string s;
    cin >> s;

    reverse(s.begin(), s.end());
    for (int i=0; i<4; i++) reverse(divide[i].begin(), divide[i].end());

    for (int i=0; i < s.size();) {
        bool is_equal = false;
        for (int j=0; j<4; j++) {
            string d = divide[j];
            if (s.substr(i, d.size()) == d) {
                is_equal = true;
                i += d.size();
            }
        }
        if (!is_equal) {
            is_equals = false;
            break;
        }
    }
    if (is_equals) cout << "YES" << endl;
    else cout << "NO" << endl;

}



Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,r) RFOR(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define lower(a,x) lower_bound(all(a), x) - a.begin();
#define COUNT(a,x)  upper_bound(all(a), x) - lower_bound(all(a), x);
#define MCOUNT(a,x,y) upper_bound(all(a), y) - lower_bound(all(a), x);
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end());
#define scan(x) scanf("%lld",&x);
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
typedef double D;
const ll inf = 5555555555555555555;
const ll mod = 1000000007;
const D pi = acos(-1);
const D eps = 1e-10;

ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool ok, flag;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111


int main(void) {
  cin >> s;
  cin >> n;
  ll len = s.length();
  rep(i, len) {
	cnt = (26 - s[i] + 'a') % 26;
	if (n >= cnt) {
	  s[i] = 'a';
	  n -= cnt;
	}
  }

  if (n > 0) {
	n %= 26;
	cnt = s[len - 1] - 'a';
	s[len - 1] = 'a' + (n + cnt) % 26;
  }
  cout << s << endl;

  return 0;
}

Measured memory_bytes: 512
def f(n, count=0, i=0, lst=[]):
    global ans
    if count == n:
        s = ""
        for j in range(count):
            s += chr(ord("a") + lst[j])
        ans.append(s)
        return
    if i == 0:
        lst.append(i)
        f(n, count + 1, i=i+1, lst=lst)
    else:
        for j in range(i + 1):
            f(n, count + 1, i=max(i, j + 1), lst=lst+[j])

import sys
sys.setrecursionlimit(10000)
n = int(input())
ans = []
f(n)
ans.sort()
for i in ans:
    print(i)

Measured memory_bytes: 12680
function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	//input = input.trim().split(" ");
	input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  var Wmax = parseInt(input[0].split(" ")[0]);
  var Hmax = parseInt(input[0].split(" ")[1]);
  var N = parseInt(input[0].split(" ")[2]);
  var Wmin = 0;
  var Hmin = 0;
  for(var i = 1; i <= N ; i++){
    var tmp = input[i].split(" ").map((a)=>Number(a));
    var a = tmp[2];
    switch(a){
      case 1:
        Wmin = Math.max(Wmin,tmp[0]);
        break;
      case 2:
        Wmax = Math.min(Wmax,tmp[0]);
        break;
      case 3:
        Hmin = Math.max(Hmin,tmp[1]);
        break;
      case 4:
        Hmax = Math.min(Hmax,tmp[1]);
        break;
    }
  }
  if(Wmin <= Wmax && Hmin <= Hmax){
    myout((Wmax - Wmin) * (Hmax - Hmin)); 
    
  }else{
    myout("0");
  }
}

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


Measured memory_bytes: 7500
n = int(input())
h = list(map(int,input().split()))
count = [0] * n
MAX = 0

j = 0
for i in range(j,n-1):
	if h[i] >= h[i+1]:
		count[j] += 1
	else:
		j += 1

for i in range(n):
	if MAX < count[i]:
		MAX = count[i]
	i = count[i] + 2

print(MAX)


Measured memory_bytes: 15020
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

namespace AOJ
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        class node
        {
            public List<long> ko = new List<long>();
            public long oya = -1;
            public long dpth = 0;
        }
        static void Main(string[] args)
        {
            var N = Sarray()[0];
            var nodes = new node[N];
            for (var i = 0; i < N; ++i)
                nodes[i] = new node();
            for (var i = 0; i < N; ++i)
            {
                var ninfo = Slist();
                for (var j = 2; j < ninfo.Count; ++j)
                {
                    nodes[ninfo[0]].ko.Add(ninfo[j]);
                    nodes[ninfo[j]].oya = ninfo[0];
                }
            }
            var root = -1;
            for (var i = 0; i < N; ++i)
            {
                if (nodes[i].oya == -1)
                {
                    root = i;
                    nodes[i].dpth = 0;
                    break;
                }
            }
            var q = new Queue<long>();            
            q.Enqueue(root);
            while (q.Any())
            {
                var n = q.Dequeue();
                if (n != root)
                { nodes[n].dpth = nodes[nodes[n].oya].dpth + 1; }
                foreach (var k in nodes[n].ko)
                { q.Enqueue(k); }
            }
            for(var i=0;i<N;++i)
            {
                var sts = nodes[i].oya == -1 ? "root" : nodes[i].ko.Count == 0 ? "leaf" : "internal node";
                var ch = string.Join(", ", nodes[i].ko);
                WriteLine($"node {i}: parent = {nodes[i].oya}, depth = {nodes[i].dpth}, {sts}, [{ch}]");
            }
        }
    }
}


Measured memory_bytes: 40940
#include <bits/stdc++.h>
using namespace std;
int main(){
	int k;
	cin>>k;
	if(k % 2 == 0){
		cout<<(k/2) * (k / 2);
		return 0;
	}
	else cout<<(k / 2 + 1) * (k / 2);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
   char b,answer;
   scanf("%c",&b);
   if(b=='A')
   {
       answer='T';
   }else if(b=='T')
   {
       answer='A';
   }else if(b=='C')
   {
       answer='G';
   }else if(b=='G')
   {
       answer='C';
   }
   printf("%c",answer);
    return 0;
}

Measured memory_bytes: 256
/* ファイル名：ITP1_7_A.c	*/
/* 内容：あるクラスの数学の成績を付ける。									*/
/*		 中間試験と期末試験は 50 点満点、再試験は 100 点満点とする。		*/
/*		 試験を受けていない場合は点数を -1 とする。							*/
/*		 以下の手順で成績を付ける											*/
/*		 ・中間試験、期末試験のいずれかを欠席した場合成績は F。				*/
/*		 ・中間試験と期末試験の合計点数が 80 以上ならば成績は A 。			*/
/*		 ・中間試験と期末試験の合計点数が 65 以上 80 未満ならば成績は B。	*/
/*		 ・中間試験と期末試験の合計点数が 50 以上 65 未満ならば成績は C。	*/
/*		 ・中間試験と期末試験の合計点数が 30 以上 50 未満ならば成績は D。 ただし、再試験の点数が 50 以上ならば成績は C。*/
/*		 ・中間試験と期末試験の合計点数が 30 未満ならば成績は F。			*/

/* include	*/
#include <stdio.h>

/* 外部変数宣言	*/

/* プロトタイプ宣言	*/

/* 関数名:main	*/
/* 処理内容:あるクラスの数学の成績を付ける。	*/
int main( void )
{
	/* 内部変数定義	*/
	int m;	/* 中間試験	*/
	int f;	/* 期末試験	*/
	int r;	/* 再試験	*/
	
	/* 出力	*/
	char result;	/* 成績	*/
	
	/* 無限ループ	*/
	while(1){
		scanf("%d %d %d",&m,&f,&r);	/* テスト結果を入力	*/
		
		/* 全ての入力が-1の場合	*/
		if((m == -1)
		&& (f == -1)
		&& (r == -1)){
			break;	/* 処理を終了する	*/
		}
		else{
			/* 処理を続行する	*/
		}
		
		/* 中間試験、期末試験のいずれかを欠席した場合	*/
		if((m == -1)
		|| (f == -1)){
			result = 'F';	/* 成績はF	*/
		}
		/* 中間試験と期末試験の合計点数が 80 以上の場合	*/
		else if((m + f) >= 80){
			result = 'A';	/* 成績はA	*/
		}
		/* 中間試験と期末試験の合計点数が 65 以上 80 未満の場合	*/
		else if((m + f) >= 65
			 && (m + f) < 80){
			result = 'B';	/* 成績はB	*/
		}
		/* 中間試験と期末試験の合計点数が 50 以上 65 未満の場合	*/
		else if((m + f) >= 50
			 && (m + f) < 65){
			result = 'C';	/* 成績はC	*/
		}
		/* 中間試験と期末試験の合計点数が 30 以上 50 未満の場合	*/
		else if((m + f) >= 30
			 && (m + f) < 50){
			/* 再試験の点数が 50 以上の場合	*/
			if(r >= 50){
				result = 'C';	/* 成績はC	*/
			}
			/* 再試験の点数が 50 未満の場合	*/
			else{
				result = 'D';	/* 成績はD	*/
			}
		}
		/* 中間試験と期末試験の合計点数が 30 未満の場合	*/
		else if((m + f) < 30){
			result = 'F';	/* 成績はF	*/
		}
		/* 上記以外の結果はないため処理なし	*/
		else{
			/* 処理なし	*/
		}
		
		/* 結果を出力	*/
		printf("%c\n",result);
	}
	
	return 0;
}



Measured memory_bytes: 2060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A;
  int B;
  cin >> A >> B;
 
  if (A == B) {
    cout << A + B << endl;
  }
  
  
  if (A - B == 1 ) {
    cout << A + B << endl;
  }
  
  if (B - A == 1) {
    cout << A + B << endl;
  }
  
  if (A - B > 1) {
    cout << A + A - 1 << endl;
  }
  
  if (B - A > 1) {
    cout << B + B - 1 << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    // ABC173 H and V
    public static void main(String[] args) {
        solve();
    }

    private static void solve() {

        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int K = sc.nextInt();

        char[][] masu = new char[H][];
        for (int h = 0; h < H; h++) {
            masu[h] = sc.next().toCharArray();
        }
        sc.close();
        System.out.println(count(H, W, K, masu));
    }

    private static int count(int H, int W, int K, char[][] masu) {
        int ans = 0;

        // すべての行・列について赤く塗る・塗らないの全パターンを試す。

        // 全列挙のための繰り返し文 ここから
        for (int h1 = 0; h1 < 1 << H; h1++) {
            for (int w1 = 0; w1 < 1 << W; w1++) {
                // 全列挙のための繰り返し文 ここまで

                int blackCount = 0; // 赤く塗られなかった黒の個数

                for (int h2 = 0; h2 < H; h2++) {
                    for (int w2 = 0; w2 < W; w2++) {
                        if (((h1 >> h2 & 1) == 1) || ((w1 >> w2 & 1) == 1)) {
                            // マスが赤く塗られたケース
                            continue;
                        } else {
                            // マスが赤く塗られなかったケース
                            if (masu[h2][w2] == '#') {
                                blackCount++;
                            }
                        }
                    }
                }

                if (blackCount == K) {
                    ans++;
                }
            }
        }

        return ans;
    }
}

Measured memory_bytes: 35728
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long long N, ans=0, tmp;
    cin >> N;
    if(N%2==1){
	cout << 0 << endl;
	return 0;
    }
    tmp=N/2;
    while(tmp!=0){
	tmp /= 5;
	ans += tmp;	
    }
    cout << ans << endl;      
}

 

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

typedef long long ll;

const int INF = 1e10;

const int MAX_N = 105;
const int MAX_V = 1005;

//input
ll N,W;
vector<ll> w(MAX_N),v(MAX_N);

//dp
ll dp[MAX_N][MAX_N*MAX_V];

int main() {
	cin>>N>>W;
	rep(i,N)cin>>w[i]>>v[i];

	//初期値
	rep(i,MAX_N)rep(j,MAX_N*MAX_V){
		dp[i][j] = INF;
	}
	dp[0][0] = 0;

	rep(i,N)rep(j,MAX_N*MAX_V){
		if(j+v[i]<=MAX_N*MAX_V){
			dp[i+1][j+v[i]] = min(dp[i+1][j+v[i]], dp[i][j]+w[i]);
			dp[i+1][j] 		= min(dp[i+1][j],dp[i][j]);
		}
		
	}


	ll ans = 0;
	rep(j,MAX_N*MAX_V){
		if(dp[N][j]<=W)ans = j;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 86784
a,v = list(map(int,input().split()))
b,w = list(map(int,input().split()))
t = int(input())

if (v - w > 0) and (a != b):
    if abs(a-b) <= (v - w) * t:
        print("YES")
    else:
        print("NO")
    
elif a == b:
    print("YES")

else:
    print("NO")

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

#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define MOD 1000000007

const int MAX_M = 100000;


int main(){
  ll n, y;    //n枚,y円
  //string s;
  cin >> n >> y;

  //vector<ll> a(n);
  //queue<ll> q;
  //map<string,ll> m;

  ll a=0, b=0, c=0; //10000円,5000円,1000円
  //c = y/1000;
  //diff = c-n;


    bool ok = false;
    ll a_max = y/10000;
    ll b_max = y/5000;


    rep(i,0,a_max+1){ //10000円札の枚数0~a_max
      a = i;
      rep(j,0,b_max+1){ //5000円札の枚数
        b = j;
        c = n-(a+b);
        if((c>=0) && (a*10000+b*5000+c*1000 == y)){
          //cout << a*10000+b*5000+c*1000 << endl;
          ok = true;
          //break;
          j = b_max+1;
          i = a_max+1;
        }
      }
    }

    if(!ok){
      a = -1;
      b = -1;
      c = -1;
    }





  //cout << fixed << setprecision(10);
  //cout << ((ok)? "Yes" : "No") << endl;
  cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define f first
#define se second
#define pb push_back
 
 
using namespace std;
 
 
const int N =  3e5 + 123;
const int MAXN = 2e5;
const ull inf = 1e18 + 7;



int n, a[N], c1[N], c2[N]; 

 
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (i % 2 == 1)
            c1[a[i]]++;
        else
            c2[a[i]]++;
    }
    pair<int, int> m1 = {0, 0}, m2 = {0, 0}, m11 = {0, 0}, m22 = {0, 0};
    for (int i = 1; i <= 100000; i++) {
        if (c1[i] >= m1.f) {
            m2 = m1;
            m1 = {c1[i], i};
        } else if (c1[i] >= m2.f) {
            m2 = {c1[i], i};
        }
        if (c2[i] >= m11.f) {
            m22 = m11;
            m11 = {c2[i], i};
        } else if (c2[i] >= m22.f) {
            m22 = {c2[i], i};
        }
    }
    if (m1.se != m11.se)
        cout << n - m1.f - m11.f;
    else {
        cout << n - max(m1.f + m22.f, m2.f + m11.f);
    }
}


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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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; }

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr double EPS = 1e-10;
constexpr int INF = 1001001001;
//constexpr ll INF = 1001001001001001001ll;






int main() {

    int N; cin >> N;
    int k = 0;

    while ((1 << k) <= N) {
        if ((1 << k) == N) {
            cout << "No" << endl;
            return 0;
        }
        k++;
    }

    cout << "Yes" << endl;

    cout << N + 1 << " " << 3 << endl;
    for (int i = 1; 2 * i + 1 <= N; i++) {
        cout << 2 * i + 1 << " " << 2 * i << endl;
        cout << 2 * i << " " << 1 << endl;
        cout << 1 << " " << 2 * i + 1 + N << endl;
        cout << 2 * i + 1 + N << " " << 2 * i + N << endl;
    }

    if (N % 2 == 0) {
        k--;
        cout << N << " " << (1 << k) << endl;
        cout << 2 * N - (1 << k) + 1 << " " << 2 * N << endl;

    }

    return 0;


}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#include<string>
#define int long long
using namespace std;
main()
{
	//freopen("input.txt","rt",stdin);
	int n;
	string s;
	cin>>n>>s;
	int c =1;
	for(int i=1;i<s.length();i++)
	{
		if(s[i-1] != s[i] )
		{
			c++;
		}
	}
	cout<<c<<endl;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<algorithm>
#include<cstring>
#include<iostream>

using namespace std;

int main()
{
	int N,a,b,c,d;
	scanf("%d",&N);
	a=N/1000;
	b=(N/100)%10;
	c=(N/10)%10;
	d=N%10;
	if(a==b&&b==c||b==c&&c==d||a==b&&b==c&&c==d)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}




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

long used[100001];

int main(void){
    long n;
    cin >> n;
    const long sn = floor(sqrt(2*n));
    const long q = 2*n/sn;
    const long r = 2*n%sn;
    //cout << sn << " " << q << " " << r << " " << endl;
    if( r!=0 || q-sn != 1 ){
        cout << "No" << endl;
        return 0;
    }
    vector<vector<long>> ans(q);
    long u_index = 1;
    ans[0].resize(sn);
    for(long j=0; j<sn; j++){
        ans[0][j] = u_index;
        used[u_index]++;
        u_index++;
    }
    for(long i=1; i<q; i++){
        ans[i].resize(sn);
        for(long j=0; j<i; j++){
            const auto it = find_if(ans[j].begin(), ans[j].end(),
                    [](long ii){ return used[ii]==1; });
            used[*it]++;
            ans[i][j] = *it;
        }
        for(long j=i; j<sn; j++){
            ans[i][j] = u_index;
            used[u_index]++;
            u_index++;
        }
    }
    cout << "Yes\n";
    cout << q << endl;
    for(long i=0; i<q; i++){
        cout << sn;
        for(long j=0; j<sn; j++){
            cout << " " << ans[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3712
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))

d = defaultdict(int)
for a in A:
    d[a] += 1

ans = 0
for k, v in d.items():
    if k > v:
        ans += v
    elif k < v:
        ans += v - k
print(ans)


Measured memory_bytes: 18668
#include <iostream>
#include <atcoder/dsu>

int main() {
    int n, q;
    std::cin >> n >> q;
    atcoder::dsu d(n);
    for (int i = 0; i < q; ++i) {
        int t, u, v;
        std::cin >> t >> u >> v;
        if (t == 0) d.merge(u, v);
        else {
            std::cout << d.same(u, v) << "\n";
        }
    }
}

Measured memory_bytes: 3952
n = int(input())
num = [list(map(int, input().split())) for i in range(n)]

ans = 0
for i in range(n-1, -1, -1):
    a, b = num[i][0], num[i][1]
    a += ans
    if a % b != 0:
        res = b - a % b
        ans += res

print(ans)


Measured memory_bytes: 27380
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <string> vs;

int main()
{
    ll p,q,r;
    cin>>p>>q>>r;
    cout<<p+q+r-max(p,max(q,r))<<endl;
}


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

int main(){
	int k,a,b;
	cin >> k>>a>>b;
	if(a%k==0){
		cout<<"OK"<<endl;
		return 0;
	}else if(a%k!=0){
		
		if(a/k*k+k<=b){
		  cout<<"OK"<<endl;
		  return 0;
		}
	}
	cout<<"NG"<<endl;
	return 0;
}

Measured memory_bytes: 3672
// B - AcCepted
#include <bits/stdc++.h>
using namespace std;

int main(){
	string s; cin>>s;
	bool ok = true;
	if(s[0] != 'A') ok = false;
	if(s[1]<'a' || 'z'<s[1]) ok = false;
	if(s.back()<'a' || 'z'<s.back()) ok = false;
	int c = 0;
	for(int i=2; i<(int)s.size()-1; ++i)
		if(s[i] == 'C') c++;
	if(c != 1) ok = false;
	cout<< (ok? "AC":"WA") <<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;
constexpr long double kPI = 3.14159265358979323846;

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

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, P;
  cin >> N >> P;
  vll A(N);
  REP(i, 0, N) {
    cin >> A[i];
  }

  bool all_even = true;
  for (const auto& a : A) {
    if (a % 2 != 0) {
      all_even = false;
      break;
    }
  }
  if (all_even) {
    if (P == 1) {
      cout << 0 << endl;
    } else {
      cout << (ll) pow(2, N) << endl;
    }
    return 0;
  }

  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }

  cout << (ll) pow(2, N - 1) << endl;

  return 0;
}


Measured memory_bytes: 384
int main()
{
  int i   , j = 0 ,N,A[1000] , v,count =0;
  scanf("%d",&N);

  for( i = 0 ; i < N; i++) scanf("%d",&A[i]);
        for(count =0 ; count < N ; count++) 
        {
            if(count == N - 1) 
            {
                printf("%d",A[count]);
		//printf("test\n");
            break;
            }
            printf("%d ", A[count] );
    }
	if(N >1)printf("\n");
   

   ///////////////////////////////////////ソート本体
  for(i = 1 ; i <N ; i++)
    {
      v = A[i];
      j = i -1 ;

      while( j  >= 0 && A[j] > v)
	{
	  A[ j+1 ] = A[j];
	  j--;
	  A[j+1] = v;

	}
      // //////////////////////////////////////
      for(count =0 ; count < N ; count++)
	{
	  if(count == N -1 )
	    {
	      printf("%d",A[count]);
	      break;
		}
	  printf("%d ", A[count] );
	}
      if(i <N-1)printf("\n");
	
    }
  printf("\n");
}



Measured memory_bytes: 2072
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

string s;

signed main() {
    //cin.tie(0); ios::sync_with_stdio(false);
    cin >> s;
    rep(i, s.size()) if (i%2==0) cout << s[i];
    cout << endl;
}

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

int main()
{
    char s[100],p[100],r[200];
    scanf("%s",s);
    scanf("%s",p);

    strcpy(r,s);
    strcat(r,s);

    if(strstr(r,p)) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
   return 0;
}

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

void Main() {
  char tmp;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> tmp;
      if (i == j) cout << tmp;
    }
  }
  cout << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.flush();
		out.close();
	}
}

class Pair {
	long first;
	long second;
	long third;

	Pair(long first, long second, long third) {
		this.first = first;
		this.second = second;
		this.third = third;
	}
}

class TaskB {

	public void solve(int testNumber, InputReader in, PrintWriter pw) {
		int N = in.nextInt();
		long x[] = new long[N];
		long y[] = new long[N];
		long h[] = new long[N];
		Pair arr[] = new Pair[N];
		Pair temp = null;
		for (int i = 0; i < N; i++) {
			x[i] = in.nextLong();
			y[i] = in.nextLong();
			h[i] = in.nextLong();
			if (h[i] >= 1) {
				temp = new Pair(x[i], y[i], h[i]);
			}
		}
		ArrayList<Pair> ans = new ArrayList<Pair>();
		for (int i = 0; i < 101; i++) {
			for (int j = 0; j < 101; j++) {
				long V = temp.third + Math.abs(i - temp.first) + Math.abs(j - temp.second);
				V = Math.max(0, V);
				boolean flag = true;
				for (int k = 0; k < N; k++) {
					long height = V - Math.abs(i - x[k]) - Math.abs(j - y[k]);
					height = Math.max(0, height);
					if (height != h[k]) {
						flag = false;
						break;
					}
				}
				if (flag) {
					pw.println(i + " " + j + " " + V);
					return;
				}
			}
		}
	}

	int __gcd(int a, int b) {
		if (b == 0)
			return a;
		return __gcd(b, a % b);

	}

	public int getInt(int num) {
		int ret = -1;
		switch (num) {
		case 0:
			ret = 6;
			break;
		case 1:
			ret = 2;
			break;
		case 2:
			ret = 5;
			break;
		case 3:
			ret = 5;
			break;
		case 4:
			ret = 4;
			break;
		case 5:
			ret = 5;
			break;
		case 6:
			ret = 6;
			break;
		case 7:
			ret = 3;
			break;
		case 8:
			ret = 7;
			break;
		case 9:
			ret = 6;
			break;
		}
		return ret;
	}

	public int isPow(long num) {
		int count = 0;
		while (num > 0) {
			num /= 2;
			count++;
		}
		return count;
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

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

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

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


Measured memory_bytes: 26156
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>
#include <unordered_map>

using namespace std;
typedef long long  ll;

int main()
{
	string s;
	cin >> s;
	deque<char> que;
	for (size_t i = 0; i < s.length(); i++)
	{
		que.push_back(s[i]);
	}
	bool isrev = false;
	ll q;
	cin >> q;
	for (ll i = 0; i < q; i++)
	{
		ll order;
		cin >> order;
		if (order == 1)
		{
			isrev = !isrev;
		}
		else
		{
			ll type;
			char c;
			cin >> type >> c;
			if (isrev)
			{
				if (type == 1)
					que.push_back(c);
				else
					que.push_front(c);
			}
			else
			{
				if (type == 1)
					que.push_front(c);
				else
					que.push_back(c);
			}
		}
	}
	if (isrev)
	{
		while (!que.empty())
		{
			cout << que.back();
			que.pop_back();
		}
	}
	else
	{
		while (!que.empty())
		{
			cout << que.front();
			que.pop_front();
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define Check system("pause")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)



int main()
{
	ios::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	int n;
	n=s.length();
	for(int i=0;i<n;i++)
	{
		if(s[i]!=t[i])
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}




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

#define v1 first
#define v2 second
#define pb push_back
#define mid ((l+r)>>1)
#define vec vector<int>
#define pr pair<int,int>
#define tp tuple<int,int,int>
#define sz(x) ((int) x.size())
#define all(x) x.begin(),x.end()
#define mem(a,x) memset(a,x,sizeof a)
#define For(x) for(int y,i=head[x];(y=e[i].to);i=e[i].nxt)

inline bool rd(int &X)
{
    X=0;int w=0;char ch=0;
    while(!isdigit(ch))w|=ch=='-',ch=getchar();
    while( isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    X=w?-X:X; return 1;
}

vec now;
int n,m,tot,ans;
int a[N],vis[N],u[N];
int head[N],cnt,mn[N];
struct nd{int nxt,to;}e[N<<1];
#define For(x) for(int y,i=head[x];(y=e[i].to);i=e[i].nxt)

void add(int x,int y){
    e[++cnt]=(nd){head[x],y};head[x]=cnt;
    e[++cnt]=(nd){head[y],x};head[y]=cnt;
}
void dfs(int x){
    if(a[x]<a[mn[tot]]) mn[tot]=x;
    For(x) if(!vis[y])
        vis[y]=1,dfs(y);
}
signed main()
{
    rd(n);rd(m); a[0]=2e9;

    for(int i=1;i<=n;i++) rd(a[i]);
    for(int x,y,i=1;i<=m;i++)
        rd(x),rd(y),add(x+1,y+1);
    for(int i=1;i<=n;i++)
        if(!vis[i]) ++tot,dfs(i);
    if(tot==1) return cout<<0,0;
    if(n<2*(tot-1)) return cout<<"Impossible",0;
    for(int i=1;i<=tot;i++)
        u[mn[i]]=1,ans+=a[mn[i]];
    for(int i=1;i<=n;i++)
        if(!u[i]) now.pb(a[i]);
    sort(all(now));
    for(int i=1;i<=2*(tot-1)-tot;i++)
        ans+=now[i-1];
    cout<<ans;
}


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

using namespace std;

typedef long long ll;

const int MAXN = 200005;

int n;
ll x[MAXN], X;

ll solve(int t) {
  ll res = X * (t + n);
  for(int i = n; i >= max(1, n - 2 * t + 1); i--) {
    res += x[i] * 5;
  }
  int cnt = 0;
  int c = 7;
  for(int i = n - 2 * t; i >= 1; i--) {
    res += x[i] * c;
    ++cnt;
    if(cnt == t) {
      cnt = 0;
      c += 2;
    }
  }
  return res;
}

int main() {
  scanf("%d %lld", &n, &X);
  for(int i = 1; i <= n; i++) {
    scanf("%lld", &x[i]);
  }
  ll ans = LLONG_MAX;
  int l = 1, r = n;
  while(r - l > 10) {
    int a = l + (r - l) / 3;
    int b = r - (r - l) / 3;
    ll v1 = solve(a);
    ll v2 = solve(b);
    ans = min(ans, v1);
    ans = min(ans, v2);
    if(v1 < v2) {
      r = b;
    } else {
      l = a;
    }
  }
  for(int i = l; i <= r; i++) {
    ans = min(ans, solve(i));
  }
  /*
  for(int t = 1; t <= n; t++) {
    ans = min(ans, solve(t));
  }
  */
  printf("%lld\n", ans);
  return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  long long ans = -100000000000000;
  long long ac = (long long)a*c;
  long long ad = (long long)a*d;
  long long bc = (long long)b*c;
  long long bd = (long long)b*d;

  cout << max(max(ac, ad), max(bc, bd)) << endl;
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int main()
{
  vector<int> count(4,0);
  int judge=0;
  string S;
  cin >> S;
  for(int i=0; i<4; i++){
    for(int j=0; j<4; j++){
      if(S.at(i)==S.at(j)){
        count.at(i)++;
      }
    }
  }
  for(int i=0; i<4; i++){
    if(count.at(i)==2){
      judge++;
    }
  }
  if(judge==4)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

int main(){
  int a; 
  cin>>a;
  int ans=0;
  int array[50];
  int i,j;
  array[0]=0;
  for(i=1;i<=a;i++){
    cin>>array[i];
  }
  
  for(i=0;i<=a;i++){
    for(j=0;j<=a;j++){
      if(i !=j){
      ans=ans+array[i]*array[j];
      }
  }
  }
  cout<<ans/2;
  
  
  
 
  return 0;
}


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

int main(){
  int H,W,mod=pow(10,9)+7; cin >> H >> W;
  vector<string> field(H+1,"#");
  for (int i=0;i<W;i++){
    field.at(0)+="#";
  }
  for (int i=0;i<H;i++){
    string a; cin >> a;
    field.at(i+1) += a;
  }
  //DPつくるお 計算量O(HW)
  vector<vector<int>> dp(H+1,vector<int>(W+1,0));
  dp.at(1).at(1)=1;
  for (int i=1;i<=H;i++){
    for (int j=1;j<=W;j++){
      if (field.at(i).at(j)=='.'){
        if (field.at(i).at(j-1)=='.'){
          dp.at(i).at(j)+=dp.at(i).at(j-1);
        }
        if(field.at(i-1).at(j)=='.'){
          dp.at(i).at(j)+=dp.at(i-1).at(j);
        }
        dp.at(i).at(j)%=mod;
      }
    }
  }
  cout << dp.at(H).at(W) << endl;
}

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

int main() {  
  int n;
  cin >> n;
  vector<int> a(n+1), b(n);
  rep(i,n+1) {
  	cin >> a[i];
  }
  rep(i,n) {
  	cin >> b[i];
  }
  ll maxbeat=0;
  for(int i = 0; i < n; i++) {
  	maxbeat += min(a[i],b[i]);
    b[i] = max(0, b[i]-a[i]);
    maxbeat += min(b[i], a[i+1]);
    a[i+1] = max(0, a[i+1]-b[i]);
  }
  cout << maxbeat << endl;
}

Measured memory_bytes: 1024
import copy
import sys

input = sys.stdin.readline
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = copy.deepcopy(a)

w = 10 ** 9 + 7

cnta = 0
cntb = 0
for i in range(len(a)):
    for j in range(len(a) - 1, i, -1):
        if a[j] < a[j - 1]:
            a[j], a[j - 1] = a[j - 1], a[j]

            cnta += 1

for i in range(len(b)):
    for j in range(len(b)):
        if b[i] > b[j]:
            cntb += 1

wa = (k * (k - 1) // 2) * cntb + cnta * k
print(wa % w)


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n); i++)
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using p = pair<int,int>;

int main(){
  int n,m;
  cin >> n >> m;
  vector<int>a(m);
  int sum = 0;
  rep(i,m){
    cin >> a[i];
    sum += a[i];
  }
  if(sum > n)cout << -1 << endl;
  else cout << n-sum << endl;
  return 0;
}

Measured memory_bytes: 3668
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

func main() {
	n := readi()
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = readi()
	}

	m := 0
	c := 0
	prev := h[0]
	for i := 1; i < n; i++ {
		if h[i] <= prev {
			c++
		} else {
			c = 0
		}
		m = max(c, m)
		prev = h[i]
	}

	fmt.Println(m)
}

/*-------------------utilities-------------------*/

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func chmin(x *int, y int) bool {
	if *x > y {
		*x = y
		return true
	}
	return false
}

func chmax(x *int, y int) bool {
	if *x < y {
		*x = y
		return true
	}
	return false
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return (a * b) / gcd(a, b)
}

func comb(n, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
}

func permutations(arr []int) [][]int {
	var helper func([]int, int)
	res := [][]int{}

	helper = func(arr []int, n int) {
		if n == 1 {
			tmp := make([]int, len(arr))
			copy(tmp, arr)
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}

func divisor(n int) (res []int) {
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i*i != n {
				res = append(res, n/i)
			}
		}
	}
	sort.Ints(res)
	return
}

/*-------------------init-------------------*/

const (
	INF = 1000000000000000000
	MOD = 1e9 + 7

	COMB_MAX = 510000
)

var (
	readString func() string
)

var (
	fac  = [COMB_MAX]int{}
	finv = [COMB_MAX]int{}
	inv  = [COMB_MAX]int{}
)

func init() {
	readString = newReadString(os.Stdin)
}

func combInit() {
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i := 2; i < COMB_MAX; i++ {
		fac[i] = fac[i-1] * i % MOD
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD
		finv[i] = finv[i-1] * inv[i] % MOD
	}
}

/*-------------------inputs-------------------*/

func readi() int {
	return int(readi64())
}

func readi64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readf() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}

bool f(int x,int &ans){
    if(x%3==2)return false;
    if(x%4==3)return false;
    for(int i=(int)sqrt(x)-2;i*i<=x;i++){
        if(i*i==x){
            ans=i;
            return true;
        }
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int n;cin >> n;
    rep2(i,1,n+1){
        int cnt=0;
        for(int x=1;x*x<=i;x++)for(int y=1;y*y<=i-x*x;y++){
            int k=0;
            if(f((x+y)*(x+y)-4*(x*x+y*y-i+x*y),k)&&((-1*(x+y+0.0)+k)/2.0+0.1>1))cnt++;
        }
        cout << cnt << endl;
    }
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll X[100005];
ll P[100005];

int main() {
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> X[i];
    }

    P[0] = P[1] = 1;
    for (ll i = 1; i <= N; ++i) {
        P[i + 1] = (P[i] * (i + 1)) % MOD;
    }

    ll ans = 1;
    ll s = X[0];
    ll n = 1;
    REP(i, N - 1) {
        s += X[i + 1] - X[i] - 1;
        n++;
        if (n > s) {
            ans = (ans * n) % MOD;
            s++;
            n--;
        }
    }
    ans = (ans * P[n]) % MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')
YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    return [NO, YES][S[2] == S[3] and S[4] == S[5]]


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    print(f'{solve(S)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 75204
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
    
ll n,cnt,ans,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),a,b,c;
bool fl;
struct edge{int to,cost;};
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n>>a>>b>>c;
    rep(i,n){
        char aa,bb,cc;
        aa=a[i];
        bb=b[i];
        cc=c[i];
        map<char,ll> mp;
        cnt=0;
        mp[aa]++;
        cnt=max(mp[aa],cnt);
        mp[bb]++;
        cnt=max(mp[bb],cnt);
        mp[cc]++;
        cnt=max(mp[cc],cnt);
        ans+=3-cnt;
    }
    Cout(ans);
    return 0;
}

Measured memory_bytes: 256