akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace AtCoder.Abcdef
{
    public class QuestionC
    {
        const long d = 1000_000_000 + 7;

        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            //Input int
            int n = int.Parse(Console.ReadLine());

            //Input int array
            long[] a = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long sum = 0;
            for (int i = 0; i < a.Length; i++)
            {
                sum += a[i];
                sum %= d;
            }

            long ans = 0;
            for (int i = 0; i < n - 1; i++)
            {
                sum -= a[i];
                if (sum < 0) sum += d;
                long temp = a[i] * sum;
                ans += temp;
                ans = ans % d;
            }

            Console.WriteLine(ans);
            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 47212
h, w = map(int, input().split())
INF = 10**5
MAP = ["."*(w+2)]
for _ in range(h):
    MAP.append("."+input()+".")
MAP.append("."*(w+2))
ROUTE = [[0]*(w+2) for _ in range(h+2)]
for i in range(2, w+1):
    ROUTE[0][i] = INF
for i in range(2, h+1):
    ROUTE[i][0] = INF

for i in range(1, h+1):
    for j in range(1, w+1):
        if MAP[i][j] == ".":
            x1 = ROUTE[i][j-1]
            x2 = ROUTE[i-1][j]
        else:
            if MAP[i][j-1] == "#":
                x1 = ROUTE[i][j-1]
            else:
                x1 = ROUTE[i][j-1]+1

            if MAP[i-1][j] == "#":
                x2 = ROUTE[i-1][j]
            else:
                x2 = ROUTE[i-1][j]+1
        ROUTE[i][j] = min(x1, x2)


print(ROUTE[h][w])


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

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define sec second
#define fori(i, a, b) for(int i = int(a); i < int(b); i++)
#define cc(x)	cout << #x << " = " << x << endl
#define ok		cout << "ok" << endl

typedef pair<int,int> ii;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

const long long N = 1e5 + 10; 
long long n, k, cost[N];
long long dp[N];

long long pog(long long at, long long n, long long k){
	if(at >= n) return 0;

	long long &r = dp[at];
	if(r != -1) return r;
	
	if(k == 1) r = pog(at+1, n, k) + abs(cost[at+1]-cost[at]);

	if(k != 1){
		long long L = pog(at+1, n, k) + abs(cost[at+1]-cost[at]);
		long long R = pog(at+2, n, k) + abs(cost[at+2]-cost[at]);

		r = min(L, R);

		for(int i = 3; i <= k; i++)
			r = min(r, pog(at+i, n, k) + abs(cost[at+i]-cost[at]));
	}	
	return r;
}

int main(){
	ios_base::sync_with_stdio(false);

	memset(dp, -1, sizeof dp);
	cin >>n >>k;

	for(int i = 1; i <= n; i++)
		cin >>cost[i];
	
	for(int i = 1; i <= k; i++)
		cost[n+i] = INF;

	cout <<pog(1, n, k) <<endl;
	return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    int n=s.size();
    vector<vector<ll>> dp(n+1,vector<ll>(4));
    dp[0][0]=1;
    rep(i,n){
        rep(j,4){
            if(s[i]=='?'){
                (dp[i+1][j]+=dp[i][j]*3)%=mod;
            }
            else{
                (dp[i+1][j]+=dp[i][j])%=mod;
            }
        }
        if(s[i]=='A'){
            (dp[i+1][1]+=dp[i][0])%=mod;
        }
        else if(s[i]=='B'){
            (dp[i+1][2]+=dp[i][1])%=mod;
        }
        else if(s[i]=='C'){
            (dp[i+1][3]+=dp[i][2])%=mod;
        }
        else{
            rep(j,3){
                (dp[i+1][j+1]+=dp[i][j])%=mod;
            }
        }
    }
    cout << dp[n][3] << endl;
}

Measured memory_bytes: 7376
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>()
        .chars()
        .map(|x| x.to_digit(10).unwrap() as i64)
        .collect::<Vec<_>>();

    let mut ans = 0;
    for i in 0..1 << s.len() - 1 {
        let mut coef = 1;
        for j in 0..s.len() {
            ans += coef * s[s.len() - 1 - j];
            if i >> j & 1 == 1 {
                coef = 1;
            } else {
                coef *= 10;
            }
        }
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define REP(i,n) for (int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define read(x) scanf("%d",&x)
ll n,x;

int main(){
	ios::sync_with_stdio(false);
	cin>>n>>x;
	ll ans=0;
	ans+=n;
	ll a=x,b=n-x;
	while(a!=b){
		if (a<b) swap(a,b);
		ll k=a/b;
		if (a%b==0) --k;
		ans+=b*2*k;
		a-=b*k;
	}
	ans+=a;
	cout<<ans<<endl;
	return 0; 
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;
ll n, a, c[2], s[2];
int main() {
  cin >> n;
  for (int i = 0; i != n; ++i) {
    cin >> a;
    for (int j : {0, 1}) {
      s[j] += a;
      auto p = 1 - (i + j) % 2 * 2;
      if (s[j] * p <= 0) {
        c[j] += abs(p - s[j]);
        s[j] = p;
      }
    }
  }
  cout << min(c[0], c[1]) << endl;
}


Measured memory_bytes: 3560
str = gets.split
M,D = str[0].to_i, str[1].to_i
answer = 0

for x in 1..M do
    for y in 22..D do
        a = y/10
        b = y%10
        if a >= 2 && b >= 2 && x == a*b
            answer += 1
        end
    end
end

puts answer

Measured memory_bytes: 1788
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::HashMap;
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::usize;

#[allow(unused_macros)]
macro_rules! read_cols {
    ($($t:ty),+) => {{
        let mut line = String::new();
        stdin().read_line(&mut line).unwrap();

        let mut it = line.trim()
            .split_whitespace();

        ($(
            it.next().unwrap().parse::<$t>().ok().unwrap()
        ),+)
    }}
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let (n, q) = read_cols!(i64, usize);

    let mut mx = vec![(n, n)];
    let mut my = vec![(n, n)];

    let white: i64 = (0..q)
        .map(|_| {
            let (t, x) = read_cols!(i64, i64);

            // eprintln!("{:?}", my);
            // eprintln!("{:?}", mx);

            if t == 1 {
                let r = my
                    .binary_search_by_key(&Reverse((x, 0)), |e| Reverse(*e))
                    .unwrap_err();
                let ty = my[r - 1].1;

                if (ty, x) < *mx.last().unwrap() {
                    mx.push((ty, x));
                }

                ty - 2
            } else {
                let r = mx
                    .binary_search_by_key(&Reverse((x, 0)), |e| Reverse(*e))
                    .unwrap_err();
                let tx = mx[r - 1].1;

                if (tx, x) < *my.last().unwrap() {
                    my.push((tx, x));
                }

                tx - 2
            }
        })
        .sum();

    println!("{}", (n - 2) * (n - 2) - white);
}


Measured memory_bytes: 5348
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>

using namespace std;

int find(vector <string>::iterator it, string s, int n);

int main() {
    string s;
    int n;
    map< string, priority_queue<int, vector<int>, greater<int> > > index;
    vector<string> word;

    while (1) {
        cin >> s;
        if(cin.eof()) break;
        cin >> n;

        index[s].push(n);
        if(find(word.begin(), s, word.size()) == -1) {
            word.push_back(s);
        }
    }

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

    vector <string>::iterator it = word.begin();
    while (it != word.end()) {
        cout << *it << endl;
        while (index[*it].size() > 1) {
            cout << index[*it].top() << " ";
            index[*it].pop();
        }
        cout << index[*it].top() << endl;
        it++;
    }

    return 0;
}

int find(vector <string>::iterator it, string s, int n) {
    for (int i=0; i<n; i++, it++) {
        if (*it == s) {
            return i;
        }
    }

    return -1;
}

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




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

    long long int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;


    string s1;
    cin>>n;

    m=n;
    while(n!=0)
    {
       if(n%26==0)
       {
           s1+='z';
           n/=26;
           n--;
       }
       else
       {
           s1+=(96+(n%26));
           n/=26;
       }

    }


    reverse(s1.begin(),s1.end());

    cout<<s1<<"\n";


    return 0;


}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define x first
#define y second
#define mod 1e9+7
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rof(i,a,b) for(ll i=a;i>b;i--)

ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}
//memset can initialize to 0 or -1 ONLY
// memset(a,0,sizeof(a[0][0])*n*n); //2D array
//memset(a, 0, sizeof(a));  //1D array
//memset(str, 't', sizeof(str)); // string
void solve()
{
    
    ll ans=0,x;cin>>x;
    ll a=x/500;
    ans+=a*1000;
    x=x-500*a;
    a=x/5;
ans+=a*5;
cout<<ans;
}


int main()
{

ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main()
{int n;
 cin >> n;
 vector<int> d(n);
 rep(i,n) cin >> d.at(i);
 
  sort(d.begin(),d.end());
  
  int ans = d.at(n/2) - d.at(n/2-1);
 
 cout << ans << endl;
  
  
  
  
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] v = new int[n];
        int[] c = new int[n];
        for(int i=0; i<n; i++) {
            v[i] = sc.nextInt();
        }
        for(int i=0; i<n; i++) {
            c[i] = sc.nextInt();
        }
        int res = 0;
        for(int i=0; i<n; i++) {
            if(v[i]-c[i] > 0) {
                res += v[i] - c[i];
            }
        }
        System.out.println(res);

    }

}


Measured memory_bytes: 21332
H, W = input().split()
H = int(H)
W = int(W)

mas = []

for i in range(H):
    a = input()
    if a == '.'*W:
        continue
    mas.append(a)

delFlg = False
delcache = []
for i in range(W):
    delFlg = True
    for x in mas:
        if x[i] != '.':
            delFlg = False
            break
    if delFlg:
        delcache.append(i)
delcache.sort(reverse=True)

for i in delcache:
    for j,x in enumerate(mas):
        mas[j] = x[0:i] + x[i+1:]

for x in mas:
    print(x)

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

#define PI 3.14159265359
double circumference(double r) 
{ 
    double cir = 2*PI*r; 
    return cir; 
}
int main()
{
    double r;
    cin>>r;
    cout<<circumference(r)<<endl;

}

Measured memory_bytes: 3804
<?php
fscanf(STDIN, "%d %d", $n, $m);
$height = explode(' ', trim(fgets(STDIN)));

$tower = array();
for ($i=1; $i <= count($height); $i++) {
  $tower[$i] = array();
}

for ($i=0; $i < $m; $i++) {
  fscanf(STDIN, "%d %d", $a, $b);
  $tower[$a][] = $height[$b-1];
  $tower[$b][] = $height[$a-1];
}

$cnt = 0;
foreach ($tower as $key => $value) {
  if (empty($value) || $height[$key-1] > max($value)) {
    $cnt++;
  }
}

echo $cnt;


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

using namespace std;

#define el				'\n'
#define sz(v)			((int)((v).size()))
#define all(v)          ((v).begin()),((v).end())
#define clr(v, d)		memset(v, d, sizeof(v))

double const EPS = 1e-8, PI = acos(-1);
const int N = 1e5 + 9, M = 50 + 9, OO = (int) 1e9 + 1;
const long long MOD = 1e9 + 7;

typedef long long ll;

void OUTPUT() {
	cout << fixed << setprecision(12);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

void INPUT() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(12);
//	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

int n, arr[N];
ll cnt;

int main() {
	OUTPUT();
//	INPUT();
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
	}
	bool can = 1;
	for (int i = n - 2; i >= 0; i--) {
		if (arr[i] > arr[i + 1]) {
			arr[i]--;
		}
		if (arr[i] > arr[i + 1]) {
			can = 0;
		}
	}
	cout << (can ? "Yes\n" : "No\n");

	return 0;

}


Measured memory_bytes: 640
abc = [chr(ord('a') + i) for i in range(26)] 
def n2a(n):
    if n <= 26:
        return abc[n - 1]
    elif n % 26 == 0:
        return n2a(n // 26 - 1) + abc[25]
    else:
        return n2a(n // 26) + abc[n % 26 - 1]

n = int(input())
print(n2a(n))

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 100100
const ll inf = (ll)1e10;
const ll mod = (ll)1e9+7;
ll dp[1010][1010];
int h, w;
char mat[1010][1010];
ll solve(int x, int y) {
	if ( x == h && y == w ) return 1;
	if ( x > h || y > w ) return 0;
	if ( dp[x][y] != -1 ) return dp[x][y];
	ll ret = 0;
	if ( mat[x+1][y] != '#' ) ret = (ret+solve(x+1,y))%mod;
	if ( mat[x][y+1] != '#' ) ret = (ret+solve(x,y+1))%mod;
	return dp[x][y] = (ret%mod);
}
int main()
{
	#ifdef __APPLE__
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> h >> w;
	for ( int i = 1; i <= h; i++ ) {
		for ( int j = 1; j <= w; j++ ) {
			cin >> mat[i][j];
		}
	}
	memset(dp,-1,sizeof(dp));
	cout << solve(1,1) << endl;
	return 0;
}




Measured memory_bytes: 9344
import sys
from pprint import *
N,K=map(int,input().split())
input=sys.stdin.readline
dpw=[[0 for _ in range(2*K+1)] for _ in range(2*K+1)]
dpb=[[0 for _ in range(2*K+1)] for _ in range(2*K+1)]
def getmatnum(x1,y1,x2,y2,mat):#左上を(x1,y1)右下を(x2,y2)にしてmatの中の左上~右下の領域の和をdpから算出
    if (x2==0)or(y2==0):
        return 0
    else:
        if (x1==-1):
            x1=0
        if (y1==-1):
            y1=0
        return mat[y2][x2]-mat[y1][x2]-mat[y2][x1]+mat[y1][x1]

for i in range(N):
    x,y,c=input().split()
    x=int(x)
    y=int(y)
    #print(x,y,c)
    if c=="W":
        dpw[(y%(2*K))+1][(x%(2*K))+1]=dpw[(y%(2*K))+1][(x%(2*K))+1]+1
    else:
        dpb[(y % (2*K))+1][(x % (2*K))+1] = dpb[(y % (2*K))+1][(x % (2*K))+1] + 1
#pprint(dpw)
#pprint(dpb)

for i in range(1,2*K+1):
    for j in range(1,2*K+1):
        dpb[i][j]=dpb[i][j-1]+dpb[i][j]

for i in range(1,2*K+1):
    for j in range(1,2*K+1):
        dpb[i][j]=dpb[i-1][j]+dpb[i][j]

for i in range(1,2*K+1):
    for j in range(1,2*K+1):
        dpw[i][j]=dpw[i][j-1]+dpw[i][j]

for i in range(1,2*K+1):
    for j in range(1,2*K+1):
        dpw[i][j]=dpw[i-1][j]+dpw[i][j]
ans=0
for i in range(K):
    for j in range(K):
        k=i+K
        l=j+K
        b1=getmatnum(-1,-1,i,j,dpb)+getmatnum(k,-1,2*K,j,dpb)+getmatnum(i,j,k,l,dpb)+getmatnum(-1,l,i,2*K,dpb)+getmatnum(k,l,2*K,2*K,dpb)
        w1=getmatnum(i,-1,k,j,dpw)+getmatnum(-1,j,i,l,dpw)+getmatnum(k,j,2*K,l,dpw)+getmatnum(i,l,k,2*K,dpw)
        b2=getmatnum(-1,-1,i,j,dpw)+getmatnum(k,-1,2*K,j,dpw)+getmatnum(i,j,k,l,dpw)+getmatnum(-1,l,i,2*K,dpw)+getmatnum(k,l,2*K,2*K,dpw)
        w2=getmatnum(i,-1,k,j,dpb)+getmatnum(-1,j,i,l,dpb)+getmatnum(k,j,2*K,l,dpb)+getmatnum(i,l,k,2*K,dpb)
        ans=max(ans,b1+w1,b2+w2)

        #print(i,j,k,l)
print(ans)
        #
#pprint(dpw)
#pprint(dpb)

Measured memory_bytes: 143128
n = int(input())
h = list(map(int, input().split()))
def water(l, r, sub):
    if l == r:
        return 0
    i = l + h[l:r].index(min(h[l:r]))
    a = water(l, i, h[i]) 
    b = water(i + 1, r, h[i])
    return h[i] - sub + a + b
print(water(0, n, 0))

Measured memory_bytes: 62940
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<long long, int> P;
int n;
vector<P> ai;
vector< vector< long long > > dp;

long long f(int i, int to){
    return ai[i].first * abs(ai[i].second-to);
}

int main(void){
    cin >> n;
    ai.push_back(P(1e18, 0));
    for(int i=1;i<=n;i++){
        int a;
        cin >> a;
        ai.push_back(P(a, i));
    }
    sort(ai.begin(), ai.end(), greater<P>());
    dp.assign(n+1, vector<long long>(n+1, -1e18));
    dp[0][0] = 0;
    for(int i=1;i<=n;i++){
        // cout << ai[i].first << " " << ai[i].second << endl;
        for(int j=0;j<=i;j++){
            dp[i][j] = dp[i-1][j] + f(i, n-i+j+1);
            if(j > 0){
                long long res = dp[i-1][j-1] + f(i, j);
                dp[i][j] = max(dp[i][j], res);
            }

            // cout << i << ", " << j << " : " << dp[i][j] << endl;
        }
    }
    long long ans = 0;
    for(int i=1;i<=n;i++){
        ans = max(ans, dp[n][i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 34476
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, ans = 0;
    cin >> n;
    int a[3] = {7, 5, 3};
    queue<int> q;
    q.push(0);
    while(!q.empty()){
        int now = q.front(); q.pop();
        rep(i, 0, 3){
            int nxt = now * 10 + a[i];
            if(nxt <= n){
                int c[10] = {};
                int tmp = nxt;
                while(tmp){
                    c[tmp % 10]++;
                    tmp /= 10;
                }
                bool f = true;
                rep(j, 0, 3) f &= (c[a[j]] != 0);
                q.push(nxt);
                if(f) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#define rep(i,s,n) for(int i=s;i<n;i++)
using namespace std;
int n;
int t[100][100];
int h[5100][8],w;
int dp[100][5100];

void Nh(int n){
	w=0;
	int c[7]={0},i;
	while(true){
		c[0]++,i=0;
		while(true){
			if(c[i]==n){if(i==n-1)goto loop;c[i+1]++,c[i]=0;}
			else break;
			i++;
		}
		bool ok=true;
		rep(f,0,n-1)rep(g,f+1,n)if(c[f]==c[g])ok=false;
		if(ok){rep(k,0,n)h[w][k]=c[k];w++;}
	}
	loop:;
	return;
}

int main(){
	cin>>n;
	rep(i,0,n)rep(j,0,n)t[i][j]=0;
	int a;
	rep(i,0,n){cin>>a;rep(j,max(0,i-a),min(a+i+1,n))t[i][j]=1;}
	rep(i,0,n){cin>>a;rep(j,0,100)t[i][j]*=a;}
	Nh(min(n,7));
	rep(i,0,n)rep(j,0,w)dp[i][j]=0;
	int ans=0;
	rep(i,0,w){
		int cnt=0;
		rep(f,0,min(n,7))rep(g,0,min(n,7))if(h[i][f]>h[i][g])cnt+=t[g][f];
		dp[6][i]=cnt,ans=max(ans,cnt);
	}
	rep(r,7,n){
		rep(i,0,w){
			rep(j,0,8){
				int cnt=0,c[7];
				rep(k,0,7){
					c[k]=h[i][k];
					if(h[i][k]<j)cnt+=t[r-7+k][r];
					else cnt+=t[r][r-7+k],c[k]++;
					if(k>0){
						if(h[i][k]>h[i][0])c[k]--;
						c[k-1]=c[k];
					}
				}
				c[6]=j;
				if(h[i][0]<j)c[6]--;
				int left=0,right=w,mid;
				while(true){
					if(left>=right-1)break;
					mid=(left+right)/2;
					int sam=0;
					rep(k,0,7){
						if(h[mid][6-k]<c[6-k]){sam=1;break;}
						if(h[mid][6-k]>c[6-k]){sam=-1;break;}
					}
					if(sam==0)break;
					if(sam==1)left=mid;
					else right=mid;
				}
				dp[r][mid]=max(dp[r][mid],dp[r-1][i]+cnt);
			}
		}
	}
	rep(i,0,w)ans=max(ans,dp[n-1][i]);
	cout<<ans<<endl;
	return 0;
}

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

int N, M;

vector<int> end1[305], end2[305], end3[305];

ll dp[305][305][305];
bool seen[305][305][305]; 

ll f(int n, int a, int b) {
    if (n == N+1) return 1;
    if (seen[n][a][b]) return dp[n][a][b];
    seen[n][a][b] = 1;
    bool agood = 1, bgood = 1, cgood = 1;
    for (int s : end1[n]) {
        if (s <= b) return 0;
        if (s < n) agood = bgood = 0;
    }
    for (int s : end2[n]) {
        if (s <= a || s == n) return 0;
        if (s <= b) agood = 0;
        else if (s < n) cgood = 0;
    }
     for (int s : end3[n]) {
         if (s > b) return 0;
         if (s > a) bgood = cgood = 0;
     }
     if (agood) dp[n][a][b] += f(n+1,b,n-1);
     if (bgood) dp[n][a][b] += f(n+1,a,n-1);
     if (cgood) dp[n][a][b] += f(n+1,a,b);
     dp[n][a][b] %= 1000000007;
     return dp[n][a][b];
}

int main() {
    scanf("%d %d", &N, &M);
    for (int i = 0, l, r, x; i < M; i++) {
        scanf("%d %d %d", &l, &r, &x);
        if (x == 1) end1[r].push_back(l);
        if (x == 2) end2[r].push_back(l);
        if (x == 3) end3[r].push_back(l);
    }
    printf("%lld\n", f(1,0,0));
}

Measured memory_bytes: 246272
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final long INF = Long.MAX_VALUE;

    Main() {
        Scanner sc = new Scanner(System.in);
        long ans = 0;
        int N = sc.nextInt();
        int M = sc.nextInt();
        long K = sc.nextLong();
        long[] A = new long[N];
        long[] B = new long[M];
        long[] Aa = new long[N + 2];
        long[] Bb = new long[M + 2];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextLong();
        }
        for (int i = 0; i < M; i++) {
            B[i] = sc.nextLong();
        }
        
        for (int i = 1; i <= N; i++) {
            Aa[i] = Aa[i - 1] + A[i - 1];
        }
        Aa[N + 1] = INF;

        for (int i = 1; i <= M; i++) {
            Bb[i] = Bb[i - 1] + B[i - 1];
        }
        Bb[M + 1] = INF;

        int acs = binarySearch(0, N + 2, Aa, K);
        // if (ac == N + 1)
        //     ac = N;
        // ans = Math.max(ans, ac + 1);
        for (int i = 0; i <= acs; i++) {
            int ac = acs - i;
            long asum = Aa[ac];
            long rem = K - asum;
            int bc = binarySearch(0, M + 2, Bb, rem);
            // if (bc == M + 1)
            //     bc = M;
            // System.err.println(ac+"  "+bc);
            ans = Math.max(ans, ac + bc);
        }
        System.out.println(ans);
    }

    static boolean isOK(int index, long[] C, long key) {
        // if (A[index] < key)
        if (C[index] <= key)
            return false;
        else
            return true;
    }

    static int binarySearch(int min, int max, long[] C, long key) {
        int ng = min - 1, ok = max;
        while (ok - ng > 1) {
            int mid = ng + (ok - ng) / 2;
            if (isOK(mid, C, key))
                ok = mid;
            else
                ng = mid;
        }
        // if (ok == max)
        // return -1;
        // throw new Error("all false");
        return ng;
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 65740
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

val br = BufferedReader(InputStreamReader(System.`in`))
val pw = PrintWriter(System.out)
fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    // 回答をここに書く
    val s = next()
    println(s.replace("2017", "2018"))
}

// 入力取得
fun next() = br.readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

// 約数のList
fun divisor(value : Long) : List<Long> {
    val max = Math.sqrt(value.toDouble()).toLong()
    return (1..max)
            .filter { value % it == 0L }
            .map { listOf(it, value / it) }
            .flatten()
            .sorted()
}

// 範囲内の素数を取得
// fromだけ指定すると戻り値の個数で素数判定ができる
fun prime(from : Long, to : Long = from) : List<Long> {
    return (from..to).filter { i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all { j ->  i % j != 0L }
    }
}

// 素因数分解
fun decom(value : Long) : List<Long>{
    if (value == 1L) return listOf(1)
    val max = Math.sqrt(value.toDouble()).toLong()
    return prime(2, max).filter { value % it == 0L }
}

// 最大公約数
fun gcd(a : Long, b : Long) : Long {
    return if (a % b == 0L) b else gcd(b, a % b)
}

// 文字列を入れ替え
fun swap(base : String, a : String, b : String) : String {
    return base.map {
        when (it) {
            a.toCharArray()[0] -> b
            b.toCharArray()[0] -> a
            else -> it.toString()
        }
    }.joinToString()
}

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 35836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    int ans;
    if(n&1) {
        ans = b[n/2]-a[n/2]+1;
    }else {
        int midA = a[n/2-1] + a[n/2];
        int midB = b[n/2-1] + b[n/2];
        ans = midB- midA + 1;
    }
    cout << ans << endl;

}

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

int main(){
	int n, y;
	cin >> n >> y;

	for (int i = 0;i <= n;i++) {
		for (int j = 0;j <= n - i;j++) {
			int k = n - i - j;
			if (k >= 0 && 10000 * i + j * 5000 + k * 1000 == y) {
				cout << i << ' ' << j << ' ' << k << endl;
				return 0;
			}
		}
	}

	cout << "-1 -1 -1" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int divisor[1000000+10];
void maked(int n){divisor[0]=-1;divisor[1]=1;ll i=2;for(;i*i<=n;i++)if(!divisor[i]){divisor[i]=i;for(ll j=i*i;j<=n;j+=i)if(!divisor[j])divisor[j]=i;}for(;i<=n;i++)if(!divisor[i])divisor[i]=i;}
int divv(ll n,ll*a){//約数（div使用）
	ll cnt=1;a[0]=1;
	while(n!=1){ll num=1,i=divisor[n],temp=i;while(n%i==0){n/=i;num++;}rep(k,1,num){rep(j,0,cnt)a[k*cnt+j]=a[j]*temp;temp*=i;}cnt*=num;}
	//sortup(a,cnt);
	return cnt;
}

int n;
int a[200010];
int aa[1000010];
ll yakusuu[1000];
int main(){
	maked(1000000+5);
	scanf("%d",&n);
	rep(i,0,n)scanf("%d",a+i);
	rep(i,0,n)aa[a[i]]++;

	int ans=0;
	rep(i,0,n){
		int cnt=divv(a[i],yakusuu);
		int flag=aa[a[i]]==1;
		rep(j,0,cnt)if(yakusuu[j]!=a[i])flag&=aa[yakusuu[j]]==0;
		if(flag)ans++;
	}
	
	printf("%d",ans);
}

Measured memory_bytes: 10264
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

cat pw(cat a, cat e, cat mod) {
	if(e <= 0) return 1;
	cat x = pw(a, e/2, mod);
	x = x * x % mod;
	if(e&1) x = x * a % mod;
	return x;
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cat A, B, K, mod = 998244353, ans = 0;
	cin >> N >> A >> B >> K;
	vector<cat> fac(N+1, 1), inv(N+1, 1);
	for(int i = 1; i <= N; i++) fac[i] = (i * fac[i-1]) % mod;
	for(int i = 1; i <= N; i++) inv[i] = pw(fac[i], mod-2, mod);
	for(int x = 0; x <= N; x++) {
		// x*A+y*B == N
		if(x*A > K || (K-x*A)%B != 0) continue;
		int y = (K-x*A)/B;
		if(y > N) continue;
		cat Cx = fac[N] * inv[x] % mod * inv[N-x] % mod;
		cat Cy = fac[N] * inv[y] % mod * inv[N-y] % mod;
		ans += Cx * Cy % mod;
	}
	ans %= mod;
	if(ans < 0) ans += mod;
	cout << ans << "\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 4992
#include<stdio.h>

int main(){
  int n = 0, i, total = 0, ave = 0, a = 0;
  scanf("%d",&n);
  int x[n];
  for(i=0;i<n;i++){ scanf("%d",&x[i]); ave+=x[i];} 
  if(ave%n > n/2){ a++; }
  ave = ave/n +a;
  for(i=0;i<n;i++){ total += (x[i]-ave)*(x[i]-ave); } 
  printf("%d",total);
  return 0;
}

Measured memory_bytes: 128
//hail to jwalaji
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main(){
lli n;
cin>>n;
vector<lli> h(n),cost(n,1e5);
for(lli i=0;i<n;i++){
    cin>>h[i];
}
cost[0]=0;
cost[1]=abs(h[1]-h[0]);
for(lli i=2;i<n;i++){
    cost[i]=min((cost[i-1]+(abs(h[i]-h[i-1]))),(cost[i-2]+(abs(h[i]-h[i-2]))));
}
cout<<cost[n-1]<<endl;
return 0;
}


Measured memory_bytes: 4840
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

int main(){
  int n; cin >> n;
  vector<pair<int,int>> red(n),blue(n);
  vector<bool> use(n,true);
  rep(i,n){
    int x,y; cin >> x >> y;
    red[i] = {y,x};
  }
  rep(i,n){
    int x,y; cin >> x >> y;
    blue[i] = {x,y}; //逆にしているの注意
  }
  sort(red.begin(),red.end(),greater<pair<int,int>>());
  sort(blue.begin(),blue.end());
  int cnt = 0;
  rep(i,n){
    int bx = blue[i].first; int by = blue[i].second;
    rep(j,n){
      if(!use[j]) continue;
      int rx = red[j].second; int ry = red[j].first;
      if(rx >= bx) continue;
      if(ry < by){
        cnt++;
        use[j] = false;
        break;
      }
    }
  }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_lim=(n); i<i##_lim; ++i)
#define FOR(i, a, b) for (int i=(a), i##_lim=(b); i<i##_lim; ++i)
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<int, int>;

int main()
{
    int N, M;
    cin >> N >> M;
    int A[N], B[M], C[M];
    REP(i, N) cin >> A[i];
    REP(i, M) cin >> B[i] >> C[i];

    map<int, ll> m;
    REP(i, N) ++m[A[i]];
    REP(i, M) m[C[i]] += B[i];

    ll ret = 0;
    ll n = N;

    auto it = m.rbegin();
    for (; it != m.rend() && n > 0; ++it)
    {
        ll m = min(n, it->second);
        ret += it->first*m;
        n -= m;
    }

    cout << ret << endl;
    return 0;
}

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

map<string,int> idx;
int p;

int calc(string s){
	int res=0;
	while(p<s.size()){
		if(s[p]==')'){p++; break;}
		int weight=0;
		string f;
		if(isupper(s[p])){
			f+=s[p];p++;
			if(p<s.size() && islower(s[p])){
				f+=s[p]; p++;
			}
			if(!idx.count(f)) return -1;
			weight=idx[f];
		}
		else if(s[p]=='('){
			p++;
			weight=calc(s);
			if(weight<0) return -1;
		}
		int mul=0;
		while(p<s.size() && isdigit(s[p])){
			mul*=10;
			mul+=s[p]-'0';
			p++;
		}
		if(mul==0) mul=1;
		res+=weight*mul;
	}
	return res;
}

int main()
{
	string s;
	while(cin>>s){
		if(s.size()>=3) break;
		int w; cin>>w;
		idx[s]=w;
	}
	while(cin>>s){
		if(s=="0") break;
		p=0;
		int ans=calc(s);
		if(ans<0) cout<<"UNKNOWN"<<endl;
		else cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int isprime(int n){
	int i;
	for(i=2;i*i <= n;i++){
		if(n%i==0)return 0;
	}
	return 1;
}
int main(){
	int n, i, k, one=0;
	int sosu[10000];
	for(i=0;i<10000;i++){
		if(isprime(i)==1){
			sosu[i]=i;
		}else{
			sosu[i]=0;
		}
	}
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=n;i>0 && one==0;i--){
			if(sosu[i]!=0 && sosu[i-2]!= 0){
				printf("%d %d\n",sosu[i-2],sosu[i]);
				one=1;
			}
		}
		one=0;
	}	
	return 0;
}

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

const int N = 1e5 + 10;
int n, ans, ar[N];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> ar[i];
	
	for (int i = 1; i <= n; i++)
		if (ar[i] == i) {
			swap(ar[i], ar[i + 1]);
			ans++;
		}
	cout << ans;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define int long long
#define eps (1e-7)
#define inf (1e9)
#define md (1000000007)
#define MAX 301
double dp[MAX][MAX][MAX];
double rec(int i,int j,int k,int n){
    if(dp[i][j][k]>=0)
        return dp[i][j][k];
    if(i==0&&j==0&&k==0)
        return 0.0;
    double res=(double)n;
    if(i>0)
        res+=rec(i-1,j,k,n)*i;
    if(j>0)
        res+=rec(i+1,j-1,k,n)*j;
    if (k>0)
        res+=rec(i,j+1,k-1,n)*k;
    res*=1.0/(i+j+k);
    return dp[i][j][k]=res;
}
signed main() {
    fast_io
    int t,n,c[4]={0,0,0,0};
    cin>>n;
    for(int i=0;i<n;i++) {
        cin>>t;c[t]++;
    }
    memset(dp,-1,sizeof(dp));
    cout<<fixed<<setprecision(10)<<rec(c[1],c[2],c[3],n)<<endl;
    return 0;
}


Measured memory_bytes: 216780
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int a;
string s;

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

  if (a >= 3200) {
    cout << s << endl;
  } else {
    cout << "red" << 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 n[]=new int[a+1];
int m[]=new int[a+1];
for(int i=0;i<a;i++)
  n[i+1]=sc.nextInt()+n[i];
  for(int i=0;i<a;i++)
  m[i+1]=sc.nextInt()+m[i];

  int ans=0;
for(int i=0;i<a;i++){
ans=Math.max(ans,n[i+1]+m[a]-m[i]);}
System.out.println(ans);
}
}

Measured memory_bytes: 23252
h, w = map(int, input().split())
grid = [str(input()) for _ in range(h)]
dp = [[0] * 1050 for _ in range(1050)]
MOD = int(1e9+7)
dp[0][0] = 1
for i in range(h):
    for j in range(w):
        dp[i][j] %= MOD
        if i + 1 < h and grid[i+1][j] == '.':
            dp[i+1][j] += dp[i][j]
        if j + 1 < w and grid[i][j+1] == '.':
            dp[i][j+1] += dp[i][j]
print(dp[h-1][w-1])

Measured memory_bytes: 50356
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n,m;
    int count = 1;
    int ans = 0;
    cin >> n;
    vector<string> s(n);
    for(int i=0;i<n;i++){
        cin >> s[i];
    }
    cin >> m;
    vector<string> t(m);
    for(int i=0;i<m;i++){
        cin >> t[i];
    }
    sort(s.begin(),s.end());
    for(int i=0;i<n;i++){
        if(i==n-1){
            for(int j=0;j<m;j++){
                if(t[j]==s[i]){
                    count--;
                }
            }
            if(ans<count){
                ans = count;
            }
        }
        else if(s[i]==s[i+1]){
            count++;
        }else{
            for(int j=0;j<m;j++){
                if(t[j]==s[i]){
                    count--;
                }
            }
            if(count>ans){
                ans = count;
            }
            count=1;
        }
    }
    if(ans <0){
        ans = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
S = [""] * N
T = [""] * N
Alltime = 0
for i in range(N):
    S[i], T[i] = input().split()
    T[i] = int(T[i])
    Alltime += T[i]
X = (input())
Waketime = 0
for i in range(N):
    Waketime += T[i]
    if S[i] == X:
        break
print(Alltime - Waketime)


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

signed main () {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    map < char, char > assigned;
    bool fucked = 0;
    for (int i = 0; i < n; ++i) {
        if (assigned.find(s[i]) == assigned.end())
            assigned[s[i]] = t[i];
        else if (assigned[s[i]] != t[i])
            fucked = 1;
    }
    assigned.clear();
    for (int i = 0; i < n; ++i) {
        if (assigned.find(t[i]) == assigned.end())
            assigned[t[i]] = s[i];
        else if (assigned[t[i]] != s[i])
            fucked = 1;
    }
    if (!fucked)
        cout << "Yes\n";
    else
        cout << "No\n";
}


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

int main()
{
    int height, First,Second,Third,index;
    First = Second = Third = 0;

    for(index=0; index<10; index++)
   {
      cin >> height;

      if(height > First)
      {
           Third = Second;
           Second = First;
           First = height;
      }
      else if(height > Second && height <= First)
      {
          Third = Second;
          Second = height;
      }
      else if(height > Third && height <= Second)
          Third = height;
    }


    cout << First << endl << Second << endl << Third << endl;

    return 0;
}
 

Measured memory_bytes: 3080
import sys
sys.setrecursionlimit(2147483647) 
S=str(input())
s=list(S)
x1=0
x2=1
y=0
len=len(s)-1
for i in range(len):
  if s[i+1]==s[i]:
    x2=x2+1
  else:
    if i==0:
      x2=0
    if s[i]=='>':
      if x2<x1:
        x2=x2-1
      else:
          x1=x1-1
    y+=x1*(x1+1)/2
    x1=x2
    x2=1
if s[len]=='>':
  if x2<x1:
    x2=x2-1
  else:
    x1=x1-1
y+=x1*(x1+1)/2
y+=x2*(x2+1)/2
print(int(y))

Measured memory_bytes: 7836
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t
#include <math.h>

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define BUF_SIZE 20

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

uint64_t get_int(void) {
  uint64_t num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%llu", &num);
#else
#error
#endif
  return num;
}

int main(void) {
    uint64_t num = get_int();
    uint64_t num_2 = sqrt(0.5 + num);
    uint64_t i;
    for(i = num_2; i >= 1; i--) {
        if(num%i) continue;
        printf("%llu\n", i + (num/i) - 2);
        return 0;
    }
    return 0;
}

Measured memory_bytes: 384
parseline(str=readline()) = parse.(Int, split(str))
function BannedK()
    N = parse(Int, readline())
    A = parseline()
    nums = zeros(Int, N)
    ans = zeros(Int, N)
    for a in A
        nums[a] += 1
    end
    for a in A
        ans[nums[a]]>0 && (println(ans[nums[a]]); continue)
        nums[a] -= 1
        temp = sum(max(0, div(m*(m-1), 2)) for m in nums)
        println(temp)
        nums[a] += 1
        ans[nums[a]] = temp
    end
end
BannedK()

Measured memory_bytes: 214228
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX
#define eps LDBL_EPSILON
#define moder 1000000007
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
string s;
stack<char> st;
signed main(){
	cin>>s;
	rep(i,s.size()){
		if(!st.empty()&&st.top()!=s[i])st.pop();
		else st.push(s[i]);
	}
	cout<<s.size()-st.size()<<endl;
	return 0;
}

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

int main() {
   int a;
   cin>>a;
   int sum=0;
   vector<int> s(a);
  
   for(int i=0;i<a;i++){
    cin>>s.at(i);
    sum+=s.at(i);
    }
    sum/=a;
    
    int ans1=0;
    int ans2=0;
    for(int i=0;i<a;i++){
        ans1+=(s.at(i)-sum)*(s.at(i)-sum);
        ans2+=(s.at(i)-sum-1)*(s.at(i)-sum-1);
    }
    cout<<min(ans1,ans2);
    }  
    

Measured memory_bytes: 256
A=[]
cnt=0
for i in range(3):
  A.append(list(map(int,input().split())))
n=int(input())
for i in range(n):
  s=int(input())
  for k in range(3):
    if s in A[k]:
      A[k][A[k].index(s)]="○"
for l in range(3):
  if A[l][0]=="○"and A[l][1]=="○"and A[l][2]=="○":
    cnt+=1
  elif A[0][l]=="○" and A[1][l]=="○"and A[2][l]=="○":
    cnt+=1
  elif A[0][0]=="○"and A[1][1]=="○"and A[2][2]=="○":
    cnt+=1
  elif A[0][2]=="○"and A[1][1]=="○"and A[2][0]=="○":
    cnt+=1

 # print(A)
if cnt>=1:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3064
#include<stdio.h>


int main(){
	int n;
	bool data[1000000];

	int i,j;
	data[0]=data[1]=0;
	for(i=2;i<1000000;i++){
		data[i]=1;
	}

	for(i=0;i<1000000;i++){
		if(data[i]==1){
			for(j=i+i;j<1000000;j=j+i){
				data[j]=0;
			}
		}
	}


	while(scanf("%d",&n)!=EOF){
		j=0;
		for(i=0;i<n+1;i++){
			if(data[i]==1)j++;
		}
		printf("%d\n",j);
	
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int H, W;
  cin >> H >> W;
  string S[H];
  for(int i=0; i<H; i++) cin >> S[i];
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(S[i][j] == '#') continue;
      int q = 0;
      if(i-1 >= 0){
        if((j-1 >= 0) && (S[i-1][j-1] == '#')) q++;
        if(S[i-1][j] == '#') q++;
        if((j+1 < W) && (S[i-1][j+1] == '#')) q++;
      }
      if(i+1 < H){
        if((j-1 >= 0) && (S[i+1][j-1] == '#')) q++;
        if(S[i+1][j] == '#') q++;
        if((j+1 < W) && (S[i+1][j+1] == '#')) q++;        
      }
      if((j-1 >= 0) && (S[i][j-1] == '#')) q++;
      if((j+1 < W) && (S[i][j+1] == '#')) q++;                        
      
      S[i][j]  = (char) (q + '0');
    }
  }
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cout << S[i][j];
//      if(j != W-1) cout << " ";
    }
    cout << endl;
  }
  return 0;
}

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

int main(){
 int h,w;
 cin >> h >> w;
 string C[50];
 for(int i = 0; i < h; i++) cin >> C[i];
 
 const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
 const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
 
 for(int i = 0; i < h; i++){
  for(int j = 0; j < w; j++){
  if(C[i][j] == '#') continue;
   int num = 0;
   for(int d = 0; d < 8; d++){
   const int ni = i + dy[d];
   const int nj = j + dx[d];
   
   if(ni < 0 or h <= ni) continue;
   if(nj < 0 or w <= nj) continue;
   if(C[ni][nj] == '#') num++;
   }
   C[i][j] = char(num + '0');
  }
 }
 for(int i = 0; i < h; i++) cout << C[i] << endl;
 return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=5069,M=269;
typedef long long lint;
template<typename TP>
inline void read(TP &kk)
{
	TP ret=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){ret=ret*10+ch-'0';ch=getchar();}
	kk=ret*f;
}
int n,m;
lint dis[N];
int b[N][M];
lint pat[N][N];
int st[N],tp;
int l[N],r[N];

lint ans;
int main()
{
	read(n),read(m);
	for(int i=2;i<=n;i++) read(dis[i]);
	for(int i=2;i<=n;i++) dis[i]+=dis[i-1];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			read(b[i][j]);
	for(int p=1;p<=m;p++)
	{
		// printf("p=%d:\n",p);
		for(int i=1;i<=n;i++)
		{
			while(tp&&b[st[tp]][p]<b[i][p]) r[st[tp--]]=i-1;
			st[++tp]=i;
		}
		while(tp) r[st[tp--]]=n;
		for(int i=n;i;i--)
		{
			while(tp&&b[st[tp]][p]<=b[i][p]) l[st[tp--]]=i+1;
			st[++tp]=i;
		}
		while(tp) l[st[tp--]]=1;
		for(int i=1;i<=n;i++)
		{
			int x1=l[i],y1=i,x2=i,y2=r[i];
			pat[x1][y1]+=b[i][p];
			pat[x1][y2+1]-=b[i][p];
			pat[x2+1][y1]-=b[i][p];
			pat[x2+1][y2+1]+=b[i][p];
		}
		// for(int i=1;i<=n;i++)
		// printf("    %d:l=%d,r=%d\n",i,l[i],r[i]);
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			pat[i][j]+=pat[i-1][j]+pat[i][j-1]-pat[i-1][j-1];
		}
	}
	/*for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			printf("%lld ",pat[i][j]);
		}
		putchar('\n');
	}*/
	for(int i=1;i<=n;i++)
	{
		for(int j=i;j<=n;j++)
		{
			ans=max(ans,pat[i][j]-(dis[j]-dis[i]));
		}
	}
	/*for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++) pat[i][j]+=pat[i][j-1];
		for(int j=1;j<=n;j++) pat[i][j]+=pat[i-1][j];
		for(int j=i;j<=n;j++) ans=max(ans,pat[i][j]-(dis[j]-dis[i]));
	}*/
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 204160