akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

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

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int d[100][100];
vector<edge> G[100];
ll _d[100];

void dijkstra(int n, vector<edge> G[], int s, ll d[]) {
	fill(d, d + n, LLONG_MAX); d[s] = 0;
	priority_queue<ll_i, vector<ll_i>, greater<ll_i> > q;
	q.push(ll_i(0, s));
	while (!q.empty()) {
		ll_i p = q.top(); q.pop();
		int u = p.second;
		if (p.first > d[u]) continue;
		for (int i = 0; i < G[u].size(); i++) {
			edge e = G[u][i];
			if (d[e.v] > d[u] + e.w) {
				d[e.v] = d[u] + e.w;
				q.push(ll_i(d[e.v], e.v));
			}
		}
	}
}

int main() {
	for (;;) {
		int N, M, L, K, A, H;
		cin >> N >> M >> L >> K >> A >> H;
		if (N == 0) break;
		vector<bool> l(N);
		l[A] = l[H] = true;
		while (L--) {
			int i; cin >> i;
			l[i] = true;
		}
		fill(d[0], d[0] + 100 * 100, INT_MAX / 2);
		for (int i = 0; i < N; i++) d[i][i] = 0;
		while (K--) {
			int X, Y, T; cin >> X >> Y >> T;
			d[X][Y] = d[Y][X] = T;
		}
		for (int k = 0; k < N; k++)
			for (int i = 0; i < N; i++)
				for (int j = 0; j < N; j++)
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
		fill(G, G + N, vector<edge>());
		for (int i = 0; i < N; i++)
			for (int j = 0; j < N; j++)
				if (l[i] && l[j] && d[i][j] <= M) {
					edge e = {i, j, d[i][j]};
					G[i].push_back(e);
				}
		dijkstra(N, G, A, _d);
		if (_d[H] == LLONG_MAX)
			cout << "Help!" << endl;
		else if (_d[H] <= M)
			cout << _d[H] << endl;
		else
			cout << _d[H] * 2 - M << endl;
	}
}

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

int main(){
    int A,B;
    cin >> A >> B;
    int Ar[3] = {A+B,A-B,A*B};
    for(int j=0;j<3;j++){
        for(int i=0;i<2;i++){
            if(Ar[i+1]>Ar[i]) swap(Ar[i+1],Ar[i]);
        }
    }
    cout << Ar[0];
    return 0;
}

