akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline


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

memolist = [0]*(N+1)

import copy

for child in a:
    nextmemolist = copy.copy(memolist)
    for i in range(len(memolist)):
        if (memolist[i] + child) <= x and ((memolist[i] + child) < memolist[i+1] or memolist[i+1] == 0):
            nextmemolist[i+1] = memolist[i] + child
        if memolist[i+1] == 0:
            break
    memolist = nextmemolist


if memolist[-1] == x:
    print(N)
elif memolist[-1] != 0:
    print(N-1)
else:
    for i, ans in enumerate(memolist):
        if i == 0:
            continue
        if ans == 0:
            print(i-1)
            break


Measured memory_bytes: 3572
N = int(input())
A = list(map(int,input().split()))

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

ans  = gcd(A[0],A[1])
for a in range(2,N):
    ans = gcd(ans,A[a])
print(ans)


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

string S;
vector<ll> dp(3, 0);
 
int main(void){
	
	cin >> S;
	
	ll str = 1;
	for(int i = 0; i < S.size(); ++i){
	    if(S[i] == 'A') dp[0] += str;
	    else if(S[i] == 'B') dp[1] += dp[0];
	    else if(S[i] == 'C') dp[2] += dp[1];
	    else{
	        dp[2] = dp[2] * 3 + dp[1];
	        dp[1] = dp[1] * 3 + dp[0];
	        dp[0] = dp[0] * 3 + str;
	        str *= 3;
	    }
	    dp[0] %= MOD;
	    dp[1] %= MOD;
	    dp[2] %= MOD;
	    str %= MOD;
	}
    cout << dp[2] << endl;
    
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

//Get a Rectangular Field
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		while(T--!=0){
			int[][] a = new int[5][5];
			for(int i=0;i<5;i++)for(int j=0;j<5;j++)a[i][j]=sc.nextInt();
			int max = 0;
			for(int i=0;i<5;i++){
				for(int j=0;j<5;j++){
					for(int h=i;h<5;h++){
						for(int w=j;w<5;w++){
							boolean f = true;
							for(int n=i;n<=h;n++){
								for(int m=j;m<=w;m++){
									if(a[n][m]==0){
										f = false;break;
									}
								}
							}
							if(f)max = Math.max(max, (h-i+1)*(w-j+1));
						}
					}
				}
			}
			System.out.println(max);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};
int key[4];
int number(State &);
int factor(State &);
int expr(State &);

int number(State &begin) {
	int ret = key[*begin - 'a'];
	begin++;
	return ret;
}

int expr(State &begin) {
	if (*begin == '[') {
		begin++;
		if (*begin == '+') {
			begin++;
			ll left  = expr(begin);
			ll right = expr(begin);
			begin++;
			return left | right;
		} else if (*begin == '*') {
			begin++;
			ll left  = expr(begin);
			ll right = expr(begin);
			begin++;
			return left & right;
		} else if (*begin == '^') {
			begin++;
			ll left  = expr(begin);
			ll right = expr(begin);
			begin++;
			return left ^ right;
		}
	} else {
		return number(begin);
	}
}

int main() {
	string s, t;
	while (1) {
		cin >> s;
		if (s == ".") break;
		cin >> t;
		for (int i = 0; i < 4; i++) {
			key[i] = t[i] - '0';
		}
		State begin = s.begin();
		ll tmp		= expr(begin);
		ll ans		= 0;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				for (int k = 0; k < 10; k++) {
					for (int l = 0; l < 10; l++) {
						key[0] = i, key[1] = j, key[2] = k, key[3] = l;
						begin   = s.begin();
						ll unko = expr(begin);
						if (tmp == unko) ans++;
					}
				}
			}
		}
		cout << tmp << " " << ans << endl;
	}
	return 0;
}


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

int n, a, b, c, s;
int main() {
	cin >> n >> a >> b;
	for(int i=0; i<n; i++) {
		scanf("%d", &c);
		if(c >= a && c < b) s++;
	}
	cout << n - s << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

vvin edge(100020);
vpii bridge;
vin articulation;
vin order(100020),low(100020);
vbo visit(100020,false);

void dfs(int v,int p,int &res){
    visit[v]=true;
    order[v]=res;
    res++;
    low[v]=order[v];
    bool isArticulation=false;
    int cnt=0;
    for(auto e:edge[v]){
        if(!visit[e]){
            cnt++;
            dfs(e,v,res);
            low[v]=min(low[v],low[e]);
            if(p!=-1&&order[v]<=low[e])isArticulation=true;
            if(order[v]<low[e])bridge.push_back(mp(min(v,e),max(v,e)));
        }
        else if(e!=p)low[v]=min(low[v],order[e]);
    }
    if(p==-1&&cnt>1)isArticulation=true;
    if(isArticulation)articulation.push_back(v);
}

int main(){
    int v,e;cin>>v>>e;
    int s,t;//1-indexならそれぞれ-1する. そして出力で+1
    rep(i,e){
        cin>>s>>t;
        edge[s].push_back(t);
        edge[t].push_back(s);
    }
    int res=0;
    rep(i,v)if(!visit[i])dfs(i,-1,res);
    sort(all(articulation));
    //sort(all(bridge));
    rep(i,articulation.size())cout<<articulation[i]<<endl;
    //rep(i,bridge.size())cout<<bridge[i].first<<" "<<bridge[i].second<<endl;
}


Measured memory_bytes: 7644
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <iomanip>

using namespace std;
typedef long long ll;
const int maxn=1e5+1111;

int arr[maxn];
int dp[maxn];
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    dp[0]=dp[1]=0;
    for(int i=1;i<=n;++i){
        scanf("%d",arr+i);
        if(i>1) dp[i]=dp[i-1]+abs(arr[i]-arr[i-1]);
        for(int j=2;j<=k&&i-j>0;++j){
            dp[i]=min(dp[i-j]+abs(arr[i]-arr[i-j]),dp[i]);
        }
    }
    printf("%d\n",dp[n]);
    return 0;
}

