akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/abc158/tasks/abc158_e

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "unordered_map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N, P;
  string S;
  cin >> N >> P >> S;

  if (P == 2 || P == 5) {
    ll res = 0;

    rep(i, N) {
      ll num = S[i] - '0';
      if (num % P == 0) res += i + 1;
    }

    drop(res);
  }

  reverse(all(S));

  ll res = 0;

  unordered_map<ll, ll> acc_mod_ct;
  acc_mod_ct[0] = 1;

  ll cur_acc_mod = 0;
  ll next_mod_of_10 = 1;

  rep(i, N) {
    ll num = S[i] - '0';
    ll mod = (cur_acc_mod + num * next_mod_of_10) % P;
    next_mod_of_10 = next_mod_of_10 * 10 % P;
    cur_acc_mod = mod;
    res += acc_mod_ct[mod];
    ++acc_mod_ct[mod];
  }

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 916
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
    int num;
    int yymm, mmyy;
    scanf("%d", &num);
    yymm = mmyy = 0;
    if(0 < num / 100 && num / 100 <= 12 ){
        mmyy = 1;
    }
    if(0 < num % 100 && num % 100 <= 12){
        yymm = 1;
    }

    if(yymm == 1 && mmyy == 1){
        printf("AMBIGUOUS\n");
    }else if(yymm == 1){
        printf("YYMM\n");
    }else if(mmyy == 1){
        printf("MMYY\n");
    }else{
        printf("NA\n");
    }

    return 0;
}

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

using namespace std;

typedef long long ll;

void solve() {
	string s, t;
	cin >> s >> t;
	int i = 0, j = 0, n = s.length();
	while(j < n) {
        if(i > 2 * n) break;
        if(s[i % n] == t[j]) {
            i++; j++;
        }
        else j = 0, i++;
	}
	cout << (j == n ? "Yes" : "No");
}

int main() {
    //freopen("input.txt", "r", stdin);
    solve();
}


Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

vi g[100005];
int ver;
map <pii,int> cost; 
int dis[100005];
bool vis[100005];

void dfs(int u){
	if (vis[u]) return;
	vis[u] = true;
	for (auto &it: g[u]){
		if (!vis[it]) {
			dis[it] = dis[u]+cost[{u,it}];
			dfs(it);
		}
	}
}

signed main()
{
	cin >> ver ; 
	for (int i=0;i<ver-1;i++){ 
		int  u, v, w ; 
		cin >> u >> v >> w ; 
		g[u].pb(v) ; 
		g[v].pb(u) ; 
		cost[{u,v}] = w ; 
		cost[{v,u}] = w ; 
	} 
	dfs(1);
	for (int i=1;i<=ver;i++){
		if (dis[i] & 1) cout << 0 << endl;
		else cout << 1 << endl;
	}
    return 0;
}


