akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <numeric>
#include <tuple>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <unordered_map>
#include <type_traits>
#include <map>
#include <cstdio>
#include <string>

using namespace std;
using str = string;

#define rep(a,l,r) for(int a=(l);a<(r);a++)
#define get cin>>
#define put cout<<

int gcd_euclid(int u, int v) {
  int r;
  while (0 != v) {
    r = u % v; u = v; v = r; /* swap */
  }
  return u;
}

// 最大公約数算出
int calc_gcd(const vector<int> vec){
	int gcd = *min_element(vec.begin(), vec.end());
	for (const int ele: vec){
		gcd = gcd_euclid(gcd,ele);
	}
	return gcd;
}

// 最小公倍数
int calc_lcm(const vector<int> vec) {
	int tmp = 1;
	for (const int ele: vec){
		tmp *= ele;
	}
	int gcd = calc_gcd(vec);
	return tmp/gcd;
}

std::string join(const std::vector<std::string>& v, const char* delim = 0) {
  std::string s;
  if (!v.empty()) {
    s += v[0];
    for (decltype(v.size()) i = 1, c = v.size(); i < c; ++i) {
      if (delim) s += delim;
      s += v[i];
    }
  }
  return s;
}

// nが奇数、偶数の場合の場合分け
// n & 1 ? odd : even

// distinctはsortしてunique + erase
// https://qiita.com/ysk24ok/items/30ae72f4f1060b088588
//sort(vec.begin(), vec.end());
//vec.erase(unique(vec.begin(), vec.end()), vec.end());

void run() {
	int n,k;
	get n;get k;

	int ans = 0;
	if (n<k) {
		ans+=k;
		k--;
	} else {
		ans+=n;
		n--;
	}

	if (n<k) {
		ans+=k;
		k--;
	} else {
		ans+=n;
		n--;
	}

	put ans;

}


int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);run();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<long 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; }

ll calc(ll c, VL x){
    ll n = x.size();
    x.push_back(c);
    VL s(n + 1);
    REP(i,n) s[i+1] = s[i] + x[i];
    ll ans = 0;
    REP(i,n){
        ll r = n - 1 - i;
        ll r1 = r / 2, r2 = r - r1;
        ll d = x[i] + 2 * (s[i + 1 + r1] - s[i + 1] - r1 * x[i]) + 2 * (r2 * x[i] + r2 * c - (s[n] - s[n - r2]));
        // cout << (s[i + r1] - s[i] - r1 * x[i]) << endl;
        if (r % 2 == 0){
            d -= x[i + r1] - x[i];
        }else{
            d -= x[i] + c - x[n - r2];
        }
        // cout << i << " " << d << endl;
        chmax(ans, d);
    }
    // cout << ans << endl;
    return ans;
}

