akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

#define ll long long

int main()
{
	int n;
	string cur, pre;
	map<string, int> ms;
	cin >> n >> cur;
	ms[cur]++;
	pre = cur;
	Rep (i, 1, n) {
		cin >> cur;
		if (pre.back() != cur.front()) {
			cout << "No" << endl;
			return 0;
		}
		pre = cur;
		ms[cur]++;
		if (ms[cur] > 1) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}



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

int main() {
  int k;
  cin >> k;

  ll ans = 0;

  repI(a, 1, k+1) {
    repI(b, 1, k+1) {
      repI(c, 1, k+1) {
        ans += __gcd(a, __gcd(b, c));
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3596
import sys
sys.setrecursionlimit(4100000)
from collections import deque

def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    visited = [[float('inf')] * W for _ in range(H)]
    if S[0][0] == '#':
        visited[0][0] = 1
    else:
        visited[0][0] = 0
    
    for h in range(H):
        for w in range(W):
            if h + 1 > H - 1 and w + 1 > W - 1:
                continue
            if S[h][w] == '.':
                if h + 1 > H - 1:
                    if S[h][w + 1] == '.':
                        visited[h][w+1] = min(visited[h][w], visited[h][w+1])
                    else:
                        visited[h][w+1] = min(visited[h][w] + 1,visited[h][w+1])
                elif w + 1 > W - 1:
                    if S[h+1][w] == '.':
                        visited[h+1][w] = min(visited[h][w],visited[h+1][w])
                    else:
                        visited[h+1][w] = min(visited[h][w] + 1,visited[h+1][w])
                else:
                    if S[h + 1][w] == '.':
                        visited[h+1][w] = min(visited[h][w],visited[h+1][w])
                    else:
                        visited[h+1][w] = min(visited[h][w] + 1,visited[h+1][w])

                    if S[h][w + 1] == '.':
                        visited[h][w+1] = min(visited[h][w],visited[h][w+1])
                    else:
                        visited[h][w+1] = min(visited[h][w] + 1,visited[h][w+1])

            else:
                if h + 1 > H - 1:
                    visited[h][w+1] = min(visited[h][w],visited[h][w+1])
                elif w + 1 > W - 1:
                    visited[h+1][w] = min(visited[h][w],visited[h+1][w])
                else:
                    visited[h][w+1] = min(visited[h][w],visited[h][w+1])
                    visited[h+1][w] = min(visited[h][w],visited[h+1][w])

    print(visited[H-1][W-1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 42864
const main = (input) => {
  input = input.trim().split('\n')

  const [x,] = input[0].split(' ').map(Number)
  if (input.length === 1) return console.log(x)
  const arr = input[1].split(' ').map(Number).sort((a, b) => a - b)

  for (let abs = 0; 'infinite'; abs++) {
    if (!arr.includes(x - abs)) return console.log(x - abs)
    if (!arr.includes(x + abs)) return console.log(x + abs)
  }
}

process.env.MYTEST
  ? (process.env.MYTEST === 'test' ? test() : main(require('fs').readFileSync('dev/stdin', 'utf8')))
  : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 29520
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int n,y;
int main(){
	scanf("%d%d",&n,&y);
	for (int i=0;i<=n;i++){
		for (int j=0;j<=n;j++){
			int k=y-10000*i-5000*j;
			if (k<0){
			   continue;
			}
			int g=k/1000;
			if (i+j+g==n){
			   printf("%d %d %d",i,j,g);
			   return 0;
			}
		}
	}
	printf("-1 -1 -1");
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n;
    cin>>n;
    Vec a(n);
    rep(i,n)cin>>a[i];
    sort(ALL(a));
    ll sum=0;
    rep(i,n-1){
        sum += a[i];
    }
    Yes(sum>a[n-1]);
    return  0;
}


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

import numpy as np

N,M,Q = map(int,sys.stdin.readline().split())
rows = sys.stdin.readlines()
S = np.zeros((N+2,M+2),dtype='U1')
S[1:-1,1:-1] = np.array([list(row) for row in rows[:N]],dtype='U1')[:,:M]
query = np.array([row.split() for row in rows[N:]],dtype=np.int32)

count_one = (S=='1').cumsum(axis=0).cumsum(axis=1)

# 左上ごとに
count_edge_x = ((S[:-1]=='1')&(S[1:]=='1')).cumsum(axis=0).cumsum(axis=1)
count_edge_y = ((S[:,:-1]=='1')&(S[:,1:]=='1')).cumsum(axis=0).cumsum(axis=1)

x1,y1,x2,y2 = query.T

answer = count_one[x2,y2] - count_one[x2,y1-1] - count_one[x1-1,y2] + count_one[x1-1,y1-1]

answer -= count_edge_x[x2-1,y2] - count_edge_x[x2-1,y1-1] - count_edge_x[x1-1,y2] + count_edge_x[x1-1,y1-1]
answer -= count_edge_y[x2,y2-1] - count_edge_y[x1-1,y2-1] - count_edge_y[x2,y1-1] + count_edge_y[x1-1,y1-1]

print('\n'.join(answer.astype(str)))

Measured memory_bytes: 226496
#include<bits/stdc++.h>
using namespace std;
main()
{
 long n;
 cin>>n;
 vector<long> v(n);
 long max1=-1;
 long max2=-1;
 for(int i=0;i<n;i++)
 {
 	cin>>v[i];
 }
 vector<long> v2=v;
 sort(v.rbegin(),v.rend());
 for(int i=0;i<n;i++)
 {
 	if(v2[i]==v[0])
 	{
 		cout<<v[1]<<endl;
 	}
 	else
 	{
 		cout<<v[0]<<endl;
 	}
 }
 


}

Measured memory_bytes: 4736
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

i64 f(string &s, char head) {
    int cnt = 0;
    if (s[0] == head) {
        ++cnt;
        s[0] = toupper(s[0]);
    }
    rep(i, 1, s.length()) {
        if (s[i] == s[i - 1]) {
            ++cnt;
            s[i] = toupper(s[i]);
        }
    }

    dump(s, cnt);
    return cnt;
}

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

    var(string, S);
    var(i64, K);

    string t1 = S;
    string t2 = S;
    const i64 p1 = f(t1, '_');
    const i64 p2 = f(t2, t1.back());

    if (t2.back() == t1.back()) {
        print(p1 + p2 * (K - 1));
    } else {
        print(p1 * (K - K / 2) + p2 * (K / 2));
    }

    return 0;
}


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

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

int main() {
    int n, y;
    cin >> n >> y;
    int a(-1),b(-1),c(-1);

    y /= 1000;

    rep(i, n+1){
        rep(j, n-i+1){
            int nocori = y - (10*i + 5*j);
            if(nocori == (n-i-j)){
                a = i;
                b = j;
                c = nocori;
            } 
        }
    }

    cout << a << " " << b << " " << c << endl;
    return 0;    
}


Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        mut abc: [usize;3],
    }

    abc.sort();

    println!("{}", abc[0]+abc[1]);

}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;

pair <ll,ll> p[110000];
int main(){
  ll n,m,cnt=0,ps=0,tmp=0;
  cin>>n>>m;
  rep(i,0,m){cin>>p[i]F>>p[i]S;}
  sort(p,p+m);
  rep(i,0,m){
    ll l=p[i]F,r=p[i]S;
    while(l<p[i+1]S&&r>p[i+1]F){i++;l=max(l,p[i]F),r=min(r,p[i]S);}
    cnt++;
  }
  cout<<cnt;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
	ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll a;
/******* define variable end *******/
int solve() {
	cin >> a;
	cout << a + a * a + a * a * a << endl;
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 3648
#include<stdio.h>

typedef struct{
  int x;
  int y;
}point;
double dabs(double a){
  return a>0.0?a:-a;
}
int main(){
  int i,n,pc,a,b,c,d;
  point ps[100];
  double area;

  pc=1;
  do{
    scanf("%d",&n);
    if(!n) break;
    for(i=0;i<n;i++) scanf("%d %d",&(ps[i].x),&(ps[i].y));
    for(i=1,area=0.0;i<n-1;i++){
      a=ps[i].x-ps[0].x;
      b=ps[i].y-ps[0].y;
      c=ps[i+1].x-ps[0].x;
      d=ps[i+1].y-ps[0].y;
      area+=(double)(a*d-b*c)/2.0;
    }
    printf("%d %.1lf\n",pc++,dabs(area));
  }while(1);
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <numeric>
using namespace std;
// rep macro
#define rep(i, n)        for (int i = 0; i < (int)(n); i++)
#define rev(i, n)        for (int i = (int)(n - 1); i >= 0; i--)
const int di[8] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dj[8] = {0, 1, 0, -1, -1, 1, 1, -1};
// vector macro
#define all(v) v.begin(), v.end()
using  vi = vector<int>;
using vvi = vector<vector<int>>;
using  vc = vector<char>;
using vvc = vector<vector<char>>;
// pair macro
#define fi first
#define sj second
using pii = pair<int, int>;

bool on_board(pii p)
{
    return (p.fi >= 0 && p.fi < 8 && p.sj >= 0 && p.sj < 8);
}
bool chk(vvc& b)
{
    bool res = true;
    vector<pii> q;
    // vertical and horizontal 
    rep(i, 8)
        rep(j, 8)
            if (b[i][j] == 'Q') q.push_back(pii(i, j));
    for (auto p : q)
    {
        for (int i = 0; i < 8; i++)
        {
            pii now;
            now = p;
            while(on_board(pii(now.fi+di[i], now.sj+dj[i])))
            {
                now.fi += di[i];
                now.sj += dj[i];
                if (b[now.fi][now.sj] == 'Q')
                {
                    res = false;
                    break;
                }
            }
            if (res == false) break;
        }
        if (res == false) break;
    }
    return res;
}
void print_board(vvc& b)
{
    rep(i, 8)
    {
        rep(j, 8)
        {
            cout << b[i][j];
        }
        cout << endl;
    }
}
int main()
{
    int k; cin >> k;
    vector<pii> q(k);
    rep(i, k) cin >> q[i].fi >> q[i].sj;
    vi I(8); iota(all(I), 0);
    bool res;
    do
    {
        vvc b(8, vc(8, '.'));
        rep(i, 8)
        {
            b[i][I[i]] = 'Q';
        }
        bool skip = false;
        for(auto p : q)
        {
            if (b[p.fi][p.sj] != 'Q') 
            {
                skip = true;
                break;
            }
        }
        if (skip) continue;
        res = chk(b);
        if (res == true)
        {
            print_board(b);
            break;
        }
    } while (next_permutation(all(I)));
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
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(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int a, b;
    cin >> a >> b;
    if (a == b) {
        cout << a + b << endl;
    } else {
        cout << 2 * max(a, b) - 1 << endl;
    }
}


Measured memory_bytes: 3540
n, a, b, c, d = map(int, input().split())
s = ' '+input()

# dのほうがとおい
if c < d:
  # acbd
  if c < b:
    for i in range(a, c-1):
      if s[i+1] == '#' and s[i+2] == '#':
        print("No")
        exit()
    for i in range(b, d-1):
      if s[i+1] == '#' and s[i+2] == '#':
        print("No")
        exit()
  # abcd      
  else:
    for i in range(b, d-1):
        if s[i+1] == '#' and s[i+2] == '#':
            print("No")
            exit()
    for i in range(a, c-1):
        if s[i+1] == '#' and s[i+2] == '#':
            print("No")
            exit()
  print("Yes")
  
# abdc
else:
  #まず全部確認
  for i in range(a, c-1):
    if s[i+1] == '#' and s[i+2] == '#':
      print("No")
      exit()
  #bd間を確認
  for i in range(b, d+1):
    if s[i-1] == '.' and s[i] == '.' and s[i+1] == '.':
      print("Yes")
      exit()
  print("No")
  exit()

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x !=NIL){
    y=x;
    if(z->key <x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
}
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else if(z->key < y->key){
    y->left=z;
  }
  else{
    y->right=z;
  }
}
void inorder(Node u){
    if(u->left !=NIL){
      inorder(u->left);
  }
    printf(" %d",u->key);
  if(u->right !=NIL){
    inorder(u->right);
  }
  }
void preorder(Node u){
  printf(" %d",u->key);
  if(u->left !=NIL){
    preorder(u->left);
  }
  if(u->right !=NIL){
    preorder(u->right);
  }
 }
Node find(Node u,int k){
  while(u !=NIL && k!=u->key){
    if(k<u->key){
      u=u->left;
    }
    else u=u->right;
  }
  return u;
}
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = find(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else break;
    }
  return 0;
}


Measured memory_bytes: 20460
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define deb(x) cout << #x << "=" << x << endl;
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   

int main() {
    fastio
    ll d, t, s;
    cin>>d>>t>>s;
    if(t*s >= d) {
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3652
#![allow(dead_code)]
macro_rules! debug {
    ($($arg:tt)*) => (if cfg!(debug_assertions) {print!("[DEBUG] "); println!($($arg)*)});
}

fn f(b: i64, n: i64) -> i64 {
    return if n < b {
        n
    } else {
        f(b, n / b) + n % b
    };
}

fn main() {
    let mut rd = reader::Reader::new();

    let n: i64 = rd.next();
    let s: i64 = rd.next();

    if n == s {
        println!("{}", n + 1);
        return;
    }

    for i in 2..1000000i64 {
        if f(i, n) == s {
            println!("{}", i);
            return;
        }
    }

    let mut b = (n as f64).sqrt() as i64;
    for l in (1..b + 2).rev() {
        let b = (n - s) / l + 1;
        if b > 1 && f(b, n) == s {
            println!("{}", b);
            return;
        }
    }
    println!("-1");
}

mod reader {
    use std::fmt::Debug;
    use std::str::FromStr;
    use std::collections::VecDeque;
    use std::io::{self, Read};

    fn _read_line() -> String {
        let mut buf = String::new();
        let _ = io::stdin().read_to_string(&mut buf);
        buf
    }

    fn _read_vec_deque_string() -> VecDeque<String> {
        _read_line()
            .split_whitespace()
            .map(|s| s.to_string())
            .collect()
    }

    pub struct Reader {
        buf: VecDeque<String>,
    }

    impl Reader {
        pub fn new() -> Reader {
            Reader { buf: VecDeque::new() }
        }

        fn update_buf(&mut self) {
            if self.buf.is_empty() {
                self.buf = _read_vec_deque_string();
            }
        }

        pub fn next<T>(&mut self) -> T
            where
                T: FromStr,
                T::Err: Debug,
        {
            self.update_buf();
            self.buf.pop_front().unwrap().parse::<T>().unwrap()
        }

        pub fn next_n<T>(&mut self, n: usize) -> Vec<T>
            where
                T: FromStr,
                T::Err: Debug,
        {
            let mut vec: Vec<T> = Vec::with_capacity(n);

            for _ in 0..n {
                vec.push(self.next());
            }
            vec
        }
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<map>
#include<cmath>
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c));
typedef long long ll;

int main()
{
  int n; cin >> n;
  vector<int> w(n);
  for(int i = 0; i < n; i++) cin >> w[i];

  vector<int> sum(n + 1, 0);
  for(int i = 1; i <= n; i++){
    sum[i] = sum[i - 1] + w[i - 1];
  }

  int ans = 1e9;
  for(int i = 1; i < n; i++){
    int left, right;
    left = sum[i];
    right = sum[n] - sum[i];
    ans = min(ans, abs(left - right));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-10;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
 
int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	printf("%d\n",min(min(a+b,b+c),c+a));
}

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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

int main() {
    ios_base::sync_with_stdio(false);
    string t,s;
    cin >> t >> s;
    bool ok = (s.size()-1 == t.size());
    for(int i = 0; i < t.size(); i++) ok &= (s[i]==t[i]);
    cout << (ok?"Yes":"No") << endl;
    return 0;
}



Measured memory_bytes: 3612
#include<stdio.h>

long long int GCD(long long int a,long long int b)
{
    if(b!=0)
        return GCD(b,a%b);
    else
        return a;
}
int main()
{
    long long int a,b;
    while(scanf("%lld%lld",&a,&b)!=EOF){
    printf("%lld %lld\n",GCD(a,b),(a*b)/GCD(a,b));
    }
    return 0;
}

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

int main(){
  double r;
  cin>>r;
  cout<<2*r*3.141592;
}


Measured memory_bytes: 3788
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

long long t1, t2, a1, a2, b1, b2;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> t1 >> t2;
	cin >> a1 >> a2;
	cin >> b1 >> b2;
	if (a1 < b1) {
		swap(a1, b1);
		swap(a2, b2);
	}
	if ((a1 > b1 && a2 >= b2)) {
		cout << 0 << E;
		return 0;
	}
	if (a1 == b1) {
		cout << "infinity" << E;
		return 0;
	}
	if (a1*t1 + a2 * t2 == b1 * t1 + b2 * t2) {
		cout << "infinity" << E;
		return 0;
	}
	long long tmp1 = a1 * t1 - b1 * t1;
	long long tmp2 = b1 * t1 + b2 * t2 - (a1*t1 + a2 * t2);
	if (tmp2 < 0) {
		cout << 0 << E;
		return 0;
	}
	long long ans = ((tmp1  + tmp2 - 1)/ tmp2) * 2;
	if (tmp1%tmp2 == 0) ans++;
	ans--;
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#! /usr/bin/env python3
from collections import defaultdict
import heapq
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))
def make_array(dim, type=int): return defaultdict(lambda: defaultdict(type))


INF=10**20
def main():
    N,M,S=mi()
    
    G = [[] for _ in range(N+1) ]
    T = [None] * M
    for i in range(M):
        u,v,a,b=mi()
        T[i] = (u,v,a,b)
        G[u].append((i,v,a,b)) # i番目の路線
        G[v].append((i,u,a,b))
        

    
    C = []
    D = []
    for i in range(N):
        c,d = mi()
        C.append(c)
        D.append(d)
    
    cost = defaultdict(lambda: defaultdict(int))
    E = defaultdict(lambda: [])
    for i in range(0,2501):
        for track in T:
            u,v,a,b = track
            if i-a < 0: continue
            cost[(u,i)][(v,i-a)] = b
            cost[(v,i)][(u,i-a)] = b
            E[(u,i)].append((v,i-a))
            E[(v,i)].append((u,i-a))
            
        
        for j in range(N):
            c,d = C[j],D[j]
            cost[(j+1,i)][(j+1,i+c)] = d
            E[(j+1,i)].append((j+1,i+c))





    if S > 2500: S = 2500

    s = (1,S)
    hq = [(0,s)]
    heapq.heapify(hq)

    dist = defaultdict(lambda: INF)
    dist[s] = 0
    while hq: 
        d,x = heapq.heappop(hq) # sからxまでの最短経路を探索する
        if dist[x] < d: continue

        for e in E[x]:
            # print(dist[e] , dist[x] , cost[x][e])
            if dist[e] > dist[x] + cost[x][e]:
                dist[e] = dist[x] + cost[x][e]
                heapq.heappush(hq,(dist[e],e))
    
    for t in range(2,N+1):
        ans = INF
        for i in range(0,2501):
            ans = min(ans,dist[(t,i)])
        print(ans)

    # if dist[t] == INF: return -1
    # return dist[t]






if __name__ == "__main__":
    main()

Measured memory_bytes: 229632
#include<iostream>
#include<algorithm>
#include<string.h>
#include<queue>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long double ll;
struct node {
	ll x, y;
friend bool operator <(node a, node b) {
	return atan2(a.x, a.y) < atan2(b.x, b.y);
}

}r[1234567];


int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> r[i].x >> r[i].y;
	}
	sort(r, r + n);
	ll x, y, ans = 0;
	for (int i = 0; i < n; i++) {
		x = r[i].x; y = r[i].y;
		ans = max(ans, r[i].x * r[i].x + r[i].y * r[i].y);
		for (int j = (i + 1) % n; j != i; j = (j+1)%n) {
			x += r[j].x; y += r[j].y;
			ans = max(ans, x * x + y * y);
		}
	
	}
	cout << fixed << setprecision(30) << ((long double)sqrt(ans)) << '\n';
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#include <deque>
#include <set>
#include <unordered_map>
#include <complex>
#include <fstream>
using namespace std;
using ll = long long;
using ld = long double;
const int mxn = 1e5+5;
char s[mxn];

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

	int n; cin>>n;
	int k; cin>>k;
	int block = 1;
	cin>>s;
	for(int i=1; i<n; i++) if(s[i]!=s[i-1]) block++;

	int ans = n-(block-2*k); 
	if(ans>=n) ans = n-1;
	cout << ans << '\n';

	
	return 0;
}

Measured memory_bytes: 3292
import numpy as np
S = list(map(int, input()))

tmp = [0]*len(S)
if S[0] == 1:
    for ii in range(0,len(S),2):
        tmp[ii] = 1
else:
    for ii in range(1,len(S),2):
        tmp[ii] = 1

A = []
for ii in range(len(tmp)):
    A.append(S[ii]-tmp[ii])
    
count = np.count_nonzero(A)

print(count)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int X, t;
  cin >> X >> t;
  cout << max(X - t, 0) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    int ans=0;
    rep(i,n){
        while(a[i]%2==0){
            ++ans;
            a[i]/=2;
        }
    }
    cout<<ans<<endl;
}


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

int main(){
    int n, m;
    string username;
    set<string> user;
    int door=1;
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> username;
        user.insert(username);
    }
    cin >> m;
    for(int i=0;i<m;++i){
        cin >> username;
        if(user.find(username)==user.end()) cout << "Unknown ";
        else{
            if(door) cout << "Opened by ";
            else cout << "Closed by ";
            door = 1 - door;
        }
        cout << username << endl;
    }
}

Measured memory_bytes: 1232
#include <iostream>
using namespace std;
int main(){
  int M1,D1;
  cin >> M1 >> D1;
  int M2,D2;
  cin >> M2 >> D2;
  if(M1+1==M2){
    cout << 1 << endl;
  }else{
    cout << 0 << endl;
  }
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  int32 dx = tx-sx;
  int32 dy = ty-sy;
  REP(i,dx){
    cout << 'R';
  }
  REP(i,dy){
    cout << 'U';
  }
  REP(i,dx){
    cout << 'L';
  }
  REP(i,dy+1){
    cout << 'D';
  }
  REP(i,dx+1){
    cout << 'R';
  }
  REP(i,dy+1){
    cout << 'U';
  }
  cout << "LU";
  REP(i,dx+1){
    cout << 'L';
  }
  REP(i,dy+1){
    cout << 'D';
  }
  cout << 'R';
  cout << endl;
  return 0;
}

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

using namespace std;

int main(void){
	long long int n, h;

	cin >> n >> h;

	vector<int> a(n), b(n);

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

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	int left = 1, right = 1000000000, mid;

/*	while (left <= right){
		mid = (left + right)/2;
		long long int id_a = n-1, id_b = n-1, num = mid, sum = 0;
		while (num > 0){
			if (b[id_b] > a[id_a]){
				sum += b[id_b];
				id_b--;
				num--;
			}
			else {
				sum += num*a[id_a];
				break;
			}
		}
		if (h <= sum){
			right = mid - 1;
		}
		else
			left = mid + 1;
	}
*/

	int id_b = n - 1, num = 0;
	while (1){
		if (id_b >= 0 && b[id_b] > a[n-1]){
			h -= b[id_b];
			num++;
			id_b--;
			if (h <= 0)
				break;
		}
		else {
			num += (h + a[n-1] - 1)/ a[n-1];
			break;
		}
	}
	left = num;



	cout << left << endl;
}


Measured memory_bytes: 1024
/// wa ^3^

#pragma GCC optimize("O3")

#include<bits/stdc++.h>
                           
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;
 
using ll = long long;
using pii = pair<int, int>;                                   

const int MOD = 1e9 + 7;
const int INF32 = 1e9 + 1e2;

template<typename T> istream 
&operator>>(istream &a, vector<T> &v) { 
for (auto& x : v) a >> x; return a; }

void stndrtn() {
#ifdef accepted
    freopen(".in", "r", stdin);
#endif        
}

const bool flag = 0;

const int N = 2e3+10;

ll dp[N][N], sum[N][N];

void maincode() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    cin >> a >> b;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (a[i-1] == b[j-1]) {
                dp[i][j] = (sum[i-1][j-1]+1) % MOD;
            }
            sum[i][j] = (sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + dp[i][j] + MOD) % MOD;
        }
    }
    cout << sum[n][m]+1;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr), stndrtn();
    int ts = 1;
    if (flag) 
        cin >> ts;
    while (ts--)
        maincode(); 
    return 0;
}

