akhauriyash/Code-Regression huggingface dataset:
/**
 *    +--+--+--++--++--In the name of ALLAH--++--++--+--+--+
 *
 *    author:  skmonir
 *    created: 21-Jun-2020 22:45:22
**/

#include <bits/stdc++.h>

using namespace std;

#define endl                '\n'
#define TN                  typename
#define mod                 1000000007LL
#define len(x)              (int) x.size()
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define mem(x, y)           memset(x, y, sizeof x)
#define FOR(x, l, r)        for (int x = l; x <= r; ++x)
#define ROF(x, l, r)        for (int x = l; x >= r; --x)

template <TN T> inline void Int(T &n) {
    n = 0; int f = 1; int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> inline void umin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void umax(T &a, T b) {a = a > b ? a : b;}
template <TN T, TN W> inline void Int(T &x, W &y) {Int(x), Int(y);}
template <TN T, TN W, TN Q> inline void Int(T &x, W &y, Q &z) {Int(x, y), Int(z);}

const int N = 1e5 + 7;
const int inf = 1e9 + 7;

template <TN T, TN R> inline T modpow(T base, R exp) {
    base %= mod; T res = 1;
    if (base < 0) base += mod;
    if (exp < 0) exp += mod - 1;
    for (; exp > 0; exp >>= 1) {
        if (exp & 1) res = (res * base) % mod;
        base = (base * base) % mod;
    }
    return res;
}

int solve() {
    int m; cin >> m;
    string s; cin >> s;

    int n = (int) s.size() + m;

    vector<long long> fact = {1LL};
    for (int i = 1; i <= n; ++i) {
        fact.push_back((fact.back() * i) % mod);
    }

    vector<long long> pow25 = {1LL};
    for (int i = 1; i <= n; ++i) {
        pow25.push_back((pow25.back() * 25) % mod);
    }

    long long res = 1LL;
    for (int i = 1; i <= n; ++i) {
        res = (res * 26) % mod;
    }

    function <long long(int, int)> choose = [&](int t, int k) {
        long long up = fact[t];
        long long dw = (fact[k] * fact[t - k]) % mod;
        long long res = (up * modpow(dw, -1)) % mod;
        return res;
    };

    long long minus = 0;
    for (int k = 0; k < s.size(); ++k) {
        minus += (choose(n, k) * pow25[n - k]) % mod;
        minus %= mod;
    }

    res = (res - minus) % mod;
    res = (res + mod) % mod;

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

    return 0;
}

int main() {
    int tests = 1, CaseNo = 0;
    // Int(tests);
    while (tests--) {
        //printf("Case %d: ", ++CaseNo);
        solve();
    }
    return 0;
}

Measured memory_bytes: 44412
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main {
	static Scanner sc;
	static PrintWriter out;
	static ArrayList<Edge> adj[];
	static int V,E;
	static int[] dist;
	static int[] parent;
	static final int oo = (int) 1e9;
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int a,b,c,d;
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		d = sc.nextInt();
		long c1 = 1l*a*c;
		long c2 = 1l*a*d;
		long c3 = 1l*b*c;
		long c4 = 1l*b*d;
		out.println(Math.max(c1, Math.max(c2, Math.max(c3, c4))));
		out.close();
	}
	static void dijkstra(int src) {
		dist = new int[V];
		Arrays.fill(dist, oo);
		parent = new int[V];
		Arrays.fill(parent, -1);
		dist[src] = 0;
		PriorityQueue<Edge> pq = new PriorityQueue<>();
		pq.add(new Edge(src,0));
		while(!pq.isEmpty()) {
			Edge e = pq.poll();
			if(dist[e.x] < e.y)
				continue;
//			if(e.x == dest)
//				return e.y;
			for(Edge e2:adj[e.x]) {
				if(dist[e2.x] > e2.y+e.y) {
					pq.add(new Edge(e2.x,dist[e2.x] = e2.y+e.y));
					parent[e2.x] = e.x;
				}
			}
		}
//		return -1;
	}
	static class Edge extends java.awt.Point implements Comparable<Edge>{		
		public Edge(int u, int val) {
			// TODO Auto-generated constructor stub
			super(u, val);
		}

		@Override
		public int compareTo(Edge e) {
			// TODO Auto-generated method stub
			return y - e.y;
		}		
	}
	static class Scanner{
		BufferedReader br;
		StringTokenizer st;
		public Scanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}
		private String next() throws Exception{
			while(st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws Exception{
			return Integer.parseInt(next());
		}
		public long nextLong() throws Exception{
			return Long.parseLong(next());
		}
		public double nextDouble() throws Exception{
			return Double.parseDouble(next());
		}
		public String nextLine() throws Exception {
			return br.readLine();
		}

	}
}


Measured memory_bytes: 32732
#include<bits/stdc++.h>
using namespace std;
void solve()
{
    long long int a,b,c,d;
    cin>>a>>b>>c>>d;
    long long int ans=max(max(a*c,b*c),max(a*d,b*d));

    cout<<ans;
}
int main()
{
    solve();
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int T;
	cin >> T;
	while(T--){
		int a, b, c, d, e, f;
		cin >> a >> b >> c;
		f = min(a, min(b, c));
		d = min((a - f) / 2, b - f);
		e = (a - f - 2 * d) / 3;
		cout << d + e + f << endl;
	}
	return 0;
}

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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string s; cin >> s;      
    int n = s.length()-1;
    if(s[n] == 's') cout << s << "es" << endl;
    else cout << s << "s" << endl;
}

Measured memory_bytes: 3648
n,x = map(int,input().split())
a = list(map(int,input().split()))

