akhauriyash/Code-Regression huggingface dataset:
M=998244353
N,*A=open(0)
d=[0]*90001
d[0]=1
e=[0]*90001
e[0]=1
z=1
s=0
for a in A:
	i=s;a=int(a);s+=a;z*=3
	while~i:d[i+a]+=d[i]%M;d[i]*=2;e[i+a]+=e[i]%M;i-=1
i=s
while i*2>=s:z=(z-d[i]*3)%M;i-=1
print([(z+e[s//2]*3)%M,z][s%2])

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

					#define F first
					#define S second
					#define N 222222
					#define M 1000000007
					#define pb push_back
					#define cend(s) return cout << s, 0
					using namespace std;
					typedef long long ll;
					typedef vector<int> vi;

					int main()
					{
						int n, t = 0;
						cin >> n;
						int l[n+9];
						for(int i = 1; i <= n; i++)
							cin >> l[i];
						for(int i = 1; i < n-1; i++)
						for(int j = i+1; j < n; j++)
						for(int q = j+1; q <= n; q++)
						{
							if(l[i]+l[j] > l[q] && l[j]+l[q] > l[i] && l[i]+l[q] > l[j])
							if(l[i] != l[q] && l[q] != l[j] && l[i] != l[j])
                              t++;
						}	
						cout << t;
					}


Measured memory_bytes: 3612
# include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,a1,b1,c1,a2,b2,c2;
  cin>>n;
  cin>>a1>>b1>>c1;
  while(--n)
  {
    cin>>a2>>b2>>c2;
	a2+=max(b1,c1);
	b2+=max(a1,c1);
	c2+=max(b1,a1);
	a1=a2,b1=b2,c1=c2;
  }
  cout<<max(a1,max(b1,c1));
return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
cnt = 0
d = [0]*(10**6+1)
a.sort()
for i in range(n):
    if d[a[i]]: continue
    cnt += 1
    if i != n-1 and a[i] == a[i+1]:
        cnt -= 1
    res = a[i]
    while res <= 10**6:
        d[res] = 1
        res += a[i]
print(cnt)

Measured memory_bytes: 97040
#include<bits/stdc++.h>
using namespace std;
#define INS(x) (x).begin(),(x).end()
#define gcd(x,y) __gcd((x),(y))



int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    double r;
    cin>>r;

    cout<<3.1415926*r*2<<'\n';  
    
    return 0;
}

Measured memory_bytes: 3804
n = int(input())
l = [list(map(int, input().split())) for _ in range(n-1)]


def left_time(time, si, fi):
    if time>si:
        a = time-si
        if a%fi:
            b = a//fi + 1
            return si + fi*b
        else:
            return time
    else:
        return si

for i in range(n-1):
    total = 0
    total = l[i][0]+l[i][1]
    for j in range(i+1, n-1):
        total = (left_time(total, l[j][1], l[j][2]) + l[j][0])
    print(total)
print(0)

Measured memory_bytes: 3316
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

n, k = input_a

sunuke = Array.new(n, 0)

k.times do |i|
  d = input_n
  a = input_a
  a.each do |okashi|
    sunuke[okashi - 1] = 1
  end
end
puts sunuke.count(0)


Measured memory_bytes: 14304
#include<fstream>
#include<sstream>
#include<algorithm>
#include<math.h>
#include<string>
#include <stdlib.h>
#include <iostream>
using namespace std;

int main() {
	string s;
	cin >> s;

	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2])
		cout << "Yes" << endl;
	else if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1])
		cout << "Yes" << endl;
	else if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;


}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    int X, A, B;
    cin >> X >> A >> B;
    cout << (X - A) % B << endl;
    return 0;

}

Measured memory_bytes: 256
import qualified Data.Vector as V (Vector, fromList, (!))
import Control.Applicative

import Debug.Trace


binarySearch :: (V.Vector Int, Int, Int) -> Int -> Bool
binarySearch (vec, s, e) a
  | v == a = True
  | s >= e = False
  | v >  a = binarySearch (vec, s, n - 1) a
  | v <  a = binarySearch (vec, n + 1, e) a
  where
    n = div (s + e) 2
    v = vec V.! n

main :: IO ()
main = do
  _ <- getLine
  s <- map read . words <$> getLine
  _ <- getLine
  t <- map read . words <$> getLine
  let vec = V.fromList s
  let ans = length $ filter (binarySearch (vec, 0, length s - 1)) t
  print ans



