akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9+7;

//メモ：偶奇で報告が間違ってるかどうかは判別可能。
// 報告が間違ってない場合、Nによって組み合わせが決まる気がする。

int main(void){
    int N;
    cin>>N;
    vector<int> A(N);
    for (int i=0;i<N;i++) cin>>A[i];
    sort(A.begin(),A.end());
    bool can=true;
    if (N%2){
        for (int i=0;i<N&&can;i++){
            if (i%2==1 && (i+1)!=A[i]){
                can=false;
            }
            if (i%2==0 && A[i]!=i){
                can=false;
            }
        }
    }
    else {
        for (int i=0;i<N&&can;i++){
            if (i%2==0 && (i+1)!=A[i]){
                can=false;
            }
            if (i%2==1 && A[i]!=i){
                can=false;
            }
        }
    }
    if (!can) {
        cout<<0<<endl;
        return 0;
    }

    ll ans=1;
    for (int i=0;i<N/2;i++){
        ans*=2;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
s = input()

case = len(s)-1
allcase = 2 ** case
total = 0


for i in range(allcase):
    sum = s[0]
    #print(sum)
    for j in range(case):
        if ((i >> j) & 1):
            sum = sum + "+" + s[j+1]
        else:
            sum = sum + s[j+1]

    total =  total + eval(sum)
print(total)

Measured memory_bytes: 3060
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define rep(i, n)           for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b)        for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a)           for (auto &i : a)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define SUM(x)              accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = (int)(1e9 + 7);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int a, int b) {                                                             //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

class C {
public:
  static void solve(istream &cin, ostream &cout) {
    string S;
    cin >> S;
    while (S.size()) {
      int s = S.size();
      if (s <= 7) {
        if (S == "dream" or S == "dreamer" or S == "erase" or S == "eraser") {
          break;
        } else {
          cout << "NO" << endl;
          return;
        }
      } else {
        if (S[s - 1] == 'r') {
          if (S.substr(s - 6, 6) == "eraser") {
            rep(i, 6) S.pop_back();
          } else if (S.substr(s - 7, 7) == "dreamer") {
            rep(i, 7) S.pop_back();
          } else {
            cout << "NO" << endl;
            return;
          }
        } else if (S[s - 1] == 'e') {
          if (S.substr(s - 5, 5) == "erase") {
            rep(i, 5) S.pop_back();
          } else {
            cout << "NO" << endl;
            return;
          }
        } else if (S[s - 1] == 'm') {
          if (S.substr(s - 5, 5) == "dream") {
            rep(i, 5) S.pop_back();
          } else {
            cout << "NO" << endl;
            return;
          }
        }
      }
    }
    cout << "YES" << endl;
  }
};


signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  C solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 3748
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

	set<string> f;
	int n;
	cin >> n;
	while (n--) {
		string s;
		cin >> s;
		f.insert(s);
	}
	cout << f.size() << endl;
}


Measured memory_bytes: 15624
package main

import "fmt"

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var N int
	fmt.Scan(&N)
	X := make([]int, N)
	for i := range X {
		fmt.Scan(&X[i])
	}
	ans := int(1e18)
	for p := 1; p <= 100; p++ {
		cost := 0
		for i := 0; i < N; i++ {
			cost += (X[i] - p) * (X[i] - p)
		}
		ans = min(ans, cost)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**5)
input = sys.stdin.readline

n, m = [int(item) for item in input().split()]
ok = [False] * n
cnt = [0] * n
submit = []
was = 0
ans = 0
for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if not ok[p] and s == "WA":
        cnt[p] += 1
    elif not ok[p] and s == "AC":
        ans += 1
        was += cnt[p]
        ok[p] = True 