count = 0
for i in range(len(a)-1):
    if a[i+1]+a[i]>x:
        c = min((a[i+1]+a[i]-x),a[i+1])
        a[i+1] -= c
        count += c
    if a[i+1]+a[i]>x:
        c = min(a[i+1]+a[i]-x,a[i])
        a[i] -=c
        count += c
print(count)

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

int main(void) {
	string S1, S2;
	cin >> S1 >> S2;

	if (S1[0] == S2[2] && S1[1] == S2[1] && S1[2] == S2[0])
		cout << "YES\n";
	else
		cout << "NO\n";

	return 0;
}


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

int main(void){
    long long n,a,b;
    long long ans;
    scanf("%lld%lld%lld",&n,&a,&b);
    if (a>b){
        printf("0\n");
    } else {
        if (n==1){
            if (a!=b){
                printf("0\n");
            } else {
                printf("1\n");
            }
        } else if (n==2){
            printf("1\n");
        } else {
            ans=(n-2)*b-(n-2)*a+1;
            printf("%lld\n",ans);
        }
    }
	return 0 ;
}

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

int main(){
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    s.erase(unique(s.begin(),s.end()),s.end());
    //for(int i=0;i<s.size();i++)cout<<s.at(i);
    if(s.size()==2) cout<<"Yes"<<endl;
    else            cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <sstream>
#include <set>
using namespace std;
using ll = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

int main() {
  int R,G,B,N;
  cin >>R>>G>>B>>N;
  int ret=0;
  for (int r : range(N+1)) {
    for (int g : range(N+1)) {
      int rest = N-r*R-g*G;
      if (rest >= 0 && rest % B == 0) ret++;
    }
  }
  cout << ret << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  int a,b,c,d,e;
  int C;
  
  for (int i=0; i <= (B-A); i++){
  a = (A + i)/10000;
  b = ((A + i)/1000)%10;
  c = ((A + i)/100)%10;
  d = ((A + i)/10)%10;
  e = ( A + i)%10;
    
    if(a==e && b==d ){
    C++;
    }
    
    
  } 
  cout << C << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;cin>>n;
    ll ary[n];
    rep(i,n) cin >> ary[i];
    ll ruisekiwa[n+1];
    ruisekiwa[0] = 0;
    rep(i,n)
    {
        ruisekiwa[i+1] = ruisekiwa[i]+ary[i];
    }
    ll ans = 0;
    
    sort(ruisekiwa, ruisekiwa+n+1);
    ll chokuzen = 0;
    REP(i,1,n+1)
    {
        if (ruisekiwa[chokuzen] != ruisekiwa[i])
        {
            ll tmp_n = i-chokuzen;
            // cout << chokuzen <<" " << ruisekiwa[chokuzen] << " " << tmp_n << endl;
            ans += tmp_n*(tmp_n-1)/2;
            chokuzen = i;
        }
    }
    ll tmp_n = n+1-chokuzen;
    // cout << chokuzen <<" " << ruisekiwa[chokuzen] << " " << tmp_n << endl;
    ans += tmp_n*(tmp_n-1)/2;

    cout << ans << endl;

}


Measured memory_bytes: 3328
#include <iostream>


using namespace std;

const int64_t INF = INT64_MAX;

const int MAXN = 410;
int N;
int64_t DIM[MAXN];
int64_t DP[MAXN][MAXN];
int64_t S[MAXN];

int main() {

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> DIM[i];
		S[i] = S[i - 1] + DIM[i];

	}
	for (int i = 1; i < N; i++) {
		DP[i][i + 1] = DIM[i] + DIM[i + 1];
	}

	for (int len = 2; len < N; len++) {
		for (int left = 1; left + len <= N; left++) {
			int right = left + len;

			int64_t mn = INF;

			for (int stop = left; stop < right; stop++) {
				int64_t cost = DP[left][stop] + DP[stop + 1][right] +
								(S[stop] - S[left - 1]) + (S[right] - S[stop]);
				mn = min(mn, cost);
			}
			DP[left][right] = mn;
		}
	}

	cout << DP[1][N];
	

	return 0;

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			cout << DP[i][j] << " ";
		}
		cout << endl;
	}

	return 0;
}

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