int main() {
    ll c, n;
    cin >> c >> n;
    VL x(n);
    REP(i,n) x[i] = in();
    ll ans = calc(c, x);
    reverse(ALL(x));
    REP(i,n) x[i] = c - x[i];
    chmax(ans, calc(c, x));
    cout << ans << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

bool check(int j, string s1){
	if(s1[j] == '-') return true;
	else return false;
}


int main() {
	int a, b;
	string s;
	cin >> a >> b >> s;
	REP(i, 0, a){
		if(check(i, s)){
			cout << "No";
			exit(0);
		}
	}
	if(!check(a, s)){
		cout << "No";
		exit(0);
	}
	REP(i, a+1 , a+b+1){
		if(check(i, s)){
			
			cout << "No";
			exit(0);
		}
	}
	cout << "Yes";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	int n;
	cin >> n;
	
	cout << 1000 * (n / 500) + ((n % 500) / 5) * 5;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
  
int main() {
  int N,L; cin >> N >> L;
  string S[N]; rep(i,N) cin >> S[i];
  
  sort(S,S+N);
  string ans = "";
  rep(i,N) ans += S[i];
  cout << ans << endl;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define dbg(x) cout << #x << ": " << (x) << '\n'
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
const ll mod = 1e9 + 7;

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

   int h, w;
   cin >> h >> w;
   vector <string> s(h);
   for (auto &i : s)
      cin >> i;
   vector <vector <ll>> dp(h + 1, vector <ll> (w + 1));

   for (int i = 1; i <= h; i++) {
      if (s[i - 1][0] == '#')
         break;
      dp[i][0] = 1;
   }
   for (int i = 1; i <= w; i++) {
      if (s[0][i - 1] == '#')
         break;
      dp[0][i] = 1;
   }

   for (int i = 1; i < h; i++) {
      for (int j = 1; j < w; j++) {
         if (s[i][j] == '.') {
            dp[i][j] = dp[i - 1][j] * (s[i - 1][j] == '.') + dp[i][j - 1] * (s[i][j - 1] == '.');
            dp[i][j] %= mod;
         }
      }
   }

   cout << dp[h - 1][w - 1] << '\n';

   return 0;
}

Measured memory_bytes: 9216
from heapq import*
(N, M), *t = [map(int, s.split()) for s in open(0)]
q = [0] * 10**5
v = [[] for _ in q]
for a, b in t:
    v[a - 1] += b,
z = 0
for i in v[:M]:
    for j in i:
        heappush(q, -j)
    z += -heappop(q)
print(z)

Measured memory_bytes: 63928
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    int N, K;
    cin >> N >> K;

    N%=K;
    ans = min(N,K-N);
    cout << ans << endl;
    
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc161/abc161_c && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc161/abc161_c && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc161/abc161_c && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x,y;
    cin >>x>>y;
    int a[7]={1,3,5,7,8,10,12};
    int b[4]={4,6,9,11};
    int q=0;
    int w=0;
    rep(i,7){
        if(x==a[i]) q=1;
        if(y==a[i]) w=1;
    }
    if(x==2) q=2;
    if(y==2) w=2;
    if(q==w) cout << "Yes" << endl;
    else cout <<"No" <<endl;





}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)
const int INF = 1<<29;
using namespace std;
using ll = long long;
int main(){
	string s , a = "";
	cin>>s;
	for(auto i : s){
        if(i=='B'){
            if(a.size()){
                a.pop_back();
            }
        }
	    else{
            a.push_back(i);
        }
    }
	cout << a << endl;
}

Measured memory_bytes: 3636
N, M = map(int, input().split())
AB = [[int(x) for x in input().split()] for _ in range(N)]

AB = sorted(AB)
ans = 0
for a, b in AB:
    if M==0:
        break
    elif M > b:
        M -= b
        ans += a * b
    else:
        ans += a * M
        break
print(ans)

Measured memory_bytes: 22376
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef pair< int, int > Pi;
map< string, int > min_cost;

Pi getPos(string s){
  int white = s.find('0');
  return make_pair( white % 4, white / 4);
}
int getPos(Pi point){
  return point.second * 4 + point.first;
}


int bfs(string s){

  queue< string > que;
  const int dy[] = { 0, 1, 0, -1}, dx[] = { 1, 0, -1, 0};

  que.push(s);
  min_cost[s] = 0;

  while(!que.empty()){

    string p = que.front(); que.pop();
    Pi white = getPos(p);

    for(int i = 0; i < 4; i++){
      int ny = white.second + dy[i], nx = white.first + dx[i];
      string next = p;
      if(ny < 0 || ny >= 2 || nx < 0 || nx >= 4) continue;
      swap( next[getPos(make_pair(nx,ny))], next[getPos(white)]);
      if(min_cost.find(next) != min_cost.end() || min_cost[next] > min_cost[p] + 1) continue;
      min_cost[next] = min_cost[p] + 1;
      que.push(next);
    }

  }
 
  return 0;
}


