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

public class Main
{
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok;

    int MOD = 1000000007;

    public void go() throws IOException
    {
        long[] fact = new long[100005];
        fact[0] = 1;
        for (int i = 1; i < fact.length; i++)
        {
            fact[i] = i * fact[i-1] % MOD;
        }
        ntok();
        int n = ipar();
        ntok();
        char[] line = spar().toCharArray();
        if (possible(line, 0, 0))
        {
            int c = 0;
            long ans = 1;
            for (int i = 0; i < 2*n; i++)
            {
                if (line[i] == '(')
                {
                    c++;
                }
                else
                {
                    ans *= c;
                    ans %= MOD;
                    c--;
                }
            }
            out.println(ans * fact[n] % MOD);
        }
        else
        {
            out.println(0);
        }

        out.flush();
        in.close();
    }

    public long inverse(long n)
    {
        return modPow(n, MOD-2);
    }

    public long modPow(long n, int p)
    {
        if (p == 0)
        {
            return 1;
        }
        long pow = modPow(n*n%MOD, p/2);
        if (p%2 == 1)
        {
            pow *= n;
            pow %= MOD;
        }
        return pow;
    }

    public boolean possible(char[] line, int i, int c)
    {
        if (c < 0)
        {
            return false;
        }
        if (i == line.length)
        {
            return c == 0;
        }
        if (c % 2 == 0)
        {
            if (line[i] == 'B')
            {
                line[i] = '(';
                return possible(line, i+1, c+1);
            }
            else
            {
                line[i] = ')';
                return possible(line, i+1, c-1);
            }
        }
        else
        {
            if (line[i] == 'W')
            {
                line[i] = '(';
                return possible(line, i+1, c+1);
            }
            else
            {
                line[i] = ')';
                return possible(line, i+1, c-1);
            }
        }
    }

    public void ntok() throws IOException
    {
        tok = new StringTokenizer(in.readLine());
    }

    public int ipar()
    {
        return Integer.parseInt(tok.nextToken());
    }

    public long lpar()
    {
        return Long.parseLong(tok.nextToken());
    }

    public double dpar()
    {
        return Double.parseDouble(tok.nextToken());
    }

    public String spar()
    {
        return tok.nextToken();
    }

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


Measured memory_bytes: 44292
#include <stdio.h>

int main(void){
    int a,b;
    
    scanf("%d %d",&a,&b);
    
    if(a < b)
        printf("a < b\n");
    else if(a > b)
        printf("a > b\n");
    else
        printf("a == b\n");
   
    return 0;
}



Measured memory_bytes: 2112
import java.util.*;
import java.io.*;
public class Main 
{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader (System.in));
		long n = Long.parseLong(br.readLine()), ans = 0;
		if (n % 2 == 1) System.out.println(0);
		else {
			for (long cur = 10; cur <= n; cur *= 5) {
				ans += n / cur;
			}
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 32536
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i = l; i < (n); i++)
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,0,n) cin >> a.at(i);
  rep(i,0,n) {
    int tmp = a.at(i);
    if(tmp%2 == 0 && (tmp%3 == 0 || tmp%5 == 0));
    else if(tmp%2 == 0){
      printf("DENIED\n");
      return 0;
    }
  }
  printf("APPROVED\n");
  return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = 1
    is_add = False
    is_minus = False
    tmp = A[0]
    for a in A[1:]:
        if tmp > a:
            if is_add:
                ans += 1
                is_add = False
            else:
                is_minus = True
        elif tmp < a:
            if is_minus:
                ans += 1
                is_minus = False
            else:
                is_add = True
        tmp = a
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14252
H,W,K=map(int,input().split())
dp=[[0]*W for i in range(H+1)]
dp[0][0]=1
if W==1:
  print(1)
  exit()
  
import itertools
A=list(itertools.product([0,1], repeat=W-1))

B=[]
for i in A:
  x=0
  for j in range(W-2):
    if i[j]==1 and i[j+1]==1:
      x=1
  if x==0:
    B.append(i)

D=[[0,0,0] for i in range(W)]
for i in B:
  for j in range(W-1):
    if i[j]==1:
      D[j+1][0]+=1
      D[j][2]+=1
    if j==0 and i[j]==0:
      D[j][1]+=1
    if j==W-2 and i[j]==0:
      D[j+1][1]+=1
    if j<W-2:
      if i[j]==0 and i[j+1]==0:      
        D[j+1][1]+=1
dp=[[0]*W for i in range(H+1)]
mod=10**9+7
dp[0][0]=1
for i in range(H):
  for j in range(W):
    if j==0:
      dp[i+1][j]=dp[i][j]*D[j][1]+dp[i][j+1]*D[j][2]
    elif j==W-1:
      dp[i+1][j]=dp[i][j]*D[j][1]+dp[i][j-1]*D[j][0]
    else:
      dp[i+1][j]=dp[i][j]*D[j][1]+dp[i][j-1]*D[j][0]+dp[i][j+1]*D[j][2]
    dp[i+1][j]%=mod
