akhauriyash/Code-Regression huggingface dataset:
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(),x.end()
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

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

    ll n,m;
    cin>>n>>m;
    ll ac=0,wa=0;
    
    vector<pair<ll,string>> ps(100050);
    rep(i,m){
        cin>>ps[i].first>>ps[i].second;
    }

    vll a(100050);
    vll b(100050);

    rep(i,m){
        if(ps[i].second=="AC" && a[ps[i].first]==0) a[ps[i].first]=1;
        if(ps[i].second=="WA" && a[ps[i].first]==0) wa++;
    }

    rep(i,m){
        if(ps[i].second=="WA" && a[ps[i].first]==0){
            wa--;
        }
    }

    rep1(i,n) ac+=a[i];

    cout<<ac<<" "<<wa<<endl;
}

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

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

    static class B121 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int m = Integer.parseInt(in.next() + in.next());
            for (int i = 1; i < 10000; i++) {
                if (m == i * i) {
                    out.println("Yes");
                    return;
                }
            }
            out.println("No");
        }

    }
}



Measured memory_bytes: 21716
#include "bits/stdc++.h"

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;


int main() {
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    string s;
    for(int i = 0; i < 2 * N; i++){
        if(i % 2 == 0) s.push_back(S[i / 2]);
        else s.push_back(T[i / 2]);
    }
    cout << s << endl;
}

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

using namespace std;

int main(){
 int N; cin >> N; 
  vector<int> A;
  
  if( N == 0){ cout << 0 << endl; return 0;}
  while( N != 0){
    if( N % 2 == 0){ N = - N /2;  A.push_back(0);}
    else{ N = - ( N - 1 ) / 2; A.push_back(1);}}
  
  reverse(A.begin(),A.end());
  
for(int i = 0; i < A.size(); i++){ cout << A[i];}
  return 0;}


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