Measured memory_bytes: 110120
use strict;
use warnings;
package Scc;
sub new{
	return bless[map[],1..$_[1]],$_[0];
}
sub add_edge{
	my$self=shift;
	push@{$self->[$_[0]]},$_[1];
}
sub scc_ids{
	my$self=shift;
	my$now_ord=0;
	my$group_num=0;
	my@low;
	my@ord=(-1)x@{$self};
	my@ids;
	my@visited;
	my$dfs;
	$dfs=sub{
		my$v=shift;
		$low[$v]=$ord[$v]=$now_ord++;
		push@visited,$v;
		for my$to(@{$self->[$v]}){
			if($ord[$to]==-1){
				$dfs->($to);
				$low[$v]=$low[$to]if$low[$v]>$low[$to];
			}
			else{
				$low[$v]=$ord[$to]if$low[$v]>$ord[$to];
			}
		}
		if($low[$v]==$ord[$v]){
			my$u=-1;
			while($u!=$v){
				$u=pop@visited;
				$ord[$u]=@{$self};
				$ids[$u]=$group_num;
			}
			$group_num++;
		}
	};
	for(0..$#ord){
		$dfs->($_)if$ord[$_]==-1;
	}
	$_=$group_num-1-$_ for@ids;
	return($group_num,\@ids);
}
sub scc{
	my$self=shift;
	my($group_num,$ids)=$self->scc_ids();
	my@groups=map[],1..$group_num;
	for(0..$#{$ids}){
		push@{$groups[$ids->[$_]]},$_;
	}
	return\@groups;
}
package TwoSat;
@TwoSat::ISA=qw(Scc);
sub new{
	return$_[0]->SUPER::new($_[1]*2);
}
sub add_clause{
	my$self=shift;
	$self->add_edge(2*$_[0]+!$_[1],2*$_[2]+!!$_[3]);
	$self->add_edge(2*$_[2]+!$_[3],2*$_[0]+!!$_[1]);
}
sub satisfiable{
	my$self=shift;
	my$ids=($self->scc_ids())[1];
	my@answer;
	for(0..@{$ids}/2-1){
		return 0 if$ids->[2*$_]==$ids->[2*$_+1];
		$answer[$_]=$ids->[2*$_]<$ids->[2*$_+1];
	}
	return(1,\@answer);
}
package main;
my($N,$D)=split$",<>;
my$twosat=TwoSat->new($N);
my@p;
for(1..$N){
	my($x,$y)=split$",<>;
	push@p,[$x,$y];
}
for my$i(0..$N-1){
	for my$j($i+1..$N-1){
		$twosat->add_clause($i,1,$j,1)if abs$p[$i][0]-$p[$j][0]<$D;
		$twosat->add_clause($i,1,$j,0)if abs$p[$i][0]-$p[$j][1]<$D;
		$twosat->add_clause($i,0,$j,1)if abs$p[$i][1]-$p[$j][0]<$D;
		$twosat->add_clause($i,0,$j,0)if abs$p[$i][1]-$p[$j][1]<$D;
	}
}
my($isok,$answer)=$twosat->satisfiable();
if($isok){
	print"Yes",$/;
	for(0..$N-1){
		print$p[$_][$answer->[$_]],$/;
	}
}
else{
	print"No",$/;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const ll MAX = 10000;
static const ll INFTY = 1e12;
static const ll MOD = 1e9+7;

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



int main() {

  int x;
  cin >> x;
  cout << !x << endl;


 


}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3592
#include<iostream>
using namespace std;
int n,a[33],cnt;
main()
{
    while(cin>>n,n)
    {
        cnt=0;
        for(int i=0;i<n;i++)cin>>a[i];
        int b[33];
        while(1)
        {
            for(int i=0;i<n;i++)
            {
                b[i]=0;
                for(int j=0;j<n;j++)b[i]+=a[i]==a[j];
            }
            bool f=1;
            for(int i=0;i<n;i++)f&=a[i]==b[i];
            if(f)
            {
                cout<<cnt<<endl;
                for(int i=0;i<n;i++)cout<<b[i]<<(i==n-1?"\n":" ");
                break;
            }
            cnt++;
            for(int i=0;i<n;i++)a[i]=b[i];
        }
    }
}


Measured memory_bytes: 3068
//K-OS WITH THE OCDE

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <iostream>
#include <numeric>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <climits>

using namespace std;

typedef long long int ll;
typedef long double db;


#define TEST ll t; cin>>t; while(t--)
#define vell vector<ll>
#define pl pair<ll,ll>
#define all(v) v.begin(),v.end()
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define dbg(x)  cerr << #x << ": "<< x <<endl
#define dbg2(x,y) cerr<< #x <<": "<< x <<" || "<< #y << ": " << y << endl

#define endl "\n"
#define MAX 1e18
#define MIN INT_MIN
#define mod 1000000007



void solve()
{
	ll n;
	cin >> n;
	ll a[n];
	ll f = 0 ;
	vell v;
	for (ll i = 0 ; i < n ; ++i) {
		cin >> a[i];

	}


 map <ll,ll> mp;
	for (ll i = 0 ; i < n ; ++i) {
		for (ll j = i + 1 ; j < n ; ++j) {
			for (ll k = j + 1 ; k < n ; ++k) {
                    v.pb(a[i]);
                    mp[a[i]]++;
                    v.pb(a[j]);
                    mp[a[j]]++;
                    v.pb(a[k]);
                    mp[a[k]]++;
                    sort(all(v));


                    if((v[0] + v[1] > v[2]) && (v[1] + v[2] > v[0]) && (v[0] + v[2] > v[1]) && mp.size() == 3)
                    	f++;

                    mp.clear();

                    v.clear();
			}
		}
	}

	cout << f;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0);
	//TEST
	solve();
}



Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    if (s[i - 1] != s[i]) ans++;
  }
  cout << ans + 1 << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  string S;cin >> S;
  int x=0,m = 0;
  rep(i,N){
    if(S[i]=='I')++x;
    else --x;
    m = max(m,x);
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 256
/*#define _USE_MATH_DEFINES
#include<cmath>*/
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}	

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M; cin >> N >> M;
	vector<pair<int, string>>ps(M);
	rep(i, M) {
		int a; cin >> a;
		string s; cin >> s;
		ps[i] = make_pair(a, s);
	}
	int ac = 0, wa = 0;
	vector<bool>is(N, false);
	vector<int>cnt(N, 0);
	rep(i, M) {
		if (is[ps[i].first-1])continue;
		else if (ps[i].second == "AC") {
			is[ps[i].first - 1] = true;
		}
		else if (ps[i].second == "WA") {
			++cnt[ps[i].first-1];
		}
	}
	rep(i, N) {
		if (is[i]) {
			ac++;
			wa += cnt[i];
		}
	}
	cout << ac << " " << wa << "\n";


	return 0;
}


