akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define F2(i,a,b) for(int i=(a);i<(b);++i)
#define dF(i,a,b) for(int i=(a);i>=(b);--i)
#define dF2(i,a,b) for(int i=(a);i>(b);--i)
#define dF3(i,a,b) for(int i=(a)-1;i>=(b);--i)
using namespace std;typedef long long ll;typedef double ld;int INF=0x3f3f3f3f;int INF2=0x7fffffff;ll LNF=0x3f3f3f3f3f3f3f3f;ll LNF2=0x7fffffffffffffff;

int n;
int a[100001],p[100001];
inline bool cmp(int p1,int p2){return a[p1]==a[p2]?p1<p2:a[p1]<a[p2];}
ll ans[100001];

int main(){
	scanf("%d",&n);
	F(i,1,n) scanf("%d",a+i), p[i]=i;
	sort(p+1,p+n+1,cmp);
	int lst=n+1;
	dF(i,n,1){
		if(a[p[i]]!=a[p[i-1]]){
			ans[lst>p[i]?p[i]:lst]+=(ll)(n-i+1)*(a[p[i]]-a[p[i-1]]);
			lst=lst>p[i]?p[i]:lst;
		}
	}
	F(i,1,n) printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 2688
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
#define fi first
#define se second
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<vi> vvi;
int main() {
    int a,b;
    cin>>a>>b;
    if(a%2==0 || b%2==0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

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

int n,m;
char s[N][N];

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();m=read();
	for (int i=1;i<=n;i++) scanf(" %s",s[i]+1);
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++)
			printf((j==1||(j!=m&&i%2==1)||s[i][j]=='#')?"#":".");
		printf("\n");
	}
	printf("\n");
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++)
			printf((j==m||(j!=1&&i%2==0)||s[i][j]=='#')?"#":".");
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,m;
  cin>>n;
  map<string,ll> ao;
  map<string,ll> aka;
  rep(i,n){
    string s;
    cin>>s;
    ao[s]++;
  }
  cin>>m;
  rep(i,m){
    string s;
    cin>>s;
    aka[s]++;
  }
  ll ans=0;
  for(auto p:ao){
    ll k=p.S;
    string h=p.F;
    if(aka.count(h)){
      k-=aka[h];
    }
    ans=max(ans,k);
  }
  COUT(ans);
}
                   


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = int(s.size());
  int res = 1;
  string before ="";
  before += s[0];
  string next = "";
  for (int i = 1; i < n; i++) {
    next += s[i];
    // cout << before <<endl;
    // cout << next << endl;
    if(before != next){
      res++;
      before = next;
      next = "";
    }
    // cout << "==" << endl;
  }


  cout << res << endl;
}


Measured memory_bytes: 720
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

string GenerateNextHand(char head,char tail,map<string,bool>& used){
  for(char i='a';i<='z';i++){
    for(char j='a';j<='z';j++){
      string str = "";
      str.push_back(head);
      str.push_back(i);
      str.push_back(j);
      str.push_back(tail);
      // printf("%s\n",str.c_str());
      if(used.find(str) == used.end()){
	return str;
      }
    }
  }
}

int main(){
  printf("?aj\n"); fflush(stdout);
  char buf[128];
  map<string,bool> used;
  used["aj"] = true;
  string prev_my_hand = "aj";
  char next_my_tail = 'j';

  while(~scanf("%s",buf)){
    if(buf[0] != prev_my_hand[prev_my_hand.size()-1]
       || used.find(buf) != used.end()){
      printf("!OUT\n");
      fflush(stdout);
    }

    used[buf] = true;
    char next_my_head = buf[strlen(buf)-1];
    prev_my_hand = GenerateNextHand(next_my_head,next_my_tail,used);
    used[prev_my_hand] = true;
    printf("?%s\n",prev_my_hand.c_str());
    fflush(stdout);
  }
}

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