print(dp[-1][K-1])

Measured memory_bytes: 63172
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            BIT bit = new BIT(n);

            int q = in.nextInt();
            for (int i = 0; i < q; i++) {
                int com = in.nextInt();
                int x = in.nextInt();
                int y = in.nextInt();

                if (com == 0) {
                    bit.add(x, y);
                } else {
                    out.println(bit.sum(y) - bit.sum(x - 1));
                }
            }
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

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

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }

    static class BIT {
        int n;
        int[] bit;

        public BIT(int n) {
            this.n = n;
            bit = new int[n + 1];
        }

        public int sum(int i) {
            int s = 0;
            while (i > 0) {
                s += bit[i];
                i -= i & -i;
            }
            return s;
        }

        public void add(int i, int x) {
            while (i <= n) {
                bit[i] += x;
                i += i & -i;
            }
        }

    }
}

Measured memory_bytes: 63932
n,m=map(int,input().split())
menu=[True]*m

for i in range(n):
  amenu=[False]*m # その人のリスト　すべてFalse
  a=list(map(int,input().split()))
  a.pop(0)
  for j in range(len(a)):
    amenu[a[j]-1]=True # 含まれていればTrueにする
    
  for p in range(len(amenu)):
    if amenu[p]==False:
      menu[p]=False

count=0
for i in range(len(menu)):
  count = count + menu[i]

