akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = input()

ans = 1

s = 0
for i in range(N):
    p = 1
    if i > 0 and A[i] == A[i-1]:
        continue
    elif i+1 < N and A[i] == A[i+1]:
        p = [6, 3, 2][s]
        s = 1
    else:
        p = [3, 1, 2][s]
        s = 2
    ans = (ans * p) % (int(1e9) + 7)

print(ans)


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

class Main {

    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        int N;
        N = sc.nextInt();
        String S;
        S = sc.next();
        solve(N, S);
    }

    static void solve(int N, String S) {
        int ans = 0;
        for (int i = 0; i < N; i++) {
            int[] z = Z(S.substring(i));
            for (int j = i; j < N; j++) {
                ans = Math.max(ans, Math.min(j - i, z[j - i]));
            }
        }
        System.out.println(ans);

    }

    static int[] search(String S1, String S2) {
        return Z(S1 + "$" + S2);
    }

    static int[] Z(String S) {
        int l = 0;
        int r = 0;
        int[] Z = new int[S.length()];

        for (int i = 1; i < S.length(); i++) {
            if (r < i) {
                l = r = i;
                while (r < S.length() && S.charAt(r) == S.charAt(r - l)) {
                    r++;
                }
                Z[i] = r - i;
                r--;
            } else {
                int k = i - l;
                if (i + Z[k] - 1 < r) {
                    Z[i] = Z[k];
                } else {
                    l = i;
                    while (r < S.length() && S.charAt(r) == S.charAt(r - l)) {
                        r++;
                    }
                    Z[i] = r - i;
                    r--;
                }
            }
        }
        return Z;
    }
}


Measured memory_bytes: 46872
#include <iostream>

using namespace std;

int main()
{
    int m,n;
    cin>>m>>n;
    if(m>n)
    {
        for(int i=0;i<m;i++)
            cout<<n;
    }
    else if(n>m)
    {
         for(int i=0;i<n;i++)
            cout<<m;
    }
    else
    {
        for(int i=0;i<n;i++)
            cout<<n;
    }
}


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

int main(){
	int n;cin>>n;
	if(n<1200){
		cout<<"ABC"<<endl;
	}else if(n<2800){
		cout<<"ARC"<<endl;
	}else{
		cout<<"AGC"<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<limits.h>
#include<string>

using namespace std;


long max(long x, long y) {
	return x > y ? x : y;
}

long min(long x, long y) {
	return x < y ? x : y;
}


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

	
	if (n % 2 == 0 && s.substr(0,n/2)==s.substr(n/2,n/2)) {
		cout << "Yes";
	}
	else{
		cout<<"No";
	}
}

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

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<vector<bool>> dp(n + 1, vector<bool>(10001));
  dp[0][0] = true;
  for (int i = 0; i < n; i++)
  {
    int s;
    cin >> s;
    for (int j = 0; j <= 10000; j++)
      if (dp[i][j])
      {
        dp[i + 1][j] = true;
        dp[i + 1][j + s] = true;
      }
  }
  int ans = 0;
  for (int i = 0; i <= 10000; i++)
    if (dp[n][i] && i % 10 != 0)
      ans = i;
  cout << ans << endl;

  return 0;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

template<typename T>
static inline void chmin(T& ref, const T  value) {
	if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T& ref, const T value) {
	if (ref < value) ref = value;
}


struct BIT {
	vector<ll> bit_;
	const ll n_;

	BIT(ll n) :n_(n) {
		bit_.resize(n + 1LL, 0);
	}

	ll sum(int i) {
		ll s = 0;
		while (i > 0) {
			s += bit_[i];
			i -= i & (-i);
		}
		return s;
	}

	void add(int i, ll x) {
		while (i <= n_) {
			bit_[i] += x;
			i += (i & (-i));
		}
	}
};

int main() {
	ll n, q;
	cin >> n >> q;
	vector<int> prev(n+1, -1);
	vector<int> cols(n+1, -1);
	rep(i, n) {
		int c;
		cin >> c;
		prev[i] = cols[c];
		cols[c] = i;
	}
	vector<vector<P>> rs(n);
	rep(i, q) {
		int left, right;
		cin >> left >> right;
		left--;
		right--;
		rs[right].emplace_back(left, i);
	}
	BIT b(n+1);
	vector<int> ans(q);
	rep(i, n) {
		auto p = prev[i];
		if (p >= 0) {
			b.add(p+1, -1);
			b.add(i+1, 1);
		}
		else {
			b.add(i+1, 1);
		}
		for (auto f : rs[i]) {
			auto left = f.first;
			auto d = b.sum(i + 1) - b.sum(left);
			ans[f.second] = d;
		}
	}
	for (auto p : ans) {
		cout << p << endl;
	}
	return 0;
}


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

int main(void){
	int n;
	double y;
	int ansb=0;
	int b[101],t[101],r[101];
	double ans[101];
	while(1){ 
		double res=0;
		scanf("%d",&n);
		if(n==0)break;
		scanf("%lf",&y);
		for(int a=0;a<n;a++){
			scanf("%d%d%d",&b[a],&r[a],&t[a]);
			if(t[a]==1)ans[a]=(double)r[a]*y*0.01+1;
			if(t[a]==2)ans[a]=pow(1+r[a]*0.01,y);
			if(ans[a]>res)ansb=b[a],res=ans[a];
		}
		printf("%d\n",ansb);
	}
    return 0;
}

Measured memory_bytes: 0
'use strict';

waterfall([
  function(next) {
    lineReader(1, next);
  }, function(line, next) {
    solve(line[0], next);
  }], function(sum, result) {
    console.log(sum);
    console.log(result.reduce(function(memo, s) {
      memo.push(s.area);
      return memo;
    }, [result.length]).join(' '));
    process.exit(0);
  });

function solve(line, cb) {
  var stack = [];
  var result = [];
  var sum = 0;
  strMap(line, function(c, i) {
    if (c === '\\') {
      stack.push(i);
      return;
    }
    if (c === '/') {
      var s = stack.pop();
      if (s !== 0 && !s) return;

      sum += i - s;
      var tmp = i - s;
      while(result.length > 0 && result[result.length - 1].left > s) {
        tmp += result[result.length - 1].area;
        result.pop();
      }

      result.push({left: s, area: tmp});
    }
  });
  cb(sum, result);
}

function strMap(str, map) {
  var newStr = '';
  for (var i = 0; i < str.length; i++) {
    newStr += map(str.charAt(i), i);
  }
  return newStr;
}

function lineReader(limit, cb) {
  var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
  });
  var lines = [];
  var counter = 0;
  reader.on('line', function(line) {
    lines.push(line);
    ++counter;
    if (counter === limit) {
      reader.close();
      return cb(lines);
    }
  });
  reader.on('close', function() {});
  reader.on('error', function(err) {
    cb(err);
  });
}

