akhauriyash/Code-Regression huggingface dataset:
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <iomanip>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define pi acos(-1)
#define mod 998244353//1000000007
#define inf 1000000007
#define ll long long
#define ull unsigned long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 2010
#define _DEBUG
template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
template <class T> void add(int &a,T b){a=(a+b)%mod;}
inline int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}

int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;b>>=1;
    }
    return ans;
}
int pow(int a,int b,int c){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%c;
        a=1LL*a*a%c;b>>=1;
    }
    return ans;
}

char s[N];
int a[N],dp[N<<1],ndp[N<<1];
int main(){
    //srand(time(NULL)+clock());
    int T,ca=0,k,i,j,m=0,K,n;
    //double start=clock();
    scanf("%s",s);n=strlen(s);
    rep(i,0,n)a[i+1]=a[i]+(s[i]=='0'?2:(s[i]=='1'?1:0));
    dp[0]=1;
    rep(i,0,n*2){
        memset(ndp,0,sizeof(ndp));
        int r=i<n?a[i+1]:a[n];
        int l=2*(i+1)-r;
        per(j,0,min(r,i)+1)if(dp[j]){
            k=i-j;
            if(j<r)add(ndp[j+1],dp[j]);
            if(k<l)add(ndp[j],dp[j]);
        } 
        swap(dp,ndp);
    }
    printf("%d\n",dp[a[n]]);
    //cerr<<(1.*clock()-start)/CLOCKS_PER_SEC<<"\n";
}


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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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




V<int>ans;
bool mark[1000010];

void sieve()
{
    int i,j;
    ans.PSB(2);
    for(i=3;i<=sqrt(1000010);i+=2)
    {
        if(!mark[i])
        {
            ans.PSB(i);
            for(j=i*i;j<=1000010;j+=2*i)mark[j]=1;
        }
    }
    for(i=1001;i<=1000010;i+=2)
    {
        if(!mark[i])ans.PSB(i);
    }
}

int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    sieve();
    int n;
    cin >> n;
    cout << ans[lower_bound(ans.B,ans.E,n)-ans.B];
    return 0;
}


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

using namespace std;

typedef long long int ll;

const ll mod = 1e9 + 7;
const ll MAXN = 2e5 + 5;

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

  ll a, b;
  cin >> a >> b;
  ll c = __gcd(a, b);
  ll cnt = 0;
  bool ok = false;
  while(c % 2 == 0){
    c /= 2;
    ok = true;
  }
  if(ok) cnt++;
  for(ll i = 3; i * i <= c; i += 2){
    ok = false;
    while(c % i == 0){
      c = c / i;
      ok = true;
    }
    if(ok) cnt++;
  }
  if(c > 1) cnt++;

  cout << cnt + 1 << '\n';
}


Measured memory_bytes: 256
#include <ctime>
#include <iomanip>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdio>
#include <list>
#include <queue>
using namespace std;

#define int long long
#define INF 1e18
#define EPS 1e-9

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

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

