akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i=0; i< (n); ++i)
typedef long long ll;
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 namespace std;

int main() {
    int n, m;

    cin >> n >> m;

    if (n == m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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);
        //        int k = sc.nextInt();
        //        ArrayList<Integer> list = new ArrayList<Integer>();
        //
        int c1 = 0;
        int c2 = 0;
        int c3 = 0;
        int c4 = 0;
 
        for (int i = 0; i < 3; i++) {
            int num = sc.nextInt();
 
            if (num == 1) {
                c1++;
            } else if (num == 2) {
                c2++;
            } else if (num == 3) {
                c3++;
            } else {
                c4++;
            }
 
            num = sc.nextInt();
 
            if (num == 1) {
                c1++;
            } else if (num == 2) {
                c2++;
            } else if (num == 3) {
                c3++;
            } else {
                c4++;
            }
 
            if (c1 == 3 || c2 == 3 || c3 == 3 || c4 == 3) {
                System.out.println("NO");
                return;
            }
        }
 
        sc.close();
 
        System.out.println("YES");
 
    }
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  ll N, P;
  string S;
  cin >> N >> P;
  cin >> S;

  ll ans = 0;
  reverse(S.begin(), S.end());
  if(P == 2){
    for(ll i = 0; i < N; i++){
      ll now = S[i] - '0';
      if(now % 2 == 0){
        ans += N - i;
      }
    }
    cout << ans << endl;
    return 0;
  }
  if(P == 5){
    for(ll i = 0; i < N; i++){
      ll now = S[i] - '0';
      if(now == 0 || now == 5){
        ans += N - i;
      }
    }
    cout << ans << endl;
    return 0;
  }

  vector<int> pow10_mod(N); // 10^i をPで割ったあまり
  for(int i = 0; i < N; i++){
    if(i == 0){
      pow10_mod[i] = 1;
    } else { 
      pow10_mod[i] = ( pow10_mod[i-1] * 10 ) % P;
    }
  }

  vector<ll> mod(N); // 部分数字列をPで割ったあまり
  for(ll i = 0; i < N; i++){
    if(i == 0){
      mod[i] = S[i] - '0';
      mod[i] %= P;
    } else { 
      ll now = S[i] - '0';
      // now * 10^i + mod[i-1] を Pで割ったあまりがほしい　
      ll tmp_mod = ( now * pow10_mod[i] ) % P ;
      tmp_mod += mod[i-1];
      tmp_mod %= P;
      mod[i] = tmp_mod;
    }
  }

  map<int, ll> m;
  for(auto x: mod){
    m[x]++;
  }
  for(auto x: m){
    // cerr << x.first << " " << x.second << endl;
    ans += (x.second * (x.second-1) / 2);
  }
  cout << ans + m[0] << endl;

  return 0;
}


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

#define F first 
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010, M = 2 * N;

int n, m;
priority_queue<int> heap;