Measured memory_bytes: 256
// A Hello World! program in C#.
using System;
namespace HelloWorld
{
    class Hello 
    {
        static void Main() 
        {
            string str = Console.ReadLine();
            if(str[0] == str[1] || str[1] == str[2] || str[2] == str[3])
            {
              Console.WriteLine("Bad");
            }
            else
            {
              Console.WriteLine("Good");
            }
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std;
 
int main() {
    string s;

    cin >> s;

    string s1 = s.substr(0,2);
    string s2 = s.substr(2,2);

    int a = 0;
    int b = 0;

    a += (s1[0] - '0') * 10;
    a += s1[1] - '0';

    b += (s2[0] - '0') * 10;
    b += s2[1] - '0';

    if((1 <= a && a <= 12) && (1 <= b && b <= 12)){
        cout << "AMBIGUOUS" << endl;
    }else if(!(1 <= a && a <= 12) && (1 <= b && b <= 12)){
        cout << "YYMM" << endl;
    }else if((1 <= a && a <= 12) && !(1 <= b && b <= 12)){
        cout << "MMYY" << endl;
    }else{
        cout << "NA" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

// for i in f..<t {... : as Swift
#define forin(i, f, t) for(auto i = f; i < t; i++)

using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    auto maxC = 0;
    forin(i, 1, n) {
        auto count = 0;
        vector<bool> chars(0xff, false);
        forin(j, 0, i) {
            auto c = s[j];
            if (chars[c])
                continue;
            chars[c] = true;
            forin(k, i, n) {
                if (s[k] == c) {
                    count++;
                    break;
                }
            }
        }
        maxC = max(maxC, count);
    }
    cout << maxC << endl;
}



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

typedef long long ll;

int main(void){
  ll M;
  int rated, rater;
  ll cd, cr;

  cin >> M >> rated >> rater >> cd >> cr;
  ll r_xyen  = ceil(100.0*(double)cr/(double)rater);
  ll d_xyen  = ceil(100.0*(double)cd/(double)rated);
  ll r_changed = floor(rater*(double)r_xyen/100.0);
  ll d_changed = floor(rated*(double)d_xyen/100.0);

  M = M - r_xyen - d_xyen;

  if(M < 0){
    cout << -1 << endl;
    return 0;
  }

  r_changed -= cr;
  d_changed -= cd;

  ll yen_ret_r = floor(100.0*(double)r_changed/(double)rater);
  ll yen_ret_d = floor(100.0*(double)d_changed/(double)rated);

  M += yen_ret_r + yen_ret_d;
  cout << M << endl;
}



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

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n), f(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> f[i];
    }
    sort(a.begin(), a.end());
    sort(f.begin(), f.end());
    reverse(f.begin(), f.end());
    ll l = -1, r = 1e+12;
    while(l + 1 < r){
        ll m = (l + r) / 2;
        ll cnt = 0;
        for(int i = 0; i < n; i++){
            cnt += max(0LL, a[i] - m / f[i]);
        }
        if(cnt <= k){
            r = m;
        } else {
            l = m;
        }
    }
    cout << r << endl;
    return 0;
}

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

typedef long long LL;

#define dbg(x) cerr << #x"=" << x << endl;
int h,w;
const int MAX_H = 1e3+100;
char a[MAX_H][MAX_H];
typedef pair<int, int> P;
#define x first
#define y second
int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

int main(){
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> h >> w;
    queue<P> que;
    int now = 0;
    for(int i = 1; i <= h; ++i){
        cin >> (a[i]+1);
        for(int j = 1; j <= w; ++j){
            if(a[i][j] == '#') {
                que.push({i, j});
                ++now;
            }
        }
    }
    int nxt = 0;
    int ans = 0;
    while(!que.empty()){
        P p = que.front(); que.pop();
        --now;
        for(int i = 0; i < 4; ++i){
            int x = p.x + dir[i][0];
            int y = p.y + dir[i][1];
            if(x < 1 || x > h || y < 1 || y > w || a[x][y] == '#') continue;
            a[x][y] = '#';
            ++nxt;
            que.push({x, y});
        }
        if(now == 0) {
            ++ans;
            now = nxt;
            nxt = 0;
        }
    }
    cout << ans-1 << endl;
    return 0;
}


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

#define alfc 32
#define rep(i,a,b) for(int (i) = (a) ; (i) < (b) ; (i) ++)
#define scin(a) scanf("%d",&a);
#define scdo(a) scanf("%lf",&a);
#define scch(a) scanf("%s",a);
#define anin(a) printf("%d\n",a);
#define ando(a) printf("%lf\n",a);
#define anch(a) printf("%s\n",a);

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

int main(void){
	int N,K;
	scin(N)
	scin(K)
	char mozi[N];
	scch(mozi)
	mozi[K - 1] += alfc;
	printf("%s\n",mozi);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<map>
#include<algorithm>

using namespace std;

void MakePrefix(map<string, int>*);
void FixNumber(string&, int&);
bool NotZero(const char&);

int main(){
  int i, n, multiplier;
  string number, unit;
  map<string, int> prefix;
  map<string, int>::iterator iter;

  MakePrefix(&prefix);
  cin >> n;

  for(i=0; i<n; ++i){
    cin >> number >> unit;
    iter = prefix.find(unit);

    if(iter == prefix.end()){
      multiplier = 0;
    }else{
      multiplier = iter->second;
      cin >> unit;
    }

    FixNumber(number, multiplier);
    cout << number << " * 10^" << multiplier << " " << unit << endl;
  }
  return 0;
}

void MakePrefix(map<string, int>* prefix){
  prefix->insert(make_pair("yotta", 24));
  prefix->insert(make_pair("zetta", 21));
  prefix->insert(make_pair("exa", 18));
  prefix->insert(make_pair("peta", 15));
  prefix->insert(make_pair("tera", 12));
  prefix->insert(make_pair("giga", 9));
  prefix->insert(make_pair("mega", 6));
  prefix->insert(make_pair("kilo", 3));
  prefix->insert(make_pair("hecto", 2));
  prefix->insert(make_pair("deca", 1));
  prefix->insert(make_pair("deci", -1));
  prefix->insert(make_pair("centi", -2));
  prefix->insert(make_pair("milli", -3));
  prefix->insert(make_pair("micro", -6));
  prefix->insert(make_pair("nano", -9));
  prefix->insert(make_pair("pico", -12));
  prefix->insert(make_pair("femto", -15));
  prefix->insert(make_pair("ato", -18));
  prefix->insert(make_pair("zepto", -21));
  prefix->insert(make_pair("yocto", -24));
}

void FixNumber(string& num, int& n){
  string::iterator i;
  i = find(num.begin(), num.end(), '.');

  if(i == num.end()){
    n += num.size()-1;
    if(num.size() != 1) num.insert(num.begin()+1, '.');
  }else if(num[0] == '0'){
    i = find_if(num.begin()+2, num.end(), NotZero);
    n -= (i - num.begin() -1);
    num.erase(num.begin(), i);
    if(num.size() != 1) num.insert(num.begin()+1, '.');
  }else{
    n += (i - num.begin() -1);
    num.erase(i);
    num.insert(num.begin()+1, '.');
  }
}

bool NotZero(const char& c){
  if(c == '0') return false;
  else return true;
}

Measured memory_bytes: 1252
import collections
import sys
input = sys.stdin.readline

n= int(input())
# ans = [0]*n
tmp = []

for x in range(1, int(n**0.5)+1):
    for y in  range(1, int(n**0.5)+1):
        for z in range(1, int(n**0.5)+1):
            tmp.append(x**2+y**2+z**2+x*y+y*z+z*x)
cnt = collections.Counter(tmp)

for i in range(1,n+1):
    print(cnt[i])


Measured memory_bytes: 50640
"use strict";

const main = arg => {
    // 標準入力の不要な空白と改行を削除し、配列に格納する
    const input = arg.trim().split("\n");
    const hitPoint = Math.floor(input[0].split(" ")[0], 10);
    const atcPoints = input[1].split(" ").map(points => {
        return Math.floor(points, 10);
    })
    const returnSum = (a, n) => {
        return a + n;
    }
    const atcSum = atcPoints.reduce(returnSum)

    atcSum >= hitPoint ? console.log("Yes") : console.log("No");
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));  

Measured memory_bytes: 16716
#include <stdio.h>
int main(void){
  long long i,j,n,m,k,a,b,c,h,w,r=0,l,t,tmp;
  scanf("%lld",&n);
  r=n*(n+1)*(n+2);r/=6;
  for(i=0;i<n-1;i++){
    scanf("%lld%lld",&a,&b);
    if(a>b){tmp=a; a=b; b=tmp;}
    k=a*(n+1-b);
    r-=k;
  }
  printf("%lld\n",r);
  return 0;
}

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

using namespace std;

int n, k, a[100001], b[100001], c[100001], dp[4][100001];

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }

    dp[1][1] = a[1];
    dp[2][1] = b[1];
    dp[3][1] = c[1];

    for(int i=2;i<=n;i++){
        dp[1][i] = max(dp[2][i-1], dp[3][i-1]) + a[i];
        dp[2][i] = max(dp[1][i-1], dp[3][i-1]) + b[i];
        dp[3][i] = max(dp[1][i-1], dp[2][i-1]) + c[i];
    }

    cout << max(dp[1][n], max(dp[2][n], dp[3][n]));


    return 0;
}

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

int main() {
	// your code goes here
	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n;i++) {
	    cin >> arr[i];
	}
	int dp[n + 1];
	dp[0] = arr[0];
	for (int i = 1; i < n;i++) {
	    dp[i] = max (arr[i],dp[i - 1]);
	}
	long long int ans = 0;
	for (int i = 0; i < n;i++) {
	    //cout << dp[i] << " ";
	    ans += (dp[i] - arr[i]);
	}
	cout << ans << endl;
	
}


Measured memory_bytes: 5124
n = int(input())

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

soredx = sorted(x)

migi = soredx[int(n/2-1)]
hidari = soredx[int(n/2)]

for i in range(n):
    if(migi<x[i]):
        print(migi)
    else:
        print(hidari)


Measured memory_bytes: 26772
#include <bits/stdc++.h>
#import <math.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vii vector<int, int>
#define po pop_back
#define hell 1000000007
#define PI 3.1415926535897
using namespace std;

void solve(){
	int n, m;
	cin>>n>>m;
	ll sum = 0;
	int temp;
	for(int i=0;i<m;i++){
		cin>>temp;
		sum+=temp;
	}
	if(sum>n) cout<<-1;
	else cout<<n-sum;
}