print(ans, was)

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main() {
  int d, g;
  cin >> d >> g;
  vector<int> p(d), c(d);
  for (int i = 0; i < d; i++) cin >> p[i] >> c[i];

  int ans = INT_MAX;
  for (int i = 0; i < (1 << d); i++) {
    // cout << bitset<8>(i) << endl;
    int tensu = 0;
    int tekazu = 0;
    for (int j = 0; j < d; j++) {
      if (i & (1 << j)) {
        tensu += p[j] * (j + 1) * 100 + c[j];
        tekazu += p[j];
      }
    }
    // cout << tensu << " " << tekazu << endl;
    // まだ足りていなかったら、（大きい方から）頑張る
    if (tensu < g) {
      for (int j = (d - 1); 0 <= j; j--) {
        if (!(i & (1 << j))) {
          for (int k = 0; k < p[j] && tensu < g; k++) {
            tensu += (j + 1) * 100;
            tekazu++;
          }
        }
      }
    }

    ans = min(ans, tekazu);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <boost/math/common_factor_rt.hpp>
using namespace std;
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long

int main(){
  int N, X;
  cin >> N >> X;
  int x[100100];
  rep(i, N) cin >> x[i];
  rep(i, N) x[i] -= X;
  
  int ans = boost::math::gcd(x[0], x[1]);
  FOR(i, 2, N) ans = boost::math::gcd(ans, x[i]);
  
  cout << ans << endl;
}

Measured memory_bytes: 640
import Text.Printf

ans' n x 0 = (n,x)
ans' n x y = ans' (n+1) y (x`mod`y)

ans :: [Int] -> (Int,Int)
ans (x:y:_) =
  if x > y
  then ans' 0 x y
  else ans' 0 y x

main = do
  c <- getContents
  let i = takeWhile (/= [0,0]) $ map (map read) $ map words $ lines c :: [[Int]]
      o = map ans i
  mapM_ (\(v,n) -> printf "%d %d\n" n v) o

Measured memory_bytes: 4444
#define EPS 1e-10
#define equals(a, b) (fabs((a) - (b)) < EPS)
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;

class Point
{
public:
  double x, y;
  Point (double x = 0, double y = 0) : x(x), y(y) {}
  Point operator + (Point p) {return Point(x + p.x, y + p.y); }
  Point operator - (Point p) {return Point(x - p.x, y - p.y); }
  Point operator * (double a) {return Point(a * x, a * y); }
  Point operator / (double a) {return Point(x / a, y / a); }

  double norm() { return x * x + y * y; }
  double abs() { return sqrt(norm()); }

  bool operator < (const Point &p) const
  {
    return x != p.x ? x < p.x : y < p.y;
  }

  bool operator == (const Point &p) const
  {
    return equals(x, p.x) && equals(y, p.y);
  }
};

typedef Point Vector;
typedef vector<Point> Polygon;

struct Segment
{
  Point p1, p2;
  Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
  Segment(double x1, double y1, double x2, double y2)
  {
    p1 = Point(x1, y1);
    p2 = Point(x2, y2);
  }
};

typedef Segment Line;

class Circle
{
public:
  Point c;
  double r;
  Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {}
};

double dot(Vector a, Vector b)
{
  return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b)
{
  return a.x * b.y - a.y * b.x;
}

Point project(Segment s, Point p)
{
  Vector base = s.p2 - s.p1;
  double r = dot(p - s.p1, base) / base.norm();
  return s.p1 + base * r;
}

Point reflect(Segment s, Point p)
{
  return p + (project(s, p) - p) * 2.0;
}

int main()
{
  double x1, y1, x2, y2;
  scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
  Segment s(x1, y1, x2, y2);
  int q;
  scanf("%d", &q);
  while (q--)
  {
    Point p;
    scanf("%lf%lf", &p.x, &p.y);
    Point ref = reflect(s, p);
    printf("%.8lf %.8lf\n", ref.x, ref.y);
  }
  return 0;
}



Measured memory_bytes: 2760
from itertools import groupby
s = input()
S = groupby(s)
table = []
for key,group in S:
  cnt = 0
  for id,_ in enumerate(group,1):
    cnt = id
  table.append([key,cnt])
#print(table)
if len(table) == 1:
  print(1,len(s))
  exit()
from collections import defaultdict
for i in range(len(table)-1):
  if table[i][1] != table[i+1][1]:
    print(i+1,i+1+table[i+1][1])
    exit()
  if i <= len(table)-3:
    if table[i][0] == table[i+2][0] and (table[i][1] + table[i+2][1])  > (table[i][1] + table[i+1][1] + table[i+2][1]) / 2:
      print(i+1,i+1+table[i+1][1] + table[i+2][1])
      exit()
print(-1,-1)

Measured memory_bytes: 13684
#include<iostream>
using namespace std;
int main(){
    int a,b;
    char op;
    while(1){
    cin>>a>>op>>b;    
    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;
    }else{
        break;
    }
    
    }
    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define FORR(I,A,B) for(int I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	//ifstream in("input.txt");
	//cin.rdbuf(in.rdbuf());
	ll n;
	cin >> n;
	vector<P> g[n+1];
	FOR(i,0,n-1){
		ll a,b,c;
		cin >> a >> b >> c;
		g[a].push_back({b,c});
		g[b].push_back({a,c});
	}
	ll q,k;
	cin >> q >> k;
	vector<ll> d(n+1,INF);
	d[k] = 0;
	vector<bool> did(n+1,false);
	did[k] = true;
	queue<ll> nex;
	nex.push(k);
	while(!nex.empty()){
		for(auto w:g[nex.front()]){
			if(! did[w.first]){
				did[w.first]=true;
				d[w.first] = d[nex.front()] + w.second;
				nex.push(w.first);
			}
		}
		nex.pop();
	}
	FOR(i,0,q){
		ll xx,yy;
		cin >> xx >> yy;
		cout << d[xx]+d[yy] << endl;
	}
}


Measured memory_bytes: 9984
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
#n = int(input())
#n, m = map(int, sys.stdin.readline().split())
s = input()
#a = list(map(int, sys.stdin.readline().split()))

ans = 0
for i in range(len(s)):
    p = 0
    for j in range(i, len(s)):
        if s[j] == "A":
            p += 1
        elif s[j] == "G":
            p += 1
        elif s[j] == "C":
            p += 1
        elif s[j] == "T":
            p += 1
        else:
            if p != 0:
                break
            else:
                continue

    if p > ans:
        ans = p

print(ans)



            


        


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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1'000'000'000ll + 7;
//const i64 smod = 998244353ll;
//const i64 inf = 1'000'000'000'000'000'000ll + 7;
//const i64 inf = 1'000'000'007;

const double inf = 1e12;

const long double eps = 1e-8;

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

    i64 n, x, t;
    cin >> n >> x >> t;

    i64 r = (n / x + (n % x ? 1 : 0)) * t;
    cout << r << endl;

    return 0;
}

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

int main()
{
    int k;cin >> k;
    string s;
    cin >> s;
    if (s.length() <= k)
    {
        cout << s <<endl;
    }else
    {
        for (int i = 0; i < k; i++)
        {
            cout << s[i];
        }
        cout << "..." <<endl;
        
    }
    
    
}

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

struct Card{
    char letter;
    int value;
};

int n;
Card A1[36],A2[36];

bool isStable(Card C1[],Card C2[],int n){
    for(int i=0; i<n; i++){
        if(C1[i].letter != C2[i].letter)
            return false;
    }
    return true;
}

void BubbleSort(Card C[], int n){
    int flag;
    flag = 1;
    while(flag){
        flag = 0;
        for(int j=n-1; j>=1; j--){
            if(C[j].value<C[j-1].value){
                swap(C[j],C[j-1]);
                flag = 1;
            }
        }
    }
    for(int i=0; i<n; i++){
        if(i) cout << ' ';
        cout << C[i].letter << C[i].value;
    }
    cout << endl;
}

void selectionSort(Card C[], int n){
    int minj;
    for(int i=0; i<n; i++){
        minj = i;
        for(int j=i; j<n; j++){
            if(C[j].value < C[minj].value){
                minj = j;
            }
        }
        if(i!=minj)
            swap(C[i],C[minj]);
    }
    for(int k=0; k<n; k++){
        if(k) cout << ' ';
        cout << C[k].letter << C[k].value;
    }
    cout << endl;
}

int main(){
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> A1[i].letter >> A1[i].value;
        A2[i] = A1[i];
    }
    
    BubbleSort(A1,n);
    cout << "Stable" << endl;
    selectionSort(A2,n);
    if(isStable(A1,A2,n)) cout << "Stable" << endl;
    else cout << "Not stable" << endl;
    
    return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265358979323846
const ll MAX = 1e5+10;
const ll INF = 1e18;
const ll MOD = 1e9+7;

ll a[405];

ll summation(ll left,ll right)
{
    ll p = 0;
    for(int i=left;i<=right;i++)
        p+=a[i];
    return p;
}

int main()
{
    ll n,i,j,k,l,p,q,x,y;
    cin >> n;
    for(i=1;i<=n;i++)
      cin >> a[i];
    ll dp[n+1][n+1];
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
            dp[i][j]=INF;
    }
    for(i=n;i>=1;i--)
    {
        for(j=1;j<=n;j++)
        {
            if(i>j)
                continue;
            else if(i==j)
            {
                dp[i][j]=0;
                continue;
            }
            else
            {
                l = summation(i,j);
                for(k=i;k<=j-1;k++)
                    dp[i][j] = min(dp[i][k]+dp[k+1][j]+l,dp[i][j]);
            }
        }
    }
    cout << dp[1][n];
}

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