print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int mINF = 1e9;
const int MOD = 1e9+7;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(){
    int n,k,q;
    vector<int> a;
    cin >> n >> k >> q;
    rep(i,q){
        int tmp;cin >> tmp;
        a.push_back(tmp);
    }
    if(k > q){
        rep(i,n)cout << "Yes" << endl;
        return 0;
    }else{
        vector<int> point(n,k-q);
        rep(i,q){
            point[a[i]-1]++;
        }
        rep(i,n){
            cout << (point[i] >= 1 ? "Yes" : "No") << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1400
//Author:xht37
#include <bits/stdc++.h>

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << (x) << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

int main() {
	int n, a, b;
	rd(n, a, b);
	prints((a ^ b) & 1 ? "Borys" : "Alice");
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vl;
typedef vector<int> vi;
#define PB push_back
#define MP make_pair
#define ln "\n"
#define forn(i,e) for(ll i=0; i<e; i++)
#define forsn(i,s,e) for(ll i=s; i<e; i++)
#define rforn(i,e) for(ll i=e; i>=0; i--)
#define rforsn(i,s,e) for(ll i=e; i>=s; i--)
#define vasort(v) sort(v.begin(), v.end())
#define vdsort(v) sort(v.begin(), v.end(),greater<int>())
#define F first
#define S second

#define out1(x1) cout << x1 << ln
#define out2(x1,x2) cout << x1 << " " << x2 << ln
#define out3(x1,x2,x3) cout << x1 << " " << x2 << " " << x3 << ln
#define out4(x1,x2,x3,x4) cout << x1 << " " << x2 << " " << x3 << " " << x4 << ln
#define out5(x1,x2,x3,x4,x5) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << ln
#define out6(x1,x2,x3,x4,x5,x6) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << " " << x6 << ln

#define in1(x1) cin >> x1
#define in2(x1,x2) cin >> x1 >> x2
#define in3(x1,x2,x3) cin >> x1 >> x2 >> x3
#define in4(x1,x2,x3,x4) cin >> x1 >> x2 >> x3 >> x4
#define in5(x1,x2,x3,x4,x5) cin >> x1 >> x2 >> x3 >> x4 >> x5
#define in6(x1,x2,x3,x4,x5,x6) cin >> x1 >> x2 >> x3 >> x4 >> x5 >> x6

#define arrin(a,n) forn(i,n) cin >> a[i];
#define arrout(a,n) forn(i,n) {cout << a[i] << " ";} cout << ln;

#define zoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


int main(){
    ll n,k;
    in2(n,k);
    vl h;
    h.PB(0);
    forn(i,n){
        ll input;
        in1(input);
        h.PB(input);
    }
    ll a[n+1];
    a[1]=0;
    for(ll i=2;i<=n;i++){
        a[i]=INFINITY;
        for(ll j=1;j<=k;j++) {
            if (i - j >= 1) {
                a[i] = min(a[i - j] + abs(h[i] - h[i - j]), a[i]);
            }else break;
        }
    }
    out1(a[n]);
    return 0;
}

Measured memory_bytes: 1908
/*
* @Author: key
* @Date:   2016-03-07 20:53:16
* @Last Modified by:   key
* @Last Modified time: 2016-03-07 22:13:15
*/

#include <iostream>
#include <queue>
#define MAX 1005
#define INF 100000000

using namespace std;

typedef struct{
    int x;
    int y;
    int state;
} Mouse;

int H,W,N;
int start_x,start_y;
char ar[MAX][MAX];
int offset_x[4] = {1,0,-1,0};
int offset_y[4] = {0,1,0,-1};
int ans[MAX][MAX];

void init(){
    for(int i = 0; i < H; i++)
        for(int j = 0; j < W; j++)
            ans[i][j] = -INF;
}

void bfs(){

    Mouse m;
    m.x = start_x;
    m.y = start_y;
    m.state = 1;

    init();

    ans[start_y][start_x] = 0;

    queue<Mouse> q;
    q.push(m);

    while(q.size()){
        Mouse m1 = q.front();
        q.pop();
        for(int i = 0; i < 4; i++){
            int dx = m1.x + offset_x[i];
            int dy = m1.y + offset_y[i];
            bool flag = true;
            if(dx >= 0 && dx < W && dy >= 0 && dy < H && ar[dy][dx] != 'X' && ans[dy][dx] == -INF){
                Mouse m2;
                m2.x = dx;
                m2.y = dy;

                ans[dy][dx] = ans[m1.y][m1.x] + 1;

                if(m1.state == (ar[dy][dx] - '0')){
                    int temp = ans[m1.y][m1.x] + 1;
                    init();
                    ans[dy][dx] = temp;
                    m2.state = m1.state + 1;

                    if(m1.state == N){
                        cout << ans[dy][dx] << endl;
                        return;
                    }
                    ar[dy][dx] == '.';
                    while(!q.empty()){
                        q.pop();
                    }
                    flag = false;
                }else{
                    m2.state = m1.state;
                }
                q.push(m2);
                if(!flag) break;
            }
        }
    }




}



int main(){

    while(cin >> H >> W >> N){
        for(int i = 0; i < H; i++){
            cin >> ar[i];
            for(int j = 0; j < W; j++){
                if(ar[i][j] == 'S'){
                    start_y = i;
                    start_x = j;
                }
            }
        }
        bfs();
        break;
    }

 return 0;
}

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

int main(){
    int n, a, b, c, d;
    string s;
    string block_2, space_3;
    block_2 = "##";
    space_3 = "...";
    cin >> n >> a >> b >> c >> d;
    cin >> s;
    n -= 1;
    a -= 1;
    b -= 1;
    c -= 1;
    d -= 1;

    string s_s = s.substr(a, (c - a) + 1);
    string s_f = s.substr(b, (d - b) + 1);

    string ans;
    if (s_s.find(block_2) == string::npos and s_f.find(block_2) == string::npos){
        if(c > d){
            /*string S = s.substr(b - 1, min((d - b) + 2, n));
            //cout << S << endl;
            if (S.find(space_3) == string::npos){
                ans = "No";
            }
            else{
                ans = "Yes";
            }*/

            for (int i = b; i <= d; i ++){
                if (s[i-1] == '.' && s[i] == '.' && s[i+1] == '.'){
                    ans = "Yes";
                    break;
                }
                else{
                    ans = "No";
                }
            }
        }
        else{
            //cout << c << " " << d << endl;
            ans = "Yes";
        }
    }
    else{
        ans = "No";
    }
    cout << ans << endl;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
#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 FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
ll n, A, B, C;
vector<ll> l(10), flag(10);
ll ans = INF;

void dfs(ll cu) {
  if (cu == n) {
    ll a = 0, b = 0, c = 0;
    ll ca = 0, cb = 0, cc = 0;
    REP(i, n) {
      if (flag[i] == 0) {
        a += l[i];
        ++ca;
      } else if (flag[i] == 1) {
        b += l[i];
        ++cb;
      } else if (flag[i] == 2) {
        c += l[i];
        ++cc;
      }
    }

    if (ca == 0 || cb == 0 || cc == 0) return;
    ll cnt = (ca - 1) * 10 + (cb - 1) * 10 + (cc - 1) * 10;
    cnt += abs(A - a) + abs(B - b) + abs(C - c);
    ans = min(ans, cnt);
    return;
  }

  REP(i, 4) {
    flag[cu] = i;
    dfs(cu + 1);
  }
}

int main() {
  cin >> n >> A >> B >> C;
  REP(i, n) { cin >> l[i]; }
  dfs(0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;


int main() {
	
	string S, tmp;
	cin >> S;
	vector<string> extract;
	for (int i = 0; i < S.size() - 1; i++) {
		if (S[i] == 'B' && S[i + 1] == 'C') {
			tmp += 'X';
			i++;
			continue;
		}
		if (S[i] == 'A') {
			tmp += 'A';
			continue;
		}
		
		if (!tmp.empty()) {
			extract.push_back(tmp), tmp.clear();
		}
	}

	if (!tmp.empty()) {
		extract.push_back(tmp), tmp.clear();
	}

	ll ans = 0;
	for (int i = 0; i < extract.size(); i++) {
		string s = extract[i];
		ll cnt = 0;

		ll cnt_x = 0;
		for (ll j = 0; j < s.size(); j++) {
			if (s[j] == 'X') {
				cnt += (j - cnt_x);
				cnt_x++;
			}
		}

		ans += cnt;
	end:;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define x first
#define y second
typedef long long ll;
const int N = 4*100000+10;
const int mod = 1000000007;
const int oo = 1e9;
const int base = 27;
typedef pair<int,int> pii;

int n , m,cost[N],cnt=1;
bool vis[N];

struct edge{
  int p , q , c;
  edge(){}
  edge(int _p , int _q , int _x){
    p = _p , q = _q, c = _x;
  }
};
vector<int> cmp,comp[N],rv,G[N],adj[N];
vector<pii> g[N];
edge E[N];
deque<int> q;

void dfs(int u){
  if(vis[u])return;
  vis[u] = 1;
  comp[cnt].push_back(u);
  for(auto v : adj[u])dfs(v);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i){
    scanf("%d%d%d",&E[i].p,&E[i].q,&E[i].c);
    cmp.pb(E[i].c);
  }
  for (int i = 0; i <= n+m; ++i)cost[i] = oo;
  sort(cmp.begin(),cmp.end());
  cmp.resize(unique(cmp.begin(),cmp.end())-cmp.begin());
  for(int i = 0; i < m;++i){
    E[i].c = lower_bound(cmp.begin(),cmp.end(),E[i].c) - cmp.begin()+1;
    G[E[i].c].push_back(i);
  }
  for(int i = 0 ; i < m ; ++i){
    vector<int> no;
    for(auto idx : G[i]){
      no.push_back(E[idx].p),no.push_back(E[idx].q);
      adj[E[idx].p].push_back(E[idx].q);
      adj[E[idx].q].push_back(E[idx].p); 
    }
    for(auto v : no){
      if(vis[v])continue;
      dfs(v);
      cnt++;
    }
    for(auto v : no)adj[v].clear(),vis[v] = 0;
  }

  for(int i = 1; i < cnt;++i)
    for(auto v : comp[i]){
      int cur = i+n;
      g[v].pb(mp(cur,1));
      g[cur].pb(mp(v,0));
    }
  cost[1] = 0;
  q.push_back(1);
  q.resize(cnt+n);
  while(q.size()){
    int cur = q.front();
    q.pop_front();
    if(vis[cur])continue;
    vis[cur] = 1;
    for(auto v : g[cur]){
      if(cost[cur]+v.second >= cost[v.first])continue;
      cost[v.first] = cost[cur]+v.second;
      if(v.second)q.push_back(v.x);
      else q.push_front(v.x);
    }
  }
  int mn = cost[n];
  if(mn == oo)mn = -1;
  printf("%d\n", mn);
  return 0;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

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

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

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n,m;
    cin>>n;

    map<int,int> app;

    rep(i,n){
        int ai;
        cin>>ai;
        app[ai]++;
    }

    int cnt=0;
    for(auto p:app)if(p.se%2==0)cnt++;

    int spe=app.size();
    if(cnt%2)ans = spe-1;
    else ans=spe;

    cout<<ans<<endl;

    //cout <<fixed<<setprecision(16)<< << endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    return 0;
}


Measured memory_bytes: 4992
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>

using namespace std;

void solve(int X) {
  if (X == 7 || X == 5 || X == 3) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
}

int main() {
  int X;
  cin >> X;
  solve(X);
  return 0;
}

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

bool Condition1(string S) {
  if (S.at(0) == 'A') return true;
  else return false;
}

bool Condition2(string S) {
  int tmp = 0;
  for (int i = 2; i < S.size() - 1; i++) {
    if (S.at(i) == 'C') tmp++;
  }
  if (tmp == 1) return true;
  else return false;
}

bool Condition3(string S) {
  string alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  int count = 0;
  for (int i = 1; i < S.size(); i++) {
    if (S.at(i) == 'C') {
      count++;
      continue;
    }
    for (int j = 0; j < alp.size(); j++) {
      if (S.at(i) == alp.at(j)) return false;
    }
  }
  if (count == 1) return true;
  else return false;
}

int main() {
  
  string S; cin >> S;
  
  if (Condition1(S) && Condition2(S) && Condition3(S)) cout << "AC" << endl;
  
  else cout << "WA" << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int n,k;
	cin >> n >> k;
	int a[n];
	int b[n];
	forr(i,n) cin >> a[i];
	for(int i = n - 1; i >= 0; i--) b[n - 1 - i] = a[i];
	int ans = 0;
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			if(i + j > n || i + j > k) continue;
			int sum = 0;
			multiset<int>s;
			for(int l = 0; l < i; l++){
				s.insert(a[l]);
				sum += a[l];
			}
			for(int l = 0; l < j; l++) s.insert(b[l]), sum += b[l];
			ans = max(ans,sum);
			int left = k - (i + j);
			while(left >0 and s.size() > 0){
				sum -= *s.begin();
				s.erase(s.find(*s.begin()));
				ans = max(ans,sum);
				left--;
			}
			
		}
	}
	cout << ans;
}

Measured memory_bytes: 3660
package main

import "fmt"

func main() {
	var in string
	fmt.Scanf("%s", &in)

	dic := make(map[string]int)
	for _, v := range in {
		dic[string(v)]++
	}

	if len(dic) != 2 {
		fmt.Println("No")
	} else {
		c := true
		for _, v := range dic {
			if v != 2 {
				c = false
			}
		}
		if c {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}

}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
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 ans=0;
    for(int i=0; i<N-2; ++i){
        for(int j=i+1; j<N-1; ++j){
            for(int k=j+1; k<N; ++k){
                if(L[k]!=L[j] && L[j]!=L[i] && L[i]+L[j]>L[k]) ++ans;
            }
        }
    }
    cout<<ans<<endl;
}


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

int main()
{
	int n,m;
	cin >> n >> m;
	if(n > 0 && n < 10 && m > 0 && m < 10){
		cout << n * m << endl;
	}else cout << -1 << endl;
	return 0;
} 

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_map>

#define X first
#define Y second
#define PB push_back

using namespace std;

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

const int N = 5e4 + 500;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;

unordered_map < ll, ll > dp;
ll A, B, C, D;

ll f(ll x){
	if(!x) return 0;
	if(dp[x]) return dp[x];
	ll ret = (ll)INF * INF;
	if(x < 3e9) ret = D * x;
	ret = min(ret, f(x / 2LL) + A + D * (x % 2LL));
	ret = min(ret, f(x / 3LL) + B + D * (x % 3LL));
	ret = min(ret, f(x / 5LL) + C + D * (x % 5LL));
	if(x / 2LL + 1LL != x)
		ret = min(ret, f(x / 2LL + 1LL) + A + D * (2LL - x % 2LL));
	if(x / 3LL + 1LL != x)
		ret = min(ret, f(x / 3LL + 1LL) + B + D * (3LL - x % 3LL));
	if(x / 5LL + 1LL != x)
		ret = min(ret, f(x / 5LL + 1LL) + C + D * (5LL - x % 5LL));
	return dp[x] = ret;
}


int main(){
	int T; scanf("%d", &T);
	for(;T--;){
		dp.clear();
		ll X; scanf("%lld%lld%lld%lld%lld", &X, &A, &B, &C, &D);
		printf("%lld\n", f(X));
	}
	return 0;
}

Measured memory_bytes: 3828
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

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

int g[305][305];

void solve() {
  int n, m;
  cin >> n >> m;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) {
      cin >> g[i][j];
    }
  }
  int ret = 1;
  while(true) {
    set<int> bad;
    vector<int> ord;
    ord.resize(n);
    while(bad.size() < m) {
      map<int, int> dp;
      bool upd = false;
      for(int i = 0; !upd && i < n; i++) {
        while(bad.count(g[i][ord[i]])) ord[i]++;
        if(++dp[g[i][ord[i]]] > ret) {
          upd = true;
          bad.insert(g[i][ord[i]]);
        }
      }
      if(!upd) break;
    }
    if(bad.size() < m) break;
    ret++;
  }
  cout << ret << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define intt long long int
#define intu unsigned long long int
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
# define PI           3.14159265358979323846 
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
int mod = 1000000007;
intt gcd(intt a, intt b) {return b ? gcd(b, a % b) : a;}
intt lcm(intt a, intt b) {return a * b / gcd(a, b); }
intt bpow(intt a,intt b) 
{
  intt res = 1;
  while (b > 0) {
    if (b & 1)res = ((res%mod) * (a%mod))%mod;
      a = ((a%mod) * (a%mod))%mod;
      b >>= 1;
  }
  return res;
}
intt fact(intt n) { 
   if ((n==0)||(n==1))
      return 1; 
   else
      return n*fact(n-1);
}
void go()
{
#ifndef ONLINE_JUDGE
  freopen("inn.txt","r",stdin);
  freopen("o.txt","w",stdout);
  #endif
}


int main()
{
	go();
	int n;cin>>n;string s;cin>>s;
	int r=0,w=0;
	for(int i=0;i<n;i++){
		if(s[i]=='W')
			w++;
		else
			r++;
	}
	if(r==0 || w==0)
		cout << "0" <<"\n";
	else{
		int ans=INT_MAX;
		ans = min(ans,w);
		int c=0,i=0,rr=r;
		while(i<n){
			if(rr==0)
				break;
			if(s[i]=='R')
				rr--;
			else{
				rr--;
				c++;
			}
			i++;
		}
		ans=min(ans,c);
		c=0;i=0;
		while(i<n){
			if(r==0)
				break;
			if(s[i]=='R')
				r--;
			else{
				c++;
			}
			i++;
		}
		ans =min(ans,c);
		cout << ans <<"\n";
	}
}














Measured memory_bytes: 3756
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;

int main(){
    int h, w, n;
    cin >> h >> w >> n;

    queue<int> q;
    rep(i,n){
        int a;
        cin >> a;
        rep(j,a){
            q.push(i + 1);
        }

    }

    int c[105][105];
    rep(i,w){
        if(i % 2){
            for(int j = h - 1; j >= 0; j--){
                c[j][i] = q.front(); q.pop();
            }
        }else{
            rep(j,h){
                c[j][i] = q.front(); q.pop();
            }
        }
    }

    rep(i,h){
        rep(j,w){
            cout << c[i][j] << ' ';
        }
        cout << endl;
    }
}


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

int main() {
    int n; cin >> n;
    vector<ll> v(n);
    for(int i = 0; i < n; i++) {
    	cin >> v[i];
    }
    ll cnt = 0;
    while(1) {
    	ll sum = 0;
    	ll maxv = -1;
    	for(int i = 0; i < n; i++) {
    		sum += v[i]/n*(1LL);
    		maxv = max(maxv, v[i]);
    	}
    	if(maxv < n) break;
    	for(int i = 0; i < n; i++) {
    		v[i] = v[i] + sum - v[i]/n*(1LL) - (v[i]/n*(1LL))*n;
    	}
    	cnt += sum;
    }
    cout << cnt;
    
	return 0;
}


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

int main() {
  string s;
  cin >> s;
  int n=s.size();
  vector<char> an(0);
  
  for(int i=0; i<n; i++){
    if (s.at(i)=='0' || s.at(i)=='1') an.push_back(s.at(i));
    else if(an.size()>0) an.pop_back();
  }
  
  for(int i=0; i<an.size(); i++) cout << an.at(i);
  cout << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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

const ll MOD = ll(1e9 + 7);

vector<vector<int>> edges;

void solve(const ll ppre, const ll pre, const ll prev, const int cur, ll &acc, const ll N, const ll K) {
    acc = (acc * (K - ppre - pre)) % MOD;
    // printf("%lld\n", acc);
    ll x = 0;
    for (auto &next : edges[cur]) {
        if (next == prev) continue;
        solve(pre + x, 1LL, cur, next, acc, N, K);
        x++;
    }
}

int main(void) {
    int N, K;
    cin >> N >> K;

    edges.resize(N);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    ll ans = 1;
    solve(0, 0, -1, 0, ans, N, K);
    cout << ans << endl;

    return 0;
}


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

int main(){
	string s;
	while(getline(cin,s)){
		for(int i=0;i<s.size();i++){
			if(s[i]=='@'){
				int n=s[++i]-'0';
				i++;
				for(int j=0;j<n;j++)cout<<s[i];
			}else cout<<s[i];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <cstdio>
const int MaxN = 1e6 + 10; 
int Red[MaxN], Ball[MaxN];
int N, M, Ans;
int main() {
	scanf("%d%d", &N, &M);
	for(int i = 1; i <= N; i++) Ball[i] = 1;
	Red[1] = true;
	for(int i = 1; i <= M; i++) {
		int X, Y; scanf("%d%d", &X, &Y);
		if(Red[X]) {
			Red[Y] = true; 
		}
		Ball[Y] += 1; Ball[X] -= 1; 
		if(!Ball[X]) Red[X] = false; 
	}
	for(int i = 1; i <= N; i++) if(Red[i]) Ans += 1; 
	printf("%d", Ans);
}

Measured memory_bytes: 4608
INF  = float("inf") # 正の無限大

N = int(input())						# 5

A=[0]*N
B=[0]*N
C=[0]*N

for i in range(N):
	a,b,c = map(int, input().split())		# 5 7 2
	A[i] = a
	B[i] = b
	C[i] = c


dp = [[0,0,0] for _ in range(N)]

for i in range(N):
	dp[i][0] = A[i] + (max(dp[i-1][1], dp[i-1][2]) if i>0 else 0)
	dp[i][1] = B[i] + (max(dp[i-1][2], dp[i-1][0]) if i>0 else 0)
	dp[i][2] = C[i] + (max(dp[i-1][0], dp[i-1][1]) if i>0 else 0)


print( max(dp[-1][0], dp[-1][1], dp[-1][2]) )

#print(dp)


Measured memory_bytes: 34676
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

struct BIT{
    int n;
    vector<double> bit;

    BIT(){}
    BIT(int x){
        n = x;
        bit.assign(n+1, 0.0);
    }

    void init(int x){
        n = x;
        bit.assign(n+1, 0.0);
    }

    void add(int i, double x){
        i++;
        while (i <= n){
            bit[i] += x;
            i += i & -i;
        }
    }

    // [0, i]
    double sum(int i){
        i++;
        double ret = 0;
        while (i > 0){
            ret += bit[i];
            i -= i & -i;
        }
        return ret;
    }

    // [l, r)
    double sum(int l, int r){
        if (l >= r) return 0;
        return sum(r-1) - sum(l-1);
    }
};

const double EPS = 1e-14;

VL calc(VL a){
    int n = a.size();
    VL ret(n);
    vector<double> d(n);
    REP(i,n) d[i] = log2(a[i]) / 2;
    BIT bit(n);
    bit.add(0, d[0]);
    FOR(i,1,n-1) bit.add(i, d[i] - d[i-1]);
    set<int> st;
    st.insert(n);
    ll s = 0;
    FORR(i,n-2,0){
        if (a[i] <= a[i+1]){
            if (d[i] <= d[i+1] - 1 + EPS) st.insert(i + 1);
            ret[i] = s;
            continue;
        }
        ll c = 0;
        while (a[i] > a[i+1]){
            a[i+1] *= 4;
            c++;
        }
        set<int> rm;
        ll y = i + 1;
        for (int x : st){
            s += c * (x - y);
            bit.add(y, c);
            bit.add(x, -c);
            if (x < n && bit.sum(x) + EPS < bit.sum(x - 1)){
                c = 1.0 + bit.sum(x - 1) - bit.sum(x) - EPS;
                rm.insert(x);
            }else{
                break;
            }
            y = x;
        }
        for (int x : rm) st.erase(x);
        ret[i] = s;

        // REP(i,n) cout << pow(4, bit.sum(i)) << " ";
        // cout << endl;
    }
    REP(i,n) ret[i] *= 2;
    return ret;
}

int main() {
    ll n;
    cin >> n;
    VL a(n);
    REP(i,n) a[i] = in();

    VL r = calc(a);

    // REP(i,n) cout << r[i] << " ";
    // cout << endl;

    reverse(ALL(a));

    VL l = calc(a);
    reverse(ALL(l));

    // REP(i,n) cout << l[i] << " ";
    // cout << endl;

    ll ans = 1e18;
    REP(i,n){
        ll tmp;
        if (i == 0) tmp = r[i];
        else tmp = r[i] + i + l[i-1];
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


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

int main(void){
    int n;
    cin>>n;
    vector<string> S(n);
    vector<vector<int>> N(n,vector<int>(26,0));
    for (int i=0;i<n;i++) {
        cin>>S[i];
        sort(S[i].begin(),S[i].end());
        for (int j=0;j<S[i].size();j++) {
            N[i][(S[i][j]-'a')]++;
        }
    }
    vector<int> mi(26,1e3);
    for (int i=0;i<26;i++) {
        for (int j=0;j<n;j++) {
            mi[i] = min(mi[i],N[j][i]);
        }
    }
    for (int i=0;i<26;i++) {
        for (int j=0;j<mi[i];j++) {
            cout<<char('a'+i);
        }
    }
    cout<<endl;
    return 0;
}

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

using namespace std;
int main(void) {
    int n;
    cin >> n;

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

    vector<long> t(n+1, -1);
    long r = 0;
    for(int i=0; i<n; i++) {
        auto it = lower_bound(t.begin(), t.end(), a[i])-1;
        if(*it == -1) r++;
        *it = a[i];
    }
    cout << r << endl;
}




Measured memory_bytes: 1408
/* In the name of God */
     
#include <bits/stdc++.h>
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pii pair <int, int>
using namespace std;
const ll mod = 1e9 + 7;
const int N = 2e5 + 5;

void solve() {
    int x;
    cin >> x;
    int y = 400;
    vector<int> a(8);
    for (int i = 0; i < 8; i++) {
        a[i] = y;
        y += 200;
    }
    for (int i = 7; i >= 0; i--) {
        if(x >= a[i]) {
            cout << 8 - i;
            break;
        }
    }
}
 
int main()  {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int tt = 1;
    // cin >> tt;
    for (int tc = 1; tc <= tt; ++tc) {
        // cout << "Case #" << tc << ": ";
        solve();
    } 
}                        

Measured memory_bytes: 3648
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	sc.Split(bufio.ScanWords)
	N, W := getInt(), getInt()
	w := make([]int, N)
	v := make([]int, N)
	for i := 0; i < N; i++ {
		w[i], v[i] = getInt(), getInt()
	}

	var dp [101][100001]int
	for i := 0; i < N; i++ {
		for k := 0; k <= W; k++ {
			if k-w[i] < 0 {
				dp[i+1][k] = dp[i][k]
			} else {
				dp[i+1][k] = max(dp[i][k], dp[i][k-w[i]]+v[i])
			}
		}
	}

	out(dp[N][W])
}


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

typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main() {
    // random_device rnd;
    // mt19937 mt(rnd());
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, D;
    cin >> N >> D;
    int ans = 0;
    vector<vector<int>> point (N,vector<int> (D));
    for(int i = 0;i < N;i++){
        for(int j = 0;j < D;j++){
            cin >> point[i][j];
        }
    }
    for(int i = 0;i < N;i++){
        for(int j = 0;j < N;j++){
            if(i >= j)continue;
            double dis = 0;
            for(int k = 0;k < D;k++){
                dis += pow(abs(point[i][k]-point[j][k]),2);
            }
            if(sqrt(dis) == int(sqrt(dis)))ans++;
        }
    }
    cout << ans << endl;
}


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

int main(){

  int N;
  vector<int> S;

  cin >> N;
  S.reserve(N);
  int sum = 0;
  for (int i = 0; i < N; ++i) {
    char c;
    cin >> c;
    sum += c=='#' ? 1 : 0;//#の数を数える
    S.push_back(sum);
  }

  int minimum = N;
  for (int i = 0; i < N; ++i) {
    int a = S[i] + (N-i-1-(S[N-1]-S[i]));
    if(a<minimum) minimum = a;
  }

  if (minimum<0) minimum = N;
  int a = S[N-1];
  int b = N-S[N-1];
  minimum = min({a,b,minimum});

  cout << minimum << endl;
  return 0;
}

Measured memory_bytes: 1656
# coding: utf-8;

def main():
    n = int(input())
    al = list(map(int, input().split()))
    mc = 10 ** 20

    for i in range(-100, 101):
        c = 0
        for a in al:
            c += (a - i) ** 2
        if mc > c: mc = c

    print(mc)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        String a = scan.next();
        String b = scan.next();
        String c = scan.next();
        
        int aturn = 0;
        int bturn = 0;
        int cturn = 0;
        
        char check = 'a';
        while(true)
        {
            switch(check)
            {
                case 'a':
                    check = NextA(aturn,a);
                    aturn++;
                    break;
                
                case 'b':
                    check = NextB(bturn,b);
                    bturn++;
                    break;
                    
                case 'c':
                    check = NextC(cturn,c);
                    cturn++;
                    break;
                    
                default:
                    return;
            }
        }
    }
    
    static char NextA(int aturn,String a){
        if(aturn == a.length())
        {
            System.out.println("A");
            return 'z';
        }
        else
        {
            return a.charAt(aturn);
        }
    }
    
    static char NextB(int bturn,String b){
        if(bturn == b.length())
        {
            System.out.println("B");
            return 'z';
        }
        else
        {
            return b.charAt(bturn);
        }
    }
    
    static char NextC(int cturn,String c){
        if(cturn == c.length())
        {
            System.out.println("C");
            return 'z';
        }
        else
        {
            return c.charAt(cturn);
        }
    }
}

Measured memory_bytes: 22740
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)

class UnionFind:
    def __init__(self,n):
        self.par=[i for i in range(n+1)] #親要素のノード番号を格納
        self.rank=[0]*(n+1) #木の高さを格納
    def find(self,x): #根を検索
        if self.par[x]==x: #par[x]==xの時そのノードは根
            return x
        else:
            self.par[x]=self.find(self.par[x]) #親を書き換える
            return self.par[x]
    def union(self,x,y): #木の併合
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return
        if self.rank[x]<self.rank[y]: #木の高さを比較し、低い方を親とする
            self.par[x]=y #xの親がy
        else:
            self.par[y]=x
            if self.rank[x]==self.rank[y]: #木の高さが同じなら親とする方を1増やす
                self.rank[x]+=1
    def same_check(self,x,y): #同じ木に属するか判定
        return self.find(x)==self.find(y)

n,m=map(int,input().split())
edges=[list(map(int,input().split())) for _ in range(m)]
ans=[n*(n-1)//2]
size=[1]*n #size[i]:iを根とするグループのサイズ
uf=UnionFind(n)
for i in range(m-1,0,-1):
    tmp=ans[-1]
    a,b=edges[i][0]-1,edges[i][1]-1
    if not uf.same_check(a,b):
        tmp-=size[uf.find(a)]*size[uf.find(b)]
        tmp_a,tmp_b=size[uf.find(a)],size[uf.find(b)]
        uf.union(a,b)
        size[uf.find(a)]=tmp_a+tmp_b
    else:
        uf.union(a,b)
    ans.append(tmp)
for i in range(1,m+1):
    print(ans[-i])

Measured memory_bytes: 36400