int main(){
	int t = 1;
	//cin>>t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3636
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

from operator import itemgetter
def index_sort(A):
    return sorted(enumerate(A),key=itemgetter(1))

N = I()
A = III()

x = index_sort(A)
y = []
for i in range(N):
    y.append(x[i][0]+1)

print(*y)

Measured memory_bytes: 68588
#include<stdio.h>
int main(){
long n,m,i,j,pi,pj,a,b,c,ans;
char s[111111],t[111111];
scanf("%ld%ld",&n,&m);
scanf("%s%s",s,t);
a=n;
b=m;
c=n%m;
while(c!=0){
a=b;
b=c;
c=a%b;
}
pi=n/b;
pj=m/b;
i=0;
j=0;
while(i<n){
if(s[i]!=t[j]){
printf("-1\n");
return 0;
}
i+=pi;
j+=pj;
}
ans=n*m/b;
printf("%ld\n",ans);
return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int N, M, sum = 0;
	cin >> N >> M;
	rep (i, M)
	{
		int j;
		cin >> j;
		sum += j;
	}
	if (sum > N)
	{
		cout << -1 << '\n';
	}
	else
	{
		cout << N - sum << '\n';
	}

	return 0;
}


Measured memory_bytes: 3656
#include<stdio.h>
int a[1000],b[1000],c[1001][1001];
int main(void)
{
    int n,m,s,j,i;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
	    scanf("%d",&a[i]);
	}
	for(i=0;i<m;i++){
	    scanf("%d",&b[i]);
	}
	for(i=0;i<=m;i++){
	    for(j=0;j<=n;j++){
		    c[i][j]=200000000;
		}
	}
	c[0][0]=0;
	for(i=0;i<m;i++){
	    for(j=0;j<=n;j++){
		    if(c[i+1][j]>c[i][j]){
			    c[i+1][j]=c[i][j];
			}
			if(c[i+1][j+1]>c[i][j]+a[j]*b[i]){
			    c[i+1][j+1]=c[i][j]+a[j]*b[i];
			}
		}
	}
	s=200000000;
	for(i=0;i<=m;i++){
	    if(s>c[i][n]){
		    s=c[i][n];
		}
	}
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 6632
#include<iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int N;
	vector<int> ListA;
	vector<int> SortList;
		
	cin >> N;

	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;

		ListA.push_back(A);
		SortList.push_back(A);
	}

	int max = -1;
	int premax = -1;

	sort(SortList.begin(), SortList.end(), greater<int>());

	max = SortList[0];
	premax = SortList[1];
	
	for (int i = 0; i < ListA.size(); i++) {
		if (max == ListA[i]) {
			cout << premax << endl;
		}
		else {
			cout << max << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3436
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

int main() {
	int n; cin >> n;
	VL a(n); rep(i, n)cin >> a[i];

	int cnt = 0;
	rep(i, n)cnt += a[i] < 0;

	LL sum = 0;
	rep(i, n)sum += abs(a[i]);
	if (cnt % 2 == 0) {
		Cout(sum);
	}
	else {
		LL mi = inf;
		rep(i, n)mi = min(mi, abs(a[i]));
		Cout(sum - mi*2);
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n, k; cin >> n >> k;
    cout << n - k + 1 << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
double dp[3030][3030];

int main(){
  int n;
  cin >> n;
  vector<double> p(n);
  rep(i,n){
    cin >> p[i];
  }
  dp[0][0]=1.0;
  /*rep(i,n) cout <<p[i]<<" ";
  cout << endl;*/
  for(int i=1;i<n+1;i++){
    for(int j=0;j<n+1;j++){
      dp[i][j]+=dp[i-1][j]*(1-p[i-1]);
      dp[i][j]+=dp[i-1][j-1]*p[i-1];
    }
  }
  double ans=0;
  for(int i=(n+2)/2;i<n+1;i++){
    ans += dp[n][i];
  }
  /*rep(i,n){
    cout << dp[1][i] <<" ";
  }*/
  //cout <<endl;
  cout << setprecision(10);
  cout << ans;
}

Measured memory_bytes: 71936
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int mod = 1e9+7;

int main() {

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

  sort(a.begin(), a.end());
  cout << abs(a[0]-a[n-1]) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,a) for(int i=0;i<(a);++i)
#define MP make_pair
#define INF 1e9
#define F first
#define S second
#define MAXN 100000
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
int N, M, n, a[MAXN], ans, cnt;
int main()
{
	cin >> N;
	REP(i, N)
	{
		cin >> a[i];
		--a[i];
	}
	REP(i, N)
	{
		if(a[i] == i)
		{
			cnt = 0;
			FOR(j, i, N)
			{
				if(a[j] == j)
				{
					cnt++;
				}
				else
				{
					i = j;
					break;
				}
				i = j + 1;
			}
			ans += cnt / 2 + cnt % 2;		
		}
	}
		cout << ans << endl;
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> mochi;
  
  for(int i=0; i<N; i++)
  {
    int s;
    cin >> s;
    mochi.push_back(s);
  }
  
  sort(mochi.begin(), mochi.end() );
//  sort(card.begin(), card.end(), std::greater<int>() );
  
  int count = 0;
  int size = 0;
  
  for(int i=0; i<N; i++)
  {
    int r = mochi[i];
    if(r>size){
      count++;
      size = r;
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    private static final PrintStream ps = System.out;
    private static final Scanner     sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();

        int[] a = new int[n + 1];
        for (int i = 1; i <= n; i++)
            a[i] = sc.nextInt();
        
        DisjointSet ds = new DisjointSet(n+1);
        for (int i = 0; i < m; i++) 
            ds.unite(sc.nextInt(), sc.nextInt());
        
        int count = 0;
        for (int i = 1; i <= n; i++)
            if (ds.same(i, a[i])) count++;
        
        ps.println(count);
   }
    
    static class DisjointSet {
        public int[] rank;
        public int[] p;
        
        DisjointSet(int size) {
            rank = new int[size];
            p = new int[size];
            for (int i = 0; i < size; i++) makeSet(i);
        }
        
        void makeSet(int x) {
            p[x] = x;
            rank[x] = 0;
        }
        
        boolean same(int x, int y) {
            return findSet(x) == findSet(y);
        }
        
        int findSet(int x) {
            if (x != p[x])
                p[x] = findSet(p[x]);
            return p[x];
        }
        
        void unite(int x, int y) {
            link(findSet(x), findSet(y));
        }
        
        void link(int x, int y) {
            if (rank[x] > rank[y]) {
                p[y] = x;
            } else {
                p[x] = y;
                if (rank[x] == rank[y])
                    rank[y]++;
            }
        }
    }
}


Measured memory_bytes: 90332
#include<bits/stdc++.h>
using namespace std;
int main()
{
     int n;
    string s;
     cin>>n>>s;
  
     int count=0;
    for(int i=0;i<=s.length()-3;)
    {
          if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
          {
            i=i+3;
             count++;
          }
          else
            i++;
    }
    cout<<count;
}

Measured memory_bytes: 256
main = do
    s <- getLine
    let len = length s
    let s1 = take ((len-1)`div`2) s
    let s2 = drop (((len+3)`div`2)-1) s
    if s == reverse s && s1 == reverse s1 && s2 == reverse s2
        then putStrLn "Yes"
        else putStrLn "No"

Measured memory_bytes: 3760
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
#define ar array
const int mxN=2e5;
const int MOD=1e9+7;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
int main()
{
    fastio;
    string s;
    cin>>s;
    ll f=0,i;
    if(s[2]==s[3]&&s[4]==s[5])
        cout<<"Yes"<<endl;
    else
            cout<<"No"<<endl;
}


Measured memory_bytes: 3608
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数

N,W = imn()
max_v = 100001
wv = [iln() for _ in range(N)]
max_w = 10**10
dp = [[max_w for _ in range(max_v+1)] for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
    for sum_v in range(max_v):
        if sum_v - wv[i][1] >= 0:
            dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v-wv[i][1]]+wv[i][0])
        dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v])

ans = 0
for sum_v in range(max_v):
    if dp[N][sum_v] <= W: ans = sum_v
print(ans)

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

def fibo(n, memo = {}):
   if n == 0 or n == 1:
      return 1
   elif n in memo:
      return memo[n]
   else:
      memo[n] = fibo(n - 1, memo) + fibo(n - 2, memo)
      return memo[n]

n = int(input())
print(fibo(n))


Measured memory_bytes: 5612
def main
  n, m = gets.split.map(&:to_i)
  # 割り切れるなら➾即決
  if m % n == 0
    puts m / n
    return
  end

  (m/n).downto(2) do |d|
    next if m % d != 0

    # 割り切れるのでチャンスはあるが、
    # 個数の問題をクリアできるか？
    num = m / d
    if n <= num
      puts d
      return
    end
  end
  puts 1
end

if __FILE__ == $0
  main
end


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

int main()
{
	string s, c;
	cin >> s;
	cin >> c;
	int cnt = 0;
	for (int i = 0; i < 3; i++) {
		if (s[i] == c[i])  cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
function Main(input) {
	var str = input;
	var ans = -1;
	var str = str.split("\n");
	var a = Number(str[0].split(" ")[0]);
	var b = Number(str[0].split(" ")[1]);
	ans = a*b;
	console.log(ans);
	}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29624
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))}
const main=()=>{
  let n=tn()
  let s=ts()
  let ans=0;
  for(let i=0;i<1000;i++){
    let e=('00' + i).slice(-3);
    let a1=false,a2=false,a3=false
    for(let j=0;j<n;j++){
      if(a1&&a2&&e[2]==s[j]){a3=true}
      if(a1&&e[1]==s[j]){a2=true}
      if(e[0]==s[j]){a1=true}
    }
    if(a1&&a2&&a3)ans++
  }
  to(ans)
}
main()

Measured memory_bytes: 7864
n, c = map(int,raw_input().split())

arr = [[0 for i in range(c)] for j in range(10**5+1)]

for i in range(n):
	s,t,ch = map(int,raw_input().split())
	s -= 1
	ch -= 1
	for i in range(s,t):
		arr[i][ch] = 1

ans = 0

for i in range(10**5+1):
	ans = max(ans,sum(arr[i]))

print ans

Measured memory_bytes: 41732
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    
    count=0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                if i+j+k==x:
                    count+=1
    print(count)


Measured memory_bytes: 5592
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            long N = sc.nextLong() - 0;
            int k = 1;
            long n = 26;
            long sum = 26;
            long prev = 0;
            for (; N > sum;) {
                k++;
                n *= 26;
                prev = sum;
                sum += n;
            }

            long N2 = N - prev - 1;
            String name = dfs(N2, k);

            System.out.println(name);
        }
    }

    private static String dfs(long n, int k) {
        if (k <= 0) {
            return "";
        }
        return dfs(n / 26, k - 1) + (char) ('a' + ((n % 26)));
    }

}


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

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }
        private const long MOD = 1000000007;
        static void SolveA(string[] args)
        {
            var nm = ReadAndParseIntArr();
            int n = nm[0];
            int m = nm[1];

            int minC = m;
            for(int c = n; c <= m/2;++c)
            {
                if( m % c == 0)
                {
                    minC = c;
                    break;
                }
            }

            int ans = m / minC;
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define int long long int
#define MP make_pair
#define PB push_back
#define F first
#define S second
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VP;

int x, ans = 0;
signed main()
{
  cin >> x;
  ans += x / 11 * 2;
  x -= x / 11 * 11;
  if(x > 0){
    ans += 1;
    x -= 6;
    if(x > 0){
      ans += 1;
    }
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

const int MAX_N = 5009;

int N, K;
int P[MAX_N];
ll C[MAX_N];

int main() {
    cin >> N >> K;
    REP(i, N) cin >> P[i];
    REP(i, N) cin >> C[i];
    REP(i, N) P[i]--;

    ll max_score = -1e18;

    REP(si, N) {
        vector<int> hist;
        int pos = si;
        ll cycle_score = 0;
        while (1) {
            pos = P[pos];
            hist.PB(pos);
            cycle_score += C[pos];
            if (pos == si) break;
        }
        int cycle_size = hist.size();

        ll cur_score = 0;
        ll max_score_i = -1e18;
        int t;
        REP(i, min(cycle_size, K)) {
            cur_score += C[hist[i]];
            if (cur_score > max_score_i) {
                max_score_i = cur_score;
                t = i + 1;
            }
        }
        if (cycle_score > 0 && cycle_size <= K) {// max_score_i += (K - t) / cycle_size * cycle_score;
            cur_score = 0;
            REP(i, cycle_size) {
                cur_score += C[hist[i]];
                max_score_i = max(max_score_i, cur_score + (K-i-1) / cycle_size * cycle_score);
            }
        }
        // printf("si = %d: max_score = %lld\n", si, max_score_i);
        max_score = max(max_score, max_score_i);
    }
    cout << max_score << endl;
    return 0;
}

Measured memory_bytes: 3688
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define ss st.st
#define sn st.nd
#define bod 100000007
/****************************/
int n;
int a[200010];
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,n)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	rep3(i,1,n)
	{
		if(a[i]==a[i-1])
		{
			cout<<"NO";
			return 0; 
		}
	}
	cout<<"YES";
	return 0;
}

Measured memory_bytes: 1024
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " <<
#define outdicimal out << fixed << setprecision(10)//TODO 小数点以下の桁数の変更
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;


class BMultiplication2 {
public:
    constexpr int mpow(const int &a, int n) noexcept  {
      if(n == 0) return 1;
      auto t = mpow(a, n / 2);
      t = t * t;
      if(n & 1) t = t * a;
      return t;
    }
	void solve(std::istream& in, std::ostream& out) {
    int n;
    in >> n;
    vector<int> a(n);
    REP(i,n) in >> a[i];
    sort(a.begin(),a.end());

    int ans = 1;
    REP(i, n) {
      int t = mpow(10,18) / ans;
      if(t < a[i]){
        ans = -1;
        break;
      }
      else{
        ans *= a[i];
        if(ans == 0) break;
      }
    }

    out << ans << endl;
	}
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
	BMultiplication2 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 4052
#include <iostream>
#include <iomanip>
#include <cassert>

#include <utility>
#include <vector>
#include <limits>
#include <algorithm>
#include <map>
#include <list>
using namespace std;

#define rep_init(i, init, n) for(int i = (init); i < n; ++i)
#define rep(i, n) rep_init(i, 0, n)
void Main()
{
	int N = 0;
	cin >> N;

	if (N % 10 == 3)
	{
		cout << "bon" << endl;
	}
	else if (N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8)
	{
		cout << "pon" << endl;
	}
	else
	{
		cout << "hon" << endl;
	}

	return;
}

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

	Main();
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rvs(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    vi(l, N);
    rep(i, N) cin >> l.at(i);
    srt(l);
    rvs(l);
    int ans=0;
    rep(i, K) ans += l.at(i);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        long N = Long.parseLong(scanner.next());
        long A = Long.parseLong(scanner.next());
        long B = Long.parseLong(scanner.next());
        if (A == 0) {
            System.out.println(0);
            return;
        }

        long q = N / (A + B);
        long r = N % (A + B);

        System.out.println(q * A + Math.min(r, A));
    }

}



Measured memory_bytes: 24916
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
int main(){
    Hello
    int a, b;
    cin >> a >> b;
    if(a <= 5) cout << 0;
    else if(a <= 12) cout << b/2;
    else cout << b;
    return 0;
}


Measured memory_bytes: 3620
for unused in xrange(input()):
    out,stack,p=0,0,0
    while out<3:
        ev=raw_input()
        if ev=="OUT":
            out+=1
        if ev=="HIT":
            stack+=1
        if ev=="HOMERUN":
            p+=stack+1
            stack=0
    if stack>=4:
        p+=stack-3
    print p

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph = vector<vector<ll>>;
int main(){
  ll N,K,b;
  cin>>N>>K>>b;
  vector<vector<ll>>vec(N,vector<ll>(K+1));
  ll d=0;
  for(ll i=0;i<N;i++){
    for(ll j=0;j<K+1;j++){
      cin>>vec.at(i).at(j); 
    }
    d+=vec.at(i).at(0);
  }
  d=d+1;
  ll re=d;
  const ll n=N;
  for (int tmp = 0; tmp < (1 << N); tmp++) {
    bitset<12> s(tmp);
    vector<ll>veco(K+1,0);
    // ビット列を出力
    for(ll i=0;i<N;i++){
      for(ll k=0;k<K+1;k++){
        if(s.test(i)){
          veco.at(k)+=vec.at(i).at(k);
        }
      }
    }
    for(ll i=1;i<K+1;i++){
      if(veco.at(i)<b)break;
      if(i==K){
        re=min(re,veco.at(0));
      }
    }
  }
  if(re==d){
    re=-1;
  }
  cout<<re<<endl;
  return 0;
}
      
    	
  

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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b) cout<<c<<endl;
  if(b==c) cout<<a<<endl;
  if(c==a) cout<<b<<endl;
  return 0;
}


