akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<cstdio>

using namespace std;

long long in;
long double judge;

int getketa(int in){
  int sum = 0;
  while(in){
    in/=10;
    sum++;
  }
  return sum;
}

void make(){
  //int keta = getketa(in);
  judge = 0.1 * in;
  judge++;
  //for(int i = 0; i < 5+keta; i++) judge *= 0.1;
  //judge += 0.00001;
  // cout << judge << endl;
}
int main(){

  while(cin >> in){
    if(in == -1) break;
    make();
    long double x = in/2;
    while(1){
      x = 2*x/3+in/x/x/3;
      if(fabs(x*x*x - in)*10*10*10*10*10 < judge) break;
    }
    printf("%.6Lf\n",x);
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<math.h>
#include<vector> 
using namespace std;
int main()
{int a,b,c,d;
 cin>>a>>b>>c>>d;
 int ans=min(a+c,min(a+d,min(b+c,b+d)));
 cout<<ans<<endl; 
 system("pause");
 return 0;
 } 
  

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

typedef long long ll;
using namespace std;
 
int main (){
  int h,w;
  cin >> h >> w;
  char c[h][w];

  rep(i,0,h){
    rep(j,0,w){
      cin >> c[i][j];
    }
  }
  rep(i,0,h){
    rep(j,0,w){
      cout << c[i][j];
    }
    printf("\n");
    rep(j,0,w){
      cout << c[i][j];
    }
    printf("\n");
  }
  return 0;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var K = int.Parse(Console.ReadLine());
            var len = s.Length;
            var array = new HashSet<string>();

            for (var i = 0; i < len; i++)
            {
                array.Add(s[i].ToString());
                var st = s[i].ToString();
                for (var j = i + 1; j < len; j++)
                {
                    array.Add(st += s[j].ToString());
                    if (st.Length == K) break;
                }
            }

            var ret = array.OrderBy(z => z).ToArray();

            Console.WriteLine(ret[K-1]);
        }
    }
}


Measured memory_bytes: 15328
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
vector<vi> G;

void dfs(int v, int d, vi& dist){
    if(dist[v] >= 0) return;
    dist[v] = d;

    for(auto& nv : G[v]){
        dfs(nv, d + 1, dist);
    }
}

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

    int n, A, B; cin >> n >> A >> B;
    A--, B--;

    G = vector<vi>(n);
    rep(_, n - 1){
        int a, b; cin >> a >> b;
        a--, b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    vi dA(n, -1), dB(n, -1);
    dfs(A, 0, dA);
    dfs(B, 0, dB);

    int res = 0;
    rep(i, n){
        int da = dA[i], db = dB[i];
        if(da >= db){
            continue;
        }
        int cur = db - 1;
        chmax(res, cur);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort(v.rbegin(), v.rend())
typedef pair<int, int> pii;

ll exp(ll taban, ll us) {
    ll carpan = taban % mod;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
} 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
} 
ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	double r; cin>>r;
	cout<<2 * 4*atan(1)*r<<endl;
}


Measured memory_bytes: 3804
#include<stdio.h>
int bomb(int y,int x);
char maps[8][8];
int dy[12]={-1,-2,-3,0,0,0,1,2,3,0,0,0};
int dx[12]={0,0,0,1,2,3,0,0,0,-1,-2,-3};
int main(){
  int n;
  int y,x;
  int i,j,l;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=0;j<8;j++){
      for(l=0;l<8;l++){
	scanf(" %c",&maps[j][l]);
      }
    }
    scanf("%d %d",&x,&y);
    x--;
    y--;
    bomb(y,x);
    printf("Data %d:\n",i);
    for(j=0;j<8;j++){
      for(l=0;l<8;l++){
	printf("%c",maps[j][l]);
      }
      printf("\n");
    }
  }
  return 0;
}

int bomb(int y,int x){
  maps[y][x]='0';
  int rec=0,ny,nx;
  int i;
  for(i=0;i<12;i++){
    ny=y+dy[i];
    nx=x+dx[i];
    if(ny>=0&&ny<8&&nx>=0&&nx<8&&maps[ny][nx]!='0'){
      rec+=bomb(ny,nx);
    }
  }
  return rec;
}

Measured memory_bytes: 1028
import sys
input = sys.stdin.readline

def make_Graph(N, edges):#頂点の名前はi - 1で受け付ける
    graph = [ [] for i in range(N)]
    for edge in edges:
        a, b, c = edge
        graph[a].append((b,c))
        graph[b].append((a,c))
    return graph

def BFS(N, graph, start):
    Q = []
    V = []
    prev = [None] * N
    dd = [float("inf")] * N
    Q.append(start)
    dd[start] = 0
    while len(V) < N:
        a = Q.pop(0)
        V.append(a)
        for b, c in graph[a]:
            if b != prev[a]:
                Q.append(b)
                prev[b] = a
                dd[b] = dd[a] + c
    return dd