Measured memory_bytes: 63104
n = int(input())

def divisor(n):
    res = 0
    for i in range(1,int(n**0.5)+1):
        if n % i  == 0:
            res += 1
            if i != n//i:
                res += 1
    return res

ans = 0
for i in range(1, n+1, 2):
    if divisor(i) == 8:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>

using namespace std;

string s;
long long m, a, r, c, h;

int main()
{
	long long n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> s;
		if (s[0] == 'M')
			m++;
		if (s[0] == 'A')
			a++;
		if (s[0] == 'R')
			r++;
		if (s[0] == 'C')
			c++;
		if (s[0] == 'H')
			h++;
	}
	cout << m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h;
	return 0;
}

Measured memory_bytes: 256
M = int(raw_input())
for _ in xrange(M):
    S = raw_input()
    a = {S}
    for i in xrange(len(S)):
        L = S[:i]
        R = S[i:]
        L2 = L[::-1]
        R2 = R[::-1]
        a |= {L + R2, L2 + R, L2 + R2, R + L, R + L2, R2 + L, R2 + L2}
    print(len(a))

Measured memory_bytes: 6312
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;

int main()
{
    static const double pi = 3.141592653589793;
    double a,b,c;
    cin >> a >> b >> c;
    double s,l,h;
    s = a * b * sin(pi * c / 180) / 2;
    l = a + b + sqrt(a * a + b * b - 2*a*b*cos(c*pi/180));
    h = s * 2 / a;
    printf("%lf\n%lf\n%lf\n",s,l,h);
}