int main(){
  int p[4][4];
  cin >> p[0][0] >> p[0][1];
  cin >> p[1][0] >> p[1][1];
  int dx = p[1][0]-p[0][0];
  int dy = p[1][1]-p[0][1];
  p[2][0] = p[1][0]-dy;
  p[2][1] = p[1][1]+dx;
  p[3][0] = p[2][0]-dx;
  p[3][1] = p[2][1]-dy;

  for(int i=2;i<4;++i)
    for(int j=0;j<2;++j)
      cout << p[i][j] << " ";

  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int N, M;
  cin >> N >> M;
  
  cout << (1900 * M + (N - M) * 100) * (1 << M) << '\n';
  
  return 0;
}


Measured memory_bytes: 380
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	K,X = inputMap()

	ans = []
	for i in range(1,(K*2)):
		ans.append(X-K+i)

	print(*ans)



if __name__ == "__main__":
	main()


Measured memory_bytes: 38384
#include<iostream>
#include<utility>
using namespace std;
int main(){
    int N,W;
    int p,w;
    pair<int,int>m[101];
    cin>>N>>W;
    for(int i=1;i<=N;++i){
        cin>>p>>w;
        m[i]=make_pair(p,w);
    }
    int V[101][10001];
    for(int i=1;i<=N;++i){
        for(int c=1;c<=W;++c){
            if(c-m[i].second<0){
                V[i][c]=V[i-1][c];
            }
            else{
                int temp;
                temp=m[i].first+V[i][c-m[i].second];
                V[i][c]=max(temp,V[i-1][c]);
            }
        }
    }
    cout<<V[N][W]<<endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define _abs(x)((x) < 0 ? (x) * -1 : (x))
#define _max(x, y)(max(0, max((x), (y))))
#define _min(x, y)(max(0, min((x), (y))))
template<typename T> inline bool __max__(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool __min__(T &x, const T &y) { return x > y ? x = y, 1 : 0; }

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;

vector<string> rec(const int *arr, const int &x, const int &index, vector<string> v) {
    if (index == 3) {
        if (x + arr[index] == 7) v.pb("+");
        else if (x - arr[index] == 7) v.pb("-");
        else v.clear();

        return v;
    }

    vector<string> vv = vector<string>(v.begin(), v.end());

    v.pb("+");
    vv.pb("-");

    vector<string> plus = rec(arr, x + arr[index], index + 1, v);
    vector<string> minus = rec(arr, x - arr[index], index + 1, vv);

    if (plus.size() != 0) return plus;
    if (minus.size() != 0) return minus;

    return plus;
}

void solve(const int &a, const int &b, const int &c, const int &d) {
    int arr[4] = {a, b, c, d};

    vector<string> p, m;

    p.pb("+");
    m.pb("-");

    vector<string> plus = rec(arr, a + b, 2, p);
    vector<string> minus = rec(arr, a - b, 2, m);

    if (plus.size() != 0) {
        cout << a << plus[0] << b << plus[1] << c << plus[2] << d << "=7" << '\n';
    } else if (minus.size() != 0) {
        cout << a << minus[0] << b << minus[1] << c << minus[2] << d << "=7" << '\n';
    }
}

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //freopen("debug.txt", "w", stderr);

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

    string s;

    cin >> s;

    int a = s[0] - '0';
    int b = s[1] - '0';
    int c = s[2] - '0';
    int d = s[3] - '0';

    solve(a, b, c, d);

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define SZ(x) ((int)(x).size())
#define int ll
#define el '\n'
template<class T> bool rmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool rmx(T &a, T b) { return a < b ? (a = b, true) : false; }
typedef long long ll; typedef long double ld; typedef double dd; typedef pair<int, int> pii;
const ll INFLL=0x7f7f7f7f7f7f7f7f, MOD=1e9+7; const int INF=0x7f7f7f7f;

//////////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';

/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<pii>> adj; vv<int> vis, color; 
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){if(a<0) a=-a; if(b<0) b=-b; while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}

///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());

int n; cin>>n;
int a[n+1], b[n+1], c[n+1];
c[n]=0;
for(int i=0;i<n;++i) cin>>a[i+1];
for(int i=0;i<n;++i) cin>>b[i+1];
for(int i=0;i<n-1;++i) cin>>c[i+1];
a[0]=-1;
int ans=0;
for(int i=1;i<=n;++i){
	ans+=b[a[i]];
	if(a[i-1]+1==a[i]) ans+=c[a[i-1]];
}
cout<<ans<<el;


return 0;
}


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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        cout<<fixed;
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}

