akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <vector>
using namespace std;

int N, M, K, P[100100], S[100100];
vector<int> F[100100], B[100100];

int find(int x)
{
	int &p = P[x];
	if (p != x) p = find(p);
	return p;
}

int main()
{
	scanf ("%d %d %d", &N, &M, &K);
	for (int i = 1; i <= N; i++) P[i] = i;
	for (int i = 0; i < M; i++){
		int x, y; scanf ("%d %d", &x, &y);
		F[x].push_back(y);
		F[y].push_back(x);
		P[find(x)] = find(y);
	}
	for (int x = 1; x <= N; x++) S[find(x)]++;
	for (int i = 0; i < K; i++){
		int x, y; scanf ("%d %d", &x, &y);
		B[x].push_back(y);
		B[y].push_back(x);
	}

	for (int x = 1; x <= N; x++){
		int a = S[find(x)] - 1;
		for (int y : F[x]) if (find(x) == find(y)) a--;
		for (int y : B[x]) if (find(x) == find(y)) a--;
		printf ("%d%c", a, x < N ? ' ' : '\n');
	}

	return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); 
	
	int n;
	cin >> n;
	long long x = 1, y = 1;
	while(n--) {
		long long a, b;
		cin >> a >> b;
		long long t = max(( x + a - 1) / a, (y + b - 1) / b);
		x = a * t;
		y = b * t;
	}
	cout << x + y << endl;
	return 0;
}


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

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
  
    int a[85][85], b[85][85];
  
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++)
        cin >> a[i][j];
    }
  
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++)
        cin >> b[i][j];
    }

    int range = 26000;
  
    bool dp[85][85][26000];
    
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      for(int k=0;k<range;k++){
        dp[i][j][k] = false;
      }
    }
  }

    dp[0][0][b[0][0] - a[0][0]  + (range/2)] = true;
    dp[0][0][-b[0][0] + a[0][0] + (range/2)] = true;

    for(int i=0;i<h;i++) {
  for(int j=0;j<w;j++) {
            for(int k=0;k<range;k++) {
              
                if (!dp[i][j][k]) continue;
              
                if (i + 1 < h) {
                    dp[i + 1][j][k + b[i + 1][j] - a[i + 1][j]] = true;
                    dp[i + 1][j][k - b[i + 1][j] + a[i + 1][j]] = true;
                }
                if (j + 1 < w) {
                    dp[i][j + 1][k + b[i][j + 1] - a[i][j + 1]] = true;
                    dp[i][j + 1][k - b[i][j + 1] + a[i][j + 1]] = true;
                }
            }
        }
    }
  
    int ans = 100000000;
  
    for(int i=0;i<range;i++) {
        if (dp[h - 1][w - 1][i]) ans = min(ans, abs(i - (range/2)));
    }
  
    cout << ans << endl;
}

Measured memory_bytes: 174720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
const int INF = 2e9;

int n, abc[100005][3], dp[100005][3];

int main(){

    cin >> n;
    for(int i=0; i<n; i++){
        for(int j=0; j<3; j++){
            cin >> abc[i][j];
        }
    }
    for(int i=0; i<3; i++){
        dp[0][i] = abc[0][i];
    }
    for(int i=1; i<n; i++){
        for(int j=0; j<3; j++){
            dp[i][j] = max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3])+abc[i][j];
        }
    }
    cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}) << endl;;
}

