akhauriyash/Code-Regression huggingface dataset:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

class Dinic:
    def __init__(self, v, inf=10**10):
        self.v = v
        self.inf = inf
        self.G = [[] for _ in range(v)]
        self.level = [-1]*v  # 深さ
        self.ite = [0]*v  # DFSでの探索が済んでいるか
    def add_edge(self, fr, to, cap):
        self.G[fr].append([to, cap, len(self.G[to])])
        self.G[to].append([fr, 0, len(self.G[fr])-1])
    def bfs(self, s):  # BFSで深さ決定,sがstart
        self.level = [-1]*self.v  # 必要
        self.level[s] = 0
        Q = deque()
        Q.append(s)
        while Q:
            v = Q.popleft()
            for i in range(len(self.G[v])):
                e = self.G[v][i]
                if e[1]>0 and self.level[e[0]]<0: ###capacity>0かつtoの深さ未定
                    self.level[e[0]] = self.level[v]+1
                    Q.append(e[0])
    def dfs(self, v, t, f):  # DFSで増加パス探索,v開始、t終点、総フローf
        if v==t:
            return f
        for i in range(self.ite[v],len(self.G[v])):
            self.ite[v] = i
            e = self.G[v][i]
            if e[1]>0 and self.level[v]<self.level[e[0]]:
                d = self.dfs(e[0], t, min(f, e[1]))
                if d>0:
                    e[1] -= d  # cap減少
                    self.G[e[0]][e[2]][1] += d  # 逆辺のcap増加
                    return d
        return 0
    def max_flow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            if self.level[t]<0:
                return flow
            self.ite = [0]*self.v  # DFSでの探索が済んでいるか否か
            f = self.dfs(s,t,self.inf)
            while f>0:
                flow += f
                f = self.dfs(s,t,self.inf)

X, Y, E = MAP()
D = Dinic(X+Y+2)
s = X+Y
t = X+Y+1

for i in range(X):
	D.add_edge(s, i, 1)

for i in range(Y):
	D.add_edge(X+i, t, 1)

for _ in range(E):
	x, y = MAP()
	D.add_edge(x, X+y, 1)

print(D.max_flow(s, t))



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

using namespace std;

vector<int> dp;
vector<vector<int> > G;

int dfs(int v) {
	if (dp[v] != -1) return dp[v];
	int d = 0;
	for (int e : G[v])
		d = max(d, dfs(e) + 1);
	return dp[v] = d;
}

int main() {
	int N, M; cin >> N >> M;
	G.assign(N, vector<int>());
	dp.assign(N, -1);
	for (int i = 0; i < M; ++i) {
		int x, y; cin >> x >> y;
		G[x - 1].push_back(y - 1);
	}
	int ans = 0;
	for (int i = 0; i < N; ++i) ans = max(ans, dfs(i));
	cout << ans << endl;

	return 0;
}

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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  VLL p(a), q(b), r(c);
  rep(i, a) cin >> p[i];
  rep(i, b) cin >> q[i];
  rep(i, c) cin >> r[i];

  // if(a < x) {
  //   p.push_back(rque.top());
  //   rque.pop();
  // }
  // if(b < y){
  //   q.push_back(rque.top());
  //   rque.pop();
  // }
  sort(all(p));
  sort(all(q));
  sort(all(r));
  reverse(all(p));
  reverse(all(q));
  reverse(all(r));
  priority_queue<ll, VLL, greater<>> ans;
  rep(i, x) { ans.push(p[i]); }
  rep(i, y) ans.push(q[i]);

  rep(i, c) {
    if(ans.top() < r[i]) {
      ans.pop();
      ans.push(r[i]);
    } else
      break;
  }
  ll aa = 0;
  while(not ans.empty()) {
    aa += ans.top();
    ans.pop();
  }
  cout << aa << endl;
  return 0;
}


