akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int t = sc.nextInt();

        int sum = 0;

        for (int i = 1; i < t + 1; i++) {
            if (i % a == 0) {
                sum += b;
            }
        }

        System.out.println(sum);
    }
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

const int MAX = 200005;
const ll INF = 1001001001001001001;
const int MOD = 1000000007;

struct dijkstra{
    struct edge {
        int to; long long cost;
        edge(int a, long long b) { to = a; cost = b; }
    };
    
    int V;
    vector<vector<edge>> G;
    vector<long long> d;
 
    dijkstra(int v) {
        V = v;
        G = vector<vector<edge>>(V);
        d = vector<long long>(V);
    }

    void addEdge(int from, int to, long long cost) {
        G[from].emplace_back(edge(to, cost));
    }

    vector<long long>& shortest_path(int s) {
        priority_queue<
            pair<long long, int>,
            vector<pair<long long, int>>,
            greater<pair<long long, int>>
        > que;
        for (long long& i : d) i = INF;
        d[s] = 0;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            auto p = que.top(); que.pop();
            int v = p.second;
            if (d[v] < p.first) continue;
            for (const edge& e : G[v]) {
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to], e.to));
                }
            }
        }
        return d;
    }
};

int main(){
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--, t--;

    dijkstra en(n), sn(n);
    rep(i, m) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--, v--;
        en.addEdge(u, v, a); en.addEdge(v, u, a);
        sn.addEdge(u, v, b); sn.addEdge(v, u, b);
    }

    auto &A = en.shortest_path(s);
    auto &B = sn.shortest_path(t);
    vector<ll> AB(n);
    rep(i, n) AB[i] = A[i] + B[i];

    vector<ll> dp(n+1);
    dp[n] = INF;
    repr(i, n) dp[i] = min(dp[i+1], AB[i]);

    rep(i, n) {
        ll ans = 1e15;
        ans -= dp[i];
        cout << ans << endl;
    }
}

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

