akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int count = 0;
    for (int i = a; i <= b; i++) {
      if (c % i == 0) {
        count++;
      }
    }
    System.out.println(count);
  }
}


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

using namespace std;

int main()
{
    string s;
	
	cin >> s;
	
	if(s[s.size()-1] == 's') {
		s += "es";
	} else {
		s += "s";
	}
	
	cout << s << endl;
		
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n;
	string s;
	cin>>n>>s;
	vector<int> e(n), w(n);
	for(int i = 0; i < n; i++){
		e[i] = (s[i] == 'E');
		if(i)e[i] += e[i - 1];
	}
	for(int i = n - 1; i >= 0; i--){
		w[i] = (s[i] == 'W');
		if(i + 1 < n)w[i] += w[i + 1];
	}
	int ans = n;
	for(int i = 0; i < n; i++){
		int tmp = 0;
		if(i)tmp += e[i - 1];
		if(i + 1 < n)tmp += w[i + 1];
		ans = min(ans, n - 1 -tmp);
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 2964
package main

import (
	"fmt"
	"bufio"
	"os"
	"strings"
)

func main() {
	var w, t string


	fmt.Scan(&w)

	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		t += strings.ToLower(scanner.Text())+"\n"
	}

	c := 0
	for _, x := range(strings.Fields(t)) {
		if x == w {
			c++
		}
	}
	fmt.Println(c)
}



Measured memory_bytes: 1180
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main() {
	int a, b;
	scanf("%d%d", &a, &b);
	
	if (a < b) {
		printf("a < b\n");
	}
	else if (a > b) {
		printf("a > b\n");
	}
	else {
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

const int INF = 1000000000;
const double PI = 3.1415926535897932384626433832795;

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

using LL = long long int;
using LD = long double;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pll = pair<LL, LL>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<LL>;

//==============================================
int n, tt = 0;
vvi M;
vi D, F, searchStatus;

void antDfs(int u) {
	searchStatus[u] = 0;
	D[u] = ++tt;
	REP3(i, 1, n) {
		if (M[u][i] == 0) continue;

		if (searchStatus[i] == -1) {
			antDfs(i);
		}
	}
	F[u] = ++tt;
	searchStatus[u] = 1;
}

void print() {
	REP3(i, 1, n) {
		cout << i << " " << D[i] << " " << F[i] << "\n";
	}
}

void solve() {
	REP3(i, 1, n) searchStatus[i] = -1;

	REP3(i, 1, n) {
		if (searchStatus[i] == -1) {
			antDfs(i);
		}
	}

	print();
}

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

	cin >> n;
	
	M.resize(n + 1, vi(n + 1));
	D.resize(n + 1);
	F.resize(n + 1);
	searchStatus.resize(n + 1);

	int u, k, v;
	REP3(i, 1, n) {
		cin >> u >> k;
		REP3(j, 1, k) {
			cin >> v;
			M[u][v] = 1;
		}
	}

	solve();
	return 0;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int N;
vector<int> g[212345];

int color[212345];
int n;

// 彩色
bool binary_color(int u, int c) {
	color[u] = c;
	
	REP(i, g[u].size()) {
		int v = g[u][i];
		if (color[v] == 0 && !binary_color(v, -c)) return false;
		if (color[v] != 0 && color[u] == color[v]) return false;
	}
	return true;
}

bool solve(int v) {
	fill(color, color + n, 0);
	return binary_color(v, 1);
}

int ans[212345];

int main() {
	cin >> N;
	REP(i, N - 1) {
		int a, b;
		scanf("%d %d", &a, &b);
		--a; --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	assert(solve(0));
	
	int c1 = 1, c2 = 2, c3 = 3;
	
	int cc = 0;
	REP(i, N) if (color[i] == 1) ++cc;
	int ncc = N - cc;
	
	if (cc > ncc) {
		REP(i, N) color[i] = -color[i];
		swap(cc, ncc);
	}
	
	// color[i]=1 < color[i]=-1
	if (cc <= N / 3) {
		REP(i, N) if (color[i] == 1) {
			ans[i] = c3;
			c3 += 3;
		}
		REP(i, N) if (color[i] == -1) {
			if (c1 <= N) {
				ans[i] = c1;
				c1 += 3;
			}
			else if (c2 <= N) {
				ans[i] = c2;
				c2 += 3;
			}
			else {
				ans[i] = c3;
				c3 += 3;
			}
		}
	}
	else {
		REP(i, N) {
			if (color[i] == 1) {
				if (c1 <= N) {
					ans[i] = c1;
					c1 += 3;
				}
				else {
					ans[i] = c3;
					c3 += 3;
				}
			}
			else {
				if (c2 <= N) {
					ans[i] = c2;
					c2 += 3;
				}
				else {
					ans[i] = c3;
					c3 += 3;
				}
			}
		}
	}
	
	bool ng = false;
	REP(i, N) if (ans[i] > N) ng = true;
	if (ng) {
		assert(false);
		return 0;
	}
	
	REP(i, N) printf("%d%c", ans[i], i == N - 1 ? '\n' : ' ');
	
	return 0;
}


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

int main(){
  int n;
  long ret=0;
  cin >> n;
  vector<int>a(n);
  for(int i=0; i<n; i++)cin >> a[i];
  for(int i=1; i<n; i++){
    if(a[i-1]>a[i]){
      ret += a[i-1]-a[i];
      a[i]=a[i-1];
    }
  }
  cout << ret;
  return 0;
}

Measured memory_bytes: 3608
import * as fs from "fs"

function Main(input: string) {
  const [a, b, c] = input.split(" ").map(num => parseInt(num, 10)).sort((a, b) => a - b)

  if (a + b === c) {
    console.log("Yes")
  }
  else {
    console.log("No")
  }
}


fs.readFile('/dev/stdin', (err, data) => {
  if(err){
    Main(fs.readFileSync('./input.txt', 'utf8'))
    return null
  }
  Main(data.toString())
  return null
})

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

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

typedef long long ll;

const int MX=200005;
ll a[MX];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%lld",&a[i]);
    sort(a,a+n,greater<ll>());
    ll ans=a[0];
    int i=1,m=2;
    while(m<n){
        if(m+1==n){
            ans+=a[i];
            break;
        }
        ans+=a[i++]<<1;
        m+=2;
    }
    printf("%lld\n",ans);
    return 0;

}

Measured memory_bytes: 5388
def main():
    s = input()
    rem = [0] * 2019  # the count of the each remainder: 0 ~ 2018
    rem[0] = 1  # why? can't understand.

    temp = 0
    digit = 1
    for c in s[::-1]:
        # No time to pow.
        temp += int(c) * digit
        rem[temp % 2019] += 1
        digit = digit * 10 % 2019

    return sum(c * (c - 1) // 2 for c in rem)


if __name__ == '__main__':
    print(main())


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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

 
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
char A; cin >> A;
cout << (char)(A+1);
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, id;
	cin >> n;
	int a[n + 1] = {0};
	for (int i = 0; i < n - 1; i++) {
		cin >> id;
		a[id]++;
	}
	for (int i = 1; i <= n; i++)cout << a[i] << "\n";
	return 0;
}

Measured memory_bytes: 4288
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
#include <cstring>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define repll(i,n) for(long long int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
template <typename T_char>
char ToUpper (char cX) { return toupper(cX); }
//g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a){
    ll count = 0;
    for (ll i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }
    }
    return count;
}
//pow(x,n) == x^n
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a,   b) * b;}



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