int main () {
  int N;
  int A[100010];
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> A[i];
  bool is_noninc = true;
  bool is_nondec = true;
  int count = 1;
  for (int i = 1; i < N; ++i) {
    if (A[i] > A[i-1]) is_nondec = false;
    if (A[i] < A[i-1]) is_noninc = false;
    if (is_nondec == false && is_noninc == false) {
      ++count;
      is_nondec = true;
      is_noninc = true;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <bitset>

using ll = long long;

using namespace std;

#define MAX_D 50
using bs = bitset<51>;

int main() {
    int n;
    cin >> n;
    int a[n], b[n];
    for (auto &ai:a) cin >> ai;
    for (auto &bi:b) cin >> bi;
    bs check(string(50, '1') + '0');
    bool all_fail = true;
    for (int i=MAX_D; i>=1; i--) {
        bool needed = false;
        check.reset(i);
        for (int j=0; j<n; j++) {
            bs dp;
            dp.set(a[j]);
            for (int k=MAX_D; k>=1; k--) {
                if (!check[k]) continue;
                bs filter((1ll << k) - 1),
                   buf = dp;
                for (int l=0; l<(51 + k - 1) / k; l++) {
                    buf >>= k;
                    dp |= (buf & filter);
                }
            }
            if (!dp[b[j]]) {
                needed = true;
                break;
            }
        }
        if (needed) check.set(i);
        else all_fail = false;
    }
    cout << (all_fail ? -1ll : (ll)check.to_ullong()) << '\n';
    return 0;
}

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

int main(){
	int N;
	cin >> N;
	vector<pair<double, string>> gift(N);
	double ans = 0;
	for (int i = 0;i < N;++i) {
		cin >> gift[i].first >> gift[i].second;
		if (gift[i].second == "JPY") {
			ans += gift[i].first;
		}
		else {
			ans += 380000 * gift[i].first;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    //int N = sc.nextInt();
    int[] num = new int[4];

    for(int i=0; i < 4; i++){
        num[i] = sc.nextInt();
    }
    int ab = num[0] - num[1];
    if(ab < 0){
        ab = (-1)*ab;
    }
    int bc = num[1] - num[2];
    if(bc < 0){
        bc = (-1)*bc;
    }
    int ca = num[2] - num[0];
    if(ca < 0){
        ca = (-1)*ca;
    }
    int d = num[3];
    
    if(ca == 0){
        System.out.println("Yes");
    }else if(ca <= d){
        System.out.println("Yes");
    }else if(ab <= d && bc <= d){
        System.out.println("Yes");
    }else{
        System.out.println("No");
    }
  }
}

Measured memory_bytes: 21844
MOD = 10**9 + 7
MOD_t_MAX = 2*(10**5)+1

fac  = [None] * MOD_t_MAX
finv = [None] * MOD_t_MAX
inv  = [None] * MOD_t_MAX
def MOD_COM_init():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MOD_t_MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD
def MOD_COM(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
def MOD_pow(a, n):
    res = 1
    while n > 0:
        if (n & 1):
            res = res * a % MOD
        a = a * a % MOD
        n = n // 2
    return res

def main():
    n, k = map(int, input().split())
    MOD_COM_init()
    ans = 0
    for i in range(n):
        if k-i < 0:
            continue
        x = MOD_COM(n, i) * MOD_COM(n-1, n-i-1) % MOD
        ans += x
        ans %= MOD
    print(ans)
if __name__ == "__main__":
    main()

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

const ll mod = 1000000007;
const ll INF = 1001001001;

ll dp[200000][5];

int main(){
    string s; cin >> s;
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for(int i = 0; i < s.size(); i++){
        for(int j = 0; j < 5; j++){
            if(s[i] == '?'){
                dp[i+1][j] += dp[i][j] * 3 % mod;
                dp[i+1][j] %= mod;
            }
            else{
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= mod;
            }
        }
        if(s[i] == 'A' || s[i] == '?'){
            dp[i+1][1] += dp[i][0];
            dp[i+1][1] %= mod;
        }
        if(s[i] == 'B' || s[i] == '?'){
            dp[i+1][2] += dp[i][1];
            dp[i+1][2] %= mod;
        }
        if(s[i] == 'C' || s[i] == '?'){
            dp[i+1][3] += dp[i][2];
            dp[i+1][3] %= mod;
        }
    }
    cout << dp[s.size()][3] << endl;
}


Measured memory_bytes: 11576
class Dice:
    def __init__(self,numbers):
        self.surface=numbers

    def roll_E(self):
        self.surface[0],self.surface[2],self.surface[3],self.surface[5]=self.surface[3],self.surface[0],self.surface[5],self.surface[2]
    def roll_N(self):
        self.surface[0],self.surface[1],self.surface[4],self.surface[5]=self.surface[1],self.surface[5],self.surface[0],self.surface[4]
    def roll_S(self):
        self.surface[0],self.surface[1],self.surface[4],self.surface[5]=self.surface[4],self.surface[0],self.surface[5],self.surface[1]
    def roll_W(self):
        self.surface[0],self.surface[2],self.surface[3],self.surface[5]=self.surface[2],self.surface[5],self.surface[0],self.surface[3]
    def result(self):
        return self.surface[0]

dice=Dice(input().split())
orders=input()
for i in orders:
    if i=='E':
        dice.roll_E()
    if i=='N':
        dice.roll_N()
    if i=='S':
        dice.roll_S()
    if i=='W':
        dice.roll_W()
print(int(dice.result()))


Measured memory_bytes: 5608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;


public class Main {
	
	public static void main(String[] args) throws IOException {
		new Main().exec();
	}
	
	public void test() {
	}
	
	public void exec() throws IOException {
		SimpleInputUtil in = new SimpleInputUtil();
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt();
		int[] w = in.nextInt(new int[n], n);
		int[] sorted_w = Arrays.copyOf(w, n);
		Arrays.sort(sorted_w);
		HashMap<Integer,Integer> costMap = new HashMap<>();
		int minWeight = sorted_w[0];
		for(int i=0; i<n; i++){
			costMap.put(sorted_w[i], i);
			
		}
		int cost = 0;
		for(int i=0; i<n; i++){
			if(w[i]<0) continue;
			int weight = w[i];
			w[i] = -1;
			int firstPos = i;
			int loopCnt = 1;
			int loopCost = weight;
			int loopMinWeight = weight;
			int nextPos = costMap.get(weight);
			while(firstPos!=nextPos) {
				weight = w[nextPos];
				w[nextPos] = -1;
				loopCnt++;
				loopCost += weight;
				if(loopMinWeight>weight) loopMinWeight = weight;
				nextPos = costMap.get(weight);
			}
			if(loopCnt==1)
				continue;
			else if (loopCnt==2)
				cost += loopCost;
			else {
				cost +=  loopCost + Math.min(loopMinWeight*(loopCnt-2), loopMinWeight + minWeight*(loopCnt+1));
			}
		}
		out.println(cost);
		out.flush();
	}
	
}

class SimpleInputUtil {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public String[] readStrArray(String delim) throws NumberFormatException, IOException{
    	return br.readLine().split(delim);
    }
    
    public int nextInt() throws NumberFormatException, IOException{
    	return Integer.parseInt(br.readLine());
    }
    
    public int[] nextInt(int[] a, int num) throws NumberFormatException, IOException{
        int i=0;
        while(i<num) {
            for(String s: br.readLine().split(" ")){
            	if(i<num) {
                    a[i++] = Integer.parseInt(s);
            	}
            }
        }
        return a;
    }
}

Measured memory_bytes: 25388
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){
    
    int A,B,C,X,Y,x,y,ans,tmp;

    cin >> A>>B>>C>>X>>Y;

    x=X%2;
    y=y%2;

    if((A+B)>C*2){
        //Cがお得
        ans = min(X,Y)*C*2;

        if(X>Y){
            ans+=min((X-Y)*A,(X-Y)*2*C);
        }else if(Y>X){
            ans+=min((Y-X)*B,(Y-X)*2*C);
        }

    }else{

        ans=X*A+B*Y;

    }

    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
abs = []

n.times do
  ab = gets.split.map(&:to_i)
  abs << ab
end

abs.sort! { |a, b| b[0] + b[1] <=> a[0] + a[1] }

t = 0
a = 0
abs.each_with_index do |v, i|
  if i.even?
    t += v[0]
  else
    a += v[1]
  end
end

puts t - a


Measured memory_bytes: 12152
n, k = map(int, input().split())
h = list(map(int, input().split()))

INF = 10**12
dp = [INF] * n
dp[0] = 0

for i in range(n):
    if i == 1:
        dp[1] = abs(h[1] - h[0])
        continue

    for j in range(1, k + 1):
        if i - j < 0:
            continue
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
print(dp[-1])


Measured memory_bytes: 52448
using System;
class program{
  static void Main(){
    string[] s=Console.ReadLine().Split(' ');
    int n=int.Parse(s[0]);
    int d=int.Parse(s[1]);
    int count=2*d+1;
    int c=0;
    while(n>0){
      n-=count;
      c++;
    }
    Console.WriteLine(c);
  }
}
      
      

Measured memory_bytes: 11092
x1,y1,x2,y2, = map(int,input().split())
p1 = x1 + y1 * 1j
p2 = x2 + y2 * 1j
vec12 = p2 - p1
p3 = p2 + vec12 * (1j)
p4 = p1 - vec12 * (-1j)
print('{} {} {} {}'.format(int(p3.real), int(p3.imag), int(p4.real), int(p4.imag)))

Measured memory_bytes: 3064
#include<stdio.h>

int main(void)
{
    int a[3], i, j, X;
    scanf("%d %d %d", &a[0], &a[1], &a[2]);
    
    for (i = 0; i < 3; i++) 
    {
        for (j = i + 1; j < 3; j++)
        {
            if (a[i] > a[j]) 
            {
                X = a[i];
                a[i] = a[j];
                a[j] = X;
            }
        }
    }

    printf("%d %d %d\n", a[0], a[1], a[2]);
    
    return 0;

}




Measured memory_bytes: 2108
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var h = int.Parse(line[0]);
        var w = int.Parse(line[1]);
        var x = int.Parse(line[2]);
        var y = int.Parse(line[3]);
        Console.WriteLine(h * w % 2 == 1 && (x + y) % 2 == 1 ? "No" : "Yes");
    }
}



Measured memory_bytes: 17924
#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
using namespace std;

typedef complex<double> P;


class UnionFind
{
public:
	vector<int> data;
	UnionFind(int size):data(size, -1){}
	
	bool unionSet(int x, int y)
	{
		x = root(x); y=root(y);
		if(x != y)
		{
			if(data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	
	int root(int x)
	{
		return data[x] < 0 ? x:data[x]=root(data[x]);
	}
};

class Edge
{
public:
	int s,d;
	double c;
	
	Edge(int s, int d, double c)
	:s(s), d(d), c(c)
	{}
	
	bool operator<(const Edge& a) const
	{
		return (c<a.c);
	}
};



double kruskal(int N, priority_queue<Edge>& q)
{
	UnionFind uf(N);
	double res = 0;
	while(!q.empty())
	{
		Edge e = q.top(); q.pop();
		
		if(!uf.unionSet(e.s, e.d))
		{
			res+=e.c;
		}
	}
	
	return res;
}

int main() {
	int N,M;
	cin >> N >> M;

	vector<P> piles(N);
	for(int i=0; i<N; i++){
		double a,b;
		cin >> a >> b;

		piles[i] = P(a,b); 
	}

	priority_queue<Edge> q;
	for(int i=0; i<M; i++) {
		int a,b;
		cin >> a >> b;
		a--; b--;
		q.push(Edge(a,b,abs(piles[a]-piles[b])));
	}

	cout.setf(ios::fixed);
	cout.precision(10);
	cout << kruskal(N,q) << endl;

}

Measured memory_bytes: 1684
#include<iostream>
#include<string>
using namespace std;
int main(){
        string s;
        cin>>s;
        int x;
        for(int i=0;i<s.size();i++){
                if(s[i]=='A'){
                        x=i;
                        break;
                }
        }
        int y=0;
        for(int i=s.size()-1;i>=0;i=i-1){
                if(s[i]=='Z'){
                        y=i;
                        break;
                }
        }
        cout<<y-x+1;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define int long long
#define INF 1000000000000000000
using namespace std;

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
template<typename T>
void debug(vector<vector<T>> m){ REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;} }

int dp[3001][3001][2];

signed main(){

    int N, M; cin >> N >> M;
    int mod = 1000000007;

    REP(i, 3001) REP(j, 3001) REP(k, 2) dp[i][j][k] = 0;
    FOR(i, 1, N + 1) dp[0][i][0] = 1;
    dp[0][0][1] = 1;

    REP(i, M){
        REP(j, N + 1){
            if(j == 1){
                dp[i + 1][j - 1][1] += dp[i][j][0] + dp[i][j][1];
                dp[i + 1][j][1] += dp[i][j][0] + dp[i][j][1];
            }else if(j > 1){
                REP(k, 2) dp[i + 1][j - 1][k] += dp[i][j][k];
                REP(k, 2) dp[i + 1][j][k] += dp[i][j][k];
            }
            if(N - j >= 1){
                REP(k, 2) dp[i + 1][j][k] += dp[i][j][k];
                REP(k, 2) dp[i + 1][j + 1][k] += dp[i][j][k];
            }
        }
        REP(j, N + 1) REP(k, 2) dp[i + 1][j][k] %= mod;
    }
    int ans = 0;
    REP(j, N + 1) ans += dp[M][j][1];
    ans %= mod;
    cout << ans << endl;

    return 0;
}


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

struct UFTree2 {
private:
	vector<int> mNode;
	vector<int> mRank;
	vector<int> mNodeNum;

public:
	UFTree2(int n) : mNode(n), mRank(n), mNodeNum(n)
	{
		for (int i = 0; i < n; i++) {
			mNode[i] = i;
			mNodeNum[i] = 1;
		}
	}

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

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

		if (idxX == idxY) {
			return;
		}

		if (mRank[idxX] > mRank[idxY]) {
			mNode[idxY] = idxX;
			mNodeNum[idxX] += mNodeNum[idxY];
		}
		else {
			mNode[idxX] = idxY;
			mNodeNum[idxY] += mNodeNum[idxX];
			if (mRank[idxX] == mRank[idxY]) {
				mRank[idxY]++;
			}
		}
	}

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

	int getNodeNum(int x)
	{
		auto node = find(x);
		return mNodeNum[node];
	}
};

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

	vector<set<int>> rg;
	vector<vector<int>> G(N);
	for (auto i = 0; i < K; ++i)
	{
		int p, q;
		cin >> p >> q;
		--p;
		--q;
		G[p].push_back(q);
		G[q].push_back(p);
	}

	vector<bool> used(N);
	for (auto i = 0; i < N; ++i)
	{
		if (used[i])
		{
			continue;
		}

		set<int> s;
		used[i] = true;
		s.insert(i);
		queue<int> q;
		q.push(i);
		while (!q.empty())
		{
			auto u = q.front();
			q.pop();
			for (auto v : G[u])
			{
				if (used[v])
				{
					continue;
				}
				used[v] = true;
				s.insert(v);
				q.push(v);
			}
		}
		rg.push_back(s);
	}

	UFTree2 t(N);
	for (auto i = 0; i < L; ++i)
	{
		int r, s;
		cin >> r >> s;
		--r;
		--s;
		t.unite(r, s);
	}

	vector<int> ans(N);
	for (auto& s : rg)
	{
		map<int, int> m;
		for (auto u : s)
		{
			auto temp = t.find(u);
			++m[temp];
		}

		for (auto u : s)
		{
			auto temp = t.find(u);
			ans[u] = m[temp];
		}
	}

	for (auto i = 0; i < N; ++i)
	{
		cout << ans[i];
		if (i < N - 1)
		{
			cout << " ";
		}
	}
	cout << endl;

	return 0;
}

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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define endl "\n"
#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
//グリッドグラフの範囲チェック
bool range_validation(int y,int x,int h,int w){
    return y>=0 && y<h && x>=0 && x < w;
}
//ビットカウント
int popcount(long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

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

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  int n,W;
  cin >> n >> W;

  int w[n],v[n];

  REP(i,n) cin >> w[i] >> v[i];

  vector<vector<ll>> dp(2,vector<ll>(100001,INF));

  dp[0][0] = 0;

  REP(i,n){
    int from = i&1;
    int to = (i+1)&1;

    REP(j,100001){
      if(j-v[i] >=0){
        dp[to][j] = min(dp[from][j] , dp[from][j-v[i]] + w[i]);
      }else{
        dp[to][j] = dp[from][j];
      }
    }
  }

  int j = n&1;
  REPD(i,100001){
    if(dp[j][i] <= W){
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 5540
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 邨ｶ蟇ｾ蛟､豎ゅａ繧・▽
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
#define INF 2000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
typedef long long ll;

void divPrime(int n,vector<ll> &A){
	for(int i = 2;i * i <= n ; i++){
		while(n%i==0){
			n/=i;
			A[i]++;
		}
	}
	if(n!=1){A[n]++;}
}

int main(){
	ll n ; cin >>n;
	ll p = pow(10,9)+7;
	vector<ll> A(n+1,0);
	ll count = 1;
	if(n==1){
		cout<<1<<endl;
	}
	else{
		for(int i = 2; i<=n;i++){
		divPrime(i,A);
		}
/*		for(auto x :A){
			cout<<"A[nanka]: "<<x<<endl;
		}*/
		//素因数分解はできてるはず A[i]には，素因数にiの~乗であることを示す値が入っている
		for(int i = 2 ; i <=n ; i++){
			ll a = A[i];
			if(a!=0){
				count*=(a+1);
				count%=p;
			}
		}
		count%=p;
		cout<<count<<endl;
	}
}


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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define m_p make_pair

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

    ll n,m,b=0,c;
    cin >> n >> m;
    vector<ll> p(m),y(m);
    vector<pair<ll,ll>> x,z;
    map<pair<ll,ll>, ll> mp;
    rep(i,m){
        cin >> p[i] >> y[i];
        pair<ll,ll> pairs = m_p(p[i],y[i]);
        x.pb(pairs);
        z.pb(pairs);
    }
    sort(all(x));
    rep(i,m){
        if(b != x[i].fi){
            b = x[i].fi;
            c = 1;
        }
        mp[x[i]] = c;
        c++;
    }
    rep(i,m) printf("%06lld%06lld\n",z[i].fi,mp[z[i]]);
    return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int  s =0;
    if(k<=a)
        cout << k;
    else{
        k-=a;
        if(k<=b)
            cout << a;
        else{
            k-=b;
            a-=k;
            cout << a;
        }
    }
    return 0;
}


Measured memory_bytes: 3652
package main

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

func main() {
	S := nextString()
	for i, s := range S {
		isOdd := (i+1)%2 == 1
		if isOdd && s == 'R' {
			continue
		} else if !isOdd && s == 'L' {
			continue
		} else if s == 'U' || s == 'D' {
			continue
		}

		fmt.Println("No")
		return
	}

	fmt.Println("Yes")
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

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

	return i
}

func nextFloat() float64 {
	sc.Scan()
	f64, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}

	return f64
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 640
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
const long long int mod = 1e9 + 7;
int main()
{
    ll N, K, Q;
    
    cin >> N >> K >> Q;
    vector<ll> A(N);

    rep(i,0,Q){
        ll temp;
        cin >> temp;
        A[temp-1]++;
    }
    rep(i,0,N){
        if(A[i]>Q-K){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<((ll)n);i++)
#define rep1(i,n) for(ll i=1;i<=((ll)n);i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define meow(a) cout<<a<<" meow\n";
typedef pair<long long,long long> pii;
typedef vector<pii> vii;
const ll maxn=200005;
const ll MOD=998244353;
double mypow(ll a,ll b){
	double res=1;
	while(b){
		if(b&1) res=res*a;
		a=a*a;

		b>>=1;
	}
	return res;
}
ll t,n,m;
vector<int> bul[15];
bool mo[15];
bool choose[15];
bool now[15];
ll ans=0;
void dfs(int index)
{
    if(index==n+1)
    {
        bool flag=true;
        rep1(i,m)
        {
            if(flag==false) break;
            int num=0;
            for(auto j:bul[i]) if(choose[j]) num++;
            if((num+mo[i])%2!=0) flag=false;
        }
        //if(flag) rep1(i,m) cout<<choose[i]<<" \n"[i==m];
        if(flag) ans++;
        return;
    }
    choose[index]=1;dfs(index+1);
    choose[index]=0;dfs(index+1);
}
int main()
{
    IOS;
    //cin>>t;
    while(cin>>n>>m)
    {
        rep1(i,m)
        {
            cin>>t;
            while(t--)
            {
                int x;
                cin>>x;
                bul[i].pb(x);
            }
        }
        rep1(i,m) cin>>mo[i];
        ans=0;
        dfs(1);
        cout<<ans<<"\n";
    }
    return 0;
}


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

using namespace std;

#define INF (long long) 1000000000000000

typedef long long ll;

ll cost[200], val[200], dp[100100][200], n, w;

ll f(ll val_left, ll cur_ind){
    if(val_left == 0){
        return 0;
    }
//    cout << "inside with: " << val_left << " " << cur_ind << endl;
    if(val_left < 0){
//        cout << "wtf" << endl;
        return INF;
    }
    if(cur_ind > n){
//        cout << "no item left " << endl;
        return INF;
    
    }
    if(dp[val_left][cur_ind] != -1){
//        cout << "already computed " << endl;
        return dp[val_left][cur_ind];
    }
    dp[val_left][cur_ind] = min( f(val_left-val[cur_ind], cur_ind+1)+cost[cur_ind], f(val_left, cur_ind+1) );
    return dp[val_left][cur_ind];
}

int main(){
    for(ll i = 0; i < 100001; i++){
        for(ll j = 0; j < 200; j++){
            dp[i][j] = -1;
        }
    }
 
    cin >> n >> w;
//    cout << "n and w: " << n << " " << w << endl;
    for(ll i = 1; i <= n; i++){
        cin >> cost[i] >> val[i];
    }
//    cout << "got the arrays" << endl;
//    cout << "waiting for func to return less or equal to " << w << endl;
    for(ll i = 100000; i >= 0; i--){
//        cout << "VALUES: " << f(i, 1) << " " << w << endl;
        if( f(i, 1) <= w ){
            cout << i << endl;
            return 0;
        }
    }

}

Measured memory_bytes: 156544
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;
const ll MOD = 998244353;

int main() {
    int N;
    cin >> N;
    vector<double> x(N), y(N), p(N);
    rep(i, N) cin >> x[i] >> y[i];
    rep(i, N) p[i] = i;
    double s = 0;
    do {
        rep(i, N - 1) {
            s += sqrt((x[p[i + 1]] - x[p[i]]) * (x[p[i + 1]] - x[p[i]]) + (y[p[i + 1]] - y[p[i]]) * (y[p[i + 1]] - y[p[i]]));
        }
    } while (next_permutation(p.begin(), p.end()));
    rep(i, N) s /= (i + 1);
    cout << setprecision(12) << s << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <memory.h>
#define N 7400000
int f[N];
int main(void){
	int n,m,i,j,c;
	while(1){
		scanf("%d %d",&m,&n);
		if(!m){
			break;
		}
		c=n;
		memset(f,0,sizeof(f));
		for(i=m;;i++){
			if(!f[i]){
				if(!c){
					break;
				}
				c--;
				for(j=i;j<N;j+=i){
					f[j]=1;
				}
			}
		}
		printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 29512
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


string s;

void solve()
{
    cin >> s;
    if (s=="ABC") nout("ARC");
    else nout("ABC");
}

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

Measured memory_bytes: 3580
S=input()
ans=0
for i in range(2**(len(S)-1)):
    a=bin(i)
    b=a[2:]
    while len(b)<len(S)-1:
        b="0"+b
    k=0
    temp=0
    for j in range(len(b)):
        if b[j]==str(1):
            temp+=int(S[k:j+1])
            k=j+1
    if S[k:len(S)]!="":    
        temp+=int(S[k:len(S)])
    ans+=temp
print(ans)


Measured memory_bytes: 9048
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <fstream>
#include <bitset>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;
const long long MOD = 1000000007LL;
const long long MAX = 500000LL;
using namespace std;
typedef unsigned long long ull;
typedef  long long ll;


int main()
{
	ll N, M;
	cin >> N >> M;
	vector<vector<ll>> g(N);
	vector<ll> idg(N, 0);
	vector<ll> dp(N, -1);
	vector<ll> to;
	for (ll i = 0; i < M; i++) {
		ll a, b;
		cin >> a >> b;

		g[a].push_back(b);
		idg[b]++;
	}
	queue<ll> q;
	for (ll i = 0; i < N; i++) {
		if (idg[i] == 0) {
			dp[i] = 0;
			q.push(i);
			to.push_back(i);
		}
	}
	while (!q.empty()) {
		ll x = q.front();
		q.pop();
		for (ll xx : g[x]) {
			idg[xx]--;
			if (idg[xx] == 0) {
				q.push(xx);
				to.push_back(xx);
			}
		}
	}
	if (to.size() == N) {
		puts("0");
	}
	else {
		puts("1");
	}
	return 0;
}



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

#define ll long long int

int main() {
	// your code goes here
	
	ll n;
	cin>>n;
//	vector<string>vc;
	map<string,ll>mp;
	for(ll i=0;i<n;i++){
		string s;
		cin>>s;
	//	st.insert(s);
		mp[s]++;
	}
//	sort(vc.begin(),vc.end());
//	vc.erase(unique(vc.begin(),vc.end()),vc.end());
vector<pair<ll,string>>vc;
	for(auto &x:mp){
		vc.push_back({x.second,x.first});
	}
	sort(vc.begin(),vc.end(),[](pair<ll,string>a,pair<ll,string>b){
		if(a.first==b.first)return a.second>b.second;
		return a.first<b.first;
	});
	ll len=vc[vc.size()-1].first;
	cout<<vc[vc.size()-1].second<<'\n';
	for(int i=vc.size()-2;i>=0;i--){
		if(len==vc[i].first){
			cout<<vc[i].second<<'\n';
		}
		else{return 0;}
	}
	/*
	vector<string>v;
	ll last=-1;
	for(int i=0;i<vc.size();i++){
		if()
	}
	
	ll cnt=1;
	for(int i=0;i<n;){
		
		for(int j=i+1;j<n;j++){
			if(vc[j]==vc[i]){
				cnt++;
			}
			else{
				v.push_back({cnt,vc[i]});
				cnt=1;
				i=j;
				break;
			}
		}
		if(j==n-1){
				v.push_back({cnt,vc[i]});
				cnt=1;
				i++;
		}
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++){
		cout<<v[i].second<<'\n';
	}*/
	return 0;
}

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

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    ll a, b, c;
    ll x, y;
    cin >> a >> b >> c >> x >> y;
    ll ans = 999999999999999999;
    for (ll i = 0; i < 200000; i++) {
        ans = min(ans, i * 2 * c + max((ll)0, x - i) * a + max((ll)0, y - i) * b);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)


using namespace std;


int main(void){
    
    int drugnumber;
    int drugcounter;
    /* x????¨????,y?????´????????? */
    double drugeffect[120][120] = {0};
    int i,j,k,l;
    double max = 0;
    double answer[100] = {0};
    
    while(cin >> drugnumber >> drugcounter,drugnumber+drugnumber)
    {
        double combination[120][120] = {0};
        /*??£??\*/
        FOR(j, 1, drugnumber+1)
        FOR(i, 1, drugnumber+1)
        cin >> drugeffect[j][i];
        
        //cout << drugeffect[2][1];
        
        for(k = 1;k <= drugnumber; k++)
            combination[1][k] = 1.0;
        //cout << combination[1][2] << endl;
        
        /* j?????¬?????°,i????????°*/
        
        for(i = 1; i< drugcounter;i++)
            for(j = 1; j<= drugnumber;j++)
            {
                for(k = 1; k<=drugnumber;k++)
                {
                    if((combination[i][j] * drugeffect[j][k]) >= combination[i+1][k])
                        combination[i+1][k] = combination[i][j]*drugeffect[j][k];
                     //cout << combination[i+1][j] << " ";
                    /*
                     if((combination[j][i] * drugeffect[j][i]) >= combination[j][i])
                     combination[j][i+1] = combination[j][i] * drugeffect[j][i];
                     */
                }
            }
        
    
    for(i = 1 ; i<= drugnumber;i++)
        if(max <  combination[drugcounter][i])
            max = combination[drugcounter][i];
    
        answer[l] = max;
        max = 0;
        l++;
        
    }
    REP(i,l)
    printf("%.2f\n",answer[i]);
    return 0;
    
}

Measured memory_bytes: 1472
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():
    N, M = in_nn()
    S = in_s()

    ans = []
    now = N
    while now > 0:
        next = -1
        end = max(0, now - M)
        for i in range(now - 1, end - 1, -1):
            if S[i] == '0':
                next = i
        if next == -1:
            print(-1)
            exit()
        else:
            ans.append(now - next)
            now = next

    ans = ans[::-1]
    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 83528
#include<iostream>
#include<vector>
#define inf 1e9
using namespace std;

struct act
{
    int x,y,z;
};

int solution(vector<act> a,int n)
{
    int dp[n+1][3];
    dp[1][0]=a[1].x;
    dp[1][1]=a[1].y;
    dp[1][2]=a[1].z;

    for(int i=2;i<=n;i++)
    {
        dp[i][0]=a[i].x+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i].y+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i].z+max(dp[i-1][0],dp[i-1][1]);
    }
    return max(dp[n][0],max(dp[n][1],dp[n][2]));
}
int main()
{
    int n;
    cin>>n;
    vector<act> a(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].x;
        cin>>a[i].y;
        cin>>a[i].z;
    }
    cout<<solution(a,n);
}


Measured memory_bytes: 3712
#include<cstdio>

int ball[11], B[11], C[11];
int cnt1, cnt2;
bool flagb, flagc, flag;

void dfs(int cur) {
    if (flag)return;
    if (cur == 10) {
        flagb = 1, flagc = 1;
        if (cnt1 > 1) {
            for (int i = 0; i < cnt1 - 1; i++)
                if (B[i] > B[i + 1]) {
                    flagb = 0;
                    break;
                }
        }
        if (cnt2 > 1) {
            for (int i = 0; i < cnt2 - 1; i++)
                if (C[i] > C[i + 1]) {
                    flagc = 0;
                    break;
                }
        }

        if (flagb && flagc) {
            flag = 1;
            return;
        }
        return;
    }
    B[cnt1++] = ball[cur];
    dfs(cur + 1);
    cnt1--;
    C[cnt2++] = ball[cur];
    dfs(cur + 1);
    cnt2--;
}

void solve() {
    flag = 0;
    dfs(0);
    if (flag)printf("YES\n");
    else printf("NO\n");
}

int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        cnt1 = 0, cnt2 = 0;
        for (int i = 0; i < 10; i++)
            scanf("%d", &ball[i]);
        solve();
    }
    return 0;
}

Measured memory_bytes: 1008
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define DEC(i, a, b) for (int i = (a); i > (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;
  int Kmax = (N - 1) * (N - 2) / 2;
  if (K > Kmax) {
    cout << -1 << endl;
    return 0;
  }

  vector<pair<int,int>> G;
  FOR(i,2,N+1) {
    G.pb({1,i});
  }

  int a = 2, b = 3;
  REP(i, Kmax - K) {
    G.pb({a,b});
    if (b == N) {
      ++a;
      b = a + 1;
    } else {
      ++b;
    }
  }
  cout << G.size() << endl;
  for(auto e: G) {
    cout << e.first << " " << e.second << endl;
  }
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mod 1000000007LL
#define eps 0.0001

#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------
    ll a,b;

    cin >> a >> b;
    ll ans = b;
    int i;
    rep1(i,a){
        ans=(b-1)*ans;
    }
    pri(ans);
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mt make_tuple
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<string,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int n;
vi used;
bool H=false;
vvi G;
int dfs(int a){
	used[a]=true;
//	int t=0;
	vi t;
	rep(i,G[a].size())if(used[G[a][i]]==0)
		t.pb(dfs(G[a][i]));
	
	int co=0;
	rep(i,t.size())if(t[i]%2)co++;
	if(co>=2){
		H=true;
		return 0;
	}else if(co==1)return 0;
	else return 1;
}
int main(){
	cin>>n;
	G=vvi(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	rep(i,n)if(G[i].size()>1){
		used=vi(n);
		int t=dfs(i);
		if(t)H=true;
		break;
	}
	if(H)cout<<"First"<<endl;
	else cout<<"Second"<<endl;
}






Measured memory_bytes: 6272
#include <iostream>
using std::cin;
using std::cout;
using std::endl;

int main()
{
	int a, b;
	char op;
	while (true)
	{
		cin >> a >> op >> b;
		if (op == '+')
			cout << a+b << endl;
		else if (op == '-')
			cout << a - b << endl;
		else if (op == '*')
			cout << a*b << endl;
		else if (op == '/')
			cout << a/b << endl;
		else
			break;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n;
  cin >> n;
  ll cnt = 0;
  bool ok = false;
  REP(i, n) {
    ll x, y;
    cin >> x >> y;
    if (x == y) {
      cnt++;
    } else {
      cnt = 0;
    }
    if (cnt == 3) {
      ok = true;
    }
  }

  cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args)
	{
		FastReader in = new FastReader();
		int n = in.nextInt();
		int[][] h = new int[n][3];
		for(int i = 0; i < n; i++)
		{
			h[i][0] = in.nextInt();
			h[i][1] = in.nextInt();
			h[i][2] = in.nextInt();
		}
		int[][] dp = new int[2][3];
		dp[0][0] = h[0][0];
		dp[0][1] = h[0][1];
		dp[0][2] = h[0][2];
		for(int i = 1; i < n; i++)
		{
			dp[1][0] = Math.max(dp[0][1], dp[0][2]) + h[i][0];
			dp[1][1] = Math.max(dp[0][0], dp[0][2]) + h[i][1];
			dp[1][2] = Math.max(dp[0][1], dp[0][0]) + h[i][2];
			
			dp[0][0] = dp[1][0];
			dp[0][1] = dp[1][1];
			dp[0][2] = dp[1][2];
		}
		
		System.out.println(Math.max(dp[0][0], Math.max(dp[0][1], dp[0][2])));
	}
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                }
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
}


Measured memory_bytes: 45812
#include <iostream>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};



int H, W;
char maze[410][410];
bool visited[410][410];


P dfs(int cur_h, int cur_w) {
  visited[cur_h][cur_w] = true;

  //cout << cur_h << " " << cur_w << "\n";

  P ans;
  if (maze[cur_h][cur_w] == '#') ans.first++;
  else ans.second++;

  Rep(k, 4) {
    int next_h = cur_h + dy[k];
    int next_w = cur_w + dx[k];

    if (next_h == 0 || next_h == H+1) {
      continue;
    }
    if (next_w == 0 || next_w == W+1) {
      continue;
    }
    if (visited[next_h][next_w]) continue;

    if (maze[cur_h][cur_w] == maze[next_h][next_w]) continue;

    //cout << next_h << " " << next_w << "\n";

    P tmp = dfs(next_h, next_w);
    ans.first += tmp.first;
    ans.second += tmp.second;
  }

  return ans;
}

int main () {
  cin >> H >> W;

  rep(i, H) {
    rep(j, W) {
      cin >> maze[i][j];
    }
  }

  ll ans = 0;

  rep(i, H) {
    rep(j, W) {
      if (visited[i][j]) continue;

      P tmp = dfs(i, j);

      //cout << "\n";

      ans += tmp.first * tmp.second;
    }
  }

  cout << ans << "\n";
}

Measured memory_bytes: 10624
#include<bits/stdc++.h>
using namespace std;
const int SIZE=1400;
int H,W;
int fld[SIZE][SIZE];

int dp[SIZE+1][SIZE+1];
int main(){
    cin>>H>>W;
    for(int i=0;i<H;i++)for(int j=0;j<W;j++)cin>>fld[i][j];

    int ma=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(fld[i][j]==1)continue;
            dp[i+1][j+1]=min(dp[i][j],min(dp[i+1][j],dp[i][j+1]))+1;
            ma=max(ma,dp[i+1][j+1]);
        }
    }

    cout<<(long long)ma*ma<<endl;
    return 0;
}

Measured memory_bytes: 16008
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const array = input.split('\n');
const line = array[0].split(' ');
const A = parseInt(line[0]);
const B = parseInt(line[1]);
const res = Math.max(A + B, A - B, A * B);
if (res === -0 || res === +0) {
  console.log(0);
} else {
  console.log(res);
}


Measured memory_bytes: 7372