Measured memory_bytes: 2560
import java.util.*;
public class Main {
	public static void main(String[] args)
	{
		//変数
		//long count=0;
		//boolean sw=false;
		long answer=0;
		//boolean poison=false;
		
		//入力
		Scanner sc = new Scanner(System.in);
		long A=sc.nextInt();
		long B=sc.nextInt();
		long C=sc.nextInt();
		
		//処理
		if(C<B || C<A || C<A+B)
		{
			answer=B+C;
		}else
		{
			long canIeatC=C-(C-B-A);
			if(canIeatC==C)
			{
				answer=B+C;
			}
			else
			{
				answer=B+canIeatC+1;
			}
			
		}
		// 出力
		System.out.println(answer);
	}
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mo 1000000007
#define pb emplace_back
typedef vector<ll> vi;
void solve(){
int n=0,k=0,w=0;
ll sum;
cin>>n>>w;
vi dp(w+1,0);
for(int i=0;i<n;i++){
	ll u,v;
	cin>>u>>v;
	for(int j=w;j>=u;j--){
		dp[j]=max(dp[j],dp[j-u]+v);
	}
}
cout<<dp[w]<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
   int t=1;
   //cin>>t;
     while(t--){
     	solve();
	 }
     return 0;
} 

Measured memory_bytes: 3972
/*
ID: victorn2
LANG: C++
TASK: fact4
*/

// 178

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define trie bakayerou_konayarou
#define pb push_back
#define INF 0x3f3f3f3f
#define ll long long
#define int long long
#define endl '\n'
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, ll> pii;
typedef pair<int, pair<int, int>> ppi;
typedef vector<vector<int>> mat;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
const ll mod = 1e9+7;
const ll MOD = 9901;
const int LINF = 0x3f3f3f3f3f3f3f;
const int MAXN = 200005;
#define fin cin
#define fout cout

int a, b, c, n, m, k;
string s, t;

int32_t main() {
	cin >> n >> m >> k;
	vector<int> a(n), b(m);
	
	for(int &i : a)
		cin >> i;
	for(int &i : b)
		cin >> i;
	for(int i = 1; i < m; i++)
		b[i] += b[i-1];

	int ans = 0;
	for(int i = 0; i <= n; i++) {
		if(k < 0) break;

		int kappa = i;
		auto aux = upper_bound(b.begin(), b.end(), k);
		if(aux != b.begin()) {
			aux--;		
			kappa += aux - b.begin() + 1;
		}

		ans = max(kappa, ans);
		if(i != n) k -= a[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 6412
N = int(input())

lst = list(map(int, input().split()))

flag = "Yes"
cnt = 0
if (N > 1):
  for i in range(len(lst) - 1):
    if (lst[i+1] - lst[i] < 0):
      cnt += 1
    elif (lst[i+1] - lst[i] > 0):
      cnt = 0
      
    if (cnt > 1 or lst[i+1] - lst[i] < -1):
      flag = "No"

print(flag)

Measured memory_bytes: 14252
#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
#define scan(x) do{while((x=getchar_unlocked())<'0'); for(x-='0'; '0'<=(_=getchar_unlocked()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define ll long long
#define ull unsigned long long
#define MAXN 1010
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define min(a, b) (a) < (b) ? (a) : (b)
#define max(a, b) (a) < (b) ? (b) : (a)
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define f first
#define s second
#define mii map<int, int>
#define umii unordered_map<int, int>
#define allof(x) x.begin(), x.end()
#define DEBUG 1
// #define NOT_DMOJ 0
#ifdef DEBUG
	#define D(x...) printf(x)
#else
	#define D(x...)
#endif
using namespace std;

inline int GCD (int a, int b) { return b == 0 ? a : GCD(b, a % b); }
inline int LCM (int a, int b) { return a * b / GCD(a, b); }
inline ll PowMod (ll a, ll b, ll mod) { ll val = 1; while (b) { if (b & 1) val = (val * a) % mod; a = (a * a) % mod; b >>= 1; } return val; }

int H, W;
string s;
char grid[MAXN][MAXN];
ll DP[MAXN][MAXN];

inline ll Mod (ll a) {
	return ((a % MOD) + MOD) % MOD;
}

inline ll Solve (int a, int b) {
	if (a == H && b == W) return 1;
	if (a > H || b > W || grid[a][b] == '#') return 0;
	ll &res = DP[a][b];
	if (~res) return res;
	return res = Mod(Mod(Solve(a + 1, b)) + Mod(Solve(a, b + 1)));
}

int main (int argc, char const *argv[]) {
	#ifdef NOT_DMOJ
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	#endif // NOT_DMOJ
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> H >> W;
	for (int i=1; i<=H; i++) {
		cin >> s;
		for (int j=1; j<=W; j++) {
			grid[i][j] = s[j - 1];
		}
	}
	memset(DP, -1, sizeof(DP));
	cout << Solve(1, 1) << "\n";
	return 0;
}

/* 
 * Look for:
 * the exact constraints (multiple sets are too slow for n=10^6 :( ) 
 * special cases (n=1?)
 * overflow (ll vs int?)
 * array bounds
 */

Measured memory_bytes: 9344
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var N = cin.ReadInt;
            var A = cin.ReadLongArray(N);
            var ans = new int[N];
            long tmp = 0;
            for(int i = 1; i < N-1; i++)
            {
                if(i % 2 == 1)
                {
                    tmp += A[i];
                }
            }
            long ans0 = A.Sum() / 2 - tmp;
            ans[0] = (int)ans0;
            for(int i = 0; i < N - 1; i++)
            {
                ans[i + 1] = (int)(A[i] - ans[i]);
            }
            for(int i = 0; i < N; i++)
            {
                WriteLine(ans[i] * 2);
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


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

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());
  if (t > s) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}


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

int main() {
	int t, n, k;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int a[100001];
		vector<int> dist;
		cin >> n >> k;
		for (int j = 0; j < n; j++) {
			cin >> a[j];
		}
		for (int j = 0; j < n - 1; j++) {
			dist.push_back(a[j + 1] - a[j]);
		}
		sort(dist.begin(), dist.end());
		int sum = 0;
		for (int j = 0; j < max(0, n - k); j++) {
			sum += dist[j];
		}
		cout << sum << endl;
	}







	return 0;
}

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

//131_C

long long A,B,CD;
long long C,D;

int gcd(int c, int d){
    if(c%d==0)return d;
    else return gcd(d,c%d);
}

int main(){
    cin>>A>>B>>C>>D;
    long long a,b;
    CD=C*D/gcd(C,D);
    b=(B/C)+(B/D)-(B/CD);
    a=((A-1)/C)+((A-1)/D)-((A-1)/CD);
    cout<<(B-A+1)-(b-a)<<endl;
}

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

constexpr long long inf = 1000000000LL;

int n, m;
std::vector<int> g[100005];
int dp[100005];

int rec(int v) {
	if (dp[v] != -1)
		return dp[v];

	int res = 0;
	for (size_t i = 0, end = g[v].size(); i < end; ++i) {
		res = std::max(res, rec(g[v][i]) + 1);
	}

	return dp[v] = res;
}

int main()
{
	std::cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int x, y;
		std::cin >> x >> y;
		--x, --y;
		g[x].push_back(y);
	}

	std::fill(dp, dp + n, -1);

	int ans = 0;
	for (int i = 0; i < n; ++i)
		ans = std::max(ans, rec(i));

	std::cout << ans << std::endl;
	return 0;
}


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

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

ll mod = 1000000007;
const ll INF = 100000000000010000;

//ll bit[200010];
//ll kai[3010];

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

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

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

/*`ll SAIKI(ll S) {
	for (ll T = S; ; T = (T - 1) & S) {

	}
}*/

void test() {
	cout << "888888888888888888888888" << endl;
}

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

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

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

/*ll com(ll x, ll y) {
	return kai[x] * div_mod(kai[y] * kai[x - y] % mod) % mod;
	//毎回オーダーlog(n)かかる
}*/

/*void kaijo() {
	kai[0] = 1;
	for (ll i = 1; i <= 3004; i++) {
		kai[i] = kai[i - 1] * i % mod;
	}
}*/

ll N, K, Q;
ll A[100010], maru[100010];

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	ll N;
	cin >> N;
}