ll a,b,ans;
cin >> a >> b;
ans = lcm(a,b);
cout << ans << endl;




//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
D = int(input())
C = list(map(int, input().split()))
s = list()
for i in range(D):
  s1 = list(map(int, input().split()))
  s.append(s1)
t = [0] * D

def point(t, C, s):
  done = [0] * 26
  ans = 0
  for d in range(1, D+1):
    td = t[d-1]
    done[td] = d
    ans += s[d-1][td]
    for i in range(26):
      ans -= C[i]*(d-done[i])
  return ans

ans = 0
bettert = 0
for i in range(26):
  t[0] = i
  #print(point(t, C, s))
  if(point(t, C, s) > ans):
    ans = point(t, C, s)
    bettert = i
    
print(bettert+1)
for i in range(D-1):
  print(1)

Measured memory_bytes: 68408
#include<stdio.h>
#define ll long long
int main(){
    ll n, i;
    scanf("%lld",&n);
    ll a[n];
    for(i = 0; i < n; i++)
        scanf("%lld",&a[i]);
    ll ans = 0, count = 1;
    for(i = 0; i < n; i++){
        if(a[i] != count)
            ans ++;
        else
            count ++;
    }
    if(count != 1)
        printf("%lld\n",ans);
    else 
        puts("-1");
    return 0;
}

Measured memory_bytes: 1664
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <iomanip>
#include <sstream>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 1LL << 60;
constexpr int inf = 1 << 30;

