akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,W;
ll weight[105],value[105];
ll dp[105][100005];
ll solve(ll pos,ll w)
{
    if(w>W)
        return -1e18;
    if(pos==n)
        return 0;
    //ll &ret=dp[pos][w];
    if(dp[pos][w]!=-1){
            //cout<<pos<<" "<<w<<endl;
        return(dp[pos][w]);
    }
    dp[pos][w]=max(dp[pos][w],solve(pos+1,w+weight[pos])+value[pos]);
    //cout<<pos<<" "<<w<<endl;
    //cout<<dp[pos][w]<<endl;
    dp[pos][w]=max(dp[pos][w],solve(pos+1,w));
    //cout<<dp[pos][w]<<endl;
    return(dp[pos][w]);
}
int main ()
{
    scanf("%lld %lld",&n,&W);
    for(ll i=0;i<n;i++)
    {
        ll w,v;
        scanf("%lld %lld",&weight[i],&value[i]);
    }
    memset(dp,-1,sizeof(dp));
    ll ans=solve(0,0);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 82304
#include<bits/stdc++.h>
#define int long long
#define maxn 200000
#define mod 998244353
#define inf 1000000000000
#define FLASH cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define FILEIO freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin); //freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);
using namespace std;

int n, s;
int a[3001], dp[3001][3001];

signed main()
{
	//FILEIO
	FLASH
	cin>>n>>s;
	
	for(int i = 1; i <= n; i++){
		cin>>a[i];
	}
	int ans = 0;
	for(int i = 1; i <= n; i++){
		dp[i][a[i]] += i;
		for(int j = 0; j <= s; j++)
			dp[i][j] += dp[i - 1][j] + ((j >= a[i])?dp[i - 1][j - a[i]]: 0), dp[i][j] %= mod;
		ans += dp[i][s];
		ans %= mod;
	}

	cout<<ans;
}

Measured memory_bytes: 70656
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

def main():
    n=int(input())
    a=[int(input()) for i in range(n-1)]
    # print(a)
    dic={}
    for i in range(n-1):
        p=a[i]
        if p in dic:
            dic[p].append(i+2)
        else:
            dic[p]=[i+2]


    lst=[-1]*(n+1)

    def solve(m):
        if lst[m]!=-1:
            return lst[m]
        tmp=[]
        if m in dic:

            for i in dic[m]:
                tmp.append(solve(i))
        tmp.sort(reverse=True)
        rtn=0
        for i in range(len(tmp)):
            rtn=max(rtn,tmp[i]+i+1)
        lst[m]=rtn
        return rtn

    solve(1)
    # print(lst)
    print(max(lst))
main()

Measured memory_bytes: 150696
N,M=map(int,input().split())
bridge=[]
for i in range(M):
  a,b=map(int,input().split())
  bridge.append((a-1,b-1))


par=[i for i in range(N)]
size=[1 for i in range(N)]
def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
def union(a,b):
  x=find(a)
  y=find(b)
  if x!=y:
    if size[x]<size[y]:
      par[x]=par[y]
      size[y]+=size[x]
    else: 
      par[y]=par[x]
      size[x]+=size[y]
  else:
    return

for i in bridge:
    union(i[0],i[1])


print(max(size))

Measured memory_bytes: 114928
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
// ------------------------5
void solve() {
    int N; cin >> N;
    ll h[100005]; rep(i, N) cin >> h[i];
    ll dp[100005]; rep(i, 100005) dp[i] = INF;

    dp[0] = 0;
    chmin(dp[1], dp[0] + abs(h[1] - h[0]));
    for (int i = 2; i < (N); ++i){
        chmin(dp[i], dp[i-1] + abs(h[i] - h[i - 1]));
        chmin(dp[i], dp[i-2] + abs(h[i] - h[i - 2]));
    }

     cout << dp[N-1] << "\n";
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

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

int main(){
    ll N;
    cin >> N;
    string S;
    cin >> S;
    vector<ll> vec(26, 0);
    rep(i,N){
        ll x = S[i] - 'a';
        vec[x]++;
    }
    ll ans = 1;
    rep(i,26){
        ans = (ans * (vec[i] + 1)) % 1000000007;
    }
    cout << (ans + 1000000007 - 1) % 1000000007 << endl;
}

Measured memory_bytes: 3704
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){
    int n;
    long int d, dqd;
    scanf("%d", &n);
    scanf("%ld", &d);
    long int x[n], y[n];
    int cnt=0;
    for(int i=0;i<n;i++){
        long int sqrt;
        scanf("%ld", &x[i]);
        scanf("%ld", &y[i]);
        sqrt=x[i]*x[i]+y[i]*y[i];
        if(sqrt <= d*d){
            cnt++;
        }
    }
    printf("%d", cnt);
    return 0;
}

Measured memory_bytes: 4816
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>

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

using namespace std;

int n;
int a[10002];
long c;

int main(){
cin >> n;
rep(i,n){
  cin >> a[i];
}
rep(i,n){
  while(a[i]%2==0){
    c++;
    a[i]/=2;
  }
}


cout << c << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdint.h>
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <string>
#include <vector>

std::vector<std::vector<int>> P;
std::vector<int> F;

int getBitCount(int n) {
  int c = 0;
  for (int i = 0; i < 10; i++) {
    c += n & 1;
    n >>= 1;
  }
  return c;
}

int main(int argc, char *argv[]) {
  int N;
  std::cin >> N;
  for (int i = 0; i < N; i++) {
    int f = 0;
    for (int k = 0; k < 5 * 2; k++) {
      int v;
      std::cin >> v;
      f = (f << 1) | v;
    }
    F.push_back(f);
  }
  for (int i = 0; i < N; i++) {
    std::vector<int> v;
    for (int k = 0; k <= 5 * 2; k++) {
      int d;
      std::cin >> d;
      v.push_back(d);
    }
    P.push_back(v);
  }
  int64_t max = -10000000000;
  for (int64_t m = 1; m < (1 << 10); m++) {
    /*
    if (!(m & 3 && m & (3 << 2) && m & (3 << 4) && m & (3 << 6) &&
          m & (3 << 8)))
      continue;
      */
    int64_t tmp = 0;
    for (int i = 0; i < N; i++) {
      int ci = getBitCount(m & F[i]);
      tmp += P[i][ci];
    }
    if (max < tmp || max == -10000000000) {
      // std::cout << max << std::endl;
      max = tmp;
    }
  }
  std::cout << max << std::endl;
  return 0;
}


Measured memory_bytes: 256
#coding:utf-8
n, k = map(int,input().split())
count = 0

for i in range(k,n+2):
    mini = 0.5 * i * (i - 1)
    maxi = 0.5 * n * (n + 1) - 0.5 * (n - i) * (n - i + 1)
    dif = maxi - mini + 1
    count += dif

count = count % (10 ** 9 + 7)
print("{}".format(int(count)))

Measured memory_bytes: 9196
N = int(raw_input())
A = []
for n in xrange(N):
  A.append(map(int, raw_input().split(' ')))
  A[n][n] = 1000000001

answer = 0
for i in xrange(N):
  Ai = A[i]
  for j in xrange(i):
    Aij = Ai[j]
    L = min(map(sum, zip(Ai, A[j])))
    if Aij < L:
      answer += Aij
    else:
      if Aij > L:
        print -1
        exit()
print answer

Measured memory_bytes: 5508
from sys import stdin
input = stdin.readline
N = int(input())
A = [0]*N
B = [0]*N
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b
A.sort()
B.sort()
if N%2 == 0:
    temp = N//2
    m = (A[temp]+A[temp-1])/2
    M = (B[temp]+B[temp-1])/2
    print(int((M-m+1/2)//(1/2)))
else:
    temp = N//2
    print(B[temp]-A[temp]+1)
    

Measured memory_bytes: 25288
import math

def calcAngle(h,m): 
          
        # validate the input 
        if (h < 0 or m < 0 or h > 12 or m > 60): 
            print('Wrong input') 
          
        if (h == 12): 
            h = 0
        if (m == 60): 
            m = 0
          
        # Calculate the angles moved by  
        # hour and minute hands with  
        # reference to 12:00 
        hour_angle = 0.5 * (h * 60 + m) 
        minute_angle = 6 * m 
          
        # Find the difference between two angles 
        angle = abs(hour_angle - minute_angle) 
          
        # Return the smaller angle of two  
        # possible angles 
        angle = min(360 - angle, angle) 
          
        return math.radians(angle)
    
A, B, H, M = list(map(int,input().split()))
angle = calcAngle(H,M)
hypotenuse = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(angle))

print('{0:.20f}'.format(hypotenuse))

Measured memory_bytes: 62616
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);


int main(int argc, char* argv[])
{
  int n;
  cin >> n;
  vector<pair<ll, ll>> pos(n);
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    pos[i] = make_pair(x, y);
  }

  map<pair<ll, ll>, int> m;
  for (int i = 0; i < n; i++) {
    auto pos1 = pos[i];
    for (int j = i+1; j < n; j++) {
      auto pos2 = pos[j];
      auto d1 = make_pair(pos1.first - pos2.first, pos1.second - pos2.second);
      auto d2 = make_pair(pos2.first - pos1.first, pos2.second - pos1.second);
      m[d1]++;
      m[d2]++;
    }
  }

  int tmp = 0;
  for (auto& v : m) {
    chmax(tmp, v.second);
  }

  cout << n - tmp << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(ll, N);
  int s = 0;
  ll M = N;
  while (M) {
    s += M % 10;
    M /= 10;
  }
  print(N % s ? "No" : "Yes");
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    vector<string> v = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv",
                        "wxyz"};
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        int cur = 0;
        string ans;
        while(cur < s.size()){
            while(s[cur] != '0'){
                int cur2 = cur;
                while(s[cur] == s[cur2+1]) cur2++;
                ans += v[s[cur]-'1'][(cur2-cur)%v[s[cur]-'1'].size()];
                cur = cur2+1;
            }
            cur++;
        }
        cout << ans << "\n";
    }
    return 0;
}