Measured memory_bytes: 3364
def main():
    n = int(input())
    AB = [[int(e) for e in input().split()] for i in range(n)]

    AB.sort(key=lambda x: x[1])

    s = 0
    for ab in AB:
        a, b = ab
        s += a
        if s > b:
            print('No')
            exit()

    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 88024
// https://atcoder.jp/contests/agc028/tasks/agc028_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int c, int d) { return c / gcd(c, d) * d; }

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    int lc = lcm(n, m);
    int gc = gcd(n, m);
    unordered_map<int, char> v;
    for (int i = 0; i < n; i += n / gc) {
        v[i * lc / n] = s[i];
    }
    for (int i = 0; i < m; i += m / gc) {
        if (v[i * lc / m] != t[i]) {
            cout << "-1\n";
            return 0;
        }
    }
    cout << lc << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
  int a, b, c, k, nokori;
  scanf("%d %d %d %d", &a, &b, &c, &k);
  if (k <= a) {
    printf("%d\n", k);
    exit(0);
  } else {  // k>aの時 bも使うか判定
    nokori = k - a;
    if (nokori <= b) {  // bも使うならaだけ
      printf("%d\n", a);
    } else {  // cも使うなら
      nokori = nokori - b;
      printf("%d\n", a - nokori);
      exit(0);
    }
  }
  return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <set>