Measured memory_bytes: 2176
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 100000000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
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; }

using memo = pair<ll, pii>; //min_ cost, from, to

struct edge {
    int to;
    ll cost;
};

int V;
vector<edge> G[301];
ll d[301];

void dijkstra(int s) {
    priority_queue<pii, vector<pii>, greater<pii> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(pll(0, s)); //コスト、移動先の頂点

    while (!que.empty()) {
        pll p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;

        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(pll(d[e.to], e.to));
            }
        }
    }
}

int main() {    
    int n; cin >> n; V = n;
    vector<vector<ll>> A(n, vector<ll>(n));
    vector<memo> memos;
    rep(i, n){
        rep(j, n){
            cin >> A[i][j];
        }
    }
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            memos.push_back(memo(A[i][j], pii(i, j)));
        }
    }
    sort(all(memos));
    ll res = 0;
    for(auto m: memos){
        ll cost = m.first; int a = m.second.first, b = m.second.second;
        //cout << "a:" << a << " b:" << b << " cost:" << cost << ln;
        dijkstra(a);
        if(d[b] > cost || d[b] == INF){
            res += cost;
            G[a].push_back(edge{b, cost});
            G[b].push_back(edge{a, cost});
        }
        else if(d[b] < cost){
            res = -1;
            break;
        }
    }
    cout << res << ln;
} 


Measured memory_bytes: 2176
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
#pragma endregion