int main()
{
	scanf("%d%d", &n, &m);
	while (n -- )
	{
		int x;
		scanf("%d", &x);
		heap.push(x);
	}
	
	while (m -- )
	{
		int t = heap.top();
		heap.pop();
		heap.push(t / 2);
	}
	
	LL res = 0;
	while (heap.size())
	{
		res += heap.top();
		heap.pop();
	}
	printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>       // ヘッダファイルインクルード

template<typename T>
void remove(std::vector<T> &vector, unsigned int index) {
    vector.erase(vector.begin() + index);
}

int main() {

    int N, a;
    std::vector<long int> A;

    std::cin >> N;

    for (int i = 0; i < N; ++i) {
        std::cin >> a;
        A.push_back(a);
    }

    std::set<long int> paper;

    for (long int tmp_a : A) {
        if (paper.find(tmp_a) != paper.end()) { // 見つかった
            paper.erase(tmp_a);
        } else {
            paper.insert(tmp_a);
        }

    }

    std::cout << paper.size() << '\n';

}

Measured memory_bytes: 5748
#include<iostream>
#include<math.h>

using namespace std;

// 指定する項のフィボナッチ
long long getFibonacci(int target){
    long long f0 = 0, f1 = 1;
    long long fn = 1;

    for(long long i = 1; i < target; i++){
        fn = (f0 + f1) % 1000000007;
        f0 = f1;
        f1 = fn;
    }

    return fn;
}

int main(){

    int N, M;

    cin >> N >> M;

    // 番兵
    int a[M + 1];

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

    long long ans = 1;
    int prev = -1;

    int diff;

    for(int i = 0; i < M + 1; i++){
        diff = a[i] - prev;
        if(diff == 1){
            cout << 0 << endl;
            return 0;
        }
        if(diff > 1){
            ans = ans * getFibonacci(diff - 1) % 1000000007;
        }
        prev = a[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;main(){int N,a,b,i;cin>>N;vector<pair<int,int>>R(N);for(auto&p:R){cin>>a>>b;p={a,a+b};}sort(R.begin(),R.end());vector<int>V(N+1,1),f(N);for(i=N;i--;){int&l=f[i]=i+1;while(l<N&&R[l].first<R[i].second)l=f[l];V[i]=(V[i+1]+V[l])%998244353;}cout<<V[0]<<'\n';}

Measured memory_bytes: 3328
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
int INF = INT_MAX / 2;
double EPS = 1e-10;

ll extgcd(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = (a >= 0) ? 1 : -1;
		y = 0;
		return abs(a);
	}
	else {
		ll res = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
		return res;
	}
}

ll mod_inverse(ll a, ll m) {
	ll x, y;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}

ll f(vector<ll>& a, vector<ll>& unko, int l, int r) {
	return ((a[r] - a[l]) * unko[l] % MOD + MOD) % MOD;
}

int main() {
	string s; cin >> s;
	int n = s.length();
	vector<ll> a(n + 1), unko(n + 1);
	ll z = 1; unko[0] = 1;
	for (int i = 0; i < n; i++) {
		char c = s[i];
		int x;
		if (c >= 'A' && c <= 'Z') x = 1 + c - 'A';
		if (c >= 'a' && c <= 'z') x = 27 + c - 'a';
		a[i + 1] = (a[i] + z * x) % MOD;
		z = z * 83 % MOD;
		unko[i + 1] = mod_inverse(z, MOD);
	}
	int len, ans = -1;
	for (len = 2; len * 2 + 1 <= n; len++) {
		int _len = n - len * 2;
		if (1 <= _len && _len <= len - 1);
		else continue;
		if (f(a, unko, 0, len) == f(a, unko, len, len * 2) && f(a, unko, 0, _len) == f(a, unko, len * 2, n)) {
			ans = len;
			break;
		}
	}
	if (ans == -1) cout << "mitomerarenaiWA" << endl;
	else cout << "Love " << s.substr(0, ans) << '!' << endl;
}

Measured memory_bytes: 18072
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] ary = new int[n];
        for (int i = 0; i < n; i++) {
            ary[i] = Integer.parseInt(sc.next());
        }
        int ans = 0;
        a:while (true) {
            for (int i = 0; i < n; i++) {
                if (ary[i] % 2 != 0) {
                    break a;
                }
                ary[i] /= 2;
            }
            ans++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 22356
parseInt(x::SubString{String}) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = parseInt.(x)

function main()
	n,hp = readline() |> split |> parseMap
	x = Array{Int}(2,n)
	maxa = 0
	for i in 1:n
		x[:,i] = readline() |> split |> parseMap
		maxa = max(maxa,x[1,i])
	end
	useb = Int[]
	for i in 1:n
		if x[2,i] > maxa
			push!(useb, x[2,i])
		end
	end
	useb = sort(useb, rev=true)
	count = 0
	for i in 1:length(useb)
		if hp > 0
			hp -= useb[i]
			count += 1
		end
	end
	if hp > 0
		if hp%maxa == 0
			count += div(hp, maxa)
		else
			count += div(hp, maxa)+1
		end
	end
	print(count)
end

main()

Measured memory_bytes: 175956
A, B, K = map(int, input().split())
x=[]
if (B-A) <= K:
    for i in range(A, B+1):
        print(i)
else:
    for i in range(A, A+K):
        x.append(i)
    for i in range(B-K+1, B+1):
        x.append(i)
    x=sorted(set(x))
    for i in x:
        print(i)

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


using namespace std;
using ll = long long;

#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define trav(a, x) for(auto& a: x)

int main () {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    string s, t; cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < sz(s); ++i)
        if(s[i] != t[i])
            ans++;

    cout << ans << '\n';
    return 0;
}



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

int h, w;
vector<string> field;

int main() {
    cin >> h >> w;
    field.assign(h, "");

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

    vector< vector<int> > dp(h, vector<int>(w, 0));
    if(field[0][0] == '#') dp[0][0] = 1;
    for(int i = 1; i < h; i++) {
        if(field[i][0] == '#' && field[i - 1][0] == '.') {
            dp[i][0] = dp[i - 1][0] + 1;
        } else {
            dp[i][0] = dp[i - 1][0];
        }
    }
    for(int j = 1; j < w; j++) {
        if(field[0][j] == '#' && field[0][j - 1] == '.') {
            dp[0][j] = dp[0][j - 1] + 1;
        } else {
            dp[0][j] = dp[0][j - 1];
        }
    }

    for(int i = 1; i < h; i++) {
        for(int j = 1; j < w; j++) {
            char here = field[i][j];
            char up = field[i - 1][j];
            char left = field[i][j - 1];
            if(here == '.') {
                dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]);
            } else {
                if(here == '#' && up == '.' && left == '.') {
                    dp[i][j] = min(dp[i - 1][j] + 1, dp[i][j - 1] + 1);
                } else if(here == '#' && up == '#' && left == '.') {
                    dp[i][j] = min(dp[i - 1][j], dp[i][j - 1] + 1);
                } else if(here == '#' && up == '.' && left == '#') {
                    dp[i][j] = min(dp[i - 1][j] + 1, dp[i][j - 1]);
                } else {
                    dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]);
                }
            }
        }
    }

    /*
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) cout << dp[i][j];
        cout << endl;
    }
    */

    cout << dp[h - 1][w - 1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define debug(x) {cerr<<#x<<" = "<<(x)<<endl;}
using namespace std;
bool isprime(int n)
{
	if(n==1) return false;
	if(n==2 || n==3) return true;
	int c=n%6;
	if(c!=1 && c!=5) return false;
	for(int i=5;i*i<=n;i+=6)
		if(n%i==0 || n%(i+2)==0)
			return false;
	return true;
}
ll ans=0;
int f[10000005]={0};
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        f[i]=1;//任何数都有因数1
    for(int i=2;i<=n;i++)
        for(int t=1;t*i<=n;t++)
            f[i*t]++;
    for(int i=1;i<=n;i++)
        ans+=(ll)i*f[i];
    cout<<ans;
    return 0;
}


Measured memory_bytes: 42616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n,k;
	cin>>n>>k;
	ll p=0;
	for(int i=k+1;i<=n;i++)
	{
		
				p += (i-k) * ((n+1)/i);
		

		if(n%i>=k && (n+1)%i!=0){
			p += n%i -k+1;
			//cout<<"yes"<<" ";
		}
		//cout<<(i-k)<<" * "<<(n+1)/i<<"\n";
		//cout<<p<<"\n";
	}
	if(k==0)
		p -= n;
	cout<<p<<"\n";
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(), (x).rend()
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
template <class T>bool chmax(T &a, const T &b){if (a < b){a = b;return 1;}return 0;}
template <class T>bool chmin(T &a, const T &b){if (b < a){a = b;return 1;}return 0;}
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp
const ll mod=1e9+7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    ll count=0;
    rep(i,n){
        ll a;
        cin>>a;
        if(i%2==1) continue;
        else{
            if(a%2==1)count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3648
#include<stdio.h>
#include <stdlib.h>
int main(){
int N,i;
long long  x,y,z;
int a[200001];
scanf("%d",&N);
for(i=0;i<N;i++){
scanf("%d",&a[i]);
y+=a[i];
}
x=a[0];
y-=a[0];
z=llabs(x-y);
for(i=1;i<N-1;i++){
x+=a[i];
y-=a[i];
if(llabs(x-y)<z) z=llabs(x-y);
}
printf("%d\n",z);
return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define lli long long int

int main() {
    lli n,a,b;
    cin>>n>>a>>b;
    lli p = a + b;
    lli q = n/p;
    lli r = n%p;
    if(r <= a){
        cout<<(q * a) + r;
    }else{
        cout<<((q * a) + a);
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

struct state{
  int y,x,z,cost;
  state(int y,int x,int z,int cost)
    :y(y),x(x),z(z),cost(cost) {}
  bool operator < (const state &s) const {
    return cost > s.cost;
  }
};

const int INF = 1e9+7;
int H,W;
int A[30][30];
int d[30][30][1000];

bool inField(int y,int x){
  return ( 0<=y && y<H && 0<=x && x<W );
}

int solve(){
  for(int i=0;i<30;i++)
    for(int j=0;j<30;j++)
      for(int k=0;k<1000;k++)
        d[i][j][k]=INF;
  d[0][0][0]=0;
  priority_queue< state > Q;
  Q.push( state(0,0,0,0) );
  int ans=INF;
  
  while(!Q.empty()){
    state s=Q.top(); Q.pop();
    if( s.cost > d[ s.y ][ s.x ][ s.z ] )continue;
    
    if(s.y==H-1&&s.x==W-1){
      ans=min(ans, s.cost-s.z );
    }
    
    for(int dir=0;dir<4;dir++){
      int ny=s.y+dy[dir];
      int nx=s.x+dx[dir];
      if(!inField(ny,nx))continue;
      int ncost=s.cost+1;
      if(A[ny][nx]>0)ncost+=A[ny][nx]*(s.z*2+1);
      int nz=s.z+1;
      if(nz > H*W)continue;
      if(d[ny][nx][nz]>ncost){
        d[ny][nx][nz]=ncost;
        Q.push( state(ny,nx,nz,ncost) );
      }
    }
  }
  return ans;
}

int main(){
  cin>>H>>W;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>A[i][j];
    }
  }
  cout<< solve() <<endl;
  return 0;
}



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

int main()
{
    int n, d1, d2, counts = 0, max_result = 0;

    cin >> n;

    for (int i = 0; i < n ; i++)
    {
        cin >> d1 >> d2;
        if(d1 == d2)
        {
            counts++;
            max_result = max(max_result,counts);
        }else{
            max_result = max(max_result,counts);
            counts = 0;
        }
    }

    if(max_result >= 3)
    {
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    map<int,int> mp;
    rep(i, n) {
        int a;
        cin >> a;
        mp[a]++;
    }
    int ans = 0;
    for(auto p : mp) {
        if(p.second > p.first) {
            ans += p.second - p.first;
        }
        else if(p.second < p.first) {
            ans += p.second;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8044
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=2147483647;
const ll LLMAX=9223372036854775807;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll A,B,H,M;
    cin>>A>>B>>H>>M;
    
    long double tA=30*(H+M/60.0);
    long double tB=6*M;
    
    long double pi=M_PI;
    
    long double coss=cos(abs(tA-tB)*pi/180);
    long double ans=sqrtl(A*A+B*B-2*A*B*coss);
    
    //cout<<sqrt(A*A+B*B-2*A*B*cos(abs(tA-tB)*3.141592653589793238462/180))<<endl;
    cout<<setprecision(15)<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 4180
#include <cstdio>
#include <algorithm>
using std::max;
const int MAXN=2000;
int cnt=0;
struct Edge {
	int v,nxt;
}ed[MAXN<<1];
int first[MAXN];
inline void add(int x,int y) {
	static int cnt=0;
	ed[++cnt].v=y;
	ed[cnt].nxt=first[x];
	first[x]=cnt;
}
void dfs(int x,int fa,int dep) {
//	printf("(%d,%d,%d)\n",x,fa,dep);
	++cnt;
//	printf("cnt %d\n",cnt);
	if(!dep) return;
	for(int i=first[x];i;i=ed[i].nxt) {
		int v=ed[i].v;
		if(v==fa) continue;
		dfs(v,x,dep-1);
	}
}
int edge[MAXN][2];
int main() {
	int n,k;
	scanf("%d%d",&n,&k);
	int in1,in2;
	for(int i=1;i<n;++i) {
		scanf("%d%d",&in1,&in2);
		edge[i][0]=in1;
		edge[i][1]=in2;
		add(in1,in2);
		add(in2,in1);
	}
	int ans=0;
	if(k&1) {
		for(int i=1;i<n;++i) {
		//    printf("id %d now\n",i);
			cnt=0;
		//	printf("first\n");
			dfs(edge[i][0],edge[i][1],k/2);
		//	printf("second\n");
			dfs(edge[i][1],edge[i][0],k/2);
		//	printf("cnt %d now\n",cnt);
			ans=max(ans,cnt);
		}
	} else {
		for(int i=1;i<=n;++i) {
		//    printf("id %d now\n",i);
			cnt=0;
			dfs(i,-1,k/2);
		//	printf("cnt %d now\n",cnt);
			ans=max(ans,cnt);
		}
	}
	printf("%d",n-ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <stack>
#include <map>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

template <class T>
struct fix_point: private T {
  explicit constexpr fix_point(T &&func): T(std::forward<T>(func)) { }
  template <class... Args>
  constexpr decltype(auto) operator () (Args &&... args) const {
    return T::operator()(*this, std::forward<Args>(args)...);
  }
};

template <class T>
constexpr decltype(auto) make_fix_point(T &&func) {
  return fix_point<T>(std::forward<T>(func));
}

int main() {
  int N, M;
  std::cin >> N >> M;
  if (M % 2 == 1) {
    std::cout << "-1\n";
    return 0;
  }
  std::vector<std::vector<int>> graph(N);
  for (int i: range(0, M)) {
    int a, b;
    std::cin >> a >> b;
    --a; --b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  std::map<std::pair<int, int>, bool> state;
  std::vector<bool> visited(N);
  std::stack<std::pair<int, int>> stack;
  make_fix_point([&](auto dfs, int u, int p) -> void {
    visited[u] = true;
    if (p != -1) {
      stack.push({ u, p });
    }
    for (int v: graph[u]) {
      if (v != p) {
        if (visited[v]) {
          state[std::minmax(u, v)] = (u < v);
        }
        else {
          dfs(v, u);
        }
      }
    }
  })(0, -1);
  while (!stack.empty()) {
    int u = stack.top().first;
    int p = stack.top().second;
    bool odd = false;
    for (int v: graph[u]) {
      if (v != p) {
        odd ^= state[std::minmax(u, v)] ^ (u < v);
      }
    }
    state[std::minmax(u, p)] = odd ^ (u < p);
    stack.pop();
  }
  for (auto p: state) {
    int u = p.first.first;
    int v = p.first.second;
    if (p.second) {
      std::swap(v, u);
    }
    std::cout << u + 1 << ' ' << v + 1 << '\n';
  }
  return 0;
}


Measured memory_bytes: 20224
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <functional>
#include <math.h> 
#define enld '\n'
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// ---------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin >> S;
  int N = S.size();
  vector<pair<char,int>> G;
  G.emplace_back(S[0],1);
  for(int i=1; i<N; i++){
    if(S[i] == G.back().first) G.back().second++;
    else G.emplace_back(S[i],1);
  }
  int ans = 0;
  for(int i=0; i+2<G.size(); i++){
    if(G[i].first == 'J' && G[i+1].first == 'O' && G[i+2].first == 'I'){
      int mn = min({G[i].second,G[i+1].second,G[i+2].second});
      if(G[i+1].second == mn){
        chmax(ans,mn);      
      }
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 13064
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
n=int(input())
d=[0,0,0]
e=[0,0,0]
f=[0,0,0]
for i in range(n):
    ab=int(input())
    for i in range(3):
        if a[i] == ab:
            d[i] = 1
        if b[i] == ab:
            e[i] = 1
        if c[i] == ab:
            f[i] = 1
if sum(d)==3 or sum(e)==3 or sum(f)==3:
    print("Yes")
    exit()

for i in range(3):
    if d[i]==e[i]==f[i]==1:
        print("Yes")
        exit()
if d[0]==e[1]==f[2]==1 or d[2]==e[1]==f[0]==1:
    print("Yes")
    exit()
print("No")

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

int N,W;
int weight[101];
long long int value[101];
long long int DP[101][100001]={};

void knapsack(){
	for(int i=1;i<=N;i++){
		for(int j=1;j<=W;j++){
			DP[i][j]=DP[i-1][j];
			if(j>=weight[i]){
				DP[i][j]=max(DP[i-1][j],DP[i-1][j-weight[i]]+value[i]);
			}
		}
	}
}

int main(){
	cin>>N>>W;
	for(int i=1;i<=N;i++){
		cin>>weight[i]>>value[i];
	}
	knapsack();
	cout<<DP[N][W]<<"\n";
	return 0;
}

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

using namespace std;

/*

        Bismillahir Rahmanir Rahim
        Problem :
        Problem Link :
        Topics :
        Solver : Masud Parves
        I Love Code More than Sharks Love Blood <3
*/


#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define SZ(a)           (int)a.size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()


#define sf(a)           scanf("%d",&a)
#define sff(a,b)        scanf("%d %d",&a,&b)
#define sfff(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int zz=1 ; zz<=t ; zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define Debug(x)            cout<<#x " = "<<(x)<<endl
#define NOT_VISITED 0
#define IS_VISITED 1
#define WHITE 0
#define GRAY 1
#define BLACK 2



int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N  (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/


const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;

int arr[maxn];

int main() {
    CIN
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);


    int n;
    cin>> n;

    cout <<3*n*n << endl;
    return 0;
}



Measured memory_bytes: 256
from itertools import permutations
if __name__ == '__main__':
    S = str(input())
    
    diff_min = 10000000

    for i in range(len(S)-2):
        diff_min = min(diff_min, max(753 - int(S[i:i+3]), -753 + int(S[i:i+3])))
    
    print(diff_min)

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

int main(){
    string re;
    cin >> re;
    if(re.size()&1){puts("No");return 0;}
    char comp[] = {'h','i'};
    for(int i = 0, j = 0; i < re.size();++i){
        if(re[i] != comp[j]){puts("No");return 0;}
        j += 1;
        j = j % 2;
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 300000000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    //int r;cin>>r;
    //cout<<(double)r*2.0*PI<<endl;
    //printf("%.10lf\n",(double)r*2.0*PI);


    int n,m;cin>>n>>m;
    V<int>a(m);
    for(int i=0;i<m;i++)cin>>a[i];
    for(int i=0;i<m;i++){
        n-=a[i];
    }
    if(n<0)cout<<-1<<endl;
    else cout<<n<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------

















































Measured memory_bytes: 3684
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


N = inp()
PP = inpl()

m = INF
ans = 0
for p in PP:
    if m > p:
        ans += 1
    m = min(m,p)

print(ans)


Measured memory_bytes: 26984
N = int(input())
ps = list(map(int, input().split()))

As = [45000 * (i+1) for i in range(N)]
Bs = list(reversed(As))

for i, p in enumerate(ps):
    As[p-1] += i
    Bs[p-1] += i

print(*As)
print(*Bs)


Measured memory_bytes: 11508
import sys; sys.setrecursionlimit(50000)
input = sys.stdin.readline

H, W = map(int, input().split())
grid = [list(input().replace("\n","")) for _ in range(H)]
dir4 = ((0, 1), (0, -1), (1, 0), (-1, 0))
dir8 = ((0, 1), (0, -1), (1, 0), (-1, 0), (-1, -1), (1, -1), (-1, 1), (1, 1))

for i in range(H):
    for j in range(W):
        if grid[i][j] != ".": continue
        cnt = 0
        for d in dir8:
            nx = i + d[0]
            ny = j + d[1]
            if not (0 <= nx < H): continue
            if not (0 <= ny < W): continue
            if grid[nx][ny] == "#": cnt += 1
        grid[i][j] = str(cnt)
    print(*grid[i], sep="")


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

int main()
{
  int a,b;

  while(cin>>a>>b){

    if((a+b)/10==0)
      cout<<1<<endl;
    else if(0<(a+b)/10 && (a+b)/10<10)
      cout<<2<<endl;
    else if (0<(a+b)/100 && (a+b)/100<10)
      cout<<3<<endl;
    else if (0<(a+b)/1000 && (a+b)/1000<10)
      cout<<4<<endl;
    else if (0<(a+b)/10000 && (a+b)/10000<10)
      cout<<5<<endl;
    else if (0<(a+b)/100000 && (a+b)/100000<10)
      cout<<6<<endl;
    else if (0<(a+b)/1000000 && (a+b)/1000000<10)
      cout<<7<<endl;
  }

  return 0;
}



Measured memory_bytes: 3000
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ls rt << 1
#define rs rt << 1 | 1
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define X first
#define Y second
#define pii pair<int, int>
#define pcc pair<char, char>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9
#define ALL(x) (x).begin(), (x).end()
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int n;
ll ans, jian = 1;

int main()
{
	n = read();
	ans = 1;
	rep(i, 1, n)
	{
		int x = read();
		if(x % 2 == 0) jian *= 2;
		ans = ans * 3;
	}
	cout << ans - jian;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
#define p pair<char,int>
int main(){
  string a;
  p b[20000];
  int n=0,cnt=0,c[100000]={},t=0,sum=0;
  cin>>a;
  for(int i=0;i<a.size();i++){
    if(a[i]!='/'&&a[i]!='_')n--;
    b[i]=make_pair(a[i],n);
    if(a[i]=='/')n++;
  }
  for(int i=0;i<a.size();i++){
    if(a[i]!='/'&&a[i]!='_'){
      for(int j=i;j<a.size();j++){
        if(a[j]=='/'&&b[j].second==b[i].second){
          if(i>=t)t=0,cnt++;
          c[cnt]+=j-i;
          sum+=j-i;
          if(j>t)t=j;
          break;
        }
      }
    }
  }
  cout<<sum<<endl<<cnt;
  for(int i=1;i<cnt+1;i++)cout<<" "<<c[i];
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3816
import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))
    ans = 0
    com = [0] * (N+1)
    for i in range(N):
        com[i+1] = (1+p[i]) / 2 + com[i]
    for i in range(K, N+1):
        ans = max(ans, com[i]-com[i-K])
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 67824
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=998244353;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
ll n,m,seg[600000];
void segstart(void){
    memset(seg,0,sizeof(seg));
    for(ll i=1;;i*=2){
        if(n<=i){m=i;break;}
    }
    m--;

    //for(ll i=m;i<n;i++)cin>>seg[i];
    for(int i=m-1;i>=0;i--){
        seg[i]=max(seg[2*i+1],seg[2*i+2]);
    }

}
void update(ll a,ll b){
    a+=m;seg[a]=b;
    while(a){
        a=(a-1)/2;
        seg[a]=max(seg[2*a+1],seg[2*a+2]);
    }
}
ll ans(ll a,ll b){
    ll ret=a;a+=m;b+=m;
    while(1){
        if(a==b){
            ret=max(ret,seg[a]);
            break;
        }
        if(b==a+1){
            ret=max(ret,seg[a]);
            ret=max(ret,seg[b]);
            break;
        }
        if(a%2)a/=2;
        else{
            ret=max(ret,seg[a]);
            a/=2;
        }
        if(b%2){
            ret=max(ret,seg[b]);
            b/=2;b--;
        }
        else{b/=2;b--;}
    }
    return ret;
}

ll a[200001];
ll solve(ll le,ll ri){
	if(le==ri)return 2LL;
	if(a[le]==le)return (2*solve(le+1,ri))%mod;
	if(a[le]==ri)return (solve(le+1,ri)+1)%mod;
	return (solve(le,a[le])*solve(a[le]+1,ri))%mod;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    segstart();
    ll x[n],d[n];
    vector<pair<ll,ll> > v;
    for(int i=0;i<n;i++){
    	cin>>x[i]>>d[i];d[i]--;
    	v.pb(make_pair(x[i],d[i]));
    }
    sort(be(v));
    a[n-1]=n-1;
    for(int i=0;i<n;i++){
    	x[i]=v[i].first;
    	d[i]=v[i].second;
    }
    update(n-1,n-1);
    for(int i=n-2;i>=0;i--){
    	ll idx=(upper_bound(x,x+n,x[i]+d[i])-x);
    	idx--;
    	a[i]=max(ans(i,idx),idx);
    	update(i,a[i]);
    }
    cout << (solve(0,n-1))%mod <<endl;
    return 0;
}


Measured memory_bytes: 19820
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char** argv) {
    int N;
    cin >> N;

    vector<int> cost(N);

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

    vector<int> DP(N);
    DP[0] = 0;
    DP[1] = abs(cost[0] - cost[1]);
    int i = 2;
    while (i < N) {
        DP[i] = min(
            DP[i - 1] + abs(cost[i - 1] - cost[i]),
            DP[i - 2] + abs(cost[i - 2] - cost[i]));
        i++;
    }
    cout << DP[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
s = input()
flag = 1
i = 0

while i < len(s):
    if s[i:i+5] == 'dream':
        if s[i+5:i+10] != "erase" and s[i+5:i+7] == "er":
            i += 7
        elif s[i+5:i+11] == "eraser":
            i += 11
        elif s[i+5:i+10] == "erase":
            i += 10
        else:
            i += 5
    elif s[i:i+6] == "eraser":
        i += 6
    elif s[i:i+5] == "erase":
        i += 5
    else:
        flag = 0
        break

if(flag == 1):
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl = vector<ll>; using vvl = vector<vl>;
using vp = vector<pair<int,int>>;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
const ll INF = 9223372036854775807;

int main() {
    int n;cin >> n;
    vector<int> in(4);
    rep(i,4){
        in[3-i]=n % 10;
        n /= 10;
    }
    rep(i,(1 << 3)) {
        bitset<3> op(i);
        int sum = in[0];
        rep(j,3){
            if(op.test(j)) sum += in[j + 1];
            if(!op.test(j)) sum -= in[j + 1];
        }
        if(sum == 7) {
            vector<char> opv(0);
            rep(j,3) {
                if(op.test(j)) opv.push_back('+');
                if(!op.test(j)) opv.push_back('-');
            }
            cout << in[0] << opv[0] << in[1] << opv[1] << in[2] << opv[2] << in[3] << "=7" << endl;
            break;
        }
    }
}

Measured memory_bytes: 3508
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define int long long
#ifdef ONLINE_JUDGE
const int maxn = 3e5 + 10;
#else
const int maxn = 1e3 + 10;
#endif
using namespace std;

signed main()
{
    ios::sync_with_stdio(false);
    int arr[5];
    cin >> arr[1] >> arr[2] >> arr[3];
    sort(arr + 1, arr + 1 + 3);
    reverse(arr + 1, arr + 1 + 3);
    int ans = arr[1] * 10 + arr[2] + arr[3];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
p=list(map(int,input().split()))

T=sum(p[0:k])
S=T
num=0

for i in range(n-k):
    T-=p[i]
    T+=p[k+i]
    if T>S:
        S=T
        num=i+1

def kitai(m):
    return (m+1)/2

ans=0
for i in p[num:num+k]:
    ans+=kitai(i)

print(ans)

Measured memory_bytes: 25060
while 1:
    n=int(input())
    if n==0:
        break
    s=0
    l=0
    sum=0
    while 1:
        if n>=10**s and n<10**(s+1):
            sum+=n//(10**s)
            break
        else:
            sum+=(n%(10**(s+1))-l)//(10**(s))
            l=n%(10**s)
            s+=1
    print(sum)


Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <cerrno>
#include <cfenv>
#include <cstring>
#include <bitset>
#include <queue>
#include <iomanip>
#include <string>
#include <set>

using namespace std;
set<int> s;
int N;
int ans = 0;
int main()

{
	cin >> N;
	int tmp;
	for (int i = 0; i < N; i++)
	{
		cin >> tmp;
		s.insert(tmp);
	}
	set<int>::iterator ite;;

	for (ite = s.begin(); ite != s.end(); ++ite)
	{
		ans++;
	}
	cout << ans;

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int a[10];
	for (int i = 0; i < 10; ++ i) 
		cin >> a[i];
	int t = 0;
	for (int i = 0; i < 10; ++ i) 
		if (a[t] < a[i]) t = i;;
	cout << a[t] << endl;
	a[t] = -1;
	t = 0;
	for (int i = 0; i < 10; ++ i) 
		if (a[t] < a[i]) t = i;;
	cout << a[t] << endl;
	a[t] = -1;
	t = 0;
	for (int i = 0; i < 10; ++ i) 
		if (a[t] < a[i]) t = i;;
	cout << a[t] << endl;
	a[t] = -1;
	t = 0;

	return 0;
}

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

using namespace std;

const int N = 2 * 1e5 + 10;
int n, maxn;
struct node {
	int x, y;
}s[N];

int cmp1 (node x, node y) {
	return x.x + x.y > y.x + y.y;
}

int cmp2 (node x, node y) {
	return x.x - x.y > y.x - y.y;
}

int main () {
	scanf ("%d", &n);
	for (int i = 1; i <= n; i ++ ) scanf ("%d%d", &s[i].x, &s[i].y);
	sort (s + 1, s + 1 + n, cmp1);
	maxn = abs (s[1].x - s[n].x) + abs (s[1].y - s[n].y);
	sort (s + 1, s + 1 + n, cmp2);
	maxn = max (maxn, abs (s[1].x - s[n].x) + abs (s[1].y - s[n].y));
	cout << maxn << endl;
	return 0;
}


Measured memory_bytes: 5320
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int input[][] = new int[n][3];

		for(int i = 0; i < n; i++){
			for(int j = 0; j < 3; j++){
				input[i][j] = sc.nextInt();
			}
		}

		int dp[][] = new int[n][3];

		for(int i = 0; i < 3; i++){
			dp[0][i] = input[0][i];
		}

		for(int i = 1; i < n; i++){
			for(int j = 0; j < 3; j++){
				dp[i][j] = Math.max(dp[i - 1][(j + 1)%3], dp[i - 1][(j + 2)%3]) + input[i][j];
			}
		}

		System.out.println(Math.max(dp[n - 1][0], Math.max(dp[n - 1][1], dp[n - 1][2])));
	}
}


Measured memory_bytes: 53748
/*
 *Author - Abhas Jain
 */

#include <bits/stdc++.h>

#define F first
#define S second
#define all(c) c.begin(), c.end()
#define endl '\n'
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

const ld PI = 3.141592653589793;
const ll INF = 9223372036854775807ll;
const ll mod = 1e9 + 7;
const ll N = 301;

ld dp[N][N][N];

ld n;

ld calc(int c1, int c2, int c3) {
	if (dp[c1][c2][c3] != -1) {
		return dp[c1][c2][c3];
	}
	ld num = 1;
	int c0 = n - (c1 + c2 + c3);
	if (c1 != 0) {
		num += (c1 * 1.0000000 / n) * calc(c1 - 1, c2, c3);
	}
	if (c2 != 0) {
		num += (c2 * 1.0000000 / n) * calc(c1 + 1, c2 - 1, c3);
	}
	if (c3 != 0) {
		num += (c3 * 1.0000000 / n) * calc(c1, c2 + 1, c3 - 1);
	}
	num *= (n / (n - c0));
	return (dp[c1][c2][c3] = num);
}

void solve() 
{
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			for (int k = 0; k < N; ++k) {
				dp[i][j][k] = -1;
			}
		}
	}
    cin >> n;
    dp[0][0][0] = 0;
    int c3 = 0, c1 = 0, c2 = 0;
    for (int i = 0; i < n; ++i) {
    	int cur;
    	cin >> cur;
    	if (cur == 1) {
    		c1++;
    	} else if (cur == 2){
    		c2++;
    	} else c3++;
    }
    cout << setprecision(14) << calc(c1, c2, c3) << endl;
}

int main( )
{   
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    solve();
    return 0;
}

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


int main() {
  
  string s;
  cin >> s;
  string amoji = s;
  string zmoji = s;
  int acount, zcount = 0;
  int kazu = s.size();
  int i = 0;
  
    for ( int i = 0; i < kazu; i++ ) {
    if ( amoji.at(i) == 'A' ) break;
    acount++;
    }
  
  reverse ( zmoji.begin(), zmoji.end() );
  
  i = 0;
  
    for ( int i = 0; i < kazu; i++ ) {
    if ( zmoji.at(i) == 'Z' ) break;
    zcount++;
    }
      
  cout << kazu - ( acount + zcount ) << endl;

}

Measured memory_bytes: 900
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

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




// ***************************************


int main(){

    int N;
    string S;
    cin >> N;
    cin >> S;

    ll r(0), g(0), b(0);
    for(char c: S){
        if(c == 'R'){
            r++;
        } else if(c == 'G'){
            g++;
        } else{
            b++;
        }
    }

    ll all = r * g * b;
    if (all == 0) {
        cout << 0 << endl;
        return 0;
    }

    ll sub = 0;
    REP(i, N){
        FOR(j, i+1, N){
            ll k = 2 * j - i;
            if (k >= N) continue;
            if (S[i] == S[j]) continue;
            if(S[i] == S[k] || S[j] == S[k]) continue;
            sub++;
        }
    }

    // cout << all << " " << sub << endl;
    cout << all - sub << endl;

    return 0;
}


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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

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


int main()
{
int n;
cin>>n;
vector<llong> a(n,0);
REP(i,n) cin>>a[i];
llong ans=0;

for(int i=0; i<n; i++)
{
    while(a[i]%2==0)
    {
        ans++;
        a[i]=a[i]/2;
    }
}
cout<<ans<<endl;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
int n,m,i,j,k,r,a[1005],ans,map[256][256][2],dp[10005][256];//map:0?路，1水路,dp[i][j]在送到i个?子船在j??的最少花?
int main()
{
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	while(~scanf("%d %d",&n,&m)&&n&&m)
	{
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				map[i][j][0]=1000000;
				map[i][j][1]=1000000;
			}
			map[i][i][0]=0;
			map[i][i][1]=0;
		}
		int x,y,t,o;
		char s;
		for(i=1;i<=m;i++)
		{
			scanf("\n%d %d %d %c",&x,&y,&t,&s);
			if(s=='L')
				o=0;
			if(s=='S')
				o=1;
			map[x][y][o]=min(map[x][y][o],t);
			map[y][x][o]=map[x][y][o];
		}
		for(k=1;k<=n;k++)
			for(i=1;i<=n;i++)
				for(j=1;j<=n;j++)
				{
						map[i][j][0]=min(map[i][j][0],map[i][k][0]+map[k][j][0]);
						map[i][j][1]=min(map[i][j][1],map[i][k][1]+map[k][j][1]);	
				}
		scanf("%d",&r);
		for(i=1;i<=r;i++)
			scanf("%d",&a[i]);
		for(i=1;i<=r;i++)
			for(j=1;j<=n;j++)
				dp[i][j]=1000000;
		dp[1][a[1]]=0;
		for(i=1;i<=n;i++)
		{
			if(map[a[0]][i][1]<2147483647&&map[i][a[0]][0]<2147483647)
			dp[0][i]=map[a[0]][i][1]+map[i][a[0]][0];
		}
		for(i=2;i<=r;i++)
		{
			for(k=1;k<=n;k++)
			{
				dp[i][k]=min(dp[i][k],dp[i-1][k]+map[a[i-1]][a[i]][0]);
				for(j=1;j<=n;j++)
					dp[i][j]=min(dp[i][j],dp[i-1][k]+map[a[i-1]][k][0]+map[k][j][1]+map[j][a[i]][0]);
			}
		}
		ans=2147483647;
		for(i=1;i<=n;i++)
			ans=min(ans,dp[r][i]);
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 3956
import java.util.Scanner;

public class Main {
	static int count;
	static int result;
	static void rec(int arr[] , int cur , int cur_val , int M, int A[] , int B[] , int C[] , int D[]){
		if(cur == arr.length){
			int S = 0;
			for(int q = 0  ; q < A.length ; ++q){
				if(arr[B[q]] - arr[A[q]] == C[q]){
					S += D[q];
				}
			}
			result = Math.max(result, S);
			++count;
			return ;
		}
		for(int i = cur_val ; i <= M ; ++i){
			arr[cur] = i;
			rec(arr , cur + 1 , i , M, A, B , C , D);			
		}
	}
	static long solve(int N , int M , int A[] , int B[] , int C[] , int D[]){
		int arr[] = new int[N];
		count = 0;
		result = 0;
		rec(arr, 0 , 1 , M, A , B , C , D);
//		System.out.println(count+" "+result);
		return result;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int Q = sc.nextInt();
		int A[] = new int[Q];
		int B[] = new int[Q];
		int C[] = new int[Q];
		int D[] = new int[Q];

		for(int i = 0 ; i < Q ; ++i){
			A[i] = sc.nextInt() - 1;
			B[i] = sc.nextInt() - 1;
			C[i] = sc.nextInt();
			D[i] = sc.nextInt();
		}
		System.out.println(solve(N , M , A , B , C , D));
	}	
}


Measured memory_bytes: 27788