Measured memory_bytes: 1024
// Problem: F - LCS
// Contest: AtCoder - Educational DP Contest
// URL: https://atcoder.jp/contests/dp/tasks/dp_f
// Parsed on: 2020-09-06 16:58:46
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);

using namespace std;

int main() {
    string a, b;
    cin >> a >> b;
    vector<vector<int>> dp(a.size(), vector<int>(b.size()));

    for (int i = 0; i < a.size(); i++)
        for (int j = 0; j < b.size(); j++)
            if (a[i] == b[j]) {
                if (i && j)
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                else
                    dp[i][j] = 1;
            } else
                dp[i][j] = max(i ? dp[i - 1][j] : 0, j ? dp[i][j - 1] : 0);

    int lcs = dp.back().back();
    string ans;
    int i, j;
    i = a.size() - 1;
    j = b.size() - 1;
    while (lcs != ans.size()) {
        if (a[i] == b[j]) {
            ans += a[i];
            i--;
            j--;
        } else {
            bool leftExists = i - 1 >= 0;
            bool topExists = j - 1 >= 0;

            if (leftExists ^ topExists) {
                if (leftExists)
                    i = i - 1;
                else
                    j = j - 1;
            } else {
                if (leftExists && topExists) {
                    if (dp[i - 1][j] > dp[i][j - 1])
                        i = i - 1;
                    else
                        j = j - 1;
                } else
                    break;
            }
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans;
    return 0;
}

Measured memory_bytes: 38176
<?php
 
$sc = new Scanner();
 
$n = $sc->nextInt();
$k = $sc->nextInt();
 
$h = [];
for($i = 0; $i < $n; $i++) {
    $h[] = $sc->nextInt();
}
sort($h);
 
$min = pow(10, 10);
$index = -1;
for($i = $k - 1; $i < $n; $i++) {
    $min = min($min, $h[$i] - $h[$i - $k + 1]);
}
echo $min . PHP_EOL;
 
class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}

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

int main()
{
    int n;
    scanf("%d", &n);
    int card[4][13] = {}, num;
    char mark, m[] = {'S', 'H', 'C', 'D'};
    for (int i = 0; i < n; i++)
    {
        cin >> mark >> num;
        if (mark == 'S')
            card[0][num - 1] = 1;
        else if (mark == 'H')
            card[1][num - 1] = 1;
        else if (mark == 'C')
            card[2][num - 1] = 1;
        else
            card[3][num - 1] = 1;
    }

    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 13; j++)
        {
            if (card[i][j] == 0)
                printf("%c %d\n", m[i], j + 1);
        }
    }
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<vector<Pii>> G(N);
    rep(i,N){
        int A; cin >> A;
        rep(j,A){
            int x,y; cin >> x >> y;
            G[i].emplace_back(--x,y);
        }
    }
    int ans=0;
    rep(bit,1<<N){
        int cnt=0,ok=1;
        rep(i,N) if (bit&1<<i){
            ++cnt;
            for (auto p:G[i]){
                if (p.second&&!(bit&1<<p.first)) ok=0;
                if (!p.second&&(bit&1<<p.first)) ok=0;
            }
        }
        if (ok) chmax(ans,cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{   int n,i,j,k,min,temp,*p,s=0;
    scanf("%d %d",&n,&k);
	p=(int*)malloc(n*sizeof(int));
    for(i=0;i<n;i++) 
	{
		scanf("%d ",(p+i));
	}
	for(i=0;i<n-1;i++)
	{
		min=i;
		for(j=i+1;j<n;j++)
		{
			if(*(p+min)>*(p+j))
			min=j;
		}
		temp=*(p+i);
		*(p+i)=*(p+min);
		*(p+min)=temp;
	}
	for(i=0;i<k;i++)
    {s=s+(*(p+i));}
    printf("%d",s);
	return 0;
}


Measured memory_bytes: 1720
wx=[]
wy=[]

def readdata():
    z=[]
    try:
        while True:
            z.append(raw_input())
    except: return z

def nextpath(p,dir0):
    for e in [3,0,1,2]:
        d = (dir0+e)%4
        if ispath(p,d): return d
    return None

def ispath(p,d):
    y,x = p
    f=""
    try:
        if   d==0 and y>0: f = wy[y-1][x]
        elif d==1 and x<len(wy): f = wx[y][x]
        elif d==2 and y<len(wx): f = wy[y][x]
        elif d==3 and x>0: f = wx[y][x-1]
    except: pass
    return f=="1"

def f0037():
    p =[0,0]
    dp = 1
    msg = []
    while True:
        dp = nextpath(p, dp)
        p[0] += [-1,0,1,0][dp]
        p[1] += [0,1,0,-1][dp]
        msg.append("URDL"[dp])
        if p==[0,0]: break
    return "".join(msg)

z = readdata()
wx = z[0::2]
wy = z[1::2]
print f0037()

Measured memory_bytes: 4288
H, N = map(int,input().split())
M = [list(map(int,input().split())) for k in range(N)]
dp = [10**10]*(10**5)
dp[0] = 0
for e in M:
    for k in range(e[0],10**5):
        dp[k] = min(dp[k],dp[k-e[0]]+e[1])
print(min(dp[H:]))


Measured memory_bytes: 75724
#include <iostream>
 
using namespace std;
 
int main()
{
  long long a, b, c, d;
  long long rect = 0;
 
  cin >> a >> b >> c >> d;
  rect = (a * b >= c * d) ? a * b : c * d;
  cout << rect << endl;
 
  return 0;
}

Measured memory_bytes: 256
using System;

public class S
{
    private const char BLANK = '.';
    private const char ROCK = '#';
    public static void Main()
    {



        var input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        var HEIGHT = input[0];
        var WIDTH = input[1];

        var TORCHMAP = new int[HEIGHT,WIDTH];
        int w_startIndex = -1;
        var h_startIndex = new int[WIDTH];
        var currentLine = new char[WIDTH];
        var w_currentCount = 0;
        var h_currentCount = new int[WIDTH];
        var MAX = 0;

        for(int i = 0; i < WIDTH; i++){
            h_startIndex[i] = -1;
        }

        for(int i = 0; i < HEIGHT; i++){
            currentLine = Console.ReadLine().ToCharArray();
            w_currentCount = 0;
            w_startIndex = -1;
            for(int k = 0; k < WIDTH; k++){
                if(currentLine[k] == '.'){
                    if(w_startIndex == -1){
                        w_startIndex = k;
                    } 
                    if(h_startIndex[k] == -1){
                        h_startIndex[k] = i;
                    } 
                    w_currentCount++;
                    h_currentCount[k]++;
                }else{
                    if(w_startIndex != -1){
                        for(int WI = k-1; WI >= w_startIndex; WI--){
                            TORCHMAP[i,WI] += w_currentCount;
                            MAX = Math.Max(TORCHMAP[i,WI], MAX);
                        }
                    }
                    if(h_startIndex[k] != -1){
                        for(int HI = i-1; HI >= h_startIndex[k]; HI--){
                            TORCHMAP[HI,k] += h_currentCount[k]-1;
                            MAX = Math.Max(TORCHMAP[HI,k], MAX);
                        }
                    }
                    w_currentCount =0;
                    h_currentCount[k] =0;
                    w_startIndex = -1;
                    h_startIndex[k] = -1;
                }
            }

            if(w_startIndex != -1){
                for(int WI = WIDTH-1; WI >= w_startIndex; WI--){
                    TORCHMAP[i,WI] += w_currentCount;
                    MAX = Math.Max(TORCHMAP[i,WI], MAX);
                }
            }
            
        }

        for(int i = 0; i < WIDTH; i++){
            if(h_startIndex[i] != -1){
                for(int HI = HEIGHT-1; HI >= h_startIndex[i]; HI--){
                    TORCHMAP[HI,i] += h_currentCount[i]-1;
                    MAX = Math.Max(TORCHMAP[HI,i], MAX);
                }
            }
        }

        Console.WriteLine(MAX);

    }
}

Measured memory_bytes: 30664
#include <iostream>

using namespace std;

int main(){
  int A,B;
  cin >> A >> B;

  if(25*(A+1)/2.0 <= 10*B || 10*(B+1) <= 25*A/2.0){
    cout << -1 << endl;
  }else if(25*A/2.0 < 10*B){
    cout << 10*B << endl;
  }else{
    cout << (int)(25*A/2.0 + 0.9) << endl;
  }

  return 0;
}

Measured memory_bytes: 256
s = input()
n = len(s)
ans = [0] * n
cnt_even = 0
cnt_odd = 0
index = 0
for i in range(n - 1):
    if s[i] == 'R' and s[i + 1] == 'L':
        index = i
    if i % 2 == 0:
        cnt_even += 1
    else:
        cnt_odd += 1
    if s[i] == 'L' and s[i + 1] == 'R' or i == n - 2:
        if i == n - 2:
            if (i + 1) % 2 == 0:
                cnt_even += 1
            else:
                cnt_odd += 1
        if index % 2 == 0:
            ans[index] += cnt_even
            ans[index + 1] += cnt_odd
        else:
            ans[index] += cnt_odd
            ans[index + 1] += cnt_even
        cnt_even = 0
        cnt_odd = 0
print(*ans, sep=' ')

Measured memory_bytes: 6400
n=int(input())
x=[]
y=[]
h=[]
for i in range(n):
    a,b,c=map(int,input().split())
    x.append(a)
    y.append(b)
    h.append(c)
    if c>0:
        g=i

for i in range(101):
    for j in range(101):
        t=h[g]+abs(x[g]-i)+abs(y[g]-j)
        f=0
        for k in range(0,n):
            if h[k]==max(0,t-abs(x[k]-i)-abs(y[k]-j)):
                f+=1
        if f==n:
            print(i,j,t)
            exit()
        


Measured memory_bytes: 3064
N, M = map(int, input().split())
loads = [[] for _ in range(N)]

for _ in range(M):
    A, B = map(int, input().split())
    loads[A-1].append(B-1)
    loads[B-1].append(A-1)

queue = [0]
dist = [0] * N
prev = [-1] * N
while(len(queue) != 0):
    now = queue[0]
    queue.pop(0)
    for i in loads[now]:
        if dist[i] != 0:
            continue
        else:
            queue.append(i)
            dist[i] = dist[now] + 1
            prev[i] = now + 1
print('Yes')
for i in prev[1:]:
    print(i)

Measured memory_bytes: 38132
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc068.contest.atcoder.jp/tasks/arc068_a?lang=en>
問題文============================================================
 すぬけくんは 6 面サイコロで遊ぶことにしました。
 サイコロは 1 から 6 までの整数がそれぞれの面に書かれており、向かい合う面に書かれた数の和はどれも 7 です。
 
 すぬけくんはサイコロの好きな面が上向きになるように置いたのち何回か以下の操作を行います。
 
 操作：サイコロを手前、奥、左、右のどれかの方向に 90° だけ回転させる。
 その後、上を向いている面に書かれた数を y として y 点得る。
 例えば、図のように 1 と書かれた面が上を向いており、手前側の面に 5 が、右側の面に 4 が書かれている状況を考えます。
 図に示されるように右方向に回転させることで 3 と書かれた面が上を向くようにすることが可能です。
 その他、左方向に回転させた場合は 4 と書かれた面が、手前方向に回転させた場合は 2 と書かれた面が、
 奥方向に回転させた場合は 5 と書かれた面が上を向くようにすることが可能です。

=================================================================

解説=============================================================

 最適な操作は サイコロの面を 6,5,6,5,6,5,6,5... と動かした場合である。
 よってこのパターンでシミュレーションすれば良い
 
================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll x; cin >> x;
    ll s = max(0LL,x/11 - 10);
    ll ans = 2*s;
    ll now = s*11;
    
    int add = 6;
    while(now < x){
        now+=add; ans++;
        if(add == 6) add =5;
        else add = 6;
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>

using namespace std;

int main(void) {
	int A, B, C;
	cin >> A >> B >> C;
	cout << (A + B >= C ? "Yes" : "No") << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 764
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int, int>pii;
typedef pair<int, pii>pi3;
ll mod = 1000000007;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
int x[100000], y[100000];
int ans[100000];
int main()
{
	map<string, int>ma;
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num; i++)
	{
		string s;
		cin >> s;
		ma[s]++;
	}
	scanf("%d", &num);
	for (int i = 0; i < num; i++)
	{
		string s;
		cin >> s;
		ma[s]--;
	}
	map<string, int>::iterator it = ma.begin();
	int maxi = 0;
	for (;;)
	{
		if (it == ma.end())break;
		maxi = max(maxi, (*it).second);
		it++;
	}
	printf("%d\n", maxi);
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int h = sc.nextInt();
		int w = sc.nextInt();
        
        for(int i = 0; i < h; i++) {
          String value = sc.next();
          // 出力
		  System.out.println(value);
          System.out.println(value);
        }
	}
}

Measured memory_bytes: 24020
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>

using namespace std;

int main() {
  int n,h[30];
  cin >> n;
  for(int i = 0; i < n; i++)
    cin >> h[i];
  
  int sum = 1;
  bool flag;
  for(int i = 1; i < n; i++) {
    for(int j = 0; j <= i-1; j++) {
      if(h[i] >= h[j]) flag = 1;
      else  {
        flag = 0; 
        break;
      }
    }
    if(flag) sum++;
  }
  cout << sum << endl; 
}

Measured memory_bytes: 3580
#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) (v).begin(),(v).end()
#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; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int main() {
	int x;
	cin >> x;
	int ans = 1;
	FOR(i, 2, x + 1) {
		int p = i * i;
		while (p * i <= x) p *= i;
		if (p <= x) chmax(ans, p);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <string.h>
#include<stdio.h>
#include <vector>

using namespace std;



int main(){
	int X, Y, a = 0;
	cin >> X >> Y;

	for (int i = 0; i <= X; i++) {
		if (2 * (X - i) + 4 * i == Y) {
			a = 1;
		}
	}
	if (a == 1) cout << "Yes" << endl;
	else cout << "No" << endl;
	
return 0;
}


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

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)

const int mod = 1e9+7;
const int N = 1e5+5; 

int main(){
	fast;
	ll t = 1; 
// 	cin >> t;
	while(t--){
       ll n,m; cin >> n >> m;
       ll arr[n+5];
       
       ll s = 0;
       rep(i,1,m){
           ll x; cin >> x;
           s += x;
       }
       
       if(s <= n) cout << n - s << endl;
       else cout << "-1\n";
	}
}

Measured memory_bytes: 3660
#include <iostream>
#include <cmath>

using namespace std;

const int MAX_N = 10000;

bool P[MAX_N + 1];

void primes() {

    fill(P, P + MAX_N + 1, true);

    P[0] = P[1] = false;

    for (int i = 2; i <= sqrt(MAX_N); i++) {
        if (P[i]) {
            for (int j = i * 2; j <= MAX_N; j += i) {
                P[j] = false;
            }
        }
    }
}

int main() {

    int n, count = 0;
    cin >> n;

    primes();

    for (int i = 0; i < n; i++) {

        int a;
        cin >> a;

        count++;

        if (a != 2 && a % 2 == 0) {
            count--;
        } else {
            for (int j = 3; j <= sqrt(a); j += 2) {
                if (P[j] && a != j && a % j == 0) {
                    count--;
                    break;
                }
            }
        }
    }

    cout << count << endl;
}


Measured memory_bytes: 3064
<?php

  list($s) = explode(" ", trim(fgets(STDIN)));

  $a = substr($s,0,2);
  $b = substr($s,2,2);

  if($a >= 1 && $a <= 12){
    if($b >= 1 && $b <= 12){
      echo "AMBIGUOUS";
    }else{
      echo "MMYY";
    }
  }else{
    if($b >= 1 && $b <= 12){
      echo "YYMM";
    }else{
      echo "NA";
    }
  }

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

using namespace std;

#define INF (1LL << 54)

#define WHITE 0
#define GRAY  1
#define BLACK 2

int main()
{
	int n, k;

	while (true)
	{
		cin >> n >> k;

		if (n == 0 && k == 0) { break; }

		vector<vector<long long> > graph(n + 1, vector<long long>(n + 1, INF));

		for (int i = 1; i <= k; i++)
		{
			int q; cin >> q;

			if (q == 0)
			{
				int a, b;

				cin >> a >> b;

				vector<int> C(n + 1, WHITE);

				vector<long long> D(n + 1, INF);

				vector<int> P(n + 1);

				D[a] = 0;
				P[a] = -1;

				int u;

				while (true)
				{
					long long mincost = INF;

					for (int i_ = 1; i_ <= n; i_++)
					{
						if (C[i_] != BLACK && D[i_] < mincost)
						{
							mincost = D[i_];

							u = i_;
						}
					}

					if (mincost == INF)
						break;

					C[u] = BLACK;

					for (int v = 1; v <= n; v++)
					{
						if (C[v] != BLACK && graph[u][v] != INF)
						{
							if (D[u] + graph[u][v] < D[v])
							{
								D[v] = D[u] + graph[u][v];
								P[v] = u;
								C[v] = GRAY;
							}
						}
					}
				}

				cout << (D[b] != INF ? D[b] : -1) << endl;
			}
			else
			{
				int c, d, e;

				cin >> c >> d >> e;

				graph[c][d] = min((long long) e, graph[c][d]);
				graph[d][c] = min((long long) e, graph[c][d]);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef long double ld;

const ll INF = 2e9 + 10;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1);
const int N = 2e5 + 10;
const int M = 100;

int a[N];
vector <pair <int, int> > g[N];
bool used[N];
int l[N], r[N], d[N];
int pos[N];

void dfs(int v, int dst) {
    used[v] = true;
    pos[v] = dst;
    for (auto u: g[v])
        if (!used[u.first])
            dfs(u.first, dst + u.second);
}

int main() {
    //freopen("a.in", "r", stdin);
    int n, m;
    cin >> n >> m;
    fill(a, a + n, INF);
    int st;
    for (int i = 0; i < m; i++) {
        scanf("%d %d %d", &l[i], &r[i], &d[i]);
        l[i]--, r[i]--;
        g[l[i]].pb({r[i], d[i]});
        g[r[i]].pb({l[i], -d[i]});
        st = l[i];
    }
    for (int i = 0; i < n; i++)
        if (!used[i])
            dfs(i, 0);
    for (int i = 0; i < m; i++)
        if (pos[r[i]] - pos[l[i]] != d[i]) {
            cout << "No";
            return 0;
        }
    cout << "Yes";
}


Measured memory_bytes: 16384
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
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; }

// Mod int
// const int mod = 1000000007;
const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  int n, k;
  cin >> n >>k;
  vi l(k), r(k);
  rep(i, k) cin >> l[i] >> r[i];
  vector<mint> dp(n+1);
  vector<mint> dpsum(n+1);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= n; i++) {
    rep(j, k) {
      int li = i - r[j];
      int ri = i - l[j];
      if (ri < 0) continue;
      li = max(1, li);
      dp[i] += dpsum[ri] - dpsum[li-1];
    }
    dpsum[i] = dpsum[i-1] + dp[i];
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 6372
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <list>

typedef long long int ll;

using namespace std;
string S;
int Q;
list<char> lc;

int main()
{
  int n, i;
  int func;
  string shead="", stail="";
  string Sn;
  string ch;
  int dir=1;

  cin >> S;
  cin >> Q;

  for (i=0; i<Q; i++) {
    cin >> func;
    switch(func) {
    case 1:
      dir *= (-1);
      break;
    case 2:
      cin >> func >> ch;
      switch((3-func*2)*dir) {
      case 1:
        shead += ch[0];
        break;
      case -1:
        stail += ch[0];
        break;
      }
      break;
    }
  }
  if (dir<0) {
    reverse(S.begin(), S.end());
    reverse(stail.begin(), stail.end());
    cout << stail << S << shead;
  } else {
    reverse(shead.begin(), shead.end());
    cout << shead << S << stail;
  }

  printf("\n");

  return 0;
}

/*

  */


Measured memory_bytes: 1088
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
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; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


void solve(){
    string s;
    cin>>s;
    ll n=s.size();
    ll a=0,b=n-1;
    rep(i,n){
        if(s[i]=='A'){
            a=i;
            break;
        }
    }
    repr(i,n){
        if(s[i]=='Z'){
            b=i;
            break;
        }
    }
    cout<<b-a+1<<endl;
}

 
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
     
    solve();


    return 0;
}

Measured memory_bytes: 720
from operator import itemgetter
n,m=map(int,input().split())
A=list(map(int,input().split()))
l=[]
A.sort()

for i in range(m):
    b,c=map(int,input().split())
    l.append([b,c])

l.sort(key=itemgetter(1),reverse=True)
# print(l)

# print(A)
# print(l)
x=0
for i in range(m):
    b=l[i][0]
    c=l[i][1]
    while(x<n and b>0):
        if(A[x]<c):
            A[x]=c
            b-=1
        x+=1
    if(x==n):
        break
print(sum(A))
        




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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N; cin >> N;
    ll A[100010],B[100010];
    ll ans = 0;
    for (int i = 0; i < N+1; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    for (int i = N-1; i >= 0; i--) {
        ll c = min(A[i+1],B[i]);
        ans += c;
        A[i+1] -= c;
        B[i] -= c;
        if(B[i] != 0){
            ll c = min(A[i],B[i]);
            ans += c;
            A[i] -= c;
            B[i] -= c;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5112
// Vicfred
// https://atcoder.jp/contests/abc166/tasks/abc166_b
// implementation
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    int n, k;
    readf("%s %s\n", &n, &k);

    int[] snukes = new int[n];

    foreach(_; 0..k) {
        readln;
        int[] a = readln.split.map!(to!int).array;

        foreach(item; a) {
            snukes[item-1] = 1;
        }
    }
  snukes.count!("a == 0").writeln;
}

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

#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 5005, MOD = 1e9 + 7;
int dp[N][N][2], dp_add[N][N], dp_add_d[N][N];

void add(int &a, int b) {
    a += b;
    if (a >= MOD)
        a -= MOD;
    if (a < 0)
        a += MOD;
}

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

    int n, a, b;
    cin >> n >> a >> b;

    if (a < b)
        swap(a, b);

    dp[0][0][0] = 1;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= n; j++) {
            if (i >= j && i >= a) {
                add(dp_add[i + 1][j], dp[i][j][0]);
            }
            else {
                add(dp_add[i + b][j], dp[i][j][0]);

                int lim = min(b - 1, n - i - a);

                if (lim > 0) {
                    add(dp_add_d[i + 1][i + 1 + a], dp[i][j][0]);
                    add(dp_add_d[i + lim + 1][i + 1 + lim + a], -dp[i][j][0]);
                }
            }
        }

        for (int j = 0; j <= n; j++) {
            add(dp_add[i + 1][j], dp_add[i][j]);
            add(dp[i + 1][j][1], dp_add[i + 1][j]);

            add(dp_add_d[i + 1][j + 1], dp_add_d[i][j]);
            add(dp[i + 1][j + 1][1], dp_add_d[i + 1][j + 1]);

            for (int k = 0; k < 2; k++) {
                add(dp[i + 1][j][0], dp[i][j][k]);
            }
        }
    }

    int ans = 0;

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j < 2; j++) {
            add(ans, dp[n][i][j]);
        }
    }

    cout << ans;

	return 0;
}

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