int main(){
  long long int N;
  cin>>N;
  long long int sum=0;
  for(int i=1;i<=sqrt(N);i++){
    if(N%i==0&&(N/i-i)>=2){
      sum=sum+N/i-1;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#https://atcoder.jp/contests/agc010/tasks/agc010_a

n = int(input())
def process(x):
    x = int(x)
    if x%2 == 0:
        return 0
    else:
        return 1
data = list(map(process, input().split()))
l = [x for x in data if x == 1]
if len(l)%2==0:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 11104
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>

using namespace std;

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

typedef long long int ll;


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

	int n;
	int arr[1000];
	cin >> n;

	rep(i , n)
		cin >> arr[i];
	
	double ans = 0;
	double temp = 1.0;
	rep(i , n)
		ans += (temp / arr[i]);
	
	cout << (1.0/ans);
	return 0;
}

Measured memory_bytes: 256
### subroutines

def interval(x, r, v, e, f)
  if x >= r
    1.0 / (v - e * (x - r))
  else
    1.0 / (v - f * (r - x))
  end
end

### main

loop do
  n = gets.to_i
  break if n == 0

  ais = gets.split.map(&:to_i)
  ais.unshift(0)
  gl = ais.pop
  b = gets.to_f
  r, v, e, f = gets.split.map(&:to_f)
  r = r.to_i
  #p [ais, gl]
  #p b
  #p [r, v, e, f]

  tis = n.times.map{[0.0]}

  for x in (0...gl)
    ti = interval(x, r, v, e, f)
    tis[0][x + 1] = tis[0][x] + ti
  end
  #p tis[0]

  for k in (1...n)
    ai = ais[k]
    tis[k][ai] = (0...k).map{|i| tis[i][ai]}.min + b

    for x in (ai...gl)
      ti = interval(x - ai, r, v, e, f)
      tis[k][x + 1] = tis[k][x] + ti
    end
  end

  min_t = (0...n).map{|i| tis[i][gl]}.min
  puts "%.4f" % min_t
end

Measured memory_bytes: 19788
#include<stdio.h>

int main(void) {
   int N, X;

   scanf("%d %d",&N, &X);

   int L[N+1];

   for(int i = 0; i < N; i++) {
      scanf("%d", &L[i]);
   }

   int D[N+1];
   D[0] = 0;

   for(int i = 1; i < N+1; i++) {
      D[i] = D[i-1] + L[i-1];
   }

   int cnt = 0;

   for(int i = 0; i < N+1; i++) {
      if(D[i] <= X) {
         cnt++;
      }
   }

   printf("%d\n", cnt);


   return 0;
}


Measured memory_bytes: 1700
n, s = map(int, input().split())
x = -1
y = -1
z = -1

for i in range(n+1):
    for j in range(n-i+1):
        c = n - i - j
        total = 10000*i + 5000*j + 1000*c
        if total == s:
            x, y, z = i, j, c

print(x , y , z)

Measured memory_bytes: 9192
#include<iostream>

const int DIV = 1000000007;

unsigned long long power(int n, int m){
  if(m == 0) return 1;
  else if(m == 1) return n;
  else{
    unsigned long long p = power(n, m / 2);
    if(m % 2 == 0) return (p * p) % DIV;
    else return ( ((n * p) % DIV) * p) % DIV;
  }
}

int main(){
  int n, m;
  std::cin >> n;
  std::cin >> m;
  
  std::cout << power(n, m) << std::endl;

  return 0;
}



Measured memory_bytes: 3080
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    H, W = map(int, input().split())
    A = [list(map(int, input().split())) for i in range(H)]

    route = []
    for h in range(H):
        if h % 2 == 1:
            route.extend([(h, w) for w in range(W)])
        else:
            route.extend([(h, w) for w in reversed(range(W))])

    ans = []
    # ex. for (i1, j1), (i2, j2) in zip(route, route[1:]):
    for (i1, j1), (i2, j2) in zip(route, route[1:]):
        if A[i1][j1] % 2 == 1:
            A[i1][j1] -= 1
            A[i2][j2] += 1
            ans.append((i1 + 1, j1 + 1, i2 + 1, j2 + 1))

    print(len(ans))
    print('\n'.join(' '.join(map(str, line)) for line in ans))


resolve()

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

using namespace std;

int main()
{
    long long n ;
    cin>>n ;
    long double ans = 0.0 ;
    while(n--)
    {
        long double x ;
        cin>>x ;
        string s ;
        cin>>s ;
        if(s[0] == 'J')
            ans += x ;
        else
            ans += (380000.00 * x) ;
    }
    return cout<<fixed<<setprecision(12)<<ans<<"\n" , 0 ;
}


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

inline int read()
{
	char ch=getchar();
	int x=0,f=0;
	while(ch<'0'||ch>'9')
	{
		f|=ch=='-';
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return f?-x:x;
}
struct eric
{
	int to,next;
}edge[400005];
int head[200005],size,ans;
int n,fa[200005],m,maxp[200005];
inline void add(int x,int y)
{
	edge[++size].to=y;
	edge[size].next=head[x];
	head[x]=size;
}
inline void dfs(int pos,int fa)
{
	maxp[pos]=0;
	for(int i=head[pos];i;i=edge[i].next)
	{
		int v=edge[i].to;
		dfs(v,pos);
		maxp[pos]=max(maxp[pos],maxp[v]+1);
	}
	if(maxp[pos]>=m-1&&pos>1&&fa>1)
	++ans,maxp[pos]=-1;
}
int main(void)
{
	n=read(),m=read();
	for(int i=1;i<=n;i++)
	{
		fa[i]=read();
	}
	if(fa[1]!=1)
	{
		ans++;
		fa[1]=1;
	}
	for(int i=2;i<=n;i++)
	add(fa[i],i);
	dfs(1,1);
	printf("%d\n",ans);
}

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

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

#define RFOR(i, b, a) for(int(i)=(b); (i)>=(a); (i)--)
#define RREP(i, n) FOR((i), (n), 0)

#define pb push_back
#define mp make_pair 

using namespace std;

const int INF=INT_MAX/4;
const int MOD=1000000007;
const double EPS=1e-14;

const bool debug_flag=true;

void debug(string str){
	if(debug_flag){
		cout<<str<<endl;
	}
}

void debugs(string str){
	if(debug_flag){
		cout<<str;
	}
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout.precision(10);


	int n, b;
	cin>>n;
	set<int> a;
	for(int i=0; i<n; i++){
		cin>>b;
		if(a.find(b) != a.end()){
			a.erase(b);
		}else{
			a.insert(b);
		}
		
	}

	cout<<a.size()<<endl;

	return 0;
}



Measured memory_bytes: 4992
import java.io.*;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        try (CustomReader in = new CustomReader()) {
            new Main().execute(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void execute(CustomReader in) throws IOException {
        final int N = Integer.parseInt(in.readLine());
        int[] A = in.readLineAsIntArray();

        for (int i = 0; i < N; i++) {
            A[i] -= i + 1;
        }
        Arrays.sort(A);
        int k = N / 2;

        int med = (N % 2 == 0) ? (A[k - 1] + A[k]) / 2 : A[k];

/*        long minS = S(A, A[k]);
        if (N > 1) {
            minS = Math.min(minS, S(A, A[k + 1]));
            minS = Math.min(minS, S(A, (A[k] + A[k + 1]) / 2));
        }
        */
        System.out.println(S(A, med));

    }

    private long S(int[] a, int b) {
        long s = 0L;
        for (int i = 0; i < a.length; i++) {
            s += Math.abs(a[i] - b);
        }
        return s;
    }

    static class CustomReader extends BufferedReader {

        // private static final int DEFAULT_BUF_SIZE = 2048;
        // private static final int DEFAULT_BUF_SIZE = 4096;
        // private static final int DEFAULT_BUF_SIZE = 8192;
        private static final int DEFAULT_BUF_SIZE = 16384;

        // private static final int DEFAULT_BUF_SIZE = 1048576;

        public CustomReader() throws IOException {
            super(new InputStreamReader(System.in), DEFAULT_BUF_SIZE);
        }

        public int[] readLineAsIntArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            int[] intArray = new int[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                intArray[i] = Integer.parseInt(strArray[i]);
            }
            return intArray;
        }

        public int[][] readAsIntMatrix(int rows, int columns) throws IOException {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++) {
                String[] r = this.readLine().split(" ");
                for (int j = 0; j < columns; j++) {
                    matrix[i][j] = Integer.parseInt(r[j]);
                }
            }
            return matrix;
        }
    }

}

Measured memory_bytes: 49928
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define nfs ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F(i,a,b) for(i=a;i<b;i++)
#define RF(i,a,b) for(i=a;i>=b;i--)
#define m_p make_pair
#define p_b push_back
#define MOD 1000000007
int main()
{
	nfs;
	int t;
	t=1;
//	cin >> t;

	while(t--)
	{
		ll n;
		cin >> n ;
		ll i;
		ll c[n];
		F(i,0,n)
		{
			cin >> c[i];
		}
		ll dp[n];
		ll marked[200005];
		F(i,0,200005)
		{
			marked[i] = 0;
		}
		map<ll,ll> mp;
		dp[0] = 1;
		mp[c[0]] = 0;
		marked[c[0]] = 1;
		//ll ans = 0;
		F(i,1,n)
		{
			dp[i] = dp[i-1] ;
			if((marked[c[i]]==1)&&(c[i]!=c[i-1]))
			{
				dp[i] = (dp[i]+dp[mp[c[i]]])%MOD;
			//	cout << dp[i] << endl;
				
				
			}
			marked[c[i]] = 1;
			mp[c[i]] = i;
			
		}
		
		cout << dp[n-1] << endl;
		
	}
	return 0;

}



Measured memory_bytes: 17408
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	vi input;
	int n;
	while(cin >> n) {
		input.push_back(n);
	}

	stack<int> S;
	REP(i, input.size()) {
		if(input[i]) {
			S.push(input[i]);
		} else {
			cout << S.top() << endl;
			S.pop();
		}
	}

	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793
int dx[] = {0,1,-1,0,1,-1,1,-1};
int dy[] = {1,0,0,-1,1,-1,-1,1};

int main(){
    vector<int> v(3);
    cin >> v[0] >> v[1] >> v[2];
    sort(v.begin(), v.end());
    cout << v[2]*10 + v[1] + v[0] << endl;
}


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

struct bit {
	vector<long> t;
	bit(int n) :t(n + 1) {}
	void upd(int a, long n) {
		for (a++; a < t.size(); a += a & -a)
			t[a] += n;
	}
	long get(int a) const {
		long r = 0;
		for (; a; a &= a - 1)
			r += t[a];
		return r;
	}
};
pair<int, int> X[222222];
int c[222222], d[222222], e[222222] = { 1 };
int main() {
	int n, p = 998244353;
	cin >> n;
	for (int i = 0; i < n; i++)
		e[i + 1] = e[i] * 2 % p;
	for (int i = 0; i < n; i++)
		scanf("%d%d", &X[i].first, &X[i].second);
	sort(X, X + n, [](auto a, auto b) {return a.second < b.second; });
	for (int i = 0; i < n; i++)
		X[i].second = i;
	sort(X, X + n);
	bit b(n);
	for (int i = 0; i < n; i++) {
		c[i] = b.get(X[i].second);
		d[i] = X[i].second;
		b.upd(X[i].second, 1);
	}
	long r = 0;
	for (int i = 0; i < n; i++) {
		int x = c[i], y = i - x, z = d[i] - x, w = n - 1 - x - y - z;
		(r += e[n] + p - 1) %= p;
		(r += e[x]) %= p;
		(r += e[y]) %= p;
		(r += e[z]) %= p;
		(r += e[w]) %= p;
		(r += p - e[x + y]) %= p;
		(r += p - e[x + z]) %= p;
		(r += p - e[w + y]) %= p;
		(r += p - e[w + z]) %= p;
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<pair<int,int>>>;
#define MOD 1000000007
#define INF 1000000000

int main(){
  string S,T;
  cin>>S>>T;
  int N=S.size();
  int n=T.size();
  int ans=n;
  for(int i=0;i<N-n+1;i++){
    int count=0;
    for(int j=0;j<n;j++){
      if(S[i+j]!=T[j]){
        count++;
      }
    }
    ans=min(ans,count);
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		int field[][] = setField();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input = null;
		while (true) {
			try {
				input = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (input == null || input.isEmpty()) {
				break;
			}
			;
			String[] inputs = input.split(",");
			drop(field, Integer.parseInt(inputs[0]),
					Integer.parseInt(inputs[1]),
					Integer.parseInt(inputs[2]));
		}
		amountOfWhite(field);
		maxDepth(field);

	}

	private static int[][] setField() {
		int field[][] = new int[10][10];
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				field[i][j] = 0;
			}
		}
		return field;
	}

	private static void drop(int[][] field, int x, int y, int size) {
		switch (size) {
		case 1:
			dropSmall(field, x, y);
			break;

		case 2:
			dropMiddle(field, x, y);
			break;
		case 3:
			dropLarge(field, x, y);
			break;
		}

	}

	private static void dropLarge(int[][] field, int x, int y) {

		dropMiddle(field, x, y);

		int dropX[] = { -2, 0, 2, 0 };
		int dropY[] = { 0, -2, 0, 2 };

		for (int i = 0; i < dropX.length; i++) {
			dropping(field, x + dropX[i], y + dropY[i]);
		}
	}

	private static void dropMiddle(int[][] field, int x, int y) {

		dropSmall(field, x, y);

		int dropX[] = { -1, -1, 1, 1 };
		int dropY[] = { 1, -1, 1, -1 };

		for (int i = 0; i < dropX.length; i++) {
			dropping(field, x + dropX[i], y + dropY[i]);
		}
	}

	private static void dropSmall(int[][] field, int x, int y) {
		int dropX[] = { -1, 0, 1, 0 };
		int dropY[] = { 0, -1, 0, 1 };
		dropping(field, x, y);

		for (int i = 0; i < dropX.length; i++) {
			dropping(field, x + dropX[i], y + dropY[i]);
		}
	}

	private static int[][] dropping(int[][] field, int x, int y) {
		if (0 <= x && x < 10 && 0 <= y && y < 10) {
			field[x][y] += 1;
		}
		return field;
	}

	private static void amountOfWhite(int[][] field) {
		int count = 0;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				if (field[i][j] == 0) {
					count++;
				}
			}
		}
		System.out.println(count);
	}

	private static void maxDepth(int[][] field) {
		int maxDepth = 0;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				if (maxDepth < field[i][j]) {
					maxDepth = field[i][j];
				}
			}
		}
		System.out.println(maxDepth);
	}
}

