akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    while (cin >> n, n) {
        vector<int> w(n);
        for (auto &wi: w) cin >> wi;
        vector<vector<int>> dp(n, vector<int>(n + 1));
        for (int len = 2; len <= n; len++) {
            for (int l = 0; l + len <= n; l++) {
                int r = l + len;
                if (dp[l + 1][r - 1] == len - 2 && abs(w[l] - w[r - 1]) <= 1) {
                    dp[l][r] = len;
                    continue;
                }
                for (int m = l; m < r; m++) {
                    dp[l][r] = max(dp[l][r], dp[l][m] + dp[m][r]);
                }
            }
        }
        cout << dp[0][n] << endl;
    }
    return 0;
}



Measured memory_bytes: 3224
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;

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

    int cnt = 0;
    while (true) {
        if (N < K) {
            ++cnt;
            break;
        }

        N = N / K;
        ++cnt;
    }

    cout << cnt << endl;
    return 0;
}

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

int main(){
int sh,sm,ss,eh,em,es,totaltime,th,tm,ts;

for(int i=0;i<3;i++){
 cin>>sh>>sm>>ss>>eh>>em>>es;
 totaltime=(eh*3600+em*60+es)-(sh*3600+sm*60+ss);
 ts=totaltime%60;
 totaltime-=ts;
 totaltime/=60;
 tm=totaltime%60;
 totaltime-=tm;
 th=totaltime/60;
 cout<<th<<" "<<tm<<" "<<ts<<"\n";
}

return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int i=0;n>1000;i++) {
		n = n % 1000;

		}

		if(n==0) {
			System.out.println(n);
		}else if(n!=0) {
			n = 1000-n;
			System.out.println(n);
		}

	}

}


Measured memory_bytes: 35800
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int mod = 1e9 + 7;
vector<vector<int>> vt;
int dp[2010][2010][2][2];
int a[2010];
int b[2010];
int n, m;
int func(int here, int here1, int ch,int ch1) {
	if (here == n || here1 == m) {
		if (ch&&!ch1)
			return 1;
		else return 0;
	}
	int &ret = dp[here][here1][ch][ch1];
	if (ret != -1)return ret;
	ret = 0;
	if(!ch1)
		ret += func(here + 1, here1, ch,0);
	ret %= mod;
	int t = lower_bound(vt[a[here]].begin(), vt[a[here]].end(), here1) - vt[a[here]].begin();
	if (t != vt[a[here]].size()) {
		ret += (func(here + 1, vt[a[here]][t] + 1, 1,0));
		ret %= mod;
		ret += func(here,vt[a[here]][t]+1,ch,1);
		ret %= mod;
	}
	return ret;
}
int main()
{
	vt.resize(100001);
	memset(dp, -1, sizeof(dp));
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	for (int i = 0; i < m; i++) {
		scanf("%d", &b[i]);
		vt[b[i]].push_back(i);
	}

	printf("%d", func(0, 0, 0,0) + 1);
}


Measured memory_bytes: 66048
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
#include <sstream>
#include <numeric>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>
#include <cassert>
using namespace std;

typedef long long ll;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
bool ISINT(double x){return fabs(x-(int)x)<EPS;}
bool ISEQ(double x,double y){return fabs(x-y)<EPS;}
string itos(ll x){stringstream ss;ss<<x;return ss.str();}
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define EREP(i,a,b) for(int i=a;i<=b;i++)
#define erep(i,n) EREP(i,0,n)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin();itr!=c.end();itr++)

int main(void){
  int n,a[100],b[100];
  string s;

  while(cin>>n,n){
    cin>>s;
    rep(i,n){
      cin>>a[n-i-1]>>b[n-i-1];
      a[n-i-1]--;
      b[n-i-1]--;
    }
    rep(i,n){
      int diff = b[i] - a[i];
      swap(s[a[i]],s[b[i]]);
      s[a[i]] = (s[a[i]] - 'a' + diff) % 26 + 'a';
      s[b[i]] = (s[b[i]] - 'a' + diff) % 26 + 'a';
    }
    cout<<s<<endl;
  }
}

Measured memory_bytes: 0
import sys
input=sys.stdin.readline
sys.setrecursionlimit(100000000)
MOD = 10**9+7

n,k=map(int,input().split())
tree=[[] for _ in range(n)]

for _ in range(n-1):
        a,b=map(int,input().split())
        a-=1
        b-=1
        tree[a].append(b)
        tree[b].append(a)

ans=k   
def dfs(i,before=-1):
    global ans 

    if i==0:
        j=1
    else:
        j=2
        
    for e in tree[i]:
        if e!=before:
            ans*=(k-j)
            ans%=MOD
            j+=1
            dfs(e,i)
dfs(0)
print(ans)  

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

#define int long long

using namespace std;

const int maxn = 3010;
int a[maxn], dp[maxn][maxn][2], n;