#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))

template<typename T1,typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 & a, T2 b) { if (a < b) a = b; }

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;
const long long kMod = 1000000007;

const long long kMAX = 1000000000;

using namespace std;
using ll = long long;

inline int readInt() {
  char c = getchar();
  while(!isdigit(c) && c != '-') c = getchar();
  int sigma = 1;
  if (c == '-') {
    sigma = -1;
    c = getchar();
  }
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * sigma;
}

template <class T>
void PrintVector(const vector<T> & v) {
  for (const auto & e: v) {
    cout << e << endl;
  }
}

template <class T>
void PrintVector(const vector<T> & v, int n) {
  rep(i, 0, n - 1) {
    cout << v[i] << endl;
  }
}

int main(int argc, char const *argv[]) {
  // long n, m, h, w, x, y;
  long n;
  // long ans = 0;
  // vector<int> a, b;
  // cin >> n >> m;
  // rep(i, 1, n) {
  //   int a0, b0;
  //   cin >> a0 >> b0;
  //   a.pb(a0);
  //   b.pb(b0);
  // }
  cin >> n;
  rep(i, 1, 9) {
    long m = n / i;
    if (i * m == n && m <= 9 && m >= 1) { cout << "Yes\n"; return 0; }
  }
  // for (const auto & a0: a) {
  //
  // }

  // cout << ans << endl;
  cout << "No\n";
  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, n) For(i, 0, n)
