akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

struct UnionFind {
  std::vector<int> par;
  std::vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    REP(i,n) par[i] = i;
  }

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

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

    if (x == y) return;

    if (sizes[x] < sizes[y]) std::swap(x, y);

    par[y] = x;
    sizes[x] += sizes[y];
  }

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

  int size(int x) {
    return sizes[find(x)];
  }
};

int N, K, L;
int main() {
    std::cin >> N >> K >> L;
    UnionFind uf1(N);
    UnionFind uf2(N);

    REP(i, K) {
        int p, q;
        std::cin >> p >> q;
        p--;
        q--;
        uf1.unite(p, q);
    }
    REP(i, L) {
        int r, s;
        std::cin >> r >> s;
        r--;
        s--;
        uf2.unite(r, s);
    }


    std::map< std::pair<PII, PII>, int > map;
    REP(i, N) {
        PII p1;
        p1.fst = uf1.size(i);
        p1.snd = uf1.find(i);

        PII p2;
        p2.fst = uf2.size(i);
        p2.snd = uf2.find(i);

        map[std::make_pair(p1,p2)]++;
    }

    REP(i, N) {
        PII p1;
        p1.fst = uf1.size(i);
        p1.snd = uf1.find(i);

        PII p2;
        p2.fst = uf2.size(i);
        p2.snd = uf2.find(i);

        std::cout << (i == 0 ? "" : " ") << map[std::make_pair(p1,p2)];
    }
    std::cout << std::endl;
}

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

using namespace std;

const int N = 2 * 1e3 + 50;
bool mark[N][N];

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

    // soma dos menores > maior_elemento
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    int cnt = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(i == j || mark[i][j] || mark[j][i]) continue;
            mark[i][j] = 1, mark[j][i] = 1;
            for(int k = j + 1; k < n; k++) {
                if(v[i] + v[j] > v[k]) cnt++;
                else continue;
            }
        }
    }
    cout << cnt << "\n";
    /*
    218 233 389 645 704 728 786
    
    218+233>389 -> 1
    ok vejo pegando de dois em dois e testando com os outros
    se nao for ja dou continue
   
    desse jeito so to pegando pares adjacentes
    N = 2 x 10³
    tentar O(n³)

    */

    return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;  cin>>n;
  int a[n];
  int hasha[n]={0};
  for(int i=0;i<n;i++)  hasha[i]=0;
  long long int ans=0,mod=1000000007;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    ++hasha[a[i]];
    if(hasha[a[i]]>2)
    ans=-1;
  }
  
  if((n%2 && hasha[0]!=1) || (n%2==0 && hasha[0]!=0) || ans==-1)
  {
    cout<<"0";
  }
  else
  {
    for(int i=1;i<n;i++)
    {
      if(!(hasha[i]==0 || (hasha[i]==2)))
      {
        ans = -1;
        break;
      }
    }
    if(ans!=-1)
    {
      n=n>>1;ans=1;
      for(int i=0;i<n;i++)
      {
        ans*=2;
        ans%=mod;
      }
      cout<<ans;
    }
    else if(ans==-1)
    cout<<"0";
  }
  
  return 0;
}

Measured memory_bytes: 4384
H, W, K = map(int, input().split())
S = [list(input()) for i in range(H)]

ans = 0
for h in range(2**H):
    hbit = bin(h)[2:].zfill(H)
    hselect = set()
    for hi, hb in enumerate(hbit):
        if hb == '1':
            hselect.add(hi)
    for w in range(2**W):
        wbit = bin(w)[2:].zfill(W)
        wselect = set()
        for wi, wb in enumerate(wbit):
            if wb == '1':
                wselect.add(wi)

        tmp = 0
        for i in range(H):
            if i in hselect:
                continue
            for j in range(W):
                if j in wselect:
                    continue
                if S[i][j] == '#':
                    tmp += 1

        if tmp == K:
            ans += 1

print(ans)
                

Measured memory_bytes: 69880
#include <stdio.h>

static long bitset;

enum kind
{
    S,
    H,
    C,
    D
};

long exists(enum kind k, int n)
{
    long bit;
    bit = 1l << (k * 13 + n);
    return bitset & bit;
}

void setbit(enum kind k, int n)
{
    long bit;
    bit = 1l << (k * 13 + n);
    bitset |= bit;
}