signed main() {
    int n; cin >> n;
    vector<vector<int>> v(n, vector<int> (3));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> v[i][j];
        }
    }

    vector<vector<int>> dp(n + 1, vector<int> (3, 0));

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 3; j++) {
            for(int k = 0; k < 3; k++) {
                if(j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + v[i][k]);
            }
        }
    }

    int res = 0;
    for(int i = 0; i < 3; i++) chmax(res, dp[n][i]);

    cout << res << endl;
}


Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;

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

	string r = s;
	reverse(r.begin(), r.end());

	if (r != s)
	{
		cout << "No" << endl;
		return 0;
	}

	string r1 = "";
	for (int i = 0; i < (s.size() - 1) / 2; i++)
	{
		r1.push_back(s[i]);
	}
	
	string r2 = r1;
	reverse(r2.begin(), r2.end());

	if (r1 != r2)
	{
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 3604
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,m,len,x,y,a[4],b[4];
string s,t;
map <char,pii> mp;

bool out(int xx,int yy)
{
	return xx<1||yy<1||xx>n||yy>m;
}

void solve(char fm,char sm)
{
	int xx=x,yy=y;
	rep(i,len)
	{
		if(s[i]==fm)
		{
			xx+=mp[fm].fi;
			yy+=mp[fm].se;
			if(out(xx,yy))
			{
				puts("NO");
				//cout<<fm<<endl;
				exit(0);
			}
		}
		if(t[i]==sm)
		{
			if(!out(xx+mp[sm].fi,yy+mp[sm].se))
			{
				xx+=mp[sm].fi;
				yy+=mp[sm].se;
			}
		}
	}
}

int main()
{
	mp['U']={-1,0};
	mp['D']={1,0};
	mp['L']={0,-1};
	mp['R']={0,1};
	cin>>n>>m>>len>>x>>y>>s>>t;
	solve('U','D');
	solve('D','U');
	solve('L','R');
	solve('R','L');
	puts("YES");
	rt0;
}

Measured memory_bytes: 776
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
use std::collections::HashSet;
fn main() {
    input! {
        n: u64,
        mut a: [u64; n]
    }
    let mut set = HashSet::with_capacity(100_000);

    for &x in &a {
        if !set.remove(&x) {
            set.insert(x);
        }
    }
    println!("{}", set.len());
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
long long dp[2005];
int main() {
	int s,i;
	cin>>s;
	for(i=4,dp[3]=1;i<=s;i++)   dp[i]=(dp[i-1]+dp[i-3])%1000000007;
	cout<<dp[s];
}

Measured memory_bytes: 3644
#include <stdio.h>
int pm(int n){
    int i,j,c=n-1,target[n-1];
    for(i=0;i<n-1;i++){target[i]=i+2;}
    for(i=0;i<n-1;i++){
        if (!target[i]){continue;}
        for(j=i;j<n-1;j=j+i+2){
            if (!target[j]){continue;}
            if (j!=i && target[j]%target[i]==0){target[j]=0;c--;}
        }
    }
    return c; 
} 

int main(void){
    int d,ds[30],c=0,i;
    while(scanf("%d",&d)!=EOF){
        ds[c]=pm(d);c++;
    }
    for(i=0;i<c;i++){printf("%d\n",ds[i]);}
    return 0;
}

    



Measured memory_bytes: 5600
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b[ohara], c, d, tmp, m, h, w, x, y, sum, k, q;
priority_queue<P, vector<P>, greater<P>> que;
U_MAP mem;
ll decrease = LINF;

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

  cin >> n;
  rep(i, n) cin >> a[i] >> b[i];
  rep(i, n) {
    sum += a[i];
    if (a[i] > b[i]) decrease = min(decrease, b[i]);
  }
  ans = sum - decrease;
  ans = (decrease == LINF ? 0 : ans);
  Cout(ans);
  return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  LL m,d;
  cin >> m >> d;
  LL answer = 0ll;
  FOR(i,2,10) FOR(j,2,10) {
    if(i*j <= m && i*10+j <= d) ++answer;
  }
  cout << answer << endl;
  return 0;
}


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

#define fr first
#define sc second
#define pb push_back
#define mk make_pair

using namespace std;
typedef long long ll;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;

int a[15][15];

bool dist(int i, int j, int d) {
      double res = 0;
      ll sum = 0;
      for (int t = 1; t <= d; t ++) {
            sum += (a[i][t] - a[j][t]) * (a[i][t] - a[j][t]);
      }
      res = sqrt(sum + 0.0);
      ll ans = res;
      if (ans * ans == sum) return true;
      return false;
}

int main()
{
      int n, d;
      cin >> n >> d;
      for (int i = 1; i <= n; i ++) {
            for (int j = 1; j <= d; j ++) {
                  cin >> a[i][j];
            }
      }
      int ans = 0;
      for (int i = 1; i < n; i ++) {
            for (int j = i + 1; j <= n; j ++)
                  ans += dist(i, j, d);
      }
      cout << ans << endl;
      return 0;
}











Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define int long long
#define all(arr) arr.begin(),arr.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define vi vector<int>
#define vstr vector<string>
#define vbool vector<bool>
#define vvi vector<vector<int> >
#define mii map<int,int>
#define pb push_back
#define pii pair<int,int>
#define vpair vector<pii > 
#define mkp make_pair
#define scan(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) {cout<<a[i]<<' ';}cout<<'\n'
#define mem(a,v) memset(a,v,sizeof(a))
#define loop(i,a,b) for (int i = a; i < b; i++)
#define loope(i,a,b) for (int i = a; i <= b; i++)
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION std::cout.unsetf ( std::ios::fixed );std::cout.precision(9)
#define PI 3.14159265
#define S second
#define F first
#define CHECK cout<<"CHEDEDWB"<<endl
#define br '\n'
/*int mod = 1e9+7;
int inf = 1e18;
int m_inf = INT_MIN;
int MOD = 100001;*/

void solve()
{
	int a,b;
	cin>>a>>b;
	int outlet = 1;
	int ans = 0;
	while(outlet<b)
	{
		outlet--;
		outlet += a;
		ans++;
	}
	cout<<ans<<endl;
}

int32_t main()
{
	FastIO; PRECISION;
	int t = 1;
	//cin>>t;
	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException err){
			err.printStackTrace();
		}
	}
	
	int[][] offset = new int[][]{
			{-1, 0}, {1, 0}, {0, -1}, {0, 1}
	};


	public Main() throws IOException, StackOverflowError{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		List<Integer> Ans = new ArrayList<Integer>();
		String line;

		while((line = in.readLine()) != null){
			String[] dst = line.split(" ");
			int h = Integer.parseInt(dst[0]);
			int w = Integer.parseInt(dst[1]);

			if(h==0 && w==0){
				break;
			}

			int[][] data = new int[h+2][w+2];
			int[][] label = new int[h+2][w+2];
			for(int j=1; j<=h; j++){
				line = in.readLine();
				for(int i=1; i<=w; i++){
					String c = line.substring(i-1, i);
					if(c.equals("@")){
						data[j][i] = 1;
					}
					else if(c.equals("#")){
						data[j][i] = 2;
					}
					else if(c.equals("*")){
						data[j][i] = 3;
					}
					label[j][i] = 0;
				}
			}
			
			for(int j=0; j<h+2; j++){
				data[j][0] = 0;
				data[j][w+1] = 0;
				label[j][0] = -1;
				label[j][w+1] = -1;
			}
			
			for(int i=0; i<w+2; i++){
				data[0][i] = 0;
				data[h+1][i] = 0;
				label[0][i] = -1;
				label[h+1][i] = -1;
			}
			

			int count = 0;
			for(int j=1; j<=h; j++){
				for(int i=1; i<=w; i++){
					if(label[j][i] == 0){
						count++;
						label[j][i] = count;
						grouping(data, label, i, j);
					}
				}
			}

			Ans.add(count);
		}

		for(int n=0; n<Ans.size(); n++){
			System.out.println(Ans.get(n));
		}
	}

	public void grouping(int[][] data, int[][] label, int x, int y){
		List<point> cue = new ArrayList<point>();
		cue.add(new point(x, y));
		while(cue.size() != 0){
			point p = cue.get(0);
			cue.remove(0);
			for(int d=0; d<4; d++){
				int xx = p.x + offset[d][0];
				int yy = p.y + offset[d][1];
				if(label[yy][xx] == 0 && data[yy][xx] == data[p.y][p.x]){
					label[yy][xx] = label[p.y][p.x];
					cue.add(new point(xx, yy));
				}
			}
		}
	}
}