int main() {
    int N; cin >> N;
    int ans = inf;
    for (int i = 0; i <= N; ++i) {
        int six = i, nine = N - i;
        int an = 0;
        while (six > 0) {
            an += six % 6;
            six /= 6;
        }
        while (nine > 0) {
            an += nine % 9;
            nine /= 9;
        }
        ans = min(an, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/***
	chauhan176's code

	DO WHATEVER IT TAKES!!!
	Nothing happens , nothing happens and then everything happens.
	But the thing is nothing happens in air:)-
***/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define maxn 300005
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define stringio cin.ignore(256, '\n')  //to take string input after taking integer inputs
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

typedef pair<int,ll>pi;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = INT_MAX;
#define PI 3.14159265
int main()
{
    fastio;
    string s;
    cin>>s;

    int n = s.size()+1;
    vector<long long> a(n);
	for (int i = 0; i < n - 1; i++)
		if (s[i] == '<') a[i + 1] = max(a[i + 1], a[i] + 1);
	for (int i = n - 2; i >= 0; i--)
		if (s[i] == '>') a[i] = max(a[i], a[i + 1] + 1);
	cout << accumulate(a.begin(), a.end(), 0LL) << endl;
    return 0;
}
/*
<>>><<><<<<<>>><
*/


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

int main()
{
    int n;
    cin >> n;
    vector<int> dp(3);
    vector<int> tmp(3);
    for(int i=0; i<n; i++){
        int a,b,c;
        cin >> a >> b >> c;
        tmp[0] = max(dp[1], dp[2]) + a;
        tmp[1] = max(dp[2], dp[0]) + b;
        tmp[2] = max(dp[0], dp[1]) + c;
        dp = tmp;        
    }
    
    cout << *max_element(dp.begin(), dp.end()) << endl;
    return 0;
}


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

def next_a(x):
    return pow(x, 2, M)

history = []
visited = set()

x = X
for _ in range(N):
    if x in visited:
        break
    visited.add(x)
    history.append(x)
    x = next_a(x)

if len(history) == N:
    # ループする前に終わる場合
    print(sum(history))
else:
    loop_start = history.index(x)
    loop_size = len(history) - loop_start
    loop_sum = sum(history[loop_start:])
    if ((N - len(history)) % loop_size) == 0:
        # ループぴったり
        print(sum(history) + loop_sum * ((N - len(history)) // loop_size))
    else:
        # ループが中途半端
        hasu = sum(history[loop_start:loop_start+((N - len(history)) % loop_size)])
        print(sum(history) + loop_sum * ((N - len(history)) // loop_size) + hasu)


Measured memory_bytes: 77372
N = int(input())
uneven = [9, 0, 900, 0, 90000]
digits = len(str(N))

if digits == 1:
    print(N)
elif (digits % 2) == 0:
    print(sum(uneven[0:digits]))
else:
    print(N - 10**(digits-1) + 1 + sum(uneven[0:digits-1]))


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef std::pair<int, int> int_pair;
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }


int main() {
	int zero = 0, ichi = 0;
	string s;
	cin >> s;

	rep(i, s.length()) {
		if (s[i] == '0') {
			zero++;
		}
		else {
			ichi++;
		}
	}

	cout << min(zero, ichi) * 2 << endl;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cctype>
#define qmin(x,y) (x=min(x,y))
#define qmax(x,y) (x=max(x,y))
using namespace std;

inline char gc() {
//	static char buf[100000],*p1,*p2;
//	return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
	return getchar();
}

template<class T>
int read(T &ans) {
	ans=0;char ch=gc();T f=1;
	while(!isdigit(ch)) {
		if(ch==EOF) return -1;
		if(ch=='-') f=-1;
		ch=gc();
	}
	while(isdigit(ch))
		ans=ans*10+ch-'0',ch=gc();
	ans*=f;return 1;
}

template<class T1,class T2>
int read(T1 &a,T2 &b) {
	return read(a)!=EOF&&read(b)!=EOF?2:EOF;
}

template<class T1,class T2,class T3>
int read(T1 &a,T2 &b,T3 &c) {
	return read(a,b)!=EOF&&read(c)!=EOF?3:EOF;
}

typedef long long ll;
const int Maxn=110000;
const int inf=0x3f3f3f3f;

int to[Maxn],nxt[Maxn],first[Maxn],tot=1,d[Maxn],n,m,u,v,f[Maxn];
queue<int> q;

inline void add(int u,int v) {
	to[tot]=v;
	nxt[tot]=first[u];
	first[u]=tot++;
}

signed main() {
//	freopen("test.in","r",stdin);
	read(n,m);
	for(int i=1;i<=m;i++) {
		read(u,v);
		add(u,v);
		d[v]++;
	}
	for(int i=1;i<=n;i++) if(d[i]==0) q.push(i);
	while(!q.empty()) {
		int now=q.front();q.pop();
		for(int i=first[now];i;i=nxt[i]) {
			qmax(f[to[i]],f[now]+1);
			d[to[i]]--;
			if(d[to[i]]==0)
				q.push(to[i]);
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++) qmax(ans,f[i]);
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
int main(){
  int b,r,g,c,s,t;
  while(cin>>b>>r>>g>>c>>s>>t,t){
    int a=100,d;
    t-=s+b*5+r*3;
    a+=(b+r)*15+c*2+(b*5+r*3)*13+g*7;
    cout<<a-t*3<<endl;
  }
}

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

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

  char s[n];
  scanf("%s", s);

  if(n % 2 == 1) {
    printf("No");
  }

  else {
    int len = strlen(s);
    int flag = 0;
    for(int i = 0; i < len / 2; i++) {
      if(s[i] != s[i + len / 2]) {
        flag = 1;
        break;
      }
    }

    if(!flag) printf ("Yes");
    else printf("No");
  }

  return 0;
}


Measured memory_bytes: 1700
using System;

public class Input
{
    public char[] sc;

    public long idx = 0;
    public char name = 'A';

    public Input()
    {
        //string[] input = null;

        // 文字列を数値の配列として読込
        sc = Console.ReadLine().ToCharArray();
    }
}

public class Program
{
    public static void Main(string[] args)
    {
        string output = Proc();

        // 出力
        Console.WriteLine(output);
    }

    static string Proc()
    {
        Input[] inputArray = new Input[3];
        string output = string.Empty;

        for (long i = 0; i < inputArray.Length; i++)
        {
            inputArray[i] = new Input();
            inputArray[i].name = (char)(inputArray[i].name + i);
        }

        long playerIdx = 0;
        while (true)
        {
            Input input = inputArray[playerIdx];

            if (input.idx >= input.sc.Length)
            {
                output = input.name.ToString();
                break;
            }

            playerIdx = input.sc[input.idx] - 'a';
            input.idx++;
        }

        return output;
    }
}



Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n);i++)

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 ctoi(char c){
    if(c >= '0' && c <= '9'){
        return c - '0';
    }
    return 0;
}
ll factorial(ll n){
    if(n == 1){
        return 1;
    }
    ll ans = factorial(n - 1);
    return 1;
}
ll gcd (ll a, ll b){
    if(b == 0)
        return 0;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b){
    return (a / gcd(a, b)) * b;
}

bool is_prime(ll n){
    for (ll i = 2; i * i <= n; i++){
        if(n%i == 0)
            return false;
    }
    return n != 1;
}
ll mod_pow(ll x, ll n, ll mod){
    if(n == 0)
        return 1;
    ll res = mod_pow(x * x % mod, n / 2, mod);
    if(n & 1)
        res = res * x % mod;
    return res;
}

int main(){
    ll n, k;
    cin >> n >> k;
    ll r, s, p;
    cin >> r >> s >> p;
    string str;
    cin >> str;
    ll res = 0;
    rep(i, n){
        bool flag = 1;
        if(i>= k){
            if(str.at(i) == str.at(i-k)){
                str.at(i) = '0';
                flag = 0;
                continue;
            }
        }
        if(flag){
            if(str.at(i) == 'r')res += p;
            if(str.at(i) == 's')res += r;
            if(str.at(i) == 'p')res += s;

        }
    }
    cout << res << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<sstream>
#include<algorithm>

struct WordRanking
{
	WordRanking(){}

	WordRanking(std::string word, int count):m_word(word),m_count(count)
	{
	}

	std::string m_word;

	int m_count;
};

int MaxNum(std::vector<WordRanking> rank)
{
	if(rank.empty())
	{
		return 0;
	}

	int max = rank[0].m_count;

	int maxNum=0;

	for(size_t i=1; i<rank.size(); ++i)
	{
		if(rank[i].m_count>max)
		{
			max = rank[i].m_count;

			maxNum = i;
		}
	}

	return maxNum;
}


int main()
{
	std::string str;

	//while(1){
		getline(std::cin,str);

		if(std::cin.eof())
		{
			exit(1);
		}

		std::stringstream ss;

		std::vector<std::string> word;

		ss << str;

		std::string hoge;

		for(; !(ss.eof());)
		{
			ss >> hoge;

			word.push_back(hoge);
		}

		std::sort(word.begin(),word.end());

		std::string temp = "";

		std::vector<WordRanking> rankFriq;

		for(size_t i=0; i<word.size(); ++i)
		{
			if(temp != word[i])
			{
				rankFriq.push_back(WordRanking(word[i],1));
			}
			else
			{
				++rankFriq[rankFriq.size()-1].m_count;
			}

			temp = word[i]; 
		}

		std::vector<WordRanking> rankLength;

		for(size_t i=0; i<word.size(); ++i)
		{
			rankLength.push_back(WordRanking(word[i],word[i].length()));
		}

		std::cout << rankFriq[MaxNum(rankFriq)].m_word << ' ' << rankLength[MaxNum(rankLength)].m_word << '\n';
		
	//}
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,W;cin>>n>>W;
	vector<int> w(n),v(n);
	vector<vector<long long int>> dp(n+1,vector<long long int>(W+1));
	for(int i=0;i<n;i++) cin>>w[i]>>v[i];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=W;j++){
			dp[i][j] = max(dp[i-1][j],((j-w[i-1]>=0)?(dp[i-1][j-w[i-1]]+v[i-1]):0));
			dp[i][j] = max(dp[i][j],dp[i][j-1]);
		}
	}
	cout<<*(max_element(dp[n].begin(),dp[n].end()));
}


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

using namespace std;
typedef long long ll;

int main() {
    ll L, R;
    cin >> L >> R;

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

    ll ans = 2019;
    for (ll i = L; i < R; ++i) {
        for (ll j = L + 1; j <= R; ++j) {
            ans = min(i * j % 2019, ans);
        }
    }
    cout << ans << endl;
    return 0;
}

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

const int MOD = 1e9 + 7;

signed main() {
  string L;
  cin >> L;

  static int dp1[101010] = {0}, dp2[101010] = {0};
  dp1[0] = 1;

  for (int i = 0; i < L.size(); i++) {
    if (L[i] == '0') {
      (dp1[i + 1] += dp1[i]) %= MOD;
      (dp2[i + 1] += 3 * dp2[i]) %= MOD;
    } else {
      (dp1[i + 1] += 2 * dp1[i]) %= MOD;
      (dp2[i + 1] += dp1[i] + 3 * dp2[i]) %= MOD;
    }
  }

  cout << (dp1[L.size()] + dp2[L.size()]) % MOD << endl;
  return 0;
}


Measured memory_bytes: 2048
#include<stdio.h>
int MAX=100;
int INFTY=(1<<21);
int W=0,G=1,B=2;

main(){
  int n,i,j,e,sum,u,v,minv,M[MAX][MAX];
  int d[MAX],p[MAX],color[MAX];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      M[i][j] = (e==-1)?INFTY:e;
    }
  }
  for(i=0;i<n;i++){
    d[i] = INFTY;
    p[i] = -1;
    color[i] = W;
  }
  d[0] = 0;
  while(1){
    minv = INFTY;
    u = -1;
    for(i=0;i<n;i++){
      if(minv > d[i] && color[i] != B/*!vis[i]*/){
        u = i;
        minv = d[i];
      }
    }
    if(u == -1)break;
    color[u] = B;
    for(v=0;v<n;v++){
      if(color[v] != B/*!vis[v]*/ && M[u][v] != INFTY){
        if(d[v] > M[u][v]){
          d[v] = M[u][v];
          p[v] = u;
          color[v] = G;
        }
      }
    }
  }
  sum = 0;
  for(i=0;i<n;i++){
    if(p[i] != -1)sum += M[i][p[i]];
  }
  printf("%d\n",sum);

  return 0;
}



Measured memory_bytes: 2052
#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 105;

int n, m;

int seen[N][N], dist[N][N][2];
int g[N][N];

queue< tuple< int, int, int>> q;

void go(int x1, int y1, int c, int x2, int y2) {
	if (x2 >= n || y2 >= m) return;

	int nxt = g[x2][y2];

	if (nxt) {
		if (c == 0) {
			if (dist[x2][y2][c ^ 1] > dist[x1][y1][c] + 1) {
				dist[x2][y2][c ^ 1] = min(dist[x2][y2][c ^ 1], dist[x1][y1][c] + 1);
				q.push(make_tuple(x2, y2, c ^ 1));
			}
		}
		else if (dist[x2][y2][c] > dist[x1][y1][c]) {
			dist[x2][y2][c] = min(dist[x2][y2][c], dist[x1][y1][c]);
			q.push(make_tuple(x2, y2, c));
		}
	}

	else {
		if (c == 0) {
			if (dist[x2][y2][c] > dist[x1][y1][c]) {
				dist[x2][y2][c] = min(dist[x2][y2][c], dist[x1][y1][c]);
				q.push(make_tuple(x2, y2, c));
			}
		}
		else if (dist[x2][y2][c ^ 1] > dist[x1][y1][c]) {
			dist[x2][y2][c ^ 1] = min(dist[x2][y2][c ^ 1], dist[x1][y1][c]);
			q.push(make_tuple(x2, y2, c ^ 1));
		}
	}
}

void bfs() {
	memset(dist, 0x3f3f3f3f, sizeof dist);
	dist[0][0][g[0][0]] = g[0][0];
	q.push(make_tuple(0, 0, g[0][0]));


	while (!q.empty()) {
		int x, y, c;
		tie(x, y, c) = q.front();
		q.pop();

		go(x, y, c, x + 1, y);
		go(x, y, c, x, y + 1);
	}
}

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

	cin >> n >> m;

	for (int i = 0; i < n; i++) {
		string x;
		cin >> x;
		for (int j = 0; j < m; j++) {
			g[i][j] = (x[j] == '#');
		}
	}

	bfs();

	cout << min(dist[n - 1][m - 1][0], dist[n - 1][m - 1][1]) << "\n";
}

Measured memory_bytes: 384
use proconio::input;
use proconio::fastout;

#[fastout]
fn main() {
    input! {
        l: usize,
        r: usize,
        d: usize,
    }

    let mut ans = 0;
    for i in l .. r + 1 {
        if i % d == 0 { ans += 1; }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2168
#include <stdio.h>
#include <utility>
#include <vector>
using namespace std;
const int INF=(1<<29);
int min(int a,int b){
    if(a>b)return b;
    return a;
}
int main(){
    int n,m,l,r,dis[110][110],cost[110][110],c,t;
    while(1){
    scanf("%d%d",&m,&n);
        if(n==0&&m==0)return 0;
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)dis[i][j]=cost[i][j]=INF;
    for(int i=0;i<m;i++){
        scanf("%d%d%d%d",&l,&r,&c,&t);
        dis[l][r]=dis[r][l]=t;
        cost[l][r]=cost[r][l]=c;
    }
    for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){
        dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
        cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
    }
    scanf("%d",&n);
    while(n--){
        scanf("%d%d%d",&l,&r,&m);
        if(m==0)printf("%d\n",cost[l][r]);
        else printf("%d\n",dis[l][r]);
    }
    }
}

Measured memory_bytes: 2704
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
using namespace std;

int n,ans;
int cnt[21][21],flag[21][21];
signed main(){
    cin>>n;
    rep(i,n){
    	string s=to_string(i+1);
    	cnt[s[0]-'0'][s[s.size()-1]-'0']++;
    }
    rep(i,9)rep(j,9){
    	if(!flag[i][j]){
    		int num=cnt[i+1][j+1]*cnt[j+1][i+1];
    		if(i!=j)num*=2;
    		ans+=num;
    	}
    	flag[i][j]=1;
    	flag[j][i]=1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;

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

signed main()
{
	int N, P;
	int A[50];

	int gu = 0;
	int ki = 0;

	cin >> N >> P;
	REP(i, N)
	{
		cin >> A[i];
		if (A[i] % 2 == 0)
		{
			gu++;
		}
		else
		{
			ki++;
		}
	}

	if (P == 0)
	{
		int cnt = 1;
		for (int i = 2; i <= ki; i += 2)
		{
			cnt += C(ki, i);
		}
		int ans = pow(2, gu) * cnt;
		cout << ans << endl;
	}
	else
	{
		int cnt = 0;
		for (int i = 1; i <= ki; i += 2)
		{
			cnt += C(ki, i);
		}
		int ans = pow(2, gu) * cnt;
		cout << ans << endl;
	}
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3
#define MAX_V 303

struct edge{ int to, cap, rev, idx; };

vector<edge> G[MAX_V];
bool used[MAX_V];
int n,m;

void add_edge(int from, int to, int cap,int idx){
  G[from].push_back((edge){to,cap,(int)G[to].size(),idx});
  G[to].push_back((edge){from,0,(int)G[from].size()-1,-1});
}

int dfs(int v,int t,int f){
  if(v==t)return f;
  used[v]=true;
  for(int i=0; i < G[v].size(); i++){
    edge &e=G[v][i];
    if(!used[e.to]&&e.cap>0){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
        e.cap-=d;
        G[e.to][e.rev].cap+=d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow=0;
  while(1){
    memset(used,0,sizeof(used));
    int f=dfs(s,t,INF);
    if(f==0)return flow;
    flow+=f;
  }
}

int main(){
	cin.sync_with_stdio(false);
  int s,t;
  cin>>n>>m;
  rep(i,m){
    int x,y;
    cin>>x>>y;
    x--; y--;
    add_edge(x,y,1,i);
    add_edge(y,x,1,i+m);
  }
  cin>>s>>t;
  s--; t--;
  cout<<max_flow(s,t)<<endl;
  vector<int> res;
  rep(i,n){
    for(edge e : G[i]){
      if(e.cap==0&&e.idx>=m){
        res.push_back(e.idx-m+1);
      }
    }
  }
  sort(all(res));
  uni(res);
  cout<<res.size()<<endl;
  rep(i,res.size())cout<<res[i]<<endl;
	return 0;
}

Measured memory_bytes: 3300
n,k = map(int,input().split())
s = input()
ans = 0
for i in range(n):
  if i != 0 and s[i-1] == "L" and s[i] == "L":
    ans += 1
  if i != n-1 and s[i] == "R" and s[i+1] == "R":
    ans += 1
print(min(ans+2*k,n-1))

Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

// 素集合データ構造
struct UnionFind
{
	// par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
	vector<int> par;
	// sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
	vector<int> sizes;

	UnionFind(int n) : par(n), sizes(n, 1) {
		// 最初は全てのデータiがグループiに存在するものとして初期化
		for (int i = 0; i < n; i++) par[i] = i;
	}

	// データxが属する木の根を得る
	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
	}

	// 2つのデータx, yが属する木をマージする
	void unite(int x, int y) {
		// データの根ノードを得る
		x = find(x);
		y = find(y);

		// 既に同じ木に属しているならマージしない
		if (x == y) return;

		// xの木がyの木より大きくなるようにする
		if (sizes[x] < sizes[y]) swap(x, y);

		// xがyの親になるように連結する
		par[y] = x;
		sizes[x] += sizes[y];
		// sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
	}

	// 2つのデータx, yが属する木が同じならtrueを返す
	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// データxが含まれる木の大きさを返す
	int size(int x) {
		return sizes[find(x)];
	}
};

int main() {
	int n, m;
	cin >> n >> m;
	vi p(n);
	rep(i, 0, n) {
		cin >> p[i];
	}
	UnionFind uf{
		UnionFind(n + 1)
	};
	rep(i, 0, m) {
		int x, y;
		cin >> x >> y;
		uf.unite(x, y);
	}
	int ans = 0;
	rep(i, 0, n) {
		if (uf.same(i + 1, p[i])) {
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1408
N = int(input())
dp = [[0] * 3 for _ in range(N+1)]

for i in range(N):
    A = list(map(int, input().split()))
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i+1][j] = max(dp[i+1][j], dp[i][k] + A[k])

print(max(dp[N]))

Measured memory_bytes: 22820
from itertools import accumulate
from bisect import bisect_right

class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.n:
            self.data[i] += x
            i += i & -i
            
N, K = map(int, input().split())
a = [int(input()) - K for _ in range(N)]
b = [0]+list(accumulate(a))
b_sorted = sorted(b)
b = [bisect_right(b_sorted, bi) for bi in b]
bit = BIT(N+1)
ans = 0
for i in range(N+1):
    ans += bit.sum(b[i])
    bit.add(b[i], 1)
print(ans)

Measured memory_bytes: 79140
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
 ll a,b,c;sc(a);
  
 pr(a+a*a+a*a*a);
return 0;}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,ll>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int N,K;
    cin>>N>>K;
    vector<ll> A(N),P(0),M(0);
    rep(i,N)cin>>A.at(i);
    int plus=0,minus=0,zero=0;
    rep(i,N){
        if(A.at(i)>0){plus++;P.pb(A.at(i));}
        if(A.at(i)==0)zero++;
        if(A.at(i)<0){minus++;M.pb(A.at(i));}
    }
    if(N==K){
        ll ans=1;
        rep(i,N){
            ans*=A.at(i);
            ans%=MOD;
        }
        if(ans<0)ans+=MOD;
        cout<<ans<<endl;
        return 0;
    }
    if(plus+minus<K){cout<<0<<endl;return 0;}
    if(plus+minus==K){
        if(minus%2==0){//答えは+
            ll ans=1;
            rep(i,N){
                if(A.at(i)!=0){
                    ans*=A.at(i);
                    ans%=MOD;
                }
            }
            if(ans<0)ans+=MOD;
            cout<<ans<<endl;
            return 0;
        }
        else{
            cout<<0<<endl;
            return 0;
        }
    }
    //plus+minus>Kの時
    if(plus==0){
        if(K%2==0){
            sort(M.begin(),M.end());
            ll ans=1;
            rep(i,K){
                ans*=M.at(i);
                ans%=MOD;
            }
            cout<<ans<<endl;
            return 0;
        }
        else{
            if(zero>0){
                cout<<0<<endl;
                return 0;
            }
            else{
                sort(M.rbegin(),M.rend());
                ll ans=1;
                rep(i,K){
                    ans*=M.at(i);
                    ans%=MOD;
                }
                if(ans<0)ans+=MOD;
                cout<<ans<<endl;
                return 0;
            }
        }
    }
    //答えは+
    sort(P.rbegin(),P.rend());
    sort(M.begin(),M.end());//絶対値大きい順
    vector<LP> mix(0);
    rep(i,plus){
        mix.pb({P.at(i),P.at(i)});
    }
    rep(i,minus){
        mix.pb({-M.at(i),M.at(i)});
    }
    sort(mix.rbegin(),mix.rend());
    int pp=0,pm=0;
    ll ans=1;
    if(K%2==1){
        ans*=P.at(0);
        pp++;
        K--;
    }
    ll np=1,nm=1;
    while(K>0){
        if(pp+1>=P.size())np=0;
        else{np=P.at(pp)*P.at(pp+1);}
        if(pm+1>=M.size())nm=0;
        else{nm=M.at(pm)*M.at(pm+1);}
        if(np>nm){
            np%=MOD;
            ans*=np;
            ans%=MOD;
            K-=2;
            pp+=2;
        }
        else{
            nm%=MOD;
            ans*=nm;
            ans%=MOD;
            K-=2;
            pm+=2;
        }
    }
    cout<<ans<<endl;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

struct BIT2d{
	int ymx, xmx;
	vector<vector<int>> dt;
	BIT2d(int my, int mx): ymx(my), xmx(mx), dt(my+5,(vector<int>(mx+5))){};
	void add(int y, int x, int v){
		for(int i = y+1; i <= ymx+1; i += i & -i)
			for(int j = x+1; j <= xmx+1; j += j & -j) dt[i][j] += v;
	}
	int qsum(int y, int x){
		int res = 0;
		for(int i = y+1; i > 0; i -= i & -i)
			for(int j = x+1; j > 0; j -= j & -j) res += dt[i][j];
		return res;
	}
	int qsum(int y0, int x0, int y1, int x1){
		return qsum(y1, x1) - qsum(y0-1, x1) - qsum(y1, x0-1) + qsum(y0-1, x0-1);
	}
};
int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VL a(n);
	const ll KS = 1e9;
	rep(i, n){
		string s;
		cin >>s;
		int ps = s.find(".");
		if(ps==-1){
			a[i]= stoll(s) * KS;
		}else{
			a[i] = stoll(s.substr(0, ps))*KS;
			string zs = s.substr(ps+1);
			while(sz(zs)<9) zs+="0";
			a[i] += stoll(zs);
		}	
	}
	//for(auto x :a) cerr<<x<<" "; dbg();
	
	vector<pii> ys(n);
	rep(i, n){
		for(ll w = a[i]; w%2==0 && w>0 ; w/=2) ys[i].second++;
		for(ll w = a[i]; w%5==0 && w>0 ; w/=5) ys[i].first++;
	}
	
	//for(auto x :ys) cerr<<x.first<<":"<<x.second<<" "; dbg();
	for(auto &x :ys){
		x.first = min(18, x.first);
		x.second = min(18, x.second);
	}
	ll ans =0;
	BIT2d bt(21,21);
	
	for(auto x :ys){
		
		ans += bt.qsum(18-x.first, 18-x.second, 20, 20);
		bt.add(x.first, x.second, 1);
	}
	
	cout << ans<<"\n";
	return 0;
}



Measured memory_bytes: 6256
#include <iostream>
using namespace std;
int main() {
  int X; cin>>X;
  if (X==0) {
    cout << 0 << endl;
  } else {
    int ans1 = X / 500;
    int per = X % 500;
    int ans2 = per / 5;
    cout << (ans1*1000+ans2*5) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
/*Coded by::
    **Avinash Tiwary**
    **BE/10298/2015**
    **Production Engineer**
    **Producing <code>**
*/
#include<bits/stdc++.h>
#define buf ios_base::sync_with_stdio (0), cin.tie (0)
typedef long long ll;
typedef double dob;
#define MAX 50010
#define M5 200009
#define M6 2000009
#define M 1000000007
#define INF 5e17
using namespace std;
typedef vector<ll> V;
typedef queue<ll > Q;
typedef stack<ll> S;
typedef pair<ll,ll> P;
#define mp make_pair
#define mt make_tuple
#define pb push_back
ll fac[M6],not_prime[M6],ar[M5];
ll power(ll x,ll n)
{   if(n==0||x==0) return 1;
    else if(n%2 == 0) return power((x*x)%M,n/2);
    else return (x*power((x*x)%M,(n-1)/2))%M;
}
string s[MAX];
void fact(){
    fac[0]=1;
    for(ll i=1;i<M6;i++) fac[i]=(i*fac[i-1])%M;
}
void sieve(){
    not_prime[1]=1; not_prime[0]=1;
    for(ll p=2;p*p<M6;p++){
        if(!not_prime[p]){
            for(ll i=p*2;i<=MAX;i+=p) not_prime[i]=1;
        }
    }
}
ll con[26];
int main(){
    buf; 
    //sieve(); 
    //fact();
    ll l,r,i,j,p,test,n,ans; string s; 
    cin>>s;
    n=s.size();
    ans=0;
    for(i=0;i<s.size();i++) con[s[i]-'a']++;
    for(i=0;i<26;i++){
        //cout<<con[i]<<" ";
        if(con[i]>1) ans+=(con[i]*(con[i]-1))/2;
        //cout<<ans<<" ";
    }
    //cout<<endl;
    //cout<<n<<" "<<ans<<endl;
    cout<<n*(n-1)/2-ans+1;
    return 0;
} 

Measured memory_bytes: 1104
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n, w_mx;
    cin >> n >> w_mx;
    vint w(n), v(n);
    rep(i, n) cin >> w[i] >> v[i];

    vvll dp(n+1, vll(1e5+1, LINF));
    dp[0][0] = 0;

    rep(i, n) {
        dp[i+1] = dp[i];
        rep(j, 1e5-v[i]+1) {
            dp[i+1][j+v[i]] = min(dp[i][j+v[i]], dp[i][j]+w[i]);
        }
    }

    ll ans = 0;
    rep(i, 1e5+1) {
        if (dp[n][i] <= w_mx) ans = i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define ld long double
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define getchar gc
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=100005;
int tong[N<<1],a[N],n,k;
ll check(int x){
	memset(tong,0,sizeof(tong));
	int dq=n,dd=1; ll ans=0;
	tong[n]=1; 
	for(register int i=1;i<=n;i++){
		a[i]>=x?dd+=tong[++dq]:dd-=tong[dq--]; 
		ans+=dd++; tong[dq]++; 
	}
	return ans;
}
signed main(){
	n=read(); ll k=((ll)n*(n+1)/2+1)/2;
	for(int i=1;i<=n;i++)a[i]=read(); 
	int l=1,r=1e9;
	while(l<r){
		int mid=(l+r)>>1; mid++;
		if(check(mid)>=k)l=mid; else r=mid-1;
	}
	cout<<l<<endl;
}

Measured memory_bytes: 1536
n = int(input())
s = input()
listed_s = list(s)
if n % 2 == 0:
    if "".join(listed_s[0: (n // 2)]) == "".join(listed_s[(n // 2): n]):
        print('Yes')
    else:
        print('No')
else:
    print('No')


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<numeric>

typedef long long LL;

using namespace std;

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

int main(void) {
	int n;
	cin >> n;
	vector<string>s(n);
	for (int i = 0; i < n; i++)cin >> s[i];
	int m;
	cin >> m;
	vector<string>t(m);
	for (int i = 0; i < m; i++)cin >> t[i];
	int ans = 0;
	int p = 0;
	int i = 0;
	while (i < n) {
		p = 0;
		for (int j = 0; j < n; j++) {
			if (s[i] == s[j]) {
				p++;
			}
		}
		for (int j = 0; j < m; j++) {
			if (s[i] == t[j]) {
				p--;
			}
		}
		ans = max(ans, p);
		i++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {

  int c[3][3];
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> c[i][j];
    }
  }
  int line1 = c[0][0] + c[1][1] + c[2][2];
  int line2 = c[0][1] + c[1][2] + c[2][0];
  int line3 = c[0][2] + c[1][0] + c[2][1];
  if(line1 == line2 && line2 == line3) cout << "Yes" << endl;
  else cout << "No" << endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = a; i < (b); ++i)
#define ALL(c) (c).begin(), (c).end()

int S[110];

int main()
{
  int N, K;
  while (cin >> N >> K, N | K) {
    REP(i, K) {
      cin >> S[i];
    }
    REP(i, N) {
      REP(j, K) {
        int b; cin >> b;
        S[j] -= b;
      }
    }
    REP(i, K) {
      if (S[i] < 0) {
        cout << "No" << endl;
        goto next;
      }
    }
    cout << "Yes" << endl;
next:;
  }
}

Measured memory_bytes: 852