Measured memory_bytes: 6912
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def main():
    n = int(input())
    csf = tuple(tuple(map(int, line.split())) for line in sys.stdin.readlines())
    ans = []
    for i in range(n - 1):
        t = 0
        for c, s, f in csf[i:]:
            if t < s:
                t = s
            k, r = divmod(t - s, f)
            if r != 0:
                t = s + (k + 1) * f
            t += c
        ans.append(t)
    ans.append(0)

    print(*ans, sep='\n')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include "stdio.h"
#include "stdarg.h"
#include "math.h"
#include "limits.h"

#define SWAP(type,a,b) do{type c=a;a=b;b=c;}while(0)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define DEBUG(format,a) do{printf(#a" : "#format,a);}while(0)


int main() {
	char s1[101], s2[101];
	scanf("%s %s", &s1, &s2);
	printf("%s%s", s2, s1);
	return 0;
}


Measured memory_bytes: 128
#include "stdio.h"


int main()
{
	int n, m, i, j, num;
	int max = 0;
	int a[1001] = { 0 };

	while (1) {
		scanf("%d %d", &n, &m);
		if (n == 0 && m == 0) {
			break;
		}


		for (i = 0; i < n; i++) {
			scanf("%d", &a[i]);
		}

		for (i = 0; i < n - 1; i++) {
			for (j = i+1 ; j < n; j++) {
				num = a[i] + a[j];
				if (num <= m) {
					if (num > max) {
						max = num;
					}
				}
			}
		}

			if (max == 0) {
				printf("NONE\n");
			}
			else {
				printf("%d\n", max);
			}
			max = 0;
	}
		return 0;
}



Measured memory_bytes: 2052
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);
    String s;
    char[] ss;


    void run(){
	while(sc.hasNext()){
	    s = sc.nextLine();
	    solve();
	}
    }

    void solve(){
	ss = s.toCharArray();
	int level = 0;
	for(; level<26; level++){
	    if(change(ss)){
		show(ss);
		return;
	    }
	}
    }

    boolean change(char[] ss){
	for(int i=0; i<ss.length; i++){
	    if(ss[i]>='a' && ss[i]<='z'){
		if(ss[i]+1>'z'){
		    ss[i] = 'a';
		}
		else ss[i] += 1;
	    }
	}
	//show(ss);
	if(check(ss)) return true;
	else return false;
    }

    void show(char[] ss){
	for(int i=0; i<ss.length; i++)
	    System.out.print(ss[i]);
	System.out.println();
    }

    boolean check(char[] ss){
	String c = "";
	for(int i=0; i<ss.length; i++){
	    if(c.length()==0 && ss[i]=='t'){
		int k = i;
		while(k<ss.length && ss[k]!=' '){
		    c += ss[k];
		    k++;
		}
		if(c.equals("the") || c.equals("this") || c.equals("that"))
		    return true;
		else c = "";
	    }
	}
	return false;
    }
}

Measured memory_bytes: 17216
#include <stdio.h>
#include <string>
#include <iostream>
#include <map>
using namespace std;

int main(void){
    int N,M,Q;
    cin >> N >> M >> Q;
    int sum[505][505]={0};
    int l,r;
    int p[100005],q[100005];
    for(int i=1; i<=M; i++){
        scanf("%d%d",&l,&r);
        sum[l][r]+=1;
    }
    //ij間に区間が完全に含まれる本数
    for(int i=1; i<=N; i++){
        for(int j=1; j<=N; j++){
            sum[i][j]+=sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1];
        }
    }
    //質問に答える
    int ans;
    for(int i=1; i<=Q; i++){
        scanf("%d%d",&p[i],&q[i]);
    }
    for(int i=1; i<=Q; i++){
        ans=sum[q[i]][q[i]]-sum[q[i]][p[i]-1]-sum[p[i]-1][q[i]]+sum[p[i]-1][p[i]-1];
        printf("%d\n",ans);
    }
    return 0;
}

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

current = 1
broken = 0
for i in range(n):
    if a[i] == current:
        current += 1
    else:
        broken += 1
if current == 1 and broken > 0:
    print('-1')
else:
    print(broken)

Measured memory_bytes: 24744
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>>
#define CO cout<<
#define EN <<endl
#define all(x) (x).begin(),(x).end()
using namespace std;
 
template <typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}
 
using ll = long long;

int main(){
    int a,ans=0; CI a;
    string s; CI s;
    set<char> st;
	
	REP(i,a){
		int tmp=0;
		set<char> st2;
		st.insert(s[i]);
		FOR(j,i+1,a-1){
			st2.insert(s[j]);
		}
		for(auto x:st){
			for(auto y:st2){
				if(x==y)tmp++;
			}
		}
		if(tmp>ans)ans=tmp;
	}
	
    CO ans EN;

    return 0;
}