Measured memory_bytes: 27408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int count = 0;
  
  for (int i = 0; i < A + 1; i++) {
    for (int j = 0; j < B + 1; j++) {
      for (int k = 0; k < C + 1; k++) {
        if (500 * i + 100 * j + 50 * k == X) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
  
}

Measured memory_bytes: 256
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005

int main()
{
	ios
	ll n,k,i,j=0;
	cin>>n>>k;
	ll a[n+1];
	for(i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(i=0;i<k;i++)
		j+=a[i];
	cout<<j;
	return 0;
}

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

constexpr int MAXV = 220;
constexpr int INF = 1e9;

int dist[MAXV][MAXV];

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

  for (int i = 0; i < MAXV; i++) for (int j = 0; j < MAXV; j++) dist[i][j] = INF;

  vector<int> r(R);
  for (int i = 0; i < R; i++) {
    cin >> r[i];
    r[i]--;
  }

  for (int i = 0; i < M; i++) {
    int a,b,c;
    cin >> a >> b >> c;
    a--, b--;

    dist[a][b] = c;
    dist[b][a] = c;
  }

  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  sort(r.begin(),r.end());
  int ans = INF;
  do {
    int tmp = 0;
    for (int i = 1; i < R; i++) {
      tmp += dist[r[i - 1]][r[i]];
    }
    ans = min(ans, tmp);
  } while(next_permutation(r.begin(),r.end()));

  cout << ans << '\n';
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <utility>
#include <algorithm>
using namespace std;


int main(){
    
    int a[5];
    for(int i=0; i<5; i++){
        cin>>a[i];
    }
    
    int mini=0;
    int minv=10000;
    for(int i=0; i<5; i++){
        if(minv>(a[i]-1)%10){
            mini=i;
            minv=(a[i]-1)%10;
        }
    }
    
    int sum=0;
    for(int i=0; i<5; i++){
        if(i!=mini){
            sum+=a[i]%10==0?a[i]:(a[i]/10+1)*10;
        }else{
            sum+=a[i];
        }
    }
    
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
 
#define MAX 10000
#define NIL -1
 
typedef struct{
  int parent,left,right;
}Node;
 
Node T[MAX];
int D[MAX],H[MAX],n;
 
void setDepth(int,int);
int setHeight(int);
int getSibling(int);
void print(int);
 
int main(){
  int i,v,l,r,root = 0;
 
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    T[i].parent = NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].left = l;
    T[v].right = r;
    if(l != NIL)T[l].parent = v;
    if(r != NIL)T[r].parent = v;
  }
 
  for(i=0;i<n;i++){
    if(T[i].parent == NIL)root = i;
  }
  
  setDepth(root,0);
  setHeight(root);
 
  for(i=0;i<n;i++){
    print(i);
  }
  return 0;
}
 
void setDepth(int u, int d){
 
  if(u == NIL)return;
  D[u] = d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}
 
int setHeight(int u){
  int h1,h2;
 
  h1 = 0;
  h2 = 0;
  
  if(T[u].left != NIL)h1 = setHeight(T[u].left) + 1;
  if(T[u].right != NIL)h2 = setHeight(T[u].right) + 1;
  return H[u] = (h1 > h2 ? h1 : h2); 
}
 
int getSibling(int u){
 
  if(T[u].parent == NIL)return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
    return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
    return T[T[u].parent].right;
  return NIL;
}
 
void print(int u){
  int deg;
 
  printf("node %d: parent = %d, sibling = %d, ",u,T[u].parent,getSibling(u));
 
  deg = 0;
 
  if(T[u].left != NIL)deg++;
  if(T[u].right != NIL)deg++;
 
  printf("degree = %d, depth = %d, height = %d, ",deg,D[u],H[u]);
 
  if(T[u].parent == NIL)printf("root\n");
  else if(T[u].left == NIL && T[u].right == NIL)printf("leaf\n");
  else printf("internal node\n");
}

Measured memory_bytes: 624
#include<stdio.h>

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

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

   if(a<b){
     for(i=0;i<b;i++){
        printf("%d",a);
     }
   }
   else if(b<a){
     for(i=0;i<a;i++){
        printf("%d",b);
     }
   }
   else if(a=b){
     for(i=0;i<b;i++){
        printf("%d",b);
     }
   }

   printf("\n");

   return 0;
}


Measured memory_bytes: 128
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,k=map(int,input().split())
a=lmp()

def ok(s):
    c=0
    for i in a:
        c+=-(-i//s)-1
    return c<=k


l=0
r=max(a)
while r>l+1:
    md=(r+l)//2
    if ok(md):
        r=md
    else:
        l=md
print(r)

Measured memory_bytes: 96464
N = int(input())
A = list(map(int, input().split()))
M = []
ABS = 0

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        else:
            ABS = abs(A[i] - A[j])
            M.append(ABS)
            
print(max(M))

Measured memory_bytes: 66196
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define Set set<int>
#define int long long
#define P pair<int,int>
const int maxn = 1005;
const int INF = 1e17 +6;
using namespace std;
int n,m,a[maxn],b[maxn],c[maxn];
set<int>T;
int32_t main() {
    IOS;
    cin>>n>>m;
    cout<<(n*3+m)/2;
    return 0;
}


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

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

  int ans = 0;
  int state = 1;
  rep(i, 3) {
    if (s[i] == 'R') {
      if (ans == 0 || state == 1) {
        ans++;
      }
      state = 1;
    } else {
      state = 0;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
const ll tMOD=(ll)998244353;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int h,n;
int a[1010],b[1010];
ll dp[20100];
int main(){
	cin>>h>>n;
	FOR(i,1,n+1)cin>>a[i]>>b[i];
	REP(i,20100)
		dp[i]=INF;
	dp[0]=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=h;j++){
			dp[j]=min(dp[j],dp[max(0,j-a[i])]+b[i]);
		}
	}
	cout<<dp[h]<<endl;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <queue>
#include <string.h>

using namespace std;

int W, H, N;
typedef pair<int, int> P;
queue<P> que;
char maze[1003][1003];
int timer[1003][1003];
int pos_x, pos_y;
int sh_x[4] = {0, 0, -1, 1};
int sh_y[4] = {1, -1, 0, 0};
int res = 0;
int strength = 1;

void solve() {
  que.push(P(pos_x, pos_y));

  while(que.size()) {
    P pos = que.front(); que.pop();
    if (maze[pos.second][pos.first] - '0' == strength) {
      //printf("[%d] [%d]\n", pos.second, pos.first);
      while(que.size()) que.pop();
      strength++;
      if (strength == N+1) {
        res = timer[pos.second][pos.first];
        break;
      }

      for (int i=0;i<H;i++) {
        for (int j=0;j<W;j++) {
          if (maze[i][j] == '#') maze[i][j] = '.';
        }
      }

      maze[pos.second][pos.first] = '#';
      que.push(pos);
      continue;
    }
    for (int i=0;i<4;i++) {
      int new_x = pos.first + sh_x[i];
      int new_y = pos.second + sh_y[i];
      if (new_x >= 0 && new_x < W && new_y >=0 && new_y < H && maze[new_y][new_x] != '#' && maze[new_y][new_x] != 'X') {
        //printf("Go to [%d] [%d]\n", new_y, new_x);
        que.push(P(new_x, new_y));
        if (maze[new_y][new_x] == '.') {
          maze[new_y][new_x] = '#';
        }
        timer[new_y][new_x] = timer[pos.second][pos.first] + 1;
      }
    }
  }
}

int main() {
    scanf("%d %d %d", &H, &W, &N);
    getchar();
    
    for (int i = 0; i < H; i++)
    {
      fgets(maze[i], 1002, stdin);
      maze[i][W] = '#';
    }

    for (int i=0;i<H;i++) {
      for (int j=0;j<W;j++) {
        if (maze[i][j] == 'S') {
          pos_x = j;
          pos_y = i;
        }
        if (i==H-1) {
          maze[H][j] = '#';
        }
      }
    }

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


Measured memory_bytes: 8168
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr ll mod = 1e9+7;
constexpr ll md = mod;
constexpr ll inf = 1e15;
tuple<int,int,ll> s(vector<tuple<int,int,ll>> & v){
    for(int cx=0;cx<=100;cx++){
        for(int cy =0;cy<=100;cy++){
            ll tmph;
            for(int i=0;i<(int)v.size();++i)if(get<2>(v[i]) > 0){tmph = abs(cx - get<0>(v[i])) + abs(cy - get<1>(v[i])) + get<2>(v[i]);break;}
            bool allok = true;
            for(int i=0;i<(int)v.size();++i){
                if( get<2>(v[i]) != max(0ll,tmph - abs(cx - get<0>(v[i])) - abs(cy - get<1>(v[i]))) ){allok=false;break;}
            }
            if(allok){
                return make_tuple(cx,cy,tmph);
            }
        }
    }
    return make_tuple(0,0,0);
}
int main(){
    int n;
    cin>>n;
    vector<tuple<int,int,ll>> v(n);
    for(int i=0;i<n;++i){
        int x,y;ll h;
        cin>>x>>y>>h;
        v[i] = make_tuple(x,y,h);
    }
    auto xy = s(v);
    cout <<get<0>(xy) << " " << get<1>(xy) << " " <<get<2>(xy) <<endl; 
    return 0;
}



Measured memory_bytes: 256
/**Bismillahir Rahmanir Rahim.**/

/**
 *    author:  nasimnoob
**/

#include<bits/stdc++.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

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

typedef long long int                        ll;
typedef unsigned long long int              ull;
typedef long double                          ld;

//-----------------------------------------------------------//
#define      test                       int t; cin>>t;  while(t--)

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

#define      sc1(x)                     scanf("%lld",&x);
#define      sc2(x,y)                   scanf("%lld %lld", &x, &y)
#define      scf1(x)                    scanf("%lf",&x)
#define      scf2(x,y)                  scanf("%lf %lf", &x, &y)

#define      srev                       reverse(s.begin(),s.end())
#define      sortstr                    sort(s.begin(), s.end());
#define      gtl(x)                     getline(cin, (x))

#define      PI                         acos(-1) // 3.1415926535897932
#define      MIN                        9999999

#define      Faster                     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

//scanf("%[^\n]%*c", str);
//sort(s,s+n,greater<int>());

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

int main()
{
    Faster;
    //string ;

    int a[1000];
    int gap = 0;
    for(int i = 0 ; i < 5 ; i++)
    {
        cin >> a[i];
        if(a[i] == 0)
          gap = i ;
    }
    cout << gap + 1 << endl;
    return 0;
}






Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using lli = long long int;
using i64 = int64_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

template<class F>
i64 bisect(i64 l, i64 r, F f) { // (l, r]
  if (r - l <= 1) return r;
  i64 m = l + (r - l) / 2;
  return f(m) ? bisect(l, m, f) : bisect(m, r, f);
}

i64 n;
int main() {
  cin >> n;
  i64 sn = sqrt(double(n)) + 1;
  i64 ans = 0;
  for (i64 y = 1; y <= sn; ++y) {
    i64 l = n / (y + 1), r = n / y;
    // l < x <= r
    //
    if (r == 0) continue;

    i64 z = bisect(l, r, [=](i64 x) { return y >= n % x; });
    // cerr << y << '\t' << l << '\t' << r << '\t' << z << endl;
    if (y == n % z) ans += z;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    REP(x,h+1) REP(y,w+1){
        if (a * x + (w - a) * (h - x) != b * y + (h - b) * (w - y)) continue;
        vector<string> ans(h, string(w, '0'));
        VI res(w, h - b);
        REP(j,y) res[j] = b;
        REP(i,h){
            int cnt = (i < x ? a : w - a);
            REP(j,w){
                if (cnt > 0 && res[j] > 0){
                    ans[i][j] = '1';
                    cnt--;
                    res[j]--;
                }
            }
        }
        REP(i,h) cout << ans[i] << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <string>

int A, B;

int main() {
    std::cin >> A >> B;
    int res=0;
    for (int num=A; num<=B; num++) {
        std::string a = std::to_string(num);
        std::string b = a;
        std::reverse(b.begin(), b.end());
        b = std::to_string( std::stoi( b ) );
        if ( a == b ) ++res;
    }
    std::cout << res << std::endl;
    return 0;
}


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

int main() {
	int n, q;
	cin >> n;
	vector<int> S(n);
	for (int i = 0; i < n; i++) cin >> S[i];
	cin >> q;
	vector<int> T(q);
	for (int i = 0; i < q; i++) cin >> T[i];

	int ans = 0;
	for (int i = 0; i < q; i++) {
		for (int j = 0; j < n; j++) {
			if (T[i] == S[j]) {
				ans++;
				break;
			}
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    string s1="eraser";
    string s2="erase";
    string s3="dreamer";
    string s4="dream";
    int found=0;
    found=s.find(s1);
    while(found>=0)
    {
        s.erase(found,6);
        found=s.find(s1);
    }
    found=s.find(s2);
    while(found>=0)
    {
        s.erase(found,5);
        found=s.find(s2);
    }
    found=s.find(s3);
    while(found>=0)
    {
        s.erase(found,7);
        found=s.find(s3);
    }
    found=s.find(s4);
    while(found>=0)
    {
        s.erase(found,5);
        found=s.find(s4);
    }
    if(s.empty())
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	buf := make([]byte, 0)
	scanner.Buffer(buf, 1000000009)
	scanner.Split(bufio.ScanWords)

	var s, t []rune
	if scanner.Scan() {
		s = []rune(scanner.Text())
	}
	if scanner.Scan() {
		t = []rune(scanner.Text())
	}

	ss := map[rune]rune{}
	tt := map[rune]rune{}

	for i := 0; i < len(s); i++ {
		if _, ok := ss[s[i]]; !ok {
			ss[s[i]] = t[i]
		}
		if _, ok := tt[t[i]]; !ok {
			tt[t[i]] = s[i]
		}
		if ss[s[i]] != t[i] || tt[t[i]] != s[i] {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 3200
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int [] d = new int[] {a,b,c};
        Arrays.sort(d);
        if ((d[1] - d[0] )% 2 == 0) {
            System.out.println((d[1] - d[0]) / 2 + d[2] - d[1] );
        } else {
            System.out.println((d[1] - d[0] - 1) / 2 + d[2] + 1 - d[1] + 1 );
        }
    }

}


Measured memory_bytes: 25300
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int f[300],l=1;
int main()
{
	f[0]=1;
	for (int p=2;p<10;p++)
		for(int b=2;b<32;b++)
		{
			int m=p,k=b,t=1;
			while (m)
			{
				if (m&1) t*=k;
				m>>=1;
				k*=k;
			}
			f[l++]=t;
		}
	int x,minn=0;
	scanf("%d",&x);
	for (int i=0;i<l;i++)
		if (x>=f[i] && minn<f[i])
			minn=f[i];
	printf("%d",minn);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll t,n,a,b,c,d;
map<ll,ll> mp;
ll dfs(ll k)
{
	if (k==0) return 0;
	if (k==1) return d;
	if (mp.count(k)) return mp[k];
	ll res=1e18,tmp;
	if (k<res/d) res=(ll)k*d;
	
	tmp=k/2*2;
	res=min(res,abs(k-tmp)*d+a+dfs(tmp/2));
	tmp=(k+1)/2*2;
	res=min(res,abs(k-tmp)*d+a+dfs(tmp/2));
	tmp=k/3*3;
	res=min(res,abs(k-tmp)*d+b+dfs(tmp/3));
	tmp=(k+2)/3*3;
	res=min(res,abs(k-tmp)*d+b+dfs(tmp/3));
	tmp=k/5*5;
	res=min(res,abs(k-tmp)*d+c+dfs(tmp/5));
	tmp=(k+4)/5*5;
	res=min(res,abs(k-tmp)*d+c+dfs(tmp/5));
	mp[k]=res;
	return res;
}
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n>>a>>b>>c>>d;
		cout<<dfs(n)<<endl;
		mp.clear();
	}
	return 0;
}


Measured memory_bytes: 4440
# -*- coding: utf-8 -*-

def main():
    n = int(input())
    a = list(map(int, input().split()))

    a.sort(reverse = True)
    ans = 0
    for i, num in enumerate(a):
        if i % 2 == 0:
            ans += num
        else:
            ans -= num

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define int ll
#define Endl endl

int gcd(int a,int b){
    if(a<b)swap(a,b);
    if(a<=0)return 0;
    if(b<=0)return a;
    int r=a%b;
    while(r){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}


const int MAX_N=200010;
int n,dat[4*MAX_N-1];
int Seg_init(int n_){
    n=1;
    while(n<n_)n*=2;
    for(int i=0;i<2*n-1;++i)dat[i]=0;
    return n;
}
int Seg_calc(int a,int b){
    return gcd(a,b);
}
void Seg_update(int k,int a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
        k=(k-1)/2;
        dat[k]=Seg_calc(dat[2*k+1],dat[2*k+2]);
    }
}
int Seg_query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l)return 0;
    if(a<=l&&r<=b)return dat[k];
    int vl=Seg_query(a,b,2*k+1,l,(l+r)/2);
    int vr=Seg_query(a,b,2*k+2,(l+r)/2,r);
    return Seg_calc(vl,vr);
}


signed main(){
    int N;
    int A[214514];
    cin >> N;
    REP(i,N){cin >> A[i];}
    int M = Seg_init(N);
    REP(i,N){
        Seg_update(i,A[i]);
    }
    
    
    int Ans=max(Seg_query(1,N,0,0,M),Seg_query(0,N-1,0,0,M));
    for(int i=1;i<N-1;i++){
        int l=Seg_query(0,i,0,0,M);
        int r=Seg_query(i+1,N,0,0,M); 
        l=Seg_calc(l,r);
        Ans=max(Ans,l);
    }
    cout << Ans << endl;
    return 0;
}


Measured memory_bytes: 5120
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
    int n;

    scanf("%d", &n);

    double x1, y1, x2, y2, x3, y3;

    while (n--) {
        scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
 
        if (y1 == y3) {
            swap(x3, x2);
            swap(y3, y2);
        }

        if (y2 == y3) {
            swap(x3, x1);
            swap(y3, y1);
        }

        double a = x2 - x3;
        double b = y2 - y3;
        double c = x2 + x3;
        double d = y2 + y3;
        double e = x3 - x1;
        double f = y3 - y1;
        double g = x3 + x1;
        double h = y3 + y1;
        double ab = a / b;
        double d2 = d / 2.0;
        double c2 = c / 2.0;
        double ef = e / f;

        double px = (ab * c2 + d2 - ef * (g / 2) - h / 2) / (ab - ef);
        double py = -ab * px + ab * c2 + d2;
        double x = x1 - px;
        double y = y1 - py;
        double r = sqrt(x * x + y * y);

        printf("%.3lf %.3lf %.3lf\n", px, py, r);
    }

    return 0;
}

Measured memory_bytes: 2724
/**
                 MD.Faysal Hasan
                Comilla Univesity               **/

#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<string>
#include <stdlib.h>
using namespace std;

#define         rep(i,n)       for ( i=0 ; i<n ; ++i )
#define         rep1(i,n)      for ( i=1 ; i<=n ; ++i )
#define         sajo(str)      sort(str.begin(),str.end())
#define         rev(str)       reverse(str.begin(),str.end())
#define         usajo(str)     sort(str.rbegin(),str.rend())
#define         pi             2*acos(0.0)
#define         nel            printf("\n")
#define         longmx         92233720368547758
#define         gcd(a,b)       __gcd(a,b)
#define         lcm(a,b)       (a/gcd(a,b))*b
#define         yes            cout<<"Yes"<<"\n"
#define         no             cout<<"No"<<"\n"
#define         vcl            vector<ll>
#define         pb             push_back
#define         mkp(x,y)       make_pair(x,y)
#define         ff             first
#define         sc             second
#define         spc            ' '
#define         nn             '\n'
#define         Faysal         ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef         long long int  lli;
typedef         long long      ll;

int main(){Faysal

    ll ans,sum,tot,cnt,mx,mn,idx,chk,tmp,mid,lft,rgt,pos;
    ll tc,n,m,a,b,c,d,g,h,l,r,x,y,i,j,k;

    cin>>n>>m;
    vcl v(n);
    tot=cnt=0;
    rep(i,n)
    {
        cin>>v[i];
        tot+=v[i];
    }
    rep(i,n)
    {
        if((4*m*v[i])>=tot)
            cnt++;
    }
    if(cnt>=m)
        yes;
    else
        no;
    return 0;
}


Measured memory_bytes: 256
uses
  SysUtils,
  Classes;

var
	a, i, total : Integer;
	atype : array of Integer;
	str : String;
	strlist : TStringList;
begin
	readln(a);
	setLength(atype, a);
	
	readln(str);
	strlist := TStringList.Create;
	try
		strlist.Delimiter := ' ';
		strlist.DelimitedText := str;
		for i := 0 to a - 1 do
			atype[i] := StrToInt(strlist.Strings[i]);
	finally
		strlist.free;
		end;
	total := 0;	
	for i := 0 to a - 1 do
		begin
		total := total + (atype[i] - 1);
		end;
		writeLn(total);
end.

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr ll INF = 1e15;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << (v[i]==INF ? "INF" : to_string(v[i])) << " \n"[i == sz - 1];
    }
}

struct Edge
{
    int from, to, cost;
    Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

bool operator<(const Edge &e, const Edge &f)
{
    return e.cost > f.cost;
}

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

    int V, E;
    cin >> V >> E;
    vector<vector<ll>> ret(V, vector<ll>(V, INF));
    for (int i = 0; i < V; i++)
        ret[i][i] = 0;
    for (int i = 0; i < E; i++)
    {
        int s, t, d;
        cin >> s >> t >> d;
        ret[s][t] = d;
    }
    for (int k = 0; k < V; k++)
    {
        for (int i = 0; i < V; i++)
        {
            for (int j = 0; j < V; j++)
            {
                if (ret[i][k] == INF || ret[k][j] == INF)
                    continue;
                ret[i][j] = min(ret[i][j], ret[i][k] + ret[k][j]);
            }
        }
    }
    bool f = false;
    for (int i = 0; i < V; i++)
        if (ret[i][i] < 0)
            f = true;
    if (f)
        cout << "NEGATIVE CYCLE" << endl;
    else
    {
        for (int i = 0; i < V; i++)
            printv(ret[i]);
    }
}



Measured memory_bytes: 3384
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	string s; cin >> s;
	ll n = s.l_ength();
	map<char, ll> m;
	for( char c : s ){
		m[c] += 1;
	}
	ll ans = n*(n-1)/2+1;
	for( char c = 'a'; c <= 'z'; ++c ){
		ans -= m[c]*(m[c]-1)/2;
	}
	cout << ans << endl;
	return 0;
}

// 23:36

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

int main()
{
    cout << fixed << setprecision(12);

    double l;

    cin >> l;

    cout << (l / 3) * (l / 3) * (l / 3) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main () {
	int a, p, pie;
	scanf("%d %d", &a, &p);
	a *= 3;
	if ((a+p) >= 2) {
		pie = (a+p)/2;
		printf("%d\n", pie);
	}
	else {
		printf("0\n");
	}
	
	
	return 0;
}

Measured memory_bytes: 1736
N = gets.to_i
dp = Array.new(N) { Array.new(3, 0) }
ABC = N.times.map{gets.split.map(&:to_i)}
dp[0] = ABC[0]
1.step(N-1) do |i|
  a = dp[i-1][1] + ABC[i][0]
  b = dp[i-1][2] + ABC[i][0]
  dp[i][0] = a > b ? a : b
  a = dp[i-1][0] + ABC[i][1]
  b = dp[i-1][2] + ABC[i][1]
  dp[i][1] = a > b ? a : b
  a = dp[i-1][0] + ABC[i][2]
  b = dp[i-1][1] + ABC[i][2]
  dp[i][2] = a > b ? a : b
end
puts dp.last.max

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

using namespace std;

int main()
{
  int H, W;
  cin >> H;
  cin >> W;

  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }

  vector<vector<int>> pointerW(H, vector<int>(W));
  vector<vector<int>> pointerH(H, vector<int>(W));
  vector<vector<int>> countW(H, vector<int>(W));
  vector<vector<int>> countH(H, vector<int>(W));

  for (int h = 0; h < H; h++) {
    pointerW[h][0] = 0;
    countW[h][0] = 1;
    for (int w = 0; w < W-1; w++) {
      pointerW[h][w+1] = w + 1;
      countW[h][w+1] = 1;
      if (S[h][w] != '#' && S[h][w+1] != '#') {
        pointerW[h][w+1] = pointerW[h][w];
        countW[h][pointerW[h][w]] += 1;
      }
    }
  }

  for (int w = 0; w < W; w++) {
    pointerH[0][w] = 0;
    countH[0][w] = 1;
    for (int h = 0; h < H-1; h++) {
      pointerH[h+1][w] = h+1;
      countH[h+1][w] = 1;
      if (S[h][w] != '#' && S[h+1][w] != '#') {
        pointerH[h+1][w] = pointerH[h][w];
        countH[pointerH[h][w]][w] += 1;
      }
    }
  }

  int ans = 0;
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      if (S[h][w] != '#') {
        int c1 = countW[h][pointerW[h][w]];
        int c2 = countH[pointerH[h][w]][w];
        ans = max(ans, c1 + c2 - 1);
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 67200
S=input()
mod=10**9+7
La,Lq,Rc,Rq=0,0,S.count("C"),S.count("?")
ans=0
f=lambda x,y:pow(x,y,mod) if y>=0 else 0
for s in S:
	Rc-=s=="C";Rq-=s=="?"
	if s=="B" or s=="?":
		ans+=(La*f(3,Lq)+Lq*f(3,Lq-1))*(Rc*f(3,Rq)+Rq*f(3,Rq-1))
		ans%=mod
	La+=s=="A";Lq+=s=="?"
print(ans)

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

typedef long long ll;

void solve() {
    int H[2], ans = 100000;
    cin >> H[0] >> H[1];
    rep(i, 2) {
        if (H[i] % 3 == 0) {
            cout << 0 << endl;
            return;
        }
        ans = min(ans, H[1 - i]);
        int H1 = H[i] / 3;
        int S_max = (H1 + 1) * H[1 - i];
        int S_min = (H[i] - H1 - 1) * (H[1 - i] / 2);
        ans = min(ans, S_max - S_min);
        S_min = H1 * H[1 - i];
        S_max = (H[i] - H1) * ((H[1 - i] + 1) / 2);
        ans = min(ans, S_max - S_min);
    }
    cout << ans << endl;
    return;
}

int main() {
    solve();
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
	int i,j;
	int f;
	int n,a,b,c,x;
	int y[100];
 
	while(scanf("%d%d%d%d%d",&n,&a,&b,&c,&x),n){
		f = 0;
		for(i = 0;i < n;i++){
			scanf("%d",&y[i]);
		}

		for(i = 0,j = 0;i < 10001;i++){
			if(x == y[j]){
				j++;
			}
			if(n == j){
				f = 1;
				break;
			}
			x = (a * x + b) % c;
		}
		if(i==10001)i = -1;
		printf("%d\n",i);
	}
	return 0;
}

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

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    string S;
    cin >> S;

    int num = 0;
    int b_num = 0;

    for (char c : S) {
        bool ans = false;
        if (c == 'a') {
            if (A + B > num) {
                ans = true;
                num++;
            }
        }
        else if (c == 'b') {
            if (A + B > num && b_num < B) {
                ans = true;
                num++;
                b_num++;
            }
        }

        if (ans) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


Measured memory_bytes: 896
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main() {
    int N; cin >> N;
    string S; cin >> S;

    int need_left = 0;
    int pointer = 0;
    for (int i = 0; i < S.size(); ++i) {
        if (S[i] == '(') ++pointer;
        else {
            if (pointer == 0) ++need_left;
            else --pointer;
        }
    }
    int need_right = pointer;

    string res = "";
    for (int i = 0; i < need_left; ++i) res += '(';
    res += S;
    for (int i = 0; i < need_right; ++i) res += ')';
    cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		int sum = 0;
		int min = 200;
		int min2 = 200;
		if (l >= 0) {
			for (int i = 2; i <= n; i++) {
				sum += l + i - 1;
			}
		} else {
			for (int i = 1; i <= n; i++) {
				sum += l + i - 1;
				if (min2 > Math.abs(l + i - 1)) {
					min = l + i - 1;
					min2 = Math.abs(l + i - 1);
				}
			}
			sum = sum - min;
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <numeric>
#define load ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#define ll long long
#define ull unsigned long long
#define fori(i,n) for (int i=0; i<int(n);i++)
#define srt(v) sort(v.begin(), v.end())
#define MOD 1000000007
const int INF = 1e9;
const double PI = 3.14159265358979323846;

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

void solve(){

}

int main(){
	load;
    char x;
    cin>>x;
    if (x>= 'A' && x <= 'Z') cout << "A\n";
    else cout << "a\n";
	return 0;



	
}



Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf = 1e9;

string s;
int H,W;
int c[10][10],A[210][210];
int cost[10];
int ans;
int main(void){
    cin>>H>>W;
    REP(i,0,10){
        REP(j,0,10){
            cin>>c[i][j];
        }
    }
    REP(i,0,H){
        REP(j,0,W){
            cin>>A[i][j];
        }
    }
    REP(i,0,10) cost[i]=inf;
    cost[1]=0;
    int start=1;
    queue<int> q;
    q.push(start);
    while(!q.empty()){
        int now=q.front();q.pop();
        REP(i,0,10){
            if(now==i) continue;
            if(cost[now]+c[i][now] < cost[i]){
                cost[i]=cost[now]+c[i][now];
                q.push(i);
            }
        }
    }
    REP(i,0,H){
        REP(j,0,W){
            if(A[i][j]==-1) continue;
            ans+=cost[A[i][j]];
        }
    }
    p(ans);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int n;
    in(n);
    vector<int> vec(n);
  	in(vec);
    int ans=vec[0];
    for(int i=1;i<n;i++){
        ans=__gcd(ans,vec[i]);
    }
    out(ans);
}


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

const int N = 1e5+10;
pair<int, int> val[N];

vector<int> p(N,-1);//change size here if needed
int find(int x) {return p[x] < 0 ? x : p[x] = find(p[x]);}
void merge(int x, int y) {
    if((x=find(x)) == (y=find(y))) return;
    if(p[y] < p[x]) swap(x,y);
    p[x] += p[y];
    p[y] = x;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    if(n == m+1) {
        cout << "0\n";
        return 0;
    }
    int edgesToAdd = n-1-m;
    if(2*edgesToAdd > n) {
        cout << "Impossible\n";
        return 0;
    }
    for(int i = 0; i < n; ++i) {
        cin >> val[i].first;
        val[i].second = i;
    }
    sort(val, val+n);
    for(int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        merge(u, v);
    }
    vector<int> minCC(n, 1e9);
    for(int i = 0; i < n; ++i) {
        minCC[find(val[i].second)] = min(minCC[find(val[i].second)], val[i].first);
    }
    int res = 0;
    int cnt = 0;
    vector<bool> used(n, false);
    vector<bool> nodeUsed(n, false);
    for(int i = 0; i < n; ++i) {
        if(used[find(val[i].second)]) continue;
        used[find(val[i].second)] = true;
        res += minCC[find(val[i].second)];
        nodeUsed[val[i].second] = true;
        ++cnt;
    }
    int pos = 0;
    while(cnt < 2*edgesToAdd) {
        while(nodeUsed[val[pos].second]) ++pos;
        nodeUsed[val[pos].second] = true;
        ++cnt;
        res += val[pos].first;
    }
    cout << res << '\n';
}


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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

template<class T> void chmax(T& a, T b){ a>b?:a=b; }
template<class T> void chmin(T& a, T b){ a<b?:a=b; }

int main() {
    int k, r[8], c[8], a[8];
    cin >> k;
    rep(i, k) {
        cin >> r[i] >> c[i];
    }
    rep(i, 8) a[i] = i;
    do {
        // 縦横が重ならないことは保証されている→斜めのみ調べる
        int d1[15] = { 0 }, d2[15] = { 0 };
        bool f = true;
        rep(i, k) {
            if (a[r[i]] != c[i])
                f = false;
        }
        rep(i, 8) {
            d1[a[i] - i + 7]++;
            d2[a[i] + i]++;
        }
        rep(i, 14) {
            if (d1[i] > 1 || d2[i] > 1)
                f = false;
        }
        if (!f)
            continue;
        rep(i, 8) {
            rep(j, 8) {
                bool isfind = false;
                rep(l, 8) {
                    if (l == i && a[l] == j)
                        isfind = true;
                }
                cout << (isfind ? 'Q' : '.');
            }
            cout << endl;
        }
        
    } while (next_permutation(a, a + 8));

    return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod =  1e9 + 7;
const int maxn = 10'000 + 5;
const int maxv = 1'000'000 + 5;
int arr[maxn], pf[maxv];
ll modpow(ll base, ll power) {
    ll res = 1;
    while (power) {
        if (power & 1)
            res = res * base % mod;
        base = base * base % mod;
        power >>= 1;
    }
    return res;
}
void fac(int num) {
    int cnt = 0;
    if (num % 2 == 0) {
        while (num % 2 == 0) {
            ++cnt;
            num /= 2;
        }
        pf[2] = max(pf[2], cnt);
    }
    int bound = sqrt(num) + 1;
    for (int i = 3; i <= bound && i <= num; i += 2) {
        if (num % i == 0) {
            cnt = 0;
            while (num % i == 0) {
                ++cnt;
                num /= i;
            }
            pf[i] = max(pf[i], cnt);
        }
    }
    if (num > 2)
        pf[num] = max(pf[num], 1);
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
        fac(arr[i]);
    }
    ll lcm = 1;
    for (int i = 2; i < maxv; ++i)
        lcm = lcm * modpow(i, pf[i]) % mod;
    ll res = 0;
    for (int i = 0; i < n; ++i)
        res = (res + lcm * modpow(arr[i], mod - 2) % mod) % mod;
    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 2816
import java.util.Arrays;

public class Main {


  private static void solve() {
    int n = ni();
    int[] a = na(n);
    int g = 0;
    Arrays.sort(a);

    
    for (int i = 0; i < n; i ++) {
      g ^= (n-i) * (a[i] % 2);
    }
    
    if (g != 0) {
      System.out.println("first");
    } else {
      System.out.println("second");
    }
    
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

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

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

namespace A
{
    class Program
    {
        public static int[] a;
        public static string str;
        static void Main(string[] args)
        {
            a = new int[6];
            for (int i = 0; i < 6; i++)
            {
                a[i] = int.Parse(Console.ReadLine());
                
            }

            if (a[4] - a[0] > a[5]) { Console.WriteLine(":("); }
            else { Console.WriteLine("Yay!"); }

        }
        public static string[] strs;
        //strs=Console.ReadLine().Split(' '):
    }
}


Measured memory_bytes: 13140
nu,ti = gets.chomp.split(" ").map(&:to_i)
ro = Array.new(nu).map{Array.new(2, 0)}
for i in 0..nu - 1
  ro[i] = gets.chomp.split(" ").map(&:to_i)
end
ans = ro.sort

for i in 0..nu - 1
  if ans[i][1] <= ti
    puts ans[i][0]
    exit
  end
end

puts "TLE"


Measured memory_bytes: 1788