int main(){
  int n;
  cin >> n;
  
  vector<int> L(n);
  for(int i = 0; i < n; i++){
    cin >> L[i];
  }
  
  sort(L.begin(), L.end());
  
  int cnt = 0;
  for(int i = 0; i < n; i++){
    for(int j = i; j < n; j++){
      for(int k = j; k < n; k++){
        if(L[i] == L[j] || L[j] == L[k]) continue;
        if(L[i] + L[j] > L[k]){
          cnt++;
        }
      }
    }
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 3628
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    touri=0
    for a in range(1,x//3):
        for b in range(a+1,x//2):
            c=x-a-b
            if b<c<=n:
                touri+=1
    print(touri)


Measured memory_bytes: 5596
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
constexpr long long MMOD = 500000004;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

int n;
int posx = 0, posy = 0;
int TT = 0;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int t, x, y;
		cin >> t >> x >> y;
		if ((abs(posx - x) + abs(posy - y)) % 2 != (t - TT) % 2) {
			cout << "No" << endl;
			return 0;
		}
		else if ((t - TT) < abs(posx - x) + abs(posy - y)) {
			cout << "No" << endl;
			return 0;
		}
		else {
			TT = t;
			posx = x;
			posy = y;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

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


/////////////////////////////////////////////////////////////////////////////////////////

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

    cin >> n;
    vector<int> b(n);
    int ans[3][3];
    
    for (int i = 0;i < n;i++) cin >> b[i];

    bool ok = false;
    for (int i = 0;i < 3;i++){
        for(int j = 0;j < 3;j++){
            ans[i][j] = 0;
            for (int k = 0;k < n;k++){
                if (a[i][j] == b[k]){
                    ans[i][j] = 1;
                    break;
                }
            }
        }
    }

    for (int i = 0;i < 3;i++){
        if (ans[i][0] == 1 and ans[i][1] == 1 and ans[i][2] == 1){
            ok = true;
        }

        if (ans[0][i] == 1 and ans[1][i] == 1 and ans[2][i] == 1){
            ok = true;
        }
    }

    if (ans[1][1] == 1 and ans[2][2] == 1 and ans[0][0] == 1){
        ok = true;
    }

    if (ans[0][2] == 1 and ans[1][1] == 1 and ans[2][0] == 1){
        ok = true;
    }

    if (ok) cout << "Yes" << endl; 
    else cout << "No" << endl;
}

Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}

	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	m := map[int]int{}

	ans := 0
	for i := 0; i < n; i++ {
		ans += m[i-aa[i]]
		m[aa[i]+i] = m[aa[i]+i] + 1
	}
	fmt.Fprintln(writer, ans)
}


Measured memory_bytes: 15640
#include <cstdio>
#include <cctype>
#include <utility>
#include <string>
using namespace std;

const auto gcu = getchar_unlocked;
const auto pcu = putchar_unlocked;
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;if(n<0)pcu('-'),n*=-1;
	if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10; while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	int n = in(), c = 0;
	string s, t;
	scan(s);
	while (n--) {
		scan(t);
		c += [&] {
			for (int i = 0; i <= (int) t.size() - (int) s.size(); i++)
				if (s[0] == t[i])
					for (int j = 1; i + j * (s.size() - 1) < t.size(); j++) {
						if ([&] {
							for (size_t k = 1; k < s.size() ; k++)
								if (t[i + j * k] != s[k])
									return false;
							return true;}())
							return 1;
					}
			return 0;
		}();
	}
	outl(c);
}


Measured memory_bytes: 2684
N = int(input())
NS = str(N)
if NS[len(NS) - 1] == "3":
  ans = "bon"
elif NS[len(NS) - 1] == "0":
  ans = "pon"
elif NS[len(NS) - 1] == "1":
  ans = "pon"
elif NS[len(NS) - 1] == "6":
  ans = "pon"
elif NS[len(NS) - 1] == "8":
  ans = "pon"
else:
  ans = "hon"
print(ans)

Measured memory_bytes: 9076
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int n;
vector<tuple<int,int,int>>a;
void solve(){
    int pti=0,pxi=0,pyi=0;
   rep(i,n)
   {
       int ti,xi,yi;
       tie(ti,xi,yi)=a[i];
       int t=ti-pti;
       int d=abs(pxi-xi)+abs(pyi-yi);
       if(d>t||t%2!=d%2){
           cout<<"No"<<endl;
           return;
       }
       pti=ti,pxi=xi,pyi=yi;
   }
     cout<<"Yes"<<endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>n;
    rep(i,n){
        int t,x,y;
        cin>>t>>x>>y;
        a.push_back(make_tuple(t,x,y));
    }
    solve();
    return 0;
}

Measured memory_bytes: 1912
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(L: int):
    print(pow(L/3, 3))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    L = int(next(tokens))  # type: int
    solve(L)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<cstdio>
typedef long long ll;
const ll mod=1e9+7;
ll dp[1000001][2][2];
int main()
{
	int n;
	scanf("%d",&n);
	dp[0][0][0]=1;
	for(int i=0;i<n;++i)
		for(int j=0;j<=1;++j)
			for(int k=0;k<=1;++k)
				dp[i+1][j][k]+=dp[i][j][k]*8,dp[i+1][j][k]%=mod,dp[i+1][j|1][k]+=dp[i][j][k],dp[i+1][j|1][k]%=mod,dp[i+1][j][k|1]+=dp[i][j][k],dp[i+1][j][k|1]%=mod;;
	printf("%lld",dp[n][1][1]);
} 

Measured memory_bytes: 32876
#include <cstdio>
#include <iostream>
#include <cstring>

using namespace std;

typedef long long ll;
const int MAXN = 10010;
const int MAXD = 110;
const int MOD = 1e9+7;

char s[MAXN];
int n, d;

inline int add(int x, int y){return (x += y) >= MOD ? x - MOD : x;}
inline int sub(int x, int y){return (x -= y) < 0 ? x+MOD : x;}

int f[MAXN][MAXD][2];
bool vis[MAXN][MAXD][2];

int dfs(int x, int y, bool lim)
{
	if(x > n) return (y == 0);
	if(vis[x][y][lim]) return f[x][y][lim];
	int maxd = lim ? s[x] - '0' : 9;
	for(int i = 0; i <= maxd; i++){
		f[x][y][lim] = add(f[x][y][lim], dfs(x + 1, (y + i) % d, ((i == maxd) && lim) ) );
	}
	vis[x][y][lim] = 1;
	return f[x][y][lim];
}

int main()
{
	scanf("%s%d",s+1 ,&d);
	n = strlen(s+1);
	printf("%d\n",sub(dfs(1, 0, 1), 1));
	return 0;
}

Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
class Dijk{
    private:
        ll n;
        vector<vector<pair<ll, ll>>> v;
    public:
        const ll INF = 5e15;
        
        Dijk(const vector<vector<pair<ll, ll>>> &v){
            this->n = v.size();
            this->v = v;
        }
        
        vector<ll> dijk(ll start){
            vector<ll> d(n, INF);
            d[start] = 0;
            priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, function<bool(pair<ll, ll>, pair<ll, ll>)>> q([&](pair<ll, ll> a, pair<ll, ll> b){return a.second > b.second;});
            q.push(pair<ll, ll>(start, 0));
            while(q.size()){
                pair<ll, ll> now = q.top();
                q.pop();
                if(d[now.first] < now.second){
                    continue;
                }
                for(auto next : v[now.first]){
                    if(d[next.first] == INF || d[now.first] + next.second < d[next.first]){
                        d[next.first] = d[now.first] + next.second;
                        q.push(pair<ll, ll>(next.first, d[now.first] + next.second));
                    }
                }
            }
            return d;
        }
};
int main(){
    ll n, m, s, t;
    cin >> n >> m >> s >> t;
    vector<vector<pair<ll, ll>>> V(n), U(n);
    for(ll i = 0; i < m; i++){
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        V[--v].push_back(pair<ll, ll>(--u, a));
        V[u].push_back(pair<ll, ll>(v, a));
        U[v].push_back(pair<ll, ll>(u, b));
        U[u].push_back(pair<ll, ll>(v, b));
    }
    Dijk D1(V), D2(U);
    vector<ll> po = D1.dijk(--s), yo = D2.dijk(--t);
    vector<ll> tmp(n);
    for(ll i = 0; i < n; i++) tmp[i] = po[i] + yo[i];
    vector<ll> ans(n);
    ans[n - 1] = tmp[n - 1];
    for(ll i = n - 2; i >= 0; i--) ans[i] = min(ans[i + 1], tmp[i]);
    for(ll e : ans) cout << (ll)1e15 - e << endl;
    return 0;
}



Measured memory_bytes: 33664
from bisect import bisect_left
s= input()
t = input()

d = {}
n = len(s)
ans = 0
for i in range(len(s)):
    if s[i] not in d:
        d[s[i]] = [i+1]
    else:
        d[s[i]].append(i+1)

flag = True
bef = 0
befchar = ""
for c in t:
    if c not in d:
        flag = False
        break
    else:
        if c == befchar:
            temp = bisect_left(d[c],bef)
            # print(temp)
            if temp == len(d[c]):
                temp = d[c][0]
                ans += temp + (n-bef)
                bef = temp
            else:
                if temp +1 < len(d[c]):
                    temp = d[c][temp+1]
                    ans += temp-bef
                    bef = temp
                else:
                    temp = d[c][0]
                    ans += temp + (n - bef)
                    bef = temp
        else:
            temp = bisect_left(d[c],bef)
            if temp == len(d[c]):
                temp = d[c][0]
                ans += temp + (n-bef)
                bef = temp
            else:
                temp = d[c][temp]
                ans += temp-bef
                bef = temp
    # print(temp)
    befchar=c
    # print(ans)
# print(d)
if flag:
    print(ans)
else:
    print(-1)




# arr = [0,2,4]
# print(bisect_left(arr,2))
# print(bisect_left(arr,4))
# print(bisect_left(arr,5))



Measured memory_bytes: 7540
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#define bogo_sort std::sort
#define bozo_sort std::stable_sort
#define alles(obj) obj.begin(), obj.end()
#define elif else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo std::cout <<
#define read std::cin >>
#define endl std::endl
#define fin << '\n'
#define bash push_back
#define makePair std::make_pair
#define _ << ' ' <<
// type-define
#define Stack std::stack
#define Queue std::queue
#define Set std::set
#define PQueue std::priority_queue
#define Vector std::vector
#define Pair std::pair
#define Map std::map
#define HashMap std::unordered_map
#define Greater std::greater
using String = std::string;
using llong = long long;
using boolean = bool;
using Pii = Pair<int, int>;
using Vi = Vector<int>;
using Vii = Vector<Pii>;
// utils
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    template<class A, class B> A power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    template<class A, class B> A power ( A x, B n ) { return power( x, n, 1000000007 ); }
    template<class A> A gcd ( A x, A y ) { return x % y ? gcd( y, x % y ) : y; }
    template<class A, class B> A lcm ( A x, B y ) { return ( x / gcd(x, y) * y ); }
    template<class A> inline A abs ( A n ) { return ( n < 0 ) ? -n : n; }
    template<class A, class B> inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B> inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    

    signed call_of_Cthulhu( signed datum ) {

        int n;
        read n;
            int i;
        for ( i = 111; i < n; i+=111) {
        }
        echo i fin;

        return 0;
    }
}
signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


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