using namespace std;

signed main(void)
{
	int n;
	cin >> n;
	vector<int> L(n);
	rep(i, n) cin >> L[i];
	int cnt;
	
	cnt = 0;
	sort(L.begin(), L.end());
	rep(i, n - 2) For(j, i + 1, n - 1)
	{
		int ab = L[i] + L[j];
		int l = lower_bound(L.begin(), L.end(),ab) - L.begin();
		int r = j + 1;
		cnt += l - r;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
int GCD(int a, int b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
 
    int main(){
      int A,B;
      char op;
      cin >> A >> op >> B;
      if(op=='+') cout << A+B << endl;
      else cout << A-B << endl;
      return 0;}

Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))

A.sort(reverse=True)
E = [0,0]

j = 0
for i in range(n):
    if E[j] == A[i]:
        j += 1
        if j == 1:
            continue
        else:
            break
    E[j] = A[i]
    
print(E[0]*E[1])

Measured memory_bytes: 62704
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;

namespace Dinic {
	const int mxn=5000, mxm=500000;
	int S, T;
	int head[mxn];
	int next[mxm], to[mxm], flow[mxm];
	inline void addedge(int idx, int a, int b, int f)
	{
		next[idx]=head[a]; head[a]=idx;
		to[idx]=b; flow[idx]=f;
	}
	int newm;
	inline void add(int a, int b, int f)
	{
		addedge((++newm)<<1, a, b, f);
		addedge(newm<<1|1, b, a, 0);
	}
	inline void init()
	{
		memset(head, 0, sizeof(head));
		newm=0;
	}
	int ch[mxn];
	inline bool tell()
	{
		memset(ch, -1, sizeof(ch));
		ch[S]=1;
		queue<int> q;
		q.push(S);
		while(!q.empty())
		{
			int u=q.front(); q.pop();
			for(int i=head[u]; i; i=next[i])
			{
				const int v=to[i];
			//printf("->%d %d %d\n", v, ch[v], flow[i]);
				if(ch[v]>0 || !flow[i]) continue;
				ch[v]=ch[u]+1;
				q.push(v);
			}
		}
		return ch[T]>0;
	}
	int expand(int a, int b)
	{
		//printf("expanding %d, %d\n", a, b);
		if(a==T) return b;
		int r=0, c;
		for(int i=head[a]; i && r<b; i=next[i])
		{
			int v=to[i];
			if(ch[v]!=ch[a]+1 || !flow[i]) continue;
			c=expand(v, min(b-r, flow[i]));
			r+=c;
			flow[i]-=c, flow[i^1]+=c;
		}
		return r;
	}
	inline int dinic(int sS, int tT)
	{
		S=sS, T=tT;
		int r=0, c;
		while(tell()) while(c=expand(S, 0x3f3f3f3f)) r+=c;
		return r;
	}
}

const int maxn=100+5;
int mx[maxn][maxn];


int main()
{
	int n, m, l; 
	while(scanf("%d%d%d", &n, &m, &l)==3)
	{
		memset(mx, 0x3f, sizeof(mx));
		for(int i=1; i<=n; ++i) mx[i][i]=0;
		for(int i=1; i<=m; ++i)
		{
			int x, y, l; scanf("%d%d%d", &x, &y, &l);
			mx[y][x]=mx[x][y]=min(mx[x][y], l);
		}
		for(int k=1; k<=n; ++k) for(int i=1; i<=n; ++i)
			for(int j=1; j<=n; ++j) mx[i][j]=min(mx[i][j], mx[i][k]+mx[k][j]);
		Dinic::init();
		for(int i=1; i<=n; ++i)
		{
			int x; scanf("%d", &x);
			Dinic::add(1, i+5, x);
		}
		for(int i=1; i<=n; ++i)
		{
			int x; scanf("%d", &x);
			Dinic::add(i+n+10, 2, x);
		}
		for(int i=1; i<=n; ++i) for(int j=1; j<=n; ++j)
		{
			if(mx[i][j]<l) 
			{
				Dinic::add(i+5, j+n+10, 0x3f3f3f3f);
				//printf("adding..%d %d\n", i, j);
			}
		}
		printf("%d\n", Dinic::dinic(1, 2));
	}
	
	return 0;
}

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

int main(){
    int n,m;
    cin >> n >>m;
    int l[m],r[m];
    for(int i=0;i<m;i++)cin >> l[i] >> r[i];
    sort(l,l+m);
    sort(r,r+m);
    if(l[m-1]>r[0]){
        cout << 0 << endl;
        return 0;
    }
    else if(r[0]-l[m-1]+1>n){
        cout << n << endl;
        return 0;
    }
    else{
        cout << r[0]-l[m-1]+1 << endl;
        return 0;
    }
}

Measured memory_bytes: 1024
n = gets.to_i
h = {}
n.times do
  s = gets
  h[s.chomp] =0 #すべとをまず与えにする　計算始めるために

end

for m in ["S", "H", "C", "D"] do #一般的なFOR分の使い方にin　を使う
  for i in 1..13 do
    puts "#{m} #{i}" if !h.has_key?(m+" "+i.to_s)#データの中にキーがあるかどうかの確認
  end
end


Measured memory_bytes: 6872
#include <functional>
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n, u, v; cin >> n >> u >> v;
    u--; v--;
    vector<int> adj[n];
    for (int j = 0; j < n-1; j++) {
        int a, b; cin >> a >> b;
        adj[a-1].push_back(b-1);
        adj[b-1].push_back(a-1);
    }
    int du[n], dv[n];
    function<void(int, int, int, int*)>
        dfs = [&adj, &dfs](int i, int p, int l, int *d) {
        d[i] = l;
        for (int j : adj[i]) if (j != p) dfs(j, i, l+1, d);
    };
    dfs(u, -1, 0, du);
    dfs(v, -1, 0, dv);
    int ans = 0;
    for (int i = 0; i < n; i++)
        if (du[i] < dv[i]) ans = max(ans, dv[i] - 1);
    cout << ans << endl;
}