Measured memory_bytes: 256
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 = Math.abs(a-b);

        int towera = 0;
        int towerb = 0;
        for(int i =1;i<c;i++){
            towera += i;
            // towerb += i;
            // if(i == c){
            //     towerb += c+1;
            // }
        }

        System.out.println(towera-a);

    }
}

Measured memory_bytes: 21844
object Main {
  val sc = new java.util.Scanner(System.in)

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val s = sc.next

    val r = s.split("[^ACGT]").map(_.length) match {
      case x if x.isEmpty => 0
      case x => x.max
    }
    println(r)

  }
}

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

int main(){
    string S;
    cin >> S;
    S.push_back(' ');
    int N = S.size();
    vector<int> A(N);
    int s = 0;
    for(int i=1; i<N; i++){
        s = (S[i-1] == '<' ? s+1 : 0);
        A[i] = s;
    }
    s = 0;
    for(int i=N-2; i>=0; i--){
        s = (S[i] == '>' ? s+1 : 0);
        A[i] = max(A[i], s);
    }
    int64_t ans = 0;
    for(int i=0; i<N; i++){
        cerr << A[i] << S[i];
        ans += A[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2820
N,M = map(int,input().split())
data = [list(map(int,input().split())) for i in range(M)]

import collections

class BellmanFord():
    def __init__(self,N):
        self.N = N
        self.e = collections.defaultdict(list)
    def add(self,u,v,d,directed = False):
        if directed is False:  #無向グラフの場合
            self.e[u].append([v,d])
            self.e[v].append([u,d])
        else:  #有向グラフの場合
            self.e[u].append((v,d))
    def BellmanFord_search(self,s):  #sから各点までの最短距離
        d = collections.defaultdict(lambda: float('inf'))
        d[s] = 0
        while True:
            update = False
            for u in self.e.keys():
                for v,c in self.e[u]:
                    if d[v] > d[u] + c:
                        d[v] = d[u] + c
                        update = True
            if not update:
                break
        return d
    def BellmanFord_negative_bool(self,s):
        d = collections.defaultdict(lambda: float('inf'))
        d[s] = 0
        for i in range(self.N):
            for u in self.e.keys():
                for v,c in self.e[u]:
                    if d[v] > d[u] + c:
                        if i != self.N - 1:
                            d[v] = d[u] + c
                        else:
                            d[v] = -float('inf')
                            for i in range(self.N):
                                for u in self.e.keys():
                                    for v, c in self.e[u]:
                                        if d[v] > d[u] + c:
                                            d[v] = d[u] + c
                            if d[N] == -float('inf'):
                                return True,d
                            else:
                                return False,d
        return False,d

G = BellmanFord(N)

for i in range(M):
    G.add(data[i][0],data[i][1],-data[i][2],directed=True)

bool,d = G.BellmanFord_negative_bool(1)
if bool:
    print('inf')
    exit()

print(-d[N])

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int n,k;
    cin >> n >> k;
    vector<int64_t> a(n),b(n),s(n),t(n);
    rep(i,0,n){
        cin >> a[i];
        if(a[i]>0) b[i]=a[i];
    }
    partial_sum(a.begin(),a.end(),s.begin());
    partial_sum(b.begin(),b.end(),t.begin());
    auto sum=[](vector<int64_t> &v,int l,int r){
        int64_t res=v[r];
        if(l>0) res-=v[l-1];
        return res;
    };

    int64_t ans=0;
    rep(i,0,n){
        if(i+k>n) break;
        int64_t tmp=max<int64_t>(sum(s,i,i+k-1),0);
        if(i>0) tmp+=sum(t,0,i-1);
        if(i+k<n) tmp+=sum(t,i+k,n-1);
        ans=max(ans,tmp);
    }
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


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

int main() {
	int N;
	int s[100];

	cin >> N;
	
	for (int i = 0; i < N; i++) {
		cin >> s[i];
	}

	sort(s, s + N);

	ll sum = 0;

	for (int i = 0; i < N; i++) {
		sum += s[i];
	}

	if (sum % 10 != 0) {
		cout << sum << endl;
		return 0;
	}

	for (int i = 0; i < N; i++) {
		if (s[i] % 10 != 0) {
			cout << (sum - s[i]) << endl;
			return 0;
		}
	}

	cout << 0 << endl;

	return 0;
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;

int main(){
	int N,L;
	cin >> N >> L;
	int m= 1000000;
	int ans=0;
	int sum=N*L-N+N*(N+1)/2;
	reps(i,N){
		int pie= sum-(L+i-1);
		if(abs(sum-pie)<m){
			ans=pie;
			m=abs(sum-pie);
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
object Main {
  def findGCD(x: Int, y: Int): Int = {
    val (small, large) = if (x < y) (x, y) else (y, x)
    if (small == 0) {
      large
    } else {
      findGCD(large % small, small)
    }
  }

  def main(args: Array[String]): Unit = {
    val xs = scala.io.StdIn.readLine().split(" ").toList.map(_.toInt)
    println(findGCD(xs(0), xs(1)))
  }
}

Measured memory_bytes: 43684
#include <iostream>//WA
#include <algorithm>
#include <vector>

using namespace std;

#define MAX_V 1000
#define INF 100000000000000

struct edge {
    long long from; //出発点
    long long to;   //到達点
    long long cost; //移動コスト
};

long long V; //頂点の数
long long E; //辺の数
long long d[MAX_V +1]; //始点からそこまで行くのにかかるコスト
vector<edge> edges; //移動の情報を保存する
bool negative_cycle=0;

vector<long long> Gra[1001], Grainv[1001];
bool canstart[1001];
bool cangoal[1001];

void bellman_ford(long long S){
    fill(d, d+V+1, INF); //すべての頂点をINFにする
    d[S] = 0; //始点を0にする
    long long i;
    for (i = 0; i < V; i++) {
        for (long long j = 0; j < (long long)edges.size(); j++) {

            struct edge e = edges[j];

            if ((d[e.to] > d[e.from] + e.cost)&&(d[e.from]<INF)) {  //移動した後のコストが小さいと、頂点のコストを更新：ただしfromがINFでないとする
                d[e.to] = d[e.from] + e.cost;
                if(canstart[e.from]==1&&cangoal[e.from]==1){
                    if (i == V-1) {         //頂点の数と同じ回数ループすると、負の閉路があるのでループをぬける
                        negative_cycle=1;
                        break;
                    } 
                }
            }
        }
    }
}

void dfs_for_start(long long v){
    long long i;
    for(i=0; i<Gra[v].size(); i++){
        if(canstart[Gra[v][i]]==0){
            canstart[Gra[v][i]]=1;
            dfs_for_start(Gra[v][i]);
        }
    }
    
}

void dfs_for_goal(long long v){
    long long i;
    for(i=0; i<Grainv[v].size(); i++){
        if(cangoal[Grainv[v][i]]==0){
            cangoal[Grainv[v][i]]=1;
            dfs_for_goal(Grainv[v][i]);
        }
    }
    
}

int main()
{
    cin >> V;
    cin >> E;

    long long S=1; //始点
    long long G=V; //終点

    long long i;
    for (i = 0; i < E; i++) {
        struct edge add;
        cin >> add.from;
        cin >> add.to;
        cin >> add.cost;
        add.cost=-add.cost;
        edges.push_back(add);

        Gra[add.from].push_back(add.to);
        Grainv[add.to].push_back(add.from);
    }

    fill(canstart,canstart+V+1,0);
    canstart[S]=1;
    dfs_for_start(S);

    fill(cangoal,cangoal+V+1,0);
    cangoal[G]=1;
    dfs_for_goal(G);

    bellman_ford(S);

    if(negative_cycle==0){    
        cout <<  -d[G] << endl;
    }else{
        cout << "inf" << endl;
    }
    system("pause");
    return 0;
}


Measured memory_bytes: 3888
//Author: A_S_M_M@sud_P@rvez
#include<bits/stdc++.h>
using namespace std;
#define    MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define    for0(i,n) for(int i=0;i<n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    gcd(a, b) __gcd(a , b)
#define    lcm(a,b) (a*(b/__gcd(a,b)))
#define    nl     "\n"
#define    End    return 0
#define    gt     greater<int>()
#define    ll     long long int
#define    mp     make_pair
#define    pb     push_back
#define    vi     vector<int>
#define    vl     vector<ll>
#define    mod    1000000007
#define    ull    unsigned long long int
#define    sp(n)  fixed<<setprecision(n)
#define    pi     acos(-1)

int main()
{
MP;

string s;
cin>>s;
if(s.size()>=3){
    for(int i=0;i<3;i++){
        cout<<s[i];
    }
}else{
    cout<<s;
}

End;   
}

Measured memory_bytes: 3632