Measured memory_bytes: 16928
import { readFileSync } from 'fs'
import { reverse } from 'dns'

function main(input: string[]) {
  let N = Number(input[0])
  let A : number[] = input[1].split(' ').map(v=>parseInt(v, 10))

  A = A.sort((a, b) => a - b)
  A.reverse()
  let ans = A[0]
  N -= 2
  for (let i = 1;; i++) {
    if (N == 0) break;
    if (N == 1) {
      ans += A[i]
      N--
    } else {
      ans += A[i] * 2
      N -= 2
    }
  }

  console.log(ans.toString())
}

let lines: string[] = [];
const reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', function (line: string) {
  lines.push(line);
});
reader.on('close', function () {
  main(lines)
});


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

using namespace std;
 
//#define int long long
using ll = long long;
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(i,n) for(ll i=0;i<=n;i++)
#define PI 3.14159265358979323846264338327950L

ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
 
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

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

int main(){
    ios_base::sync_with_stdio(false);
    ll h,a,ans=0;
    cin >> h >> a;
    while(h>0){
        h -= a;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
// https://atcoder.jp/contests/abc132/tasks/abc132_c
#pragma GCC optimize("Ofast")
#include <algorithm>
#include <functional>
#include <iostream>
#include <utility>
#include <vector>
#define ll long long
#define rep(i, s, n) for (ll i = s; i < n; ++i)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define MOD 1000000007
using namespace std;

int solve(int n, vector<int> d) {
    int mid = n / 2;
    return d[mid] - d[mid - 1];
}

int main() {
    int n, di;

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;

    vector<int> d;
    rep(i, 0, n) {
        cin >> di;
        d.push_back(di);
    }

    sort(begin(d), end(d));
    // rep(i, 0, n) cout << d[i] << endl;

    int ans = solve(n, d);
    cout << ans << endl;
}


Measured memory_bytes: 3996
<?php
// スペース区切りの整数の入力
fscanf(STDIN, "%d %d %d", $a, $b, $k);

for ($i = 1; $i <= $k; $i++) {
  //奇数番目だったら高橋くんの番
  if ($i % 2 === 1) {
    //奇数枚だったら１枚食べる
    if ($a % 2 === 1) {
      $a--;
    }

    $a /= 2;
    $b += $a;
  } else {
    //偶数番目だったら青木くんの番
    //奇数枚だったら１枚食べる
    if ($b % 2 === 1) {
      $b--;
    }

    $b /= 2;
    $a += $b;
  }
}

echo $a. " ". $b;

?>


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    int l = s.size();
    vector<ll> sum(l + 1);
    ll tenmod;

    for (int i = l; i > 0; i--) {
        int x = s[i - 1] - '0';
        if (i == l) {
            sum[i] = x;
            tenmod = 1;
        } else {
            tenmod = (tenmod * 10) % 2019;
            sum[i] = (sum[i + 1] + (tenmod * x % 2019)) % 2019;
        }
    }

    // for (int i = 0; i <= l; i++) {
    //     printf("%04d: %lld\n", i, sum[i]);
    // }

    // print count of 0 and nC2 in sum[0..l]
    ll ans = 0;
    ll prev = -1;
    ll count = 0;
    sort(sum.begin(), sum.end());
    for (int i = 0; i <= l; i++) {
        // printf("%04d: %lld\n", i, sum[i]);
        if (sum[i] != prev) {
            if (count > 0) {
                ans += count * (count - 1) / 2;
            }
            count = 1;
            prev = sum[i];
        } else {
            count++;
        }
    }
    ans += count * (count - 1) / 2;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;
#define fori(i,a,b) for(ll i=(a);i<=(b);i++)
#define repi(i,n) fori(i,0,(n)-1)
#define forr(i,a,b) for(ll i=(b);i>=(a);i--)
#define repr(i,n) forr(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
#define vec vector<ll>
#define pb push_back
#define mp make_pair
#define pcnt __builtin_popcount
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

void solve(ll a, ll b, ll k){
    if (k<a){
        a-=k;
    }else if(k<a+b){
        k-=a;
        a=0;
        b-=k;
    }else{
        a=0;
        b=0;
    }
    cout<<a<<" "<<b<<endl;
}

int main(){
    ll a;
    scanf("%lld",&a);
    ll b;
    scanf("%lld",&b);
    ll k;
    scanf("%lld",&k);
    solve(a, b, k);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = 1e9+7;
const int SIZE = 1e6+5;
const LL INF = 1LL<<62;
const double eps = 1e-4;
const double PI=3.1415926535897932;
 
vector<int> adj[100009];
 
int dfs(int x,int p){//returns bitmask of visible positions
	bool hasc=0;
	int visible=0;
	int doubleup=0;
	for(int i:adj[x]){
		if(i==p)continue;
		hasc=1;
		int dfsv=dfs(i,x);
		doubleup|=(visible&dfsv);
		visible|=dfsv;
	}
	if(!hasc)return 1;
	int m2=0;
	for(int i=19;i>=0;i--){
		if(doubleup&(1<<i)){m2=i+1;break;}
	}
	int v=0;
	REPP(i,m2,20){
		if(!(visible&(1<<i))){v=i;break;}
	}
	visible|=(1<<v);
	REP(i,v){
		if(visible&(1<<i))
		visible^=(1<<i);
	}
	return visible;
}
 
int main(){
	DRI(n);
	REP(i,n-1){
		DRII(a,b);a--;b--;
		adj[a].PB(b);adj[b].PB(a);
	}
	int vv=dfs(0,-1);
	//printf("%d ",vv);
	for(int i=20;i>=0;i--){
		if(vv&(1<<i)){printf("%d",i);return 0;}
	}
}

Measured memory_bytes: 10240
/**
 *  author:   TakeruOkuyama
 *  created:  2020-04-08 01:29:57
**/
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P =pair<int,int>;

int main(){
    int N;
    cin >> N;
    vector<int64_t> luca(N+1);
    luca[0] = 2LL;
    luca[1] = 1LL;
    for(int i = 2; i <= N; i++){
        luca[i] = luca[i-1] + luca[i-2];
    }
    cout << luca[N] << endl;
return 0;}

/**
 * compile: g++ code.cpp
 * run: ./a.out
 * insert date string: ctrl + shift + i
 * 
**/ 

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

using namespace std;
using ll = long long;

ll w, b, cnt;

int main()
{
    string s;
    cin >> s;
    
    for (int i = 0; i < s.size(); ++i)
        if (s[i] == 'W')
            cnt += b;
        else
            ++b;

    cout << cnt;
}

Measured memory_bytes: 640
N, M = map(int,input().split())
s = []

for i in range(M):
    s.append(list(map(int,input().split())))

for num in range(1000):
    str_num = str(num)
    if len(str_num) != N:
        continue
    
    flag = True
    for i in range(M):
        keta = s[i][0]
        if str_num[keta - 1] != str(s[i][1]): 
            flag = False
    if flag:
        print(num)
        exit()

print(-1)


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

using namespace std;

vector<int> factorize(int x) {
  vector<int> factors;
  for (int a = 1; a * a <= x; a++) {
    if (x % a == 0) {
      factors.push_back(a);
      if (a * a != x) {
        factors.push_back(x / a);
      }
    }
  }
  sort(factors.begin(), factors.end());
  return factors;
}

template <typename T>
T gcd(T a, T b) {
  return (b ? gcd(b, a % b) : a);
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];

  int answer = 0;
  {
    vector<int> f = factorize(A[0]);
    reverse(f.begin(), f.end());
    for (int k : f) {
      int count = 0;
      for (int i = 0; i < N; i++) {
        if (A[i] % k == 0) count++;
      }
      if (count >= N - 1) {
        answer = max(answer, k);
        break;
      }
    }
  }
  {
    int g = A[1];
    for (int i = 1; i < N; i++) {
      g = gcd(g, A[i]);
    }
    answer = max(answer, g);
  }

  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>

#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;


string S;

ll ans,N,W[105];
queue<int>que;

int main() {

	cin >> N;
	FOR(i, 0, N) {
		cin >> W[i];
	}
	ans = MOD;

	FOR(i, 0, N) {
		ll mae = 0, ato = 0;
		FOR(k, 0, N) {
			if (k <= i)mae += W[k];
			else ato += W[k];
		}
		ans = min(ans, abs(mae - ato));

	}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
#define INF (1<<30)-1
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int h,w; cin >> h >> w;
  int ch,cw,dh,dw; cin >> ch >> cw >> dh >> dw;
  ch--; cw--; dh--; dw--;
  vector<string> s(h); rep(i,h) cin >> s[i];

  vector<vi> cnt(h,vi(w,INF));
  deque<pair<int,int>> q;
  q.push_front({ch,cw});
  cnt[ch][cw] = 0;
  while(!q.empty()){
    pair<int,int> p = q.front(); q.pop_front();
    int x = p.second, y = p.first;
    rep(i,4){
      if(x+dx[i]<0 || w<=x+dx[i] || y+dy[i]<0 || h<=y+dy[i]) continue;
      if(s[y+dy[i]][x+dx[i]] == '.'){
        if(chmin(cnt[y+dy[i]][x+dx[i]],cnt[y][x])) q.push_front({y+dy[i],x+dx[i]});
      }
    }
    for(int ddx = -2; ddx <= 2; ddx++){
      for(int ddy = -2; ddy <= 2; ddy++){
        if(x+ddx<0 || w<=x+ddx || y+ddy<0 || h<=y+ddy) continue;
        if(s[y+ddy][x+ddx] == '.'){
          if(chmin(cnt[y+ddy][x+ddx],cnt[y][x]+1)) q.push_back({y+ddy,x+ddx});
        }
      }
    }
  }
  if(cnt[dh][dw] == INF) cout << -1;
  else cout << cnt[dh][dw];
  return 0;
}


Measured memory_bytes: 8672
# coding: UTF-8
# sample code

s = input()

bf = s[0] + s[1]
af = s[2] + s[3]

bf_num = int(bf)
af_num = int(af)

if (bf_num >= 1) & (bf_num <= 12):
	if (af_num >= 1) & (af_num <= 12):
		print('AMBIGUOUS')
	else :
		print('MMYY')
else :
	if (af_num >= 1) & (af_num <= 12):
		print('YYMM')
	else :
		print('NA')

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

int main() {
	int N; cin >> N;
	string S; cin >> S;
	map<pair<string, string>, int>mp;
	//前半部分の組み合わせを全列挙
	for (int mask = 0; mask < (1 << N); ++mask) {
		string R = "", B = "";
		for (int i = 0; i < N; ++i) {
			if (mask&(1 << i)) {
				R.push_back(S[i]);
			}
			else {
				B.push_back(S[i]);
			}
		}
		mp[{R, B}]++;
	}
	//後半部分の組み合わせを全列挙
	ll ans = 0;
	for (int mask = 0; mask < (1 << N); ++mask) {
		string R = "", B = "";
		for (int i = 0; i < N; ++i) {
			if (mask&(1 << i)) {
				R.push_back(S[N + i]);
			}
			else {
				B.push_back(S[N + i]);
			}
		}
		reverse(R.begin(), R.end());
		reverse(B.begin(), B.end());
		ans += mp[{B, R}];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 87040
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int k;
 
int gcd(int a, int b){
    if(b == 0) return a;
 
    return gcd(b, a%b);
}
 
int main(){

    int n;
    cin >> n;

    map<int, int> mp;

    rep(i,n) {
        int x;
        cin >> x;
        mp[x-1]=i;
    }

    //sort(mp.begin(), mp.end());

    rep(i,n){
        cout << mp[i]+1 << " ";
    }
    
    return 0;
}

Measured memory_bytes: 5504
# 二項係数のmod (大量のmod計算が必要なとき)
def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r=min(r,n-r)

    return g1[n] * g2[r] * g2[n - r] % mod

mod = 10 ** 9 + 7
N = 10 ** 6 # 出力の制限
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)


s=int(input())
x=s//3
ans=0
for i in range(1,x+1):
    cnt=(s-i*3)
    cnt2=cmb(cnt+i-1,i-1,mod)
    ans+=cnt2
print(ans%mod)


Measured memory_bytes: 167928
#include <iostream>
using namespace std;
void dp(int wt[],int val[],int n,int w)
{
    
    long int matrix[n+1][w+1];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=w;j++)
        {
            if(i==0||j==0)
            matrix[i][j]=0;
            else if(j>=wt[i])
            matrix[i][j]=max(val[i]+matrix[i-1][j-wt[i]],matrix[i-1][j]);
            else
            matrix[i][j]=matrix[i-1][j];
        }
    }
    
    cout<<matrix[n][w];
    

    
}
int main() {
	int n,w;
	cin>>n>>w;
	int wt[n+1],val[n+1];
	for(int i=1;i<=n;i++)
	{
	    cin>>wt[i];
	    cin>>val[i];
	}
	
	dp(wt,val,n,w);
	return 0;
}

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

int main() {
    while (cin) {
        int a, b;
        cin >> a >> b;
        if (a == 0 && b == 0){
            return 0;
        }
        int n;
        cin >> n;
        const int cannot = -101010;
        vector<vector<int> > dp(a, vector<int>(b, 0));
        dp[0][0] = 1;
        rep(i, n) {
            int x, y;
            cin >> x >> y;
            dp[--x][--y] = cannot;
        }
        // rep(i, a) {
        //     rep(j, b) {
        //         cout << dp[i][j] << " ";
        //     }
        //     cout << endl;
        // }
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++) {
                if (dp[i][j] != cannot) {
                    dp[i][j] += (i > 0 && dp[i - 1][j] != cannot ? dp[i - 1][j] : 0);
                    dp[i][j] += (j > 0 && dp[i][j - 1] != cannot ? dp[i][j - 1] : 0);
                }
            }
        }
        // rep(i, a) {
        //     rep(j, b) {
        //         cout << dp[i][j] << " ";
        //     }
        //     cout << endl;
        // }
        cout << dp[a - 1][b - 1] << endl;
    }
}