#include <math.h>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;
int main()
{
  string s;
  cin>>s;
  int ans =0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='o')
      ans++;
  }
  cout<<700+100*ans;
 
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int sum=0,n,i;
    string str;
    cin>>n;
    cin>>str;
    for(i=0;i<n;i++)
   {

     if(str[i]=='A' && str[i+1]=='B' && str[i+2]=='C')
     {
         sum++;
     }

   }
   cout<<sum<<endl;
 return 0;
}


Measured memory_bytes: 3624
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n)  for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int n,m;  cin >> n >> m;
  vll x(n),y(n),z(n);
  rep0(i,n){
    cin >> x[i] >> y[i] >> z[i];
  }
  ll ans = 0;
  for(int i = 0; i < (1 << 3); i++){
    vll cnt(n);
    rep0(j,n){
      if(i >> 0 & 1){
        cnt[j] -= x[j];
      }else{
        cnt[j] += x[j];
      }
      if(i >> 1 & 1){
        cnt[j] -= y[j];
      }else{
        cnt[j] += y[j];
      }
      if(i >> 2 & 1){
        cnt[j] -= z[j];
      }else{
        cnt[j] += z[j];
      }
    }
    sort(all(cnt),greater<ll>());
    ll sum = 0;
    rep0(j,m){
      sum += cnt[j];
    }
    ans = max(ans,sum);
  }
  cout << ans;
}