int main(void)
{
    int n, r, i;
    char c, buf[6];
    enum kind k;

    bitset = 0;
    fgets(buf, 6, stdin);
    sscanf(buf, "%d", &n);

    for (i = 0; i < n; ++i)
    {
        fgets(buf, 6, stdin);
        sscanf(buf, "%c %d", &c, &r);
        switch (c)
        {
        case 'S':
            k = S; break;
        case 'H':
            k = H; break;
        case 'C':
            k = C; break;
        case 'D':
            k = D; break;
        }
        setbit(k, r);
    }
    bitset = ~bitset;
    for (i = 1; i <= 52; ++i)
    {
        k = (i - 1) / 13;
        r = (i - 1) % 13 + 1;
        if (exists(k, r))
        {
            switch (k)
            {
            case S:
                printf("S %d\n", r); break;
            case H:
                printf("H %d\n", r); break;
            case C:
                printf("C %d\n", r); break;
            case D:
                printf("D %d\n", r); break;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 2048
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;

struct Edge{
    int to, cap, rev;
    Edge(int t, int c, int r):to(t), cap(c), rev(r) {}
};

void AddEdge(int fr, int to, int cap, vector<vector<Edge> >& gr)
{
    gr[fr].push_back( Edge(to, cap, gr[to].size()) );
    gr[to].push_back( Edge(fr, 0, gr[fr].size()-1) );
}

int dfs(int v, int G, int f, vector<vector<Edge> >& gr, vector<int>& used )
{
    if(v==G) return f;
    used[v]=1;
    auto it = gr[v].begin();
    for(; it!=gr[v].end(); ++it) {
        if(!used[it->to] && it->cap>0) {
            int d = dfs( it->to, G, MIN(f, it->cap), gr, used);
            if(d>0) {
                it->cap -= d;
                gr[it->to][it->rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow( int S, int G, vector<vector<Edge> >& g)
{
    int flow=0;
    while(1) {
        vector<int> used(g.size(), 0);
        int f = dfs(S, G, INF, g, used);
        if(f==0) break;
        flow += f;
    }
    return flow;
}

char str[100][105];

int main(int argc, char* argv[])
{
    int h,w;
    scanf("%d%d", &h, &w);

    int i,j;
    int s0,s1,t0,t1;
    for(i=0; i<h; i++) {
        scanf("%s", str[i]);
        for(j=0; j<w; j++) {
            if(str[i][j]=='S') {
                s0=i; s1=j;
            }
            if(str[i][j]=='T') {
                t0=i; t1=j;
            }
        }
    }
    if(s0==t0 || s1==t1) {
        printf("-1\n"); return 0;
    }

    vector<vector<Edge> > gr(h+w+2);

    for(i=0; i<h; i++) {
        for(j=0; j<w; j++) {
            if(str[i][j]=='o') {
                AddEdge(i, j+h, 1, gr);
                AddEdge(j+h, i, 1, gr);
            }
        }
    }
    AddEdge(h+w, s0, INF, gr);
    AddEdge(h+w, s1+h, INF, gr);
    AddEdge(t0, h+w+1, INF, gr);
    AddEdge(t1+h, h+w+1, INF, gr);
 
    int f = max_flow( h+w, h+w+1, gr);
    printf("%d\n", f);
 
    return 0;
}



Measured memory_bytes: 896
import java.util.*;

public class Main{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int tar;
		
		List<Integer> lis = new LinkedList<>();
		for( int i=0 ;i < n ;i ++){
			lis.add(sc.nextInt());
		}
		printLis(lis);
		for(int j = 1 ; j < n ; j++)
		{
			tar = lis.get(j);
			int k = j - 1 ;
			while( k >= 0 && lis.get(k) > tar )
			{
				k--;
			}
			
			if( k++ != j - 1 ){
				lis.remove(j);
				lis.add(k,tar);
			}
				printLis(lis);
			
		
		}
	}
	public static void printLis(List<?> list){
		for(int i = 0; i<list.size()-1;i++){
			System.out.print(list.get(i)+" ");
		}
		System.out.println(list.get(list.size()-1));
	}
}

Measured memory_bytes: 31820
using System;
using System.Linq;
using System.Collections.Generic;

namespace _0030
{
    
    class Program
    {

        
        static void Main(string[] args)
        {

            int n = int.Parse(Console.ReadLine());
            int cnt = 0;
            int ans = 0;
            
            for (int i = 3; i <= n; i += 2)
            {
                cnt = 2;               
                for(int j = 3; j <= i - 2; j += 2)
                {
                    if(i % j == 0)
                    {
                        cnt++;                        
                    }
                    if(cnt > 8)
                    {
                        break;
                    }
                }

                if(cnt == 8)
                {
                    ans++;
                }

            }

            Console.WriteLine(ans);
           
        }
    }
}

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

const int MAXN = 3e5;
int N;
vector<int> adj[MAXN];

pair<int, int> furthest(int cur, int prv = 0) {
	pair<int, int> ans(0, cur);
	for (int nxt : adj[cur]) {
		if (nxt == prv) continue;
		auto res = furthest(nxt, cur);
		res.first ++;
		ans = max(ans, res);
	}
	return ans;
}

int diameter() {
	return furthest(furthest(1).second).first;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	for (int e = 0; e < N-1; e++) {
		int a, b; cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	cout << (diameter() % 3 == 1 ? "Second" : "First") << '\n';

	return 0;
}


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

using namespace std;
using ll = long long;
const ll MAX = 1e9;
const ll MOD = 1e9 + 7;

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);
}

ll solve(ll n, ll m, vector<ll> &a) {
  bool same = true;
  while (a[0] % 2 == 0) {
    for (int i = 0; i < n; i++) {
      if (a[i] % 2 != 0) {
        return 0;
      }
      a[i] /= 2;
    }
    m /= 2;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] % 2 == 0) {
      return 0;
    }
  }
  ll v = 1;
  for (int i = 0; i < n; i++) {
    v = lcm(v, a[i]);
    if (v > m) {
      return 0;
    }
  }
  return (m / v + 1) / 2;
}

// (ai/2 * (2p + 1))に変形できる
// 奇数はかけれるが偶数はかけれない
// 任意のai, akで2の約数の数が異なった場合はNG
// そうでない場合は同じ値にできる
int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] /= 2;
  }
  cout << solve(n, m, a) << endl;
}


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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll) 1e9 + 7;
constexpr long long MOD = 998244353LL;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
    string s;
    cin>>s;
    
    ll a,b,c,d;
    a=s[0]-'0';
    b=s[1]-'0';
    c=s[2]-'0';
    d=s[3]-'0';
    
    REP(i,2){
        REP(j,2){
            REP(k,2){
                ll ans=a;
                if(i==0) ans+=b;
                else ans-=b;
                if(j==0) ans+=c;
                else ans-=c;
                if(k==0) ans+=d;
                else ans-=d;
                if(ans==7){
                    cout<<a;
                    if(i==0) cout<<"+";
                    else cout<<"-";
                    cout<<b;
                    if(j==0) cout<<"+";
                    else cout<<"-";
                    cout<<c;
                    if(k==0) cout<<"+";
                    else cout<<"-";
                    cout<<d<<"=7"<<en;
                    return;
                }
            }
        }
    }

}

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

    solve();
    //ll t;cin>>t;REP(i,t) solve();

    return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef pair<int,int> ii;