using namespace std;

int main()
{
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < 4; i++)
	{
		if (s[i] == '+')
			ans++;
		else
			ans--;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc119/tasks/abc119_d
import itertools
import collections
import bisect

def main():
    # big value
    INF = int(1e15)
    A, B, Q = map(int, input().split())
    S = [-INF] + [int(input()) for _ in range(A)] + [INF]
    T = [-INF] + [int(input()) for _ in range(B)] + [INF]
    X = [int(input()) for _ in range(Q)]

    for x in X:
        pos_s = bisect.bisect(S, x)  # xより大きい S の最小値のインデックス
        pos_t = bisect.bisect(T, x)  # xより大きい T の最小値のインデックス
        s1, s2 = S[pos_s - 1], S[pos_s]
        t1, t2 = T[pos_t - 1], T[pos_t]

        ans = INF
        for st, tt in itertools.product([s1, s2], [t1, t2]):
            path1 = abs(x - st) + abs(st - tt)
            path2 = abs(x - tt) + abs(st - tt)
            ans = min(ans, path1, path2)
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 16480
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    all_evens = True
    for _ in range(N):
        a = read_int()
        all_evens = all_evens and a%2 == 0
    if all_evens:
        return 'second'
    return 'first'


if __name__ == '__main__':
    print(solve())


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long a, b, x;
  cin >> a >> b >> x;
  cout << (b / x) - (a % x ? a / x : a / x - 1) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int a[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
    int k; cin >> k;
    cout << a[k - 1] << "\n";
}


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


long long a;
long long b;
long long c;
int suc = 0;
int A = 0;


int main()
{
	int L;

	cin >> L;

	long double v = pow((long double)L / 3, (long double)3);
	
	
	cout << fixed << setprecision(6) << v << endl; 
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define MIN INT_MIN
#define MAX INT_MAX
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define E "\n"
#define frep(i,j,k,inc) for(int i=j;i<k;i+=inc)
#define rrep(i,j,k,dec) for(int i=j;i>k;i-=dec)
#define arep(elm,obj) for(auto elm:obj)
#define all(x) x.begin(),x.end()
#define revT greater<int>()
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int>pii;
const ll mod=1000000007;
void solve();
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    int t;
//    cin>>t;
//    while(t--)
    	solve();

    return 0; 
}

int mima(vi vec,int f){
	int mi=vec[0],ma=vec[0];
	frep(i,1,vec.size(),1){
		mi=min(mi,vec[i]);
		ma=max(ma,vec[i]);
	}
	if(f){return ma;}
	else{return mi;}
}


void solve(){
	int h,w,k;
	cin>>h>>w>>k;
	string arr[h];
	frep(i,0,h,1){
		cin>>arr[i];
	}
	int ans=0;
	frep(R,0,(1<<h),1){
		frep(C,0,(1<<w),1){
			int b=0;
			frep(i,0,h,1){
				frep(j,0,w,1){
					if(R &(1<<i))continue;
					if(C &(1<<j))continue;
					if(arr[i][j]=='#')b++;
				}
			}
			if(b==k){
				ans++;
			}
		}
	}
	cout<<ans<<E;
}

Measured memory_bytes: 3648
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
#N, K = map(int, input().split())
# 文字列の入力
s = list(input())
t = list(input())
#開業されたN個要素を受け付ける
#list = [input() for i in range(N)]
s = sorted(s)
t = reversed(sorted(t))

strs = "".join(s)
strt = "".join(t)

if strs < strt:
    print("Yes")
else:
    print("No")


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

int a,b,c,d,s1,s2;

int main()
{
	cin>>a>>b>>c>>d;
	s1=(a+d-1)/d,s2=(c+b-1)/b;
	if(s1<s2) cout<<"No\n";
	else cout<<"Yes\n";
}

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    long long N, u, v, ans;
    cin >> N;
    ans = (N * (N+1) * (2*N+1) / 6 + N * (N+1) / 2) / 2;
    for(int i=0;i<N-1;++i) {
        cin >> u >> v;
        if(u < v) ans -= u*(N-v+1);
        else ans -= v*(N-u+1);
    }
    cout << ans << endl;
}


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