signed main()
{
    ios::sync_with_stdio(false);
    cin >> n;

    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        dp[i][i][0] = a[i], dp[i][i][1] = -a[i];
    for (int l = 2; l <= n; l++)
        for (int i = 0; i + l - 1 < n; i++)
        {
            int j = i + l - 1;
            dp[i][j][0] = max(dp[i + 1][j][1] + a[i], dp[i][j - 1][1] + a[j]);
            dp[i][j][1] = min(dp[i + 1][j][0] - a[i], dp[i][j - 1][0] - a[j]);
        }

    cout << dp[0][n - 1][0];

    return 0;
}


Measured memory_bytes: 141568
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;



int main(){
    cin>>N;
    M = INF;
    ll ans = 0;
    rep(i,N){
        cin>>A;
        if(M > A){
            ++ans;
            M = A;
        }
    }
    cout<<ans<<endl;
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf=1000000001;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};


int main(){
	string s;
	cin >> s;
	int i;
	bool flag = false;
	while(!flag){
		s.pop_back();
		if(s.size() % 2 == 1){
			continue;
		}
		bool flag2=true;
		loop(i,0,s.size()/2){
			if(s[i] != s[i + s.size()/2]){
				flag2 = false;
				break;
			}
		}
		if(flag2){
			flag = true;
		}
	}
	cout<<s.size()<<endl;
}

Measured memory_bytes: 256
/*
 *  author : Atul Anand   
 *  created on : Sat Mar 14 2020
 */

import java.io.*;
import java.util.*;

public class Main{
    