int main(){
  bfs("01234567");
  string s;
  s.resize(8);
  while(cin >> s[0] >> s[1] >> s[2] >> s[3] >> s[4] >> s[5] >> s[6] >> s[7]){
    cout << min_cost[s] << endl;
  }
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

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

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

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

void solve() {
  int N;
  cin >> N;
  ll p = 1, q = 1;
  for (int i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    ll c = (p + a - 1) / a;
    ll d = (q + b - 1) / b;
    p = max(c, d) * a;
    q = max(c, d) * b;
  }
  cout << p + q << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
int arr[100015];
int dp[100015];
void solve()
{
   int n;int k;cin>>n>>k;
   dp[0]=0;
   for(int i=0;i<n;i++)
   cin>>arr[i];
   
   for(int i=1;i<n+10;i++)
   dp[i]=1e9;
   
   for(int i=0;i<n;i++)
   {
       for(int j=1;j<=k;j++)
       {
           dp[i+j]=min(dp[i+j],dp[i]+abs(arr[i+j]-arr[i]));
       }
   }
   cout<<dp[n-1]<<endl;
}
int32_t main()
{
    rapido;
    int t;t=1;
    while(t--)
    solve();
}

Measured memory_bytes: 5164
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

ll N;

constexpr ll max_n = 1000006;
bool is_prime[max_n];

void solve(){
    int cnt=0;
    for(int i=2;i<=N;i++) if(is_prime[i]) cnt++;
    cout << cnt << endl;
}

int main(){
    rep(i,max_n) is_prime[i]=true;

    for(int i=2;i<max_n;i++){
        if(!is_prime[i]) continue;
        for(int j=2;i*j<max_n;j++) is_prime[i*j]=0;
    }
    while(cin>>N){
        solve();
    }
}

Measured memory_bytes: 3908
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
  int key;
  node *left,*right,*p;
  node(){}
  node(int key):key(key){left=right=p=NULL;};
};
node *root;
void insert(node z){
  node *y=NULL;
  node *x=root;
  while(x!=NULL){
    y=x;
    if(z.key<x->key) x=x->left;
    else x=x->right;
  }
  z.p=y;
  if(y==NULL) root=new node(z);
  else if(z.key<y->key) y->left=new node(z);
  else y->right=new node(z);
}
bool find(int z){
  node *x=root;
  while(x!=NULL){
    if(z==x->key) return true;
    if(z<x->key) x=x->left;
    else x=x->right;
  }
  return false;
}
void inorderTreeWalk(node *v){
  if(v==NULL) return;
  inorderTreeWalk(v->left);
  cout<<" "<<v->key;
  inorderTreeWalk(v->right);
}
void preorderTreeWalk(node *v){
  if(v==NULL) return;
  cout<<" "<<v->key;
  preorderTreeWalk(v->left);
  preorderTreeWalk(v->right);
}
signed main(){
  int n;
  cin>>n;
  root=NULL;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    //cout<<(root==NULL?-1:root->key)<<endl;
    if(s=="print"){
      inorderTreeWalk(root);
      cout<<endl;
      preorderTreeWalk(root);
      cout<<endl;
      continue;
    }
    int x;
    cin>>x;
    if(s=="insert"){
      insert(node(x));
    }
    if(s=="find"){
      cout<<(find(x)?"yes":"no")<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 21900
/// Updated! https://www.youtube.com/watch?v=U07_n9xGIlM
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define dbug printf("I am here\n");
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int maxn = 2e5+100;

const ll inf = 1e18;
ll arr[maxn];

int main()
{
    fast;
    ll ans = 0;
    ll mn = 1e9;
    int n; cin >> n;
    for(int i = 1; i<=n; i++)cin >> arr[i];
    for(int i = 1; i<=n; i++){
        if(arr[i]<=mn)ans++;
        mn = min(mn,arr[i]);
    }
    cout << ans << endl;
    return 0;
}
/*



*/



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

l = []
for i in range(n):
    s, p = input().split()
    p = int(p)
    l.append([s, p, i+1])
    
#print(l)
l = sorted(l, key=lambda x:x[1], reverse=True)
#print(l)
l = sorted(l, key=lambda x:x[0])
#print(l)

for item in l:
    print(item[2])

Measured memory_bytes: 3060
n,m = map(int,input().split())
 
lis = [[] for i in range(n)] #なぜか知らんけど[[]]*nじゃだめらしい
 
for i in range(m):
  a,b = map(int,input().split())
  lis[a-1].append(b-1)
  lis[b-1].append(a-1)
 
 
if set(lis[-1]).isdisjoint(set(lis[0])):
    print('IMPOSSIBLE')
else:
  print('POSSIBLE')

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

int main(){
  int N;
  cin >> N;
  int Xmin = 100;
  
  for(int i=0; i<N; i++){
    int A;
    cin >> A;
    int count = 0;
  
    while(A % 2 == 0){
      A /= 2;
      count++;
    }
    Xmin = min(Xmin, count);
  }
  cout << Xmin <<endl;
}

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

string c[3];
int now[3] = {0}, t = 0;

int main() {
  for(int i = 0; i < 3; ++i) cin >> c[i];
  while(1) {
    if(now[t] == c[t].size()) break;
    ++now[t];
    t = c[t][now[t] - 1] - 'a';
  }

  cout << (char)(t + 'A') << endl;
  return 0;
}

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

int root(vector<int> &U,int x){
	if(x==U[x]){
		return x;
	}else{
		return U[x]=root(U,U[x]);
	}
}

void unite(vector<int> &U,int x,int y){
	int px=root(U,x);
	int py=root(U,y);
	U[px]=py;
}

bool same(vector<int> &U,int x,int y){
	return root(U,x)==root(U,y);
}

int main(){
	int n,q,command,x,y;
	cin >> n >> q;
	
	vector<int> U(n);
	for (int i=0;i<n;i++){
		U[i]=i;
	}
	
	for(int i=0;i<q;i++){
		cin >> command >> x >> y;
		if(command==0){
			unite(U,x,y);
		}else{
			cout << same(U,x,y) <<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1348
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i]--;
    }

    ll next = a[0];
    ll cnt = 1;
    while (1)
    {
        if (next == 0 || cnt > n)
        {
            cout << -1 << endl;
            break;
        }
        if (next == 1)
        {
            cout << cnt << endl;
            break;
        }
        next = a[next];
        cnt++;
    }
}

Measured memory_bytes: 1024
d = {}
d[0] = 'pon'
d[1] = 'pon'
d[2] = 'hon'
d[3] = 'bon'
d[4] = 'hon'
d[5] = 'hon'
d[6] = 'pon'
d[7] = 'hon'
d[8] = 'pon'
d[9] = 'hon'
x = int(input())
a = x % 10
print(d[a])

Measured memory_bytes: 9200
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< string, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789


///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int N;
int L[112];
int ans = 0;


int main(){

    cin>>N;
    REP( i, N ) cin>>L[i];
    
    sort( L, L+N );
    
    REP( i, N ){
        FOR( j, i+1, N ){
            if( L[i] == L[j] ) continue;
            FOR( k, j+1, N ){
                if( L[j] == L[k] ) continue;
                if( L[i]+L[j] <= L[k] ) break;
                ans++;
            }
        }
    }
    
    cout<<ans<<endl;
    
    return 0;
}



Measured memory_bytes: 3160
import sys 

S = sys.stdin.readline()

def is_mmyy(s):
    former, latter = int(S[0:2]), int(S[2:])
    if former >= 1 and former <= 12:
        return True
    return False

def is_yymm(s):
    former, latter = int(S[0:2]), int(S[2:])
    if latter >= 1 and latter <= 12:
        return True
    return False


# MMYY && YYMM
if is_mmyy(S) and is_yymm(S):
    print("AMBIGUOUS")
# MMYY
elif is_mmyy(S):
    print("MMYY")
# YYMM
elif is_yymm(S):
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int num[3];

int main(void){
    int A, B, C;
    vector <int> num;
    int cnt = 0;
    
    
    cin >> A >> B >> C;
    num.push_back(A);
    num.push_back(B);
    num.push_back(C);
    
    sort(num.begin(), num.end());
    
    if(num[1] < num[2]){
        while(num[1] < num[2]){
            num[0]++;
            num[1]++;
            cnt++;
        }
    }
    
    // cout << cnt << endl;
    
    if((num[2] - num[0]) % 2 != 0){
        num[1]++;
        num[2]++;
        cnt++;
    }
    
    // cout << cnt << endl;
    
    cnt += (num[2] - num[0]) / 2;
    // cout << cnt << endl << endl;
    
    
    cout << cnt << "\n";
}

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

int main()
{
       int a, b, sum = 0;

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

       sum = a + b;
       if( sum >= 10)
              puts( "error" );
       else 
              printf("%d\n", sum );


       return 0;
}

Measured memory_bytes: 128
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      w: usize,
      h: usize,
      x: usize,
      y: usize,
   }
   let f = if x * 2 == w && y * 2 == h { 1 } else { 0 };
   println!("{} {}", (w * h) as f64 / 2.0, f);
}


Measured memory_bytes: 4352
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>
#define long long

using namespace std;

int main() {
	int n,k;
	string s;
	cin>>n>>k>>s;
	s[k-1]=(char)(s[k-1]-'A'+'a');
	cout<<s;
}


Measured memory_bytes: 3568
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
int a=0;
a+=(n-m)*100;
a+=m*1900;
for (int i=1;i<=m;i++)
a*=2;
cout<<a<<endl;
return 0;
}