Measured memory_bytes: 256
using System;
 
class P
{
    static void Main()
    {
  //input = input.split('\n');
  //var firstLine = input[0];
  var firstLine = int.Parse(Console.ReadLine());
  //s = firstLine[0].split('');
  //t = input[1].split('');
  //var n = 0;
 Console.WriteLine(firstLine * firstLine);
  
  }
}

Measured memory_bytes: 11092
'use strict'
function Main(input){
  var N=input.trim()-0;
  var M=Math.pow(10,9)+7;
  var A=[1,4];//A[i]はi+1文字、okかつ最後の一文字がAの文字列数%M
  var G=[1,4];
  var AG=[0,1];
  var AC=[0,1];
  var GA=[0,1];
  var A_TG_G=[0,0,2];
  var AG_TG_=[0,0,2];
  var AGG=[0,0,1];
  var all=[4,16];
  for(let i=2;i<110;i++){
    all[i]=(4*all[i-1]-AG[i-1]-AC[i-1]-GA[i-1]-A_TG_G[i-1]-AG_TG_[i-1]+AGG[i-1])%M;
    A[i]=all[i-1];
    G[i]=all[i-1]-AC[i-1];
    AG[i]=A[i-1];
    AC[i]=A[i-1]-GA[i-1];
    GA[i]=G[i-1];
    A_TG_G[i]=2*A[i-2];
    AG_TG_[i]=2*AG[i-1];
    AGG[i]=AG[i-1];
  }
  console.log(all[N-1]);
}

Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7372
# reference: https://img.atcoder.jp/abc125/editorial.pdf
N = int(input())
A = list(map(int, input().split()))