function waterfall(tasks, cb) {
  var taskIndex = 0;
  function nextTask(args) {
    if (taskIndex === tasks.length)
      return cb.apply(null, args);

    var taskCallback = function() {
      var _arguments = arguments;
      nextTask(Object.keys(_arguments).reduce(function(memo, key) {
        memo.push(_arguments[key]);
        return memo;
      }, []));
    };
    args.push(taskCallback);
    var task = tasks[taskIndex++];
    task.apply(null, args);
  }
  nextTask([]);
}

Measured memory_bytes: 19356
using System;
using System.Collections.Generic;
class Program
{
    //static List<string> str = new List<string>();
    static void Main(string[] args)
    {
        // 入力
        //string[] input = Console.ReadLine().Split(' ');
        string S = Console.ReadLine();
        int N = S.Length;

        S = S.Replace("1", string.Empty);

        //while(true)
        //{
        //    string tempS = S;
        //    S = S.Replace("01", "");
        //    S = S.Replace("10", "");

        //    if (tempS == S)
        //        break;
        //}
        int oneNum = S.Length;
        int zeroNum = N - oneNum;
        int ret = Math.Min(oneNum, zeroNum) * 2;
        Console.WriteLine(ret);
    }
}

Measured memory_bytes: 13536
#include <iostream>
#include <string>
using namespace std;
int main() {
	int H, W, i;
	char c;
	string row;
	while (true) {
		row = "";
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		else if (W % 2 == 0)c = '.';
		else c = '#';
		for (i = 0; i < W-1; i++) {
			if (i % 2 == 0)row += '#';
			else row += '.';
		}
		for (i = 0; i < H;i ++) {
			if (i % 2 == 0)cout << row << c << endl;
			else cout << '.' << row << endl;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int x;
  cin >> x;
  cout << x * x * x << endl;
}



Measured memory_bytes: 3140
#include<iostream>
#include<queue>
using namespace std;
class com{
    public:bool operator()(const pair<int,int>p1,const pair<int,int>p2){
        return p1.first==p2.first?p1.second>p2.second:p1.first<p2.first;
    }
};
int main(){
    int p[1000001]={0};
    int n,q,a,v;
    priority_queue<pair<int,int>,vector<pair<int,int> >,com>que;
    cin>>n>>q;
    while(q--){
        cin>>a>>v;
        p[a]+=v;
        que.push(make_pair(p[a],a));
        while(que.top().first!=p[que.top().second])que.pop();
        cout<<que.top().second<<" "<<que.top().first<<endl;
    }
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define SORT(arr) sort(arr, arr + ARRAY_LENGTH(arr))

int N;
int main(){
	cin >> N;
	int a[N];
	for(int i=0;i<N;i++){
		cin >> a[i];
	}
	SORT(a);
	int bench;
	if(N%2 == 0)bench = 1;
	else bench = 0;
	int asum=0,bsum=0;
	for(int i=N-1;i>=0;i--){
		if(i%2 == bench) asum+=a[i];
		else bsum+=a[i];
	}
	cout << asum - bsum << endl;
	return 0;
}


Measured memory_bytes: 256
x = list(input())
for i in range(2**3):
  a = []
  for j in range(3):
    if (i >> j) & 1:
      a.append('+')
    else:
      a.append('-')
  b = x[0]+a[0]+x[1]+a[1]+x[2]+a[2]+x[3]
  if eval(b) == 7:
    print(b+'=7')
    break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////


void solve() {
	int a, b; cin >> a >> b;
	cout << a * (a - 1) / 2 + b * (b - 1) / 2 << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



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

int main(){
  int n,m; cin >> n >> m;
  vector<int> k(n);
  vector<vector<int>> a(n,vector<int>(m,0));
  vector<vector<int>> flag(n,vector<int>(m,0));
  for(int i=0; i<n; i++){
    cin >> k[i];
    for(int j=0; j<k[i]; j++){
      cin >> a[i][j];
      flag[i][a[i][j]-1]=1;
    }
  }
  
  int count=0;
  for(int j=0; j<m; j++){
    int product=1;
    for(int i=0; i<n; i++){
      product*=flag[i][j];    
    }
    if(product==1) count++;
    else continue;
  }  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int n;
    cin >> n;
    vector<P> a(n);
    rep(i,n) cin >> a[i].second >> a[i].first;
    sort(a.begin(),a.end());
    ll time = 0;
    bool ok = true;
    rep(i,n){
        if(time + a[i].second > a[i].first){
            ok = false;
            break;
        }else{
            time += a[i].second;
        }
    }
    cout << (ok? "Yes" : "No") << endl;
}

Measured memory_bytes: 1792
import copy
h,w,k = map(int,input().split())
c = [list(input()) for i in range(h)]
count = 0
for i in range(2**h):
    for j in range(2**w):
        d = copy.deepcopy(c)
        for t in range(h):
            if (i >> t) & 1: 
                for q in range(w):
                    d[t][q] = "x"
        for t in range(w):
            if (j >> t) & 1: 
                for q in range(h):
                    d[q][t] = "x"
        ci = 0
        for m in d:
            ci += m.count("#")
        if ci == k:
            count += 1

print(count)


Measured memory_bytes: 9340
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <set>
#include <cstdio>
using namespace std;

typedef long long ll;
typedef pair<int,int> P1;
typedef pair<int,P1> P2;
const int inf=1000000000;
struct edge{
	int to,cost;
};

int main() {
	ll a,b,c;
	cin>>a>>b>>c;
	ll t=(a%2)*b*c;
	t=min(t,(b%2)*a*c);
	t=min(t,(c%2)*a*b);

	cout<<t<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;++i)
#define per(i,a,b) for(int i=(b),i##_st=(a);i>=i##_st;--i)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define dbg(x) cerr<<#x" = "<<x<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define Es(x,i) for(Edge *i=G[x];i;i=i->nxt)
typedef long long ll;
typedef pair<int,int> pii;
const int inf=~0u>>1,MOD=1e9+7;
inline int rd() {
    int x,c,f=1;while(!isdigit(c=getchar()))f=c!='-';x=c-'0';
    while(isdigit(c=getchar()))x=x*10+c-'0';return f?x:-x;
}
const int N=1e5+11;
struct Edge{int v;Edge*nxt;}pl[N<<1],*cur=pl,*G[N];
inline void ins(int u,int v){*cur=(Edge){v,G[u]},G[u]=cur++;}
int n,d[N],q[N];
void dfs(int x,int f=-1){
	int sz=0;
	Es(x,i)if(i->v!=f){
		sz+=d[i->v]==1;
		dfs(i->v,x);
	}
	if(sz>1)puts("First"),exit(0);
	else if(sz==1){
		q[x]=1;
	}
}
int main(){
#ifdef flukehn
	freopen("test.txt","r",stdin);
#endif
	n=rd();
	if(n&1)puts("First"),exit(0);
	For(i,1,n){
		int u=rd(),v=rd();
		ins(u,v),ins(v,u);
		d[u]++,d[v]++;
	}
	rep(i,1,n)if(d[i]!=1){
		dfs(i);break;
	}
	rep(i,1,n)if(!q[i]&&d[i]>=2){
		int f=1;
		Es(i,j)f&=q[j->v];
		if(f)puts("First"),exit(0);
	}
	puts("Second");
}

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

int main(void){

    int i,j;
    int N;
    int *C;
    int *V;
    int diff;
    int max=0;

    scanf("%d",&N);
    C=malloc(sizeof(int)*N);
    V=malloc(sizeof(int)*N);

    for(i=0;i<N;i++){
        scanf("%d ",&V[i]);
    }
    for(i=0;i<N;i++){
        scanf("%d ",&C[i]);
        diff=V[i]-C[i];
        if(diff>0){
            max+=diff;
        }  
    }
    printf("%d",max);
    return 0;
}


Measured memory_bytes: 128
from fractions import gcd 
a,b,c,d=map(int,input().split())

cc=b//c-(a-1)//c
dd=b//d-(a-1)//d

f=(c*d)//gcd(c,d)

dup=b//f-(a-1)//f

ans=b-(a-1)-(cc+dd-dup)

print(ans)


Measured memory_bytes: 5048
def f(v, i):
    s = 4 * 2 ** v - 3
    n = 2 * 2 ** v - 1
    m = (s + 1) / 2
    if i < 1 or i > s: return 0
    return [0, f(v - 1, i - 1), n / 2 + 1, f(v - 1, i - s / 2 - 1) + n / 2 + 1, n, 1][(i > 1) + (i >= m) + (i > m) + (i >= s) + (v == 0) * 3]

print f(*map(int, raw_input().split()))

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

int main(void){
	string s, t;
	cin >> s >> t;
	int n=s.size(), l=t.size();
	for(int i=n-l; i>=0; i--){
		for(int j=0; j<l; j++){
			if(s[i+j]!=t[j] && s[i+j]!='?') j=l;
			if(j==l-1){
				for(int k=0; k<i; k++){
					if(s[k]=='?') cout << 'a';
					else cout << s[k];
				}
				cout << t;
				for(int k=i+l; k<n; k++){
					if(s[k]=='?') cout << 'a';
					else cout << s[k];
				}
				return 0;
			}
		}
	}
	cout << "UNRESTORABLE" << endl;
}

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

int v[1000000], N;

int search(int key){
    int l = 0, r = N;

    while (l < r){
        int mid = (r+l) / 2;
        if(v[mid] == key){
            return 1;
        }
        if(v[mid] > key){
            r = mid;
        } else if(v[mid] < key) {
            l = mid+1;
        }
    }
    return 0;
}

int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int Q,ans=0;
    cin >> N;
    rep(i, N) cin >> v[i];
    cin >> Q;

    for (int i = 0; i < Q; i++){
        int key;
        cin >> key;
        if(search(key)) ans++;
    }

    cout << ans << endl;
}



Measured memory_bytes: 3456
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int n,a[200005];
inline bool check(const int &k)
{
	if((a[n-1]<=k&&a[n]<=k)||(a[n]<=k&&a[n+1]<=k))return 1;
	if((a[n-1]> k&&a[n]> k)||(a[n]> k&&a[n+1]> k))return 0;
	for(int i=1;i<n-1;i++)
    {
		if((a[n+i]<=k&&a[n+i+1]<=k)||(a[n-i]<=k&&a[n-i-1]<=k))return 1;
		if((a[n+i]> k&&a[n+i+1]> k)||(a[n-i]> k&&a[n-i-1]> k))return 0;
	}
	return a[1]<=k;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n<<1;i++)scanf("%d",a+i);
	int l=1,r=(n<<1)-1;
	while(l<r)
    {
		int mid=l+r>>1;
		if(check(mid))r=mid;
		else l=mid+1;
	}
	printf("%d",l);
}
/*
我知道，我会，这是套路，二分变01。
然后陷入了沉默
30min之后看了眼sol
？？？？？
真就打表大胜利啊？
 
*/ 

Measured memory_bytes: 4576
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
using namespace std;

string key,s,ans="no such property";
vector<pair<string,int> > yaml;
vector<string> k;

void dfs(int index,int indent,int s,int t){
  if(k.size()==index){
    ans="object";
    return;
  }
  for(int i=s;i<t;i++){
    string subs="";
    for(int j=indent;j<yaml[i].f.size();j++){
      if(yaml[i].f[j]==':')break;
      if(yaml[i].f[j]==' ')break;
      subs+=yaml[i].f[j];
    }
    if(k[index]!=subs)continue;
    if(yaml[i].f[yaml[i].f.length()-1]!=':'){
      if(index==k.size()-1){
	ans="string \"";
	for(int j=indent;j<yaml[i].f.length();j++){
	  if(yaml[i].f[j]==' '){
	    ans+=yaml[i].f.substr(j+1,yaml[i].f.length()-j);
	    break;
	  }
	}
	ans+="\"";
      }
      return;
    }
    int last=i+1,k;
    for(int j=i+1;j<yaml.size();j++){
      if(indent>=yaml[j].s)break;
      last=j;
    }
    dfs(index+1,yaml[i+1].s,i+1,last+1);
  }
}


int main()
{ 
  getline(cin,key);
  while(getline(cin,s)){
    int c=0;
    for(int i=0;i<s.length();i++){
      if(s[i]!=' ')break;
      c++;
    }
    yaml.push_back(mp(s,c));
  }

  int start=1;
  key+='.';
  for(int i=1;i<key.size();i++){
    if(key[i]=='.'){
      k.push_back(key.substr(start,i-start));
      start=i+1;
    }
  }

  dfs(0,0,0,yaml.size());

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 1328
#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a)

    ball_dict = {}
    count = 1
    for i in range(1, n):
        if a_sort[i] == a_sort[i - 1]:
            count += 1
        else:
            ball_dict.setdefault(a_sort[i - 1], count)
            count = 1
    ball_dict.setdefault(a_sort[n - 1], count)

    ans = 0
    for v in ball_dict.values():
        ans += v * (v - 1) // 2

    ans_dict = {}
    for v in ball_dict.values():
        if v not in ans_dict:
            ans_dict.setdefault(v, ans - (v - 1))

    for i in range(n):
        print(ans_dict[ball_dict[a[i]]])

if __name__ == '__main__':
    main()


Measured memory_bytes: 26200
using System;
using System.Collections.Generic;
using System.Linq;

class A
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		var n = h[0];

		var r = new List<int>();
		var uf = new UF(n);

		for (int i = 0; i < h[1]; i++)
		{
			var q = Read();
			if (q[0] == 0)
				uf.Unite(q[1], q[2]);
			else
				r.Add(uf.AreUnited(q[1], q[2]) ? 1 : 0);
		}
		Console.WriteLine(string.Join("\n", r));
	}
}

class UF
{
	int[] p;
	public UF(int n) { p = Enumerable.Range(0, n).ToArray(); }

	public void Unite(int a, int b) { if (!AreUnited(a, b)) p[p[b]] = p[a]; }
	public bool AreUnited(int a, int b) => GetRoot(a) == GetRoot(b);
	public int GetRoot(int a) => p[a] == a ? a : p[a] = GetRoot(p[a]);
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

signed main() {
  int N = read();
  int ans = 0;
  REP(i, N) { ans += read() - 1; }
  print(ans);
}


Measured memory_bytes: 256
A, B, K = map(int, input().split())

divider_A = set()
divider_B = set()

for i in range(1, A+1):
  if A % i == 0:
    divider_A.add(i)

for i in range(1, B+1):
  if B % i == 0:
    divider_B.add(i)

print(sorted(divider_A & divider_B, reverse=True)[K-1])

Measured memory_bytes: 3060
# input
N, M = map(int, input().split())
edge_lst = [list(map(int, input().split())) for i in range(M)]

adj_matrix = {} # グラフを辺列挙 -> 隣接行列に変換
for i in range(1, N + 1):
    adj_lst = []
    for j in range(M):
        if edge_lst[j][0] == i:
            adj_lst.append(edge_lst[j][1])
        if edge_lst[j][1] == i:
            adj_lst.append(edge_lst[j][0])
    adj_matrix[i] = adj_lst

# root: 葉を探索中の根
# next: 次に探索される葉
# count: 探索回数
# order[1,...,N]: 頂点iが探索された順番
# low[1,...,N]: 頂点iから訪問可能な頂点のうち、最も上にある頂点の探索順

def dfs_bridge(graph, root, next, count, low, order, bridges): # graphは隣接行列表示
    count += 1
    order[next] = count
    low[next] = order[next]

    for w in graph[next]: # vと隣接している頂点
        if order[w] == -1: # wは未訪問
            dfs_bridge(graph, next, w, count, low, order, bridges)

            low[next] = min(low[next], low[w])
            if low[w] == order[w]: # 頂点w以降から頂点v以前に戻れない
                bridges.append((next, w))
        elif w != root: # 一つ前の頂点（自明に戻れる頂点）より前に戻れる場合
            low[next] = min(low[next], order[w])

def get_bridges(graph):
    bridges = []
    count = 0
    low = {n: -1 for n in graph.keys()}
    order = low.copy()

    for n in graph.keys():
        dfs_bridge(graph, n, n, count, low, order, bridges)
    
    return(bridges) # 橋 = (node, node)のタプルのリスト
            
ans = get_bridges(adj_matrix)
print(len(ans))

Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
	int h;
	int m;
	int s;
	int watch;

	scanf("%d", &watch);

	h = watch / 3600;
	m = (watch % 3600) / 60;
	s = watch % 3600 % 60;

	printf("%d:%d:%d\n", h, m, s);

	return 0;
}

Measured memory_bytes: 592
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
    String S = sc.nextLine();
    String T = sc.nextLine();
    int maxcnt = 1000;
    for(int i=0; i<=S.length()-T.length(); i++){
      int cnt = 0;
      for(int j=0; j<T.length(); j++){
        if(T.charAt(j) != S.charAt(i+j)){
          cnt++;
        }
      }
        if(cnt<=maxcnt) {
          maxcnt=cnt;
        }
    }
    System.out.println(maxcnt);
  }
}