Measured memory_bytes: 3080
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<vector>
#include<string> 
#include<queue>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define mod 1000000007
#define ll long long
#define mp make_pair
int main()
{
	std::ios::sync_with_stdio(false);
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	int ans=0;
	ans+=(a[2]-a[1]);
	ans+=(a[1]-a[0]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc079/tasks/abc079_c
q, w, e, r = map(int, list(input()))
# 全探索
op = [1, -1]
ansls = ['+', '-']
for a, b, c in product(range(2), repeat=3):
    if q + op[a] * w + op[b] * e + op[c] * r == 7:
        ans = str(q) + ansls[a] + str(w) + \
            ansls[b] + str(e) + ansls[c] + str(r) + '=7'
        print(ans)
        exit()


Measured memory_bytes: 3316
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

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

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void solveSingleCase(int caseNo)
{
    int A, B, C;
    cin >> A >> B >> C;
    VEC(bool) rem(B, false);
    FOR(i, 0, 10001)
        rem[A * i % B] = true;
    cout << (rem[C] ? "YES" : "NO") << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

const int mod = 1000000007;

struct Mod {
  int n;
  Mod () : n(0) {;}
  Mod (int m) : n(m) {
    if (n >= mod) n %= mod;
    else if (n < 0) n = (n % mod + mod) % mod;
  }
  operator int() { return n; }
};

bool operator==(Mod a, Mod b) { return a.n == b.n; }
Mod operator+=(Mod &a, Mod b) { a.n += b.n; if (a.n >= mod) a.n -= mod; return a; }
Mod operator-=(Mod &a, Mod b) { a.n -= b.n; if (a.n < 0) a.n += mod; return a; }
Mod operator*=(Mod &a, Mod b) { a.n = ((long long)a.n * b.n) % mod; return a; }
Mod operator+(Mod a, Mod b) { return a += b; }
Mod operator-(Mod a, Mod b) { return a -= b; }
Mod operator*(Mod a, Mod b) { return a *= b; }
Mod operator^(Mod a, int n) {
  if (n == 0) return Mod(1);
  Mod res = (a * a) ^ (n / 2);
  if (n % 2) res = res * a;
  return res;
}

ll inv(ll a, ll p) {
  return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
Mod operator/(Mod a, Mod b) { return a * Mod(inv(b, mod)); }

#define MAX_N 1024000

Mod fact[MAX_N], factinv[MAX_N];
void init() {
  fact[0] = Mod(1); factinv[0] = 1;
  REP(i,MAX_N-1) {
    fact[i+1] = fact[i] * Mod(i+1);
    factinv[i+1] = factinv[i] / Mod(i+1);
  }
}
Mod comb(int a, int b) {
  return fact[a] * factinv[b] * factinv[a-b];
}

void solve(ll n, ll m, vector<ll> x, vector<ll> y) {
  Mod s1 = 0, s2 = 0;
  REP(i,n-1) s1 += (Mod(x[i+1]) - Mod(x[i])) * Mod(i + 1) * Mod(n - i - 1);
  REP(i,m-1) s2 += (Mod(y[i+1]) - Mod(y[i])) * Mod(i + 1) * Mod(m - i - 1);
  cout << s1 * s2 << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll n;
	ll m;
	scanf("%lld", &n);
	vector<ll> x(n-1+1);
	scanf("%lld", &m);
	vector<ll> y(m-1+1);
	for (int i = 0 ; i <= n-1 ; i++) {
	  scanf("%lld", &x[i]);
	}
	for (int i = 0 ; i <= m-1 ; i++) {
	  scanf("%lld", &y[i]);
	}
	solve(n, m, x, y);
	return 0;
}


Measured memory_bytes: 11392
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			int X = scan.nextInt();
			
			int i = X;
			int minprime;
			
			while(true) {
				if(isprime(i)) {
					minprime =i;
					break;
				}
				i++;
			}
			
			System.out.println(minprime);
		}
	
		
	}
	
	
	
	private static boolean isprime(int x) {//素数判定、入力xが素数かtrue,falseで返す
		int i;
		if(x<2)return false;//まず２より小さいのは素数じゃない
		if(x==2)return true;//２は素数
		if(x%2==0)return false;//２で割り切れたら素数じゃない
		for(i =3;i*i<=x;i = i+2) {//それ以降iで割り切れたら素数じゃない
			if(x%i==0)
				return false;
		}
		return true;//for文回しても割り切れなかったらそれは素数
	}
		

}


Measured memory_bytes: 22608
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

int n;
string s;

ll solve(ll k){
  ll r=-1,m=0,c=0,sco=0,ans=0;
  rep(l,0,n){
    while(r-1<n && r-l+1<k){
      r++;
      if(s[r]=='M')m++;
      else if(s[r]=='C'){
        c++;
        sco+=m;
      }
    }

    if(s[l]=='D'){
      ans+=sco;
    }else if(s[l]=='M'){
      m--;
      sco-=c;
    }else if(s[l]=='C'){
      c--;
    }
  }

  return ans;
}


signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  cin>>n;
  cin>>s;
  int qq;cin>>qq;
  while(qq--){
    int k;cin>>k;
    cout<<solve(k)<<ENDL;
  }
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

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

Measured memory_bytes: 3312
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)