Measured memory_bytes: 256
/*
 * @Author: Kaizyn
 * @Date: 2020-04-26 17:06:58
 * @LastEditTime: 2020-04-26 18:15:02
 */
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const int N = 2e3+7;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const double eps = 1e-7;
const double PI = acos(-1);
typedef pair<int, int> pii;

struct Node {
    int x, p;
    friend bool operator < (const Node &lhs, const Node &rhs) {
        return lhs.x > rhs.x;
    }
};

int n;
Node a[N];
long long dp[N][N];
// dp[i][j] take i, j on left

inline void solve()
{
    cin >> n;
    for (int i = 1, x; i <= n; ++i) {
        cin >> a[i].x;
        a[i].p = i;
    }
    sort(a+1, a+n+1);
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < i; ++j) {
            dp[i][j] = max(dp[i][j], dp[i-1][j]+1ll*a[i].x*abs(n-(i-j)+1-a[i].p));
        }
        for (int j = 1; j <= i; ++j) {
            dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1ll*a[i].x*abs(j-a[i].p));
        }
    }
    long long res = 0;
    for (int i = 0; i <= n; ++i) res = max(res, dp[n][i]);
    cout << res << endl;
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int testcase = 1;
    // cin >> testcase;
    for (int i = 1; i <= testcase; ++i) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 26272
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