Measured memory_bytes: 35844
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////

	
int main() {

	ll N;
	cin >> N;

	ll a[MAX];
	repn(i, N) cin >> a[i];

	ll ans = 0;
	repn(i, N) {
		while (a[i] % 2 == 0) {
			ans++;
			a[i] /= 2;
		}
	}

	cout << ans;
	
	

	
	system("PAUSE");
}

Measured memory_bytes: 2552
import java.util.Scanner;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String[] inp = sc.nextLine().split(" ");
        long t = Long.parseLong(inp[0]);
        long a = Long.parseLong(inp[1]);
        long k = Long.parseLong(inp[2]);
        long tmp = 0;
        tmp = k - t;
        t = t - k;
        if(t < 0) {
            t = 0;
            k = tmp;
            a = a - k;
            if(a < 0) {
                a = 0;
            }
        }
        System.out.println(t + " " + a);
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
vector<pair<int,int>> A;
ll memo[2000][2000];
bool visited[2000][2000];
ll f(int p, int q) {
	if (p == N) return 0;
	if (visited[p][q]) return memo[p][q];
	visited[p][q] = true;
	ll Ax = A[p].first;
	int x = A[p].second;
	ll r1 = f(p+1, q+1) + Ax * abs(x-q);
	int y = N-1-(p-q);
	ll r2 = f(p+1, q) + Ax * abs(x-y);
	return memo[p][q] = max(r1, r2);
}
int main() {
	cin >> N;
	for (int i = 0; i < N; ++ i) {
		int ai;
		cin >> ai;
		A.push_back({ai, i});
	}
	sort(A.rbegin(), A.rend());
	cout << f(0, 0) << endl;
}