dp = [[0, 0] for _ in range(N + 1)]
dp[0] = [0, -float("inf")]
for i in range(N):
    dp[i + 1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i])
    dp[i + 1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i])

print(dp[N][0])


Measured memory_bytes: 25588
def readinput():
    n,a,b=list(map(int,input().split()))
    s=input()
    return n,a,b,s

def main(n,a,b,s):
    kokunai=0
    kaigai=0
    for c in s:
        if c=='a':
            if kokunai+kaigai<a+b:
                print('Yes')
                kokunai+=1
            else:
                print('No')
        elif c=='b':
            if kokunai+kaigai<a+b and kaigai<b:
                print('Yes')
                kaigai+=1
            else:
                print('No')
        else:
            print('No')

if __name__=='__main__':
    n,a,b,s=readinput()
    main(n,a,b,s)


Measured memory_bytes: 9256
#include <stdio.h>

int W,H,x,y,r;

main(){
  
  scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
  
  if((W>=x+r && H>=y+r)&& (x-r>=0 && y-r>=0)){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
return 0;

}
     

Measured memory_bytes: 584
#include <iostream>
using namespace std;
int main(){
    int A,B;
    cin >> A >> B;
    int count = 0;
    for (int i = 0; i < B-A+1; i++){
        int X = A + i;
        int pick;//取り出す桁
        int reverse = 0; //反転する
        int mp = X;
        while(mp > 0){
            pick = mp%10;
            reverse = reverse*10 + pick;
            mp = mp/10;
        }
        if (reverse == X ){
            count += 1;
        }

    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>
#include <iomanip> //cout << fixed << setprecision(15) << << endl;
#include <cassert>
//#include "atcoder/all"

using namespace std;
//using namespace atcoder;

typedef long long ll;

#define pb push_back
#define rep(i, n) for(int i=0;i<(n);i++)
#define REP(i, n) for(int i=1;i<=(n);i++)
#define P pair<int,int>

int mx8[] = {0, 0, 1, -1, -1, 1, -1, 1};
int my8[] = {-1, 1, 0, 0, -1, -1, 1, 1};
int mx4[] = {1, -1, 0, 0};
int my4[] = {0, 0, -1, 1};

const int MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    unsigned long long ans = 1;
    vector<unsigned long long> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    rep(i, n)
    {
        if (a[i] == 0)
        {
            cout << 0 << endl;
            return 0;
        }
        if (ans > 1000000000000000000 / a[i])
        {
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4052
N, K = map(int,input().split())
ans = 0
cnt = 0
s = list(input())
for i in range(N-1):
    if s[i] == s[i+1]:
        ans += 1
    else:
        cnt += 1
if cnt == 1:
    ans = ans + 1
else:
    ans = ans + 2 * min(K,cnt)
print(min(ans,N-1))

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

void Acout(int A[],int N){
    rep(i,N){
        if(i)cout<<" ";
        cout<<A[i];
    }
    cout<<endl;
}

int bubblesort(int A[],int N){
    int flag=1;
    int ns=0;
    int i=0;
    while(flag){
        flag=0;
        for(int j=N-1;j>=i+1;j--){
            if(A[j]<A[j-1]){
                swap(A[j],A[j-1]);flag=1;ns++;
            }
        }
        i++;
    }
    return ns;
}

int main(){
    int N;
    cin>>N;
    int A[N];
    int ns;

    rep(i,N)cin>>A[i];
    ns = bubblesort(A,N);
    Acout(A,N);
    cout<<ns<<endl;
}


Measured memory_bytes: 3112
# include<stdio.h>
int main()
{
    int a,b,c,d,e;
    scanf("%d%d%d",&a,&b,&c);
    d=a-b;
    e=c-d;
    if(e>0) printf("%d\n",e);
    else printf("0\n");
    return 0;
}


Measured memory_bytes: 128
n,k=map(int,input().split())
a=list(map(int,input().split()))
ato=[]
zen=[]
for i in range(n):
    now=a[i]
    temp=0
    if(i!=n-1):
        for j in range(i+1,n):
            if(now>a[j]):
                temp+=1
    ato.append(temp)
    temp=0
    for j in range(n):
        if(a[j]>a[i]):
            temp+=1
    zen.append(temp)

#print(ato)
#print(zen)

ans=0
p=10**9+7
for i in range(n):
    ans+=(ato[i]*2+(k-1)*zen[i])*k//2
    ans=ans%p
print(ans%p)

Measured memory_bytes: 3188
#include <bits/stdc++.h>  // ver2.2.8
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define COUNT(a,k) upper_bound(ALL(a),k)-lower_bound(ALL(a),k)
#define BIGGER(a,k) a.end()-upper_bound(ALL(a),k)
#define SMALLER(a,k) lower_bound(ALL(a),k)-a.begin()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl
#define _ <<' '<<
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){if(!a[lY].empty()){Vout(a[lY]);}else cout<<endl;}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define Verr(a) rep(iZ,0,a.size()-1)cerr<<a[iZ]<<' ';cerr<<a.back()<<endl
#define VVerr(a) rep(J,0,a.size()){if(!a[J].empty()){Verr(a[J]);}else cerr<<'.'<<endl;}
#define VPerr(a) rep(iX,0,a.size())cerr<<a[iX].FI<<' '<<a[iX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void press(auto &v){v.erase(unique(ALL(v)),v.end());}  //  圧縮
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n;
  cin >> n;
  n--;
  cout<<n/2<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    if(a + b > n + 1 || n > a * b)
    {
        cout << -1 << endl;
        return 0;
    }

    vector<int> ans;
    ll s = n - a;
    int cur = n;
    for(int i = 1; i <= a; i++)
    {
        ll num = min(s, b-1) + 1;
        s -= num-1;
        for(int j = 1; j <= num; j++)
        {
            ans.push_back(cur-num+j);
        }
        cur -= num;
    }
    reverse(ans.begin(), ans.end());
    for(int i = 0; i < ans.size(); i++)
    {
        cout << ans[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3440