Measured memory_bytes: 256
<?php
    $seconds = fgets(STDIN);
    $hours = 3600;
    $hours = $seconds / 3600;
    $minute = ($seconds % 3600) / 60;
    $second = ($seconds % 3600) % 60;
    echo (int)$hours . ":" . (int)$minute . ":" . (int)$second . "\n";
?>


Measured memory_bytes: 9192
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define pb push_back


///Input/Output macros!
#define gi(x) scanf("%d", &x)
#define gi2(x, y) scanf("%d%d", &x, &y)
#define gi3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define gill(x) scanf("%lld", &x)
#define gill2(x, y) scanf("%lld%lld", &x, &y)
#define gill3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define pi(x) printf("%d\n", x)
#define pill(x) printf("%lld\n", x)


///Basic Debugging macros!
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(ll __i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(ll __i__=0;__i__<r;__i__++){for(ll __j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}

using namespace std;

///Power of 2 till 2^31!
ll pow2[32] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648};

///Power function!
ll power(ll x,ll y)
{
        ll res = 1;
        while(y>0){
            if(y&1)
                res *= x;
            y>>=1;
            x*=x;
        }
        return res;
}
map<ll,ll> mp;
///Basic Sieve of Eratosthenes!
void Sieve(ll n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (ll p=2; p<=n; p++)
       if (prime[p])
        ++mp[p];
          //cout << p << " ";
}

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

bool isPerfectSquare(ll x){ ll s = sqrt(x); return (s*s == x);}

bool isFibonacci(int n){return isPerfectSquare(5*n*n + 4) || isPerfectSquare(5*n*n - 4);}

bool isPrime(int n){if (n <= 1)return false;if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0)return false;
    return true;
}

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;


const int MOD = 1000000007;
const long double PI = 4*atan((long double)1);
const ll INF = 1e18;

int main()
{
    ios::sync_with_stdio(false);
    int a[2];
    cin>>a[0]>>a[1];
    for(int i=1;i<4;++i){
            int cnt=0;
        for(int j=0;j<2;++j){
            if(a[j]==i){
                cnt++;
                break;
            }
        }
    if(!cnt){cout<<i<<'\n';return 0;}
    }
}


Measured memory_bytes: 256
import sys
from math import sqrt
from collections import Counter, defaultdict, deque

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    s = input()
    for n in s:
        if n == "7":
            print("Yes")
            exit()
    print("No")
    pass


if __name__ == "__main__":
    main()


Measured memory_bytes: 65200
n = int(input())
inab = 0
topb = 0
taila = 0
topb_taila = 0
for _ in range(n):
    s = str(input())
    if (s[0] == "B")&(s[-1] == "A"):
        topb_taila += 1
    else:
        if (s[0] == "B"):
            topb += 1
        if (s[-1] == "A"):
            taila += 1
    
    bef =""
    for i in range(len(s)):
        if (bef=="A")&(s[i]=="B"):
            inab += 1
        bef = s[i]

ans = inab

topb += topb_taila
taila += topb_taila

if topb==taila:
    if topb==topb_taila:
        if topb==0:
            ans+=0
        else:
            ans += topb-1
    else:
        ans += topb
else:
    ans += min(topb,taila)

print(ans)

Measured memory_bytes: 45912
import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}

object Main extends App {
  val n = in.readInt
  val a = in.readLine.split(" ").map(_.toInt)

  val c = (0 until n).map { i =>
    a(i) - (i+1) 
   }.sorted
  val b = c(n/2)

  val ans = a./:(0L, 1L){  (elm, ai) =>
    val (acc, idx) = elm
    (acc + (ai - (b + idx)).abs, idx + 1L)
  }._1

  println(ans)
}

Measured memory_bytes: 63952
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

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

int visit[MAX_N][MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,K;
    cin >> h >> w >> K;
    vs s(h);
    int sx,sy;
    rep(i,h){
        cin >> s[i];
        rep(j,w){
            if(s[i][j] == 'S'){
                sx = i, sy = j;
            }
        }
    }
    rep(i,h){
        rep(j,w){
            visit[i][j] = INF;
        }
    }
    queue<P> que;
    visit[sx][sy] = 0;
    que.push(P(sx,sy));
    while(!que.empty()){
        P p = que.front();
        que.pop();
        rep(i,4){
            int nx = p.fi + dx[i], ny = p.se + dy[i];
            if(nx >= 0 && nx < h && ny >= 0 && ny < w && s[nx][ny] != '#' && visit[nx][ny] > visit[p.fi][p.se]+1){
                visit[nx][ny] = visit[p.fi][p.se]+1;
                que.push(P(nx,ny));
            }
        }
    }
    int dist = INF;
    rep(i,h){
        rep(j,w){
            if(visit[i][j] <= K) cmn(dist,min({i,h-1-i,j,w-1-j}));
        }
    }
    cout << (dist+K-1)/K+1 << "\n";
    return 0;
}


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


int main(){

  int n;
  int a[100];
  int tmp;
  int sum=0;
  bool flg=true;

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

  while(flg){
    flg = 0;
    for(int j=n-1; j>0; j--){
      if(a[j] < a[j-1]){
	tmp = a[j];
	a[j] = a[j-1];
	a[j-1]=tmp;

	sum ++;
	flg = true;
      }
    }
  }

  cout << a[0];
  for(int i=1; i<n; i++)
    cout << ' ' << a[i];

  cout << endl << sum << endl;

  return 0;
}

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