n,m=l()
if(n==1 and m==0):
    print(0)
    exit()
A=[-1]*(n)
for  i in range(m):
    s,c=l()
    s-=1
    if(s>=n):
        print(-1)
        exit()
    if(A[s]==-1):
        A[s]=c
        continue
    if(A[s]!=-1 and A[s]!=c):
        print(-1)
        exit()
        break
if(A[0]==0 and n!=1):
    print(-1)
    exit()
for i in range(n):
    ele=A[i]
    if(ele==-1 and i==0):
        print(1,end="")
    elif(ele==-1 and i!=0):
        print(0,end="")
    else:
        print(ele,end="")



    



Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;cin>>H>>W;
  string ans="";
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      string s;cin>>s;
      if(s=="snuke"){
        ans='A'+j;
        ans+=to_string(1+i);
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long
#define MAX 200200
#define lson (now<<1)
#define rson (now<<1|1)
const int inf=1e9;
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,Rmin,Rmax,Bmin,Bmax;ll ans=2e18;
struct Node{int x,y;}a[MAX];
bool operator<(Node a,Node b){if(a.x!=b.x)return a.x>b.x;return a.y>b.y;}
struct SegMentTree
{
	int t1[MAX<<2],t2[MAX<<2],a[MAX];
	void pushup(int now){t1[now]=max(t1[lson],t1[rson]);t2[now]=min(t2[lson],t2[rson]);}
	void Build(int now,int l,int r)
	{
		if(l==r){t1[now]=t2[now]=a[l];return;}
		int mid=(l+r)>>1;
		Build(lson,l,mid);Build(rson,mid+1,r);
		pushup(now);
	}
	int Querymx(int now,int l,int r,int L,int R)
	{
		if(L<=l&&r<=R)return t1[now];
		int mid=(l+r)>>1,ret=0;
		if(L<=mid)ret=max(ret,Querymx(lson,l,mid,L,R));
		if(R>mid)ret=max(ret,Querymx(rson,mid+1,r,L,R));
		return ret;
	}
	int Querymn(int now,int l,int r,int L,int R)
	{
		if(L<=l&&r<=R)return t2[now];
		int mid=(l+r)>>1,ret=1e9;
		if(L<=mid)ret=min(ret,Querymn(lson,l,mid,L,R));
		if(R>mid)ret=min(ret,Querymn(rson,mid+1,r,L,R));
		return ret;
	}
}T;
int main()
{
	n=read();int mn=1e9;
	for(int i=1;i<=n;++i)a[i].x=read(),a[i].y=read();
	for(int i=1;i<=n;++i)if(a[i].x<a[i].y)swap(a[i].x,a[i].y);
	for(int i=1;i<=n;++i)mn=min(mn,a[i].y);
	for(int i=1;i<=n;++i)if(a[i].y==mn){swap(a[i],a[n]);break;}
	Rmin=mn;sort(&a[1],&a[n]);
	for(int i=1;i<n;++i)T.a[i]=a[i].y;
	T.Build(1,1,n-1);
	//Rmax=Max
	for(int i=1;i<n;++i)
	{
		Rmax=a[1].x;
		Bmax=max(a[n].x,max(T.Querymx(1,1,n-1,1,i),a[i+1].x));
		Bmin=min(a[n].x,min(T.Querymn(1,1,n-1,1,i),i==n-1?inf:a[n-1].x));
		ans=min(ans,1ll*(Rmax-Rmin)*(Bmax-Bmin));
	}
	//Bmax=Max
	for(int i=1;i<n;++i)
	{
		Bmax=max(a[n].x,a[1].x);
		Rmax=max(T.Querymx(1,1,n-1,1,i),i==n-1?0:max(T.Querymx(1,1,n-1,i+1,n-1),a[i+1].x));
		Bmin=min(a[n].x,min(i==n-1?inf:a[i+1].y,i==n-2?inf:a[n-1].x));
		ans=min(ans,1ll*(Rmax-Rmin)*(Bmax-Bmin));
	}
	printf("%lld\n",ans);
	return 0;
}


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

typedef long long ll;

using namespace std;

const int inf=1000000007;

int main()
{
    int k;
    scanf("%d",&k);
    int z=7, ji=0;
    while(ji<=1000000)
    {
        ji++;
        z=z%k;
        if(z==0)
        {
            break;
        }
        z=z*10+7;
    }
    if(ji>1000000)
    {
        ji=-1;
    }
    printf("%d\n",ji);
    return 0;
}


Measured memory_bytes: 3816
var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});