vector<int> G[510];

vector<string> arr;
vector<ii> edges;
bool found[510];
bool used[510];
bool cycle;

bool inValid(string a,string b) {
  if( a == b ) return false;
  int diff = -1;
  rep(i,min(a.size(),b.size())) if( a[i] != b[i] ) { diff = i; break; }
  if( diff == -1 && a.size() > b.size() ) return true;
  return false;
}

void add(string a,string b){
  if( a == b ) return;
  int diff = -1;
  rep(i,min(a.size(),b.size())) if( a[i] != b[i] ) { diff = i; break; }
  if( diff == -1 ) return;
  edges.push_back(ii(a[diff]-'a',b[diff]-'a'));
}

bool visit(int v,vector<int>& order,vector<int>& color){
  color[v] = 1;
  rep(i,G[v].size()){
    int e = G[v][i];
    if(color[e] == 2)continue;
    if(color[e] == 1)return false;
    if(!visit(e,order,color))return false;
    }
  order.push_back(v);
  color[v] = 2;
  return true;
}

bool topologicalSort(vector<int>& order){
  vector<int> color(26,0); 
  for(int u=0;u<26;u++) if(!color[u] && !visit(u,order,color)) return false;
  reverse(order.begin(),order.end());
  return true;
}


int main(){
  int n;
  while(cin >> n,n){
    rep(i,510) { G[i].clear(); found[i] = used[i] = false;  }
    bool fin = false;
    cycle = false;
    arr.clear();
    arr.resize(n);
    edges.clear();
    rep(i,n) cin >> arr[i];
    rep(i,n-1) {
      if( inValid(arr[i],arr[i+1]) ) { puts("no"); fin = true; break; }
      add(arr[i],arr[i+1]);
    }
    if( fin ) continue;
    rep(i,edges.size()) {
      int src = edges[i].first;
      int dst = edges[i].second;
      G[src].push_back(dst);
    }
    vector<int> order;
    if( !topologicalSort(order) ) { puts("no"); continue; }
    puts("yes");
  }
  return 0;
}

// same as http://codeforces.com/contest/512/problem/A 

Measured memory_bytes: 1300
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val s = readLine() ?: return
    var count = 0
    0.until(n - 1).forEach { i ->
        if (s[i] != s[i + 1]) {
            count++
        }
    }
    println((count + 1).toString())
}

Measured memory_bytes: 34580
fun main(args: Array<String>) {
	readLine()
	val h = (readLine() ?: return).split(" ").map { it.toInt() }.toIntArray()
	var max = h[0]
	var count = 1
	for (i in 1 until h.size) {
		if (h[i] >= max) {
			count++
			max = h[i]
		}
	}
	println(count)
}

Measured memory_bytes: 37768
# -*- coding: utf-8 -*-
from collections import Counter

def maybe_check(n,A):
    try:
        if n <= 0 or n > 100000:
            raise

        div = 1000000007
        maybe_list = [abs(abs(i - n) - ((n -1 ) - abs(i - n))) for i in range(1, n+1)]
        maybe_list.sort()
        A.sort()
        if A !=  maybe_list:
            raise

        pattern = len([num for num,count in Counter(maybe_list).items() if count != 1])
        return (2 ** pattern) % div

    except:
        return 0


_n = int(raw_input())
_A = map(int,raw_input().split())

print maybe_check(_n,_A)


Measured memory_bytes: 19896
s = input()
if 'BC' not in s:
  print(0)
  import sys
  sys.exit()
t = s.split('BC')
m = 0
ans = 0
for l in t[:-1]:
  cnt = 0
  for i in range(len(l)-1,-1,-1):
    if l[i]!='A':
      ans += cnt
      m = cnt
      break
    cnt += 1
  else:
    m += cnt
    ans += m