def DFS(N, graph, a, p, d):
    dd[a] = d
    for b, c in graph[a]:
        if b == p or dd[b] != 0:
            continue
        else:
            DFS(N, graph, b, a, d + c)

N = int(input())

sys.setrecursionlimit(100)

graph = [ [] for i in range(N)]
for i in range(N-1):
    a, b, c = (int(j) for j in input().split())
    graph[a-1].append((b-1,c))
    graph[b-1].append((a-1,c))

Q, K =(int(i) for i in input().split())
dd = [0] * N

try:
    DFS(N, graph, K-1, -1, 0)
except:
    dd = BFS(N, graph, K-1)

for i in range(Q):
    x, y = (int(a) for a in input().split())
    print(dd[x-1] + dd[y-1])

Measured memory_bytes: 87200
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n];

    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }

    for(int i=k;i<n;i++)
    {
        if(a[i]>a[i-k])
        {
            cout<<"Yes\n";
        }

        else
        {
            cout<<"No\n";
        }
    }

    return 0;
}


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

void solve() {
    int H, W, D, A;
    cin >> H >> W >> D;
    vector<int> h(H * W), w(H * W);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> A;
            h.at(A - 1) = i;
            w.at(A - 1) = j;
        }
    }
    vector<int> m(H * W, 0);
    for (int i = D; i < H * W; i++) {
        m.at(i) = m.at(i - D) + abs(h.at(i) - h.at(i - D)) + abs(w.at(i) - w.at(i - D));
    }
    int Q, L, R;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        cin >> L >> R;
        cout << m.at(R - 1) - m.at(L - 1) << endl;
    }
    return;
}