LL comb[100][100];

int main(){
    REP(i,100){
        comb[i][0]=comb[i][i]=1;
        FOR(j,1,i)comb[i][j]=comb[i-1][j-1]+comb[i-1][j];
    }
    int N,A,B;
    cin>>N>>A>>B;
    vector<LL> v(N,0);
    REP(i,N)cin>>v[i];
    
    sort(ALL(v));
    v.pb(0);
    reverse(ALL(v));
    auto latte=v;
    int num=A;
    N++;
    FOR(i,1,N)v[i]+=v[i-1];
    FOR(i,A,B+1){
        if(v[num]*i<v[i]*num)num=i;
    }
    cout<<v[num]/(1.0*num)<<endl;
    LL res=0;
    FOR(q,A,B+1){
        if(v[num]*q==v[q]*num){
            LL val=latte[q];
            int a=0;
            int b=0;
            for(int i=q;i>0;i--)if(val==latte[i])a++;
            FOR(i,q+1,N)if(val==latte[i])b++;
            res+=comb[a+b][a];
        }
    }
    cout<<res<<endl;
    
    return 0;
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  char a,b; cin >> a >> b;

  if(a=='H' && b == 'H') cout << "H" << endl;
  if(a=='H' && b == 'D') cout << "D" << endl;
  if(a=='D' && b == 'H') cout << "D" << endl;
  if(a=='D' && b == 'D') cout << "H" << endl;
  
  return 0;
}