rl.on('line', function (line) {
    const arr = line.split(' ').map(x => Number(x));
    let n = arr[0];
    let x = arr[1];
    let t = arr[2];
    console.log(Math.ceil(n/x)*t);
});


Measured memory_bytes: 30020
import sys

N , W = map(int, input().split())

WV = [list(map(int, sys.stdin.readline().split())) for i in range(N)]

INF = (-1)*10**13

dp = [[0]*(1+W) for i in range(N+1)]
for j in range(1, W+1):
    dp[0][j] = INF
for i in range(1, N+1):
    for j in range(1, W+1):
        if j-WV[i-1][0]>=0 and dp[i-1][j-WV[i-1][0]]!=INF:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-WV[i-1][0]]+WV[i-1][1])
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])

print(dp[N][W])

Measured memory_bytes: 120684
#!/usr/bin/env python3

def is_prime(d):
    assert d >= 1
    if d == 1:
        flag = False
    else:
        flag = True
        for t in range(2, d):
            if d % t == 0:
                flag = False
                break
            if t ** 2 > d:
                break
    return flag

def get_list():
    res = [i * 5 + 6 for i in range(12000) if is_prime(i * 5 + 6)]
    res = [x for x in res if is_prime(x)]
    return res[:55]

def main():
    n = int(input())
    res = get_list()
    print(*res[:n])