int main(){
  int a,b;
  int ans=0;
  cin>>a>>b;
  rep(i,2){
    if(a>=b){
      ans+=a;
      a--;
    }else{
      ans+=b;
      b--;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,k,cnt[200010] = {},ans = 0;
	cin >> n >> k;
	for(int i = 0;i < n;i++){
		int a;
		cin >> a;
		cnt[a]++;
	}
	sort(cnt,cnt + n + 1,greater<int>());
	for(int i = 0;i < k;i++) ans += cnt[i];
	cout << n - ans << endl;
}

Measured memory_bytes: 1920
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import combinations
def main():
    def divisor(n):
        i = 1
        t = []
        while i * i <= n:
            if n % i == 0:
                t.append(i)
                t.append(n // i)
            i += 1
        return len(set(t))

    n = int(input())
    r = 0
    for i1 in range(1, n + 1, 2):
        r += 8 == divisor(i1)
    print(r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 62204
#pragma region Template

#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <bitset>
#include<map>
#include<cmath>
#include <set>
#include<limits.h>
#include<fstream>

#define lli long long int
#define l long
#define us unsigned short
#define mod 1000000007
#define INF 1e9+5

#define vi vector<int>
#define vus vector<unsigned short>
#define vlli vector<long long int>
#define vs vector<string>
#define mii map<int,int>

#define w(t) int t; cin>>t;while(t--)

using namespace std;

#pragma endregion

int main()
{
	lli n, W;
	cin >> n >> W;
	vlli v(n+1),p(n+1);
	vector<vector<lli>> dp(n+1,vector<lli>(W+1));

	for (lli i = 1; i <= n; i++)
	{
		cin >> v[i] >> p[i];
	}

	for (lli i = 1; i <= n; i++)
	{
		for (lli w = 1; w <= W; w++)
		{
			if (w - v[i] >= 0)
				dp[i][w] = max(dp[i - 1][w], dp[i - 1][w - v[i]] + p[i]);
			else
				dp[i][w] = dp[i - 1][w];
		}
	}

	cout << dp[n][W] << endl;

	return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  if((N - N/1000)%111 == 0 || (N - N%10)%111 == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main(){
    long long a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(a*c, max(a*d , max(b*c, b*d))) << endl;;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    //データ定義
    ll matrixA[100][100];
    ll matrixB[100][100];
    int n, m, l;
    int i, j, k;

    //データ入力
    cin >> n >> m >> l;
    
    //行列A　データ入力
    for(i = 0; i < n; i++)
    {
        for(j = 0; j < m; j++)
        {
            cin >> matrixA[i][j];
        }
    }
    //行列B　データ入力
    for(i = 0; i < m; i++)
    {
        for(j = 0; j < l; j++)
        {
            cin >> matrixB[i][j];
        }
    }

    //行列の積を求める
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < l; j++)
        {
            ll c = 0;
            for(k = 0; k < m; k++)
            {
                c += matrixA[i][k] * matrixB[k][j];
            }
            if( j == 0) cout << c;
            else cout << " " << c;
         }
         cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

int main(){
    int A, B, C;
    cin >> A >> B >> C;

    if(A==B) cout << C << endl;
    else if(B==C) cout << A << endl;
    else cout << B << endl;
    return 0;
}


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

int main(){
    int H,W,h,w;
    cin>>H>>W>>h>>w;
    //maybe i can do it in a better way
    int tot=H*W;
    int paint=h*W;
    int left=tot-paint;
    int col=left/W;
    int more=col*w;
    cout<<left-more;
}


Measured memory_bytes: 256
L = input().split()
n = len(L)
A  = []
top = -1
for i in range(n):
    if L[i] not in {"+","-","*"}:
        A.append(int(L[i]))
        top += 1
    else:
        if(L[i] == "+"):
            A[top - 1] = A[top - 1] + A[top]
        elif(L[i] == "-"):
            A[top - 1] = A[top -1] - A[top]
        elif(L[i] == "*"):
            A[top - 1] = A[top - 1] * A[top]
        del A[top]
        top -= 1
print(A[top])


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
 
long modpow(long a, long n, int mod){
  long res = 1;
  while (n > 0){
    if (n & 1){
      res = res * a % mod;
    }
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
 
int main(){
  long N, b, c;
  cin >> N >> b >> c;
  
  long mod = 1000000007;
  
  long A = modpow(2, N, mod);
  
  long Bch = 1;
  long Bmo = 1;
  for (int i = 0; i < b; i++){
    Bch = Bch * (N - i) % mod;
    Bmo = Bmo * (b - i) % mod;
  }
  Bmo = modpow(Bmo, mod - 2, mod);
  long B = Bch * Bmo % mod;
  
  long Cch = 1;
  long Cmo = 1;
  for (int i = 0; i < c; i++){
    Cch = Cch * (N - i) % mod;
    Cmo = Cmo * (c - i) % mod;
  }
  Cmo = modpow(Cmo, mod - 2, mod);
  long C = Cch * Cmo % mod;
  
  long answer = A - 1 - B - C;
  if (answer < 0) answer += 2 * mod;
  
  cout << answer % mod << endl;
  
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        EPayment solver = new EPayment();
        solver.solve(1, in, out);
        out.close();
    }

    static class EPayment {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String x = in.next();
            long ans = 0;
            int d[] = new int[x.length() + 1];
            int dp[][] = new int[x.length() + 1][2];
            for (int i = 0; i < x.length(); i++) d[i + 1] = x.charAt(i) - '0';
            dp[x.length()][0] = d[x.length()];
            dp[x.length()][1] = 10 - d[x.length()];
            for (int i = x.length() - 1; i >= 0; i--) {
                dp[i][0] = Math.min(dp[i + 1][0] + d[i], dp[i + 1][1] + 1 + d[i]);
                dp[i][1] = Math.min(dp[i + 1][0] + 10 - d[i], dp[i + 1][1] - 1 + 10 - d[i]);
            }
            out.println(Math.min(dp[0][0], dp[0][1]));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

    }
}



Measured memory_bytes: 82500
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int n,k,c;cin>>n>>k>>c;
  string s="x";
  string buf;cin>>buf;
  s+=buf;
  string a=s;
  vector<int> res;
  int sum=0;
  for(int i=n;i>0;i--){
    if(a[i]=='o'){
      res.push_back(i);
      i-=c;
      sum++;
    }
    if(sum==k)break;
  }
  sort(res.begin(),res.end());
  rep(i,k){
    //cout<<res[i]<<"\n";
  }
  int cur=0;int nxt=0;
  vector<int> ans;
  for(int i=1;i<=n;i++){
    if(cur==k)break;
    if(s[i]=='o'){
      if(i==res[cur]){
        ans.push_back(i);
      }
      rep(j,c+1){
        s[min(n,i+j)]='x';
      }
      cur++;
    }
  }
  for(int i=0;i<ans.size();i++){
    cout<<ans[i]<<"\n";
  }

  return 0;
}


Measured memory_bytes: 5492
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll H, W;
  cin>>H>>W;
  if(H==1 || W==1) cout<<1<<endl;
  else {
    if(H*W%2==0) cout<<H*W/2<<endl;
    else cout<<H*W/2+1<<endl;
  }
}



Measured memory_bytes: 256
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.immutable._
import scala.io.StdIn.readLine

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}

object Main {
  val m = (1 << 9) - 1

  def solve(sc: => Scanner): Unit = {
    val A, B = sc.nextInt
    println(A - (if (A > B) (1) else (0)))
  }

  def recursive(now: Int, A: Array[List[Int]]): Int = {
    if (A(now).size == 0) (now) else {
      val next = A(now).head
      A(now) = A(now).filter(_ != next)
      A(next) = A(next).filter(_ != now)
      recursive(next, A)
    }
  }

  def check(A: Array[List[Int]]): Boolean = {
    A.map(_.size == 0).fold(true)((a, b) => a & b)
  }

  def shift(n: Long): Long = {
    if (n == 0) (0) else if (n == 1) (1) else (shift(n - 1) << 1)
  }

  def unShift(n: Long): Long = {
    if (n == 0) (0) else (unShift(n >> 1) + 1)
  }

  def calc(v: Long): Long = (v + 1) * v / 2

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

object Util {
  def getPermutation(begin: Long = 0): Stream[Long] =
    Stream.cons(begin, getPermutation(begin + 1))

  def getPrimeList(): Stream[Long] =
    getPrimeListRecursive(getPermutation(begin = 2))

  private def getPrimeListRecursive(A: Stream[Long]): Stream[Long] =
    Stream.cons(A.head, getPrimeListRecursive(A.tail.filter(_ % A.head != 0)))

  def fib(a: Long = 0, b: Long = 1, mod: Long = Long.MaxValue): Stream[Long] = a #:: fib(b % mod, (a + b) % mod, mod)
}

Measured memory_bytes: 25408
#include<cstdio>
#include<cstring>
int main()
{
	char a[110];
	int k,l;
	scanf("%d\n%s",&k,a);
	l=strlen(a);
	if(l<=k) printf("%s",a);
	else
	{for(int i=0;i<k;i++)
	printf("%c",a[i]);
	printf("...");
	}
}

Measured memory_bytes: 3232
import sys
input=lambda: sys.stdin.readline().rstrip()
mod=10**9+7
n,k=map(int,input().split())
n_max=2*(10**5+1)
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
FI[n_max-1]=pow(F[n_max-1],mod-2,mod)
for i in reversed(range(n_max-1)):
  FI[i]=(FI[i+1]*(i+1))%mod
def comb(x,y):
  return (F[x]*FI[x-y]*FI[y])%mod

for i in range(1,k+1):
  if n-k<i-1:
    print(0)
  else:
    print((comb(k-i+i-1,k-i)*comb(n-k-(i-1)+i,n-k-(i-1)))%mod)

Measured memory_bytes: 19188
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, l; cin >> n >> l;
	string s[n];
	for(int i = 0; i < n; i++) cin >> s[i];
	sort(s, s + n);
	for(int i = 0; i < n; i++) {
		cout << s[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3596
long long fiboDP(int n) { 
    long long fibo_dp[200] = {0}; 
              fibo_dp[0] = 1;
              fibo_dp[1] = 1; 
              for(int i=2; i<=n; i++) {
                  fibo_dp[i] = fibo_dp[i-1] + fibo_dp[i-2];
                  } return fibo_dp[n]; 
     
}
int main(void){ 
    int n; scanf("%d\n", &n); 
    printf("%lld\n", fiboDP(n)); 
    return 0; } 



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;cin>>n;
    int ans = 0;
    vector<int> a(n),b(n),c(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++){
        cin>>b[i];
        ans+=b[i];
    }
    for(int i=0;i<n-1;i++){
        cin>>c[i];
    }
    //cout<<ans<<endl;
    for(int i=0;i<n-1;i++){
        if(a[i+1]-a[i]==1){
            ans+=c[a[i]-1];
        }
    }
    cout<<ans<<endl;
}

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


// A[i]~A[j] を2つに分ける位置を探す
void divideHalf( long long& F, long long& S, int i, int j, vector<long long>& A )
{
    // それぞれの和が同じくらいになる位置を二部探索
    long long s = A[j]-A[i];
    auto itr_l = lower_bound(A.begin()+i, A.begin()+j+1, s/2+A[i]);
    auto itr_s = itr_l--;
    // abs(F-S) = abs( 2*(*itr) - (A[i]+A[j]) ) を小さくする方を採用する
    //cout << abs( 2*(*itr_l)-(A[i]+A[j]) ) << " " << abs( 2*(*itr_s)-(A[i]+A[j]) ) << endl;
    if( abs( 2*(*itr_l)-(A[i]+A[j]) ) < abs( 2*(*itr_s)-(A[i]+A[j]) ) ){
        F = *itr_l-A[i];
        S = A[j]-*itr_l;
        //cout << "Large: " << distance(A.begin(), itr_l) << endl;
    }else{
        F = *itr_s-A[i];
        S = A[j]-*itr_s;
        //cout << "Small: " << distance(A.begin(), itr_s) << endl;
    }
}


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


    // 累積話
    for( int i = 1; i <= N; ++i ) A[i] += A[i-1];

    long long ans = 1e+15;
    // 真ん中の分割点について全探索
    for( int i = 2; i <= N-2; ++i ){
        long long P, Q, R, S;
        divideHalf(P, Q, 0, i, A);  // 左側
        divideHalf(R, S, i, N, A);  // 右側
        ans = min( ans, max({P,Q,R,S}) - min({P,Q,R,S}) );
        // cout << ans << endl;
    }
    cout << ans << endl;

    return 0;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    ios::sync_with_stdio(false);
  	int a, b;
  cin >> a >> b;
  cout << 6-a-b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;

int main(){
  ll N, M; cin >> N >> M;

  vector < pair<int, int> > AB(M);
  for (int i = 0; i < M; i++){
    int A, B; cin >> A >> B;
    A--; B--;
    AB[i] = make_pair(A, B);
  }

  vector <int> group(N);
  vector <ll> cnt(N);
  for (int i = 0; i < N; i++){
    group[i] = i;
    cnt[i] = 1;
  }
  
  vector <ll> ans(M + 1);

  for (int i = M - 1; i >= 0; i--){
    int A = AB[i].first, B = AB[i].second;

    int GA = group[A];
    while (GA != group[GA]){
      GA = group[GA];
    }

    int GB = group[B];
    while (GB != group[GB]){
      GB = group[GB];
    }
    
    if (GA != GB){
      ans[i] = cnt[GA] * cnt[GB];
      cnt[min(GA, GB)] += cnt[max(GA, GB)];
      group[max(GA, GB)] = min(GA, GB);
    }
    ans[i] += ans[i + 1];

  }
  
  ll all = N * (N - 1) / 2;
  for (int i = 1; i < M + 1; i++){
    cout << all - ans[i] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

int main() { IO;
  int k;
  vector<int> v(5);

  for (auto &x : v) {
    cin >> x;
  }

  cin >> k;

  bool is_good = (v[4] - v[0]) <= k;
  cout << (is_good ? "Yay!" : ":(") << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define vl vector<ll>
#define el endl;cout.flush();
#define be begin()
#define fi first
#define se second
#define br break
#define sz size()
#define en end()
#define ro return 0;
#define br break;
#define con continue;
#define um unordered_map<ll,ll>
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define forr(i,a,b) for(ll i=a;i<b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace2(a,b) cerr <<"a is " << a << " b is " << b << el;
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;
int main()
{
    ios;
    ll a , b , c , d, e ,k ;
    cin >> a >> b >> c >> d >> e >> k ;
    vl v;
    v.pb(a) ;
    v.pb(b);
    v.pb(c);
    v.pb(d);
    v.pb(e);
    sort(all(v));
    for(auto &x : v){
        cerr << x << el ;
    }
    ll flag  = -1 ;
    if(abs(v[0] - v[4] )<= k) flag = 0 ;
    if(flag == 0 ) {
        cout <<"Yay!\n";
    }
    else cout << ":(\n";
    ro;

}























Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, m;
int main() {
	while (cin >> n >> m, n | m) {
		m *= 2;
		vector<char> d(n); vector<int> v(n);
		for (int i = 0; i < n; i++) cin >> d[i] >> v[i], v[i] *= 2;
		for (int t = 0; ; t++) {
			bool ok = false;
			for (int i = 0; i < n; i++) {
				if (0 < v[i] && v[i] < m) ok = true;
			}
			if (!ok) {
				int s = 0;
				vector<pair<int, int> > w;
				for (int i = 0; i < n; i++) w.push_back(make_pair(v[i], i + 1));
				sort(w.begin(), w.end());
				for (int i = n - 1; i >= 0; i--) {
					if (w[i].first == 0 || w[i].first == m) s = w[i].second;
				}
				cout << t / 2 << ' ' << s << endl;
				break;
			}
			for (int i = 0; i < n; i++) {
				if (d[i] == 'R') v[i]++;
				else v[i]--;
			}
			vector<char> e = d;
			for (int i = 0; i < n; i++) {
				bool ok = false;
				for (int j = 0; j < n; j++) {
					if (e[i] != e[j] && v[i] == v[j]) ok = true;
				}
				if (ok && v[i] % 2 == 0) {
					if (d[i] == 'L') d[i] = 'R';
					else d[i] = 'L';
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3096
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		boolean f = false;
		for(int i=0; i<n.length(); i++) {
			if(n.charAt(i) == '7') {
				f=true;
			}
		}
		if(f) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		sc.close();
	}


}


Measured memory_bytes: 35704
#include<bits/stdc++.h>
#define N 250
using namespace std;
typedef pair<int,int> P;
map<string,int> m;
int n,x,s2,num,s;
bool ans,used[N];
vector<P> e[N];
string s1,s3;

void dfs(int x,int y,int sum){
  if(used[x])return;
  used[x]=true;
  if(x==y){
    s=sum;
    return;
  }
  for(int i=0;i<e[x].size();i++)
    dfs(e[x][i].first,y,sum+e[x][i].second);
}

int main(){
  while(1){
    cin>>n;
    if(!n)break;
    num=0;
    ans=true;
    for(int i=0;i<n;i++){
      cin>>s3>>s1>>s3;
      scanf(" 10^%d",&s2); cin>>s3;
      if(m.count(s1)&&m.count(s3)){
	s=(1e9);
	memset(used,0,sizeof(used));
	dfs(m[s1],m[s3],0);
	if(s!=(1e9)&&(s!=s2&&s!=-s2))ans=false;
      }
      if(!m.count(s1))m[s1]=num++;
      if(!m.count(s3))m[s3]=num++;
      e[m[s1]].push_back(P(m[s3],s2));
      e[m[s3]].push_back(P(m[s1],-s2));
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    for(int i=0;i<N;i++)e[i].clear();
    m.clear();
  }
  return 0;
}

Measured memory_bytes: 1308
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cmath>
#include <cstdarg>
#include <cstdlib>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
using namespace std;

typedef pair<int, int> P;

int main(int argc, char const *argv[])
{
    int h, w;
    cin >> h >> w;

    char s[h][w], res;
    int tmp[h][w];
    int white = 0;

    for (int i = 0; i < h * w; i ++) {
        cin >> res;
        if (res == '.') {
            white ++;
        }
        s[i/w][i%w] = res;
        tmp[i/w][i%w] = -1;
    }

    // 最短距離を求めれば、それと白いマスの差の絶対値が答え
    queue<P> que;
    que.push(make_pair(0, 0));
    tmp[0][0] = 0;
    int x, y, nx, ny;
    P coor;

    while (!que.empty()) {
        coor = que.front();
        que.pop();
        x = coor.first;
        y = coor.second;
        for (int dx = -1; dx < 2; dx ++) {
            for (int dy = -1; dy < 2; dy ++) {
                nx = x + dx;
                ny = y + dy;
                if (
                    dx * dy == 0 && dx != dy &&
                    0 <= nx && nx < h &&
                    0 <= ny && ny < w &&
                    s[nx][ny] == '.' &&
                    tmp[nx][ny] == -1
                ) {
                    if (nx == h-1 && ny == w-1) {
                        printf("%d\n", white - tmp[x][y] - 2);
                        return 0;
                    }
                    tmp[nx][ny] = tmp[x][y] + 1;
                    que.push(make_pair(nx, ny));
                }
            }
        }
    }
    printf("-1\n");
    return 0;
}


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

int main() {
  int n,y,m=0;
  string s;
  cin >> n >> s;
  rep(i,s.size()-1) {
    if(s[i]==s[i+1]) {
      y++;
    }else{
      m++;
    }
  }
  cout << m+1 <<endl;
  return 0;
}

Measured memory_bytes: 512
function solve()
  n,w=parse.(Int,split(readline()))
  dp=zeros(Int,n+1,w+1)
  for i=1:n
    wi,vi=parse.(Int,split(readline()))
    for j=1:w+1
      dp[i+1,j]=max(dp[i,j],(j>wi ? dp[i,j-wi]+vi : 0))
    end
  end
  println(dp[n+1,w+1])
end
solve()

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    string s; cin >> s;
    int n = s.size();

    bool ok = true;
    if (n < 4) ok = false;
    else {
        if (s.substr(0, 4) == "YAKI") ok = true;
        else ok = false;
    }

    if (ok) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 256
tenNum, roadNum = map(int, input().split())
elevs = list(map(int, input().split()))
sides = []

for _ in range(roadNum):
    sides.append(list(map(int, input().split() )))


# 展望台ごとの隣接の集合に置き換える
tenNeibors = [ [] for _ in range(tenNum)]

for side in sides:
    p1, p2 = side
    tenNeibors[p1-1].append(p2)
    tenNeibors[p2-1].append(p1)


ans = 0
for tid, tenNei in enumerate(tenNeibors):
    if len(tenNei) == 0:
        ans += 1
    else:
        selfelv = elevs[tid]
        higherFound = False
        for otherTen in tenNei:
            if elevs[otherTen-1] >= selfelv:
                higherFound = True
                break
        if higherFound == False:
            ans += 1

print(ans)

Measured memory_bytes: 41332
#include<cstdio>
#include<cstring>
char a[1005];
int s,n,e,w;
int main(){
	int l;
	scanf("%s",a);
	l=strlen(a);
	for(int i=0;i<l;i++){
		if(a[i]=='S')
			s++;
		else if(a[i]=='N')
			n++;
		else if(a[i]=='E')
			e++;
		else if(a[i]=='W')
			w++;
		else{
			printf("No");
			return 0;
		}
	}
	if(s==l||w==l||e==l||n==l)
		printf("No");
	else if((n==0&&s==0)||(e==0&&w==0))
		printf("Yes");
	else if(n!=0&&s!=0&&e!=0&&w!=0)
		printf("Yes");
	else
		printf("No");
}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
	char a[11],b[11],c[11];
	int i;
	scanf("%s %s %s",a,b,c);
	i=0;
	while(a[i]!='\0')
		i++;
	if(a[i-1]!=b[0])
	{
		printf("NO\n");
		return 0;
	}
	i=0;
	while(b[i]!='\0')
		i++;
	if(b[i-1]!=c[0])
	{
		printf("NO\n");
		return 0;
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 128
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
def point(i, t):
    if i == 0 and t == "s":
        return r
    elif i == 1 and t == "p":
        return s
    elif i == 2 and t == "r":
        return p
    else:
        return 0
ans = 0
for i in range(k):
    count = (n-i-1) // k + 1
    dp = [[0 for k in range(3)] for l in range(count)]
    dp[0][0] = max(dp[0][0], point(0, t[i]))
    dp[0][1] = max(dp[0][1], point(1, t[i]))
    dp[0][2] = max(dp[0][2], point(2, t[i]))
    for j in range(count-1):
        for l in range(3):
            if l == 0:
                dp[j+1][1] = max(dp[j+1][1], dp[j][l] + point(1,t[i+(j+1)*k]))
                dp[j+1][2] = max(dp[j+1][2], dp[j][l] + point(2,t[i+(j+1)*k]))
            if l == 1:
                dp[j+1][0] = max(dp[j+1][0], dp[j][l] + point(0,t[i+(j+1)*k]))
                dp[j+1][2] = max(dp[j+1][2], dp[j][l] + point(2,t[i+(j+1)*k]))
            if l == 2:
                dp[j+1][0] = max(dp[j+1][0], dp[j][l] + point(0,t[i+(j+1)*k]))
                dp[j+1][1] = max(dp[j+1][1], dp[j][l] + point(1,t[i+(j+1)*k]))
    ans += max(dp[-1][0], dp[-1][1], dp[-1][2])
print(ans)

Measured memory_bytes: 24216
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int h, w;
  cin >> h >> w;

  char c[h][w];
  char d[2 * h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> c[i][j];
    }
  }
  for (int i = 0; i < h; i++) {
    for (int k = 0; k < 2; k++) {
      for (int j = 0; j < w; j++) {
        cout << c[i][j];
      }
      cout << endl;
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>
#include<deque>
#include<fstream>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
#define First first
#define Second second.first
#define Third second.second
//#define MOD 998244353

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

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

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

	ll N;
	cin >> N;
	vl A(N);
	vl OUT(N, 0);
	rep(i, N) {
		cin >> A[i];
	}

	ll A1 = 0;
	ll s = 1;
	rep(i, N) {
		A1 += s * A[i];
		s *= -1;
	}

	OUT[0] = A1;

	rep(i, N-1) {
		OUT[i + 1] = (A[i] - (OUT[i] / 2)) * 2;
	}

	rep(i, N) {
		cout << OUT[i] << " ";
	}

	return 0;
}



Measured memory_bytes: 2944
#include <stdio.h>
int main(void){
 
  int n,i,l;
  int a[200000];
  int b[200000];
  
  if(scanf("%d",&n)==1);
  
  for(i=0;i<n;i++){
    if(scanf("%d",&a[i])==1);
  	b[i]=0;
  }
  
  
 for(i=0;i<n-1;i++)
    b[a[i]-1]=b[a[i]-1]+1;
    
  
  for(i=0;i<n;i++)
    printf("%d\n",b[i]);
    
   
}


Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
vector<lli> factorize(lli n) {
    vector<lli> res;
    for (lli i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            res.push_back(i);
            n /= i;
        }
    }
    if (n != 1) {
        res.push_back(n);
    }
    sort(res.begin(),res.end());
    return res;
}
int main() {
    fast;
    lli sample[9]={1,3,6,10,15,21,28,36,45};
    lli n,i,j,ans=0;
    cin>>n;
    if(n==1)
    {
        cout<<0;
        return 0;
    }
    vector<lli>v=factorize(n);
    lli count=1;
    fr(i,v.size()-1)
    {
        if(v[i]==v[i+1])
            count++;
        else
        {
            fr(j,9)
            {
                if(sample[j]==count)
                {
                    ans+=j+1;
                    break;
                }
                else if(sample[j]>count)
                {
                    ans+=j;
                    break;
                }
            }
            count=1;
        }
    }
    fr(j,9)
    {
        if(sample[j]==count)
        {
            ans+=j+1;
            break;
        }
        else if(sample[j]>count)
        {
            ans+=j;
            break;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3664
A,B,H,M = map(int,input().split())


import math

a = 360*H/12 + 30*M/60
b = 360*M/60

#print(a,b)
theta = min(a-b,360-a+b)
#print(theta)

c = A**2 + B**2 - 2*A*B*math.cos(math.radians(theta))

print(c**0.5)


Measured memory_bytes: 9496
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
signed main(){
	int s1=0,s2=0;
	int n,a[10001],b[10001];
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	for(int i=1;i<=n;i++){
		scanf("%lld",&b[i]);
	}
	for(int i=1;i<=n;i++){
		if(a[i]>b[i]) s1+=a[i]-b[i];
		if(b[i]>a[i]) s2+=(b[i]-a[i])>>1;
	}
	if(s1<=s2) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 384
n, k = map(int, input().split())
A = list(map(int, input().split()))


val = 0
for i in range(n):
    inv = 0
    sub = 0
    B = A[i + 1:] + A[:i]
    for j in range(n - 1):
        if A[i] > B[j] and j >= n - i - 1:
            inv += 1
            sub += 1
        elif A[i] > B[j]:
            inv += 1

    val += inv * k * (k + 1) // 2 - sub * k
    val %= 10 ** 9 + 7
    
print(val)

Measured memory_bytes: 42732
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const int MOD = 1000000007; 

int main() {
    string s;
    cin >> s;
    int n = s.size();
    const string keyence = "keyence";
    if (n == 7) {
        string ret = (s == keyence ? "YES" : "No");
        cout << ret << endl;
        return 0;
    }
    rep(i, 8) {
        bool is_ok = true;
        if (i > 0 && s[i-1]!=keyence[i-1]) continue;
        rng(j, i, 7) if(s[j+n-7] != keyence[j]){
            is_ok = false; 
            break;
        } 
        if (is_ok) {
            cout << "YES" << endl;
            return 0; 
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
 
const int INF = 1000;
 
// Applies the permutation perm on the bits of x.
int shuffle_bitmask(int len, const vector<int>& perm, int x) {
    int y = 0;
    for (int i = 0; i < len; i++) if (x&(1<<i)) y ^= 1<<perm[i];
    return y;
}
 
const int MAXLEN = 5;
int memo_shuffle_bitmask[MAXLEN+1][120][1<<MAXLEN];
int factorial[MAXLEN+1];
 
// Precompute the factorials and shuffle_bitmask.
// The precomputation of shuffle_bitmask is not necessary, but it makes the code
// much faster.
void preprocessing() {
    factorial[0] = factorial[1] = 1;
    for (int n = 2; n <= MAXLEN; n++) {
        int z = 0;
        factorial[n] = n * factorial[n-1];
        vector<int> perm(n);
        for (int i = 0; i < n; i++) perm[i] = i;
        while (next_permutation(perm.begin(), perm.end())) {
            for (int bb = 0; bb < (1<<n); bb++) {
                memo_shuffle_bitmask[n][z][bb] = shuffle_bitmask(n, perm, bb);
            }
            z++;
        }
    }
}
 
// Returns whether conf is name-preserving.
bool is_name_preserving(int len, const vector<int>& conf) {
    static bool arr[1<<MAXLEN];
    for (int bb = 0; bb < (1<<len); bb++) arr[bb] = false;
    for (int x: conf) arr[x] = true;
    for (int i = 0; i < factorial[len]-1; i++) {
        bool works = true;
        for (int x: conf) works &= arr[memo_shuffle_bitmask[len][i][x]];
        if (works) return false;
    }
    return true;
}
 
// Enumerate configurations of q distinct subsets of {0, ..., len-1}; counting how many are name-preserving.
// A configuration is identified with a q-subset of {0, 1, ..., (2^len)-1}.
int count_name_preserving(int len, int q, int last, vector<int>& curr) {
    if (q == 0) return is_name_preserving(len, curr);
    int res = 0;
    for (int i = last+1; i < (1<<len) and res/factorial[len] <= INF; i++) {
        curr.push_back(i);
        res += count_name_preserving(len, q-1, i, curr);
        curr.pop_back();
    }
    return res;
}
 
int solve(LL k, LL n) {
    if (k > n) swap(k, n);
    if (n > (1ll<<k)-n) return solve(k, (1ll<<k)-n);
    if (k > MAXLEN) return -1;
 
    vector<int> curr = {};
    int res = count_name_preserving(k, n, -1, curr) / factorial[k];
    return (res > INF)?-1:res;
}
 
int g(LL n) {
    if (n == 1) return 0;
    for (int k = 0; k <= n; k++) if ((1ll<<k) >= n and (1ll<<k)-g(k) >= n) return k;
    return -1;
}
 
int main() {
    preprocessing();
    
    LL N;
    cin >> N;
    LL res = solve(g(N), N);
    if (N == 4) res++;
    if (N == 7) res += 2;
    cout << res << "\n";
}

Measured memory_bytes: 3664
#dp[i+1][x]:i日目にxを選んだ時の総和の最大値

N = int(input())
dp = [[0 for i in range(3)] for j in range(N+1)]
for i in range(N):
    a, b, c = map(int, input().split())
    dp[i+1][0] = max(dp[i][1], dp[i][2]) + a
    dp[i+1][1] = max(dp[i][0], dp[i][2]) + b
    dp[i+1][2] = max(dp[i][0], dp[i][1]) + c

print(max(dp[N][0], dp[N][1], dp[N][2]))

Measured memory_bytes: 24300
o = list(input())
e = list(input())
 
oe = list()
 
while len(o) > 0 or len(e) > 0:
    if len(o) > len(e):
        oe.append(o.pop())
    else:
        oe.append(e.pop())
 
oe.reverse()
print(''.join(oe))

Measured memory_bytes: 3060
#include<cstdio>
int min(int x,int y) {return x<y?x:y;}
int c(int x) {int ret=0;while(x) {ret+=x%10;x/=10;}return ret;}
int main()
{
	int n,ans=0x3f3f3f3f;scanf("%d",&n);
	for(int i=1;i<=n/2;i++) ans=min(ans,c(i)+c(n-i));
	printf("%d\n",ans);
	return 0;
}

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

int main()
{
    string a,b;
    cin>>a>>b;
    if(a==b){
        cout<<"EQUAL\n";
    }
    else if(a.size()>b.size())cout<<"GREATER"<<endl;
    else if(a.size()<b.size())cout<<"LESS"<<endl;
    else if(a>b)cout<<"GREATER"<<endl;
    else cout<<"LESS"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
constexpr int MOD = 1e9 + 7;

int N,n;
ll a[200010],h[200010];
vector<ll> dp; // dp[i] := 高さiまでの総和の最大値

// seg tree (0-indexed)
void update(int i,ll x){
    i += n - 1;
    dp[i] = x;
    while(i){
        i = (i-1)/2;
        dp[i] = max(dp[i*2+1],dp[i*2+2]);
    }
}

ll query(int i,int k=0,int l=0,int r=n){
    if(r<=0 || i<=l) return 0;
    if(0<=l && r<=i) return dp[k];
    return max(query(i,k*2+1,l,(l+r)/2),query(i,k*2+2,(l+r)/2,r));
}

int main(){
    cin >> N;
    int t;
    for(int i=0;i<N;++i){
        cin >> t;
        h[i] = --t;
    }
    for(int i=0;i<N;++i) cin >> a[i];

    // init seg tree
    n = 1;
    while(N>n) n *= 2;
    dp.assign(n*2-1,0);
    //

    for(int i=0;i<N;++i){
        ll tmp = query(h[i]) + a[i];
        update(h[i],tmp);
    }
    cout << query(n) << endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    int n = s.size();
    if (s[0]==s[n-1]){
        if (n%2==0){
            cout<<"First\n";
        }else{
            cout<<"Second\n";
        }
        return 0;
    }
    if (n%2==0){
        cout<<"Second\n";
    }else{
        cout<<"First\n";
    }
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;

int count_block(int n)
{
  return n * (n + 1) * (n + 2) / 6;
}

int main()
{
  int block_num = 0;
  int cnt = 1;
  vector<int> block_nums;
  while (true)
  {
    block_num = count_block(cnt);
    if (block_num > 1000000)
    {
      break;
    }
    block_nums.push_back(block_num);
    cnt += 1;
  }
  int size_block_nums = block_nums.size();
  vector<int> dp(1000000 + 1, INF);
  vector<int> odd_dp(1000000 + 1, INF);
  dp.at(0) = 0;
  odd_dp.at(0) = 0;
  for (int i = 0; i < 1000000; ++i)
  {
    for (int j = 0; j < size_block_nums; ++j)
    {
      int next_num = i + block_nums.at(j);
      if (next_num > 1000000)
      {
        break;
      }
      int temp = dp.at(i) + 1;
      if (dp.at(i + block_nums.at(j)) > temp)
      {
        dp.at(i + block_nums.at(j)) = temp;
      }
      if (block_nums.at(j) % 2 == 1)
      {
        temp = odd_dp.at(i) + 1;
        if (odd_dp.at(i + block_nums.at(j)) > temp)
        {
          odd_dp.at(i + block_nums.at(j)) = temp;
        }
      }
    }
  }
  while (true)
  {
    int n;
    cin >> n;
    if (n == 0)
    {
      break;
    }
    // for (int i = 0; i < block_nums.size(); ++i)
    // {
      //   cout << block_nums.at(i) << endl;
      // }
    cout << dp.at(n) << ' ' << odd_dp.at(n) << endl;

    // for (int i = 0; i < n + 1; ++i)
    // {
    //   dp.at(i) = INF;
    // }
    // dp.at(0) = 0;
    // for (int i = 0; i < n; ++i)
    // {
    //   for (int j = 0; j < size_block_nums; ++j)
    //   {
    //     if (block_nums.at(j) % 2 == 0)
    //     {
    //       // cout << block_nums.at(j) << endl;
    //       continue;
    //     }
    //     int next_num = i + block_nums.at(j);
    //     if (next_num > n)
    //     {
    //       break;
    //     }
    //     int temp = dp.at(i) + 1;
    //     if (dp.at(i + block_nums.at(j)) > temp)
    //     {
    //       dp.at(i + block_nums.at(j)) = temp;
    //     }
    //   }
    // }
    // // for (int i = 0; i < n + 1; ++i)
    // // {
    // //   cout << dp.at(i) << endl;
    // // }
    // cout << dp.at(n) << endl;
  }
}



Measured memory_bytes: 10608
def solve():
    S = set(input())
    alph = set("qwertyuiopasdfghjklzxcvbnm")
    nonS = sorted(alph-S)
    if len(nonS) == 0:
        print("None")
    else:
        print(nonS[0])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3188