Measured memory_bytes: 15488
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        long[][] dp = new long[n+1][n*50+1];
        dp[0][0] = 1;
        for(int i = 1; i <= n; i++){
            int x = sc.nextInt();
            for(int j = n; j > 0; j--){
                for(int k = 0; k < n*50+1; k++){
                    if(k-x >= 0){
                        dp[j][k] += dp[j-1][k-x];
                    }
                }
            }
        }
        long ans = 0;
        for(int i = 1; i <= n; i++){
            ans += dp[i][i*a];
        }
        System.out.println(ans);
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

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

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>

using namespace std;

typedef complex<double> P;
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))
double dot(P a, P b) {
  return (a.real() * b.real() + a.imag() * b.imag());
}

double cross(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}

double distance_l_p(P a, P b, P c) {
  return abs(cross(b-a, c-a)) / abs(b-a);
}

int main(){


	char cm;
	double x1,y1,x2,y2,xq,yq;

	while(cin>>x1>>cm>>y1>>cm>>x2>>cm>>y2>>cm>>xq>>cm>>yq){
		P p[2];
		p[0]=P(x1,y1);
		p[1]=P(x2,y2);
		P q=P(xq,yq);
		P v=p[0]-p[1];
		P nve = P(-v.imag(),v.real());
		nve/=abs(nve);
		double d = distance_l_p(p[0],p[1],q);
		
		P r[2];
		r[0] = q + 2*d*nve;
		r[1] = q - 2*d*nve;
		if(distance_l_p(p[0],p[1],r[0])>distance_l_p(p[0],p[1],r[1])){
			printf("%.5f %.5f\n",r[1].real(),r[1].imag());
		}
		else{
			printf("%.5f %.5f\n",r[0].real(),r[0].imag());
		}
	}

	return 0;
}