int main() {
    solve();
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   int a, b;
   char op;
   while (1) {
      cin >> a >> op >> b;
      if (op == '?')
         break;
      else if (op == '+')
         cout << a + b << endl;
      else if (op == '-')
         cout << a - b << endl;
      else if (op == '*')
         cout << a * b << endl;
      else if (op == '/')
         cout << a / b << endl;
   }
   return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
typedef long long ll;
using namespace std;

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    rep(i,a,b+1) {
        if (i%k==0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3104
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

a, b = nm()
print(a*b)

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

int main() {
  int A, B;
  float T;
  scanf("%d%d%f", &A, &B, &T);
  T += 0.5;

  double time = 0.0;
  int ans = 0;
  while (time + (double)A < T) {
    ans += B;
    time += (double)A;
  }

  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n=0;
  int x,y,b,p;
  int max=0;
  int num=0;
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d %d %d",&x,&y,&b,&p);
    max=x*b+y*p;
    if(b<5) b=5;
    if(p<2) p=2;
    num=((x*b)+(y*p))*0.8;
    if(max<num)
      printf("%d\n",max);
    else 
      printf("%d\n",num);
    if(b==0&&p==0)
      printf("0\n");
    max=0,num=0;
  }
  return 0;
}

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

namespace AtCoder.Abc
{
    class Abc_087_B
    {
        public static void Main(string[] args)
        {
            // 整数の入力
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int c = int.Parse(Console.ReadLine());
            int x = int.Parse(Console.ReadLine());
            int result = 0;

            for (int i = 0; i <= a; i++)
            {
                for (int j = 0; j <= b; j++)
                {
                    for (int k = 0; k <= c; k++)
                    {
                        int total = 500 * i + 100 * j + 50 * k; // 合計金額
                        if (total == x) result++; // 合計金額が X に一致したら答えをインクリメント
                    }
                }
            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdlib>
#include <set>
#include <queue>
using namespace std;

#define X first
#define Y second
#define N 62
typedef long long ll;
typedef pair<int,int> pii;
const int Mod=1000000007;

const double INF=1e18;


int main()
{
	//freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
	
	int a,b; char op;
	scanf("%d %c %d",&a,&op,&b);
	if (op=='+') printf("%d\n",a+b);
	else printf("%d\n",a-b);
	
	return 0;

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 102, inf = 1e6; int n, m;
char mat[maxN][maxN + 1];

int di[2] = {1, 0}, dj[2] = {0, 1};
struct Node
{
  int i, j, d;
  bool operator<(const Node &other) const { return d > other.d; };
};
int dist[maxN][maxN];
int dijkstra()
{
  for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) dist[i][j] = inf;
  priority_queue<Node> pq;
  pq.push(Node{0, 0, dist[0][0] = mat[0][0] == '#'});
  while (!pq.empty())
  {
    Node u = pq.top(); pq.pop();
    if (u.d > dist[u.i][u.j]) continue;
    for (int k = 0; k < 2; k++)
    {
      int ni = u.i + di[k], nj = u.j + dj[k];
      if (ni >= n || nj >= m) continue;
      if (dist[u.i][u.j] + (mat[ni][nj] == '#') < dist[ni][nj])
        pq.push(Node{ni, nj, dist[ni][nj] = dist[u.i][u.j] + (mat[ni][nj] == '#')});
    }
  }
  return dist[n - 1][m - 1];
}

int memo[maxN][maxN][2];
int solve(int i = 0, int j = 0, char wasInside = false)
{
  if (i >= n || j >= m) return inf;
  if (i == n - 1 && j == m - 1) return wasInside || (mat[i][j] == '#' && !wasInside);
  if (memo[i][j][wasInside] != -1) return memo[i][j][wasInside];
  
  int ans = min(solve(i + 1, j, mat[i][j] == '#'), solve(i, j + 1, mat[i][j] == '#'));
  ans += wasInside && mat[i][j] == '.';

  return memo[i][j][wasInside] = ans;
}

int main()
{
  while (scanf("%d %d", &n, &m) != EOF)
  {
    for (int i = 0; i < n; i++)
      scanf(" %s", mat[i]);

    memset(memo, -1, sizeof(memo));
    int ans = solve();
    DEBUG printf("%d - ", dijkstra());
    printf("%d\n", ans);
  }
  return 0;
}

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

int main(){
  long long int n,a;
  cin>>n>>a;
  vector<long long int> x(n);
  long long int mx=0;
  for(int i=0;i<n;i++){
    cin>>x[i];
    mx=max(mx,x[i]);
    x[i]-=a;
  }
  //vector< vector< vector<int> > > dp(n,vector< vector<int> >(n,vector<int>(n,0)));
  vector<vector<long long int> > dp(n+1,vector<long long int>(n*mx*2,0));

  dp[0][n*mx]=1;

  for(int i=1;i<n+1;i++){
    //cout<<x[i]<<endl;
    for(int j=0;j<n*mx*2;j++){
        dp[i][j]=dp[i-1][j]+dp[i-1][j-x[i-1]];
    }
  }

  cout<<dp[n][n*mx]-1<<endl;
  return 0;
}


Measured memory_bytes: 2304
"use strict";
function I(s,f){this._s=s.split("\n");this._c=0;this._l=0;this._f=f||Number}I.prototype.a=function(){var l=this._s[this._l];if(!l)return;var t=l.trim().split(" ");var a=t[this._c];this._c++;if(t.length===this._c){this._c=0;this._l++}return this._f(a)};I.prototype.l=function(){var l=this._s[this._l];if(!l)return;this._c=0;this._l++;return l.split(" ").map(this._f)};
function PriorityQueue(t,i){this._pq=[null].concat(t),this._cf=i||function(t,i){return t>i};for(let t=Math.floor(this._pq.length/2);t>=1;t--)this._maxHeapify(t)}PriorityQueue.prototype._parent=function(t){return Math.floor(t/2)},PriorityQueue.prototype._left=function(t){return 2*t},PriorityQueue.prototype._right=function(t){return 2*t+1},PriorityQueue.prototype._maxHeapify=function(t){(function t(i){let e=this._left(i),p=this._right(i),r=i;if(e<this._pq.length&&this._cf(this._pq[e],this._pq[i])&&(r=e),p<this._pq.length&&this._cf(this._pq[p],this._pq[r])&&(r=p),r!==i){let e=this._pq[i];this._pq[i]=this._pq[r],this._pq[r]=e,t.call(this,r)}}).call(this,t)},PriorityQueue.prototype.maximum=function(){return this._pq[1]},PriorityQueue.prototype.extractMax=function(){if(this._pq.length<=1)return;let t=this._pq[1];return this._pq[1]=this._pq[this._pq.length-1],this._pq.pop(),this._maxHeapify(1),t},PriorityQueue.prototype.increaseKey=function(t,i){let e=t;if(!this._pq[e]||this._cf(i,this._pq[e]))for(this._pq[e]=i;e>1&&!this._cf(this._pq[this._parent(e)],this._pq[e]);){let t=this._pq[e];this._pq[e]=this._pq[this._parent(e)],this._pq[this._parent(e)]=t,e=this._parent(e)}},PriorityQueue.prototype.insert=function(t){this._pq.push(null),this.increaseKey(this._pq.length-1,t)},PriorityQueue.prototype.size=function(t){return this._pq.length-1};

function main(input) {
  var o = new I(input);

  var n = o.a();
  var k = o.a();

  var td = [];
  for (var i = 0; i < n; i++) {
    var t = o.a();
    var d = o.a();
    td.push({t,d});
  }

  td.sort((a,b) => b.d - a.d);

  var results = [];

  var curD = 0;
  var curT = 0;
  var dup = [];
  var mark = {};
  for (var i = 0; i < k; i++) {
    if (mark[td[i].t]) {
      dup.push(td[i]);
    } else {
      curT += 1;
      mark[td[i].t] = true;
    }

    curD += td[i].d;
  }

  results.push(curD + curT * curT);

  var pq = new PriorityQueue(dup, (a,b) => a.d < b.d);

  var i = k;
  while(pq.size() > 0 && i < n) {
    if (mark[td[i].t] !== true) {
      curT += 1;
      mark[td[i].t] = true;
      var min = pq.extractMax();
      curD -= min.d;
      curD += td[i].d;
      results.push(curD + curT * curT);
    }
    i += 1;
  }

  console.log(results.sort((a,b) => b - a)[0]);
}


main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 56864
import java.util.*;

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

        if (S.equals("AAA") || S.equals("BBB")) {
            System.out.println("No");
        }

        else {
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 21844
/// ببِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
     ios_base::sync_with_stdio(false);cin.tie(NULL);
     ll int i,n,t,p=INT_MAX,j=0,x,a=0,b,l=0,r=0,y,k,c;
     string s,m;
     cin>>a>>b;
     p=(a*(a-1))/2+(b*(b-1))/2;
     cout<<p<<endl;

     return EXIT_SUCCESS;
}




Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
ll mod=1000000007;
typedef pair<int, int> P;

int main()
{
    string S;
    cin >> S;
    int N=S.size(), c0=0, c1=0;//c1はiが奇数
    vector<int> ans(N, 0);
    bool flag=true;
    for(int i=0; i<N; i++){
        if(S[i]=='R'){
            flag=true;
            if(i%2==1) c1++;
            else c0++;
        }else{
            if(!flag) continue;
            flag=false;
            if(i%2==0){
                ans[i]+=c0;
                ans[i-1]+=c1;
            }else{
                ans[i]+=c1;
                ans[i-1]+=c0;
            }
            c0=0,c1=0;
        }
    }

    c0=0,c1=0;
    flag=true;
    for(int i=N-1; i>=0; i--){
        if(S[i]=='L'){
            flag=true;
            if(i%2==1) c1++;
            else c0++;
        }else{
            if(!flag) continue;
            flag=false;
            if(i%2==0){
                ans[i]+=c0;
                ans[i+1]+=c1;
            }else{
                ans[i]+=c1;
                ans[i+1]+=c0;
            }
            c0=0;
            c1=0;
        }
    }
    for(int i=0; i<N-1; i++){
        cout << ans[i] << ' ';
    }
    cout << ans[N-1] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;
 
int n, m, k, a[N], b[N], pr[N], cp[N], cm[N];
 
int fnd(int p) {
	return pr[p]==p ? p : pr[p] = fnd(pr[p]);
}
 
int main() {
	int i, x, y;
	cin >> n >> m >> k;
	for(i=1; i<=n; i++) pr[i] = i, cp[i] = 1;
	while(m--) {
		scanf("%d%d", &x, &y);
		cm[x]++, cm[y]++;
		x = fnd(x); y = fnd(y);
		if(x != y) {
			pr[y] = x;
			cp[x] += cp[y];
		}
	}
	while(k--) {
		scanf("%d%d", &x, &y);
		if(fnd(x) == fnd(y)) cm[x]++, cm[y]++;
	}
	for(i=1; i<=n; i++) {
		printf("%d ", cp[fnd(i)] - cm[i] - 1);
	}
	return 0;
}

Measured memory_bytes: 2560
W=87,i,n;char a[100002],s[100002];f(x,y){*a=x;a[1]=y;for(i=0;++i<=n;)a[i+1]=a[i]==W^a[i-1]==W^s[i]=='o'?83:W;strncmp(a,a+n,2)==0?a[n]=0,puts(a),exit(0):0;}main(){scanf("%d%s",&n,&s);s[n]=*s;s[n+1]=s[1];f(83,83);f(83,W);f(W,83);f(W,W);puts("-1");}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class SegmentTree:
    def __init__(self, array, operator, identity_element):
        _len = len(array)
        self.__op = operator
        self.__size = 1 << (_len - 1).bit_length()
        self.__tree = [identity_element] * self.__size + \
            array + [identity_element] * (self.__size - _len)
        self.__ie = identity_element

        for i in range(self.__size - 1, 0, -1):
            self.__tree[i] = operator(
                self.__tree[i * 2], self.__tree[i * 2 + 1])

    def update(self, i, v):
        i += self.__size
        self.__tree[i] = v
        while i:
            i //= 2
            self.__tree[i] = self.__op(
                self.__tree[i * 2], self.__tree[i * 2 + 1])

    def query(self, l, r):
        """[l, r)
        """
        l += self.__size
        r += self.__size
        ret = self.__ie
        while l < r:
            if l & 1:
                ret = self.__op(ret, self.__tree[l])
                l += 1
            if r & 1:
                r -= 1
                ret = self.__op(ret, self.__tree[r])
            l //= 2
            r //= 2
        return ret

from collections import Counter

def slv(N, K, A):
    B = [0]
    for i, a in enumerate(A, start=0):
        B.append((B[-1] + a) % K)

    for i in range(len(B)):
        B[i] = (B[i] - i) % K

    ans = 0
    C = Counter()
    n = 0
    for i, b in enumerate(B):
        C[b] += 1
        n += 1
        if n > K:
            C[B[i-K]] -= 1
            n -= 1
        ans += C[b] - 1

    return ans



def main():
    N, K = read_int_n()
    A = read_int_n()
    print(slv(N, K, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 87696
#include<iostream>
#include<string.h>
using namespace std;

int D[6];
void spin(char c)
{
  if(c=='E'){
    swap(D[0],D[3]);swap(D[3],D[5]);swap(D[5],D[2]);
  }
  else if(c=='W'){
    swap(D[0],D[2]);swap(D[2],D[5]);swap(D[5],D[3]);
  }
  else if(c=='S'){
    swap(D[0],D[1]);swap(D[0],D[4]);swap(D[4],D[5]);
  } 
  else if(c=='N'){
    swap(D[0],D[1]);swap(D[1],D[5]);swap(D[5],D[4]);
  }
}
int main()
{
  char M[101];

  for(int i=0;i<6;i++)cin>>D[i];
  cin>>M;

  for(int i=0;i<strlen(M);i++)spin(M[i]);

  cout<<D[0]<<endl;

  return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    string S;
    int w;
    cin >> S >> w;
    REP(i, S.length())
    {
        if (i % w == 0)
            cout << S[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
c = [list(map(int, input().split())) for k in range(10)]
A = [list(map(int, input().split())) for k in range(H)]

for p in range(10):
    for q in range(10):
        for r in range(10):
            c[q][r] = min(c[q][r], c[q][p]+c[p][r])

ans = 0
for k in range(H):
    for l in range(W):
        if A[k][l] >= 0:
            ans += c[A[k][l]][1]
print(ans)


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

int main(){
  ll n,k;
  cin >> n >> k;
  ll a=n%k;
  if(a==0){
    int b=0;
    cout << b << endl;
    return 0;
  }
  ll ans=min(a,abs(a-k));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

// AtCoder
// #include <atcoder/all>
// using namespace atcoder;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<P> d(n);
    for (auto &e : d) cin >> e.first >> e.second;
    bool ok = false;
    int count = 0, m = 0;
    rep (i, n) {
        if (d[i].first == d[i].second) {
            count++;
        } else {
            count = 0;
        }
        chmax(m, count);
    }
    if (m >= 3) cout << "Yes\n";
    else cout << "No\n";
    /***************************************************/
    /* Submit this code from the browser if using ACL! */
    /***************************************************/
    return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  vector<ll> X(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i];
  }
  vector<ll> dp(N);
  dp[0] = 0;
  for (int i = 1; i < N; i++) {
    dp[i] = dp[i - 1] + min((X[i] - X[i - 1]) * A, B);
  }
  cout << dp[N - 1] << endl;
  return 0;
}

Measured memory_bytes: 4832
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#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(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

void prime_factorization(ll N, map<ll, int>& res) {
  if(N == 1 || N == 0) return;
  ll n = N;
  ll i = 2;
  while(n >= i * i) {
    while(n % i == 0) {
      if(res.count(i)) res[i]++;
      else res[i] = 1;
      n /= i;
    }
    if(i == 2) i++;
    else i += 2;
  }
  if(n != 1) res[n] = 1;
}
#define MAX_N 2000005
ll inv[MAX_N], fac[MAX_N], finv[MAX_N];
void make() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i=2; i<MAX_N; i++) {
    inv[i] = mod - inv[mod%i] * (mod/i) % mod;
    fac[i] = fac[i-1] * (ll)i % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}
ll perm(ll n, ll r) {
  if(n < 0)       return 0;
  else if(n < r)  return 0;
  else            return (fac[n] * finv[n-r]) % mod;
}
ll comb(ll n, ll r) {
  ll ans = 1;
  ans = perm(n, r);
  ans = (ans * finv[r]) % mod;
  return ans;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  make();
  int n; ll m; cin >> n >> m;
  map<ll, int> res;
  prime_factorization(m, res);
  ll ans = 1;
  for(auto ele: res) {
    ll cnt = ele.second;
    (ans *= comb(cnt+n-1, cnt)) %= mod;
  }
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 50544
N = int(input())
l1 = []
for i in range(N):
    l1.append(int(input()))
l1.sort()
if N == 3 :
    l2 = l1
else :
    l2 = l1[:4]
l3 = []
for i in range(len(l2)):
    for j in range(len(l2)):
        if i == j:
            continue
        l3.append(int(str(l2[i])+str(l2[j])))
l3.sort()
print(l3[2])


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

#define MAXN 100010
#define INF 1000000007

using namespace std;

char s[MAXN];
long long n;
long long pd[30][30];
long long quant[30];

int main() {
    scanf("%lld", &n);
    scanf("%s", s+1);
    long long i, j;
    for (i=1; i<=n; i++) {
        quant[s[i]-'a'+1]++;
    }

    for (j=1; j<=26; j++) {
        pd[0][j]=0;
    }
    for (i=0; i<=26; i++) {
        pd[i][0]=1;
    }
    for (i=1; i<=26; i++) {
        for (j=1; j<=26; j++) {
            pd[i][j]=pd[i-1][j] + pd[i-1][j-1]*quant[i];
            pd[i][j]%=INF;
        }
    }
    long long res = 0;
    for (j=1; j<=26; j++) {
        res += pd[26][j];
        res %= INF;
    }

    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 384
import java.util.*;

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

class Point {
    int x;
    int y;

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

    public int distanceTo(Point other) {
        return Math.abs(x - other.x) + Math.abs(y - other.y);
    }

    public String toString() {
        return String.format("(%d, %d)", x, y);
    }
}

class Solver {

    private boolean paintable(char[][] s, int H, int W, int i, int j) {
        boolean ok = false;
        if (i - 1 >= 0 && s[i - 1][j] == '#') ok = true;
        if (j - 1 >= 0 && s[i][j - 1] == '#') ok = true;
        if (i + 1 < H  && s[i + 1][j] == '#') ok = true;
        if (j + 1 < W  && s[i][j + 1] == '#') ok = true;

        return ok;
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();

        char[][] s = new char[H][];
        for (int i = 0; i < H; i++) {
            s[i] = sc.next().toCharArray();
        }

        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (s[i][j] == '#' && !paintable(s, H, W, i, j)) {
                    System.out.println("No");
                    return;
                }
            }
        }

        System.out.println("Yes");
        return;
    }

}

Measured memory_bytes: 23124
<?php

fscanf(STDIN, '%s %s', $a, $b);

if ($a === 'H') {
    if ($b === 'H') {
        echo 'H';
    } else {
        echo 'D';
    }
} else {
    if ($b === 'H') {
        echo 'D';
    } else {
        echo 'H';
    }
}

echo PHP_EOL;


Measured memory_bytes: 15908
n = int(input())
p = map(int, input().split())
pp = list(range(1, n+1))

count = 0
for i, j in zip(p, pp):
    if i != j:
        count += 1
    if count == 3: break

if count < 3:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
//mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count());
//int rnd(int x) { return mrand()%x;}
typedef long long ll;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
int main(){
	ll a,b,n;
	scanf("%lld%lld%lld",&a,&b,&n);
	int ans=0;
	//if((b+a-1)/a<=n){
	//	ans=max(1ll*ans,((b+a-1)/a)*a/b-a*((b+a-1)/a/b));
	//}
	n=min(n,b-1);
	ans=max(ans*1ll,(a*n)/b-a*(n/b));
	for(int i=0;i<=min(a,n);i++){
		ans=max(1ll*ans,(a*i)/b-a*(i/b));
	}
	printf("%d\n",ans);
	return 0;
}


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

int main(){
	int n,k; cin>>n>>k;
	vector<int> v(n);
	rep(i,n) cin>>v[i];
	sort(all(v));
	int ans=0;
	rep(i,k) ans+=v[i];
	cout << ans << endl;	
}

Measured memory_bytes: 3592
while 1:
    a = input().split()
    if a[1] == '?':
        break
    elif a[1] == '+':
        print(int(a[0])+int(a[2]))
    elif a[1] == '-':
        print(int(a[0])-int(a[2]))
    elif a[1] == '*':
        print(int(a[0])*int(a[2]))
    elif a[1] == '/':
        print(int(a[0])//int(a[2]))


Measured memory_bytes: 5600
import collections

n,m = list(map(int,input().split()))

coriddorList = [set() for i in range(n+1)]
deepList = [-1 for i in range(n+1)]


for i in range(m):
    a,b = list(map(int,input().split()))
    coriddorList[a].add(b)
    coriddorList[b].add(a)

checkList = [0] * (n + 1)
ansList = [0] * (n + 1)
checkList[1] = 1
q = collections.deque()
q.appendleft(1)

while len(q) > 0:
    value = q.pop()
    for k in coriddorList[value]:
        if checkList[k] == 0:
            checkList[k] = 1
            ansList[k] = value
            q.appendleft(k)

print("Yes")
for i in range(2,n+1):
    print(ansList[i])

Measured memory_bytes: 64432
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    int n;
    cin >> n;
    cout << lcm(n, 2) << endl;
    return 0;
}

Measured memory_bytes: 3620
N = int(input())
mod = 10 ** 9 + 7
D = [{} for i in range(N + 1)]

def check(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i - 1], t[i] = t[i], t[i - 1]
        if ''.join(t).count('AGC') >= 1:
            return False
    return True
    
def dfs(cur, last3):
    if last3 in D[cur]:
        return D[cur][last3]
    if cur == N:
        return 1
    res = 0
    for c in 'ACGT':
        if check(last3 + c):
            res = (res + dfs(cur + 1, last3[1:] + c)) % mod
    D[cur][last3] = res
    return res
    
print(dfs(0, '000'))

Measured memory_bytes: 3856
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define inf 1000000005
#define all(a) (a).begin(), (a).end()
#define ms(a,x) memset(a, x, sizeof(a))
#define mod 1000000007
#define sz(a) ((ll)(a).size())

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcnt(s);}
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
#define eps 1e-12
typedef pair<int, int> II;
typedef pair<ll, ll> LL;
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define PI (2 * acos((ld)0))
#define linf (1ll << 60)
#define y1 y32432
#define y0 y435346

#define maxn 500005

int n, a[maxn], b[maxn], numa[maxn], numb[maxn];
vector<int> V[maxn];
vector<int> VV;
bool flag[maxn];
int que[maxn], size;

int main()
{
//	freopen("in.txt", "r", stdin);

	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n;
	int XO = 0, xo;
	For(i, 1, n){
		cin >> a[i];
		XO ^= a[i];
		VV.pb(a[i]);
	}
	For(i, 1, n){
		cin >> b[i];
		VV.pb(b[i]);
	}
	VV.pb(XO);

	sort(all(VV));

	ms(numa, 0); ms(numb, 0);
	For(i, 1, n){
		int ta = lower_bound(all(VV), a[i]) - VV.begin() + 1;
		int tb = lower_bound(all(VV), b[i]) - VV.begin() + 1;
		if(ta != tb){
			numa[ta]++;
			numb[tb]++;
			V[ta].pb(tb);
			V[tb].pb(ta);
		}
	}
	xo = lower_bound(all(VV), XO) - VV.begin() + 1;

	ms(flag, 0);

	ll res = 0;
	bool ok = true;
	For(i, 1, n + n + 2) if(sz(V[i]) && !flag[i]){
		size = 0;
		que[size++] = i;
		flag[i] = 1;
		int numedge = 0;
		bool havexo = 0;
		Rep(t, size){
			int u = que[t];
			if(u != xo && numb[u] > numa[u]){
				ok = false;
			}
			if(u == xo && (numb[u] < numa[u] || numb[u] > numa[u] + 1)) ok = false;
			if(u == xo) havexo = 1;
			Rep(j, sz(V[u])){
				numedge++;
				int v = V[u][j];
				if(!flag[v]){
					flag[v] = 1;
					que[size++] = v;
				}
			}
		}
		if(havexo) res += numedge / 2;
		else res += numedge / 2 + 1;

	}
	if(!ok){
		cout << -1 << endl;
	}
	else cout << res << endl;

	return 0;
}


Measured memory_bytes: 23028
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		//入力値X,Kを取得
		int X = scan.nextInt();
		int K = scan.nextInt();
		
		int min = K-(X-1);
		int max = K+(X-1);
		
		int range = max-min;
		int answer = min;
		
		for(int i=0; i <= range; i++) {
						
			System.out.print(answer + " ");
			answer++;
		}
	}
}

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

int main() {
    
    string S;
    
    cin >> S;
    
    int win = 0;
    int lose = 0;
    
    for ( int i = 0; i < S.length(); i++ ) {
        if ( S.substr( i, 1 ) == "p" && (i%2) == 0 ) { lose++; }
        if ( S.substr( i, 1 ) == "g" && (i%2) == 1 ) { win++; }
    }
    
    cout << win - lose << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 998244353;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

  i64 h, w;
  cin >> h >> w;

  if(h == 1 || w == 1) return cout << 1 << endl, 0;
  
  i64 ans = 0;
  if(w % 2 == 0) ans = h * w / 2;
  else ans = (w / 2 + 1) * (h / 2 + (h % 2)) + (w / 2) * (h / 2);
  cout << ans << endl;
}

Measured memory_bytes: 256
ABC = list(map(int,input().split()))
count = 0
while True:
    ABC = list(sorted(ABC))
    if ABC[0] +2 <= ABC[2]:
        ABC[0] += 2
        count += 1
    elif ABC[0] < ABC[2]:
        ABC[0] += 1
        ABC[1] += 1
        count += 1
    if max(ABC) == min(ABC):
        break
print(count)

Measured memory_bytes: 3060
import sys
import math
from functools import lru_cache

gcd = [[0] * 201 for _ in range(201)]

for i in range(201):
    for j in range(201):
        gcd[i][j] = math.gcd(i, j)

K = int(input())

total = 0

for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            total += gcd[gcd[a][b]][c]

print(total)


Measured memory_bytes: 68868
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>

using namespace std;

int P, Q, R;
int pos;
string str;

int formula(void){

  pos++;
  switch(str[pos]){
  case '-': return 2 - formula();
  case 'P': return P;
  case 'Q': return Q;
  case 'R': return R;
  case '0': return 0;
  case '1': return 1;
  case '2': return 2;

  case '(':
    int form1 = formula();
    int form2;
    pos++; // '*' or '+' のぶんを飛ばすため
    switch(str[pos]){
    case '*':
      form2 = formula();
      pos++; // ')' のぶんを飛ばすため
      return min(form1, form2);
    case '+':
      form2 = formula();
      pos++; // ')' のぶんを飛ばすため
      return max(form1, form2);
    }
  }
  return 0;
}


int main(void){

  while(getline(cin, str )){
    int cnt = 0;
    if(str == ".") break;

    // 全パターン試す
    for(int i = 0 ; i < 3 ; i++){
      for(int j = 0 ; j < 3 ; j++){
	for(int k = 0 ; k < 3 ; k++){
	  P = i, Q = j, R = k;
	  pos = -1;
	  if(formula() == 2) cnt++;
	}
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

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

using namespace std;

#define ff              first
#define ss              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
//mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void sb()
{	
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
vector<vector<int>> dp;
ll n;
ll k;
vector<int> a;
int solve(int left,int chance){

	//cout<<" count "<<endl;
	if(dp[chance][left]!=-1)
		return dp[chance][left];

	if(left==0)
		return dp[chance][left] = !chance;
	//cout<<left<<" : "<<chance<<endl;
	bool temp = 0;
 
	for(int i=0;i<n;i++){
		if(left>=a[i]){
			//cout<<left<<" "<<a[i]<<endl;
		temp|= (solve(left-a[i],!chance)==chance);
	}
	}
	int ret;
	if(temp==0)
		ret = !chance;
	else ret = chance;
	return dp[chance][left] = ret;
}
int main()
{
	
	
	cin>>n;
	
	cin>>k;
	 a = vector<int>(n);
	dp = vector<vector<int>>(2,vector<int>(k+1));

	for(int i=0;i<2;i++)
		for(int j=0;j<=k;j++)
			dp[i][j] = -1;
		
	
	for(int i=0;i<n;i++)
		cin>>a[i];

	bool ans;
	ans = solve(k,0);
	//  for(int i=0;i<2;i++){
	// 	for(int j=0;j<=k;j++)
	// 		cout<<dp[i][j]<<" ";
	// 	cout<<endl;
	// }
	if(ans==0)
		cout<<"First";
	else cout<<"Second";
	
}

Measured memory_bytes: 11848
#include<bits/stdc++.h>
using namespace std;
int main()
{
    map<char,string> mp;
    cin>>mp['a']>>mp['b']>>mp['c'];
  //  cout<<mp['a']<<' '<<mp['b']<<' '<<mp['c']<<endl;
    char ch,p;
    ch=mp['a'][0];
    mp['a'].erase(mp['a'].begin());
    while(1)
    {
       // cout<<ch<<endl;
        p=ch;
        if(mp[ch].empty())
        {
            cout<<(char)toupper(ch)<<endl;
            break;
        }
        ch=mp[ch][0];
        mp[p].erase(mp[p].begin());
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<deque>
#define maxn 1010
#define inf 2000000007
using namespace std;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n;
int w[maxn],f[maxn];
int g[2][5050];
int head[maxn],nxt[maxn],to[maxn],tot;
void add(int u,int v)
{
    tot++;
    nxt[tot]=head[u];
    head[u]=tot;
    to[tot]=v;
}
void dfs(int x)
{
    for(int i=head[x];i;i=nxt[i])  dfs(to[i]);
    int cur=0;
    for(int i=0;i<2;i++)
      for(int j=0;j<=w[x];j++)  g[i][j]=inf;
    g[cur][0]=0;
    for(int i=head[x];i;i=nxt[i])
    {
        for(int j=0;j<=w[x];j++)
        {
            if(j>=w[to[i]])  g[cur^1][j]=min(g[cur^1][j],g[cur][j-w[to[i]]]+f[to[i]]);
            if(j>=f[to[i]])  g[cur^1][j]=min(g[cur^1][j],g[cur][j-f[to[i]]]+w[to[i]]);
        }
        for(int j=0;j<=w[x];j++)  g[cur][j]=inf;
        cur^=1;
    }
    int now=inf;
    for(int i=0;i<=w[x];i++)  now=min(now,g[cur][i]);
    if(now==inf)
    {
        puts("IMPOSSIBLE");
        exit(0);
    }
    f[x]=now;
}
int main()
{
    n=read();
    for(int i=2;i<=n;i++)  add(read(),i);
    for(int i=1;i<=n;i++)  w[i]=read();
    dfs(1);
    puts("POSSIBLE");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
  string st,key;
  int n;
  int ret = 0;
  cin >> key; 
  cin >> n;
  while(n--){
    cin >> st;
    st+=st;
    if(st.find(key,0) != string::npos)ret++;
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int arr[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
cin>>k;
cout<<arr[k-1]<<endl;
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = (int)(n)-1; 0 <= i; i--)
#define rrep1(i, n) for (int i = (int)(n); 1 <= i; i--)

#define each(it, c) \
    for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(obj) (obj).begin(), (obj).end()

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x) cerr << #x << " = " << (x) << endl;

#define endl "\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 (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

typedef long long lint;

using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    lint a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    cout << (abs(b - a) <= (v - w) * t ? "YES" : "NO") << endl;
}

Measured memory_bytes: 3656