int main(){
    array<int, 5> A;
    A[0] = A[1] = A[2] = A[3] = A[4] = 0;
    for(int i = 0, a, b; i < 3; ++i){
        cin >> a >> b;
        ++A[a];
        ++A[b];
        if(A[a] >= 3)return 0 & puts("NO");
        if(A[b] >= 3)return 0 & puts("NO");
    }
    puts("YES");
    return 0;
}

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

namespace CSharpSample01
{
	class Program
	{



	static void Main(string[] args)
		{
			var valueList = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			var N = valueList[0];
			var K = valueList[1];

			var sunukeDic = new Dictionary<int, int>();

			// 初期化
			for(int i = 1; i <= N; i++)
			{
				sunukeDic.Add(i, 0);
			}

			for(int i = 0;i < K; i++)
			{
				// 何個お菓子があるか？
				var okasiNum = int.Parse(Console.ReadLine());
				var okasiSunukeList = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

				for(int d = 0; d < okasiNum; d++)
				{
					sunukeDic[okasiSunukeList[d]]++;
				}
			}

			var answer = 0;
			// 回答計算
			for (int i = 1; i <= N; i++)
			{
				if(sunukeDic[i] == 0)
				{
					answer++;
				}
			}

			Console.WriteLine(answer);

		}
	}
}

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

