akhauriyash/Code-Regression huggingface dataset:
mod=10**9+7
inv2=5*(10**8)+4
B,W=map(int,input().split())
 
Factorial=[1]*(B+W+1)
for i in range(1,B+W+1):
  Factorial[i]=Factorial[i-1]*(i)%mod
def power(x,y):
  if y==0:
    return 1
  elif y==1:
    return x%mod
  elif y%2==0:
    return power(x,y//2)**2%mod
  else:
    return (power(x,y//2)**2)*x%mod
 
inverseFactorial=[1]*(B+W+1)
inverseFactorial[B+W]=power(Factorial[B+W],mod-2)
for i in range(0,B+W)[::-1]:
  inverseFactorial[i]=(inverseFactorial[i+1]*(i+1))%mod
  
def comb(x,y):
  if x<y or y<0:
    return 0
  else:
    return (Factorial[x]*inverseFactorial[y]*inverseFactorial[x-y])%mod
w,b=[0]*(B+W+1),[0]*(B+W+1)
p2=[1]*(B+W+1)
for i in range(1,B+W+1):
  p2[i]=(p2[i-1]*2)%mod
bunbo=power(inv2,B+W+1)  

for i in range(1,B+W+1):
  w[i]=(w[i-1]+comb(i-1,W-1)*p2[B+W-i])%mod
  b[i]=(b[i-1]+comb(i-1,B-1)*p2[B+W-i])%mod
ans=[0]*(B+W+1)
#print(w)
#print(b)
for i in range(1,B+W+1):
  ans[i]=(p2[B+W]+w[i-1]-b[i-1])*bunbo
  print(ans[i]%mod)

Measured memory_bytes: 120088
unittest
{
	assert( [ "11009 11332" ].parse.expand.solve == 4 );
	assert( [ "31415 92653" ].parse.expand.solve == 612 );
}



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

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

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto ab = input.front.split.to!( long[] );
	return tuple( ab[ 0 ], ab[ 1 ] );
}

auto solve( long a, long b )
{
	auto c = 0L;
	
	foreach( i; a .. b + 1 )
	{
		auto d1 = i % 10;
		auto d2 = i / 10 % 10;
		auto d4 = i / 1000 % 10;
		auto d5 = i / 10000 % 10;
		
		if( d1 == d5 && d2 == d4 ) c++;
	}
	
	return c;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int v, w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int INF = INT_MAX / 4;

int main() {
	int N; cin >> N;
	if (N < 6) {
		cout << 0 << endl;
		return 0;
	}
	vector<ll> a(N);
	for (int i = 0; i < N; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	vector<ll> b(N - 2);
	for (int i = 0; i + 3 <= N; i++)
		if (a[i] + a[i + 1] > a[i + 2])
			b[i] = a[i] + a[i + 1] + a[i + 2];
	vector<ll> c(N - 1);
	c[0] = 0;
	for (int i = 1; i - 1 < N - 2; i++)
		c[i] = max(c[i - 1], b[i - 1]);
	ll maxi = 0;
	for (int i = 3; i + 3 <= N; i++)
		if (c[i - 2] && b[i])
			maxi = max(maxi, c[i - 2] + b[i]);
	for (int i = N - 6; i >= 0; i--) {
		bool ok = false;
		for (int S = 0; S < (1 << 6); S++) {
			vector<ll> v, w;
			for (int j = 0; j < 6; j++)
				if ((S >> j) & 1) v.push_back(a[i + j]);
				else w.push_back(a[i + j]);
			if (v.size() == 3 && v[0] + v[1] > v[2] && w[0] + w[1] > w[2])
				ok = true;
		}
		if (ok) {
			maxi = max(maxi, a[i] + a[i + 1] + a[i + 2] + a[i + 3] + a[i + 4] + a[i + 5]);
			break;
		}
	}
	cout << maxi << endl;
}

Measured memory_bytes: 3384
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)

int main()
{
    fastio;
    long long a,b,c,d,ans;
    cin>>a>>b>>c>>d;
    if(a>=0 && b>=0 && c>=0 && d>=0)
        ans=b*d;
    else if(a<=0 && b<=0 && c<=0 && d<=0)
        ans=a*c;
    else
        ans=max(max(max(b*d,a*c),a*d),b*c);
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>

using namespace std;
typedef long long ll;
typedef pair<ll,ll>P;
int main(){
  ll n,k;
  priority_queue<P,vector<P>,greater<P> >pq;
  
  scanf("%lld %lld",&n,&k);
  for(int i=0;i<n;i++){
    ll a,b;
    scanf("%lld %lld",&a,&b);
    pq.push(P(a,b));
  }

  for(int i=0;i<n;i++){
    P p=pq.top();
    pq.pop();
    k=k-p.second;
    if(k<=0){
      printf("%lld\n",p.first);
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	ll a,b,k;
	rl3(a,b,k);
	if(k>=a)
	{
		k=k-a;
		a=0;
	}
	else
	{
		a=a-k;
		k=0;
	}
	if(k>=b)
	{
		k=k-b;
		b=0;
	}
	else
	{
		b=b-k;
		k=0;
	}
	cout<<a<<" "<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define intt int64_t
#define all(vec) vec.begin(), vec.end()
#define INF 2000000000

int main() {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    x -= z;
    printf("%d\n", x/(y+z));
}

Measured memory_bytes: 256
#include "iostream"

void merge(int A[],int left,int right,int* count){
  if(left<right){
    int mid=(left+right)/2;
    int n1=mid-left+1,
        n2=right-mid;
    int L[n1],R[n2];
    for(int i=0;i<n1;i++){
      L[i]=A[left+i];
    }
    for(int i=0;i<n2;i++){
      R[i]=A[mid+i+1];
    }
    int p=0,j=0;
    for(int i=left;i<=right;i++){
      *count+=1;
      if(p==n1){
        A[i]=R[j];
        j++;
      }else if(j==n2){
        A[i]=L[p];
        p++;
      }else if(L[p]>R[j]){
        A[i]=R[j];
        j++;
      }else if(L[p]<=R[j]){
        A[i]=L[p];
        p++;
      }else{
        std::cout<<"error"<<std::endl;
        break;
      }
    }
  }
}

void merge_sort(int A[],int left,int right,int *count){
  if(right-left>0){
    int mid=(right+left)/2;
    merge_sort(A,left,mid,count);
    merge_sort(A,mid+1,right,count);
    merge(A,left,right,count);
  }
}

int main(){
  int n;
  std::cin>>n;
  int S[n];
  for(int i=0;i<n;i++){
    std::cin>>S[i];
  }
  int count=0;
  merge_sort(S,0,n-1,&count);
  for(int i=0;i<n;i++){
    std::cout<<S[i];
    if(i==n-1){
      std::cout<<std::endl;
    }else{
      std::cout<<" ";
    }
  }
  std::cout<<count<<std::endl;
}



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

int n;
vector<long long int> s;

int main(){
	cin >> n;
	long long int sum = 0;
	long long int flag = LLONG_MAX;
	for (int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		s.push_back(a);
		sum += a;
		if (a % 10LL != 0LL){
			flag = min(flag, (long long int)a);
		}
	}
	if (sum % 10LL == 0LL){
		if (flag == LLONG_MAX){
			puts("0");
			return 0;
		}
		sum-=flag;
	}
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
x=int(input())

count=0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if x == 500*i + 100*j + 50*k:
        count+=1

print(count)

Measured memory_bytes: 39536
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;
		try {
			while ((buffer = reader.readLine())  != null) {
				Integer a = Integer.valueOf(buffer.substring(0, buffer.indexOf(" ")));
				Integer b = Integer.valueOf(buffer.substring(buffer.indexOf(" ") + 1, buffer.indexOf(" ", buffer.indexOf(" ") + 1)));
				Integer c = Integer.valueOf(buffer.substring(buffer.indexOf(" ", buffer.indexOf(" ") + 1) + 1));
				if (a < b) {
					if (b < c) {
						System.out.println(a + " " + b +" " + c);
					}
					else {
						if (a < c) {
							System.out.println(a + " " + c + " " + b);
						}
						else {
							System.out.println(c + " " + a + " " + b);
						}
					}
				}
				else {
					if (a < c) {
						System.out.println(b + " " + a + " " + c);
					}
					else {
						if (b < c) {
							System.out.println(b + " " + c + " " + a);
						}
						else {
							System.out.println(c + " " + b + " " + a);
						}
					}
				}
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}

Measured memory_bytes: 24308
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 1100000000000000000LL
//#define MOD 1000000007
#define MOD 123456789012345671
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=1050;
const int MAX=105;
//ここまでテンプレ
int main() {
	//↓パスカルの三角形
	//三角形のサイズ
	const long long MAX=55;
	//テーブル（nCk=C[n][k]）
	long long C[MAX][MAX];
	for(int i=0;i<MAX;i++){
		for(int j=0;j<=i;j++){
			if(j==0 || j==i)
				C[i][j]=1LL;
			else
				C[i][j]=(C[i-1][j-1]+C[i-1][j]);
		}
	}
	
	cout<<setprecision(20);
	int N,A,B;
	map<ll,ll> tes,ket;
	cin>>N>>A>>B;
	vll v;
	for(int i=0;i<N;i++){
		ll c;
		cin>>c;
		v.pb(c);
		tes[c]++;
	}
	sort(v.begin(),v.end(),greater<ll>());
	ll sum=0,ans=0;
	int i;
	for(i=0;i<A;i++){
		sum+=v[i];
		ket[v[i]]++;
	}
	cout<<fixed<<(double)sum/A<<endl;
	if(tes[v[0]]>A && ket[v[0]]==A){
		for(int i=A;i<=tes[v[0]] && i<=B;i++){
			ans+=C[tes[v[0]]][i];
		}
	}
	else
		ans=C[tes[v[A-1]]][ket[v[A-1]]];
	cout<<ans<<endl;
    return 0;
}

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

namespace B_Exchange
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int[] line = ReadIntAr();
            int a = line[0];
            int b = line[1];
            int k = line[2];

            for (int i = 0 ; i < k ; i++)
            {
                if (i % 2 ==0)
                {
                    if (a % 2 != 0) a--;
                    a /= 2;
                    b += a;
                }
                else
                {
                    if (b % 2 != 0) b--;
                    b /= 2;
                    a += b;
                }
            }

            Console.WriteLine("{0} {1}",a,b);
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}


Measured memory_bytes: 13140
from collections import deque
n=int(input())
g=[[] for _ in range(n+1)]
e=[]
for i in range(n-1):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    e.append(b-1)
 
q=deque([0])
 
color=[0 for _ in range(n)]
while(len(q)>0):
    ei=q.popleft()
    c=1
    for x in g[ei]:
        if c == color[ei]:
            c+=1
 
        color[x]=c
        c+=1
        q.append(x)
 
print(max(color))
for i in e:
    print(color[i])

Measured memory_bytes: 26076
h, w = map(int, input().split())

line_list = []
for i in range(h):
    line_list.append(input())

if h == 1:
    if w == 1:
        print("No")
        exit()
    else:
        current_line = line_list[0]
        j = 0
        while j < w - 1:
            if current_line[j] == "#":
                if current_line[j + 1] == "#":
                    j += 1
                    while j < w - 1:
                        if current_line[j + 1] != "#":
                            break
                        else:
                            j += 1
                    j += 1
                    continue
            j += 1
    print("Yes")
    exit()
elif w == 1:
    if h == 1:
        print("No")
        exit()
    else:
        j = 0
        while j < h - 1:
            if line_list[j] == "#":
                if line_list[j + 1] == "#":
                    j += 1
                    while j < h - 1:
                        if line_list[j + 1] != "#":
                            break
                        else:
                            j += 1
                    j += 1
                    continue
            j += 1
    print("Yes")
    exit()


before_line = [["."] for _ in range(w)]
current_line = list(line_list[0])
for i in range(h-1):
    after_line = list(line_list[i + 1])
    j = 0
    while j < w-1:
        if current_line[j] == "#":
            if current_line[j+1] == "#":
                j += 1
                while j < w - 1:
                    if current_line[j + 1] != "#":
                       break
                    else:
                        j += 1
                j += 1
                continue
            elif before_line[j] != "#" and after_line[j] != "#":
                print("No")
                exit()
        j += 1
    before_line = current_line
    current_line = after_line

print("Yes")

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define mod 1000000007
#define bitcount __builtin_popcountll
#define ll long long
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<pi,ll>
#define mp make_pair
ll a[200005],b[200005];
vector<ll>v;
ll inv;
void mergesort(ll a[],ll n)
{
	if(n==1)
		return;
	
	mergesort(a,n/2);
	mergesort(a+n/2,n-n/2);

	ll i=0,j=n/2,k=0;
	while(i<n/2&&j<n)
	{
		if(a[i]<a[j])
		{
			b[k]=a[i];
			k++;
			i++;
		}
		else
		{
			b[k]=a[j];
			k++;
			j++;
			inv+=n/2-i;
		}
	}
	while(i<n/2)
	{
		b[k]=a[i];
		k++;
		i++;
	}
	while(j<n)
	{
		b[k]=a[j];
		k++;
		j++;
	}
	for(i=0;i<n;i++)
		a[i]=b[i];
	/*for(i=0;i<n;i++)
		prllf("%d ",a[i] );
	prllf("\n");*/
}
int main()
{
	ll i,j,k,n;
	slld(n);
	slld(k);
	for(i=0;i<n;i++){
		slld(a[i]);
		a[i]-=k;
	}
	for(i=1;i<n;i++)
		a[i]+=a[i-1];
	reverse(a,a+n);
	inv=0;
	mergesort(a,n);
	for(i=0;i<n;i++){
		if(a[i]>=0)
			inv++;
	}
	printf("%lld\n",inv );
	return 0;
}

Measured memory_bytes: 3328
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0,loop;
    string str;
    ll x,y,z;
    cin>>str;
    map<char,ll> mp;
    rep(i,4) mp[str[i]]++;
    rep(i,4){
        if(mp[str[i]]!=2) f=1;
    }

if(f) No;
else Yes;

    return 0;
}


Measured memory_bytes: 3620
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var h = int.Parse(spl[0]);
        var w = int.Parse(spl[1]);

        var cc = new int[10][];
        for (int i = 0; i < cc.Length; i++) {
            cc[i] = ToIntArray(input.ReadLine(), 10);
        }

        var aa = new int[h][];
        for (int i = 0; i < aa.Length; i++) {
            aa[i] = ToIntArray(input.ReadLine(), w);
        }

        var mp = new int[10];
        SetArray(mp, (x, i) => cc[i][1]);

        while (true) {
            var ch = false;
            for(int i=0; i<10; i++) {
                for (int j = 0; j < 10; j++) {
                    var co = cc[i][j] + mp[j];
                    if(co < mp[i]) {
                        ch = true;
                        mp[i] = co;
                    }
                }
            }
            if (!ch) {
                break;
            }
        }

        var sum = 0;
        for(int i=0; i<h; i++) {
            for(int j=0; j<w; j++) {
                if (aa[i][j] == -1) continue;
                sum += mp[aa[i][j]];
            }
        }

        return sum;
    }

    static void SetArray<T>(T[] array, Func<T, int, T> f) {
        for (int i = 0; i < array.Length; i++)
            array[i] = f(array[i], i);
    }
    static void FillArray<T>(T[] array, T value) {
        for (int i = 0; i < array.Length; i++)
            array[i] = value;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


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

int main(){
	int a,b;
	while(cin >> a >> b){
		int ans = a + b;
		int count = 0;
		while(true){
			count++;
			ans /= 10;
			if(ans == 0){
				break;
			}
		}
		cout << count << endl;
	}
}

Measured memory_bytes: 0
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e9
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll N, M, Q;
ll A[100001];
ll B[100001];
ll ans;
string S;
ll K;
map<ll, ll> m;
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
int main() {
	cin >> N;
	rep(i, 0, N) {
		cin >> A[i];
		ans += A[i] - 1;
	}

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

Measured memory_bytes: 256
N, M = [int(n) for n in input().split()]

if N == 1 and M == 1:
  print(1)
elif N == 1:
  print(M-2)
elif M == 1:
  print(N-2)
elif N == 2 or M == 2:
  print(0)
else:
  print((N-2)*(M-2))



Measured memory_bytes: 2940
import sys
input=sys.stdin.readline

def main():
    N = int(input())
    x = 0
    n = N
    while n > 0:
        x += n%10
        n //= 10
    if N%x == 0:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
int a[200002], b[200002], n;
vector<int> v;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    for(int i=n;i;i--)
    {
        int x = 0;
        for(int j=2*i;j<=n;j+=i)
            x ^= b[j];
        b[i] = x ^ a[i];
        if(b[i]) v.push_back(i);
    }
    cout << v.size() << '\n';
    sort(v.begin(), v.end());
    for(int x : v)
        cout << x << ' ';
}

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

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

using namespace std;

int main(){
	int n,W; scanf("%d%d",&n,&W);
	int w[3000],v[3000];
	rep(i,n) scanf("%d%d",&w[i],&v[i]);

	static int dpl[3001][3001],dpr[3001][3001];
	rep(i,n){
		rep(x,W+1) dpl[i+1][x]=dpl[i][x];
		for(int x=W;x>=w[i];x--) dpl[i+1][x]=max(dpl[i+1][x],dpl[i][x-w[i]]+v[i]);
		rep(x,W-1) dpl[i+1][x+1]=max(dpl[i+1][x+1],dpl[i+1][x]);
	}
	for(int i=n-1;i>=0;i--){
		rep(x,W+1) dpr[i][x]=dpr[i+1][x];
		for(int x=W;x>=w[i];x--) dpr[i][x]=max(dpr[i][x],dpr[i+1][x-w[i]]+v[i]);
		rep(x,W-1) dpr[i][x+1]=max(dpr[i][x+1],dpr[i][x]);
	}

	int ans=0;
	rep(i,n){
		for(int x=W-1;x>=0;x--){
			int y=W-x-1;
			ans=max(ans,dpl[i][x]+v[i]+dpr[i+1][y]);
		}
	}
	printf("%d\n",ans);

	return 0;
}


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

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

    Int s,c,a,ans=0;
    cin>>s>>c;
    a=c-s*2;
    if(a<0)ans=c/2;
    else if(a==0)ans=s;
    else ans=s+a/4;
    cout<<ans<<'\n';
}

Measured memory_bytes: 256
N,M = map(int, input().split())
H = list(map(int,input().split()))
flags = [1]*N

A=[0]*M
B=[0]*M

for i in range(M):
    A[i],B[i] = map(int,input().split())

for i in range(M):
    if H[A[i]-1]>=H[B[i]-1]:
        flags[B[i]-1] = 0
    if H[B[i]-1]>=H[A[i]-1]:
        flags[A[i]-1] = 0    
print(sum(flags))

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define FOR(itr, v) for (auto itr = (v).begin(); itr != (v).end(); ++itr)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
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; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int x, n; cin >> x >> n;
    set<int> p;
    rep(i, n)
    {
        int a; cin >> a; p.insert(a);
    }

    int mini = MOD;
    int ans = 0;
    Rep(i, -1, 102)
    {
        if (p.count(i)) continue;
        int a = abs(i - x);
        if (a < mini)
        {
            mini = min(a, mini);
            ans = i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include<stdio.h>

int main(void){
	int a,b,c;
	char op;
	
	while(1){
		scanf("%d %c %d", &a, &op, &b);
		if(op=='+'){
			c=a+b;
		}else if(op=='-'){
			c=a-b;
		}else if(op=='*'){
			c=a*b;
		}else if(op=='/'){
			c=a/b;
		}else{
			break;
		}
		
		printf("%d\n",c);
	}

return 0;
}


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

int N,R,price=0,C,M;
bool y=false;

int main(){
    cin >> N;
    for(int i=1;i<=N;i=i+2){
        for(int i=2;i<=N;i=i+2){
            price++;
        }
    }
    cout << price << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>

main ()
{
	int x ;
	int a ;
	int b ;

	scanf ( "%d %d %d", &x, &a, &b );

	while ( a != x && b != x )
	{
		if ( a < x )
		{
			a++;
		}
		else if ( a > x )
		{
			a--;
		}
		if ( b < x )
		{
			b++;
		}
		else if ( b > x )
		{
			b--;
		}

	}
	if ( a == x )
	{
		printf ( "A\n" ) ;
	}
	else
	{
		printf ( "B\n" ) ;
	}

	return 0 ;
}


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

#define int             long long
#define	ll				long long

#define	mod 			1000000007
#define	inf 			1000000000000000
#define infty			1000000000000000000LL
#define	md				998244353
#define	PI				acos(-1.0)
#define	endl 			"\n"
#define	rr				return
#define	br				cout<<"\n";
long long prime[1000000];

void sieve()
{
	prime[0]=0;
	prime[1]=0;
	for(int i=2;i<1000000;i++)
		prime[i]=1;

	for(int i=2;i*i<1000000;i++)
		if(prime[i]==1)
			for(int j=i*i;j<1000000;j+=i)
				prime[j]=0;
}

bool isPrime(int n)
{
    if (n <= 1)
        return false;
    for (ll i = 2; i <= floor(sqrt(n)); i++)
        if (n % i == 0)
            return false;

    return true;
}

int factorial(int n)
{
    int f=1;
    for(int i = 1;i<=n ; i++)
        f = (f*i)%mod;
    return f;
}

int gcd(int a, int b)
{
	return !b ? a : gcd(b, a % b);
}

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

int fastExponentiation(int n, int x, int modulo)
{
	int res = 1;
	while(x > 0)
       {
          if(x & 1)
          res = (res*n) % modulo;
          x = x >> 1;
          n = (n * n) % modulo;
       }
       return res;
}

int power(int n , int p )
{
	if(p==0)
	   return 1;

	 int res = power((n*n)%mod,p/2);
	 if(p%2==1)
	   res = (n*res)%mod;

	   	 return res;
}

bool isPowerOfTwo(int n)
{
   	return n && (!(n&(n-1)));
}

bool isSet(int n,int i)
{
	// To check if ith bit is set or not in binary representation of n
   	return n & (1 << i);
}

bool valid_coordinate(ll x,ll y,ll n,ll m)
{
    if(x<0 || y<0)
       return false;

   	else if(x>=n || y>=m)
       return false;

   	else
   		return true;
}

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



void solve()
{
	int n,count=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		int a;
		cin>>a;
		if(a%2!=0 and i%2!=0)
		count++;
	}
	cout<<count<<endl;
}

int32_t main()
{

	//int t; cin>>t; while(t--)
	solve();

	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 26
 
bool data[MAX][MAX];
bool used[MAX];
vector<char> ans;
set<int> st;
 
bool cyc(int now, int cnt)
{
    if (cnt == 1) {
	return 1;
    }
    set<int>::iterator it;
    for (it = st.begin(); it != st.end(); ++it) {
	int next = (*it) - 'a';
	ans.push_back((char)(*it));
	if (data[now][next] && cyc(next, cnt-1)) {
	    return 1;
	}
	ans.pop_back();
    }
    return 0;
}
 
int main()
{
    int n;
    string str;
 
    cin >> n;
    while (n--) {
	memset(data, 0, sizeof(data));
	st.clear();
 
	cin >> str;
	string tmp;
	for (int i = 0; i < (int)str.size(); i++) {
	    if (str[i] == '-') continue;
	    tmp += str[i];
	}
	str = tmp;
	st.insert(str[0]);
	for (int i = 2; i < (int)str.size(); i += 2) {
	    if (str[i-1] == '<') {
		data[str[i]-'a'][str[i-2]-'a'] = 1;
	    } else {
		data[str[i-2]-'a'][str[i]-'a'] = 1;
	    }
	    if (!st.count(str[i])) {
		st.insert(str[i]);
	    }
	}
 
	int size = st.size();
	set<int>::iterator it;
	for (it = st.begin(); it != st.end(); ++it) {
	    ans.clear();
	    memset(used, 0, sizeof(used));
	    ans.push_back((char)(*it));
    
	    if (cyc((*it)-'a', size)) {
		break;
	    }
	}
	for (int i = 0; i < (int)ans.size(); i++) {
	    cout << ans[i];
	}
	cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli N=2e5+5, M = 998244353;
lli st[4*N], lazy[4*N], a[N];

lli add(lli a, lli b)
{
	lli res = a + b;
	return res % M;
}
lli mul(lli a, lli b)
{
	lli  res = a * b;
	return res % M;
}

void build(lli node, lli L, lli R)
{
	if(L==R)
	{
		st[node] = a[L];
		return;
	}
	lli M=(L + R)/2;
	build(node*2, L, M);
	build(node*2 + 1, M + 1, R);
	st[node]=add(st[2*node], st[2*node+1]);
}
void update(lli node, lli L, lli R, lli low, lli high, lli value) 
{ 
    if(lazy[node]!=0)
    {
        st[node] = add(st[node], mul((R - L + 1), lazy[node]));
        if(L != R)
        {
            lazy[node*2] = add(lazy[node*2], lazy[node]);
            lazy[node*2+1] = add(lazy[node*2+1], lazy[node]);
        }
        lazy[node] = 0;
    }
    
    if(L > R or high < L or R < low) return;
    
    if(low <= L and R <= high)
    {
        st[node] = add(st[node], mul((R - L + 1), value));
        if(L != R)
        {
            lazy[node*2] = add(lazy[node*2], value);
            lazy[node*2+1] = add(lazy[node*2+1], value);
        }
        return;
    }
    
    lli M=(L + R)/2;
    update(node*2,   L,   M, low, high, value); 
    update(node*2+1, M+1, R, low, high, value); 
    st[node] = add(st[node*2], st[node*2+1]);
    return ;
}
lli query(lli node, lli L, lli R, lli low, lli high)
{
    if(L > R or high < L or R < low) return 0LL;
    
    if(lazy[node]!=0)
    {
        st[node] = add(st[node], mul((R - L + 1), lazy[node]));
        if(L != R)
        {
            lazy[node*2] = add(lazy[node*2], lazy[node]);
            lazy[node*2+1] = add(lazy[node*2+1], lazy[node]);
        }
        lazy[node] = 0;
    }
    
    if(low <= L and R <= high) return st[node];
    
    lli M = ( L + R ) / 2;
    return add(query(2*node  , L  , M, low, high),
           query(2*node+1, M+1, R, low, high));
}
int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);
    lli n, k;
    cin>>n>>k;
    lli i, j, l[k], r[k];
    
    for(i=0;i<k;i++) cin>>l[i]>>r[i];
    
    a[0] = 1;
    build(1, 0, n+1);
    for(i=0;i<n;i++)
    {
        for(j=0;j<k;j++)
        {
            lli curl = i + l[j];
            lli curr = i + r[j];
            lli cur = query(1, 0, n+1, i, i);
            
            if(curl <= n-1)
            {
                curr = min(curr, n-1);
                update(1, 0, n+1, curl, curr, cur);
            }
        }
    }
    
    cout<<query(1, 0, n+1, n-1, n-1);
    return 0;
}

Measured memory_bytes: 11848
package main

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

const modd int = 1000000007

func main() {
	scanInit()

	n := nextInt()
	s := nextStr()
	m := map[byte]int{}
	for i := 0; i < n; i++ {
		m[s[i]]++
	}

	ans := 1 // 0だとずっと0であるため。最後に引く。
	for _, v := range m {
		ans = (ans * (v + 1)) % modd
	}

	fmt.Println(ans - 1)

}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 2000
S = input()

# 後ろから削除したいので、反転して前から削除する
S = S[::-1] 
words = {'maerd', 'remaerd', 'esare', 'resare'}

while len(S) > 0:
  orig = S
  for w in words:
    if S.startswith(w):
      S = S[len(w):]
      break
  if orig == S:
    break

if len(S) == 0: print('YES')
else: print('NO')

Measured memory_bytes: 9164
#include <iostream>
#define ll long long
using namespace std;

int x[51];
ll dp[51][51][2501]; // i番目までのカードをj枚使って合計をkになるような選び方

int main(){

  int n, a;
  cin >> n >> a;
  for(int i = 0; i < n; i++) cin >> x[i];
  dp[0][0][0] = 1;
  for(int i = 0; i < n; i++){
    for(int j = 0; j <= i; j++){
      for(int k = 0; k <= n*a; k++){
        dp[i+1][j][k] += dp[i][j][k];
        dp[i+1][j+1][k+x[i]] += dp[i][j][k];
      }
    }
  }
  ll sum = 0;
  for(int i = 1; i <= n; i++){
    sum += dp[n][i][i*a];
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 49152
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;


void call(int n){
    for(auto i = 1; i <= n; i++){
        int x = i;
        if(x % 3 == 0){
            cout << " " << i;
        }
        else if(x % 10 == 3){
            cout << " " << i;
        }
        else{
            while(x){
                x /= 10;
                if(x){
                    if(x % 10 == 3){
                        cout << " " << i;
                        break;
                    }
                }
            }
        }
    }
    cout <<endl;
}

signed main(){
    int n;

    std::cin >> n;

    call(n);

    return 0;
}


Measured memory_bytes: 3100
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.append(0)

    base = abs(a[0])
    for i in range(n):
        base += abs(a[i+1] - a[i])
    
    ans = []
    for i in range(n):
        if (a[i] - a[i-1]) * (a[i+1] - a[i]) >= 0:
            ans.append(base)
        else:
            ans.append(base - 2 * min(abs(a[i] - a[i-1]), abs(a[i+1] - a[i])))
    
    for i in ans:
        print(i)

main()

Measured memory_bytes: 90476
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

use std::cmp;

fn main() {
    let n = get!(usize);
    let mut ts = get!(String).split_whitespace().map(|i| i.parse::<usize>().unwrap() * 2).collect::<Vec<_>>();
    for i in 1..n {
        ts[i] += ts[i-1];
    }
    let vs = get!(String).split_whitespace().map(|i| i.parse::<usize>().unwrap() * 2).collect::<Vec<_>>();

    let &t_sum = ts.last().unwrap();
    let &v_max = vs.iter().max().unwrap();

    let mut tt = vec![vec![false; v_max + 1]; t_sum + 1];

    for i in 0..n {
        let s = if i == 0 { 0 } else { ts[i-1]+1 };
        for j in s..ts[i]+1 {
            tt[j][vs[i]] = true;
        }
    }

    for i in 0..cmp::min(t_sum, v_max)+1 {
        tt[i][i] = true;
    }
    for i in 0..n {
        let mut j = ts[i];
        let mut k = vs[i];
        loop {
            if j > t_sum || k > v_max {
                break;
            }
            tt[j][k] = true;
            j += 1;
            k += 1;
        }
    }
    let mut j = t_sum;
    let mut k = 0;
    loop {
        tt[j][k] = true;
        if j == 0 || k == v_max {
            break;
        }
        j -= 1;
        k += 1;
    }
    for i in 0..n-1 {
        let mut j = ts[i];
        let mut k = vs[i+1];
        if k > v_max {
            break;
        }
        loop {
            tt[j][k] = true;
            if j == 0 || k == v_max {
                break;
            }
            j -= 1;
            k += 1;
        }
    }

    let mut s = 0;
    for i in 0..t_sum+1 {
        for j in 0..v_max+1 {
            if tt[i][j] {
                break;
            }
            s += 1;
        }
    }
    println!("{:.12}", (s as f64) / 4.0);
}

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


ll findMaxGCD(vector<ll> arr, ll n) 
{ 

    ll high = 0; 
    for (ll i = 0; i < n; i++) 
        high = max(high, arr[i]); 
   
    ll count[high + 1] = {0}; 
    for (ll i = 0; i < n; i++) 
        count[arr[i]]++; 
  
    ll counter = 0; 
  
    for (ll i = high; i >= 1; i--) 
    { 
        ll j = i; 
       counter = 0; 
    

        while (j <= high) 
        { 
            
            if(count[j] >=2) 
               return j; 
  
           else if (count[j] == 1)          
                counter++;          
  

            j += i; 
  
            if (counter == 2)          
                return i; 
        } 
    } 
} 


ll findGCD(vector<ll> arr, ll n) 
{ 
    ll result = arr[0]; 
    for (ll i = 1; i < n; i++) 
    { 
        result = __gcd(arr[i], result); 
  
        if(result == 1) 
        { 
           return 1; 
        } 
    } 
    return result; 
} 


void solve(){
    ll n;
    cin>>n;
    vector<ll> vec(n);
    for(ll i=0; i<n; ++i) cin>>vec[i];

    bool pairwise = findMaxGCD(vec,n) == 1?true:false;
    // cout<<gcd_pairs(vec,n);
    bool setwise = findGCD(vec, n) == 1 ? true:false;
    if(pairwise) cout<<"pairwise coprime";
    else if(setwise) cout<<"setwise coprime";
    else cout<<"not coprime";



    
}


int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ll q;
    q=1;
    // cin>>q;
    while(q--) solve();


    return 0;
}


Measured memory_bytes: 26732
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    string s;
    cin>>s;
    vector<int> v(4);
    REP(i,4){
        v[i]=(int)(s[i]-'0');
    }
    int tmp;
    for (int bit = 7; bit >= 0;bit--){
        tmp = v[0];
        REP(i,3){
            if(bit&(int)pow(2,i)){
                tmp += v[i + 1];
            }else{
                tmp -= v[i + 1];
            }
        }
        if(tmp==7){
            cout << v[0];
            REP(i,3){
                if(bit&(int)pow(2,i)){
                    cout << "+";
                }else{
                    cout<<"-";
                }
                cout << v[i + 1];
            }
            cout<<"=7" << endl;
            return 0;
        }
    }

        return 0;
}


Measured memory_bytes: 256
def dfs(x):
    if x > N * 10:
        return
    if x >= N:
        cand.append(x)
    for y in not_dislike:
        dfs(x*10 + y)

N, K = map(int, input().split())
D = set(int(x) for x in input().split())

not_dislike = set(range(10)) - D
cand = []
for x in not_dislike-set([0]):
    dfs(x)
print(min(cand, key=lambda x: abs(x-N)))

Measured memory_bytes: 5404
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
using namespace std;
#define vel vector<long long>
#define vvel vector<vel>
#define veb vector<bool>
#define int long long
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
#define fin(fl,s) if(fl){cout<<s<<endl;return 0;}
long long p = 1000000007;
vel kai(200001, 1);
vel ink(200001, 1);
int le = (1 << 20) + 1;
vel BIT(le, 0);
vel uni(vel &list) {
	if (list.size() == 0) { return list; }
	sort(list.begin(), list.end());
	vel ql(1, list[0]);
	rep(i, list.size() - 1) {
		if (list[i] != list[i + 1]) { ql.push_back(list[i + 1]); }
	}
	list = ql;
	return ql;
}
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a) {
	return ru(a, p - 2);
}
void make_kai() {
	rep(i, 200000) { kai[i + 1] = (kai[i] * (i + 1)) % p; }
	rep(i, 200001) { ink[i] = inv(kai[i]); }
}
int com(int n, int r) {
	int ans = kai[n] * ink[r];
	ans %= p; ans *= ink[n - r]; ans %= p;
	return ans;
}
int per(int n, int r) {
	int ans = kai[n] * ink[n - r];
	ans %= p;
	return ans;
}
signed main() {
	int n; cin >> n;
	vel p(n + 6);
	veb same(n + 6, true);
	p[0] = 0; p[1] = 1; p[2] = 2;
	rep(i, n) {
		cin >> p[i + 3]; p[i + 3] += 2;
		same[i + 3] = (p[i + 3] == i + 3);
	}
	n += 3;
	rep(i, 3) { p[n + i] = n + i; }
	n += 3;
	vel wall(0);
	rep(i, n - 1) {
		if (!(same[i] ^ same[i + 1])) { wall.push_back(i + 1); }
		if (i) {
			fin(!(same[i - 1] || same[i] || same[i + 1]), "No")
		}
	}
	for (int i = 0; i + 1 < wall.size(); i++) {
		int st = wall[i];
		int to = wall[i + 1];
		vel all(to - st);
		vel samp(to - st);
		vel up(0);
		vel dow(0);
		for (int i = st; i < to; i++) {
			all[i - st] = p[i];
			samp[i - st] = i;
			if (p[i] < i) {
				dow.push_back(p[i]);
			}
			else if (p[i] > i) {
				up.push_back(p[i]);
			}
		}
		sor(all);
		fin(all != samp, "No");
		for (int i = 0; i + 1 < up.size(); i++) {
			fin(up[i] > up[i + 1], "No");
		}
		for (int i = 0; i + 1 < dow.size(); i++) {
			fin(dow[i] > dow[i + 1], "No");
		}
	}
	cout << "Yes" << endl;
	return 0;
}



Measured memory_bytes: 20856
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

typedef tuple<int, int> state; // now, clr

ll N;
ll M;
vector<int> V[100010];

int main () {
  cin >> N >> M;
  for (auto i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    V[a].push_back(b);
    V[b].push_back(a);
  }
  int visited[100010];
  fill(visited, visited+100010, 0);
  int color[100010];
  fill(color, color+100010, -1);
  stack<state> S;
  S.push(state(0, 0));
  while (!S.empty()) {
    int now = get<0>(S.top());
    int clr = get<1>(S.top());
    S.pop();
    if (visited[now] == 0) {
      visited[now] = 1;
      color[now] = clr;
      S.push(state(now, clr));
      for (auto x : V[now]) {
        S.push(state(x, 1-clr));
      }
    } else if (visited[now] == 1) {
      if (color[now] != clr) {
        cout << N * (N-1) / 2 - M << endl;
        return 0;
      }      
    }
  }
  ll black = 0;
  for (auto i = 0; i < N; ++i) {
    if (color[i] == 1) black++;
  }
  cout << black * (N - black) - M << endl;
}


Measured memory_bytes: 7168
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    int N,K;string S;cin>>N>>K>>S;
    vector<int>D;
  	if(S[0]!='1')D.eb(0);
    int ren=0;
    REP(i,N-1){
        if(S[i]!=S[i+1]){
            D.eb(ren+1);
            ren=0;
        }
        else ren++;
    }
    D.eb(ren+1);
  	if(S[S.size()-1]!='1')D.eb(0);
    int ans=0;
	vector<int>SUM(D.size()+1,0);
  	REP(i,D.size())SUM[i+1]=SUM[i]+D[i];
    int left=0;int right=K*2+1;
  	for(;left<SUM.size();left+=2){
      	if(right>=SUM.size())right=SUM.size()-1;
      	ans=max(ans,SUM[right]-SUM[left]);
      	right+=2;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2164
S = input()
ans = 0

#左端が>のときはその左に<を増やす
if S[0]=='>':
    S = '<' + S

#終端処理
#右端が<のときはその右に><を増やす
if S[len(S)-1]=='<':
    S = S + '><'
#右端が>のときはその右に<を増やす
if S[len(S)-1]=='>':
    S = S + '<'

lefts = 0
rights = 0

for i in range(len(S)):
    if S[i]=='<':
        lefts += 1
    if S[i]=='>':
        rights += 1
    if S[i]=='>' and S[i+1]=='<': #ここは絶対0になる
        M = max(lefts,rights)
        m = min(lefts,rights)
        ans += M*(M+1)/2 + m*(m+1)/2 - m
        lefts = 0
        rights = 0
        
print(int(ans))

Measured memory_bytes: 46448
import numpy as np

n = int(input())
records= np.array([int(i) for i in input().split()])

enrolled = np.argsort(records)

attendance_list = np.array([i+1 for i in range(n)])

attendance_order = np.array(attendance_list[enrolled]).tolist()

for i in attendance_order:
  print('{} '.format(i), end="")
print()


Measured memory_bytes: 23428
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
unchip = sorted(p)[::-1]
dsrxqp = unchip[0:x]
unchiq = sorted(q)[::-1]
dsrxqq = unchiq[0:y]
unchipqr = sorted(r+dsrxqq+dsrxqp)[::-1]
print(sum(unchipqr[0:x+y]))

Measured memory_bytes: 24800
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int n,y;
    cin >> n >> y;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n-i;j++){
            for(int k=0;k<=n-i-j;k++){
                if(i*10000+j*5000+k*1000==y&&i+j+k==n){
                    cout << i << " " << j << " " << k;
                    return 0;
                }
            }
        }
    }
    cout << "-1 -1 -1";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  long long int sum=0;
  for(int i=0;i<s.size();i++)
  {sum=sum+s[i]-'0';
  }
  if(sum%9==0)
    cout<<"Yes";
  else
    cout<<"No";
}
    

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

vector<string> group;
vector<string> mem[211];
set<string> st;
bool vis[211];
char inc[1024];

void dfs(int v){
	vis[v]=true;
	rep(i,mem[v].size()){
		string name=mem[v][i];
		if(exist(group,name)){
			int nv=find(all(group),name)-group.begin();
			if(vis[nv])continue;
			dfs(nv);
		}else{
			st.insert(name);
		}
	}
}

int main(){
	//cin.sync_with_stdio(false);
	while(1){
		int n=0;
		string ins;
		scanf("%d",&n);
		//dbg(n);
		if(n==0)break;
		group.clear();
		rep(i,n)mem[i].clear();
		st.clear();
		rep(i,n){
			scanf("%s",inc);
			ins=inc;
			int l=0;
			rep(j,ins.length()){
				if(ins[j]==':'){
					group.pb(ins.substr(l,j-l));
					l=j+1;
				}else if(ins[j]==','||ins[j]=='.'){
					mem[i].pb(ins.substr(l,j-l));
					l=j+1;
				}
			}
		}
		memset(vis,0,sizeof(vis));
		dfs(0);
		cout<<st.size()<<endl;
	}
	return 0;
}

Measured memory_bytes: 3328