Measured memory_bytes: 3096
#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 INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{	
	ll A, B, C, D;
	cin >> A >> B >> C >> D;
	ll ans = 0;
	ll numC = B/C - (A-1)/C;
	ll numD = B/D - (A-1)/D;
	ll numCD = B/(C*D/__gcd(C, D)) - (A-1)/(C*D/__gcd(C, D));
	ans = B-A+1-numC-numD+numCD;
	cout << ans << endl;
	//cout << numC << " " << numD << " " << numCD <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
int a[102];
int main(){
	fastIO;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int ans=(int)1e7+7;
	for(int i=-100;i<=100;i++){
		int cnt=0;
		for(int j=0;j<n;j++){
			cnt+=(a[j]-i)*(a[j]-i);	
		}	
		ans=min(ans, cnt);
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d %d', $n, $k);
fscanf(STDIN, '%s', $s);
$pos = $s[0];
$i = 0;
$j = 0;
$sum[0] = 0;
while ($i < $n) {
    if ($pos === '0') $j++;
    $n_pos = ($pos === '1') ? '0' : '1';
    $n_i = strpos($s, $n_pos, $i);
    if (!$n_i) $n_i = $n;
    $r[] = [
        'val' => $pos,
        'cnt' => $n_i - $i
    ];
    $m = count($sum);
    $sum[] = $sum[$m - 1] + $n_i - $i;
    $pos = $n_pos;
    $i = $n_i;
}
if ($j <= $k) {
    echo $n . PHP_EOL;
    exit();
}
$max = 0;
if ($s[0] === '0') {
    for ($i = 0; $i < 2 * ($j - $k + 1); $i += 2) {
        $val = $sum[$i + 2 * ($k - 1) + 1] - $sum[$i] + ($r[$i + 2 * ($k - 1) + 1]['cnt'] ?? 0) + ($r[$i - 1]['cnt'] ?? 0);
        $max = max($max, $val);
    }
} else {
    for ($i = 1; $i < 2 * ($j - $k + 1) + 1; $i += 2) {
        $val = $sum[$i + 2 * ($k - 1) + 1] - $sum[$i] + ($r[$i + 2 * ($k - 1) + 1]['cnt'] ?? 0) + ($r[$i - 1]['cnt'] ?? 0);
        $max = max($max, $val);
    }
}
$ans = $max;
echo $ans . PHP_EOL;

Measured memory_bytes: 48756
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  ll x,money = 100;
  std::cin >> x;

  ll year = 0;
  while (money < x) {
    money *= 1.01;
    year++;
  }

  std::cout << year << '\n';
  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define EPS 1e-10
#define INF 1e18
#define mod 1000000007
#define PI acos(-1.0L)
#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 ALL(n) begin(n),end(n)
#include<bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
int main(void){
    int k;
    string s;
    cin >> k >>s;
    if(s.length() <= k)cout << s << endl;
    else
    {
        REP(i,k){
            cout <<s[i];
        }
        cout << "..." << endl;
    }

    return 0;
}

Measured memory_bytes: 3592
/*  ex5_3
    potter0723sw  */

#include <stdio.h>
#include <stdlib.h>

int main(void){
    int height, width, i, j, rowblack[100]={0}, colblack[100]={0};
    char cell[100][100];
    scanf("%d %d", &height, &width);

    for(i=0; i < height; i++){//マスの入力を受け取る
        for(j=0; j < width; j++){
            scanf(" %c", &cell[i][j]);
        }
    }

    for(i=0; i < height; i++){//黒マスのある行と列を記憶
        for(j=0; j < width; j++){
            if(cell[i][j] == '#'){
                rowblack[i] = 1;
                colblack[j] = 1;
            }
        }
    }
    
    for(i=0; i < height; i++){//同じ行と列両方に黒マスがあるマスのみ出力
        if(rowblack[i]==1){
            for(j=0; j < width; j++){
                if(colblack[j] == 1){
                    printf("%c", cell[i][j]);
                }
            }
        printf("\n");
        }
    }
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>

using namespace std;

static const double EPS = 1e-8;
const double DTR = (2 * acos(-1)) / 360;


enum ans {
        ABC, ACD, ADB, BCD,
};

int solve() {
        string xy;
        cin >> xy;
        int d, l;
        scanf("%d%d", &d, &l);
        double base = 
                xy == "BC" ? -60 :
                xy == "CD" ? 0 :
                xy == "DB" ? 60:
                0;
        double theta = (base + d) * DTR;
        double y = l * sin(theta);
        double x = l * cos(theta);
        double z60 = x + sqrt(3) / 3.0 * y;
        double z120 = -x + sqrt(3) / 3.0 * y;
        z60 = fmod(fmod(z60, 2.0) + 2.0 + EPS, 2.0);
        z120 = fmod(fmod(z120, 2.0) + 2.0 + EPS, 2.0);
        y = (z60 + z120) * sqrt(3) / 2.0;
        if (z60 < 1.0) {
                if (z120 < 1.0) {
                        if (y < sqrt(3) / 2.0) {
                                return ADB;
                        } else {
                                return BCD;
                        }
                } else {
                        if (y < sqrt(3)) {
                                return ABC;
                        } else {
                                return ACD;
                        }
                } 
        } else {
                if (z120 < 1.0) {
                        if (y < sqrt(3)) {
                                return ACD;
                        } else {
                                return ABC;
                        }
                } else {
                        if (y < 3.0 * sqrt(3) / 2.0) {
                                return BCD;
                        } else {
                                return ADB;
                        }
                }
        }
}

int main() {
        int a = solve(), b = solve();
        puts(a == b ? "YES" : "NO");
        return 0;
}

Measured memory_bytes: 3564