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

using namespace std;

#define int long long

int n, m;
int a[100001];

struct Node
{
	int val, lazy_a, lazy_d;
	Node(){}
}Seg[400001];	

void diffuse(int node, int l, int r)
{
	Seg[node].val += (Seg[node].lazy_a * (r - l + 1) + Seg[node].lazy_d * (r - l) * (r - l + 1) / 2);
	if (l != r)
	{
		Seg[node * 2].lazy_a += Seg[node].lazy_a;
		Seg[node * 2].lazy_d += Seg[node].lazy_d;
		int mi = (l + r)/2;
		int nxt_a = Seg[node].lazy_a + (mi + 1 - l) * Seg[node].lazy_d;
		Seg[node * 2 + 1].lazy_a += nxt_a;
		Seg[node * 2 + 1].lazy_d += Seg[node].lazy_d;
	}
	Seg[node].lazy_a = Seg[node].lazy_d = 0;
}

void upd(int node, int l, int r, int ll, int rr, int val, int d)
{
	diffuse(node, l, r);
	if (ll > rr)
		return;
	if (r < ll || rr < l)
		return;
	if (ll <= l && r <= rr)
	{
		Seg[node].lazy_a += val + (l - ll) * d;
		Seg[node].lazy_d += d;
		diffuse(node, l, r);
		return;
	}
	int mi = (l + r)/2;
	upd(node * 2, l, mi, ll, rr, val, d);
	upd(node * 2 + 1, mi + 1, r, ll, rr, val, d);
	//Seg[node].val = Seg[node * 2].val + Seg[node * 2 + 1].val; // Not necessary
}

// Not needed

/*
int query(int node, int l, int r, int ll, int rr)
{
	diffuse(node, l, r);
	if (ll > rr)
		return 0;
	if (r < ll || rr < l)
		return 0;
	if (ll <= l && r <= rr)
		return Seg[node].val;
	int mi = (l + r)/2;
	int a = query(node * 2, l, mi, ll, rr);
	int b = query(node * 2 + 1, mi + 1, r, ll, rr);
	return a + b;	
}
*/

int get_ans(int node, int l, int r)
{
	diffuse(node, l, r);
	if (l == r)
		return Seg[node].val;
	int mi = (l + r) /2;
	return min(get_ans(node * 2, l, mi), get_ans(node * 2 + 1, mi + 1, r));
}

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

	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> a[i];

	for (int i = 2; i <= n; i++)
		if (a[i - 1] < a[i])
		{
			// .....S.....T.....                           
			upd(1, 1, m, 1, a[i - 1], a[i] - a[i - 1], 0); // from 1 to S
			upd(1, 1, m, a[i] + 1, m, a[i] - a[i - 1], 0); // from T + 1 to m

			// from S + 1 to T
			upd(1, 1, m, a[i - 1] + 1, a[i], 1 + a[i], 0);
			upd(1, 1, m, a[i - 1] + 1, a[i], -(a[i - 1] + 1), -1);
		}
		else
		{
			// ....T.....S.....
			upd(1, 1, m, a[i] + 1, a[i - 1], m - a[i - 1] + 1 + a[i] - 1, 0); // from T + 1 to S

			// from S + 1 to m
			upd(1, 1, m, a[i - 1] + 1, m, (1 + a[i] - 1) + 1 + m, 0);
			upd(1, 1, m, a[i - 1] + 1, m, -(a[i - 1] + 1), -1);

			// from 1 to T
			upd(1, 1, m, 1, a[i], 1 + a[i], 0);
			upd(1, 1, m, 1, a[i], -1, -1);
		}
	cout << get_ans(1, 1, m);
}

Measured memory_bytes: 10572
#include <stdio.h>
#include <string.h>

int main(void)
{
	char str[1000];
	int i, len;
	
	fgets(str, 1000, stdin);
	len = strlen(str);
	for (i = 0; i < len; i++){
		if (str[i] >= 'a' && str[i] <= 'z'){
			str[i] -= 0x20;
		}
	}
	
	printf("%s", str);
	
	return (0);
}

Measured memory_bytes: 524
#include <iostream>

using namespace std;