class point{
	int x;
	int y;
	
	public point(int x, int y){
		this.x = x;
		this.y = y;
	}
}

Measured memory_bytes: 11000
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
   
   
public class Main {
	static int INF = 2 << 27;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[m];
		for(int i = 0; i < m; i++) {
			a[i] = sc.nextInt()-1;
		}
		int[] score = new int[n];
		for(int i = 0; i < m; i++) {
			int x = 0;
			for(int j = 0; j < n; j++) {
				if(sc.nextInt()-1 == a[i]) {
					score[j]++;
				}
				else {
					x++;
				}
			}
			score[a[i]] += x;
		}
		for(int i = 0; i < n; i++) {
			System.out.println(score[i]);
		}
		
		
		
	}
	
}

Measured memory_bytes: 40568
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,q,w,e,r,count=0;
  cin>>a>>b;
  for(int i=a;i<=b;i++){
    q=i/10000;
    w=i%10000/1000;
    e=i%100/10;
    r=i%10;
    if(q==r && w==e){
      count++;
  }
  }
  cout<<count<<endl;
  return 0;
}


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

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(n), c(m), d(m);
	for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
	for (int i = 0; i < m; i++) cin >> c[i] >> d[i];


	for (int i = 0; i < n; i++) {
		int e = abs(c[0]-a[i])+abs(d[0]-b[i]), f = 0;
		for (int j = 0; j < m; j++) {
			if (e > abs(c[j] - a[i]) + abs(d[j] - b[i])) {
				e = abs(c[j] - a[i]) + abs(d[j] - b[i]);
				f = j;
			}
		}
		cout << f + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

typedef long long ll;


int main(){
  string s;
  cin >> s;
  int p=0,g=0,win=0,lose=0;
  rep(i,s.length()){
    if(s[i]=='p'){
      if(g>p){
	p++;
      }
      else{
	g++;
	lose++;
      }
    }else if(s[i]=='g'){
      if(g>p){
	p++;
	win++;
      }
      else{
	g++;
      }
    } 
  }
  cout << (win-lose) << "\n";

  return 0;
}


Measured memory_bytes: 512
/**
 * Created by hiramekun at 20:44 on 2019-12-08.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll h, w;
    cin >> h >> w;
    int a[h][w], b[h][w];
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) cin >> b[i][j];

    ll max_diff = 2 * 80 * 160;
    bool dp[h][w][max_diff];
    rep(i, h) rep(j, w) rep(l, max_diff) dp[i][j][l] = false;

    ll mid = max_diff / 2;
    dp[0][0][b[0][0] - a[0][0] + mid] = true;
    dp[0][0][-b[0][0] + a[0][0] + mid] = true;

    rep(i, h) {
        rep(j, w) {
            rep(l, max_diff) {
                if (!dp[i][j][l]) continue;
                if (i + 1 <= h - 1) {
                    dp[i + 1][j][l + b[i + 1][j] - a[i + 1][j]] = true;
                    dp[i + 1][j][l - b[i + 1][j] + a[i + 1][j]] = true;
                }
                if (j + 1 <= w - 1) {
                    dp[i][j + 1][l + b[i][j + 1] - a[i][j + 1]] = true;
                    dp[i][j + 1][l - b[i][j + 1] + a[i][j + 1]] = true;
                }
            }
        }
    }
    ll ans = ll_inf;
    rep(i, max_diff) {
        if (dp[h - 1][w - 1][i]) ans = min(ans, abs(i - mid));
    }
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

int main(){
  int n; cin>>n;
  long long ans=0;
  unordered_map<string,int> m;
  for(int i=0;i<n;i++){
    string s; cin>>s;
    sort(s.begin(),s.end());
    ans+=m[s];
    m[s]++;
  }cout<<ans<<endl;
}

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

int main() {
	int b1, b2, b3;
	cin >> b1 >> b2 >> b3;

	int sum = b1;
	sum += b2;
	sum += b3 * 2;
	if (sum >= 2) {
		cout << "Open" << endl;
	} else cout << "Close" << endl;
}


Measured memory_bytes: 3092
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int i,n;
	long long x;
	x=1;
	cin>>n;
	for(i=1;i<=n;i++){
		x=x*i;
		x=x%(1000000000+7);
	}
	cout<<x<<endl;
	return 0;
}


Measured memory_bytes: 256
def ruiseki_xor(n):
    if n%4==0:
        return n
    elif n%4==1:
        return 1
    elif n%4==2:
        return n+1
    else:
        return 0

A,B = map(int,input().split())
print(ruiseki_xor(B)^ruiseki_xor(A-1))

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

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

  int n;
  cin >> n;

  string s;
  cin >> s;

  int ans = 0;
  for (int i = 0; i < n-1; ++i) ans += (s[i] != s[i+1]);

  cout << ans+1 << endl;

  return (0);
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007
#define iP pair<int,int>
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define pb push_back
#define inf 1e15
#define mod1 998244353
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
int power(int x,int y){
    int res=1;
    while(y>0){
        if(y&1)res=(res*x)%mod1;
        x=(x*x)%mod1;
        y/=2;
    }
    return res;
}
// int mulmod(int x,int y){
//     int res=0ll;
//     while(y>0){
//         if(y&1)res=(res+x)%mod;
//         x=(2*x)%mod;
//         y/=2ll;
//     }
//     return res%mod;
// }
// bool prime[1000001];
// int spf[2000005];
// int fact[1000001];
// // vector<int> p;
// void sieve(){
//     for(int i=2;i<2000005;i++){spf[i]=i;}
//     for (int i=2;i<2000005;i++){
//         if (spf[i]==i){  
//             // p.push_back(i);
//             for (int j=i*i;j<2000005;j+=i)
//                 spf[j]=i;
//         }
//     }
// }
// int phi(int n){
// 	//phi(p)=p-1;
// 	//phi(p^k)=(p^(k-1))(p-1);
// 	//phi(ab)=phi(a)*phi(b) if a and b are co-prime;
// 	//phi(ab)=phi(a)*phi(b)*(gcd(a,b))/(phi(gcd(a,b));
// 	//a^(phi(b)) is equivalent to 1 mod b if a and b are co-prime;
// 	int result=n;
// 	for(int i=2;i*i<=n;i++){
// 		if(n%i==0){
// 			while(n%i==0)
// 				n/=i;
// 			result-=(result)/i;
// 		}
// 	}
// 	if(n>1)
// 		result-=result/n;
// 	return result;
// }
// void bfs(vector<int> adj[],int src,int n,vector<int> &dist){
// 	priority_queue<iP,vector<iP>,greater<iP>> pq;
// 	pq.push({0,src});
// 	dist[src]=0;
// 	vector<bool> vis(n+1,false);
// 	while(!pq.empty()){
// 		int a=pq.top().second;
// 		pq.pop();
// 		if(vis[a])continue;
// 		vis[a]=1;
// 		for(auto it: adj[a]){
// 		    if(dist[it]>dist[a]+1){
// 				pq.push({dist[it],it});
// 				dist[it]=dist[a]+1;
// 		    }
// 		}
// 	}
// }
void dfs(vector<int> adj[],int x,vector<bool> &vis){
    vis[x]=1;
    for(auto it: adj[x]){
        if(!vis[it]){
            dfs(adj,it,vis);
        }
    }
}
int32_t main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);cout<<fixed;
    vector<int> arr({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;
    cin>>k;
    cout<<arr[k-1];
}


Measured memory_bytes: 256
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL; 																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																							   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////
	
int A, B, M;
int a[100005];
int b[100005];

int x[100005];
int y[100005];
int c[100005];

int ans = INF;
int mini_a = INF;
int mini_b = INF;

///////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////



/////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	cin >> A >> B >> M;
	for(int i = 1; i <= A; i++){
		cin >> a[i];
		mini_a = min(mini_a, a[i]);
	}
	for(int i = 1; i <= B; i++){
		cin >> b[i];
		mini_b = min(mini_b, b[i]);
	}
	for(int i = 1; i <= M; i++){
		cin >> x[i] >> y[i] >> c[i];
	}
	
	for(int i = 1; i <= M; i++){
		int wynik = a[x[i]] + b[y[i]] - c[i];
		//cout << "current wynik: " << wynik << endl;
		ans = min(ans, wynik);
	}
	
	int res = mini_a + mini_b;
	cout << min(ans, res) << endl;
	
	
	
	
	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#include <numeric>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define pb push_back
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<ll> > mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;
const int dx[9] = {-1, 0, 0, 1, -1, -1, 1, 1, 0};
const int dy[9] = {0, -1, 1, 0, -1, 1, -1, 1, 0};


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

  int ans = 0;
  REP(i,N) {
    int a;
    cin >> a;
    ans += a - 1;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MOD_VAL	1000000007

long long int modpow(long long int a, long long int n, long long int mod) {
  long long int res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

long long int modinv(long long int a) {
  return modpow(a, (long long int)(MOD_VAL - 2), (long long int)MOD_VAL);
}

long long int factorial_mod(long long int a)
{
  long long int ret = 1;
  while( a > 1 ) {
    ret = (ret * a) % (long long int)MOD_VAL;
    a--;
  }
  return ret;
}

long long int combination_mod(long long int n, long long int k)
{
  long long int bunbo, bunshi;
  bunshi = factorial_mod( n );
  bunbo = (factorial_mod( k ) * factorial_mod( n-k )) % (long long int)MOD_VAL;
  return (bunshi * modinv( bunbo )) % (long long int)MOD_VAL;
}

int main()
{
  int ret, X, Y;
  int n, m;
  ret = scanf("%d %d", &X, &Y);
  if ( (X + Y) % 3 != 0 ) {
    printf("0\n");
    return 0;
  }
  n = (2 * X - Y) / 3;
  m = (2 * Y - X) / 3;
  if ( n < 0 || m < 0 ) {
    printf("0\n");
    return 0;
  }
  printf("%lld\n", combination_mod( (long long int)(n + m), (long long int)n ));
}



Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
int main(void){
    ll n;cin>>n;
    vector<ll> A(n);
    REP(i,n)cin>>A[i];
    bool v[44000];REP(i,44000)v[i]=false;
    for(int bit=0;bit<(1<<n);bit++){
        ll sm=0;
        REP(i,n){
            if(bit&(1<<i))sm+=A[i];
        }
        v[sm]=true;
    }
    ll Q;cin>>Q;
    ll q[Q];
    REP(i,Q){
        cin>>q[i];
    }
    REP(i,Q){
        if(v[q[i]])cout<<"yes\n";
        else cout<<"no\n";
    }
}


Measured memory_bytes: 3128
#-------------------------------------------------------------------
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")
#-------------------------------------------------------------------

N = int(input()) #1行目のNを取得


A=[]
for i in range(N):
	sp = input().split()
	s,p=sp[0],sp[1]
	A.append([i+1,s,p])


B = sorted(A, key=lambda x: (x[1],int(x[2])*(-1)))

for l in B:
	print(l[0])



Measured memory_bytes: 38512
def lcs(s1, s2):
    dp = []
    for s2_k in s2:
        bgn_idx = 0
        for i, cur_idx in enumerate(dp):
            chr_idx = s1.find(s2_k, bgn_idx) + 1
            if not chr_idx:
                break
            dp[i] = min(cur_idx, chr_idx)
            bgn_idx = cur_idx
        else:
            chr_idx = s1.find(s2_k, bgn_idx) + 1
            if chr_idx:
                dp.append(chr_idx)
    return len(dp)


n = int(input())
for _ in range(n):
    x = input()
    y = input()
    print(lcs(x, y))



Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<char> S(4);
  cin >> S.at(0) >> S.at(1) >> S.at(2) >> S.at(3);
  
  if(S.at(0) == S.at(1) && S.at(2) == S.at(3) && S.at(0) != S.at(2)){
    cout << "Yes" << endl;
  }
  else if(S.at(0) == S.at(2) && S.at(1) == S.at(3) && S.at(0) != S.at(1)){
    cout << "Yes" << endl;
  }
  else if(S.at(0) == S.at(3) && S.at(1) == S.at(2) && S.at(0) != S.at(1)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define dforr(i, a, b) for(int i = (int)(b-1); i >= (a); i--)
#define dforn(i, n) dforr(i, 0, n)
#define db(v) cerr << #v << " = " << v << endl
#define pb push_back
#define sz(x) ((int)x.size())
#define ff first
#define ss second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
const int MAXN = -1;

ll lcm(ll a, ll b){ return a/__gcd(a, b)*b; }

ll n, m;
string S, T;
map<int, char> M;

int main(){
//	freopen("input.txt", "r", stdin);
	while(scanf("%lld %lld", &n, &m) >= 1){
        cin >> S >> T;
        ll t = lcm(n, m), tn = t/n, tm = t/m;
        bool win = true; M.clear();
        for(ll i = 0; i < t; i += tn)M[i] = S[i/tn];
        for(ll i = 0; i < t; i += tm){
            char c = T[i/tm];
            if(M.count(i) && M[i] != c)win = false;
            M[i] = c;
        }
        cout << (win ? t : -1) << endl;
    }
	return 0;
}


Measured memory_bytes: 8192
#include<stdio.h>
#include<stdlib.h>

typedef long long ll;

int max(int a, int b){
  if(a > b) return a;
  else return b;
}
int min(int a, int b){
  if(a < b) return a;
  else return b;
}

int sort(const void *a ,const void *b){
  return *(int*)a - *(int*)b;
}

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

int main(){

  int n,a[100001];
  scanf("%d",&n);

  for(int i = 0; i < n; ++i){
    scanf("%d",a+i);
  }

  qsort(a,n,sizeof(int),sort);

  int ans = a[0];
  for(int i = 1; i < n; ++i){
    ans = gcd(ans,a[i]);
  }

  printf("%d",ans);

  return 0;
}


Measured memory_bytes: 892
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

constexpr int MOD = 1000000007;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int main() {
    int N, A, B;
    string s;

    cin >> N >> A >> B >> s;

    int a = 0, b = 0;
    for (int j = 0; j < N; ++j) {
        if (s[j] == 'a') {
            if (a + b < A + B) {
                ++a;
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        } else if (s[j] == 'b') {
            if (a + b < A + B && b < B) {
                ++b;
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <algorithm>
#define maxn 200010
using namespace std;
int f[maxn],cnt[maxn];
int getf(int u){
	return f[u]==u?u:f[u]=getf(f[u]);
}
void merge(int u,int v){
	int f1,f2;
	f1=getf(u),f2=getf(v);
	if(f1!=f2)f[f2]=f1;
}
int main(){
	int n,m,i,u,v,mx=0;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)f[i]=i;
	for(i=1;i<=m;i++)scanf("%d%d",&u,&v),merge(u,v);
	for(i=1;i<=n;i++)cnt[getf(i)]++;
	for(i=1;i<=n;i++)mx=max(mx,cnt[i]);
	printf("%d\n",mx);	
	return 0;
}

Measured memory_bytes: 3176
#! /usr/bin/env ruby

s = gets.chomp
op = ['+', '-']

op.each do |op1|
  op.each do |op2|
    op.each do |op3|
      exp = s[0] + op1 + s[1] + op2 + s[2] + op3 + s[3]
      if eval(exp) == 7
        puts exp + '=7'
        exit 0
      end
    end
  end
end


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

ll d[1000][1000];
int main(){
	int n,m;scanf("%d%d",&n,&m);
	rep(i,n)rep(j,n){
		if(i==j)d[i][j]=0;
		else d[i][j]=LLONG_MIN/2;
	}
	rep(i,m){
		int a,b,c;scanf("%d%d%d",&a,&b,&c);a--;b--;
		d[a][b]=c;
	}
	rep(k,n)rep(i,n)rep(j,n)d[i][j]=max(d[i][j],d[i][k]+d[k][j]);
	if(d[0][0]>0)puts("inf");
	else printf("%lld\n",d[0][n-1]);
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
template<typename tn> void read(tn &a){
    tn x=0,f=1;char c=' ';
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar() ) x=x*10+c-'0';
    a=x*f;
}
template<typename tn> void print(tn a){
    if(a<0) putchar('-'),a=-a;
    if(a>9) print(a/10);
    putchar(a%10+'0');
}
int n;
int v[1000005];
long double ans;
int main(){
	read(n);
	for(int i=1;i<=n;i++)
	    read(v[i]);
	sort(v+1,v+n+1);
	ans=v[1];
	for(int i=2;i<=n;i++)
	    ans=(ans+v[i])/2;
	printf("%Lf\n",ans);
	return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()
S2 = input()

if N == 1:
	print(3)
	sys.exit()
else:
	tmp = ""
	if S[0] == S[1]:
		ans = 6
		mode = 2
	else:
		ans = 3
		mode = 1
	tmp = S[0]
	for i in range(1, N):
		if S[i] == tmp:  # 前と同じ
			mode = 2
		else:  # 切り替わり
			if i != N-1 and S[i] == S[i+1]:
				if mode == 1:
					ans = (ans*2)%mod
				elif mode == 2:
					ans = (ans*3)%mod
			else:
				if mode == 1:
					ans = (ans*2)%mod
				elif mode == 2:
					pass
			mode = 1

		tmp = S[i]

print(ans)


Measured memory_bytes: 5148
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ll long long int
#define INF INT_MAX
#define mod
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b){return (a.second < b.second);}
ll gcd(ll a, ll b){if(a==0)return b;return gcd(b % a, a);}
int main()
{
	chutiyaap;
	ll n;cin>>n;
	string s,t;cin>>s>>t;
	for(ll i=0;i<n;i++)cout<<s[i]<<t[i];
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())

int main()
{
    int n;
    cin >> n;

    vector<int64_t> arr(n);
    rep(i,n){
      int64_t a;
      cin >> a;
      arr.at(i) = a;
    }

    srt(arr);

    int64_t ans = 1;
    rep(i,n){
      int64_t a = arr.at(i);

      if(a==0) {
        ans=0;
        break;
      }
      
      if(ans > 1000000000000000000/a){
        ans = -1;
        break;
      }
      ans *= a;

    }

    cout << ans << endl;
}


Measured memory_bytes: 4056
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define int  long long
#define ll long long
#define pb push_back 
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl;
#define mod 1000000007
#define mod1 998244353
#define INT_MAX1 900000000


void solve()
{
    int n;
    cin >> n;

    string s[n];
    int t[n];
    rep(i,0,n-1)
        cin >> s[i] >> t[i];
    int ans = 0;
    bool x = 0;
    string xx;
    cin >> xx;
    rep(i,0,n-1)
    {
        if(x)
            ans += t[i];
       if(s[i]==xx)
        x = 1;
    }

    cout << ans << endl;

}

signed main()
{
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

Measured memory_bytes: 256
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
const int INF = 1e9+7;

int main(int argc, char **argv)
{
	int H, W, i, j;
	for (;;) {
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0) break;
		for (i = 0; i < H; i++) {
			for (j = 0; j < W; j++) {
				putchar('#');
			}
			putchar('\n');
		}
		putchar('\n');
	}

	return 0;
}

Measured memory_bytes: 572
import java.util.*;
public class Main {
    static int MOD = 1000000007;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		//Long tmp = sc.nextLong();
      int output = 0;
      int N = sc.nextInt();
      int M = sc.nextInt();
      if(Math.abs(N - M) >= 2){
        System.out.println(output);
      }else if(Math.abs(N - M) == 1){
        System.out.println((fact(N) * fact(M)) % MOD);
      }else{
        //最後に2倍
        //System.out.println(fact(N));
        //System.out.println(fact(M));
        System.out.println(((fact(N) * fact(M)) % MOD) * 2 % MOD);
      }
	}
  
  public static Long fact(int a){
    Long ret = new Long(1);
    for(int i = 1; i <= a; i++){
      ret = (ret * i) % MOD;
    }
    return ret;
  }
}


Measured memory_bytes: 27092
from collections import deque, Counter
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7


def main():
    # N = int(input())
    N, K = [int(a) for a in input().split()]

    ts = [0] * (K + 1)
    for k in reversed(range(1, K + 1)):
        m = K // k
        ts[k] = pow(m, N, M)
        for k2 in range(k * 2, K + 1, k):
            ts[k] -= ts[k2]
        ts[k] = ts[k] % M
    print(sum([a * i for i, a in enumerate(ts)]) % M)


if __name__ == "__main__":
    main()


Measured memory_bytes: 16132
#include <stdio.h>

int main(void) {
	static const int gaku[6]={1,5,10,50,100,500};
	int sum=0;
	int i;
	for(i=0;i<6;i++) {
		int c;
		if(scanf("%d",&c)!=1)return 1;
		sum+=gaku[i]*c;
	}
	puts(sum>=1000?"1":"0");
	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <cmath>

#define mst(a,b)memset(a, b, sizeof(a))
#define repi(a,b)for(int i = a; i < b; i++)
#define repj(a,b)for(int j = a; j < b; j++)
#define pii pair<int,int>

#ifdef LOCAL
#define fre()freopen("in.txt","r",stdin)
#endif
#ifndef LOCAL
#define fre()
#endif

//static int x = []() {
//	std::ios::sync_with_stdio(false);
//	std::cin.tie(NULL);
//	return 0;
//}();

#define FASTIO
#ifdef FASTIO
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//#define scanf abcabc
//#define printf abcabc
#endif
//#ifndef FASTIO
//#define cin abcabc
//#define cout abcabc
//#endif

typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;

using namespace std;


const int mod = 1e9 + 7;
ll dp[2010][2010], a[2010], b[2010];
int main() {
	int n, m;
	cin >> n >> m;
	repi(0, n)cin >> a[i];
	repi(0, m)cin >> b[i];
	repi(0, n + 1)dp[i][0] = 1;
	repi(0, m + 1)dp[0][i] = 1;
	repi(1, n + 1)
		repj(1, m + 1) {
		//dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + mod) % mod;
		//if (a[i - 1] == b[j - 1])dp[i][j] = (dp[i - 1][j - 1] + dp[i][j]) % mod;
		dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
		if (a[i - 1] != b[j - 1])dp[i][j] -= dp[i - 1][j - 1];
		dp[i][j] = (dp[i][j] + mod) % mod;
	}
	cout << dp[n][m] << endl;
	return 0;
}

Measured memory_bytes: 31744
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val a = hashSetOf<Int>()
    (0 until m).forEach { a.add(sc.next().toInt()) }
    println(problem129c(n, m, a))
}

fun problem129c(n: Int, m: Int, a: HashSet<Int>): Long {
    val mod: Long = (Math.pow(10.0, 9.0) + 7).toLong()
    val dp = LongArray(n + 1) { 0 }
    dp[0] = 1
    dp[1] = 1
    for (i in 2..n) {
        dp[i] += when {
            a.contains(i - 1) && a.contains(i - 2) -> {
                return 0
            }
            a.contains(i) -> {
                dp[i - 1]
            }
            a.contains(i - 1) || a.contains(i - 2) -> {
                dp[i - 1]
            }
            else -> {
                dp[i - 1] + dp[i - 2]
            }
        }
        dp[i] = dp[i] % mod
    }
    return dp[n]
}

Measured memory_bytes: 51920