pii INIT = pii(-1, -1);
int board[33][33];
int acc[33][33];
pii memo[33][33][33][33];

int H, W, E, S;

int getsum(int p, int q, int x, int y) {
    return board[x][y] - board[p][y] - board[x][q] + board[p][q];
}

// ?°???°??? (??????) ??????????????????
pii solve(int lx, int ly, int rx, int ry) {
    pii& ans = memo[lx][ly][rx][ry];
    if(ans != INIT) return ans;

    // ?°???°???????????¶???????????????????????§??????????????±???????????????????????????????????????
    int sum = getsum(lx, ly, rx, ry);
    if(sum < E - S) return ans = pii(0, INF);

    // ??????
    ans = pii(1, S - (E - sum));

    // ?¨??????????
    rep(i,lx+1,rx) {
        pii ra = solve(lx, ly, i, ry);
        pii rb = solve(i, ly, rx, ry);
        pii temp = pii(ra.first + rb.first, min(ra.second, rb.second));
        chmax(ans, temp);
    }

    // ????????????
    rep(i,ly+1,ry) {
        pii ra = solve(lx, ly, rx, i);
        pii rb = solve(lx, i, rx, ry);
        pii temp = pii(ra.first + rb.first, min(ra.second, rb.second));
        chmax(ans, temp);
    }
    return ans;
}

signed main() {
    while(cin >> H >> W >> S, H || W || S) {
        memset(board, 0, sizeof(board));
        rep(i,0,33) rep(j,0,33) rep(k,0,33) rep(l,0,33)
            memo[i][j][k][l] = INIT;
        rep(i,0,H) rep(j,0,W) cin >> board[i+1][j+1];
        rep(i,0,H) rep(j,0,W) board[i+1][j+1] += board[i+1][j];
        rep(j,0,W) rep(i,0,H) board[i+1][j+1] += board[i][j+1];

        E = getsum(0, 0, H, W);
        pii ans = solve(0, 0, H, W);
        printf("%lld %lld\n", ans.first, ans.second);
    }
    return 0;
}

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