int n;
vector<long long> a;
int ans;

int main(){
        //      cin.tie(0);
        //      ios::sync_with_stdio(false);
        cin >> n;
        for(int i=0; i<n; ++i){
                long long t;
                cin >> t;
                a.push_back(t);
        }
        sort(a.begin(), a.end());
        vector<long long> b(a);
        for(int i=1; i<n; ++i)
                b[i] += b[i-1];
//      for(int i=0; i<n; ++i)
//              cout << b[i] << " ";
//      cout << "\n";
        ans = 1;
        for(int i=n-1; i>=0; --i){
                if(2 * b[i] >= a[i+1])
                        ans = n - i;
                else break;
        }
        cout << ans << "\n";
}

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

typedef long long int ll;

int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    map<int,int>counter;
    counter[a]++;
    counter[b]++;
    counter[c]++;
    printf("%d\n",counter.size());
    return 0;
}


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

class Progaram
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var line = Console.ReadLine().Split(' ')
            .Select(x => int.Parse(x)).ToList();
        var sline = line.Select(x => x).OrderBy(x => x).ToList();
        int c = 0;
        for (var i = 0; n > i; i++)
        {
            if (line[i] != sline[i]) c++;
        }
        if (c <= 2) Console.WriteLine("YES");
        else Console.WriteLine("NO");
    }
}