Measured memory_bytes: 4852
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

    int n, m; cin>>n>>m;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    int asum = accumulate(all(a), 0);

    int cnt = 0;
    for(int i=0; i<n; i++){
        if(!(asum > a[i] * 4 * m)) cnt++;
    }

    cout << (cnt >= m ? "Yes" : "No") << endl;

    return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string s; cin >> s;
  string m = s.substr(5, 2), d = s.substr(8, 2);

  if(m < "04" || (m == "04" && d <= "30")) {
    cout << "Heisei" << endl;
  } else {
    cout << "TBD" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << endl
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rrep(i,n) for(int i=(n); (i)>=0; --(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
#define maxemt(v) *max_element(v.begin(), v.end())
#define minemt(v) *min_element(v.begin(), v.end())
#define lb(v,x) v[lower_bound(v.begin(), v.end(), x) - v.begin()]
#define ub(v,x) v[upper_bound(v.begin(), v.end(), x) - v.begin()]
template<class T> inline bool print(T& x){ cout << x << endl; return true; }
template<class T> inline bool print_(T& x){ cout << x << " "; return true; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
ll lcm(ll x, ll y){
  return x / gcd(x,y) * y;
}
const int INF = 1e9;
const ll llINF = 1LL<<60;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main(){
  int n; cin >> n;
  vector<int> a(n), v(n+1,0);
  rep(i,n){
    cin >> a[i];
    if(a[i]>n) v[n]++;
    else v[a[i]-1]++;
  }
  int ans=0;
  ans += v[n];
  rep(i,n){
    if(v[i] > i+1) ans += v[i] - (i+1);
    else if(v[i] < i+1) ans += v[i];
  }
  
  cout << ans; 

return 0;
}

Measured memory_bytes: 1024
def main():

    from collections import deque


    N = int(input())
    B = []
    L = []
    for i in range(N-1):
        ta,tb = map(int,input().split())
        B.append(ta)
        B.append(tb)
        L.append([ta,tb])
    B =B[1::2]
    E = [[] for _ in range(N + 1)]
    for a, b in L:
        E[a].append(b)

    Q = deque([1])
    C = [0] * (N + 1)
    while Q:
        v = Q.popleft()
        c = 0
        for u in E[v]:
            c += 1 + (c + 1 == C[v])
            C[u] = c
            Q.append(u)

    print(max(C))
    print("\n".join(str(C[b]) for b in B))
main()

Measured memory_bytes: 37580
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;

long long n;
int cnt;
bool ok(long long a) {
    string s = to_string(a);
    int cnt[10] = {};
    for (char c : s) {
        cnt[c - '0']++;
    }
    return cnt[3] && cnt[5] && cnt[7];
}

void dfs(long long a) {
    if (a <= n) {
        if (ok(a)) cnt++;
        dfs(10 * a + 3);
        dfs(10 * a + 5);
        dfs(10 * a + 7);
    }
}

int main() {
    cin >> n;
    dfs(0);
    cout << cnt;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 200001;
int n, x[maxn], y[maxn], a[maxn], b[maxn];
int main() {
	cin >> n;
	for(int i = 1; i <= n; ++ i) {
		cin >> x[i] >> y[i];
		a[i] = x[i] + y[i], b[i] = y[i] - x[i];
	}
	sort(a + 1, a + n + 1);
	sort(b + 1, b + n + 1);
	cout << max(a[n] - a[1], b[n] - b[1]);
	return 0;
}


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

ab=[list(map(int,input().split())) for i in range(n)]

c=[]
ans=0
if ab[n-1][0]%ab[n-1][1]!=0:   
    ans+=ab[n-1][1]-(ab[n-1][0]%ab[n-1][1])
#print(ab[n-1][0],ab[n-1][1],ans)
for i in range(n-2,-1,-1):
    ab[i][0]+=ans
    if ab[i][0]%ab[i][1]!=0:
        
        ans+=ab[i][1]-(ab[i][0]%ab[i][1])
    #print(ab[i][0],ab[i][1],ans)
print(ans)

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

int main() {
    int N;
    cin >> N;
    int ans = 0;
    for (int i=0; i<100; i++) {
        ans+=1000;
        if (ans>=N) {
            cout << ans-N;
            return 0;
        }
    }
}

Measured memory_bytes: 3624
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */

public class Main {
    public static void main(String[] args) {
        InputStream    inputStream    = System.in;
        OutputStream outputStream = System.out;
        InputReader    in                      = new InputReader(inputStream);
        PrintWriter      out                    = new PrintWriter(outputStream);
        Task                 solver               = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
    	public void solve(int testNumber, InputReader in, PrintWriter out) {
    		int N = in.nextInt();
    		if(N % 2 != 0) {
    			N = 2 * N;
    		}
    		out.println(N);
    	}
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



Measured memory_bytes: 21460
use std::io::BufRead;

fn main() {
  let stdin = std::io::stdin();
  let mut buf = String::new();
  stdin.read_line(&mut buf).unwrap();

  let word = buf.trim();

  let mut cnt = 0;

  for line in stdin.lock().lines() {
    let line = line.unwrap();
    let line = line.trim();

    if line == "END_OF_TEXT" {
      break;
    }

    cnt += line.split_whitespace().filter(|&x| x.to_lowercase() == word).count();
  }

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


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

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

    string str = to_string(n);
    string res = "";
    for (int idx=0; idx<str.length(); idx++) {
        switch (str[idx]) {
            case '1': res += '9'; break;
            case '9': res += '1'; break;
            default: res += str[idx]; break;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>


int comp(const void *p, const void *q){

    return * (int*) q - * (int*) p;

    }
                                                                                                
  
int main(void){
                                                                                                
   
    int n, k, i, j;
   
    int a[200001] = {0};

    int b[200001] = {0};

    int A = 0;

    int t = 0;
   
      
    scanf("%d %d", &n, &k);
   
    for( i = 0 ; i < n ; i = i + 1 ){

        scanf("%d", &a[i]);
   
        }


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

        b[ a[i] ] += 1;

        }
        

    qsort( b, n, sizeof(int), comp );


    for( i = 0 ; i < k ; i = i + 1 ){

         A += b[i];

         }
               

    printf("%d\n", n - A );


    return 0;
                                                          
}

Measured memory_bytes: 2556
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(ll i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (ll i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<ll, ll>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const ll INF = 4E+18;


int main(){
    int n, k;
    cin >> n >> k;
    vector<P> v(n);
    rep(i, n) cin >> v[i].first >> v[i].second;
    auto comp = [](P a, P b) {
        return a.second < b.second;
    };
    sort(whole(v), comp);

    ll ans = INF;
    rep(i, n) rep(j, n) {
        if (j-i<k-1) continue;
        vector<P> tmp;
        for (int l=i; l<=j; l++) {
            tmp.push_back(v[l]);
        }
        sort(whole(tmp));
        ll dy = v[j].second - v[i].second;
        int ii = 0;
        int jj = k-1;
        while (jj<tmp.size()) {
            ll dx = tmp[jj].first - tmp[ii].first;
            chmin(ans, dx*dy);
            ii++; jj++;
        }
    }
    
    cout << ans << endl;
    return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  
  int ans = 0;
  for (int k=a; k<=b; k++) {
    string s = to_string(k);
    if (s[0] == s[4] && s[1] == s[3]) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  string s;
  cin >> s;
  int n = s.size();
  vector <int> cnt(26);
  for (int i = 0; i < n; ++i) ++cnt[s[i] - 'a'];
  ll ans = 0;
  for (int i = 0; i < 26; ++i) {
    ans += (ll)cnt[i] * (n - cnt[i]);
  }
  ans /= 2;
  cout << ans + 1 << '\n';
}



Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd;
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif // LOCAL
    int n;
    cin >> n;
    ll W;
    cin >> W;
    ll w[n+1]={}, v[n+1]={};
    for (int i=1; i<=n; i++) cin >> w[i] >> v[i];

    ll dp[W+1][n+1]={};
    for (int j=1; j<=n; j++) {
        for (int i=1; i<=W; i++) {
            if (i>=w[j]) dp[i][j] = max(dp[i-w[j]][j-1] + v[j], dp[i][j-1]);
            else dp[i][j] = dp[i][j-1];
        }
    }
    ll ans=0;
    for (int i=1; i<=W; i++) ans = max(ans, dp[i][n]);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const int N = 100010;
vector<int> e[N];
int vis[N],col[N],tag,n,m;
ll point,bi,con,cnt,ans,tot;
int dfs(int p,int c)
{
    cnt++;
    vis[p] = 1;
    col[p] = c;
    for (int i = 0;i < e[p].size();i++)
    {
        int x = e[p][i];
        if (!vis[x]) dfs(x,c^1);
        else {
            if (col[p] == col[x]) tag = 1;
        }
    }
}
int main()
{
    cin >> n >> m;
    for (int i = 0;i < m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        e[x].pb(y);
        e[y].pb(x);
    }
    for (int i = 1;i <= n;i++)
    {
        cnt = tag = 0;
        if (!vis[i])
        {
            dfs(i,0);
            if (cnt == 1)
            {
                ans = ans + tot*2 + 1;
                point++;
            } else if (tag == 1)
            {
                ans = ans + (cnt*point+bi+con)*2 + 1;
                con++;
            } else {
                ans = ans + (cnt*point+2*bi+con)*2 + 2;
                bi++;
            }
            tot += cnt;
        }
    }
    printf("%lld",ans);
    return 0;
}


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

int main(){
int a=0;
int b=0;
int c=0;
for(int i=0;i<9;i++){
	b=0;
a++;
for(int j=0;j<9;j++){
b++;
c=a*b;
cout<<a<<"x"<<b<<"="<<c<<endl;}}}

Measured memory_bytes: 1116
until (rec = $<.gets.chomp) == "0"
  record = rec.chars.drop(1)
  a = b = 0
  loop do
    (record.shift == "A") ? a += 1 : b += 1
    if record.empty?
      (a > b) ? a += 1 : b += 1
      break
    end
  end
  puts "#{a} #{b}"
end


Measured memory_bytes: 6836
#ABC124C/Coloring_Colorfully
def main():
    s = [int(x) for x in input()]
    cnt = 0
    if len(s) == 1:
        print("0")
        exit()
    for i in range(len(s)-1):
        if s[i] == 1:
            if s[i+1] == 1:
                s[i+1] = 0
                cnt+=1
        else:
            if s[i+1] == 0:
                s[i+1] = 1
                cnt+=1
    print(cnt)
main()

Measured memory_bytes: 3956
#include <iostream>
    #include <string>
    #include <algorithm>
    #include <cassert>
    #include <set>
    #include <vector>
    #include <cmath>
    #include <bitset>
    #include <functional>
    #include <limits>
    #include <map>
    using namespace std;

    typedef long long ll;
    #define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
    #define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

    ll pow(ll a, ll n) { //compute a^n with o(logn)
        ll res = 1;
        while (n > 0) {
            if (n & 1) res = res * a;
            a = a * a;
            n >>= 1;
        }
        return res;
    }

    ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
        ll res = 1;
        while (n > 0) {
            if (n & 1) res = res * a % mod;
            a = a * a % mod;
            n >>= 1;
        }
        return res;
    }

    int main(){
        string s,t;
        cin >> s;
        cin >> t;
        ll cnt = 0;
        rep0(i, s.length() - 1){
            if(s[i] != t[i]){
                cnt++;
            }
        }
        cout << cnt <<endl;
        return 0;
    }

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

long long n;
long long  as[100010];
long long as2[100010];
long long sum[100010];//最初が正
long long sum2[100010];//最初が負


int main() {
	sum[0] = 0;
	sum2[0] = 0;
	cin >> n;
	for (long long i = 0; i < n; i++) {
		int a;
		cin >> a;
		as[i] = a;
		as2[i] = a;
	}


	long long count = 0;

	if (as[0] <=0) {
		count += 1-as[0];
		as[0] = 1;
	}
	for (long long i = 0; i < n; i++) {
		sum[i + 1] = sum[i] + as[i];
		if ( sum[i + 1] >= 0 && sum[i] > 0) {
			count += sum[i + 1] - (-1);
			sum[i + 1] = -1;
		}
		else if ( sum[i + 1] <= 0 && sum[i] < 0) {
			count += 1 - sum[i + 1];
			sum[i + 1] = 1;
		}
	}

	long long count2 = 0;

     if (as2[0] >= 0) {
		count2+= as2[0] - (-1);
		as2[0] = -1;
	}
	for (long long i = 0; i < n; i++) {
		sum2[i + 1] = sum2[i] + as2[i];
		if (sum2[i + 1] >= 0 && sum2[i] > 0) {
			count2 += sum2[i + 1] - (-1);
			sum2[i + 1] = -1;
		}
		else if ( sum2[i + 1] <= 0 && sum2[i] < 0) {
			count2 += 1 - sum2[i + 1];
			sum2[i + 1] = 1;
		}


	}
	if (count < count2) {
		cout << count << endl;
	}
	else {
		cout << count2 << endl;
	}
	return 0;
}








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

int main(){
	int H, W;
	cin >> H >> W;
	vector<string> A(H);

	for(int i=0; i<W+2; i++){
		cout << '#';
	}
	cout << endl;

	for(int i=0; i<H; i++){
		cin >> A.at(i);
		cout << '#';
		cout << A.at(i);
		cout << '#' << endl;
	}

	for(int i=0; i<W+2; i++){
		cout << '#';
	}
	cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int n;
int a[105];
int dp[105][100005];
int DP[105][100005];
 
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=1;i<=n;i++)cin>>a[i];
    fill(dp[0],dp[105],-1e9);
    fill(DP[0],DP[105],1e9);
     
    int ans=0,ANS=1e9;
    dp[0][0]=0;
    DP[0][0]=0;
    for(int i=1;i<=n;i++){
      for(int j=0;j<=100000;j++){
        int A=a[i]%1000;
        if(A==0)A=1000;
         
        dp[i][j]=dp[i-1][j];
        DP[i][j]=DP[i-1][j];
 
        if(A<=500){
          int k=1000-A-500;
          if(j-k>=0){
            int d=dp[i-1][j-k]+1;
            int D=DP[i-1][j-k]+a[i];
            if( (d==dp[i][j]&&D<DP[i][j]) || d>dp[i][j]){
              dp[i][j]=d;
              DP[i][j]=D;
            }
          }
        }else{
          int k=1000-A;
          if(j-k>=0){
            int d=dp[i-1][j-k];
            int D=DP[i-1][j-k]+a[i];
            if( (d==dp[i][j]&&D<DP[i][j]) || d>dp[i][j]){
              dp[i][j]=d;
              DP[i][j]=D;
            }
          }
           
          if(j+A-500<=100000){
            int d=dp[i-1][j+A-500]+1;
            int D=DP[i-1][j+A-500]+a[i];
            if( (d==dp[i][j]&&D<DP[i][j]) || d>dp[i][j]){
              dp[i][j]=d;
              DP[i][j]=D;
            }
          }
        }
        if( (ans==dp[i][j]&&DP[i][j]<ANS) || ans<dp[i][j] ){
          ans=dp[i][j];
          ANS=DP[i][j];
        }
      }
    }
    cout<<ans<<' '<<ANS<<endl;
  }
  return 0;
}

Measured memory_bytes: 85132
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	auto C = A - min(A, K);
	B = max(0ll, B - max(0ll, K - A));
	cout << C << " " << B << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
h.reverse()
for i in range(n-1):
	if h[i] < h[i+1]:
		h[i+1] -= 1
for i in range(n-1):
	if h[i] < h[i+1]:
		print('No')
		exit()

print('Yes')

Measured memory_bytes: 14396
// AOJ 2922: Mercy
// 2019.2.17 bal4u

#include <stdio.h>
#include <stdlib.h>

#define gc() getchar()

int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int main()
{
	int N, M, sa, sb;

	N = in(), M = in();
	sa = sb = 0;
	while (N--) sa += in();
	while (M--) sb += in();
	printf("%lld\n", (long long)sa * sb);
	return 0;
}



Measured memory_bytes: 2064
L = gets.to_i

R = Math.log2(L).floor
R2 = 2 ** R
N = R + 1

paths = []
1.upto(N - 1) do |i|
  paths << [i, i + 1, 0]
  paths << [i, i + 1, 2 ** (i - 1)]
end

l = L
(N-1).downto(1) do |t|
  lt = l - 2 ** (t - 1)
  if lt >= R2
    paths << [t, N, lt]
    l = lt
  end
end

puts "#{N} #{paths.size}"
paths.each do |path|
  puts path.join(' ')
end

Measured memory_bytes: 1788
fun main(args: Array<String>) {
    val n = readLine()!!.toLong()
    val sn = Math.sqrt(n.toDouble())
    var sum = 0L
    for (i in 1..sn.toLong()) {
        if ((n - i) % i == 0L) {
            var x=(n - i) / i
            if (x>i) {
                sum += (n - i) / i
            }
        }
    }
    println(sum)
}


Measured memory_bytes: 32068
package main

import "fmt"

func main() {
	var a, b int
	var s string

	fmt.Scan(&a, &b)
	fmt.Scan(&s)

	if len(s) != a + b + 1 {
		fmt.Println("No")
		return
	}

	for i := 0; i < a + b + 1; i++ {
		if i == a {
			if string(s[i]) != "-" {
				fmt.Println("No")
				return
			}
		} else {
			if string(s[i]) == "-" {
				fmt.Println("No")
				return
			}
		}
	}

	fmt.Println("Yes")
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

class unionfind {
    vector<int> par, rank;

   public:
    void init(int n) {
        par.resize(n);
        rank.resize(n);

        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
        }
    }

    int find(int x) {
        if (par[x] == x)
            return x;
        else
            return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;

        if (rank[x] < rank[y])
            par[x] = y;
        else {
            par[y] = x;
            if (rank[x] == rank[y]) ++rank[x];
        }
    }

    bool same(int x, int y) { return (find(x) == find(y)); }
};

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    V<int> c(N);
    rep(i, N) cin >> c[i], --c[i];
    V<pair<int, pii>> edges;
    auto get = [&](int x) { return (c[x] >= 0 ? c[x] : x + K); };
    rep(i, M) {
        int a, b, w;
        cin >> a >> b >> w;
        --a, --b;
        edges.eb(w, mp(get(a), get(b)));
    }
    sort(ALL(edges));
    unionfind uf;
    uf.init(N + K);

    ll ans = 0;
    int add = 0;

    for (auto e : edges) {
        int a, b;
        tie(a, b) = e.se;
        if (!uf.same(a, b)) {
            uf.unite(a, b);
            ans += e.fi;
            if (++add == K - 1) {
                break;
            }
        }
    }

    cout << (add < K - 1 ? -1 : ans) << endl;

    return 0;
}

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

const int N = 1e6 + 11;
bool used[N] = {};
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector <int> a(n);
    for (auto &i : a) cin >> i;
    int ans = 0;
    map <int, int> cnt;
    for (auto &i : a) ++cnt[i];
    for (auto &i : cnt) {
        if (i.y == 1 && !used[i.x]) ++ans;
        for (int j = i.x; j < N; j += i.x) {
            used[j] = 1;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 14188
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX

#include <bits/stdc++.h>
#define db(x) cout << (x) << '\n';
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<double,ll> pdi;
typedef pair<ld,ld> pdd;
typedef pair<double,ll> pdi;
typedef pair<double,pii> pdp;
typedef pair<string,ll> psi;
typedef pair<ll,string> pls;
typedef pair<string,string> pss;
typedef pair<ll,pii> pip;
typedef pair<pii,pii> ppp;
typedef complex<ld> point;
#define mod (ll)(998244353)
#define eps (1e-9)
#define oo (ll)(0x3f3f3f3f)
#define pi acos(-1)
#define MAXN (ll)(5e5+5)

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

    int n;
    cin >> n;
    int x=__gcd(n,360);
    db(360/x)

    return 0;
}


Measured memory_bytes: 3620
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto A = RD;
	auto B = RD;
	auto C = RD;
	auto D = RD;

	writeln(max(A*B, C*D));
	stdout.flush();
	debug readln();
}

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

using namespace std;
#define int long long int
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define vi vector <int>
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define piii pair< int,pair<int,int> >
#define tiii tuple <int,int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(v) v.rbegin(),v.rend()
#define endl '\n'
#define matrix vector <vector <int> >
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define NAYAN freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define N 1000005
#define mod 1000000007
#define mod2 998244353
#define inf 1e17

int power(int x,int n)
{
    if(x==0)
        return x;
    int res=1;
    while(n)
    {
        if(n%2==0)
        {
            x=(x%mod*x%mod)%mod;
            n/=2;
        }
        else
        {
            res=(res%mod*x%mod)%mod;
            n--;
        }
    }
    return res;
}

int fact[N];
int invfact[N]; 

void init()
{
    fact[0]=invfact[0]=1;
    int i;
    for(i=1;i<N;i++)
    {
        fact[i]=(fact[i-1]*i)%mod;
        invfact[i]=power(fact[i],mod-2);
    }
}

int ncr(int a,int b)
{
    if(a<b || a<=0)
        return 0;
    if(a==b || b<=0)
        return 1;

    int ans=(fact[a]*invfact[a-b])%mod;
    ans=(ans*invfact[b])%mod;
    return ans;
}



int32_t main()  
{
    boost
    // #ifndef ONLINE_JUDGE 
    // NAYAN
    // #endif

    init();
    int h,w,n;
    cin >> h >> w >> n;
    int i,j;
    vector <pii> a;
    int u,v;
    for(i=0;i<n;i++)
    {
        cin >> u >> v;
        a.pb({u,v});
    }
    a.pb({h,w});

    sort(all(a));

    int ans[n+1];
    for(i=0;i<=n;i++)
    {
        int tmp=ncr(a[i].ff+a[i].ss-2,max(a[i].ff,a[i].ss)-1);
        ans[i]=tmp;
    }

    for(i=0;i<n;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            int dx,dy;
            dx=a[j].ff-a[i].ff;
            dy=a[j].ss-a[i].ss;
            if(dx<0 || dy<0)
                continue;

            int tmp=ncr(dx+dy,max(dx,dy));
            tmp=(tmp*ans[i])%mod;
            ans[j]=(ans[j]-tmp+mod)%mod;
        }
    }

    ans[n]=(ans[n]+mod)%mod ;
    cout << ans[n]<< endl;
}

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

template <typename T>
using lim = numeric_limits<T>;

const int MAXN = 2e5;
int arr[MAXN+1];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n; cin >> n;
	memset(arr, 0, sizeof arr);
	for (int i = 2; i <= n; i++){
		int a; cin >> a;
		arr[a]++;
	}

	for (int i = 1; i <= n; i++) cout << arr[i] << "\n";
}

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

int main() {
  int N, A[101], b = 0, s = 100000000;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (b < A[i]) {
      if(s > b && i == 0) s = A[i];
      else if (s > b) s = b;
      b = A[i];
    }
    else if (s > A[i]) s = A[i];
  }
  if (s == 100000000) s = 0;
  cout << b - s;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1<<29;
typedef long long int ll;

bool searched[200000];

int main(){
    int N;cin >> N;
    ll A[N], B[N];
    rep(i, N)B[i] = 0;
    rep(i, N){
        cin >> A[i];
        --A[i];
        B[A[i]] += 1;
    }
    ll ans = 0, tmpans = 0;
    rep(i, N){
        if(!searched[A[i]]){
            searched[A[i]] = true;
            tmpans += (B[A[i]] *(B[A[i]] - 1))/2;
        }
    }
    rep(i, N){
        cout << tmpans - (B[A[i]] *(B[A[i]] - 1))/2 + ((B[A[i]]-1) *(B[A[i]] - 2))/2<<endl;
    }
}


Measured memory_bytes: 5888
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

main:-
    get_string(S),
    (S = "ABC") -> writeln('ARC') ; writeln('ABC').


Measured memory_bytes: 8080
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [list(sys.stdin.readline())[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [list(map(list, sys.stdin.readline().split())) for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

N = I()
ans = 0
for i in range(1, N+1):
    if (len(str(i))%2):
        ans += 1
    
print(ans)

Measured memory_bytes: 40048
import numpy as np


def main(n, m, a):
    dp = np.zeros(n + 1, dtype=int)
    dp[0] = 1
    dp[1] = 1 if 1 not in a else 0

    for i in range(2, len(dp)):
        dp[i] = dp[i - 1] + dp[i - 2] if i not in a else 0
        dp[i] %= 1000000007

    return dp[-1]


if __name__ == '__main__':
    N, M = map(int, input().split())
    A = set()
    for _ in range(M):
        A.add(int(input()))

    print(main(N, M, A))


Measured memory_bytes: 21064
n,w=map(int,input().split())
l=[]
weight=[0]
value=[0]

for _ in range(n):
    a,b=map(int,input().split())
    value.append(b)
    weight.append(a)
maxvalue=sum(value)
dp=[[10**10 for i in range(maxvalue+1)]for i in range(n+1)]
for i in range(n+1):
    dp[i][0]=0
for i in range(1,n+1):
    for j in range(1,maxvalue+1):
        if value[i]<=j:
            
            dp[i][j]=min(dp[i-1][j],dp[i-1][j-value[i]]+weight[i])
        else:
            dp[i][j]=dp[i-1][j]
for i in range(maxvalue+1):
    if dp[-1][i]<=w:
        ans=i
print(ans)


Measured memory_bytes: 171528
#include <iostream>
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b);
ll lcm(ll a, ll b);

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

  cout << lcm(A,B) << endl;

  return 0;
}

ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b,a%b);
  }
}
ll lcm(ll a, ll b) {
  return a*b/gcd(a,b);
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int h[] = new int[n];
            int s[] = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = Integer.parseInt(in.next());
            }
            for (int i = 0; i < n - 1; i++) {
                s[i] = h[i] - h[i + 1];
            }
            int ans = 0;
            int tmp = 0;
            for (int i = 0; i < n - 1; i++) {
                if (s[i] >= 0) tmp++;
                else tmp = 0;
                ans = Math.max(ans, tmp);
            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 48976
import collections as cl
N = int(input())
S = input()

max_count = -1
max_index = -1
for i in range(N) :
    c1 = cl.Counter(list(S[0:i]))
    c2 = cl.Counter(list(S[i:]))
    if (len(c1.keys() & c2.keys()) > max_count) :
        max_count = len(c1.keys() & c2.keys())
        max_index = i

print(max_count)

Measured memory_bytes: 3444
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if(a==b && b!=c){
		cout << "Yes";
		return 0;
	}
	if(a==c && b!=c){
		cout << "Yes";
		return 0;
	}
	if(c==b && b!=a){
		cout << "Yes";
		return 0;
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

template <typename T>
void read(T &x) {
    x = 0; bool f = 0;
    char c = getchar();
    for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
    for (;isdigit(c);c=getchar()) x=x*10+(c^48);
    if (f) x=-x;
}

template<typename F>
inline void write(F x, char ed = '\n') {
	static short st[30];short tp=0;
	if(x<0) putchar('-'),x=-x;
	do st[++tp]=x%10,x/=10; while(x);
	while(tp) putchar('0'|st[tp--]);
	putchar(ed);
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

int k;
int main() {
	read(k); int n = (k + 1) / 2; n += n & 1;
	if (k == 1) return write(1), write(1), 0;
	write(n);
	for (int i = 1;i <= n; i++) {
		for (int j = 1;j <= n; j++) {
			int t = (i + j - 2) % n + 1;
			if (t > k - n) write(t, ' ');
			else write((i & 1) ? n + t : t, ' ');
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include <cmath>
#include<algorithm>

#include<stack>
#include<map>
#include<ctime>
#define rep(i,n) for (int i=0;i<n;i++)
#define inf 100000000000000
//#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long int N,K;
    cin>>N>>K;
    vector<long int> h(N),dp(N,inf);
    rep(i,N) cin>>h[i];
    dp[0]=0;
    for (long int i=1;i<N;i++){
       // dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
        for (int j=1;j<=min(K,i);j++){
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout<<dp[N-1]<<endl;
    return 0;
}

Measured memory_bytes: 1792
<?php
//error_reporting(0);
//$N = trim(fgets(STDIN));
list($N,$M) = explode(" ",trim(fgets(STDIN)));
//$H = explode(" ",trim(fgets(STDIN)));
for($i=0;$i<$M;$i++) {
  list($P[],$Y[]) = explode(" ",trim(fgets(STDIN)));
  $PY[$P[$i]][$Y[$i]]=$i;
}

foreach($PY as $k=>$y) {
  ksort($y);
  $seq=1;
  foreach($y as $kk=>$v) {
    $a[$v]=sprintf("%06d%06d",$k,$seq);
    $seq++;
  }
}
ksort($a);
foreach($a as $v) {
  printf("%s\n",$v);
}


Measured memory_bytes: 124644
n=int(input())
l=list(map(int,input().split()))
d={}
for i in l:
	if i in d:
		d[i]+=1
	else:
		d[i]=1
s=sum(l)
q=int(input())
for _ in range(q):
	b,c=map(int,input().split())
	if b in d:
		if c in d:
			d[c]+=d[b]
		else:
			d[c]=d[b]
		if c>b:
			s+=(c-b)*d[b]
		else:
			s-=(b-c)*d[b]
		d[b]=0
	print(s)

Measured memory_bytes: 85080
import heapq

def dijkstra(start: int, graph: list) -> list:
    """dijkstra法: 始点startから各頂点への最短距離を求める
    計算量: O((E+V)logV)
    """
    INF = 10 ** 18
    n = len(graph)
    dist = [INF] * n
    dist[start] = 0
    q = [(0, start)]  # q = [(startからの距離, 現在地)]
    while q:
        d, v = heapq.heappop(q)
        if dist[v] < d:
            continue
        for nxt_v, cost in graph[v]:
            if dist[v] + cost < dist[nxt_v]:
                dist[nxt_v] = dist[v] + cost
                heapq.heappush(q, (dist[nxt_v], nxt_v))
    return dist

def main():

    n, m, s = map(int, input().split())
    info = [list(map(int, input().split())) for i in range(m)]
    INF = 10 ** 18

    graph = [[] for i in range(n)]
    for a, b, cost in info:
        graph[a].append((b, cost))

    dist = dijkstra(s, graph)
    for i in range(n):
        if dist[i] == INF:
            print("INF")
        else:
            print(dist[i])

if __name__ == '__main__':
    main()


Measured memory_bytes: 163044
#include<iostream>

using namespace std;
bool is_prime(int n) {
    // Assumes that n is a positive natural number
    // We know 1 is not a prime number
    if (n == 1) {
        return false;
    }

    int i = 2;
    // This will loop from 2 to int(sqrt(x))
    while (i*i <= n) {
        // Check if i divides x without leaving a remainder
        if (n % i == 0) {
            // This means that n has a factor in between 2 and sqrt(n)
            // So it is not a prime number
            return false;
        }
        i += 1;
    }
    // If we did not find any factor in the above loop,
    // then n is a prime number
    return true;
}


int main()
{
	int x;
  	cin >> x;
  	while(!(is_prime(x))){
    	x++;
    }
  	cout << x << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int m,f,r,s,c;
	while(scanf("%d%d%d",&m,&f,&r)){
 		if((m&f&r)==-1)break;
		s=m+f;
		c=4-(29<s)-(49<s)-(64<s)-(79<s);
 		c-=(c==3&&49<r);
		if((m|f)==-1||s<30)c=5;
		printf("%c\n",c+'A');
	}
}


Measured memory_bytes: 2092
import java.util.*;

public class Main{

    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        Restaurant[] r = new Restaurant[n];
        for(int i = 0; i < n; i++){
            r[i] = new Restaurant(scan.next(), scan.nextInt(), i + 1);
        }
        Arrays.sort(r);
        for(int i = 0; i < n; i++) System.out.println(r[i].index);
    }

    public class Restaurant implements Comparable<Restaurant>{

        String place;
        int score;
        int index;

        public Restaurant(String place, int score, int index){
            this.place = place;
            this.score = score;
            this.index = index;
        }


        @Override
        public int compareTo(Restaurant r) {
            if(!r.place.equals(this.place)) return this.place.compareTo(r.place);
            return Integer.compare(r.score, this.score);
        }

        @Override
        public String toString(){
            return this.place + " " + this.score + " " + this.index;
        }
    }


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


Measured memory_bytes: 36096