Measured memory_bytes: 30372
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;

int main(){
    string s,t;
    cin>>s>>t;
    int cnt=0;
    for(int i=0;i<s.length();i++){
        if(s[i]!=t[i]){
            cnt++;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3464
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b,c,d,e,k;
    cin >> a>>b>>c>>d>>e>>k;
    if(e-a<=k){
      cout<<"Yay!"<<endl;
    }else{
      cout<<":("<<endl;
    }
}

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

int main(){
    int a, b, c, x, count=0;
    cin >> a >> b >> c;

    for (x=a;x<=b;x++){
        if(c%x == 0){
            count++;
        }
    }

    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 3108
H,W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
l = []
for color,m in enumerate(a,1):
    l += [color]*m
for i in range(H):
    k = l[:W]
    l = l[W:]
    if i%2 != 0:
        k.reverse()
    print(*k)

Measured memory_bytes: 3920
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N, K, S;
    cin >> N >> K >> S;
    rep(0, i, K)
    {
        cout << S << ' ';
    }
    rep(0, i, N - K)
    {
        if (S == 1000000000)
        {
            cout << 1 << ' ';
        }
        else
        {
            cout << S + 1 << ' ';
        }
    }
    cout << endl;
}

Measured memory_bytes: 3620
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#define maxn 100003
using namespace std;

int main(){
    int a,b,c,x,y;
    int ans=0;
    cin >> a >> b >> c >> x >> y;
    if(2*c >= (a+b)){
        ans = a*x+b*y;
    }else{
        while(x>0 && y>0){
            ans+=2*c;
            x--;
            y--;
        }
        while(y > 0){
            if(2*c < b) ans += 2*c;
            else ans += b;
            y--;
        }
        while(x > 0){
            if(2*c < a) ans += 2*c;
            else ans += a;
            x--;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
import os
import re
import sys
from collections import defaultdict

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())


def is_ok(s):
    ok = True
    for ng in ['AGC', 'GAC', 'ACG']:
        ok &= ng not in s
    ok &= not re.match(r'A.GC', s)
    ok &= not re.match(r'AG.C', s)
    return ok


# 最後が s である文字の数
dp = [defaultdict(int) for _ in range(N)]
for c in 'AGCT':
    for d in 'AGCT':
        for e in 'AGCT':
            if is_ok(c + d + e):
                dp[2][c + d + e] = 1

for i in range(3, N):
    for k in dp[i - 1].keys():
        for c in 'AGCT':
            if is_ok(k + c):
                dp[i][k[-2:] + c] += dp[i - 1][k]
                dp[i][k[-2:] + c] %= MOD

print(sum(dp[-1].values()) % MOD)


Measured memory_bytes: 4340
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program {
    static void Main(string[] args) {
        //入力
        int N = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();

        int[] L = new int[2 * N];

        for (int i = 0; i < 2 * N; i++) {
            L[i] = int.Parse(s.Split(' ')[i]);
        }

        //並び替え
        Array.Sort(L);

        //回答用変数
        int ans = 0;

        //検証
        for (int i = 0; i < 2 * N; i = i + 2) {
            ans += Math.Min(L[i], L[i + 1]);
        }

        //出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    int64_t x;
    mint(int64_t x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(int64_t t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    //for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> frac, ifrac;
    combination(int n):frac(n+1), ifrac(n+1) {
        assert(n < mod);
        frac[0] = 1;
        for (int i = 1; i <= n; ++i) frac[i] = frac[i-1]*i;
        ifrac[n] = frac[n].inv();
        for (int i = n; i >= 1; --i) ifrac[i-1] = ifrac[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return frac[n]*ifrac[k]*ifrac[n-k];
    }
} c(1000000);

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    k = min(k, n-1);


    mint ans = 0;
    rep(i, k+1) {
        ans += c(n-1, i) * c(n, i);
    }

    cout << ans << endl;
}

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

using namespace std;

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef long long ll;
typedef pair<int, int> pii;


int main() {

#ifndef ONLINE_JUDGE
    //freopen("in.in", "r", stdin);
    //freopen("out.in", "w", stdout);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, l;
    cin >> n >> l;
    long long sum = 0;
    long long best = 0, close = 1e18;
    range(i, 1, n)sum += l + i - 1;
    range(i, 1, n) {
        long long cur = sum - (l + i - 1);
        if (abs(sum - cur) < close) {
            close = abs(sum - cur);
            best = cur;
        }
    }

    cout << best << endl;


    return 0;
}


Measured memory_bytes: 256
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/
#include<bits/stdc++.h>
#define mem(a) memset(a,0,sizeof(a))
#define INF 0x3f3f3f3f
#define Min 1e-6
#define lowbit(x) ((x)&(-x))
#define ls rt<<1
#define rs rt<<1|1
#define ll int

using namespace std;

const int N = 1e6 + 7;
const int M = 1e9 + 7;
const ll Mod = 2;

int i,j,n,m,t,T,p,l,r,q,len,len1,v,u,k,w,st,res,cnt,ans,tmp,nex,a[N],c[5];
string s;

int eo(int m,int n)
{
    if(!(m&(n-m))) return 1;
    else return 0;
}

int main()
{
    ios::sync_with_stdio(false);
    mem(c);
    cin >> n;
    cin >> s;
    for(i = 1;i < n;i++){
        a[i] = abs(s[i-1]-s[i]);
        c[a[i]]++;
    }
    if(n == 2){
        cout << a[1];
        return 0;
    }
    if(!c[1]){
        ans = 0;
        for(i = 1;i < n;i++)
            if(a[i]) ans += eo(i-1,n-2);
        cout << (ans%2)*2;
    }
    else{
        ans = 0;
        for(i = 1;i < n;i++)
            if(a[i] == 1) ans += eo(i-1,n-2);
        cout << ans%2;
    }
    return 0;
}



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

int main() {
	int n, m, a;
	cin >> n >> m;
	vector<int> A;
	for (int i = 0; i < m; i++) {
		cin >> a;
		A.push_back(a);
	}
	int sum=0;
	for (int i = 0; i < m; i++) {
		sum += A.at(i);
	}
	n -= sum;
	if (n < 0)cout << -1;
	else cout << n;
	system("pause");

	return 0;
}

Measured memory_bytes: 3720
#include<iostream>
#define LRN 15

using namespace std;

bool row[8];   //hang
bool line[8];  //lie
bool ln[15];
bool rn[15];
int loc[8];

void show(){
    for(int i=0;i<8;i++){
        for(int j=0;j<8;j++){
            if(j==loc[i]) cout<<'Q';
            else cout<<'.';
        }
        cout<<endl;
    }
}

void dfs(int r){
    if(r>=8){
        show();
        return;
    }
    if(row[r]){
        dfs(r+1);
        return;
    }
    for(int i=0;i<8;i++){
        if(!line[i] && !ln[r-i+7] && !rn[r+i]){
            line[i]=ln[r-i+7]=rn[r+i]=true;
            loc[r]=i;
            dfs(r+1);
            line[i]=ln[r-i+7]=rn[r+i]=false;
        }
    }
}

void init(){
    int n,a,b;

    for(int i=0;i<8;i++){
        row[i]=false;
        line[i]=false;
        for(int j=0;j<8;j++) loc[i]=-1;
    }
    for(int i=0;i<15;i++){
        ln[i]=rn[i]=false;
    }
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        loc[a]=b;
        row[a]=line[b]=true;
        ln[a-b+7]=rn[a+b]=true;
    }

}

int main(){
    init();
    dfs(0);
    return 0;
}



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

namespace contest
{
    class Program
    {
        static int Main(string[] args)
        {
            int MAX = 10;
            int[] ranking = new int[MAX];

            for(int i= 0;i < MAX; i++)
            {
                int high_num = int.Parse(Console.ReadLine());
                ranking[i] = high_num;
            }

            Array.Sort(ranking);
            
            Console.WriteLine("{0}", ranking[MAX-1]);
            Console.WriteLine("{0}", ranking[MAX - 2]);
            Console.WriteLine("{0}", ranking[MAX - 3]);

            Console.ReadKey();
            return 0;
        }

    }
}

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

using namespace std;

std::string substrBack(std::string str, size_t pos, size_t len) {
    const size_t strLen = str.length();
 
    return str.substr(strLen - pos, len);
}

int main(){
  	string S;
  	cin >> S;
  	
  	int A = S.size() / 2;
  	string S1, S2;
  	S1 = S.substr(0, A);
  	S2 = substrBack(S, A, A);
  	reverse(S2.begin(), S2.end());
  
  	int cnt = 0;
  	for(int i = 0; i < A; i++){
    if(S1[i] != S2[i])cnt++;
    }
  
  	cout << cnt << endl;
  
	return 0;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

ll dp[100005][4];

int main() {
  string s;
  cin >> s;
  REP(i, 100005) REP(j, 4) dp[i][j] = 0;
  dp[0][0] = 1;
  REP(i, s.size()) {
    REP(j, 4) {
      if (s[i] == '?')
        dp[i + 1][j] += (dp[i][j] * 3) % MOD;
      else
        dp[i + 1][j] += dp[i][j];

      dp[i + 1][j] %= MOD;
    }
    if (s[i] == 'A' || s[i] == '?') {
      dp[i + 1][1] += dp[i][0];
      dp[i + 1][1] %= MOD;
    }
    if (s[i] == 'B' || s[i] == '?') {
      dp[i + 1][2] += dp[i][1];
      dp[i + 1][2] %= MOD;
    }
    if (s[i] == 'C' || s[i] == '?') {
      dp[i + 1][3] += dp[i][2];
      dp[i + 1][2] %= MOD;
    }
  }

  cout << dp[s.size()][3] % MOD << endl;
  return 0;
}

Measured memory_bytes: 3584
// 

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <stack>
#include <cstring>

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

using namespace std;

int main(){
    int n;
    int cnt = 0;
    cin >> n;

    cnt = n / 2;
    if(n % 2 != 0) cnt++;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
#define INF (1<<31) - 1 //INT_MAX/2
#define MOD 1000000007
#define PI  acos(-1)
 
using ll  = long long;
using ull = unsigned long long;
using P = std::pair<int, int>;
 
int main(int argc, char *argv[])
{
    int N;
    std::cin >> N;

    std::string A, B, C;
    std::cin >> A >> B >> C;

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] == B[i]) {
            if (A[i] != C[i]) {
                ans++;
            }
        } else {
            if (A[i] == C[i]) {
                ans++;
            } else if (B[i] == C[i]) {
                ans++;
            } else {
                ans += 2;
            }
        }
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define MOD2 998244353
#define vi vector<ll>
#define PB push_back
#define FOI(i, a, n) for( ll i = a; i <= n; i++)
#define FOD(i, a, n) for( ll i = a; i >= n; i--)
#define F0I(i, n) FOI(i,0,n)
#define F0D(i, n) FOD(i,n,0)
#define F1I(i, n) FOI(i,1,n)
#define F1D(i, n) FOD(i,n,1)
#define watch(x) cout << #x << ": " << x << endl;
#define cnl(d) cout<<d<<'\n'
#define cns(d) cout<<d<<' '
#define printcont(v) for (auto &i : v) cout << i << " "; cout << endl
#define printmat(mat,row,col) F0I(i,row-1)F0I(j,col-1)cout << mat[i][j] << " \n"[j == col-1];
#define PNS cout<<' '
#define PNL cout<<'\n'
#define inint(i) ll i;cin >> i
#define invec(n,v) vi v(n); F0I(i,n-1) cin >> v[i]
#define insvec(n,v) inint(n); vi v(n); F0I(i,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll>> v(row, vector<ll>(col,val))
#define trvl(c,it) for(auto it=(c).begin();it!=(c).end();it++)
using namespace std;
ll findmin(ll a, ll b) { if(a < b) return a; return b; }
ll findmax(ll a, ll b) { if(a > b) return a; return b; }
ll fast_pow(ll base,ll exp){if (exp == 0) return 1;if (exp == 1) return base % MOD;ll t = fast_pow(base, exp / 2);t = ((t% MOD) * (t%MOD)) % MOD;if (exp % 2 == 0)return t;else return ((base %  MOD) * t) % MOD;}
ll abso(ll a){
	if(a < 0) return -a;
	return a;
}
struct trii
{
	ll ans[3];
};
//GLOBAL FUNCTIONS AND VARIABLES GO HERE //
int main()
{
	ll n;
	cin >> n;
	vector<trii> h(n);
	F0I(i,n-1)
	{
		cin >> h[i].ans[0];
		cin >> h[i].ans[1];
		cin >> h[i].ans[2];
	}
	MK2DV(dp,n,3,INT_MIN);
	dp[0][0] = h[0].ans[0];
	dp[0][1] = h[0].ans[1];
	dp[0][2] = h[0].ans[2];
	for(ll i = 1; i < n; i++)
	{
		for(ll j = 0; j < 3; j++)
		{
			for(ll mm = 0; mm < 3; mm++)
			{
				if(mm != j)
					dp[i][j] = findmax(dp[i][j], dp[i-1][mm] + h[i].ans[j]);
			}
		}
	}
	ll ans = INT_MIN;
	for(ll i = 0; i < 3; i++)
		ans = findmax(ans, dp[n-1][i]);
	cout << ans << '\n';
	return 0;
 }

Measured memory_bytes: 8064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		int n = sc.nextInt();
		
		int res = 0;
		
		for(int i = 1; i <= n; i+=2) {
			int count = 0;
			for(int j = 1; j <= i; j++) {
				if(i%j==0) count++;
			}
			if(count == 8) res++;
		}
		
		out.println(res);
		
		out.flush();
	}

	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 22612
def bubble_sort(A, N):
    sw = 0
    flag = True
    while flag:
        flag = False
        for j in range(1, N):
            if A[j - 1] > A[j]:
                A[j - 1], A[j] = A[j], A[j - 1]
                sw += 1
                flag = True
    return sw


def main():
    N = int(input().rstrip())
    A = list(map(int, input().rstrip().split()))
    
    sw = bubble_sort(A, N)

    print(' '.join(map(str, A)))
    print(sw)


if __name__ == '__main__':
    main()

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

int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  int p=0;
  int q=0;
  for(int i=0;i<n-1;i++){
    if(a.at(i)<a.at(i+1)){
      q=max(p,q);
      p=0;
    }
    else{
      p++;
    }
  }
  cout<<max(p,q)<<endl;
}

Measured memory_bytes: 640