Measured memory_bytes: 13396
import math
import os 
def main(): #get the driver code
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    mod = 10**9+7
 
    a.sort()
    ret = 1
    if k % 2 == 0 or a[-1] >= 0:
        l = 0
        r = -1
        mlt1 = a[0] * a[1]
        mlt2 = a[-2] * a[-1]
        for _ in range(k//2):
            if mlt1 >= mlt2:
                ret *= mlt1 % mod
                l += 2
                if l <= n-2:
                    mlt1 = a[l+1] * a[l]
            else:
                ret *= mlt2 % mod
                r -= 2
                if r >= -n+1:
                    mlt2 = a[r-1] * a[r]
            ret %= mod
 
        if k % 2 == 1:
            ret *= a[r]
            ret %= mod
 
    else:
        for i in range(k):
            ret *= a[n-1-i]
            ret %= mod
 
    print(ret)
 
 
if __name__ == '__main__':
    main()
	

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n, a;
  cin >> n >> a;
  vector<int> x(n);
  rep(i, n) cin >> x[i];
  

  vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(n+1, vector<ll>(2600, 0ll)));
  rep(i, n+1) rep(j, n+1) rep(s, 2600) dp[i][j][s] = 0;

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

  rep(i, n) {
    for(int j = 0; j <= n; ++j) {
      for(int s = 0; s <= 2500; ++s) {
        if(j > 0 && s-x[i] >= 0) dp[i+1][j][s] += dp[i][j-1][s-x[i]];
        dp[i+1][j][s] += dp[i][j][s];
      }
    }
  }

  ll ans = 0;
  for(int i = 1; i <= n; ++i) ans += dp[n][i][a*i];
  cout << ans << endl;
}

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