void solve() {
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i=0; i<n; i++) {
        cin >> s.at(i);
    }
    sort(s.begin(), s.end());

    vector<pair<int, string>> st;
    string cur = s.at(0);
    int cnt = 1;
    for (int i=1; i<n; i++) {
        if (cur != s.at(i)) {
            st.push_back({cnt, cur});
            cur = s.at(i);
            cnt = 1;
        } else {
            cnt++;
        }
    }
    st.push_back({cnt, cur});

    sort(st.begin(), st.end());
    int maxi = st.back().first;
    for (auto p : st) {
        if (p.first == maxi) {
            cout << p.second << '\n';
        }
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 17136
#include <bits/stdc++.h>
#define MAX 11000
#define ll long int
using namespace std;
 
 
int main() {
 
	map<string,int> mp;
	string s ;
	ll i,j,n,count=0,sum=0;
	
	cin >> n;
	
	for(i=0;i<n;i++)
	{
		cin >> s;
		sort(s.rbegin(), s.rend(), greater<char>());
		count += mp[s]++;
	
	}
	
	cout << count;


	
 
}

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

int main() {
  int x, y;
  scanf("%d %d", &x, &y);
  if(y - x >= 0)
    printf("%d\n", min(y - x, abs(x + y) + 1));
  else
    printf("%d\n", min(x - y + 2, abs(x + y) + 1));
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	private static List<Long> getNewList(List<Long> list) {
		List<Long> retList = new ArrayList<>();

		//引数の全要素に対して追加の要素を作成する
		for (Long item : list) {

			//追加するのは±1
			for (int i = -1; i < 2; i++) {

				if (item % 10 == 0) {
					if (i == -1) {
						continue;
					}
				} else if (item % 10 == 9) {
					if (i == 1) {
						continue;
					}
				}

				long d = item % 10 + i;

				retList.add(item * 10 + d);
			}
		}

		return retList;
	}

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		int k = scan.nextInt();
		int count = 1;
		int pointer = 1;

		List<Long> list = Arrays.asList(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L);

		while (true) {

			//要素取得
			long ret = list.get(pointer - 1);

			if (ret == list.get(list.size() - 1)) {

				//listの最後だったら、新しいリストの更新しておく
				list = getNewList(list);
				//ポインタクリア
				pointer = 0;
			}

			if (count == k) {
				//答え出力

				System.out.println(ret);
				return;
			}

			count++;
			pointer++;
		}

	}

	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


Measured memory_bytes: 30676
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';


template<typename T>
struct Rint{
  static T mod;
  static void set_mod(T nmod){mod=nmod;}

  T v;
  Rint():v(0){}
  Rint(signed v):v(v){}
  Rint(long long t){v=t%mod;if(v<0) v+=mod;}

  Rint pow(long long k){
    Rint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Rint add_identity(){return Rint(0);}
  static Rint mul_identity(){return Rint(1);}

  Rint inv(){return pow(mod-2);}

  Rint& operator+=(Rint a){v+=a.v;if(v>=mod)v-=mod;return *this;}
  Rint& operator-=(Rint a){v+=mod-a.v;if(v>=mod)v-=mod;return *this;}
  Rint& operator*=(Rint a){v=1LL*v*a.v%mod;return *this;}
  Rint& operator/=(Rint a){return (*this)*=a.inv();}

  Rint operator+(Rint a) const{return Rint(v)+=a;}
  Rint operator-(Rint a) const{return Rint(v)-=a;}
  Rint operator*(Rint a) const{return Rint(v)*=a;}
  Rint operator/(Rint a) const{return Rint(v)/=a;}

  Rint operator-() const{return v?Rint(mod-v):Rint(v);}

  bool operator==(const Rint a)const{return v==a.v;}
  bool operator!=(const Rint a)const{return v!=a.v;}
  bool operator <(const Rint a)const{return v <a.v;}
};
template<typename T> T Rint<T>::mod;
template<typename T>
ostream& operator<<(ostream &os,Rint<T> m){os<<m.v;return os;}

//INSERT ABOVE HERE
const int MAX = 2020;
using R = Rint<int>;
// lenght, (#1)-(#2)
R dp[MAX*3][MAX*4]={};

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

  int n,mod;
  cin>>n>>mod;

  R::set_mod(mod);

  dp[0][MAX]=R(1);
  for(int i=0;i<n*3;i++){
    for(int j=-n;j<=n*3;j++){
      R res=dp[i][MAX+j];
      if(res.v==0) continue;

      // use 3
      dp[i+3][MAX+j+0]+=res*R(i+1)*R(i+2);
      // use 2
      dp[i+2][MAX+j-1]+=res*R(i+1);
      // use 1
      dp[i+1][MAX+j+1]+=res;
    }
  }

  R ans{0};
  for(int j=0;j<=n*3;j++) ans+=dp[n*3][MAX+j];
  cout<<ans<<newl;

  return 0;
}


Measured memory_bytes: 191488
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")
#pragma warning( disable : 6031)
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <limits>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-9)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;
const long long inf = 1e12;

int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
	int n, d;
	cin >> n >> d;
	vvi a(n, vi(d));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < d; j++)
			cin >> a[i][j];
	set<int> sq;
	for (int i = 1; i < 1000; i++)
		sq.insert(i * i);
	int res = 0;
	for (int i = 0; i < n - 1; i++)
		for (int j = i + 1;j < n; j++)
		{
			int cur = 0;
			for (int k = 0; k < d; k++)
			{
				cur += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
			}
			if (sq.count(cur))
				res++;
		}
	cout << res;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-6
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
double dp[1<<15][15];//dp[S][v]:at vertex v,visited S ,max time[h]
int n;
int kura[17],dist[17],num[17];
double Dist(int u,int v,int mask)
{
	int senryou=0;
	for(int i=0;i<n;i++)if((mask>>i)&1)senryou+=num[i];
	return (abs(dist[u]-dist[v]))/60.0*(70+senryou*20)/2000.0;
}
void print()
{
	for(int i=0;i<(1<<n);i++)
	{
		for(int j=0;j<n;j++)
		{
			cout << dp[i][j] << ' ';
		}
		cout << endl;
	}
	return;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d %d %d",&kura[i],&dist[i],&num[i]);
	for(int i=1;i<(1<<n);i++)
	{
		for(int j=0;j<n;j++)
		{
			if(__builtin_popcount(i)==1&&((i>>j)&1))
			{
				dp[i][j]=0;
			}
			else dp[i][j]=INF;
		}
	}
	//print();
	for(int i=1;i<((1<<n)-1);i++)
	{
		for(int j=0;j<n;j++)
		{
			if(dp[i][j]==INF)continue;
			if(!((i>>j)&1))continue;
			for(int k=0;k<n;k++)
			{
				if(!((i>>k)&1))
				{
					dp[i|(1<<k)][k]=min(dp[i|(1<<k)][k],dp[i][j]+Dist(j,k,i));
				}
			}
		}
	}
	//print();
	//cout << endl;
	vector<int> answer;
	double ans=INF;
	int ansnum;
	for(int i=0;i<n;i++)
	{
		if(dp[(1<<n)-1][i]<ans)
		{
			ans=dp[(1<<n)-1][i];
			ansnum=i;
		}
	}
	int ansmask=((1<<n)-1)-(1<<ansnum);
	answer.pb(ansnum);
	for(int i=0;i<n-1;i++)
	{
		for(int j=0;j<n;j++)if((ansmask>>j)&1)
		{
			//cout << j << ' ' << ansmask << ' ' << ans << ' ' << dp[ansmask][j] << ' ' << Dist(j,ansnum,ansmask) << endl;
			if(EQ(ans,dp[ansmask][j]+Dist(j,ansnum,ansmask)))
			{
				answer.pb(j);
				ans=dp[ansmask][j];
				ansmask-=(1<<j);
				ansnum=j;
				break;
			}
		}
	}
	reverse(answer.begin(),answer.end());
	for(int i=0;i<answer.size();i++)
	{
		if(i<answer.size()-1)printf("%d ",kura[answer[i]]);
		else printf("%d\n",kura[answer[i]]);
	}
	return 0;
}

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