Measured memory_bytes: 3604
def f(h, w)
  area = h*w

  g=lambda{|h,w|
    return 0 if h%3==0
    h1 = area/3/w
    a = [h1, h1+1].map{|h1|
      # p [w,h]
      a1 = h1*w
      h23 = h-h1
      # p [h1, a1, h23]
      if w.even?
        (a1 - (area-a1)/2).abs
        # [(a1 - (area-a1)/2).abs,
        #   [(a1-(w/2+1)*h23).abs, h23*2].max].min
      else
        [(a1-w/2*h23).abs, (a1-(w/2+1)*h23).abs, h23].max
      end
    }
    a << h
    a.min
  }
  [g.(h,w), g.(w,h)].min
end

H, W = gets.split.take(2).map(&:to_i)
p f(H, W)


Measured memory_bytes: 1788
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
int dis[100005],flag[100005],vis[100005],h[100005];
int n,m,cnt;
struct wf{
    int to,nxt,w;
}edge[200005*2];
using namespace std;
queue < int > Q;
void add(int u,int v,int w)
{
    edge[++cnt].to=v;
    edge[cnt].w=w;
    edge[cnt].nxt=h[u];
    h[u]=cnt;
}
bool spfa(int s)
{
    dis[s]=0;
    //vis[s]=1;
    Q.push(s);
    flag[s]=1;
    while(!Q.empty())
    {
        int u=Q.front();
        Q.pop();
        //vis[u]=0;
        for (int j=h[u];j;j=edge[j].nxt)
        {
            int v=edge[j].to;
            if (dis[v]==99999999)
            {
                dis[v]=dis[u]+edge[j].w;
                vis[v]=1;
                if (!flag[v]) Q.push(v);
            }
            else if (dis[v]!=dis[u]+edge[j].w) return false;
        }
        flag[u]=0;
    }
    return true;
}
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=0;i<=n;i++)
	  dis[i]=99999999;
    for (int i=1;i<=m;i++)
    {
        int k,l,q;
        scanf("%d%d%d",&k,&l,&q);
        add(k,l,q);
        add(l,k,-q);
    }
    for (int i=1;i<=n;i++)
    {
        if (!vis[i])
        {
            vis[i]=1;
            if (!spfa(i))
            {
                printf("No");
                return 0;
            }
        }
    }
    printf("Yes");
    //while(1);
    return 0;
}


Measured memory_bytes: 6912
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N;
    cin >> N;
    vl A(N);
    vP p(N);
    rep(i,N){
        cin >> A[i];
        p[i].first=A[i];
    }
    rep(i,N){
        p[i].second=i;
    }
    sort(p.begin(),p.end());
    rep(i,N){
        p[i].first=i;
    }
    ll ans=0;
    rep(i,N){
        if((p[i].first+p[i].second)%2!=0){
            ans++;
        }
    }
    cout << ans/2 << endl;
}

Measured memory_bytes: 5548
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  int n, r;
  cin >> n >> r;

  int ans = r;
  if (n < 10) {
    ans += 100 * (10 - n);
  }

  cout << ans << endl;

  return 0;
}

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

int main(void)
{
    char s[1200];
    int freq[26];
    int i;
    
    memset(freq, 0, sizeof(freq));
    while (fgets(s, 1200, stdin) != NULL){
        i = 0;
        while (s[i] != '\0'){
            if ('A' <= s[i] && s[i] <= 'Z'){
                freq[s[i] - 'A']++;
            }
            else if ('a' <= s[i] && s[i] <= 'z'){
                freq[s[i] - 'a']++;
            }
            i++;
        }
    }
    for (i = 0; i < 26; i++){
        printf("%c : %d\n", 'a' + i, freq[i]);
    }
    
    return (0);
}



Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;
 