int main(){
    int n;
    cin >> n;
    string s[n];
    int t[n];
    for(int i=0;i<n;i++){
        cin >> s[i] >> t[i];
    }
    string x;
    cin >> x;
    bool isSleep = false;
    int ans = 0;
    for(int i=0;i<n;i++){
        if(s[i] == x)isSleep = true;
        if(isSleep == true && s[i] != x){
            ans += t[i];
        }
    }
    cout << ans;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt();
        int x = (int)Math.ceil((double)c / b);
        System.out.println(d * (x - 1) < a ? "Yes" : "No");
    }
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, K;
  IN(N,K);
  vll A(N);
  REP(i,N) IN(A[i]);

  for(ll i=K; i<N; ++i){
    if(A[i]>A[i-K]){
      OUT("Yes");
    }else{
      OUT("No");
    }
  }

  return 0;
}

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

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> p;
    for (int i = 0; i < N; ++i)
    {
        int temp;
        cin >> temp;
        p.push_back(temp);
    }
    sort(p.begin(), p.end());
    ll ans = 0;
    for (int i = 0; i < K; ++i)
    {
        ans += p[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3612
X = int(input())
if X == 2:
  y = 2
elif X%2 ==0:
  y = X+1
else:
  y = X
Flag = True
while Flag == True:
  a = int(y**(1/2))
  t = 0
  for i in range(2,a):
    if y % i == 0:
      t = 1
  if t == 0:
    Flag = False
  y += 1
print(y-1)

Measured memory_bytes: 3064
from itertools import product
s = input()
n = len(s)
ans = 0
for lst in product(['x', ' '], repeat=n-1):
    ss = ''
    for i in range(n-1):
        ss += (s[i] + str(lst[i]))
    ss += s[-1]
    ss = ss.replace('x', '')
    temp = [int(x) for x in ss.split()]
    ans += sum(temp)
print(ans)

Measured memory_bytes: 9132
n, k =map(int, input().split())
dt = sorted(tuple(map(int, input().split()))[::-1] for _ in range(n))[::-1]
r = v = 0
a = []
s = set()
for i, (d,t) in enumerate(dt, 1):
    if t in s:
        if i <= k:
            a.append(d)
            v += d
    else:
        if i > k:
            if not a:
                break
            v -= a.pop()
        v += d
        s.add(t)
    r = max(r, len(s)**2+v)
print(r)

Measured memory_bytes: 19188
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>

#line 1 "lib/modint.hpp"



#include <iostream>

// Modint
struct Mint {
    static const long long mod = (long long)1e9 + 7;
    long long val;

    Mint() { val = 0; }
    Mint(long long a) { val = a; verify_value(); }

    void verify_value() {
        if (val >= mod) val %= mod;
        if (val < 0) val %= mod, val += mod;
    }

    Mint pow(long long p) const {
        Mint cur = Mint(val), ret = 1;
        while (p > 0) {
            if (p & 1) ret *= cur;
            cur *= cur;
            p >>= 1LL;
        }
        return ret;
    }
    Mint inv() const {
        if (val == 0)
            std::cerr << "WARNING: inv() is called with 0." << std::endl;
        return pow(mod - 2);
    }

    Mint operator+() const { return *this; }
    Mint operator-() const { return Mint(mod - val); }

    Mint operator+=(const Mint &a) {
        val += a.val;
        if (val >= mod) val -= mod;
        return Mint(val);
    }
    Mint operator*=(const Mint &a) {
        val *= a.val;
        if (val >= mod) val %= mod;
        return Mint(val);
    }
    Mint operator-=(const Mint &a) { return *this += -a; }
    Mint operator/=(const Mint &a) { return *this *= a.inv(); }

    Mint operator++() { return *this += Mint(1); }
    Mint operator--() { return *this -= Mint(1); }
    Mint operator++(int) {
        Mint ret = *this;
        ++(*this);
        return ret;
    }
    Mint operator--(int) {
        Mint ret = *this;
        --(*this);
        return ret;
    }

    operator long long() const { return val; }
};

Mint operator+(const Mint &a, const Mint &b) {
    long long ret = a.val + b.val;
    if (ret >= Mint::mod) ret -= Mint::mod;
    return Mint(ret);
}
Mint operator*(const Mint &a, const Mint &b) {
    long long ret = a.val * b.val;
    if (ret >= Mint::mod) ret %= Mint::mod;
    return Mint(ret);
}
Mint operator-(const Mint &a, const Mint &b) { return a + (-b); }
Mint operator/(const Mint &a, const Mint &b) { return a * b.inv(); }

std::ostream &operator<<(std::ostream &out, const Mint &a) { return out << a.val; }
std::istream &operator>>(std::istream &in, Mint &a) {
    in >> a.val;
    a.verify_value();
    return in;
}

Mint pow(Mint a, long long b) {
    return a.pow(b);
}         


int main() {
    int n; std::cin >> n;
    std::vector<int> x(n);
    for (int i = 0; i < n; i++) std::cin >> x[i];
    Mint ans = 1, cnt = 1;
    x[0] = 1;
    for (int i = 0; i < n - 1; i++) {
        if (x[i + 1] - x[i] > 1) {
            x[i + 1] = x[i] + 2;
            ans *= ++cnt;
        }
        else {
            x[i + 1] = x[i];
            ans *= cnt + Mint(1);
        }
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int( 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17);


signed main(){
    int a,b,q;
    cin >> a >> b >> q;
    pair<int,int> A[MAX],B[MAX];
    REP(i,a){
        scanf("%lld",&(A[i+1].fi) );
    }
    REP(i,b) scanf("%lld",& (B[i+1].fi) );
    A[0].fi = -INF;
    B[0].fi = - INF;
    A[0].se = INF;
    B[0].se = INF;
    A[a+1].fi = INF;
    B[b+1].fi = INF;
    A[a+1].se = INF;
    B[b+1].se = INF;

    int id = 0;
    while( A[1].fi > B[id + 1].fi ) id ++;
    FOR(i,1,a+1){
        while( A[i].fi > B[id+1].fi) id ++;
        A[i].se = min( abs (A[i].fi - B[id].fi) , abs(A[i].fi - B[id +1].fi));
    }



    id = 0;
    while( B[1].fi > A[id + 1].fi ) id ++;
    FOR(i,1,b+1){
        while( B[i].fi > A[id+1].fi) id ++;
        B[i].se = min( abs (B[i].fi - A[id].fi)  , abs(B[i].fi - A[id +1].fi));
    }







    REP(i,q){
        int tmp;
        scanf("%lld",&tmp);
        int ng = 0,ok = a+1;
        while(ng + 1 < ok){
            int mid = (ng + ok)/ 2;
            if( A[mid].fi < tmp) ng = mid;
            else ok = mid; 
        }
        int a_id = ok-1;
        ng = 0;
        ok = b+1;
        while(ng + 1 < ok){
            int mid = (ng + ok)/ 2;
            if( B[mid].fi < tmp) ng = mid;
            else ok = mid; 
        }        
        int b_id = ok-1;

        int ans = min( abs(tmp-A[a_id].fi) + A[a_id].se , abs(tmp-B[b_id].fi) + B[b_id].se);
        ans = min( ans , abs(tmp - A[a_id +1].fi) + A[a_id +1].se);
        ans = min( ans , abs(tmp-B[b_id +1].fi) + B[b_id+1].se );
/*
        int ans = INF;
        FOR(j,a_id , a_id +2){
            FOR(k,b_id , b_id + 2){
                int res = min( abs(A[j].fi-tmp) + abs(A[j].fi - B[k].fi), abs(B[k].fi-tmp)+ abs(A[j].fi - B[k].fi) );
                ans = min(ans,res);
            }
        } 
*/ 
        printf("%lld\n",ans);
    }

}

Measured memory_bytes: 4480
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
//const int mod=(int)1e9+7;

const llint big=(llint)(2.19e15+1)*18;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
#define dme cout<<"-1\n";return 0
int main(void){
	int n,i;cin>>n;
	map<pair<int,int>,int>ban;
	for(i=0;i<n;i++){
		int a,b;cin>>a>>b;
		if((i==0)^(a==0)){dme;}
		if((i==1)^(b==0)){dme;}
		ban[mp(a+b,a)]++;
	}
	//dpで解く
	int ans=-2,sen=0;
	pair<int,int>maebas=mp(-1,-1);
	for(auto it:ban){
		int a=it.fir.sec;
		int b=it.fir.fir-a;
		int kaz=it.sec;
		if(kaz==0){continue;}
		if(!(maebas.fir==it.fir.fir&&maebas.sec+1==it.fir.sec)){sen=0;}//前と連結してない
		if(ban[mp(a-1+b-1,a-1)]>0){ans+=kaz;mineq(sen,kaz);}//接続あり
		else{
			ans+=kaz;ans+=max(0,kaz-sen);sen=kaz;
			if(ban[mp(a-1+b,a-1)]+ban[mp(a+b,a-1)]==0&&a>0&&b>0){dme;}
			if(ban[mp(a+b-1,a)]+ban[mp(a+b,a+1)]==0&&a>0&&b>0){dme;}
		}
		maebas=it.fir;
		
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007

vector<int>answer[200001];
int storeIt[200001];
int v[200001];


void dfs(int node){
  vector<int> pushIt;
  int i;
  pushIt.push_back(node);
  while(1){
    int temp=pushIt.size();
    if(temp==0){
      break;
    }
    for(i=0;i<temp;i++){
      int node=pushIt[i];
      for(int j=0;j<answer[node].size();j++){
        if(storeIt[answer[node][j]]==0){
          pushIt.push_back(answer[node][j]);
          storeIt[answer[node][j]]=node;
        }
      }
    }    
    while(temp--){
      pushIt.erase(pushIt.begin());
    }
  }
}

int main(){
  FIO;
  // ifstream cin("input");
  int n,m;
  cin>>n>>m;
  int x,y;
  int i;
  for(i=1;i<=n;i++){
    v[i]=0;
    storeIt[i]=0;
  }
  while(m--){
    cin>>x>>y;
    answer[x].push_back(y);
    answer[y].push_back(x);
  }
  int flag=0;
  dfs(1);
  for(i=2;i<n;i++){
    if(storeIt[i]==0){
      flag=1;
      break;
    }
  }
  if(flag==1){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
  for(i=2;i<=n;i++){
    cout<<storeIt[i]<<endl;
  }
  return 0;  
}

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

int main() {
 string S;
 int n,cnt0=0,cnt1=0,a;
 cin >> S;
 n = S.size();
 vector<int> num(n);
 for(int i=0;i<n;i++){
  num[i] = S[i]-'0';
   if(num[i]==0){
    cnt0++;
   }
   else{
    cnt1++;
   }
 }

 a=min(cnt0,cnt1);
 cout << 2*a << endl;

}

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

////////////// Prewritten code follows. Look down for solution. ////////////////
#define x first
#define y second
#define len(x) ((int)(x).size())
using pii = pair<int, int>;
using ll = long long;
using llu = long long unsigned;
using ld = long double;

const ld EPS = 1e-9;
inline int cmp(ld x, ld y = 0, ld tol = EPS) {
	return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

const int MOD = 1;
inline int mod (ll x, int m = MOD) {
	return (int)(((x%m) + m)%m);
}

////////////////////////// Solution starts below. //////////////////////////////

const int N = 102, K = 1e5+10;

int n;
int a[N];
int dp[K];

bool solve (int k) {
	int &r = dp[k];
	if (r != -1) return r;
	for (int i = 1; i <= n; i++)
		if (k-a[i] >= 0 and !solve (k-a[i]))
			return r = 1;
	return r = 0;
}

int main () {
	memset (dp, -1, sizeof dp);
	int k;
	scanf ("%d %d", &n, &k);
	for (int i = 1; i <= n; i++)
		scanf ("%d", &a[i]);
	printf ("%s\n", solve (k) ? "First" : "Second");
	
	return 0;
}


Measured memory_bytes: 3712