using namespace std;

int main(){
	int n,i,count =0;
	int d1[100],d2[100];
	bool result = false;
	cin >> n;
	for (i=0; i < n; i++){
		cin >> d1[i] >> d2[i];
	}
	for (i=0; i < n; i++){
		if (d1[i] == d2[i]){
			count++;
		}
		else count = 0; 
		if ( count == 3) result = true;		
	}
	if (result == true ) cout << "Yes";
	else cout << "No";
	return 0;
}


Measured memory_bytes: 3624
import Control.Monad

main :: IO ()
main = do
  n <- readLn
  if n == 0
    then return ()
    else do
      ls <- replicateM n getLine
      let scoreL = map words ls
          ansL = solve scoreL
      mapM_ putStrLn ansL
      main

solve :: [[String]] -> [String]
solve ls = foldl getName [] (sort (deform ls))
  where
    getName :: [String] -> (String,Int,Int) -> [String]
    getName acc (n,v,l) = acc ++ [n]
    deform :: [[String]] -> [(String,Int,Int)]
    deform = map result
      where
        result :: [String] -> (String,Int,Int)
        result (x:xs) = (x, (fst count), (snd count))
          where
            count :: (Int,Int)
            count = count' xs (0,0)
              where
                count' :: [String] -> (Int,Int) -> (Int,Int)
                count' [] t = t
                count' (s:r) (v,d)
                  | s == "0" = count' r (v+1,d)
                  | s == "2" = count' r (v,d+1)
                  | otherwise = count' r (v,d)
    sort :: [(String,Int,Int)] -> [(String,Int,Int)]
    sort [] = []
    sort ((n,v,d):r) = (sort higher) ++ [(n,v,d)] ++ (sort lower)
      where
        lower = [(a,b,c) | (a,b,c) <- r, (b < v) || (b == v && c <= d)]
        higher = [(a,b,c) | (a,b,c) <- r, (b > v) || (b == v && c > d)]
  

Measured memory_bytes: 4056
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
const long long int MaxN=10000005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
const float pi=3.1415926535897932384626433832795028;
	lli mcd(lli a,lli b){
		if(a==0)return b;
		return mcd(b%a,a);
	}