int main(){
    int m,d;cin>>m>>d;
    int ans=0;
    for(int i=1;i<=d;i++){
        int d1=i%10;
        int d10=i/10;
        if(d1<2||d10<2)continue;
        int yay=d1*d10;
        if(yay>0&&yay<=m){ans++;}
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <cstdio>
#define abs(x) ((x>0)?x:(-(x)))
int H ,W ,D , A ;
int Q ,L , R ;
int px [90001] , py [90001];
int d [90001];
int main ()
{
scanf ("%d %d %d " ,&H ,& W ,& D );
for ( int i =0; i < H ; i ++)
{
for ( int j =0; j < W ; j ++)
{
scanf ("%d " ,& A );
px [ A ]= i , py [ A ]= j ;
}
}
for ( int i = D +1; i <= H * W ; i ++)
d[ i ]= d [i - D ]+ abs ( px [ i ] - px [i - D ])+ abs ( py [ i ] - py [i - D ]);
scanf ("%d " ,& Q );
while (Q--)
{
scanf ("%d %d " ,&L ,& R );
printf ("%d \n " , d [ R ] - d [ L ]);
}
}


Measured memory_bytes: 2304
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;
#define ll long long
#define pb push_back

int main() {
  string n;
  cin >> n;
  vector<int> nums(n.size());

  // char -> int 変換
  transform(n.begin(), n.end(), nums.begin(), [](char ch) { return ch - '0';});

  // 確認
  for(int i=0;i<3;i++){
    if(nums[i]==1) nums[i] = 9;
    else if(nums[i]==9) nums[i] = 1;
    cout << nums[i];
  }
  cout << endl;  

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
using pii = pair<int, int>;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

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

  string S, T;
  cin >> S >> T;
  dump(S.substr(0,0));
  bool f = false;
  rep(i, 0, S.size()) {
    if (T == S.substr(i) + S.substr(0, i))
      f = true;
  }
  cout << (f ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/diverta2019/tasks/diverta2019_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c, n, ans = 0;
    cin >> a >> b >> c >> n;
    REP(i1, n / a + 1) REP(i2, n / b + 1) {
        int t = i1 * a + i2 * b;
        if (t > n) {
            break;
        } else if ((n - t) % c == 0) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
w,h,n=map(int,input().split())
x=[0]*n
y=[0]*n
a=[0]*n
left=0
right=w
up=h
down=0

for i in range(n):
  x[i],y[i],a[i]=map(int,input().split())
for i in range(n):
  if a[i]==1:
    left=max(left,x[i])
  if a[i]==2:
    right=min(right,x[i])
  if a[i]==3:
    down=max(down,y[i])
  if a[i]==4:
    up=min(up,y[i])
if left>=right or down>=up:
  print(0)
else:
  print((right-left)*(up-down))

Measured memory_bytes: 3064
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

H, W = MAP()
s = [input() for _ in range(H)]

dp = [[0]*W for _ in range(H)]

if s[0][0] == ".":
	dp[0][0] = 0
else:
	dp[0][0] = 1


for i in range(1, W):
	if s[0][i] == s[0][i-1]:
		dp[0][i] = dp[0][i-1]
	else:
		dp[0][i] = dp[0][i-1] + 1

for y in range(1, H):
	for x in range(W):
		if x == 0:
			dp[y][x] = dp[y-1][x] + (s[y-1][x] != s[y][x])
		else:
			dp[y][x] = min(dp[y-1][x]+(s[y-1][x] != s[y][x]), dp[y][x-1]+(s[y][x-1] != s[y][x]))

if s[H-1][W-1] == "#":
	dp[H-1][W-1] += 1


print(dp[H-1][W-1]//2)




Measured memory_bytes: 10632
N = int(input())
D = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in range(N):
    a = input()
    if a[0] in D:
        D[a[0]] += 1
L = [D["M"], D["A"], D["R"], D["C"], D["H"]]
ans = 0
for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+1, 5):
            ans += L[i]*L[j]*L[k]
print(ans)

Measured memory_bytes: 3064
n,x = map(int,input().split())
li = list(map(int,input().split()))
X = [abs(x-li[i]) for i in range(n)]

def gcd(a,b):
    if a<b:
        a,b = b,a
    if b==0:
        return a
    else:
        return gcd(b,a%b)

ans = X[0]
for i in range(n-1):
    ans = gcd(ans,X[i+1])
print(ans)

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

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

    if (A == 1 && B == 1) {
        cout << "Draw" << endl;
    } else if (A == 1) {
        cout << "Alice" << endl;
    } else if (B == 1) {
        cout << "Bob" << endl;
    } else if (A == B) {
        cout << "Draw" << endl;
    } else if (A < B) {
        cout << "Bob" << endl;
    } else {
        cout << "Alice" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>

using namespace std;

using ll = long long;

int main() {
    string s;
    
    cin >> s;
    
    cout << min(count(s.begin(), s.end(), '0'), count(s.begin(), s.end(), '1')) * 2 << endl;
}


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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

constexpr int lim = 1e5;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> x(m), y(m);
  for (int i = 0; i < m; ++i) {
    cin >> x[i] >> y[i];
    --x[i], --y[i];
  }
  vector<bitset<lim>> ps, qs;
  for (int v = 0; v < n; ++v) {
    vector<bool> b(n);
    b[v] = true;
    bool ok = true;
    bitset<lim> p, q;
    for (int i = m; i--; ) {
      if (b[x[i]] and b[y[i]]) {
        ok = false;
        break;
      }
      if (b[x[i]]) {
        p[i] = 1;
        b[y[i]] = true;
      } else if (b[y[i]]) {
        q[i] = 1;
        b[x[i]] = true;
      }
    }
    if (ok) {
      ps.push_back(p);
      qs.push_back(q);
    }
  }
  int res = 0;
  for (int j = 0; j < (int)ps.size(); ++j) {
    for (int i = 0; i < j; ++i) {
      if ((ps[i] & qs[j]).any()) continue;
      if ((qs[i] & ps[j]).any()) continue;
      ++res;
    }
  }
  cout << res << '\n';
}


Measured memory_bytes: 13724
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<sstream>
#include<stdio.h>
#include<set>
#include<utility>
using namespace std;
int main()
{
	int abcd;
	cin >> abcd;
	int a[4];
	for (int i = 3; i >=0; i--)
	{
		a[i] = abcd%10;
		abcd /=10;
	}
	for (int bit = 0; bit < (1 << 4); bit++)
	{
		int ans = a[0];
		string s = to_string(a[0]);
		for (long long int i = 1; i < 4; i++)
		{

			if (bit & (1 << i))
			{
				ans += a[i];
				s += '+';
			}
			else {
				ans -= a[i];
				s += '-';
			}
			s += to_string(a[i]);
			
		}
		
		if(ans == 7)
		{
			s += "=7";
			cout << s << endl;
			return 0;
		}
		ans = 0;
	}

}



Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;
int n;
vector<int> A;
bool ans(int i, int m){
    if(m == 0){
        return true;
    }

    if(i >= n){
        return false;
    }

    return (ans(i + 1,m) || ans(i + 1,m - A[i]));
}

int main(){
    cin >> n;
    A = vector<int>(n);

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

    int q;
    cin >> q;

    for(int i = 0;i < q;i++){
        int answer;
        cin >> answer;
        if(ans(0,answer)){
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3160
#include "bits/stdc++.h"
#define   LF      '\n'
#define   ALL(x)  x.begin(), x.end()
#define   iostreamBooster()  do{cin.tie(nullptr);ios::sync_with_stdio(false);}while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f'3f3f3f3fLL;


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

  cout << 2*min( count(ALL(s), '0'), count(ALL(s), '1')) << endl;

  return 0;
}



Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>

int main(){

	int n,m[500],max,min;
	int num[500][500];
	int i,j,s;
	
	scanf("%d",&n);

	for(i=0;i<n;i++){
	    scanf("%d",&m[i]);
	    for(j=0;j<m[i];j++){
	        scanf("%d ",&num[i][j]);
	    }
	}

	for(i=0;i<n;i++){
		max=0;
	    min=0;
	    for(j=0;j<m[i]-1;j++){
	        s=num[i][j+1]-num[i][j];
	        
	        if(s>max){
	            max=s;
	        }
	        if(min>s){
	            min=s;
	        }
	    }
		min=abs(min);
	    printf("%d %d\n",max,min);
	}
return 0;
}

Measured memory_bytes: 796
parseInt(x) = parse(BigInt, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	k = readline() |> parseInt
	a = Int[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]
	println(a[k])
end

main()

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

#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define SPEED ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz size()
#define all(x) x.begin(),x.end()
#define OO 1e18
#define iOO INT_MAX
#define Mdp memset(dp,-1,sizeof dp)
#define R return
#define Test int TT;cin>>TT;for(int T=1;T<=TT;T++)
using namespace std;
const ll Mod = 1e9+7;
int n,a[200],k;
ll Dp[200][100100];
ll Pre[100010];

void Calc(int x)
{
    Pre[0] = 0;
    for(int i=1;i<=k+1;i++)
        Pre[i] = Pre[i-1]+Dp[x][i-1];
}

int main()
{

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

    Dp[0][0] = 1;

    for(int i=1;i<=n;i++)
    {
        Calc(i-1);
        for(int j=0;j<=k;j++)
        {
            Dp[i][j] = (((Pre[j+1]-Pre[max(0,j-a[i])])%Mod)+Mod)%Mod;
        }
    }

    cout << Dp[n][k] << endl;
    R 0;
}


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

#define fto(i, a, b) for (int i = a; i <= b; ++i)
#define fdto(i, a, b) for (int i = a; i >= b; --i)
#define ff first
#define ss second
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define ll long long
#define pi = 3.1415926535897
#define oo 1000000007
#define OO 1000000000000000007

using namespace std;

string s[105];

int main() {
//    freopen("codef.inp", "r", stdin);
//    freopen("codef.out", "w", stdout);
    int n;
    scanf("%d", &n);
    fto(i, 1, n) cin >> s[i];

    string ans = "Yes";
    fto(i, 1, n) {
        fto(j, i+1, n) if (s[i] == s[j]) ans = "No";
    }

    fto(i, 2, n) {
        string x = s[i-1];
        string y = s[i];
        if (x[x.length()-1] != y[0]) ans = "No";
    }

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



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

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

ll dp[3001][3001];

int main() {
  string s, t;
  int k = 0;
  cin >> s >> t;
  for (int i = 0; i < s.size(); ++i) {
    for (int j = 0; j < t.size(); ++j) {
      if (s[i] == t[j])
        dp[i + 1][j + 1] = dp[i][j] + 1;
      else
        dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
    }
  }

  // cout << dp[s.size()][t.size()] << endl;

  string res = "";
  int i = (int)s.size(), j = (int)t.size();
  while (i > 0 && j > 0) {
    // (i-1, j) -> (i, j) と更新されていた場合
    if (dp[i][j] == dp[i - 1][j]) --i;  // DP の遷移を遡る

    // (i, j-1) -> (i, j) と更新されていた場合
    else if (dp[i][j] == dp[i][j - 1])
      --j;

    // (i-1, j-1) -> (i, j) と更新されていた場合
    else
      res = s[i - 1] + res, --i, --j;  // DP の遷移を遡る
  }
  cout << res << endl;

  return 0;
}


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

lint lcm(lint x, lint y) {
    return abs(x) / __gcd(x,y) * abs(y);
}

void solve() {
    lint n,m; cin >> n >> m;
    string s,t; cin >> s >> t;
    lint l = lcm(n,m);
    map<lint,char> x;
    bool ans = true;
    rep(i,n) {
        // cout << i*(l/n)+1 << ' ';
        x[i*(l/n)+1] = s[i];
    }
    // cout << endl;
    rep(i,m) {
        // cout << i*(l/m)+1 << ' ';
        if (x.count(i*(l/m)+1)) {
            if (x[i*(l/m)+1] != t[i]) ans = false;
        }
    }
    // cout << endl;
    if (ans) cout << l << endl;
    else cout << -1 << endl;
}

int main() {
    solve();
}

Measured memory_bytes: 9428
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<bool> bits(55556);
    vector<int> primes;
    for (int i = 2; i*i <= 55555; i++) {
        if (bits[i]) continue;
        for (int j = i+i; j <= 55555; j+=i) {
            bits[j] = true;
        }
    }
    for (int i = 2; i <= 55555; i++) {
        if (!bits[i]) primes.push_back(i);
    }
    int count = 0;
    for (int prime : primes) {
        if (prime % 10 == 1) {
            cout << prime << ' ';
            count++;
            if (count == N) break;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

int N;
int dp[3][104];
int dx[3][104];

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &dp[1][i]);
  }
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &dp[2][i]);
  }

  for (int i = 1; i <= 2; ++i) {
    for (int j = 1; j <= N; ++j) {
      dx[i][j] = std::max(dx[i - 1][j], dx[i][j - 1]) + dp[i][j];
    }
  }

  printf("%d\n", dx[2][N]);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#define MAX_N 101
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  int N;
  cin >> N;
  int S[MAX_N];
  rep(i, N) { cin >> S[i]; }
  bool DP[10001];
  rep(i, 10001) DP[i]= false;

  DP[0] = true;
  for (int i = 1; i <= N; i++) {
    for (int j = 10000; j >= 0; j--) {
      if (DP[j]) {
        DP[j + S[i - 1]] = true;
      }
    }
  }

  int ANS = 0;
  for (int i = 10000; i >= 0; i--) {
    if ((DP[i]) && (i % 10)) {
      ANS = i;
      break;
    }
  }
  cout << ANS << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import random
input = sys.stdin.readline

################################################################################

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

res = 0
for i in range(1, n-1):
    a, b, c = p[i-1], p[i], p[i+1]
    t = [a, b, c]
    t.sort()
    if b == t[1]:
        res += 1

print(res)

Measured memory_bytes: 39280
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
	input!{n:usize, a:[u64;n]};
	let mut a = a;
 	a.sort();
	
  	if a[0] == 0 {
    	println!("0");
      	return;
  	}
  
  	let ans = a.into_iter().fold(1u64, |s, a| s.saturating_mul(a));
 
    if ans > 10u64.pow(18) {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}


Measured memory_bytes: 5012
#!/usr/bin/env python3
import sys
from pprint import pprint

def solve(N: int, A: "List[int]"):
    bits = [[] for _ in range(N)]
    for i, a in enumerate(A):
        bit = 0
        while a > 0:
            if a % 2 == 1:
                bits[i].append(bit)
            a //= 2
            bit += 1
    #pprint(bits)
    cur = set()
    l = 0
    r = 0
    ret = 0
    while l < N:
        while r < N:
            ok = True
            for b in bits[r]:
                if b in cur:
                    ok = False
            if ok:
                for b in bits[r]:
                    cur.add(b)
                r += 1
            else:
                break
        ret += r - l
        #print(l, r)
        for b in bits[l]:
            cur.remove(b)
        l += 1
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


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

int main()
{
    int N;
    cin >> N;
    int a[N + 1];
    for (int i = 1; i < N + 1; i++)
    {
        cin >> a[i];
    }
    int i = 1;
    int counter = 0;
    while (i != -1)
    {
        //       cout << "i=" << i << endl;
        //     cout << "a[i]=" << a[i] << endl;
        int itmp = i;
        i = a[i];
        a[itmp] = -1;
        counter++;
        if (i == 2)
        {
            cout << counter << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 640