print(ans)

Measured memory_bytes: 5476
N = int(input())
C = []
S = []
F = []
for i in range(N-1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for i in range(0, N-1):
    t = 0
    for j in range(i, N-1):
        if t <= S[j]:
            t = S[j]
        elif t%F[j] != 0:
            t += F[j] - t%F[j]
        t += C[j]
    print(t)
print(0)

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

using std::pair;
using std::vector;
using std::string;

typedef long long ll;
typedef pair<int, int> pii;

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

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

ll pw3(ll x) { return x * x * x; }

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    int n, k;
    read(n), read(k);

    ll ans = pw3(n / k);
    if(k % 2 == 0 && n >= k/2) ans = ans + pw3(1 + (n - k/2) / k);
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 256
package main

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

var stdin = bufio.NewScanner(os.Stdin)

func main() {
	var arr = []map[string]int{{"time": 0, "x": 0, "y": 0}}
	n := func() int { stdin.Scan(); i, _ := strconv.Atoi(stdin.Text()); return i }()
	for i := 0; i < n; i++ {
		in := scanArrayInt()
		arr = append(arr, map[string]int{"time": in[0], "x": in[1], "y": in[2]})
	}
	flag := true
	for i := 1; i < n+1; i++ {
		dt := float64(arr[i]["time"] - arr[i-1]["time"])
		xm := math.Abs(float64(arr[i]["x"] - arr[i-1]["x"]))
		ym := math.Abs(float64(arr[i]["y"] - arr[i-1]["y"]))
		dist := xm + ym
		if dt < dist {
			flag = false
			break
		}
		if int(dt)%2 != int(dist)%2 {
			flag = false
			break
		}
	}
	if flag {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}
func scanArrayInt() []int {
	var ret = []int{}
	stdin.Scan()
	for _, s := range strings.Split(stdin.Text(), " ") {
		i, _ := strconv.Atoi(s)
		ret = append(ret, i)
	}
	return ret
}

Measured memory_bytes: 34560
package main

import (
	"fmt"
)

func main() {
	var n int
	var s string
	fmt.Scanln(&n)
	fmt.Scanln((&s))

	fmt.Println(logic(s))
}

func logic(s string) int {
	var char rune
	count := 0

	for _, c := range s {
		if c != char {
			count++
			char = c
		}
	}
	return count
}

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

#define MAX(a,b) ((a)>(b)?(a):(b))

#define POS(i,j) ((i)*(m+1)+(j))

void run(void){
  char *s=(char *)calloc(3001,sizeof(char));
  char *t=(char *)calloc(3001,sizeof(char));
  scanf("%s",s);
  scanf("%s",t);
  int n=strlen(s);
  int m=strlen(t);
  int *dp=(int *)calloc((n+1)*(m+1),sizeof(int));
  int i,j;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      if(s[i]==t[j]){
	dp[POS(i+1,j+1)]=dp[POS(i,j)]+1;
      } else {
	dp[POS(i+1,j+1)]=MAX(dp[POS(i+1,j)],dp[POS(i,j+1)]);
      }
    }
  }
  char *ans=(char *)calloc(3001,sizeof(char));
  int top=0;
  i=n;
  j=m;
  while(i>0 && j>0){
    if(s[i-1]==t[j-1]){
      ans[top++]=s[i-1];
      i--;
      j--;
    } else if(dp[POS(i,j)]==dp[POS(i-1,j)]){
      i--;
    } else {
      j--;
    }
  }
  while(top>0){
    putchar(ans[--top]);
  }
  putchar('\n');
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 35328
n = int(input())
a = [int(i) for i in input().split()]

count = {}
for i in set(a):
    count[i] = 0
for i in a:
    count[i] += 1
    
keys = [k for k,v in count.items() if v >= 2]
keys_2 = [k for k,v in count.items() if v >= 4]

ans_1 = -10 ** 18
ans_2 = -10 ** 18
ans_3 = -10 ** 18
if len(keys) >= 2:
    ans_1 = sorted(keys)[-1]* sorted(keys)[-2]
if len(keys_2) >= 1:
    ans_2 = sorted(keys_2)[-1]**2
else:
    ans_3 = 0
print(max(ans_1,ans_2,ans_3))

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (ll)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

ll digsum(ll n){
    ll sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }

    return sum;
}

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

    ll ans = 0;
    REP(i,1,n+1){
        ll cnt = 0,tmp = i;
        while(tmp > 0){
            tmp /= 10;
            cnt++;
        }
        if(cnt % 2 == 1)ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#define N 100005
using namespace std;
double a[10][10];
int n, d;
double distance(int x, int y)
{
	double temp = 0;
	for (int i = 0; i < d; i++)
		temp += (a[x][i] - a[y][i]) * (a[x][i] - a[y][i]);
	return sqrt(temp);
}

int main()
{
	//freopen("Data.txt", "r", stdin);
	cin >> n >> d;
	int cnt = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < d; j++)
			cin >> a[i][j];
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++)
		{
			double dis = distance(i, j);
			int dis_int = floor(dis);
			if (fabs(dis - dis_int) < 1e-6)
				cnt++;
		}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut s = read::<String>().chars().collect::<Vec<char>>();
    let n = s.len();
    s.sort();
    s.dedup();
    let m = s.len();
    println!("{}", if n == m { "yes" } else { "no" });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
   int n;
   cin>>n;
   vector<ll> v1;
   ll a1;
   loop(i,0,n)
   {
       cin>>a1;
       v1.pb(a1);
   }
   GSORT(v1);
   ll ans = 0;
   loop(i,0,n-1){
       int k = (i+1)/2;
   ans += v1[k];
   }
   cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 5324