int main() {
  int N,M,X,Y;
  cin >> N >> M >> X >> Y;
  int maxx=X,miny=Y,xi,yi;
  for(int i=0;i<N;i++) {
    cin >> xi;
    maxx=max(maxx,xi);
  }
  for(int j=0;j<M;j++) {
    cin >> yi;
    miny=min(miny,yi);
  }
  if(maxx<Y && miny>X && maxx<miny) cout << "No War" << endl;
  else cout << "War" << endl;
}
    


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define ull unsigned long long
#define EPS 1e-8
using namespace std;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
const double pi = acos(-1.0);
int read()
{
	int ret=0;char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	for(;ch>='0'&&ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret;
}
ll N,x,y,h,n; 
int main()
{
 	#ifdef TEST
	 	freopen("input.txt","r",stdin);
	#endif
	scanf("%I64d",&N);
	for(h=1;h<=3500;h++)
	{
		for(n=1;n<=3500;n++)
		{
			ll temp1=N*n*h;
			ll temp2=4*h*n-h*N-n*N;
			if(temp2>0&&temp1%temp2==0)
			{
				printf("%lld %lld %lld",h,n,temp1/temp2);
				return 0;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;
struct Edge{
    int from,to;
    LL capacity;
    Edge(int from,int to, LL capacity)
        : from(from),to(to),capacity(capacity) {};
};
typedef pair<int,int> pii;
typedef vector<vector<Edge>> Graph;
typedef vector<unordered_map<int, LL>> Flow; //(to,flow)
//typedef vector<vector<LL>> Flow;

LL add_flow(const Graph &g, Flow &flow, const vector<int> &level, vector<int> &iter, int u, int t, LL cur){
    if(u==t || cur==0) return cur;
    for(int &i= iter[u];i<g[u].size();++i){
        auto e=g[u][i];
        if(level[e.to] > level[u]){
            LL f= add_flow(g, flow, level, iter, e.to, t, min(cur,e.capacity-flow[e.from][e.to]));
            if(f > 0){
                flow[e.from][e.to] += f;
                flow[e.to][e.from] -= f;
                return f;
            }
        }
    }
    return 0;
}

LL maximumFlow(const Graph &g, Flow &flow, int s, int t){
    const LL INF=1<<30;
    int n=g.size();
    LL total=0;
    for(bool cont = true ; cont;){
        cont =false;
        vector<int> level(n,-1);
        level[s]=0;
        queue<int> Q;
        Q.push(s);
        for(int d = n; !Q.empty() && level[Q.front()] < d;){
            int u = Q.front();
            Q.pop();
            if(u == t) d = level[u];
            for(auto e : g[u]){
                if(e.capacity>flow[e.from][e.to] && level[e.to]==-1){
                    Q.push(e.to);
                    level[e.to]=level[u]+1;
                }
            }
        }
        vector<int> iter(n);
        while(true){
            LL f=add_flow(g,flow,level,iter,s,t,INF);
            if(f==0)break;
            total += f;
            cont = true;
        }
    }
    return total;
}
void add_edge(Graph &G, int a, int b, LL cap){
    G[a].push_back(Edge(a,b,cap));
    G[b].push_back(Edge(b,a,0));
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; //vertex,edge
    cin >> n;
    Graph G(n+2);
    Flow flow(n+2);
    LL ans =0;
    vector<LL> primes = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};

    for(int i = 1 ; i <=n ; i++){
        LL price; cin >> price;
        if(price>0){
            ans += price;
            add_edge(G,0,i,price);
            add_edge(G,i,n+1,0);
        }else{
            add_edge(G,0,i,0);
            add_edge(G,i,n+1,-price);
        }
        for(int j=0; j<25; ++j){
            if(i%primes[j]==0){
                add_edge(G,i,i/primes[j],LINF);
            }
        }
    }
    cout << ans - maximumFlow(G,flow,0,n+1) << endl;

    return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        long ans = 0;
        int dest = s.indexOf("B");
        int index = dest + 1;
        int nowIndex;
        while ((nowIndex = s.indexOf("W", index)) > 0) {
            ans += nowIndex - dest++;
            index = nowIndex + 1;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 28532
#include <bits/stdc++.h>
using namespace std;
using p = pair<int, int>;

int main()
{
    long long sum = 0;
    int k, ans;

    cin >> k;
    for (int i = 1; i < k + 1; i++) {
        for (int j = 1; j < k + 1; j++) {

            for (int m = 1; m < k + 1; m++) {
                ans = gcd(i, j);
                ans = gcd(ans, m);
                //cout << "(" << i << "," << j << "," << m << ") = " << ans << endl;
                sum += ans;
            }

        }
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3600
as = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = gets.to_i
puts as[k-1]


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(int argc, char const *argv[])
{
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    // 0: 左、1: 右向き
    vector<int> hoge(n);
    //cout << n << endl;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'L')
        {
            hoge[i] = 0;
        } else
        {
            hoge[i] = 1;
        }
    }
    int ans = 0;
    if (hoge[0] == 1 && hoge[1] == 1)
    {
        ans++;
    }
    
    for (int i = 1; i < n - 1; i++)
    {
        if ((hoge[i] == 0 && hoge[i - 1] == 0)||(hoge[i] == 1 && hoge[i + 1] == 1))
        {
            ans++;
        }
        
    }
    if (hoge[n - 1] == 0 && hoge[n - 2] == 0)
    {
        ans++;
    }
//    cout << ans << endl;
    // 幸福な人数の最大値はn - 1
    // 一回の操作で2人幸福にできるので、
    ans = min(n - 1, ans + 2 * k);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 896
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int ans;
		int i = 1;

		while (true) {
			ans = i * N;

			if (ans % 2 == 0) {
				System.out.println(ans);
				return;
			}

			i++;
		}
	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


Measured memory_bytes: 27044
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b,c;
    cin >> a >> b >>c;

    int A = a.size();
    int B = b.size();
    int C = c.size();
    if(a[A-1]==b[0] && b[B-1]==c[0])
        cout << "YES";
    else
        cout << "NO";
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int s = 1000;
  int e = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a < s) {
      s = a;
    }
    if (e < a) {
      e = a;
    }
  }
  cout << e - s << endl;
  return 0;
}


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

using namespace std;

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

        int c0 = 0;
        int c1 = 0;
        int c2 = 0;
        int c3 = 0;
        for (int i = 0;i < n;i++){
                string s;
                cin >> s;
                if (s == "AC"){
                        c0++;
                }
                else if(s == "WA"){
                        c1++;
                }
                else if(s == "TLE"){
                        c2++;
                }
                else if(s == "RE"){
                        c3++;
                }
        }

                cout << "AC x " << c0 << endl;
                cout << "WA x " << c1 << endl;
                cout << "TLE x " << c2 << endl;
                cout << "RE x " << c3 << endl;


                return 0;
}

Measured memory_bytes: 3580
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    if (n == 1)
    {
        cout << "Hello World" << endl;
    }
    else
    {
        int a, b;
        cin >> a >> b;
        cout << (a + b) << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] t = new int[n];
		int[] v = new int[n];
		int sumT = 0;
		for(int i = 0; i < n; i++){
		    t[i] = sc.nextInt();
		    sumT += t[i];
		}
		for(int i = 0; i < n; i++){
		    v[i] = sc.nextInt();
		}
		
		// 計算
		double result = 0;
		int[] V = new int[sumT];
		int[] minV = new int[sumT+1];
		int index = 0;
		for(int i = 0; i < n; i++){
		    for(int j = 0; j < t[i]; j++){
		        V[index] = v[i];
		        index++;
		        if(index == sumT) continue;
		        if(j < t[i]-1){
		            minV[index] = v[i];
		        }else{
		            minV[index] = min(v[i], v[i+1]);
		        }
		    }
		}
		int[] minA = new int[sumT+1];
		for(int i = 0; i < (sumT+2)/2; i++){
		    minA[i] = i;
		    minA[sumT-i] = i;
		}
		int[] r = new int[sumT+1];
		for(int i = 1; i < sumT+1; i++){
		    r[i] = min(r[i-1]+1, min(minV[i], minA[i]));
		}
		int[] l = new int[sumT+1];
		for(int i = 1; i < sumT+1; i++){
		    l[sumT-i] = min(l[sumT-i+1]+1, min(minV[sumT-i], minA[sumT-i]));
		}
		int[] res = new int[sumT+1];
		for(int i = 0; i < sumT+1; i++){
		    res[i] = min(r[i], l[i]);
		}
		
		for(int i = 1; i < sumT+1; i++){
		    result += (double)abs(res[i]-res[i-1])/2 + min(res[i], res[i-1]);
		}
		for(int i = 1; i < sumT+1; i++){
		    if(res[i] == res[i-1] && res[i-1] < V[i-1]) result += 0.25;
		}
		//System.out.println(Arrays.toString(V));
		//System.out.println(Arrays.toString(minV));
		//System.out.println(Arrays.toString(minA));
		//System.out.println(Arrays.toString(r));
		//System.out.println(Arrays.toString(l));
		//System.out.println(Arrays.toString(res));
		
		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 24020
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define MAX_NM 100000

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }


int N, M;
vector<int> jobs[MAX_NM + 1];
int main(int argc, char **argv) {
    cin >> N >> M;
    for(int i = 0; i < N; ++i) {
        int A, B;
        cin >> A >> B;
        jobs[A].push_back(B);
    }

    int res = 0;
    priority_queue<int> pq;

    for(int i = 1; i <= M; ++i) {
        for(int j = 0; j < jobs[i].size(); ++j) {
            pq.push(jobs[i][j]);
        }

        if(!pq.empty()) {
            res += pq.top();
            pq.pop();
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 5632
import sys


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, W = map(int, input().split())
    dp = [[0] * (N + 1) for _ in range(W + 1)]
    for i in range(1, N + 1):
        w, v = map(int, input().split())
        for j in range(W + 1):
            if j >= w:
                dp[j][i] = max(dp[j][i - 1], dp[j - w][i-1] + v)
            else:
                dp[j][i] = dp[j][i - 1]

    print(dp[W][N])


if __name__ == "__main__":
    main()


Measured memory_bytes: 154412
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

using vi = vector<int>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int a, b;
  cin >> a >> b;
  cout << (a - 1) * (b - 1);
}
#endif


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    string s,t;
    ll k;
    cin>>s>>k;
    ll l;
    t=s;
    l=s.size();
    char S=s[0];
    bool a=true;
    for(ll i=1;i<l;i++)if(S!=s[i]){
        a=false;
        break;
    }
    if(a){
        cout<<k*l/2<<endl;
    }
    else{
        ll ans1=0,ans2=0;
    for(ll i=1;i<l;i++){
        if(s[i]==s[i-1]){
            ans1++;
            i++;
        }
    }
    s+=t;
    l=l*2;
    for(ll i=1;i<l;i++){
        if(s[i]==s[i-1]){
            ans2++;
            i++;
        }
    }
    cout<<(ans2-ans1)*(k-1)+ans1<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()


int main() {
    int n;
    cin >> n;
    vector<ll> a(n), s(n+1, 0);
    map<ll, int> m;
    m[0]++;
    rep (i, n) {
        cin >> a[i];
        s[i + 1] = s[i] + a[i];
        m[s[i + 1]]++;
    }
    ll ans = 0;
    for (auto au: m) {
        ll val = au.second;
        if (val < 2) continue;
        ans += val * (val - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 15872
#include <iostream>

using namespace std;

int main()
{
    int H1, M1, H2, M2, K;    
    cin >> H1 >> M1 >> H2 >> M2 >> K;

    int A1 = 60 * H1 + M1;    
    int A2 = 60 * H2 + M2;
    int L = A2 - A1;
    cout << (L - K) << endl;


    return 0;    
}

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

int main(){
    int a,b;string op;bool chk=1;
    while(chk){
        cin>>a>>op>>b;
        if(op=="+") cout<<a+b<<endl;
        else if(op=="-") cout<<a-b<<endl;
        else if(op=="*") cout<<a*b<<endl;
        else if(op=="/") cout<<a/b<<endl;
        else break;
    }
}


Measured memory_bytes: 3128
H, W = map(int, input().split())
S = ["." + input() + "." for _ in range(H)]
S.insert(0, "." * W)
S.append("." * W)
dx, dy = [1, -1, 0, 0], [0, 0, 1, -1]

for h in range(H):
    for w in range(W):
        if not S[h][w] == "#":
            continue
        cnt = 0
        for i in range(4):
            if S[h + dy[i]][w + dx[i]] == "#":
                cnt += 1
        if cnt == 0:
            print("No")
            exit()
print("Yes")


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    long A = scan.nextLong();
    long B = scan.nextLong();
    long C = scan.nextLong();
    long D = scan.nextLong();
    long CD = leastCommonMultiple(C, D);

    long cStart;
    long dStart;
    long cdStart;
    if (A % C == 0) {
      cStart = A / C;
    } else {
      cStart = A / C + 1;
    }
    if (A % D == 0) {
      dStart = A / D;
    } else {
      dStart = A / D + 1;
    }
    if (A % CD == 0) {
      cdStart = A / CD;
    } else {
      cdStart = A / CD + 1;
    }

    long cEnd = B / C;
    long dEnd = B / D;
    long cdEnd = B / CD;

    long cn = cEnd - cStart + 1;
    long dn = dEnd - dStart + 1;
    long cdn = cdEnd - cdStart + 1;

    long result = B - A + 1 - cn - dn + cdn;

    System.out.println(result);

  }

  private static long leastCommonMultiple(long a, long b) {
    long temp;
    long c = a;
    c *= b;
    while ((temp = a % b) != 0) {
      a = b;
      b = temp;
    }
    return c / b;
  }
}



Measured memory_bytes: 22996
#include <iostream>
using namespace std;
 
int main(){
    int i, j, r, c;
    int a[102][102];
 
    cin >> r >> c;

    for (i = 1; i <= r + 1; i++){
        for (j = 1; j <= c + 1; j++){
            a[i][j] = 0;
        }
    }
 
    for (i = 1; i <= r; i++){
        for (j = 1; j <= c; j++){
            cin >> a[i][j];
            a[i][c+1] += a[i][j];
            a[r+1][j] += a[i][j];
            a[r+1][c+1] += a[i][j];
        }
    }
 
    for (i = 1; i <= r + 1; i++){
        for (j = 1; j <= c + 1; j++){
            if (j != 1) cout << " ";
            cout << a[i][j];
        }
        cout << endl;
    }
 
    return 0;
}

Measured memory_bytes: 1196