main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t W, H, x, y;
  cin >> W >> H >> x >> y;
  
  double S = W * H;
  cout << S / 2.0 << endl;
  
  if(W % 2 == 0 && H % 2 == 0 && x == W / 2 && y == H / 2) {
    cout << 1 << endl;
  }
  else {
    cout << 0 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int N, K;
    cin >> N >> K;
    int ans = 0;
    REP(i, N){
        int x;
        cin >> x;
        ans += 2*min(x, K-x);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    
    int a;
    int b;

    scanf("%d %d", &a, &b);

    if(a > b) printf("a > b\n");
    else if(a < b) printf("a < b\n");
    else printf("a == b\n");

    return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <cmath>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <vector>
using namespace std;
#define INF 1000000007
#define ll long long
#define rep(i_, __start, __end) for(ll i_=(ll)__start; i_<(ll)__end; i_++)
#define print(_a) cout << _a << endl;
#define printarray(a, len) rep(ii,0,len) cout << a[ii] << " ";
#define printarray2(aa, len) rep(ij,0,len) printarray(aa[ij], aa[ij].size()); print("");


int main(){
    double a, b;
    cin >> a >> b;
    print(ceil((a+b)/2));
   
  return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;

//最大値の中央値あたりが怪しい
int main() {

    ll N, M;
    cin >> N >> M;
    
    vector<ll > A(N, 0);
    
  	for(ll i = 0; i < N; i++){
        cin >> A[i];
    }
    
    ll ans = INF;
    ll r = 0;
    ll l = M - 1;
    for(ll i = 0; i <= N - M; i++){
        ans = min(ans, A[l]-A[r]+min(abs(A[r]), abs(A[l])));
        //cout << A[r] << " " << A[l] << endl;
        r++;
        l++;
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 1024
import time
st_time=time.time()

from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
ts=time.time()
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
show_flg=False
#show_flg=True

V,E=MI()
g=[[] for _ in range(V+1)]
for i in range(E):
    u,v,d=MI()
    g[u].append((v,d))
    g[v].append((u,d))

T=I()
order=[0]*T
accor=[0]*T
for i in range(T):
    n=I()
    accor[i]=accor[i-1]
    if n>0:
        oid,v=MI()
        order[i]=v
        accor[i]+=1

def rand_move(s,c):
    move=[]
    state=0 # on vertex
    cur=1
    point=0
    
    #st=min(T//2,bisect.bisect(accor,V//2))
    #st=s+int(max( 100/(c),0 )*random.randint(0,T) )
    #st=max(0,min(T-1,st))
    st=random.randint(0,T)
    cur_order=[0]*(V+1)
    stock=[0]*(V+1)
    
    for t in range(T):
        cur_order[order[t]]+=1
        if t<st:
            move.append(-1)
            cur_order[order[t]]+=1
        else:
            if state==0:
                r=len(g[cur])
                dest,dist=g[cur][random.randint(0,r-1)]
                state=1
                move.append(dest)
                dist-=1
                if dist==0:
                    state=0
                    cur=dest
                    if dest==1: # 店で荷物を積載
                        for i in range(V+1):
                            stock[i]+=cur_order[i]
                        cur_order=[0]*(V+1)
                    else: # 配達完了
                        point+=stock[dest]
                        stock[dest]=0
            else:
                move.append(dest)
                dist-=1
                if dist==0:
                    state=0
                    cur=dest
    return point,st,move

#for i in range(1,V+1):
    #show(i,g[i])

time_limit=29.5 # 1 = 1 sec
#time_limit=1
now=time.time()
p=-1
s=T//2
c=1
while True:
    c+=1
    now=time.time()
    if now - st_time > time_limit:
        break
    cur_p,cur_st,cur_move=rand_move(s,c)
    if cur_p>p or p==-1:
        p=cur_p
        s=cur_st
        move=cur_move


for i in move:
    print(i)


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

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    cout << a * b / 2 << endl;
    return 0;
}

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

using namespace std;

int main() {

	string S,T;
	cin >> S;
	cin >> T;

	for (int i = 0; i < S.length(); i++) {

		if (S[i] != T[i]) {
			cout << "No";
			return 0;
		}

	}

	cout << "Yes";

}

Measured memory_bytes: 3624
#include <stdio.h>

int issq(int x){
  for(int i = 0; i <= x; i++){
    if(i * i == x){
      return 1;
    }
  }
  return 0;
}

int main(){
  int n, d;
  scanf("%d %d", &n, &d);
  int V[n][d];
  for(int i = 0; i < n; i++){
    for(int j = 0; j < d; j++){
      scanf("%d", &V[i][j]);
    }
  }
  int c = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < i; j++){
      int sum = 0;
      for(int k = 0; k < d; k++){
        sum += (V[i][k] - V[j][k]) * (V[i][k] - V[j][k]);
      }
      if(issq(sum)){
        c++;
      }
    }
  }
  printf("%d\n", c);
  return 0;
}


Measured memory_bytes: 128
read s
d=`echo $s | sed 's/\(.*\) \(.*\)/\2 - \1/' | xargs expr | xargs seq | sed -z 's/\n$//;s/\n/ + /g;s/$/\n/' | xargs expr`
echo $d - `echo $s | sed 's/.* \(.*\)/\1/'` | xargs expr


Measured memory_bytes: 1200
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


import numpy as np
from numba import njit, b1, i4, i8, f8
from heapq import heappop as hpp, heappush as hp

h,w = map(int, input().split())
ch,cw = map(int, input().split())
dh,dw = map(int, input().split())
ch -= 1
cw -= 1
dh -= 1
dw -= 1
rows,cols = h,w

OK = "."
NG = "#"

ss = np.array([[c=="#" for c in input()] for _ in range(h)])
inf = 1<<30
@njit((b1[:, :],i8,i8,i8,i8), cache=True)
def main(ss,ch,cw,dh,dw):
    start = ch*w+cw
    goal = dh*w+dw
    n = h*w
    seen = np.full(n, inf, np.int64)
    seen[start] = 0
    q = [(0, start)] # ワープ回数, 現在位置, 最後の道の位置
    # dx = [0,1,0,-1]
    # dy = [1,0,-1,0]
    dx = []
    dy = []
    vvs = []
    for i in range(-2,3):
        for j in range(-2,3):
            if not (i==j==0):
                dx.append(i)
                dy.append(j)
                if abs(i)+abs(j)>1:
                    vvs.append(1)
                else:
                    vvs.append(0)
    while q:
#         print(seen)
        pnum,pu = hpp(q)
        ux,uy = divmod(pu,w)
        # print(pnum,divmod(pu,w))
        if pu==goal:
            break
        for xx,yy,vv in zip(dx,dy,vvs):
    #         x = ux+xx
    #         y = uy+yy
            x,y = ux+xx, uy+yy
            u = x*w + y
            num = pnum+vv
            if x<0 or y<0 or x>=h or y>=w or ss[x][y]:
                continue
    #         print(x,y)
            if seen[u]>num:
                seen[u] = num
                hp(q,(num, u))
                
    val = seen[goal]
    if val==inf:
        return -1
    else:
        return val
print(main(ss,ch,cw,dh,dw))

Measured memory_bytes: 127228
#include<stdio.h>

int main(){
    int a,b,c,i,n,res[1000]={};

    scanf("%d",&n);

    for(i=0;i<n;i++){
        scanf("%d %d %d",&a,&b,&c);
        if(a*a==b*b+c*c)res[i]=1;
        else if(b*b==a*a+c*c)res[i]=1;
        else if(c*c==b*b+a*a)res[i]=1;
    }

    for(i=0;i<n;i++){
        if(res[i]==1)printf("YES\n");
        else printf("NO\n");
    }

    return 0;
}

Measured memory_bytes: 1736
#include <iostream>

using namespace std;

int main()
{
    int M1, D1;
    cin >> M1 >> D1;

    int M2, D2;
    cin >> M2 >> D2;

    int ans = (M1 == M2) ? 0 : 1;

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


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20

N = int(input())
dict = {}
for _ in range(N):
    str = input()
    st = ''.join(sorted(str))
    if st not in dict:
        dict[st] = 1
    else:
        dict[st] += 1
answer = 0
for key in dict:
    l = dict[key]
    answer += l*(l-1)//2
# print(dict)
print(answer)

Measured memory_bytes: 20264
#include <stdio.h>

double n, s, dp[11][1001];

int main(void)
{	
	int i, j, k;
	int s, n;
	
	dp[0][0] = 1;
   	
  	for(i = 0; i < 101;i++)
    	for(j = 9; j >= 0; j--)
      		for(k = 0; i + k < 1001; k++)
        		dp[j + 1][k + i] += dp[j][k];
				
	
	while (1){
		scanf("%d %d", &n, &s);
		if (n == 0 && s == 0) break;
		
		printf("%.0lf\n", dp[n][s]);
	}
	
	return (0);
}	

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DBG(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define DBG(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define CIN(type, ...) \
  type __VA_ARGS__;    \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define COUT(...) write_to_cout(__VA_ARGS__);

#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

struct Edge {
  int index;
  int dst;
};

ll use[20];

ll DFS(int curr, int dst, int prev, ll used, const vector<vector<Edge>>& edges) {
  if (curr == dst) {
    return used;
  }
  for (const Edge& e : edges[curr]) {
    if (e.dst == prev) continue;
    ll res = DFS(e.dst, dst, curr, used | (1LL << e.index), edges);
    if (res > 0) {
      return res;
    }
  }
  return 0;
}

int main() {
  CIN(int, N);
  vector<vector<Edge>> edges(N);
  REP(i, N - 1) {
    CIN(int, a, b);
    --a, --b;
    edges[a].push_back({i, b});
    edges[b].push_back({i, a});
  }
  CIN(int, M);
  REP(i, M) {
    CIN(int, u, v);
    --u, --v;
    use[i] = DFS(u, v, -1, 0, edges);
    DBG(use[i]);
  }
  ll ans = 1LL << (N - 1);
  for (int s = 1; s < (1 << M); ++s) {
    int cnt = 0;
    ll u = 0;
    for (int i = 0; i < M; ++i) {
      if (s & (1 << i)) {
        ++cnt;
        u |= use[i];
      }
    }
    ans -= (cnt % 2 ? 1 : -1) * (1LL << (N - 1 - bitset<64>(u).count()));
  }
  COUT(ans);
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
using namespace std;
#define eps 0.000001
#define LONG_INF 10000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	REP(i, n - 1) {
		string a;
		cin >> a;
		if (s == "T"&&a == "F") {
			s = "F";
		}
		else s = "T";
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 3140
#include<stdio.h>

int main(void)
{
        double a,b;

        scanf("%lf",&a);
        scanf("%lf",&b);

        if(a>b)
                printf("GREATER\n");
        else if(a<b)
                printf("LESS\n");
        else
                printf("EQUAL\n");

        return 0;
}


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

struct dsu { // 0-indexed
	int n; // number of connected components
	vector<int> par;
	vector<int> sz;

	dsu(int _n) : n(_n), par(n, -1), sz(n, 1) { }

	int getpar(int a) {
		return par[a] == -1 ? a : (par[a] = getpar(par[a]));
	}

	bool merge(int a, int b) {
		a = getpar(a);
		b = getpar(b);
		if (a == b) return false;
		n--;
		if (sz[a] < sz[b]) swap(a, b);
		par[b] = a;
		sz[a] += sz[b];
		return true;
	}
};

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int N, K, L; cin >> N >> K >> L;
	dsu roads(N);
	dsu railways(N);
	for (int k = 0; k < K; k++) {
		int a, b; cin >> a >> b; a--, b--;
		roads.merge(a, b);
	}
	for (int l = 0; l < L; l++) {
		int a, b; cin >> a >> b; a--, b--;
		railways.merge(a, b);
	}

	map<pair<int, int>, int> cnt;
	for (int i = 0; i < N; i++) {
		cnt[make_pair(roads.getpar(i), railways.getpar(i))]++;
	}

	for (int i = 0; i < N; i++) {
		cout << cnt[make_pair(roads.getpar(i), railways.getpar(i))] << " \n"[i == N - 1];
	}

	return 0;
}


Measured memory_bytes: 15104
import sys
sys.setrecursionlimit(10**9)
N,K,C = map(int,input().split())
S = input()

i=0
forward = set()
while N>i:
    if S[i] == "o":
        forward.add(i)
        i+=C+1
    else:
        i+=1

if len(forward) != K:
    exit()

i=N-1
backward = set()
while i>=0:
    if S[i] == "o":
        backward.add(i)
        i-=C+1
    else:
        i-=1
    
# print(forward, backward)
isect = list(forward&backward)
for i in sorted(isect):
    print(i+1)


Measured memory_bytes: 82648
#include <cstdio>
#include <vector>

int main()
{
  std::vector<int> in;
  int a, count = 1;

  while(1)
  {
    scanf("%d", &a);
    in.push_back(a);
    if (a == 0){
      break;
    }
  }
  
  for (int i = 0; i < in.size()-1; i++)
  {
    printf("Case %d: %d\n", i+1, in[i]);
  }

  return 0;
}


Measured memory_bytes: 2860
N, M = map(int, input().split(" "))

LList = []
RList = []

for i in range(M) :
    L, R = map(int, input().split(" "))
    LList.append(L)
    RList.append(R)

maxL = max(LList)
minR = min(min(RList), N)

print(max(minR - maxL + 1, 0))

Measured memory_bytes: 11028
//============================================================================
// Name        : p
// Date        : Mon Mar  4 21:10:15 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//============================================================================
#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mst(x, y) memset(x, y, sizeof(x))
#define pvar(x) cout << #x << ": "
#define fora(e, c) for (auto &e : c)
#define fori(i, a, b) for (int i = a; i < b; ++i)
#define ford(i, a, b) for (int i = a; i > b; --i)
#define output(v) cout << (v) << '\n'
#define jam(x, n) cout << "Case #" << x << ": " << n << "\n"
#define prt(x, a, n) { cout << x[a]; if (a < n - 1) cout << " "; }
#define par(x, s, n, v) if(v) pvar(x); fori(y, s, n) prt(x, y, n) cout << "\n"

#ifndef __has_trace
#define trace(...)
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define x first
#define y second

const int mod = (int) 1e9 + 7;
const int maxn = (int) 1e5 + 7;

void mul(int& a, int b) {
    a = ((ll) a * b) % mod;
}

pii dp[maxn];
vi gg[maxn];

pii dfs(int u, int parent) {
    if (dp[u].x || dp[u].y) {
        return dp[u];
    }

    pii ret = {1, 1};
    fora (v, gg[u]) {
        if (v != parent) {
            pii t = dfs(v, u);
            // white black.
            mul(ret.x, t.y + t.x);
            mul(ret.y, t.x);
        }
    }
    return dp[u] = ret;
}

void solve() {
    int n; cin >> n;
    fori (i, 0, n - 1) {
        int x, y;
        cin >> x >> y;
        // trace(x, y);
        gg[x].pb(y);
        gg[y].pb(x);
    }

    // trace(gg);
    dfs(1, -1);

    // fori (i, 1, n + 1) {
    //     trace(dp[i]);
    // }

    int ret = (dp[1].x + dp[1].y) % mod;
    output(ret);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}



Measured memory_bytes: 13440
//#include<bits/stdc++.h>
#include<cstdio>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	int N = getint(), L = getint(), T = getint();
	int X;
	char W;
	X = getint();
	W = *ci++;
	ci++;
	int amari = T % L * 2;
	int round = T / L * 2;

	ll kaisuu = 0;
	vector<int> A, B;
	if (W == '1') A.pb(X);
	else B.pb(X);

	rep(i, N - 1) {
		int x = getint();
		char w = getcha();
		getcha();

		if (w == '1') A.pb(x);
		else B.pb(x);

		if (W != w) {
			kaisuu += round;
			int kari;
			if (W == '1') kari = x - X;
			else kari = X - x;
			while (kari <= 0) kari += L;
			kari -= amari;
			while (kari <= 0) {
				kari += L;
				kaisuu++;
			}
		}
	}
	amari /= 2;

	
	int NA = A.size();
	int NB = B.size();
	int AA[100000], BB[100000];
	int k = 0;
	rep(i, NA) {
		if (A[i] + amari >= L) AA[k++] = A[i] + amari - L;
	}
	rep(i, NA) {
		if (A[i] + amari < L) AA[k++] = A[i] + amari;
	}
	k = 0;
	rep(i, NB) {
		if (B[i] - amari >= 0) BB[k++] = B[i] - amari;
	}
	rep(i, NB) {
		if (B[i] - amari < 0) BB[k++] = B[i] - amari + L;
	}

	int zenbu[100000];
	int k1 = 0, k2 = 0;
	rep(i, N) {
		if (k1 == NA) zenbu[i] = BB[k2++];
		else if (k2 == NB) zenbu[i] = AA[k1++];
		else if (AA[k1] <= BB[k2]) zenbu[i] = AA[k1++];
		else zenbu[i] = BB[k2++];
	}

	int doko;
	if (W == '1') {
		int itiban = (X + T) % L;
		for (int i = N - 1; i >= 0; i--) {
			if (zenbu[i] == itiban) {
				doko = i;
				break;
			}
		}
	}
	else {
		int itiban = ((X - T) % L + L) % L;
		rep(i, N) {
			if (zenbu[i] == itiban) {
				doko = i;
				break;
			}
		}
	}

	int kotae[100000];

	if (W == '1') kaisuu %= N;
	else kaisuu = ((-kaisuu) % N + N) % N;
	for (int i = doko; i < N; i++) {
		kotae[kaisuu++] = zenbu[i];
		kaisuu %= N;
	}
	rep(i, doko) {
		kotae[kaisuu++] = zenbu[i];
		kaisuu %= N;
	}
	rep(i, N) putint(kotae[i]);

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

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

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>21){
        cout<<"bust";
    }
    else{
        cout<<"win";
    }

    

    

    int o ; cin>>o;
} 


Measured memory_bytes: 256