string s;

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

    cin >> s; s.push_back('#');
    for(int i=0;i<(int)s.size();i++){
        if(s[i] == s[i+1]){
            puts("Bad");
            return 0;
        }
    }
    puts("Good");


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main(void) {
	int num, i = 0, a;
	string s;
	cin >> num;
	vector<pair<string, int>> d(num);
	map<int, int> pos;
	for (; i < num; i++) {
		cin >> d[i].first >> d[i].second;
		d[i].second = 100 - d[i].second;
		pos[d[i].second] = i;
	}
	sort(d.begin(), d.end());
	for (i = 0; i < num; i++)
		cout << pos[d[i].second] + 1 << "\n";
	return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	vector<tuple<int,int,bool>> v;
	int n;
	cin>>n;
	for(int i=0;i<n;++i){
		int x,y;
		cin>>x>>y;
		v.emplace_back(x,y,0);
	}
	for(int i=0;i<n;++i){
		int x,y;
		cin>>x>>y;
		v.emplace_back(x,y,1);
	}
	sort(v.begin(),v.end());
	set<int> s;
	int res=0;
	for(int i=0;i<2*n;++i)
		if(!get<2>(v[i])) s.insert(get<1>(v[i]));
		else{
			int y=get<1>(v[i]);
			auto it=s.lower_bound(y);
			if(it==s.begin()) continue;
			res++;
			it--;
			s.erase(*it);
		}
	cout<<res<<'\n';
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


int main() {
  ll n; cin >> n;
  Vll a(n); cin >> a;

  ll m = n/2;

  if (n % 2 == 1) {
    VVll dp(m+1, Vll(3));
    rep(i, m) {
      dp[i+1][2] =      dp[i][2] + a[2*i+2];
      chmax(dp[i+1][2], dp[i][1] + a[2*i+2]);
      chmax(dp[i+1][2], dp[i][0] + a[2*i+2]);

      dp[i+1][1] =      dp[i][1] + a[2*i+1];
      chmax(dp[i+1][1], dp[i][0] + a[2*i+1]);
      
      dp[i+1][0] =      dp[i][0] + a[2*i];
    }

    ll ans = *max_element(all(dp[m]));
    cout << ans << endl;
  }
  else {
    VVll dp(m+1, Vll(2));
    rep(i, m) {
      dp[i+1][1] =      dp[i][1] + a[2*i+1];
      chmax(dp[i+1][1], dp[i][0] + a[2*i+1]);
      
      dp[i+1][0] =      dp[i][0] + a[2*i];
    }

    ll ans = *max_element(all(dp[m]));
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 10328
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void){
    long long int n, i, j, max=0, ans=0, btn=1, ok=0;
    scanf("%lld", &n);
    long long int a[n][n-1], aa[n], aaa[n], b[n][n-1];
    for(i=0; i<n; i++){
        for(j=0; j<n-1; j++){
            scanf("%lld", &b[i][j]);
            b[i][j]--;
        }
        aa[i] = 0;
    }
        for(i=0; i<n; i++){
            for(j=0; j<n-1; j++){
                a[i][j] = b[i][n-j-2];
            }
        }
    while(btn>0){
        btn=0;
        for(i=0; i<n; i++){
            if(aa[i] == n-1) aaa[i] = -1;
            else aaa[i] = a[i][aa[i]];
        }
        for(i=0; i<n; i++){
            if(aaa[i]!=-1){
                if(aaa[aaa[i]] == i && i<aaa[i]){
                    aa[i]++;
                    aa[aaa[i]]++;
                    btn++;
                }
            }
        }
        ans++;
        for(i=0; i<n; i++){
            if(aa[i]!=n-1) break;
            if(i == n-1) ok++;
        }
        if(ok>0) break;
//        printf("%lld %lld %lld %lld\n", ans, aa[0], aa[1], aa[2]);
    }
    if(ok>0) printf("%lld", ans);
    else printf("-1");
    
}

Measured memory_bytes: 15744
a = [1, 3, 5,  7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]

# print(a)
# print(b)
# print(c)

x, y = map(int, input().split())

# print(a.index(x))
# print(b.index(x))
# print(c.index(x))

# print(a.index(y))
# print(b.index(y))
# print(c.index(y))

# print(x in a)
# print(x in b)
# print(x in c)

# print(b in a)
# print(b in b)
# print(b in c)

if x in a and y in a:
    print('Yes')
elif x in b and y in b:
    print('Yes')
elif x in c and y in c:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
x = int(input())

a = 0

while True:
    b5 = a**5 - x
    
    if b5 >= 0:
        for b in range(b5+1):
            if b**5 == b5:
                print(a, b)
                exit()
            if b**5 > b5:
                break
    else:
        b5m = -b5
        for bm in range(b5m+1):
            if bm**5 == b5m:
                print(a, -bm)
                exit()
            if bm**5 > b5m:
                break
    
    a += 1



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

int main(void)
{
  int i, c = 0;
  char s[17];
  char t[17] = {"CODEFESTIVAL2016"};

  scanf("%s", s);

  for (i = 0; i < 16; i++) {
    if (s[i] != t[i]) {
      s[i] = t[i];
      c++;
    }
  }

  printf("%d\n", c);
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define tll tuple<ll, ll, ll>
#define all(c) c.begin(),c.end()

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
 
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;

char albt[26] = {'a','b','c','d','e','f','g','h','i','j','k','l',
                 'm','n','o','p','q','r','s','t','u','v','w','x',
                 'y','z'};

//vector<ll> g[202020];
//fill(score, score+202020, 0);
//vector<ll> v[505];

int main(){
  ll n;
  cin >> n;
  n = n-1;
  if(n%2==1) cout << (1+n)*(n/2)+(n/2)+1 << endl;
  if(n%2==0) cout << (1+n)*n/2 << endl;
  
  //cout << max << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
ll dp[51][51][2510];//i番目 j個 合計k

main(){
    int N,A;
    cin >> N >> A;
    vector<int> X(N);
    rep(i,0,N)cin >> X[i];
    dp[0][0][0] = 1;
    rep(i,0,N)rep(j,0,N)rep(k,0,2500){
        dp[i+1][j][k] += dp[i][j][k];
        if(k + X[i] > 2500)continue;
        dp[i+1][j+1][k+X[i]] += dp[i][j][k];
    }
    ll sum = 0;
    rep(i,1,N+1)sum += dp[N][i][i * A];
    cout << sum << endl;
}

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

typedef long long ll;
ll lcm( ll a, ll b ){
  return a * b / __gcd( a, b );
}
ll N,K;
ll sc=11;

ll get(ll i, ll j ){
  ll pr = 0;
  for(ll y=i;y<i+3;y++)
    for(ll x=j;x<j+3;x++)
      pr += (7LL*y+x);
  return pr;
}
ll solve( ll n ){
  if( n <= 0 ) return 0;
  if( n > sc ){
    return solve( n % sc ) + solve( sc ) * (ll)(n/sc);
  } else {
    ll ret = 0;
    for(ll i=0;i<n;i++){
      for(ll j=1;j<=5;j++){
        if( get( i,j ) % 11 == K ) {
          //          cout << i << "( " << i % 11 << " )  : " << j << endl;
          ret++;
        }
      }
    }
    return ret;
  }
}

int main(){
  cin >> N >> K;
  cout << solve( N-2 ) << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string btos(bool ans){
  return (ans?"Yes":"No");
}
ll Lucus(int n){
  if(n==0)return 2;
  if(n==1)return 1;
  ll L,L_1=1,L_2=2;
  fori(i,2,n+1){
    L=L_1+L_2;
    L_2=L_1;
    L_1=L;
  }
  return L;
}

int main() {
  int n;cin>>n;
  ll ans=Lucus(n);
  cout << ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;

int main() {
	int N, M, sum = 0;
	cin >> N;
	vector<int> T(N);
	for (int i = 0; i < N; i++) {
		cin >> T[i];
		sum += T[i];
	}
	cin >> M;
	vector<int> P(M), X(M);
	for (int i = 0; i < M; i++) {
		cin >> P[i] >> X[i];
		cout << sum - T[P[i] - 1] + X[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int N,K,W[200005],i,j,r,l,m;
int bs(int p)
{
	int i,t=0,c=1;
	for(i=0;i<N;i++)
	{
		if(W[i]>p)return 0;
		if(t+W[i]>p)
		{
			c++;
			t=0;
		}
		t+=W[i];
	}
	return c<=K;
}
int main()
{
	scanf("%d%d",&N,&K);
	for(i=0;i<N;i++)
		scanf("%d",&W[i]);
	for(l=0,r=2147483647;l<r;)
	{
		m=(l+r)/2;
		if(bs(m))
			r=m;
		else
			l=m+1;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 988
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        var nx = Console.ReadLine().Split().Select(int.Parse).ToArray();
        long X = nx[1];
        //ちゅーごくじょーよてーり
        //オーダーによってSの終端が決定する
        //まず影響するのは降順のみなことは自明に分かって、
        //で、「次」を選ぶことができる順番は
        //「確率」「期待値」
        //aを取り除いた場合、その後に適用できるのはそれ以前全て。

        int[] s = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(x => x).ToArray();

        long[] dp = new long[X + 1];
        dp[X] = 1;
        int remain = s.Length - 1;
        foreach (var mod in s)
        {
            long[] newDP = new long[X + 1];

            for (int i = 0; i < dp.Length; i++)
            {
                newDP[i % mod] += dp[i];
                newDP[i % mod] %= 1000000007;
                newDP[i] += dp[i] * remain;
                newDP[i] %= 1000000007;
            }
            remain--;
            dp = newDP;
        }

        ModInt res = 0;
        for (int i = 0; i < dp.Length; i++)
        {
            res += dp[i] * i;
        }
        Console.WriteLine(res);
    }
}

struct ModInt
{
    const int MOD = 1000000007;
    long Data;
    public ModInt(long data) { Data = data; Eval(); }

    private long Eval() => (Data %= MOD) < 0 ? Data += MOD : Data;
    public static implicit operator long(ModInt modInt) => modInt.Eval();
    public static implicit operator ModInt(long val) => new ModInt(val);
    public static ModInt operator +(ModInt a, ModInt b) => new ModInt(a.Eval() + b.Eval());
    public static ModInt operator -(ModInt a, ModInt b) => new ModInt(a.Eval() - b.Eval());
    public static ModInt operator *(ModInt a, ModInt b) => new ModInt(a.Eval() * b.Eval());
    public static ModInt operator /(ModInt a, ModInt b) => a * Power(b.Eval(), MOD - 2);

    public override string ToString() => Data.ToString();

    static ModInt Power(ModInt n, long m)
    {
        ModInt res = 1;
        while (m > 0)
        {
            if ((m & 1) == 1) res *= n;
            n *= n;
            m >>= 1;
        }
        return res;
    }
}


Measured memory_bytes: 31696
n,m =map(int, input().split())
ab =[]
for i in range(n):
    a,b =map(int, input().split())
    ab.append([a,b])
ab.sort()
sum =0
count =0
num =0
for i in range(n):
    price =ab[i][0]*ab[i][1]
    if ab[i][1] +count <= m:
        count +=ab[i][1]
        sum +=price
    else:
        num += m -count
        sum +=num*ab[i][0]
        break
print(sum)

Measured memory_bytes: 20072
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 2005
#define ba 47
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 998244353,inv2 = (MOD + 1) / 2;
int N,A[(1 << 18) + 5],S;
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void update(int &x,int y) {
    x = inc(x,y);
}
int fpow(int x,int c) {
    int res = 1,t = x;
    while(c) {
	if(c & 1) res = mul(res,t);
	t = mul(t,t);
	c >>= 1;
    }
    return res;
}
vector<int> trans(vector<int> p,vector<int> m) {
    if(p.size() == 1) {
	if(p[0] == 0 && m[0] == 0) return (vector<int>){1};
	else return (vector<int>){mul(m[0],fpow(p[0],MOD - 2))};
    }
    vector<int> p0,p1,m0,m1;
    for(int i = 0 ; i < p.size() ; i += 2) {
	p0.pb(inc(p[i],p[i + 1]));
	p1.pb(inc(p[i],MOD - p[i + 1]));
	m0.pb(inc(m[i],m[i + 1]));
	m1.pb(inc(m[i],MOD - m[i + 1]));
    }
    p0 = trans(p0,m0);p1 = trans(p1,m1);
    vector<int> res;
    for(int i = 0 ; i < p0.size() ; ++i) {
	res.pb(mul(inc(p0[i],p1[i]),inv2));
	res.pb(mul(inc(p0[i],MOD - p1[i]),inv2));
    }
    return res;
}
void Solve() {
    read(N);
    for(int i = 0 ; i < (1 << N) ; ++i) {
	read(A[i]);
	update(S,A[i]);
    }
    S = fpow(S,MOD - 2);
    for(int i = 0 ; i < (1 << N) ; ++i) {
	A[i] = mul(A[i],S);
    }
    vector<int> a,b;
    b.pb((1 << N) - 1);
    for(int i = 1 ; i < (1 << N) ; ++i) b.pb(-1);
    for(int i = 0 ; i < (1 << N) ; ++i) {
	int t = A[i];
	if(i == 0) t = inc(t,MOD - 1);
	a.pb(t);
    }
    vector<int> ans = trans(a,b);
    for(int i = 0 ; i < (1 << N) ; ++i) {
	out(inc(ans[i],MOD - ans[0]));enter;
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}



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

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using ull = unsigned long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using ii = pair<int,int>;
using vii = vector<ii>;
using vvii = vector<vii>;
using dd = pair<double, double>;
using vdd = vector<dd>;
using vvdd = vector<vdd>;
using Mii = map<int,int>;
using vMii = vector<Mii>;

#define fi first
#define se second
#define INF INT_MAX
#define mod(a,m) (a%m+m)%m
#define PB push_back
#define MP make_pair

void max_self(ll& a, ll b) {
	a = max(a, b);
}

int main(){
//	cout.setf(ios::fixed);
//	cout.precision(4);
	int n;
	while (cin >> n) {
		vi h(n), a(n);
		for (int i = 0; i < n; ++i) cin >> h[i];
		for (int i = 0; i < n; ++i) cin >> a[i];
		
		ll l = 1;
		while (l <= n) l <<= 1;
		vll tree(2*l, 0);
		vll dp(n+1, 0);
		for (int i = 0; i < n; ++i) {
			int left = l;
			int right = l + h[i];
			while (left != right) {
				if(right%2 == 0) max_self(dp[h[i]], tree[right--]);
				left >>= 1;
				right >>= 1;
			}
			max_self(dp[h[i]], tree[right]);
			dp[h[i]] += a[i];
			int j = h[i] + l;
			while(j != 1) {
				j >>= 1;
				max_self(tree[j], dp[h[i]]);
			}
		}
		ll ans = 0;
		for (int i = 0; i <= n; ++i) {
			max_self(ans, dp[i]);
		}
		cout << ans << '\n';
	}
}




Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define rrep(i,n) for(int i=(n);i>=0;--i)
#define ssort(n) sort((n).begin(),(n).end())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define INF 10101010

int main()
{
    vector<int> x(5);
    rep(i,5)cin >> x[i];
    rep(i,5){
        if(x[i]==0){
            cout << i+1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3588
import java.util.*;
public class Main {
	Scanner sc;
	void run() {
		sc = new Scanner(System.in);
		int dx[] = {-1,1,0,0};
		int dy[] = {0,0,-1,1};
		while(true) {
			int h = sc.nextInt();
			int w = sc.nextInt();
			if( w == 0 && h == 0  ) break;
			int[][] room = new int[h][w];
			boolean[][] visited = new boolean[h][w];
			
			for(int i=0;i<h;i++) {
				String str = sc.next();
				for(int j=0;j<w;j++) {
					room[i][j] = 0;
					visited[i][j] = false;
					if(str.charAt(j) == '<') room[i][j] = 1;
					else if(str.charAt(j) == '>') room[i][j] = 2;
					else if(str.charAt(j) == '^') room[i][j] = 3;
					else if(str.charAt(j) == 'v') room[i][j] = 4;
//					System.out.print(room[i][j] + " ");
//					if(j % w== w-1) System.out.println();
				}
			}
			int x = 0,y = 0;
			boolean loop = false;
			while(true) {
				if(room[y][x] == 0) break;
				if(visited[y][x]) {
					loop = true;
					break;
				}
				visited[y][x] = true;
				int tmp = x;
				x += dx[ room[y][x]-1 ];
				y += dy[ room[y][tmp]-1 ];
			}
			if(loop) System.out.println("LOOP");
			else System.out.println(x + " " + y);
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

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

int main(){
string S,T;
  cin>>S>>T;
  T+=T ;
  int c=0;
     // cout<<T<<endl;
  for(int i=0;i<=S.size();i++){
  if(T.substr(i,S.size())==S)
    c++;
  }
  if(c>0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

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

using namespace std;
using ll = long long;

class Dijkstra {
  using QItem = pair<ll, int>;

 public:
  vector<ll> minDistance(vector<vector<pair<int, ll>>> &distances, int n,
                         int src) {
    vector<ll> costs(n, -1);
    costs[src] = 0;

    vector<bool> used(n, false);
    priority_queue<QItem, vector<QItem>, greater<QItem>> q;
    q.push({0, src});

    while (!q.empty()) {
      // 未確定で，コストの一番低いノードを選択する
      auto [min_cost, min_idx] = q.top();
      q.pop();

      // 選択したノードは確定とする
      used[min_idx] = true;

      // 選択したノードの隣接ノードについて，そのコストを再計算する
      for (auto &p : distances[min_idx]) {
        ll new_cost = min_cost + p.second;
        if (costs[p.first] < 0 || costs[p.first] > new_cost) {
          costs[p.first] = new_cost;
          q.push({new_cost, p.first});
        }
      }
    }

    return costs;
  }
};

int main(int argc, const char *argv[]) {
  int n, m, s;
  cin >> n >> m >> s;

  // costs[i][j]: (移動先，運賃，時間)
  vector<vector<array<ll, 3>>> costs(n);
  ll max_a = 0;
  for (int i = 0; i < m; i++) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    max_a = max(max_a, a);
    costs[u].push_back({v, a, b});
    costs[v].push_back({u, a, b});
  }

  // (枚数，交換にかかる時間)
  vector<pair<ll, ll>> rates(n);
  for (auto &r : rates) {
    cin >> r.first >> r.second;
  }

  // 銀貨の必要最大枚数
  int max_s = max_a * m;
  s = min(s, max_s);

  auto calc_key = [&](int i, int s) { return (max_s + 1) * i + min(s, max_s); };

  // 頂点と辺を増やす
  // distances[i][j] = (繋がっている先，コスト)
  int cnt = 0;
  vector<vector<pair<int, ll>>> distances(n * (max_s + 1));
  for (int i = 0; i < n; ++i) {
    // それぞれの都市について処理する
    // j枚銀貨を持っている時，コストを払うことで銀貨を増やせる
    for (int j = 0; j <= max_s; ++j) {
      int idx = calc_key(i, j);
      if (j != max_s) {
        auto [r_amount, r_cost] = rates[i];
        distances[idx].push_back({calc_key(i, j + r_amount), r_cost});
      }

      for (auto &c : costs[i]) {
        if (j >= c[1]) {
          distances[idx].push_back({calc_key(c[0], j - c[1]), c[2]});
          cnt++;
        }
      }
    }
  }

  Dijkstra d;
  vector<ll> dists = d.minDistance(distances, distances.size(), s);
  vector<ll> ans(n);
  for (int i = 1; i < n; ++i) {
    ans[i] = dists[calc_key(i, 0)];
    for (int j = 0; j <= max_s; ++j) {
      ans[i] = min(ans[i], dists[calc_key(i, j)]);
    }
  }

  for (int i = 1; i < ans.size(); ++i) {
    cout << ans[i] << '\n';
  }

  return 0;
}

Measured memory_bytes: 43508