int main(){
	cin.tie(0),ios_base::sync_with_stdio(0);
	lli N,X,i,sum=0,p;
	cin>>N>>X;
	for(i=1;i<=N;i++){
		cin>>p;
		sum+=p;
		if(sum>X){
			cout<<i;
			return 0;
		}
	}
	cout<<N+1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((ll)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
typedef long long ll;
ll INF = 1e18;
using namespace std;

map<ll, vector<pair<ll,ll>>> m;
vector<ll> ans;
void dfs(ll current, ll dist,ll from){
  
  for(pair<ll,ll> p: m[current]){
  
    // m[current].erase(m[current].begin());
    
    ll next = p.first;
    if(next==from)continue;
    
    ll next_dist = dist + p.second;
    //
    // cout << "current: " << current << endl;
    // cout << "from: " << from << endl;
    // cout << "next: " << next << endl;
    // cout << "next_dist: " << next_dist << endl;
    // cout << p.first << " " << p.second << endl;
    
    if(next_dist%2==0) ans[next] = 0;
    if(next_dist%2==1) ans[next] = 1;
    
    // cout << "ans: ";
    // rep(i,3) cout << ans[i+1];
    // cout << endl;

    dfs(next, next_dist,current);
  
  }
}

int main(){
  ll N;
  cin >> N;
  ans.resize(N+1);
  
  rep(i,N-1){
    ll u,v,w;
    cin >> u >> v >> w;
    
    m[u].push_back({v,w});
    m[v].push_back({u,w});
  }
  
  ans[1] = 0;

  dfs(1,0,0);
  
  rep(i,N){
    cout << ans[i+1] << endl;
  }



  return 0;
}


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

using namespace std;

typedef long long ll;

#define REP(i, a, b) for (i = a; i < b; i++)
#define REP_ITER(it, v) for (it = v.begin(); it != v.end(); it++)

#define FASTIO                   \
    ios::sync_with_stdio(false); \
    cin.tie(0)

#define TEST(test) \
    int test;      \
    cin >> test;   \
    while (test--)

#define cll(a, b) cin >> a >> b
#define YES cout << "YES\n"
#define NO cout << "NO\n"

#define vi vector<int>
#define vi_iterator vector<int>::iterator

#define si set<int>
#define si_iterator set<int>::iterator

double pi = 2 * acos(0.0);
int i, j;
int main()
{
    FASTIO;
    ll a=0,b=0;
    string s;
    cin >> s;
    REP(i,0,s.size()){
        if(i%2==1){
            if(s[i]=='1')a++;
        }
        else{
            if(s[i]=='0')a++;
        }
    }
    REP(i,0,s.size()){
        if(i%2==1){
            if(s[i]=='0')b++;
        }
        else{
            if(s[i]=='1')b++;
        }
    }
    cout << min(a,b) << endl;
}

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

using namespace std;

int main(){
    int n;
    
    cin >> n;
    vector<int> a(n);

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

    for(int k=0;k<n;k++){
        if(k==n-1){
            cout << a[k] << endl;
            break;
        }
        cout << a[k] << " ";
    }

    for(int i=1;i<n;i++){
        
        int key = a[i];
        int j=i-1;
        while(j>=0&&(a[j+1]<a[j])){
            a[j+1] = a[j];
            a[j] = key;
            j--;
        }

        for(int k=0;k<n;k++){
            if(k==n-1){
                cout << a[k] << endl;
                break;
            }
            cout << a[k] << " ";
        }
    }
    
    return 0;
}


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

int main()
{
	int month[] = {
		0, 31, 29, 31, 30, 31, 30,
		31, 31, 30, 31, 30, 31
	};
	int m, d;
	while(cin >> m >> d){
		if(m == 0) break;
		int days = 0;
		for(int i = 1; i < m; i++) days += month[i];
		days += d;
		days = days % 7;
		switch(days){
		case 0: cout << "Wednesday" << endl; break;
		case 1: cout << "Thursday" << endl;break;
		case 2: cout << "Friday" << endl;break;
		case 3: cout << "Saturday" << endl;break;
		case 4: cout << "Sunday" << endl;break;
		case 5: cout << "Monday" << endl;break;
		case 6: cout << "Tuesday" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

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

vector<vector<char>> g;

void dfs(int x, int y){
    g[x][y]='.'; 

    for(int i=0; i<4; i++){
        int nx=x+dx[i], ny=y+dy[i];
        if(nx<0 || ny<0 || h<=nx || w<=ny || g[nx][ny]=='.') continue;
        dfs(nx, ny);
    }
}


int main(){
    cin >> h >> w;
    g.resize(h, vector<char>(w));
    REP(i, h)   REP(j, w) cin >> g[i][j];


    REP(i, h){
        REP(j, w){
            if(g[i][j]=='#'){
                for(int k=0; k<4; k++){
                    int nx=i+dx[k], ny=j+dy[k];
                    if(nx<0 || ny<0 || h<=nx || w<=ny || g[nx][ny]=='.') continue;
                    dfs(i, j);
                }
            }
        }
    }

    string ans="Yes";
    REP(i, h) REP(j, w) if(g[i][j]=='#') ans= "No";
    
    cout << ans << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

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

        String str;

        while(true){
            str = sc.nextLine();
            if(str.equals(".")) break;
            char [] A;
            A = new char[100];
            A = str.toCharArray();
            char [] c;
            c = new char[100];
            int count=0;
            for(int i=0;i<str.length();i++){
                if(A[i] == '[' || A[i] == ']' || A[i] == '(' || A[i] == ')' ){
                    c[count] = A[i];
                    count++;
                }

            }
            String ans = new String(c);
            for(int i=0;i<50;i++){
                ans = ans.trim();
                ans = ans.replace("()","");
                ans = ans.replace("[]","");
            }
            if(ans.equals("")){
                System.out.println("yes");
            }else{
                System.out.println("no");
            }
        }
        sc.close();
    }
}


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

int N, D;

int main() {
    cin >> N >> D;

    if (N % (2*D + 1) == 0) cout << N / (2*D + 1) << endl;
    else cout << N / (2*D + 1) + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
class Card:
    def __init__(self, suit='', num=''):
        self.suit = suit
        self.num = num
    def __str__(self):
        return "" + self.suit + self.num

def bubble_sort(list):
    for i in range(n):
        for j in range(n - 1, i, -1):
            if list[j].num < list[j - 1].num:
                tmp = list[j]
                list[j] = list[j - 1]
                list[j - 1] = tmp

def selection_sort(list):
    for i in range(n):
        mini = i
        for j in range(i+1, n):
            if list[j].num < list[mini].num:
                mini = j
        tmp = list[mini]
        list[mini] = list[i]
        list[i] = tmp

n = int(input())
inputs = [string for string in input().split(" ")]

cards = []
for i in range(n):
    cards.append(Card(inputs[i][0], inputs[i][1]))

selection_cards = cards.copy()

bubble_sort(cards)
selection_sort(selection_cards)

bubble_result = str(cards[0])
for i in range(1, n):
    bubble_result += " " + str(cards[i]);
print(bubble_result)
print("Stable")

selection_result = str(selection_cards[0])
stable_flag = (cards[0] == selection_cards[0])
for i in range(1, n):
    if cards[i] != selection_cards[i]:
        stable_flag = False
    selection_result += " " + str(selection_cards[i])
print(selection_result)
if stable_flag:
    print("Stable")
else:
    print("Not stable")


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

using namespace std;

#define ll long long
#define endl '\n'

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, a, b;
    cin >> n >> a >> b;
    cout << (n / (a + b)) * a + (n % (a + b) > a ? a : n % (a + b)) << endl;
    return 0;
}

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

int n , x , y , cnt1 , cnt2 ;
map<int,int>mp;

int main(){

cin>>n;
for(int i=0;i<n;i++){
    cin>>x;
    mp[x]++;
}

if( mp.size()>2 ){
    cout<<"No"<<endl;
    return 0;
}
if( mp.size()==1 ){
    x = mp.begin()->first;
    if( x == n-1 || 2*x <= n ){
        cout<<"Yes"<<endl;
    }else
        cout<<"No"<<endl;
    return 0;
}

  x  = mp.begin()->first;
cnt1 = mp.begin()->second;

  y  = (--mp.end())->first;
cnt2 = (--mp.end())->second;

if( x+1==y && cnt1 < y && cnt2/2+cnt1 >=y )
    cout<<"Yes"<<endl;
else
    cout<<"No"<<endl;

return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<stdio.h>
#include<iomanip>
#include<algorithm>
#include<cstring>
using namespace std;

int main() {

  int n, k, d[10];
  bool flag[10], ok=true;
  memset(flag, 1, sizeof(flag));
  cin >> n >> k;
  for(int i=0; i<k; i++){
    cin >> d[i];
    flag[d[i]]=false;
  }
  for(int i=1; i<100000; i++){
    if(n<=i){
      int s=i;
      for(int j=0; j<5; j++){
        if(!flag[s%10]){
          ok=false;
        }
        if(9<s){
          s/=10;
        }
      }
      if(ok){
        cout << i << endl;
        return 0;
      }
      ok=true;
    }
  }

  return 0;
}

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

using ll = long long;

using vi = vector<int>;
using vll = vector<long long>;

constexpr long long mod = 1000000007;

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

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

    ll n, a, b;
    cin >> n >> a >> b;

    vll x(n);
    rep(i, n) cin >> x[i];

    vll c(n,0);

    for (int i = 1; i < n; i++) {
        c[i] = a * (x[i] - x[i - 1]);

        if(c[i]>b){
            c[i] = b;
        }
    }
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        sum += c[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;

int main() {
	int h, a;
	cin >> h >> a;
	if (h % a == 0) cout << h / a;
	else cout << h / a + 1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int dp[3300][3300];

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int m = t.size();
  rep(i,n+1)rep(j,m+1) {
    if(i==0 || j==0) dp[i][j] = 0;
    else {
      dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
      if(s[i-1]==t[j-1]) dp[i][j] = max(dp[i][j],dp[i-1][j-1]+1);
    }
  }
  string ans = "";
  while(n>0 && m>0) {
    if(dp[n][m] == dp[n-1][m]) n--;
    else if(dp[n][m] == dp[n][m-1]) m--;
    else {
      ans += s[n-1];
      n--;
      m--;
    }
  }
  reverse(ans.begin(),ans.end());
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 39168
#include<iostream>
#include<algorithm>
#include<math.h>

bool isPrime( int n ){
  if( n == 2 ) return true;
  if( n < 2 || n % 2 == 0 ) return false;

  int sqrt_n = sqrt(n);
  for( int i = 3; i <= sqrt_n; i+=2 ){
    if( n%i == 0 )  return false;
  }
  return true;
}

int main()
{
  int n;
  std::cin >> n;
  
  int ans = 0;
  int x;
  for( int i = 0; i < n; i++ ){
    std::cin >> x;
    ans += isPrime( x );
  }
  std::cout << ans << std::endl;
}



Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static IEnumerable<int> Count(IEnumerable<char> S)
        {
            int N = S.Count();
            var counts = new int[N];
            for (int i = 0; i < N; ++i)
            {
                int prev = (i == 0) ? 0 : counts[i - 1];
                switch (S.ElementAt(i))
                {
                case '(': counts[i] = prev + 1; break;
                case ')': counts[i] = prev - 1; break;
                }
            }
            return counts;
        }
        static string Solve(string S)
        {
            int min = Math.Min(Count(S).Min(), 0);
            int max = Math.Max(Count(S.Reverse()).Max(), 0);
            return new string('(', -min) + S + new string(')', max);
        }
        static void Main(string[] args)
        {
            int N = ReadInt();
            string S = Read();
            Console.WriteLine(Solve(S));
        }
    }
}


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

int main(){
    string w,t;
    int num=0;
    cin>>w;
    cin>>t;
    while(t!="END_OF_TEXT"){
        for(int i=0;i<t.size();i++){
            if(t[i]>='A'&&t[i]<='Z'){
                t[i]+='a'-'A';
            }
        }
        if(t==w){
            num++;
        }
        cin>>t;
    }
    cout<<num<<endl;
}


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

int main(){
  int N;
  cin >> N;
  if(N<=111){
    cout << "111" << endl;
  } else if(N<=222) {
    cout << "222" << endl;
  } else if(N<=333) {
    cout << "333" << endl;
  } else if(N<=444) {
    cout << "444" << endl;
  } else if(N<=555) {
    cout << "555" << endl;
  } else if(N<=666) {
    cout << "666" << endl;
  } else if(N<=777) {
    cout << "777" << endl;
  } else if(N<=888) {
    cout << "888" << endl;
  } else if(N<=999) {
    cout << "999" << endl;
  }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    AB=[list(map(int,input().split())) for _ in range(m)]
    AB.sort(lambda x:(x[1],x[0]))
    cnt=0
    L,R=AB[0]
    for a,b in AB:
        L=max(L,a)
        if(L>=R):
            cnt+=1
            L=a
            R=b
    print(cnt+1)
resolve()

Measured memory_bytes: 61532
import itertools

n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))

a=[i for i in range(1,n+1)]

cnt_1=0
cnt_2=0
k=0

for i in itertools.permutations(a):
    if list(i)==p:
        cnt_1=k
    if list(i)==q:
        cnt_2=k
    k+=1

print(abs(cnt_1-cnt_2))

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

using ll = long long;

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

    ll x, k, d; cin >> x >> k >> d;
    x = abs(x);
    
    if (k < x/d) {
        printf("%lld\n", x - k*d);
        return 0;
    }

    k-= x/d;
    x%= d;
    if (k % 2) {
        x-= d;
    }
    printf("%lld\n", abs(x));
}


Measured memory_bytes: 3780
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>
#include <climits>

using namespace std;

double sq(double x){return x*x;}

int a[5001];

int main(){
	int n;
	while(cin>>n,n){
		for (int i = 0; i < n; i++){
			cin>>a[i+1];
			a[i+1] += a[i];
		}
		int ans = INT_MIN;
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j <= i; j++)
			{
				ans = max(ans,a[i+1] - a[j]);
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<vs> vvs;

typedef vector<pair<int, int>> vpi;
typedef vector<tuple<int, int, int>> vti;


int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    vpi p(n);
    for (int i=0;i<n;i++){
        int t;
        cin >> t;
        p[i] = make_pair(t, i);
    }
    sort(p.begin(), p.end());
    int cnt = 0;
    for (int i=0;i<n;i++){
        if (i!=p[i].second) cnt++;
    }
    if (cnt == 2 || cnt == 0) cout << "YES" << endl;
    else cout << "NO" << endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;

#define EPS 3e-4

struct point{
	double x, y, z;
};

inline double sq(double x){ return x * x; }

double dist(const point &a, const point &b){
	return sqrt(sq(a.x - b.x) + sq(a.y - b.y) + sq(a.z - b.z));
}

int main(){
	int dataset;
	for( scanf("%d", &dataset); dataset--; ){
		double pq, qr, rp;
		int n;
		scanf("%lf%lf%lf%d", &qr, &rp, &pq, &n);
		
		vector<point> pt(n);
		for(int i = 0; i < n; ++i){
			scanf("%lf%lf%lf", &pt[i].x, &pt[i].y, &pt[i].z);
		}
		
		int p = -1, q = -1, r = -1;
		for(int i = 0; i < n; ++i)
		for(int j = 0; j < n; ++j)
		for(int k = 0; k < n; ++k){
			if( i == j || j == k || k == i ) continue;
			
			double dpq = dist(pt[i], pt[j]);
			double dqr = dist(pt[j], pt[k]);
			double drp = dist(pt[k], pt[i]);
			
			double ratio = dpq / pq;
			if( abs(dqr / qr / ratio - 1.0) < EPS && abs(drp / rp / ratio - 1.0) < EPS ){
				p = i + 1;
				q = j + 1;
				r = k + 1;
			}
		}
		
		printf("%d %d %d\n", p, q, r);
	}
}

Measured memory_bytes: 1076
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, a, b;
  cin >> n;
  a = n % 1000;
  b = n / 10;
  if (a % 111 == 0 || b % 111 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
    
}


Measured memory_bytes: 256
#A=int(input())
#A=list(map(int,(input().split())))
A=list(map(int,(input().split())))
N=A[0]
def dou(ans):
	for x in range(int(N**0.5+1),0,-1):
		if ans%x==0:
			return x
ans=dou(N)
print(N//ans+ans-2)

Measured memory_bytes: 3060
import numpy as np
 
N,M = map(int,input().split())
A = np.array([list(input()) for _ in range(N)])
B = np.array([list(input()) for _ in range(M)])
 
bl = False
for i in range(N-M+1):
  for j in range(N-M+1):
    if (A[i:i+M,j:j+M] == B).all():
      bl = True
 
answer = 'Yes' if bl else 'No'
print(answer)

Measured memory_bytes: 12440
<?php

while (TRUE) {
    fscanf(STDIN, '%d', $n);
    if ($n === 0) {
        break;
    }
    $a = array();
    for ($i = 0; $i < $n; $i++) {
        fscanf(STDIN, '%d', $a[$i]);
    }
   
    $dp = array();
    $dp[0] = -1;
    for ($i = 1; $i <= $n; $i++) {
        $dp[$i] = $dp[$i - 1] >= 0 ? $dp[$i - 1] + $a[$i - 1] : $a[$i - 1];
    }
    $max = $dp[1];
    for ($i = 1; $i <= $n; $i++) {
        if ($dp[$i] > $max) {
            $max = $dp[$i];
        }
    }

    echo $max;
    echo PHP_EOL;
}

Measured memory_bytes: 7476