Measured memory_bytes: 0
s = list(input())

#不等号の向きを記録する
memo = ""

#不等号の連続した個数を記録する
cnt = 0

#1つ前に数えた不等号の連続した個数を記録する
before_cnt = 0

#出力する答え
ans = 0

#文字列Sの連続した不等号の向きを数える
for x in s:
    #初めはmemoが空白なので,memoに不等号の向きを記録
    if memo == "":
        memo = x
    
    #不等号の向きが同じ場合は、数を1カウントしてループに戻る
    if memo == x:
        cnt += 1
        
    #不等号の向きが異なる場合
    else:
        #ansに和を加算する
        ans += cnt * (cnt+1) // 2
        
        #不等号の向きの変化が処理が必要な場合
        if memo == ">":
            if before_cnt < cnt:
                ans -= before_cnt
            else:
                ans -= cnt

        before_cnt = cnt
        cnt = 1
        memo = x
else:
    ans += cnt * (cnt+1) // 2
    if before_cnt < cnt:
        if memo == ">":
            ans -= before_cnt
    else:
        if memo == ">":
            ans -= cnt
    before_cnt = cnt
    cnt = 0
 
print(ans)


Measured memory_bytes: 13156
def main():
    s = input()
    q = int(input())
    jun = True
    mae = ""
    ushiro = ""
    for _ in range(q):
        qu = input()
        if qu == '1':
            jun = not jun
        else:
            if qu[2] == '1':
                if jun:
                    mae = qu[4] + mae
                else:
                    ushiro = ushiro + qu[4]
            else:
                if jun:
                    ushiro = ushiro + qu[4]
                else:
                    mae = qu[4] + mae
    s = mae + s + ushiro
    if not jun:
        s = s[::-1]
    print(s)
main()

Measured memory_bytes: 4372
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const ll N = 1000030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;
string s;
ll n;
ll fn(ll y,ll x)
{
	if(y==n)
	return x;
	ll cursum=0;
	ll ans=0;

	rep(i,y,n)
	{
		cursum*=10;
		cursum+=s[i]-'0';
		ans+=fn(i+1,cursum+x);
	}

	return ans;
}
int main()
{
		ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
   cin>>s;
   n=s.size();
   cout<<fn(0ll,0ll);
   //cout<<ans;
}

Measured memory_bytes: 256