#!/usr/bin/python

import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N = int(line)
        total = 0
        for i in xrange(N):
            l, r = map(lambda x: int(x), sys.stdin.readline().split(" ", 2))
            total += (r - l) + 1
        print(total)
        line = sys.stdin.readline()
        

if __name__ == "__main__":
    main(sys.argv)

Measured memory_bytes: 2568
#include "bits/stdc++.h"
using namespace std;

int main(){
    int N ,a,b,c,d;
    cin >> N;

    a =  N/1000%10; 
    b =  N/100%10;
    c =  N/10%10;
    d =  N%10;

    if(a == b  && b== c)cout << "Yes" << endl;
    else if(b ==c && c == d )cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

struct BIT{
  int n;
  vector<int> d;
  BIT(int n) : n(n), d(n + 1){
    for(int i = 0; i <= n; i++) d[i] = 0;
  }
  
  void add(int i, int x){
    for(; i <= n; i += i & -i){
      d[i] += x;
    }
  }
  
  int sum(int i){
    int x = 0;
    for(; i; i -= i & -i){
      x += d[i];
    }
    return x;
  }
};

int main(){
  int N; cin >> N;
  string S; cin >> S;
  int Q; cin >> Q;
  
  vector<BIT> kind(26, BIT(N));
  for(int i = 1; i <= N; i++){
    kind[(int)(S[i - 1] - 'a')].add(i, 1);
  }
  
  while(Q--){
    int q; cin >> q;
    if(q == 1){
      int i;
      char ch;
      cin >> i >> ch;
      kind[S[i - 1] - 'a'].add(i, -1);
      kind[ch - 'a'].add(i, 1);
      S[i - 1] = ch;
    }else{
      int l, r;
      cin >> l >> r;
      int k = 0;
      for(int c = 0; c < 26; c++){
        if(kind[c].sum(r) - kind[c].sum(l - 1)) k++;
      }
      
      cout << k << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 53636
import numpy as np

n,W = (int(i) for i in input().split())
items=[[int(i) for i in input().split()]for j in range(n)]

dp  = np.zeros(W+1)

for w,v in items:
    dp[w:] = np.maximum(dp[w:],v+dp[:-w])

print(int(dp[-1]))


Measured memory_bytes: 15468
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>

#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

int main(int argc, char *argv[]) {
	const int mod = 1000000007;
	unordered_map<int, unordered_map<int, unordered_map<int, long long int>>> um1, um2;
	um1[0][0][0] = 1;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		um2.clear();
		for (auto p1 : um1) {
			for (auto p2 : p1.second) {
				for (auto p3 : p2.second) {
					// [p1.first][p2.first][p3.first] = p3.second
					if (p1.first == a) {
						um2[p1.first + 1][p2.first][p3.first] += p3.second;
						um2[p1.first + 1][p2.first][p3.first] %= mod;
					} 
					if (p2.first == a) {
						um2[p1.first][p2.first + 1][p3.first] += p3.second;
						um2[p1.first][p2.first + 1][p3.first] %= mod;
					} 
					if (p3.first == a) {
						um2[p1.first][p2.first][p3.first + 1] += p3.second;
						um2[p1.first][p2.first][p3.first + 1] %= mod;
					} 
				}
			}
		}
		um1 = um2;
	}
	long long int res = 0;
	for (auto p1 : um1) {
		for (auto p2 : p1.second) {
			for (auto p3 : p2.second) {
				res += p3.second % mod;
				res %= mod;
			}
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>
#include <numeric>
#include <climits>
#include <cfloat>
#include <bitset>

int main() {
	int n; long long int t; std::cin >> n >> t;
	long long int result = t;
	int prev_time = 0;
	for (auto i = 0; i < n; ++i) {
		int at; std::cin >> at;
		result += t;
		if (prev_time + t > at) {
			result += at - prev_time - t;
		}
		prev_time = at;
	}
	std::cout << result << std::endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
    int n, m;
    int x, y;
    cin >> n >> m;
    vector<bool> prob(n, false);
    vector<int> num(n, 1);
    prob[0] = true;

    for(int i = 0; i < m; i++){
        cin >> x >> y;
        x--;
        y--;

        prob[y] = prob[x] || prob[y];
        prob[x] = (--num[x] != 0) && prob[x];
        num[y]++;
    }

    /*
    for_each(num.begin(), num.end(), [](int x){ cout << x << " "; });
    cout << endl;
    for_each(prob.begin(), prob.end(), [](bool x){ cout << (x ? 1 : 0) << " "; });
    cout << endl;
    */

    cout << accumulate(prob.begin(), prob.end(), 0, [](int n, bool b){ return (b ? n + 1 : n); }) << endl;
    return 0;
}


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

int main() {
	long n,t,a,k;
	cin>>n>>t>>a;
	long h[n],b[n];
	for(int i=0;i<n;i++)cin>>h[i];
	for(int i=0;i<n;i++)b[i]=max(1000*(t-a)-6*h[i],-1000*(t-a)+6*h[i]);
	k=1;
	for(int i=0;i<n;i++){
		if(b[k-1]>b[i])k=i+1;
		
	}
	cout<<k<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 101

int main(){
  int n,i,j,k,a,b;
  int v[MAX][MAX];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++) v[i][j]=0;
  }
  
  for(i=1;i<=n;i++){
    scanf("%d%d",&a,&k);
    
    for(j=1;j<=k;j++){
      scanf("%d",&b);
      v[a][b]=1;
    }
    
  }

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



Measured memory_bytes: 2104
unittest
{
	assert( [ "5", "24 11 8 3 16" ].parse.expand.solve == 3 );
	assert( [ "4", "5 5 5 5" ].parse.expand.solve == 0 );
	assert( [ "10", "33 18 45 28 8 19 89 86 2 4" ].parse.expand.solve == 5 );
	
	assert( [ "4", "5 5 6 6" ].parse.expand.solve == 0 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	as.sort();
	
	auto ans = 0L;
	bool[ long ] ds;
	LOOP: foreach( i, a; as )
	{
		if( i + 1 < as.length && as[ i ] == as[ i + 1 ] )
		{
			ds[ a ] = true;
		}
		
		auto s = cast( long ) a ^^ 0.5L;
		for( auto d = 1L; d <= s; d++ )
		{
			if( a % d != 0 ) continue;
			if( d in ds || ( a / d ) in ds )
			{
				continue LOOP;
			}
		}
		
		ds[ a ] = true;
		ans++;
	}
	return ans;
}


Measured memory_bytes: 19556
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
using namespace std;
using ll = long long;

int main()
{
    ll N;
    cin >> N;
    vector<ll> L = vector<ll>(N);

    for(ll i = 0; i < L.size(); i++){
        cin >> L[i];
    }

    ll ans = 0;
    rep(i, 0, N - 2) rep(j, i + 1, N - 1) rep(k, j + 1, N){
        if (L[i] == L[j] || L[j] == L[k] || L[k] == L[i]){
            continue;
        }
        if (L[i] + L[j] > L[k] && L[j] + L[k] > L[i] && L[i] + L[k] > L[j]){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <numeric> //lcm


#define ERROR() cout << "ERROR!!" << endl; return 0;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const long long int INF = 1000000000; //<10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

inline bool maxch(int &a, int b) { if (a < b) {a = b; return true;} else return false;}

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

	if (n >= 10) cout << r << endl;
	else cout << r + 100*(10-n) << endl;
	
}




Measured memory_bytes: 256
n = int(input())
x = [[int(i) for i in input().split()] for i in range(n)]
for i in range(n-1):
	if x[i][0]>x[i+1][0] or x[i][1]>x[i+1][1]:
		a = ((x[i][0]-x[i][0]%x[i+1][0])//x[i+1][0])+1
		b = ((x[i][1]-x[i][1]%x[i+1][1])//x[i+1][1])+1
		if x[i][0]%x[i+1][0]==0: a -= 1
		if x[i][1]%x[i+1][1]==0: b -= 1
		x[i+1] = [x[i+1][0]*max(a,b),x[i+1][1]*max(a,b)]
print(x[-1][0]+x[-1][1])

Measured memory_bytes: 3188
#include"bits/stdc++.h"
using namespace std;
int a[100009];

int main()
{
	int n;
	cin>>n;
	string s[100005],s1[10];

	s1[0]="AC",s1[1]="WA",s1[2]="TLE",s1[3]="RE";
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<4;j++)
		{
			if(s[i]==s1[j])
			{
				a[j+1]++;
			}
		}
	}
	for(int i=0;i<4;i++)
	{
		cout<<s1[i]<<" x "<<a[i+1]<<endl;
	}
	return 0;

}

Measured memory_bytes: 6748
/*
 * =template=.cpp
 * Copyright (C) 2017 hzw <hzw@huzhenweideMacBook.local>
 *
 * Distributed under terms of the MIT license.
 */

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<cstring>
#include<sstream>
#define FR first
#define SC second
#define MP make_pair
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200010,p=1000000007,inf=100000000;
int pow(int a,int b,int c)
{
    if (a==0)return 0;int d=a,e=1;
    while (b)
    {
        if (b&1) e=(1LL*e*d)%c;
        d=1LL*d*d%c;b>>=1;
    }
    return e;
}
int random(int n) { return 1LL*rand()*rand()%n+1;}
struct Edge {int y,ne;};
/*int read(int &x)
{
	while (buf[pt]<=32&&pt<len) pt++;
	if (pt>=len) return 0;
	x=0;
	while (buf[pt]>32) x=x*10+buf[pt++]-48;
	return 1;
}*/

int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	if (n>m) swap(n,m);
	if (n>=2) cout<<1LL*(n-2)*(m-2)<<endl;
	if (n==1) 
	{
		if (m==1) cout<<1<<endl;else cout<<m-2<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i,n) for (int i = 0; i < (n); ++i)


void solve(long long N, std::vector<long long> A){
    ll ans = 0;
    vector<ll> res(1000004);
    rep(i,N){
        if(res[A[i]]){
            res[A[i]] = 2;
            continue;
        }
        for(ll j = A[i]; j <= 1000004; j += A[i]){
            res[j]++;
        }
    }
    rep(i,N){
        if(res[A[i]] == 1) ans++;
    }

    cout << ans << endl;

}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

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

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n, l;
  cin >> n >> l;
  vector<string> a(n);
  for (auto &i : a) cin >> i;
  sort(all(a));
  for (auto i : a) cout << i;
  cout << '\n';
}


Measured memory_bytes: 3648
<?php
    $n;
    $m;
    fscanf(STDIN, "%d", $n);
    $input = fgets(STDIN);
    $t = explode(" ", $input);
    $sum = array_sum($t);
    fscanf(STDIN, "%d", $m);
    for($i = 0; $i < $m; $i++){
        $p;
        $x;
        fscanf(STDIN, "%d %d", $p, $x);
        $ans = $sum - $t[$p-1] + $x;
        echo "$ans\n";
    }
?>


Measured memory_bytes: 3828
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

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

inline long ab(long a, long b){return a>b?a-b:b-a;}

int main(void){
	int h, w, i;
	scanf("%d%d", &h, &w);
	
	long ans=((long)h)*w;
	for(i=0; i<=w; i++){
		long a1 = ((long)h)*(w-i);
		long now;
		if(h%2==0 || i%2==0){
			long a2 = ((long)h)*i/2;
			now = ab(a1, a2);
		}else{
			long a2, a3;
			if(h<i){
				a2 = ((long)h)*(i/2);
				a3 = ((long)h)*((i+1)/2);
			}else{
				a2 = ((long)h/2)*i;
				a3 = ((long)(h+1)/2)*i;
			}
			long b1 = ab(a1, a2);
			long b2 = ab(a2, a3);
			long b3 = ab(a3, a1);
			now = b1<b2?b2<b3?b3:b2:b1<b3?b3:b1;
		}
		if(now<ans) ans=now;
	}
	for(i=0; i<=h; i++){
		long a1 = ((long)w)*(h-i);
		long now;
		if(w%2==0 || i%2==0){
			long a2 = ((long)w)*i/2;
			now = ab(a1, a2);
		}else{
			long a2, a3;
			if(w<i){
				a2 = ((long)w)*(i/2);
				a3 = ((long)w)*((i+1)/2);
			}else{
				a2 = ((long)w/2)*i;
				a3 = ((long)(w+1)/2)*i;
			}
			long b1 = ab(a1, a2);
			long b2 = ab(a2, a3);
			long b3 = ab(a3, a1);
			now = b1<b2?b2<b3?b3:b2:b1<b3?b3:b1;
		}
		if(now<ans) ans=now;
	}
	printf("%ld\n", ans);
}


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

int main()
{
  int n;
  while( cin >> n, n ) {
    int cnt = 0;

    while( n != 1 ) {
      if( n % 2 == 0 ) n /= 2;
      else n = n * 3 + 1;
      cnt++;
    }

    cout << cnt << endl;

  }

}

Measured memory_bytes: 1160
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = sys.stdin.buffer.readline().decode().rstrip()
    print('Heisei' if S <= '2019/04/30' else 'TBD')


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#!/usr/bin/env python
# coding: utf-8
#

import copy

            
    
def main(n, k, l):
    cost_l = []

    if k == 0:
        print(0)
        return
    
    if k == 1:
        t = [abs(l[i]) for i in range(len(l)) ]
        print(min(t))
        return
    
    for i in range(n - k + 1):
        mae = i
        ato = i + k - 1
        if l[mae] * l[ato] < 0:
            cost_l.append(min(- l[mae] * 2 + l[ato], - l[mae] + l[ato] * 2))
        elif l[mae] >= 0:
            cost_l.append(l[ato])
        elif l[ato] <= 0:
            cost_l.append(-l[mae])
            
    print(min(cost_l))

    
    
if __name__ == '__main__':
    try:
        n, k = list(map(int,input().strip().split(" ")))
        l = list(map(int,input().strip().split(" ")))
        main(n, k, l)
    except EOFError:
        pass


Measured memory_bytes: 15076
N,Y = map(int,input().split())
exist_flag = False
for i in range(N+1):
    for j in range(N+1-i):
        if Y == 10000*i + 5000*j + 1000*(N-i-j):
            exist_flag = True
            break
    if exist_flag:
        break
if not exist_flag:
    print(-1, -1, -1)
else:
    print(i, j, N-i-j)

Measured memory_bytes: 9056
#include<iostream>
#include<algorithm>
#include<string>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
typedef long long ll;

int main(){
    int s, w; cin >> s >> w;
    if(w<s) cout << "safe" << endl;
    else cout << "unsafe" << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
//typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

const ll mod = 1000000007;
const ll INF = 100000000000010000;

ll kai[100010];
ll bit[700010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

/*ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= 700005)
	{
		bit[i] += x;
		i += i & -i;
	}
}*/

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll y) {
	if (y == 0) return 1;
	if (y % 2 == 1) {
		return x * pow_mod(x, y - 1) % mod;
	}
	else {
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

ll com(ll x, ll y) {
	return kai[x] * div_mod(kai[y] * kai[x - y] % mod) % mod;
}

string S, T;
P par[3010][3010];
ll dp[3010][3010];
string ans;

void solve() {
	cin >> S >> T;
	for (int i = 0; i < S.length(); i++) {
		for (int j = 0; j < T.length(); j++) {
			if (S[i] == T[j]) {
				dp[i + 1][j + 1] = dp[i][j] + 1;
				par[i + 1][j + 1] = P(i, j);
			}
			else {
				if (dp[i][j + 1] > dp[i + 1][j]) {
					dp[i + 1][j + 1] = dp[i][j + 1];
					par[i + 1][j + 1] = P(i, j + 1);
				}
				else {
					dp[i + 1][j + 1] = dp[i + 1][j];
					par[i + 1][j + 1] = P(i + 1, j);
				}
			}
		}
	}
	ll num_s = S.length(), num_t = T.length();
	while (num_s > 0 && num_t > 0) {
		ll ns = par[num_s][num_t].f, nt = par[num_s][num_t].s;
		if (dp[num_s][num_t] != dp[ns][nt]) {
			ans = S[ns] + ans;
		}
		num_s = ns, num_t = nt;
	}
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	ll N;
	cin >> N;
}
////////////////////////////////////////////////////////////////////////////////////////////jagfhaoi;sd;joi;asdfjzasdi;lfjoi;ernjsdoivcnoizvdfnvdfnon/////////////////////////////////////////////////////////
////////////////////jgoiadhsjgoi;vsjvgfonhjasoivhoivhno

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

int main(){
  int n;
  cin >> n;
  vector<int> w(n);
  vector<int> c(n+1);
  int INF = 100*100;
  int res = INF;

  for(auto& term : w){
	cin >> term;  
  }
  for(int i = 1; i < n+1; i++){
    c[i] = c[i-1] + w[i-1];
  }
  for(int j = 0; j < n+1; j++){
	res = min(res, abs(c[n]-2*c[j]));
  }
  cout << res << endl;
}

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

using namespace std;

typedef long long ll;

#ifdef RED
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const int N = (int)1e6 + 5;
const int inf = (int)1e9 + 7;

int n;
int h[N], dp[N];

int main() {
#ifdef RED
  freopen("a.in", "r", stdin);
#endif
  ios_base :: sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> h[i];
  }
  dp[1] = 0;
  dp[2] = abs(h[2] - h[1]);
  for (int i = 3; i <= n; ++i) {
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
  }
  cout << dp[n] << "\n";
  return 0;
}


Measured memory_bytes: 4736
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    reverse(ALL(s));

    LL cnt[2020] = {1,0};
    LL sum = 0;
    LL x = 1;
    for(char c : s){
        LL a = c - '0';
        sum += a * x;
        sum %= 2019;
        x *= 10;
        x %= 2019;
        cnt[sum]++;
    }

    LL ans = 0;
    REP(i,2019){
        ans += cnt[i] * (cnt[i] - 1) / 2;
    }
    PUTS(ans);
}

Measured memory_bytes: 3704
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str = br.readLine();

		char c = str.charAt(0);

		if (Character.isUpperCase(c)) {
			System.out.println("A");
		} else {
			System.out.println("a");
		}
	}
}

Measured memory_bytes: 32532
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,m;
    cin >> a >> b >> m;
    vector <int> priceA(a),priceB(b),x(m),y(m),c(m);
    int niceA = -1,niceB = -1;
    int minA = -1, minB = -1;
    for(int i = 0; i < a; i++){
        cin >> priceA[i];
        if(i==0){
            minA = priceA[i];
            niceA = i;
        }else{
            if(minA>priceA[i]){
                minA = priceA[i];
                niceA = i;
            }
        }
    }
    for(int i = 0; i < b; i++){
        cin >> priceB[i];
        if(i==0){
            minB = priceB[i];
            niceB = i;
        }else{
            if(minB>priceB[i]){
                minB = priceB[i];
                niceB = i;
            }
        }
    }
    vector <int> couponedPrice(m);
    int ans = -1;
    for(int i = 0; i < m; i++){
        cin >> x[i] >> y[i] >> c[i];
        couponedPrice[i]=priceA[x[i]-1]+priceB[y[i]-1]-c[i];
        //cout << "couponed price " << couponedPrice[i] << endl;
        if(i==0){
            ans=couponedPrice[i];
        }else{
            ans=min(ans,couponedPrice[i]);
        }
    }
    ans=min(ans,priceA[niceA]+priceB[niceB]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5544