    public static void main(String[] args) throws IOException {
        int seq[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
        int k = in.nextInt() - 1;
        println(seq[k]);
        
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);
    static void read(int arr[], int N) throws IOException{ for(int i = 0; i < N; i++){ arr[i] = in.nextInt(); } }
    static void read(long arr[], int N) throws IOException{ for(int i = 0; i < N; i++){ arr[i] = in.nextLong(); } }
    static void read(String arr[], int N) throws IOException{ for(int i = 0; i < N; i++){ arr[i] = in.next(); } }
    static void print(Object O){ out.print(O); }
    static void println(Object O){ out.println(O); }
    static void print(int arr[]){ for(int i = 0; i < arr.length; i++){ print(arr[i]+" "); } println(""); }
    static void print(int arr[][]){ for(int i = 0; i < arr.length; i++){ print(arr[i]); } }
    static void debug(Object O){ System.out.println(O); }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

Measured memory_bytes: 22740
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n)for(int i=0; i<n; i++)

int main(){
  int K;
  string S;
  cin >> K >> S;

  if(S.size() <= K)
    cout << S << endl;
  else{
    rep(i, K)
      cout << S[i] ;
    cout << "..." << endl; 
  }

  return 0;
}


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

typedef long long ll;

bool find_vec(vector<int> xx,int yy,int zz){
    bool yyFlag = false;
    bool zzFlag = false;
    for(int i=0;i<xx.size();i++){
        if(xx[i]==yy)yyFlag=true;
        if(xx[i]==zz)zzFlag=true;
    }
    if(yyFlag&&zzFlag){
        return true;
    }else{
        return false;
    }
}

int main(){
  int x,y;
  cin >> x >> y;
  vector<int> a = {1,3,5,7,8,10,12};
  vector<int> b = {4,6,9,11};

  if(find_vec(a,x,y)||find_vec(b,x,y)||x==y==2){
      cout<< "Yes" <<endl;
  }else{
      cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {
	    String[] inputs = Io.read();
	    String s = inputs[0];
	    int x = Integer.parseInt(inputs[1]);

	    StringBuilder builder = new StringBuilder();

	    for (int i = 0; i < s.length(); i++) {
	        if (i % x == 0) {
	            builder.append(s.charAt(i));
            }
        }
        String ans = builder.toString();

	    Io.write(ans);
    }
}

class Io {

    public static String[] read() throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        List<String> inputs = new ArrayList<>();
        String line;
        while ((line = br.readLine()) != null) {
            if (line.equals(""))
                break;

            inputs.add(line);
        }
        br.close();
        return inputs.toArray(new String[0]);
    }

    public static void write(String answer)
    {
        System.out.println(answer);
    }
}

Measured memory_bytes: 21204
import sys, copy
import heapq
input = sys.stdin.readline

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

N = [X,Y,Z]
V = [A,B,C]
que = []
top = ((-1)*(V[0][0]+V[1][0]+V[2][0]),[0,0,0])
heapq.heappush(que, top)
ans_set = set()
ans_set.add(tuple(top[1]))
for k in range(K):
    cur = heapq.heappop(que)
    print((-1)*cur[0])
    for i in range(3):
        if cur[1][i] + 1 < N[i]:
            s = (-1) * cur[0] - V[i][cur[1][i]] + V[i][cur[1][i] + 1]
            index = copy.copy(cur[1])
            index[i] = cur[1][i] + 1
            t_index = tuple(index)
            if t_index not in ans_set:
                ans_set.add(t_index)
                heapq.heappush(que,((-1)*s,index))
    


Measured memory_bytes: 55512
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for(int i=(s);i<(t);++i)
#define rng(obj) (obj).begin(), (obj).end()
#define maxs(x,y) (x=max((x),(y)))
#define mins(x,y) (x=min((x),(y)))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x=max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T>>
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<P>;
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,sz(v))i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(sz(v))o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
template <class T> inline ll suma(const v(T)& a) 
{ ll res(0); for(auto&& x:a) res += x; return res;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
const int MX = 200005;
//----------------------------------------------------------------

#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
#define fastio ios_base::sync_with_stdio(false);
#define MOD 1000000007

//----------------------------------------------------------------
template <class T>
map< T, int > prime_factor(T n) {
    map< T, int > ret;
    for(T i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}
ll fac(ll n){
  ll ret=1;
  while(n>1){
    ret*=n;
    if(ret>MOD)ret%=MOD;
    n--;
  }
  return ret;
}


void Main(){
  int n;
  cin>>n;
  vl s(n);
  cin>>s[0];
  rep(i,n-1){
    ll a;
    cin>>a;
    s[i+1] = s[i]+a;
  }
  ll ans=1e10;
  srep(i,0,n-1){
    mins(ans,abs(s[i]-(s[n-1]-s[i])));
  }
  cout<<ans<<endl;
} int main(int argc,char* argv[]){ 
    fastio; fileio; Main();}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define For(i, begin, end) for(int i=begin;i<end;i++)
#define Rep(i, n) For(i,0,n)
#define Sort(v) sort(v.begin(),v.end())
using namespace std;

int main(){
  int X,Y,Z;cin>>X>>Y>>Z;
  cout<<(X-Z)/(Y+Z);

  return 0;
}

Measured memory_bytes: 256
cnt = 0
n = int(raw_input())
A = [int(raw_input()) for _ in range(n)]
G = [1] if n < 5 else [1, 4]
while G[-1]*3+1 <= n/3: G.append(G[-1]*3+1)
G.append(n/5*4)
G.reverse()

def insersionSort(g):
	global cnt
	for i in range(g, n):
		v = A[i]
		j = i - g
		while j >= 0 and A[j] > v:
			A[j+g] = A[j]
			j = j - g
			cnt += 1
		A[j+g] = v

def shellSort():
	for g in G:
		insersionSort(g)

shellSort()
print len(G)
print " ".join(map(str, G))
print cnt
print "\n".join(map(str, A))

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

const int INF = 1001001001;
vector<int> to[100005];

int main() {
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  rep(i,n) {
    cin >> s[i];
  }

  sort(s.begin(),s.end());
  string result;
  rep(i,n) {
      result += s[i];
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int const MOD = 1000000007;

int main() {
    int n; cin >> n; cin.ignore();
    rep(i,0,n) {
        string s; getline(cin, s);
        string ans;
        bool findans = false;
        for(int alpha = 3; ; alpha+=2) {
            if(alpha % 13 == 0) continue;
            rep(beta,0,26) {
                ans.clear();
                rep(j,0,s.length()) {
                    if('a' <= s[j] && s[j] <= 'z') {
                        ans += (((int)s[j] - 96) * alpha + beta) % 26 + 96;
                    }
                    else ans += s[j];
                }
                if(ans.find("that") != string::npos || ans.find("this") != string::npos) {
                    findans = true;
                    break;
                }
            }
            if(findans) break;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1212
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int sum = 0;
		
		int temp = n;
		
		while(temp>0){
			sum+=temp%10;
			temp/=10;
		}
		
		if(n%sum == 0)
			System.out.println("Yes");
		else	
			System.out.println("No");
	}
}

Measured memory_bytes: 21972
#include <iostream>
#include<string>

using namespace std;

struct Dice{
	int num[6];
};

//???????????§OK
int main()
{
	struct Dice dice;
	string str;
	
	int i,j;
	int next[6];
	//???????????§??????
	
	for( i=0 ; i<6; i++){
		cin >> dice.num[i];
	}
	cin >> str;
	//koko??????
	for( i=0; i<str.length(); i++){
		for( j=0; j<6; j++){
			next[j] = dice.num[j];}
		
		switch(str[i]){
		case 'N':
			dice.num[0] = next[1];//??????1?????¨???
			dice.num[1] = next[5];//??????2?????¨???
			dice.num[5] = next[4];//??????6?????¨???
			dice.num[4] = next[0];//??????5?????¨???
			break;
		
		case 'E':
			dice.num[0] = next[3];//??????1?????¨???
			dice.num[3] = next[5];//??????4?????¨???
			dice.num[5] = next[2];//??????6?????¨???
			dice.num[2] = next[0];//??????3?????¨???
			break;
			
		case 'S':
			dice.num[0] = next[4];//??????1?????¨???
			dice.num[4] = next[5];//??????5?????¨???
			dice.num[5] = next[1];//??????6?????¨???
			dice.num[1] = next[0];//??????2?????¨???
			break;
			
		case 'W':
			dice.num[0] = next[2];//??????1?????¨???
			dice.num[2] = next[5];//??????3?????¨???
			dice.num[5] = next[3];//??????6?????¨???
			dice.num[3] = next[0];//??????3?????¨???
			break;
		}
	}
	
	cout << dice.num[0] <<endl;
	return 0;
}
	
	
	
	

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define NM 100005
using namespace std;
int n, m, d[NM], t[NM];
vector<int> v[NM];
set<int> s[NM];
void lee()
{
    for(int i=1; i<=n; i++)
        d[i] = INT_MAX;
    d[1] = 0;
    queue<int> q;
    q.push(1);
    while(!q.empty())
    {
        int nod = q.front();
        q.pop();
        for(auto it:v[nod])
            if(d[it] == INT_MAX)
            {
                d[it] = d[nod] + 1;
                t[it] = nod;
                q.push(it);
            }
    }
}
priority_queue<pair<int,int>, vector<pair<int,int>>, less<pair<int,int>>> q;
void afisare()
{
    for(int i=1; i<=n; i++)
    {
        for(auto it:s[i])
            cout << i << ' ' << it << '\n';
    }
}
void read();
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    read();
    lee();
    for(int i=1; i<=n; i++)
        q.push(make_pair(d[i], i));
    for(int i=1; i<=n; i++)
    {
        for(auto it:v[i])
            if(d[i] < d[it])
                s[i].insert(it);
            else if(d[i] == d[it] && i < it)
                s[i].insert(it);
    }
    //afisare();
    while(q.top().second!=1)
    {
        int nod = q.top().second;
        q.pop();
        if(s[nod].size()%2 == 1)
        {
            int tata = t[nod];
            s[tata].erase(nod);
            s[nod].insert(tata);
        }
    }
    afisare();
    return 0;
}
void read()
{
    cin >> n >> m;
    for(int i=1; i<=m; i++)
    {
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    if(m%2)
    {
        cout << -1;
        exit(0);
    }
}


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

using namespace std;

int main() {
	char moji[200],*p;
	int len,i;
	p = moji;
	cin >> moji;
	len = strlen(moji);
	p[len-1] = '\0';

	while (1) {
		len = strlen(moji);
		if (len % 2 == 0) {
			for (i = 0; i < len / 2; i++) {
				if (p[i] != p[i + len / 2])
					break;
			}
			if (i == len / 2) {
				cout << len;
				break;
			}
		}
		p[len-1] = '\0';
	}

	return 0;
}

Measured memory_bytes: 1016
# -*- coding: utf-8 -*-

num = int(input())

if num >= 64:
    print(str(64))
elif num >= 32:
    print(str(32))
elif num >= 16:
    print(str(16))
elif num >= 8:
    print(str(8))
elif num >= 4:
    print(str(4))
elif num >= 2:
    print(str(2))
else:
    print(str(1))


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

int main() {
  int N,K,A;
  cin >> N >> K;
  A = 0;
  for(int i=0;i<N;i++){
    int x;
    cin >> x;
    if(2*x>=K){
      A+=2*(K-x);
    }
    else{
      A+=2*x;
    }
  }
  cout << A ;
}


Measured memory_bytes: 764
//============================================================================
// Name        : JOI.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<ll,ll> P;

//1. dp,?????°
int n,m;
ll c;

vector<P> road[100001];
ll d[200001]={};
ll dp[100001]={};
ll dp2[100001]={};


int main() {
	//2. ??\???
	cin>>n>>m>>c;

	ll a,b,d1;
	ll totalC=0;
	for(int i=0;i<m;++i){
		cin>>a>>b>>d1;
		road[a].push_back(P(b,i));
		road[b].push_back(P(a,i));
		d[i]=d1;
		totalC+=d1;
	}

	queue<P> que;

	//3.?????????
	for(int i=0;i<100001;++i)dp[i]=10000000001;
	que.push(P(1,0));
	//4.loop
	//
	while(!que.empty()){
		//5.???????????????
		P p1=que.front();que.pop();
		ll pos=p1.first;
		ll cost=p1.second;
		if(dp[pos]<cost)continue;
		dp[pos]=cost;
		for(auto it:road[pos]){
			int pos2=it.first;
			int roadm=it.second;
			que.push(P(pos2,cost+d[roadm]));
		}
	}
	priority_queue<P,vector<P>,greater<P>> que2;
	ll x=0;
	ll total=20000000000;
	for(ll i=1;i<n+1;++i)que2.push(P(dp[i],i));
	while(!que2.empty()){
		//5.???????????????
		P p2=que2.top();que2.pop();
		ll cos=p2.first;
		ll pos=p2.second;
		dp2[pos]=1;
		x=cos;
		for(auto it:road[pos]){
			ll pos2=it.first;
			ll roadm=it.second;
			if(dp2[pos2]>0)totalC-=d[roadm];
		}
		total=min(total,c*x+totalC);
	}


	//4.??????
	cout << total << endl;
	return 0;
}

Measured memory_bytes: 26764
import java.util.*;
class Main {
  public static void main (String[] args)  {
    
    Scanner sc = new Scanner(System.in);
    
    String S=sc.next();
    String T=sc.next();
    
     
     int [] as= new int [26];
      int [] at= new int [26];
     
     
     for(int i=0;i<26;i++){
      as[i]=-1;
      at[i]=-1;
     }
     
     int tv = 0;
     int sv = 0;
     
     for(int i=0; i<S.length(); i++){
       tv = T.charAt(i)-97;
       sv = S.charAt(i)-97;
       
       if(as[sv]!=-1&& as[sv]!=tv){
         System.out.println("No");
         System.exit(0);
         }
       
       if(at[tv]!=-1&& at[tv]!=sv){
         System.out.println("No");
         System.exit(0);
         }
       
       at[tv]=sv;
       as[sv]=tv;
       
       }
     
     
        
       System.out.println("Yes");
       
  }
}

Measured memory_bytes: 26844
N,M = map(int,input().split())
A = list(map(int,input().split()))
new_A = []
for i in range(N):
  if A[i] >= sum(A)/(4*M):
    new_A.append(A[i])

if len(new_A)>=M:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main(void)
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    for (int i = 1; i <= k; i++)
    {
        if (i <= a)
        {
            ans++;
        }
        else if (i <= (a + b))
        {
            /*nothing*/
        }
        else
        {
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
}


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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	string y, m, d;
	while (cin >> y >> m >> d) {
		//if (y <= 1868 && m <= 9 && d < 8)cout << "pre-meiji" << endl;
		//else if (y <= 1912 && m <= 7 && d < 30)cout << "meiji" << endl;
		//else if (y <= 1926 && m <= 12 && d < 25)cout << "taisho" << endl;
		//else if (y <= 1989 && m <= 1 && d < 8)cout << "showa" << endl;
		//else cout << "heisei" << endl;
		while (y.size() < 4)y = "0" + y;
		while (m.size() < 2)m = "0" + m;
		while (d.size() < 2)d = "0" + d;

		string s = y + m + d;

		if (s < "18680908")cout << "pre-meiji" << endl;
		else if (s < "19120730")cout << "meiji" << " " << stoi(y) - 1868 + 1 << " " << stoi(m) << " " << stoi(d) << endl;
		else if (s < "19261225")cout << "taisho" << " " << stoi(y) - 1912 + 1 << " " << stoi(m) << " " << stoi(d) << endl;
		else if (s < "19890108")cout << "showa" << " " << stoi(y) - 1926 + 1 << " " << stoi(m) << " " << stoi(d) << endl;
		else cout << "heisei" << " " << stoi(y) - 1989 + 1 << " " << stoi(m) << " " << stoi(d) << endl;

	}
	return 0;
}

Measured memory_bytes: 3052
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

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

		long A = sc.nextLong();
		BigDecimal B = sc.nextBigDecimal();
		int C = 100;
//		BigDecimal変換
		BigDecimal bA = new BigDecimal(A);
		BigDecimal bC = new BigDecimal(C);

		B = B.multiply(bC); //少数を整数に直す
		BigDecimal pop = bA.multiply(B);
		pop = pop.divide(bC);
		pop = pop.setScale(0, BigDecimal.ROUND_DOWN);

		System.out.println(pop);
	}
}

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

int main()
{
  string S;
  cin >> S;

  int len = S.size();
  vector<int> ans(len, 0);
  vector<int> cnt(2, 0);
  for (int i=0; i<len; i++) {
    if (S[i] == 'R') {
      cnt[i%2]++;
    } else {
      if (i%2==0) {
        ans[i]+=cnt[0];
        ans[i-1]+=cnt[1];
      } else {
        ans[i-1]+=cnt[0];
        ans[i]+=cnt[1];
      }
      cnt[0]=0;
      cnt[1]=0;
    }
  }
  cnt[0]=0;
  cnt[1]=0;
  for (int i=len-1; i>=0; i--) {
    if (S[i] == 'L') {
      cnt[i%2]++;
    } else {
      if (i%2==0) {
        ans[i]+=cnt[0];
        ans[i+1]+=cnt[1];
      } else {
        ans[i+1]+=cnt[0];
        ans[i]+=cnt[1];
      }
      cnt[0]=0;
      cnt[1]=0;
    }
  }

  for (int i=0; i<len; i++) {
    if (i==0) cout << ans[i];
    else cout << " " << ans[i];
  }
  cout << endl;

  return 0;
}


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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

ll modpow(ll a, ll n) {
  ll ret = 1LL;
  while(n > 0) {
    if(n & 1) ret = a * ret % MOD;
    a = a * a % MOD;
    n >>= 1;
  }

  return ret;
}

int main() {
  int N;
  std::cin >> N;

  std::vector<ll> C(N);
  rep(i, N) {
    std::cin >> C[i];
  }
  std::sort(C.rbegin(), C.rend());

  ll ans = 0;

  rep(i, N) {
    ans += C[i] * (i + 2) % MOD;
    ans %= MOD;
  }
  ans *= modpow(2, 2 * (N - 1));
  ans %= MOD;

  std::cout << ans << '\n';
}


Measured memory_bytes: 1792
/***

    Muhammad Imdad-Ul-Haque Rakib(Attari)
    CSE'19
    Chittagong,Bangladesh

***/


#include<bits/stdc++.h>


/**Definitions**/


#define   ld             long double
#define   ll             long long
#define   boost_         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define   pb             push_back
#define   ppb            pop_back
#define   ull            unsigned long long
#define   over           return 0
#define   scan(i,n,a)    for(i=0;i<n;i++) cin>>a[i]
#define   MP             make_pair
#define   spc            " "

using namespace std;


/** Predefined Functions **/


int gcd(int x,int y){
    if(x==0) return y;
    else return gcd(y%x,x);
}
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b){ return (a.second<b.second); }
bool sortbysecinrev(const pair<int,int>&a, const pair<int,int>&b){ return (a.second>b.second); }
bool sortbysize(string &s1,string &s2){ return s1.size() < s2.size(); }
bool sortinrev(const pair<int,int> &a, const pair<int,int> &b){ return (a.first > b.first); }


/** Main Function **/


int main(){

    boost_;
    ll n;
    cin>>n;
    ll a[n],i,sum=0,minn=110,maxx=0,mn=2e7,j;

    for(i=0;i<n;++i){
        cin>>a[i];
        maxx=max(maxx,a[i]);
        minn=min(minn,a[i]);
    }

    for(i=minn;i<=maxx;++i){

        for(j=0;j<n;++j){

            sum+=abs(a[j]-i)*abs(a[j]-i);
        }

        mn=min(mn,sum);
        sum=0;
    }

    cout<<mn<<endl;
    over;
}


Measured memory_bytes: 3644
#include<stdio.h>
#include<string.h>
//using namespace std;
int n,t[100005],x[100005],y[100005];
int i;
int main()
{
    t[0]=x[0]=y[0]=0;//the first
    scanf("%d",&n);
    for(i=1;i<=n;++i)
      scanf("%d%d%d",&t[i],&x[i],&y[i]);
    for(i=1;i<=n;++i)
    {
      if((x[i]+y[i]-x[i-1]+y[i-1])%2!=0&&(t[i]-t[i-1])%2==0||(x[i]+y[i]-x[i-1]-y[i-1])%2==0&&(t[i]-t[i-1])%2!=0)//odd or double isnt the same
      {
        break;
      }
      if((x[i]+y[i]-x[i-1]-y[i-1])%2==0&&(t[i]-t[i-1])%2==0||(x[i]+y[i]-x[i-1]-y[i-1])%2!=0&&(t[i]-t[i-1])%2!=0)
      {
        if(t[i]<(x[i]+y[i]))
          break;
      }
    }
    if(i==n+1)
      printf("Yes\n");
    else
      printf("No\n");
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

typedef vector<ll> vec;
typedef vector<vec> mat;

mat mul(mat &A,mat& B){
	mat C(A.size(),vec(B[0].size()));
	rep(i,A.size())rep(k,B.size())rep(j,B[0].size()){
		C[i][j]=(C[i][j]+A[i][k]*B[k][j])%mod;
	}
	return C;
}

mat pow(mat &A,ll n){
	mat B(A.size(),vec(A.size()));
	rep(i,A.size()) B[i][i]=1;
	while(n>0){
		if(n&1) B=mul(B,A);
		A=mul(A,A);
		n>>=1;
	}
	return B;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  ll k;
  cin>>n>>k;
  mat a(n,vec(n)),g(n,vec(n));
  rep(i,n)rep(j,n) cin>>a[i][j];
  g=pow(a,k);
  ll ans=0;
  rep(i,n)rep(j,n) (ans+=g[i][j])%=mod;
  cout<<ans<<endl;
}

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

int main(){
    int dom[4][3][10]={};
    int n,b,f,r,v;
    cin >> n;
    for(int i = 0;i<n;i++){
        cin>>b>>f>>r>>v;
        dom[b-1][f-1][r-1] += v;
        if(dom[b-1][f-1][r-1]>=9){
            dom[b-1][f-1][r-1]=9;
        }else if(dom[b-1][f-1][r-1]<=0){
            dom[b-1][f-1][r-1]=0;
        }
    }
    for(int k = 0;k<4;k++){
        for(int l = 0;l<3;l++){
            for(int m = 0;m<10;m++){
                cout <<" "<< dom[k][l][m];
            }
            cout << endl;
        }
        if(k != 3){
            cout << "####################"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    int a, b, m;
    cin >> a >> b >> m;
    vector<int> v(a), u(b);
    rep(i, a) cin >> v[i];
    rep(i, b) cin >> u[i];

    vector<int> res(m);
    rep(i, m){
        int x, y, c;
        cin >> x >> y >> c;
        res[i] = v[x-1] + u[y-1] - c;
    }
    sort(all(res));

    sort(all(v));
    sort(all(u));
    cout << min(res[0], v[0]+u[0]) << endl;
}

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

#define M 1000033
#define L 14

char H[M][L]; 
/* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}
int h(int key ,int i){return (h1(key)+i*h2(key))%M; }
int h1(int key){ return key%M; }
int h2(int key){ return 1+key%(M-1); }

int find(char str[]){
  int i=0,k=getKey(str),m=h(k,i);
  while(H[m][0]!='\0'){
    if(strcmp(H[m],str)==0)return 1;
    i++;
    m=h(k,i);
  }
  return 0;
}

int insert(char str[]){
  int i=0,k=getKey(str),m;

  while(1){
    m=h(k,i);
    if( H[m][0] == '\0' ){
      strcpy(H[m],str);
      return 1;
    }
    i++;   
  }

}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 14280
#include <bits/stdc++.h>
#include<string>
#define fn(i,n) for(int i=0;i<n;i++)
#define rn(i,n) for(int i=1;i<n;i++)
#define ll long long
#define wh while
#define pb push_back
#define sc(n) scanf("%lld",&n)
#include <vector>
#define N 100100

using namespace std; 
 
int main() {
	// your code goes here
    ll a,b,c,d;
    sc(a);sc(b);sc(c);sc(d);
	if(a+b>c+d)
        cout<<"Left"<<endl;
    else if(a+b==c+d)
        cout<<"Balanced"<<endl;
    else
        cout<<"Right"<<endl;
        
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    float sum;

    sort(a.rbegin(), a.rend());
    sum = accumulate(a.begin(), a.end(), 0);

    if (a[m-1] < sum/(4*m)) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define rep(i,l,r)for(int i=(l);i<(r);i++)

char s[4010];
int main(){
	int n;
	scanf("%d %s",&n,s);
	int ans=0;
	rep(m,0,n)rep(d,0,n)if(m-d>=0&&m+d<n){
		if(s[m-d]!=s[m]
		   &&s[m]!=s[m+d]
		   &&s[m+d]!=s[m-d])ans++;
	}
	long long c[300]={};
	rep(i,0,n)c[s[i]]++;
	printf("%lld",c['R']*c['G']*c['B']-ans);
}

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

int main() {
   vector<pair<char,char>> p1;
   vector<pair<char,char>> p2;
    string S,T; cin >> S >> T;
    bool can = true;
    rep(i,S.size()){
     p1.push_back(make_pair(S[i],T[i]));
     p2.push_back(make_pair(T[i],S[i]));
    }
    sort(p1.begin(),p1.end());
    sort(p2.begin(),p2.end());
    rep(i,S.size()-1){
        if(p1[i].first==p1[i+1].first && p1[i].second!=p1[i+1].second){
            can=false; break;
        }
        if(p2[i].first==p2[i+1].first && p2[i].second!=p2[i+1].second){
            can=false; break;
        }
    }
    if(can)cout <<"Yes"<< endl;
    else cout << "No" << endl;

    return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> d(k);
  vector<int> a(n + 1, 0);
  for (int i = 0; i < k; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int tmp;
      cin >> tmp;
      a.at(tmp)++;
    }
  }
  int num = 0;
  for (int i = 1; i < n + 1; i++)
    if (a.at(i) == 0) num++;
  cout << num;
  return 0;
}


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

int dp[1234][8];
int n;
int a[1234];

char str[1234];
int hash[256];

int main()
{
	memset(dp, 0, sizeof(dp));
	hash['J'] = 1; hash['O'] = 2; hash['I'] = 4;
	scanf("%d", &n);
	scanf("%s", str);
	for (int i = 0; i < n; ++i)a[i] = hash[str[i]];
	dp[0][1] = 1;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 0; j < 8; ++j)
		{
			for (int k = 0; k < 8; ++k)
			{
				if ((a[i - 1] & j) && (j & k))
				{
					dp[i][j] += dp[i - 1][k];
					dp[i][j] %= 10007;
				}
			}
		}
	}
	int answer = 0;
	for (int j = 0; j < 8; ++j)
	{
		answer += dp[n][j];
		answer %= 10007;
	}
	printf("%d\n", answer);
	return 0;
}

Measured memory_bytes: 2736
from sys import stdin
def input():
    return stdin.readline().strip()

def main():
    mod = 10**9 + 7
    h, w = map(int, input().split())

    dp = [0] * (w + 1)
    dp[1] = 1
    for _ in range(h):
        a = input()
        for i in range(w):
            if a[i] == '#':
                dp[i+1] = 0
            else:
                dp[i+1] += dp[i]
                dp[i+1] %= mod

    print(dp[w])

main()

Measured memory_bytes: 73624
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
//using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;
const double PI = acos(-1.0);

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  int P = 0;
  int G = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'p')
      P++;
      else G++;
  }
  int ans = (G - P) / 2; // Gが1個減ってPが1個増えるから
  cout << ans << endl;
  return 0;
}
// (別解)とりあえずTopCoDeer君は条件を満たした手の出し方をしているからTopCoDeer君と同じ手を出し続ければ必ず0点になる．その上でパーを出した回数とグーを出した回数を数えて条件を満たす数を数えて後ろからパーに変えていけばよい．


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

using namespace std;

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

const int N = 1010;

int tt = -1;
char stk[N];

int main()
{

    string s;
    cin >> s;

    for(int i = 0; i < s.size(); i++)
        if(s[i] == '1') stk[++tt] = '1';
        else if(s[i] == '0') stk[++tt] = '0';
        else
        {
            if(tt >= 0) tt--;
        }

    for(int i = 0; i <= tt; i++) cout << stk[i];
    puts("");

    return 0;
}


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

bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}
double distance(double x1, double y1, double x2, double y2)
{
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int main()
{
    string s;
    cin >> s;
    int n = s.length();
    int cnt = 0;
    ll ans = 0;
    for (size_t i = 0; i < n; i++)
    {
        if (s[i] == 'W')
        {
            ans += i - cnt;
            cnt++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

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

    int d;
    cin >> d;

    vector<int> c(26);
    vector<vector<int>> s(d,vector<int>(26));

    int sub=0;
    // 減少率
    for(int i=0;i<26;i++){
        cin >> c[i];
        sub+=c[i];
    }

    // 満足度
    for(int i=0;i<d;i++){
        for(int j=0;j<26;j++) cin >> s[i][j];
    }

    long long ans=0;
    vector<int> t(26,0);
    for(int i=1;i<=d;i++){
        int buf;
        cin >> buf;
        buf--;

        for(int j=0;j<26;j++){
            if(j==buf){
                ans+=s[i-1][j];
                t[j]=i;
            }
            else{
                ans-=c[j]*(i-t[j]);
            }
        }
        cout << ans << endl;
    }
}

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

#define inf 0x3f3f3f3f
#define INF 1000111000111000111LL
#define mod 1000000007
#define endl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define all(cc) (cc).begin(),(cc).end()
using lli = long long int ;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vb = vector<bool> ;
using vvi = vector<vector<int>> ;
using vlli = vector<long long int> ;
using vpii = vector<pair<int, int>> ;

int main()
  {
    ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
    lli n, m, ans=0 ;
    cin>> n >> m ;
    if(m>=2*n)
      {
        ans=n ;
        m-=2*n ;
        ans+=m/4 ;
        cout<< ans ;
        return 0 ;
      }
    else
      {
        ans=m/2 ;
        cout<< ans ;
        return 0 ;
      }
  }


Measured memory_bytes: 384
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        A: usize,
        B: usize,
        C: usize,
    }
    println!("{}", if B > A * C { C } else { B / A });

}




Measured memory_bytes: 4352
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = if n <= m then  List.range n `To m else []
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'
let itoa n = Char.chr (n + Char.code '0')

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let (n,m,k) = scan "%d %d %d" Tuple3.make
let a = scan_list ~sep:' ' Int.of_string
let b = scan_list ~sep:' ' Int.of_string

let () =
  let aa = Array.make (succ n) 0 in
  let ab = Array.make (succ m) 0 in
  ListL.iteri a ~f:(fun i v -> aa.(i+1) <- aa.(i) + v);
  ListL.iteri b ~f:(fun i v -> ab.(i+1) <- ab.(i) + v);
  let rec aux f left right =
    if right - left > 1 then
      let mid = (left + right)/2 in
      if f mid then aux f mid right
      else aux f left mid
    else left
  in
  let f i = ListL.exists (0++i)
      ~f:(fun j ->
          let (x, y) = j, i - j in
          if 0 <= x && x <= n && 0 <= y && y <= m then aa.(x) + ab.(y) <= k
          else false)
  in
  Printf.printf "%d\n" @@ aux f 0 (n+m+1)


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

int main(){
    int n;
    int A[100];
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> A[i];
    }
    for (int i = 0; i < n; i++){
        int v = A[i];
        int j = i-1;
        while (j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
            A[j+1] = v;
        }
        for (int j = 0; j < n; j++){
            if (j == n-1) cout << A[j] << endl;
            else cout << A[j] << " ";
        }
    }
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k,n,p,i,j,s,m=-1;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  for(i=0;i<n-1;i++){
    for(j=i+1;j<n;j++){
      s=a[i]*a[j];
      k=s%10+1;
      while(s){
        p=s%10;
        if(p!=k-1)goto L;
        s/=10;
        k=p;
      }
      m=max(m,a[i]*a[j]);L:;
    }
  }
  cout<<m<<endl;
}

Measured memory_bytes: 3104