int main(){
    string s;
    //sを定義
    cin >> s;
    //標準入力

    bool isgood = true;
    if (s[0] == s[1]) isgood = false;
    if (s[1] == s[2]) isgood = false;
    if (s[2] == s[3]) isgood = false;
    //隣り合う文字を比較して判定
    if (isgood){
        cout << "Good" << endl;
    } else {
        cout << "Bad" << endl;
    }
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
string s;
int main() {
	cin >> s;
	bool ret = (s == "ABC");
	while (!ret) {
		vector<int> v(s.size(), 0);
		for (int i = 2; i < s.size(); i++) {
			if (s[i - 2] == 'A' && s[i - 1] == 'B' && s[i] == 'C') {
				v[i - 2] = v[i - 1] = v[i] = 1;
			}
		}
		vector<int> ok(3, 1);
		for (int i = 0; i < s.size(); i++) ok[s[i] - 65] &= v[i];
		if (ok[0] + ok[1] + ok[2] != 1) break;
		int z = -1;
		for (int i = 0; i < 3; i++) if (ok[i]) z = i;
		string res;
		for (int j = 0; j < s.size();) {
			if (j <= s.size() - 3 && v[j] == 1) res += (char)(z + 65), j += 3;
			else res += s[j], j++;
		}
		if (res == "ABC") { ret = true; break; }
		if (res.size() != s.size()) s = res;
		else break;
	}
	cout << (ret ? "Yes" : "No") << endl;
	return 0;
}

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


int main(){
    int N, M; cin >> N >> M;
    vector<pair<int, int>> brige(M);
    rep(i, M){
        int a, b; cin >> a >> b;
        a--, b--;
        brige[i] = make_pair(b, a);
    }
    sort(begin(brige), end(brige));

    int res = 1;
    int end = brige[0].first;
    int start = brige[0].second;
    for(int i = 1; i < M; ++i){
        if(brige[i].second >= end){
            ++res;
            end = brige[i].first;
            start = brige[i].second;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
bool seat[100010];
int main() {
  int n;
  cin >> n;
  int a;
  ll ans = 1;
  rep(i,n) {
    cin >> a;
    if ((n+a-1) % 2 != 0) {
      ans = 0;
      break;
    }
    int y1 = (n+a-1) / 2 + 1;
    int y2 = (n-a-1) / 2 + 1;
    if (y1 == y2 & !seat[y1]) {
      seat[y1] = true;
      continue;
    }
 
    if (!seat[y1] && !seat[y2]) {
      seat[y1] = true;
      ans *= 2;
    } else if (!seat[y2]) {
      seat[y2] = true;
    } else ans = 0;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    string s;cin >> s;
    int n = s.size();
    int k;cin >> k;
    for(auto &c : s){
        int m = 'z'-c+1;
        if(c == 'a') continue;
        if(m <= k){
            c = 'a';
            k -= m;
        }
    }
    s[n-1] = 'a' + (s[n-1]-'a'+k)%26;
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 592
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <cctype>
#include <algorithm>
using namespace std;
int main(void){
    int A , B ;
    cin >> A >> B ;
    if(A == 1){
        A =14;
    }
    if(B == 1){
         B = 14;
    }
    if( A > B ){
        cout << "Alice" << endl;
    } else if(A < B){
        cout << "Bob" << endl;
    }else{
        cout << "Draw" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;
 
public class Main {
    @SuppressWarnings("unchecked")
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int V = sc.nextInt();
        int E = sc.nextInt();

        Object[] list = new Object[V];
        for (int i = 0; i < V; i++) {
            list[i] = new LinkedList<Edge>();
        }
        for (int i = 0; i < E; i++) {
            int s = sc.nextInt();
            int t = sc.nextInt();
            int w = sc.nextInt();
            LinkedList<Edge> edges = (LinkedList<Edge>)list[s];
            edges.add(new Edge(s, t, w));
            edges = (LinkedList<Edge>)list[t];
            edges.add(new Edge(t, s, w));
        }
        solve(V, E, list);
    }
     
    @SuppressWarnings("unchecked")
	public static void solve(int V, int E, Object[] list) {
        boolean[] visited = new boolean[V];
        PriorityQueue<Edge> que = new PriorityQueue<Edge>(10000, new Comparator<Edge>() {
            @Override
            public int compare(Edge o1, Edge o2) {
                return o1.w - o2.w;
            }
        });
        
        int node = 0; // start
        visited[node] = true;
        int d = 0;
        int count = 0;
        
        LinkedList<Edge> edges = (LinkedList<Edge>)list[node];
        Iterator<Edge> it = edges.iterator();
        while(it.hasNext()) {
        	que.add(it.next());
        }
        while(que.isEmpty() == false) {
            Edge edge = que.poll();
            if (visited[edge.t])
                continue;
            
            visited[edge.t] = true;
            node = edge.t;
            d += edge.w;

            it = ((LinkedList<Edge>)list[node]).iterator(); 
            while(it.hasNext()) {
            	edge = it.next();
            	if (visited[edge.t])
            		continue;
            	que.add(edge);
            }
            
            count++;
            if (count >= V-1)
                break;
        }
        System.out.println(d);
    }
}
 
class Edge {
    int s;
    int t;
    int w;
    public Edge(int s, int t, int w) {
        this.s = s;
        this.t = t;
        this.w = w;
    }
}

Measured memory_bytes: 110396
#include <set>
#include <cstdio>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

double l[20];
double a[20];
double b[20];

template<class T>
T dbl(T a){ return a * a; }

int main(){
  int n, m;
  scanf("%d%d", &n, &m);

  REP(i,n){
    scanf("%lf%lf%lf", l+i, a+i, b+i);
  }

  double ans = 0.0;
  REP(i, (1 << n)){
    if(__builtin_popcount(i) == m){
      double tmp = 0.0;
      REP(j, n) if(i & (1 << j)){
	for(int k = j + 1; k < n; k++) if(i & (1 << k)){
	    tmp += dbl(l[j] - l[k]);
	    tmp += dbl(a[j] - a[k]);
	    tmp += dbl(b[j] - b[k]);
	}
      }
      ans = max(ans, tmp);
    }
  }
  
  printf("%.6f\n", ans);

  return 0;
}

Measured memory_bytes: 772
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int Y = scan.nextInt();
        int[] a = new int[3];
        Arrays.fill(a, -1);
        boolean found = false;
        for (int i = 0; i <= N; i++) {
            if (Y < i * 10000) {
                continue;
            }
            int remain1 = Y - i * 10000;
            for (int j = 0; j <= N - i; j++) {
                if (remain1 < j * 5000) {
                    continue;
                }
                int remain2 = remain1 - j * 5000;
                if (N - i - j == remain2 / 1000) {
                    a[0] = i;
                    a[1] = j;
                    a[2] = N - i - j;
                    break;
                }
            }
            if (found) {
                break;
            }
        }
        System.out.printf("%d %d %d\n",a[0],a[1],a[2]);

    }
}


Measured memory_bytes: 23764
#include <stdio.h>
#include <algorithm>

long long array[100001];
int main()
{
	long long N, K;
	scanf("%lld%lld", &N, &K);
	int i;
	for (i = 0; i < N; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		array[i] = a * 1000000ll + b;
	}
	std::sort(array, array + i);
	long long idx = 0;
	for (i = 0; i < N; i++)
	{
		idx += array[i] % 1000000;
		if (idx >= K)
		{
			printf("%lld\n", array[i] / 1000000);
			break;
		}
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back
#define mp make_pair

int main()
{
    ll N;
    cin >> N;
    vec A(N);
    ll p = 1;
    long double _p = 1;
    for(ll i=0; i<N; ++i) cin >> A[i];
    sort(ALL(A));
    for(ll i=0; i<N; ++i) {
        p *= A[i];
        _p *= A[i];
        if(p > 1e18 || _p > 1e18) {
            p = -1;
            break;
        }
    }
    _PR(p);

    return 0;
}

/*



*/

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

int n, k;
ll T[MAX];

int check(ll P){
    int i = 0;

    for(int j = 0; j < k; j++){
        ll w = 0;
        while(w + T[i] <= P){
            w += T[i];          
            i++;
            if(i == n) return n;
        }
    }

    return i;
}

int solve(){
    ll left = 0;
    ll right = 100000 * 10000;
    ll mid;
    while(left + 1 < right){
        ll mid = (left + right) / 2;
        int v = check(mid);
        if(v >= n) right = mid;
        else left = mid;
    }
    return right;
}
int main(){
    cin >> n >> k;
    rep(i,n) scanf("%d", &T[i]);
    ll ans = solve();
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, L;
    cin >> N >> L;
    int ans = (2*L+N-1)*N/2;
    if(L>0) ans -= L;
    if(L+N-1<0) ans -=L+N-1;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 51
int main(void){
    int n;//長さN
    char s[N];//文字列s
    int k;//文字列sのk文字目を小文字にする

    //入力
    scanf("%d %d",&n,&k);
    scanf("%s",s);

    //大文字から小文字
    s[k-1]=s[k-1]+32;

    printf("%s",s);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <functional>

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

using namespace std;
using ll = long long;


int main() {
	int N;
	double N_;
	cin >> N;
	N_ = sqrt(N);
	N = pow(int(N_), 2);
	cout << N << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int[] frq = new int[26];
        for(int i = 0 ; i < s.length() ; i++)
        {
            if( Character.isLowerCase(s.charAt(i)) )
            {
                frq[s.charAt(i)-'a']++;
            }
        }
        boolean flag = true;
        for(int i = 0 ; i < 26; i++)
            if(frq[i]%2!=0)
            {
                flag = false;
                break;
            }

        if(flag)
            System.out.println("Yes");
        else System.out.println("No");
    }
}


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

int dp[3000][3000][2];
ll fact[3000];

int main(){
	fact[0]=1;
	for(int i=1;i<3000;i++)fact[i]=(fact[i-1]*i)%MOD;
	int n,K;scanf("%d%d",&n,&K);
	map<int,vector<int>>mp;
	rep(i,n){
		mp[i%(2*K)].push_back(i);
	}
	dp[0][0][0]=1;
	int cnt=0;
	for(auto p:mp){
		for(int i=cnt;i<cnt+p.second.size();i++)rep(j,n+1)rep(k,2){
			if(dp[i][j][k]==0)continue;
			int d=p.second[i-cnt];
			if(d+K<n)(dp[i+1][j+1][i-cnt==p.second.size()-1?0:1]+=dp[i][j][k])%=MOD;
			if(k==0&&d-K>=0)(dp[i+1][j+1][0]+=dp[i][j][k])%=MOD;
			(dp[i+1][j][0]+=dp[i][j][k])%=MOD;
		}
		cnt+=p.second.size();
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		int sum=(dp[n][i][0]+dp[n][i][1])*fact[n-i]%MOD;
		if(i&1)(ans+=sum)%=MOD;
		else ans=(ans+MOD-sum)%MOD;
	}
	cout<<(fact[n]+MOD-ans)%MOD<<endl;
}

Measured memory_bytes: 45824
#include <stdio.h>
#include <cmath>
#include <algorithm>
 
int main(){
    int n,tmp,count = 0,limit;
    scanf("%d",&n);
 
    for(int i = 0; i < n; i++)
    {
        scanf("%d",&tmp);
        limit = sqrt(tmp);
        for(int j = 2; j <= limit; j++){
            if(tmp%j==0){
                count++;
                break;
            }
        }
    }
    printf("%d\n",n-count);
}


Measured memory_bytes: 2728
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)

using namespace std;

int main() {
  long long a, b, x;
  cin >> a >> b >> x;
  long long b_set = (b / x);
  if (a >= x) {
    b_set -= (a / x);
  }
  if (a % x == 0) {
    b_set++;
  }

  cout << b_set << "\n";

  return(0);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 200010
ll n,k;
ll p[N];
vector<ll> g[N];
ll l[N],r[N];
void dfs1(ll x,ll from){
    for(auto y:g[x])if(y!=from){
	dfs1(y,x);
    }
    if(-1!=p[x]){
	l[x]=r[x]=p[x];
    }
    else{
	l[x]=-1e17,r[x]=1e17;
	for(auto y:g[x])if(y!=from){
	    chmax(l[x],l[y]-1);
	    chmin(r[x],r[y]+1);
	}
    }
}
bool dfs2(ll x,ll from,ll t){
    //if((t+1)%2!=l[x]%2&&l[x]>-1e9)return 0;
    if(l[x]<=t+1&&t+1<=r[x])p[x]=t+1;
    else if(l[x]<=t-1&&t-1<=r[x])p[x]=t-1;
    else return 0;
    for(auto y:g[x])if(y!=from){
	if(dfs2(y,x,p[x])==0)return 0;
    }
    return 1;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin>>n;
    for(int i=0;i<n-1;i++){
	ll a,b; cin>>a>>b;
	g[a].push_back(b);
	g[b].push_back(a);
    }
    for(int i=1;i<=n;i++){
	p[i]=-1;
    }
    cin>>k;
    ll root=-1;
    for(int i=0;i<k;i++){
	ll v; cin>>v;
	cin>>p[v];
	root=v;
    }
    dfs1(root,0);
    /*cout<<root<<endl;
    for(int i=1;i<=n;i++)cout<<i<<":"<<l[i]<<" "<<r[i]<<endl;*/
    bool ok=1;
    for(auto x:g[root]){
	ok&=dfs2(x,root,p[root]);
    }
    if(ok){
	cout<<"Yes"<<endl;
	for(int i=1;i<=n;i++){
	    for(auto x:g[i]){
		if(abs(p[i]-p[x])!=1)cout<<1/0<<endl;
	    }
	    cout<<p[i]<<endl;
	}
    }
    else cout<<"No"<<endl;
}




Measured memory_bytes: 18176
n = gets.to_i
s1 = gets.chomp
s2 = gets.chomp

pat = {
  none: { tate: 3, yoko: 6 },
  tate: { tate: 2, yoko: 2 },
  yoko: { tate: 1, yoko: 3 }
}

ans = 1
i = 0
pre = :none
MOD = 10 ** 9 + 7

while i < n
  now = s1[i] == s2[i] ? :tate : :yoko
  ans = ans * pat[pre][now] % MOD
  pre = now
  i += 1
  i += 1 if now == :yoko
end

puts  ans
  

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    string N;
    //int N, A, B;
    cin >> N;// >> A >> B;
    string tmp;
    for(int i=0;i<10;i++){
        tmp = to_string(100 * i + 10 * i + i);
        if(i == 0)
            tmp = "000";
        //cout <<tmp <<endl;
        if(N.find(tmp) != string::npos){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,m;
    cin >> n;
    string s,t;
    cin >> s;
    t = "red";
    if(n >= 3200)t = s;
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main () {
  int num,x,count=0,i,r;
  int hantei(int);

  scanf("%d",&num);

  for(i=0;i<num;i++) {
    scanf("%d",&x);
    r = hantei(x);
    if(r == 1)
      count++;
  }
  printf("%d\n",count);

  return 0;
}

int hantei(int x) {
  int j;
  if(x<2) return 0;
  else if(x==2) return 1;
  if(x%2==0) return 0;
  for(j=3;j*j <=x; j+=2){
    if(x%j==0) return 0;
  }
  return 1;
}



Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
long long h,w;
int main(){
    scanf("%lld%lld",&h,&w);
    if(h==1||w==1){
        printf("1");
        return 0;
    }
    if(h%2==0||w%2==0){
        printf("%lld",h*w/2);
    }else{
        printf("%lld",h*w/2+1);
    }
    return 0;
}


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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int m1, d1, m2, d2; cin >> m1 >> d1 >> m2 >> d2;
        cout << (m1 == m2 ? 0 : 1) << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
  char s[20];
  scanf("%s",s);
  int i,n=strlen(s);
  int count=0;
  for(i=0;i<n;i++)
    if(s[i]=='x')
      count++;
  if(count<8)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <utility>
#include <queue>

using namespace std;

typedef long long int ll;

int N,M;

const int DATA_SIZE=100000;
const ll BIGNUM = 2000000000;

// 値段*美味しさ
pair<ll, ll> sweets[DATA_SIZE];
// 値段*個数
pair<ll,ll> friends[DATA_SIZE+1];

struct Sweet_ptr_comp{

    // 美味しさを下降順
    int operator()(pair<ll, ll> *a, pair<ll, ll> *b)
    {
        return a->second<=b->second;
    }
};

// 
using MaxQueue=priority_queue<pair<ll,ll>*,vector<pair<ll,ll>*>,Sweet_ptr_comp>;


int main(){

    scanf("%d%d",&N,&M);
    for (int i=0;i<N;i++) 
        scanf("%lld%lld", &sweets[i].first, &sweets[i].second);

    ll prev=BIGNUM;
    for (int i=0;i<M;i++) {
        scanf("%lld%lld", &friends[i].first, &friends[i].second);
        friends[i].second=min(prev,friends[i].second);
        prev = friends[i].second;
    }

    //　仮想の友達
    friends[M]=pair<ll,ll>(BIGNUM,1);

    // indexは探索したお菓子のインデクス
    int index=0;
    ll ans=0;

    // 価値の小さいお菓子をいっぱい持つ
    while (index<N&&sweets[index].first<friends[0].first)
        ans+=sweets[index++].second;
    
    
    // printf("%lld\n",ans);

    MaxQueue Q;
    // 全ての友達にたいする
    for (int i=0;i<M;i++){


        // 値段が今の友達と次の友達の間のお菓子を最大ヒープに追加
        while (
            index<N
            &&sweets[index].first>=friends[i].first
            &&sweets[index].first<friends[i+1].first)
             Q.push(&sweets[index++]);

        // 美味しさの高い奴から
        for (int j=friends[i].second;j>friends[i+1].second&&!Q.empty();j--){

            // printf("%lld %lld\n",Q.top()->first,Q.top()->second);
            ans+=Q.top()->second;
            Q.pop();
        }

    }

    printf("%lld\n",ans);

    return 0;
}


Measured memory_bytes: 6576
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
#define init(c) memset(c,0,sizeof c)
typedef long long ll;
const int N=20000005;
int n,k,x,t,a,b,m;
string s;
vector<int>v;
int main(){

	cin >> n >> m;
	int sum=0;
	for(int i =0;i<n;i++){
		cin >> x;
		v.push_back(x);
		sum+=x;
	}
	double c = 1/(4.0*m)*sum;
	for(int i =0;i<n;i++){
		if(v[i]>=c){
			m--;
		}
	}
	if(m>0){
		cout << "No";
	}else{
		cout << "Yes";
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,S;
  cin >> N >> K;
  vector<int> p(N);
  for (int i=0; i<N; i++) {
    cin >> p.at(i);
  }
  S = 0;
  
  sort(p.begin(),p.end());
  
  for (int i=0; i<K; i++) {
    S = S + p.at(i);
  }
      
  cout << S << endl;
  
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;


int main(){
    ll n,m;cin >>n>>m;
    ll ans=0;
    ans+=min(n,m/2);
    m=(m-2*ans<0)?0:m-2*ans;
    ans+=m/4;
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  map< char , int > count;
  string str;
  while( cin>>str ){
    for(int i=0;i<(int)str.size();i++){
      if( isupper(str[i]) ){
        str[i]=tolower(str[i]);
      }
    }
    for(int i=0;i<(int)str.size();i++){
      count[ str[i] ]++;
    }
  }
  for(char ch='a';ch<='z';ch++){
    cout<<ch<<" : "<<count[ch]<<endl;
  }
  return 0;
}


Measured memory_bytes: 3176
n, m = map(int, input().split())
l = []
for i in range(n):
  a, b = map(int, input().split())
  l.append([a, b])

l.sort()
ans = 0
for i in range(n):
  if l[i][1] <= m:
    ans += l[i][0] * l[i][1]
    m -= l[i][1]
  else:
    ans += l[i][0] * m
    break
print(ans)

Measured memory_bytes: 20056
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
#define SELECTOR(_1, _2, _3, SELECT, ...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__, _rep1, _rep0)(__VA_ARGS__)
#define _rep0(i, n) for (ll i = 0; i < n; ++i)
#define _rep1(i, k, n) for (ll i = k; i < n; ++i)

void solve() {
  // input
  ll n,m; cin>>n>>m;
  vector<vector<int>> E(n);
  rep(_,m) {
    ll a,b; cin>>a>>b;
    --a; --b; // 0-indexed
    E[a].push_back(b);
  }
  // bfs
  function<vector<ll>(ll)> bfs=[&](ll sv){
    vector<ll> prev(n,-1); // also as visited
    ll last=-1;
    queue<ll> q;
    q.push(sv);
    while(!q.empty()) {
      ll v=q.front(); q.pop();
      for(ll nv:E[v]) {
        if(nv==sv) { // loop detected
          last=v;
          break; // for loop
        } else if(prev[nv]==-1) { // unvisited
          prev[nv]=v;
          q.push(nv);
        }
      }
      if(last!=-1) break; // while loop
    }
    // return loop
    if(last!=-1) {
      vector<ll> loop;
      while(last!=-1) {
        loop.push_back(last);
        last=prev[last];
      }
      reverse(loop.begin(),loop.end());
      return loop;
    } else return vector<ll>(n+1);
  };
  // shortest loop
  vector<ll> ans(n+1);
  rep(v,n) {
    vector<ll> now=bfs(v);
    if(now.size()<ans.size()) ans=now;
  }
  // output
  if(ans.size()==n+1) cout<<-1<<"\n";
  else {
    cout<<ans.size()<<"\n";
    for(ll v:ans) cout<<v+1<<"\n"; // 1-indexed
  }
}

int main() {
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}


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

int main()
{
	int n,i;
	cin>>n;
	string s,t,str="";
	cin>>s>>t;
	for(i=0;i<n;i++)
	{
		str+=s[i];
		str+=t[i];
	}
	cout<<str;
	return 0; 
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define pi(n,m) n.insert(n.begin(),m);
#define ee(n) n.erase(n.end()-1)
#define eb(n) n.erase(n.begin())
#define check(n) reverse(all(n));rep(z,0,n.size())cout<<n[z];co("");reverse(all(n));
using namespace std;
using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  ll n,ans=0,ca=1;
  pair<ll,int> p;
  ll rootn,cc=0;
  cin >> n;
  if(n==1){co(0); return 0;}
  rootn=pow(n, 0.5);
  vector<ll> prime={2,3,5,7};
  vector<pair<ll,int>> pp={};
  bool f=true,g=true;
  if(n==2 || n==3) f=true;
  ll root=3, num=11, c=1, wc=0, thr=0;
  while(num<=rootn){
    if((root+1)*(root+1)<num) root++;
    if(root>prime[c-1]) c++;
    rep(i,0,c){
      if(num/prime[i]*prime[i]==num){
        g=false;
        break;
      }
    }
    if(g==true) prime.push_back(num);
    else g=true;
    thr++;
    if(thr==2){
      num+=4;
      thr=0;
    }
    else num+=2;
  }
  rep(i,0,prime.size()){
    p.first=prime[i];
    p.second=0;
    while(1){
      if(n%prime[i]==0){
        p.second++;
        n/=prime[i];
      }
      else break;
    }
    if(p.second!=0) pp.push_back(p);
    if(n<prime[i]) break;
  }
  if(pp.size()==0) co(1);
  else{
    rep(i,0,pp.size()){
      while(1){
        if(pp[i].second>=ca){ans++; pp[i].second-=ca;}
        else break;
        ca++;
      }
      ca=1;
    }
    if(n!=1) ans++;
    co(ans);
  }
  return 0;
}


Measured memory_bytes: 4836
//use proconio::{input, fastout};
use proconio::input;
use std::collections::HashMap;

//#[fastout]
fn main() {
    input! {
        n: usize, k: u64,
        a: [usize; n],
    }

    if a[0] == 1 {
//        println!("1");
//        return;
    }

    let mut h = HashMap::new();
    let mut count = 0;
    let mut p = 1;
    while count < k {
        h.insert(p, count);
        count += 1;
        let next = a[p - 1];
        if let Some(s) = h.get(&next) {
            let loops = count - s;
            let k = (k - s) % loops + s;
            let (p, _) = h.iter().find(|(_, v)| **v == k).unwrap();
            println!("{}", p);
            return;
        }
        p = next;
    }
    println!("{}", p);
}


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

int n;
std::vector<int> b;

void read_input() {
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        int t;
        scanf("%d", &t);
        b.push_back(t - 1);
    }
}

bool check(std::vector<int> &seq, std::vector<int> &answer) {
    if (seq.empty()) {
        return true;
    } else {
        for (int i = seq.size() - 1; i >= 0; i--) {
            if (seq[i] == i) {
                answer.push_back(i);
                seq.erase(seq.begin() + i);
                return check(seq, answer);
            }
        }
        return false;
    }
}

void solve() {
    std::vector<int> answer;
    if (!check(b, answer)) {
        std::cout << -1 << std::endl;
    } else {
        std::reverse(answer.begin(), answer.end());
        for (auto t: answer) {
            std::cout << t + 1 << std::endl;
        }
    }
}

int main() {
    // freopen("a.in", "r", stdin);

    read_input();
    solve();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll long long int
#define ld long double
#define pb push_back
#define pq priority_queue
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vvll vector<vector<ll>>
#define vvi vector<vector<int>>
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define MODNUM 1000000007
#define lp(i,a,b) for(ll i=a; i<b; i++)
 
using namespace std;
 
ll mex(ll a, ll b, ll m) {
	if(b==0) return 1;
	if(b%2) return a*mex((a*a)%m,(b-1)/2,m)%m;
	else return mex((a*a)%m,b/2,m);
}
 
int x,y;
void exteu(ll a, ll m) {
	if(m==0) { x=1;y=0; }
	else {
		exteu(m,a%m);
		ll temp = x;
		x=y;
		y=temp-(a/m)*y;
	}
}
 
ll fact(ll n) 
{	ll prod=1;
	for(ll i=2; i<=n; i++) {
		prod*=i;
	}
	return prod;
}
 
ll gcd(ll a, ll b) {
	if(b==0) return a;
	return gcd(b, a%b);
}
 
// bool isprime[100001];
// void makesieve() {
// 	memset(isprime, true, sizeof(isprime));
// 	for (int i = 2; i <= sqrt(200000); ++i)
// 	{
// 		if(isprime[i]) {
// 			for (int j = i*i; j <= 200000; j+=i)
// 			{
// 				isprime[j]=false;
// 			}
// 		}
// 	}
// }
// 
// 1 2 4 5 8
void solve() {
	char c; cin>>c;
	if(c<='z' && c>='a') c = 'a';
	else c = 'A';
	cout<<string(1,c)<<endl;
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll TESTS=1;
	// cin >> TESTS;
	// makesieve();
	while(TESTS--) {
		solve();
	}
	return 0;
}


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

#define fi first
#define se second

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

    int n;cin>>n;
    map<int,int> nm;
    for(int i=0;i<n;i++)
    {
        int d;cin>>d;
        nm[d]++;
    }
    int m;cin>>m;
    map<int,int> mm;
    for(int i=0;i<m;i++)
    {
        int t;cin>>t;
        mm[t]++;
    }

    bool ans=true;

    for(auto im:mm)
    {
        if(nm[im.fi]<im.se){ans=false;break;}
    }

    puts(ans?"YES":"NO");

    return 0;
}


Measured memory_bytes: 22320
c = []
for i in range(3):
    c.append(list(map(int, input().split())))

for i in range(2):
    if c[0][i] - c[0][i+1] == c[1][i] - c[1][i+1] == c[2][i] - c[2][i+1]:
        continue
    else:
        print("No")
        exit()
print("Yes")

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

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<cstring>
#include<sstream>
#define FR first
#define SC second
#define MP make_pair
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=100010;
const int p=1000000007;
int pow(int a,int b,int c)
{
    if (a==0)return 0;
    int d=a,e=1;
    while (b)
    {
        if (b&1) e=(1LL*e*d)%c;
        d=1LL*d*d%c;
        b>>=1;
    }
    return e;
}
int random(int n) { return 1LL*rand()*rand()%n+1;}
int n;
int a[10];
char s[100];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%s",s);
		if (s[0]=='M') a[0]++;
		if (s[0]=='A') a[1]++;
		if (s[0]=='R') a[2]++;
		if (s[0]=='C') a[3]++;
		if (s[0]=='H') a[4]++;
	}
	LL ans=0;
	for (int i=0;i<5;i++)
	for (int j=i+1;j<5;j++)
	for (int k=j+1;k<5;k++)
		ans+=1LL*a[i]*a[j]*a[k];
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[100001],b[100001]={'C','O','D','E','F','E','S','T','I','V','A','L','2','0','1','6'};
int main(){
	int ans=0;
	cin>>a;
	for(int i=0;i<16;i++)
		if(a[i]!=b[i])
			ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
     try(Scanner sc= new Scanner(System.in)){
         while(true){
         int n =sc.nextInt();
         int r= sc.nextInt();
         if(n==0 && r==0){
             break;
         }
         int[] deck =new int[n];
         for(int i=0;i<deck.length;i++){
             deck[i]=i+1;
         }
         for(int i=0;i<r;i++){
             int p =sc.nextInt();
             int c= sc.nextInt();
             int[] save1=new int[n-c];
             int[] save2=new int[c];
             int a=0,b=0;
             for(int j=0;j<deck.length;j++){
               //  System.out.println("ok");
                 if(j<=n-p && j>n-p-c){
                   //  System.out.println("case1");
                     save2[a]=deck[j];
                     a++;
                 }else{
                   //  System.out.println("case2");
                     save1[b]=deck[j];
                     b++;
                 }
             }
             for(int j=0;j<deck.length;j++){
                 if(j<n-c){
                    deck[j]=save1[j];
                 }else{
                     deck[j]=save2[j-n+c];
                 }
             }
         //  System.out.println("roop");  
         } 
         System.out.printf("%d\n",deck[n-1]); 
        }
     }
      
    }
}


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

using namespace std;

typedef long long int ll;
typedef long long unsigned int llu;
#define tc long long int t; cin>>t; while(t--)
#define  sync ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define mpi unordered_map<ll, ll>
#define mpc unordered_map<char, ll>
#define map_loop(it,m) for(auto it = m.begin(); it!=m.end(); it++)
#define rep(i,n) for(ll i=0;i<n;i++)



template<typename... T>
void read(T&... args){
  ((cin>>args), ...);
}

template<typename... T>
void write(T... args){
  ((cout<<args<<" "), ...);
}


int main(){
  
  sync;
  ll n,m;
  read(n,m);
  int a[m];
  ll sum=0;
  
  rep(i,m){
    cin>>a[i];
     sum+=a[i];
  }
  
  if(n-sum>=0)
   cout<<n-sum<<endl;
  else
   cout<<-1<<endl; 
  
  
  
}


Measured memory_bytes: 3696
# frozen_string_literal: true

k = gets.to_i

if k.even?
  puts '-1'
  exit
end

s = 7
(10**6).times do |i|
  if (s % k).zero?
    puts i + 1
    exit
  end
  s *= 10
  s += 7
  s %= k
end
puts '-1'


Measured memory_bytes: 14416
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int ans = (int)(Math.pow(n/2, 2));
    System.out.println(n%2 == 0 ? ans : ans+(n/2));
  }
}


Measured memory_bytes: 35572
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/B-GridCompression.py
#
import numpy as np

h, w = map(int, input().split())
a = []
for i in range(h):
    a_i = input()
    if a_i != '.' * w:
        a.append(list(a_i))

b = [""] * len(a)

for j in range(w):
    for i in range(len(a)):
        if a[i][j] == "#":
            break

    if a[i][j] == "#":
        for ii in range(len(a)):
            b[ii] = b[ii] + a[ii][j]

for i in range(len(a)):
    print(b[i])



Measured memory_bytes: 12500
/*
	Author: houtaru
	Create: 17.12.2017 22:12:26
*/
#include <bits/stdc++.h>
using namespace std;

const int maxn = 8888;

int n;
char s[maxn];
bitset <maxn << 2> x, y;

int main() {
	scanf("%s", s);
	n = strlen(s); s[++n] = 'T';
	bool side = 0, first = 1;
	x[maxn] = 1; y[maxn] = 1;
	for (int i = 0, len = 0; i <= n; ++i) {
		if (s[i] == 'F') len++;
		else {
			auto &axis = (side) ? y : x;
			if (first) axis <<= len;
			else axis = (axis << len) | (axis >> len);
			len = 0; side ^= 1; first = 0;
		}
	}
	int xs, ys; scanf("%d%d", &xs, &ys);
	bool ok = x[xs + maxn] && y[ys + maxn];
	puts(ok ? "Yes" : "No");

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

char p[101];

int main(){
  scanf("%s",p);
  for(int i=0;i<strlen(p);i++){
    if(i%2==0&&p[i]=='L'){
      puts("No");
      return 0;
    }
    if(i%2==1&&p[i]=='R'){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string a,b;
    cin>>a>>b;
    int m = a.length();
    int n = b.length();
    string dp[2][n+1];

    for (int i = 0; i < n+1; ++i) {
        dp[0][i]="";
    }

    for (int i = 0; i < 2; ++i) {
        dp[i][0]="";
    }
int x=0;
    for (int i= 1; i < m+1; i++) {
        for (int j = 1; j <n+1 ; ++j) {
            if(a[i-1]==b[j-1]) {
                dp[(i)%2][j] = dp[(i+1)%2][j - 1];
                dp[(i)%2][j] += a[i-1];
            }
            else
            {
                if(dp[i%2][j-1].length()>=dp[(i+1)%2][j].length())
                {
                    dp[i%2][j]=dp[i%2][j-1];
                }
                else {
                    dp[i%2][j] = dp[(i+1)%2][j];
                }
            }
        }
    }

    int maxa=0;
    string maxs;
    for (int k = 0; k < 2; ++k) {
        for (int i = 0; i < n + 1; ++i) {
            if (dp[k][i].length() > maxa) {
                maxa = dp[k][i].length();
                maxs = dp[k][i];
            }
        }
    }
   cout<<maxs;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector <int> a(n), dp(n, 1e9+5);
    for (int i = 0; i < n; ++i) cin >> a[i];
    dp[0] = 0;
    for (int i = 0; i < n; ++i)
        for (int j : {i+1, i+2})
            if (j < n)
                dp[j] = min(dp[j], dp[i]+abs(a[i]-a[j]));
    cout << dp[n-1] << '\n';
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iomanip>
#define faster       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define r(i,a,b) for(ll i=a;i>b;i--)
using namespace std;
typedef long long ll;
typedef long double ld;


int main(){

ll x,y; cin>>x>>y;

if(y%2!=0){
  cout << "No" << endl;
}else{
  if(y<=4*x && y>=2*x){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

}

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

template<typename T> void drop(const T &x){cout<<x<<'\n';exit(0);}

void solve() {
  int n;
  cin >> n;
  for(int i=0; i<=n/4; ++i) {
    for(int j=0; j<=n/7; ++j) {
      if(n - (i*4 + j*7) == 0) drop("Yes");
    }
  }
  cout << "No" << '\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <set>
#include <algorithm>
#include <queue>

using namespace std;

typedef long long ll;

const int INF =0x7fffffff;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int N, M; cin >> N >> M;
	int u, v;
	vector<vector<int>> graph(N+1, vector<int>());
	for(int i = 1; i <= M; i++){
		cin >> u >> v;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}

	vector<int> dist(N+1, INF); dist[1] = 0;
	vector<int> parent(N+1, -1);
	queue<int> q;
	q.push(1);
	int found = 1;
	while(q.size()){
		int u = q.front(); q.pop();
		for(int v : graph[u]){
			if (dist[v] == INF){
				dist[v] = dist[u] + 1;
				found++;
				parent[v] = u;
				q.push(v);
			}
		}
	}
	// cout << found << endl;
	if (found != N) {
		cout << "No" << endl;
		
	}else{
		cout << "Yes" << endl;
		for(u = 2; u <= N; u++){
			cout << parent[u] << endl;
		}	
	}

	return 0;
}


Measured memory_bytes: 10708
a = list(input())
b = list(reversed(a))
ans_f = 0
ans_r = 0
for i in range(len(a)-1):
  if a[i] == a[i+1]:
    a[i+1] = str(abs(int(a[i]) - 1))
    ans_f += 1
for i in range(len(a)-1):
  if b[i] == b[i+1]:
    b[i+1] = str(abs(int(b[i]) - 1))
    ans_r += 1
print(min(ans_f,ans_r))

Measured memory_bytes: 16720
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<random>
#include<deque>
#include<cstdio>
#include<fstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2000100;
const int mod = (int)pow(10, 9) + 7;
const ll INF = 10000000100;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define ppd pair<double,double>
#define ppp pair<ll,pp>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
#define print(s) cout<<s<<endl
#define inp(s) cin>>s
string yn(bool b) { return (b ? "Yes" : "No"); }
string YN(bool b) { return (b ? "YES" : "NO"); }
ll n, a[100010],ans;
vector<ll>v, v2;
int main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	sort(a, a + n);
	rep(i, n / 2+n%2)v.pb(a[i]);
	rep(i, n - n / 2-n%2)v2.pb(a[n / 2+n%2 + i]);
	reverse(ALL(v2));
	if (n % 2 == 1) {
		for (int j = -1; j <= 1; ++j) {
			vector<ll>vv;
			rep(i, n) {
				if (i % 2 == 0) 
					vv.pb(v[(i / 2 - j + v.size()) % v.size()]);
				else vv.pb(v2[i / 2]);
			}
			ll ct = 0;
			rep(i, n - 1)ct += abs(vv[i + 1] - vv[i]);
			ans = max(ct, ans);
		}
		v2.pb(v[v.size() - 1]);
		v.pop_back();
		reverse(ALL(v));
		reverse(ALL(v2));
		for (int j = -1; j <= 1; ++j) {
			vector<ll>vv;
			rep(i, n) {
				if (i % 2 == 0)
					vv.pb(v2[(i / 2 - j + v2.size()) % v2.size()]);
				else vv.pb(v[i / 2]);
			}
			ll ct = 0;
			rep(i, n - 1)ct += abs(vv[i + 1] - vv[i]);
			ans = max(ct, ans);
		}
	}
	else {
		rep(j, 2) {
			for (ll k = -1; k < 2; ++k) {
				vector<ll>vv;
				rep(i, n) {
					if (j % 2 == 0&&i%2==0)vv.pb(v[(i / 2 + k + v.size()) % v.size()]);
					else if (j%2==0&&i%2==1)vv.pb(v2[(i / 2 + k + v2.size()) % v2.size()]);
					else if (j%2==1&&i%2==0)vv.pb(v2[(i / 2 + k + v2.size()) % v2.size()]);
					else vv.pb(v[(i / 2 + k + v.size()) % v.size()]);
				}
				ll ct = 0;
				rep(i, n - 1)ct += abs(vv[i + 1] - vv[i]);
				ans = max(ct, ans);
			}
		}
		reverse(ALL(v2));
		rep(j, 2) {
			for (ll k = -1; k < 2; ++k) {
				vector<ll>vv;
				rep(i, n) {
					if (j % 2 == 0 && i % 2 == 0)vv.pb(v[(i / 2 + k + v.size()) % v.size()]);
					else if (j % 2 == 0 && i % 2 == 1)vv.pb(v2[(i / 2 + k + v2.size()) % v2.size()]);
					else if (j % 2 == 1 && i % 2 == 0)vv.pb(v2[(i / 2 + k + v2.size()) % v2.size()]);
					else vv.pb(v[(i / 2 + k + v.size()) % v.size()]);
				}
				ll ct = 0;
				rep(i, n - 1)ct += abs(vv[i + 1] - vv[i]);
				ans = max(ct, ans);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3672
#include <cstdio>
#include<iostream>
#include <set>

using namespace std;

struct query
{
	int o,x,y,z;
	inline bool operator < (const query t) const
	{
		if (z!=t.z)
			return z<t.z;
		else
			if (x!=t.x)
				return x<t.x;
			else
				if (y!=t.y)
					return y<t.y;
				else
					return o<t.o;
	}
};

set <query> S;
query q[300000];
query t;

char c[6000000];
int f[300000];
int i,k,l,m,n,fx,fy;
long long s;
bool b;

inline int fastscanf()
{
	int t=0;
	l++;
	while (! ((c[l]>47) && (c[l]<58)))
		l++;
	while ((c[l]>47) && (c[l]<58))
		t=t*10+c[l]-48,l++;
	return t;
}

inline int getfather(int x)
{
	if (f[x]==x)
		return x;
	else
		return f[x]=getfather(f[x]);
}

int main()
{
	fread(c+1,1,5999999,stdin);
	n=fastscanf(),m=fastscanf();
	for (i=0;i<n;i++)
		f[i]=i;
	for (i=1;i<=m;i++)
	{
		q[i].x=fastscanf(),q[i].y=fastscanf(),q[i].z=fastscanf();
		S.insert(q[i]);
	}
	for (k=1;k<n;)
	{
		t=*S.begin(),b=false;
		S.erase(S.begin());
		fx=getfather(t.x);
		fy=getfather(t.y);
		if (fx!=fy)
		{
			b=true;
			s=s+t.z;
			f[fx]=fy;
			k++;
		}
		if (! t.o)
		{
			t.x++;
			if (t.x==n)
				t.x=0;
		}
		else
		{
			t.y++;
			if (t.y==n)
				t.y=0;
		}
		t.z++,t.o=t.o^1;
		fx=getfather(t.x);
		fy=getfather(t.y);
		if (fx!=fy)
			b=true;
		if (b)
			S.insert(t);
	}
	cout<<s<<endl;
}

Measured memory_bytes: 21248
#include<stdio.h>

int main()
{
    int a,b,c,x,y,Z;
    scanf("%d%d%d",&a,&b,&c);
    if(1<=a && a<=10000 && 1<=b && b<=10000 && 1<=c && c<=10000)
    {
        if(a>b && a>c || b==c && a>c){
                x=b+c;
                printf("%d",x);
        }
        if(b>a && b>c || a==b && b>c){
            y=a+c;
            printf("%d",y);
        }
        if(c>a && c>b || a==b && c>b || a==b && a==c){
            Z=a+b;
            printf("%d",Z);
        }
    }

return 0;
}

Measured memory_bytes: 1728
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

#include <bits/stdc++.h>
using namespace std;
int main(){
  float f;
  int n,m,d;   cin>>n>>m;
  
  if(m>=100){
    d=1000*n+m;
  } else if(m>=10) {
    d=100*n+m;
  } else {
    d=10*n+m;
  }
  
  f=sqrt(d);
  d=sqrt(d);
  
  (f!=d) ? (cout<<"No"<<"\n") : (cout<<"Yes"<<"\n");
return 0;
}

Measured memory_bytes: 256