akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main () {

   int s[10000], t[500];
   int n, q, i, j, k = 0;

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

   scanf ("%d\n", &q);
   for (j = 0; j < q; j++) {
     scanf ("%d\n", &t[j]);
   }

   for (i = 0; i < q; i++) {
     for (j = 0; j < n; j++) {
       if (s[j] == t[i]) {
         k++;
         break;
       }
     }
   }

   printf ("%d\n", k);

   return 0;
}

Measured memory_bytes: 644
s = input()
N = len(s)
array = [0] * (N+1)
flg = False
for i in range(N):
    if s[i] == '<' and flg:
        array[i+1] = array[i] + 1
        continue
    if s[i] == '<':
        array[i+1] += 1
        flg = True
    else:
        flg = False
flg = False
for i in range(N):
    if array[N-(i+1)] > array[N-i]:
        continue
    if s[N-1-i] == '>' and flg:
        array[N-(i+1)] = array[N-i] + 1
        continue
    if s[N-1-i] == '>':
        array[N-(i+1)] += 1
        flg = True
    else:
        flg = False

# print(array)
print(sum(array))

Measured memory_bytes: 23372
n, m = map(int, input().split())
k = []
count_sub = 0
steps = []
j = 0
for i in range(m):
    k.append(int(input())) 
    if len(k)>1 and k[i]-k[i-1]==1:
        count_sub = 1
        
if count_sub ==1:
    steps = [0 for i in range(n)]  
else:
    for i in range(n+1):
        if k!=[] and k[j]==i:
            steps.append(0)
            if j < len(k)-1:
                j = j + 1
        elif i ==0:
            steps.append(1)
        elif i ==1:
            steps.append(1)  
        else:
            steps.append((steps[i-1]+steps[i-2])%1000000007)
 
print(steps[-1])

Measured memory_bytes: 7896
height, width = map(int, input().split())
i, j = 0, 0
if height % 2 > 0:
    i = height // 2 + 1
else:
    i = height // 2

if width % 2 > 0:
    j = width // 2 + 1
else:
    j = width // 2
ans = 0
if height == 1 or width == 1:
    ans = 1
elif height % 2 == 0 and width % 2 == 0:
    ans = j * height
elif height % 2 > 0 and width % 2 > 0:
    ans = j * height - (height // 2)
elif width % 2 == 0:
    ans = j * height
elif height % 2 == 0:
    ans = j * height - (height // 2)

print(ans)

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


int main(){

  char s[200];
  int i, j;
  int len, flag;

  scanf("%s", s);
  len=strlen(s);

  for(i=2;i<len;i+=2){
    flag=0;
    for(j=0;j<(len-i)/2;j++){
      if(s[j]!=s[(len-i)/2+j]){
        flag=1;
        break;
      }
    }
    if(flag==0){
      printf("%d\n", len-i);
      break;
    }
  }


  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main(){
    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    ll ans = 0;
    while(a > 0){
        if(k == 0){
            cout << ans << endl;
            return 0;
        }
        ans++;
        k--;
        a--;
    }

    while(b > 0){
        if(k == 0){
            cout << ans << endl;
            return 0;
        }
        k--;
        b--;
    }

    while(c > 0){
        if(k == 0){
            cout << ans << endl;
            return 0;
        }
        k--;
        c--;
        ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<vector>
#include<deque>
#include<cmath>
#include<math.h>
#include<cstdlib>
#include<assert.h>
#include<string>
#include<sstream>
#include<algorithm>
#include<ctime>
#include<iostream>
#define ll long long 
#define ld long double
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define BP(n) __builtin_popcount(n)
#define rep(i,n) for(i=0;i<n;i++)
#define rep1(j,n) for (j=i;j<n;j++)
#define Unique(v) vector<ll>::iterator it; sort(all(v)); it= unique(all(v)); v.resize(distance(v.begin(),it))
#define PI 3.14159265358979323846
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL) 
using namespace std;
void input(vector<string>& v,int n){ int i; string io; rep(i,n) { cin>>io; v.pb(io);} }
void output(vector<int> v) { int i; rep(i,v.size()) cout<<v.at(i)<<" "; }
/*map<char,int>  frequency(string a){  int i; map<char,int> m; rep (i,a.length()) {  if (m.find(a[i])==m.end()) m.insert({a.at(i),1}); else m[a.at(i)]++; } return m; }
bool perfsq(ll n){ return (ceil(sqrt(n))==floor(sqrt(n))); }
bool ispower2(ll n) { if (n&(n-1)==0) return true; else return false; }
bool binary_pred(int a,int b){ return a==b; }*/

int main()
{
	fastio;
	int n;
	cin>>n;
    if ((n%1000)==0)
        cout<<0<<endl;
    else 
	    cout<<1000-(n%1000)<<endl;
}


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

#define ll long long
using namespace std;
ll A;
int b1, b2;

int main()
{
	cin>>A;
	scanf("%d.%d", &b1, &b2);
	int B = b1 * 100 + b2;
	A = A * B;
	cout<<A / 100<<endl;
	
}


Measured memory_bytes: 3768
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <numeric>
#include <array>
#include <float.h>
#include <memory>
#include <functional>
#include <iomanip>
#include <random>
#include <map>
#include <set>
#include <boost/lexical_cast.hpp>

using namespace std;


using ULL = decltype(0ull);
constexpr auto DIV = 1000000007ull;
constexpr auto MAX = numeric_limits<ULL>::max();

struct Node {
  vector<int> next;
};

int N, M;

int Calc(const vector<Node>& Root, int Index, vector<bool>& Map) {
  int result = 0;
  Map[Index] = true;
  if (all_of(Map.begin(), Map.end(), [](const auto& v) {return v; })) {
    result = 1;
  }
  for (auto&& next : Root[Index].next) {
    if (!Map[next]) {
      result += Calc(Root, next, Map);
    }
  }
  Map[Index] = false;
  return result;
}

int Calc(const vector<Node>& Root) {
  int result;
  vector<bool> map(N, false);
  return Calc(Root, 0, map);
}

int main() {
  cin >> N >> M;
  vector<Node> node(N);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    node[a - 1].next.push_back(b - 1);
    node[b - 1].next.push_back(a - 1);
  }
  cout << Calc(node) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(void){
    unsigned long long int a,b;
    scanf("%llu %llu", &a, &b);
    if((b+a) % 2){
        puts("IMPOSSIBLE");
    }else{
        printf("%llu\n", (b + a)/2);
    }
    
    return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
using namespace std;
typedef long long ll;


int main(int argc, char *args[]) {
	int N;
	cin >> N;
	int num;
	num = N;
	int sum;
	sum = 0;
	while (num > 0) {
		sum += num % 10;
		num /= 10;
	}
	if (N % sum == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	

}


Measured memory_bytes: 256
def main():
    from string import ascii_lowercase
    N = int(input())
    ascii_dic = {i: a for i, a in enumerate(ascii_lowercase)}
    ascii_rdic = {a: i for i, a in enumerate(ascii_lowercase)}
    # ans = []

    def dfs(A):
        if len(A) == N:
            # ans.append("".join(A))
            print("".join(A))
            return
        if not A:
            dfs(["a"])
        else:
            s = max(ascii_rdic[a] for a in A)
            for i in range(s+2):
                dfs(A + [ascii_dic[i]])

    dfs([])

    # for i in range(len(ans)):
    #     for j in range(i+1, len(ans)):
    #         S = ans[i]
    #         T = ans[j]
    #         same = True  # 同型である
    #         for k in range(N):
    #             for m in range(k, N):
    #                 if not ((S[k] == S[m] and T[k] == T[m]) or
    #                         (S[k] != S[m] and T[k] != T[m])):
    #                     same = False
    #         if same:  # 同型である
    #             print(S, T)


if __name__ == '__main__':
    main()


Measured memory_bytes: 73880
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod = 10e9+7;

#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prtd(n, var)  cout << fixed << setprecision(n) << var << endl
#define prt2(var1, var2) cout << var1 << " " << var2 << endl

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

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

  vector<pair<pair<string, int>, int>> restor(n);
  rep(i,n){
    string s;
    int p;
    cin >> s >> p;
    restor[i] = make_pair(make_pair(s, -p), i);
  }

  sort(all(restor));

  rep(i,n){
    prt(restor[i].second+1);
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#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##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T1, class T2>bool chmax(T1& a, const T2& b) { return a < b ? a = b, 1 : 0; }
template<class T1, class T2>bool chmin(T1& a, const T2& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

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

    int C = 1;
    int ans = 0;
    while (C < B) {
        C += A - 1;
        ans++;
    }

    write(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r)for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r)for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k)for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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 (b<a) { a=b; return 1; } return 0; }

/*
   upll : (a<b)なら-1, (a=b)なら0, (a>b)なら1
 downll : (a<b)なら1, (a=b)なら0, (a>b)なら-1

 const void* a : 型を縛らずにconstをつける(=変数aが読み込み専用の変数であることを明示する)
        (ll*)a : 変数aがconst long long *型であると明示する
*/
// int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
// int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
// void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
// void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

int main(){
    ll n; cin >> n;
    ll a[n]; rep(i,0,n) cin >> a[i];

    ll minus = 0;
    rep(i,0,n) if(a[i] < 0) minus++;

    rep(i,0,n) a[i] = abs(a[i]);
    ll sum = 0;
    sort(a, a+n);
    rep(i,0,n) sum += a[i];
    if(minus % 2 == 0) cout << sum << endl;
    else cout << sum - 2*a[0] << endl;
}

Measured memory_bytes: 1024
import Control.Applicative
import Control.Monad
import Data.List

trans :: [String] -> [[Integer]] 
trans []=[]
trans (x:xs)=(map read.words$x) : trans xs

dist [a,b] [c,d]=abs (a-c)+abs (b-d)

comp a b
    |(snd a)==(snd b) =compare (fst a) (fst b)
    |otherwise =compare (snd a) (snd b)

nearFt :: [[Integer]] -> [Integer] -> Integer
nearFt checkPts student=(fst.head) $ sortBy comp $zip [1,2..] (map (dist student) checkPts)

nearPts :: [[Integer]] -> [[Integer]] -> [Integer]
nearPts students checkPts=map (nearFt checkPts) students

output n size_n list=do
  if(n==1) then 
             (putStrLn.show) $ last list
           else do
             (putStrLn.show) $ list!!(size_n-n)
             output (n-1) size_n list

main=do
  [n,m]<-map read.words<$>getLine
  data_students<- replicateM n getLine
  data_checkPts<- replicateM m getLine
  output n n (nearPts (trans data_students) (trans data_checkPts)) 

Measured memory_bytes: 1020
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, a, b)    for (int i(a); i <= (b); ++i)
#define dec(i, a, b)    for (int i(a); i >= (b); --i)
#define MP      make_pair
#define fi      first
#define se      second
 
 
typedef long long LL;
 
const int N = 1e3 + 5;
 
int a[N], b[N];
int n, m, c, fg;
char s[45];
 
 
int main(){
 
    scanf("%d", &n);
    c = 0;
 
    rep(i, 1, n){
        scanf("%d%d", a + i, b + i);
        if ((a[i] + b[i]) & 1) ++c;
        else --c;
    }
 
    if (abs(c) != n) return 0 * puts("-1");
 
    m = 31 + (c < 0);
 
    printf("%d\n", m);
    rep(i, 0, 30) printf("%d ", 1 << i);
    if (c < 0) putchar(49);
    putchar(10);
 
    rep(i, 1, n){
        int x = a[i], y = b[i];
        if (c < 0) s[31] = 'R', --x;
        fg = 0;
        dec(j, 30, 0){
            if (abs(x) < abs(y)) swap(x, y), fg ^= 1;
            if (x > 0) x -= 1 << j, s[j] = fg ? 'U' : 'R';
            else x += 1 << j, s[j] = fg ? 'D' : 'L';
        }
 
        puts(s);
    }
 
    return 0;
}
 

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;

#define sync std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define loopi(n) for(int i=0;i<n;i++)
#define loopj(n) for(int j=0;j<n;j++)
#define loop(a,b,c) for(int i=a;i<=b;i=i+c)

#define     deb(x)      cout<<#x<<"="<<x<<endl
#define     all(x)      (x).begin(),(x).end()
#define     reset(a)    memset(a,0,sizeof(a))
#define     sz(x)       ((int)(x.size()))
#define     pb          push_back
#define     pf          push_front
#define     pob	        pop_back
#define     pof         pop_front
#define     ins         insert
#define     F           first
#define     S           second
#define     mkp         make_pair
#define     mkt         make_tuple
#define     bitcount(x) __builtin_popcountll(x)
#define     gcd(a,b)    (__gcd(a,b))
#define     lcm(a,b)    ((a*b)/gcd(a,b))
#define PI 3.1415926535897932384626
 
const int mod = 1e9+7;
const int N=2e5+5;
//============================================//
int ans=0;
int c;
vector<int> g[N];

void DFS(int v, bool vis[])
{
	vis[v]=true;
	c++;
	for(auto x: g[v])
		if(!vis[x])
			DFS(x,vis);
}
void solve()
{
	int n,m;
	cin>>n>>m;
	set<pair<int,int>> s;
	loopi(m)
	{
		int x,y;
		cin>>x>>y;
		if(!s.count({x,y}) || !s.count({y,x}))
		{
			g[x].pb(y);
			g[y].pb(x);
		}
		s.insert({y,x});
		s.insert({x,y});
	}
	bool vis[n+1]={false};
	loop(1,n,1)
	{
		c=0;
		if(vis[i]==false)
			DFS(i,vis);
		ans=max(ans,c);
	}
	cout<<ans;
	
}
int main() 
{
	sync;

	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
		cout<<endl;
	}
}



Measured memory_bytes: 39592
# -*- coding: utf-8 -*-
import sys

#n= int(input())
#tmp= float(input())
tmp = input().split()
n,m = list(map(lambda a: int(a), tmp))

out=[]
for i in range(n):
    out.append(0)

a=[]
for i in range(n):
    tmp = input().split()
    a.append(list(map(lambda a: int(a), tmp)))

#for i in range(n):
#    out=[]
#    out.append(0)

#print(out)
#print(a)
for i in range(m):
    b= int(input())
    for j in range(n):
        out[j]+=a[j][i]*b
#    print(out)

for i in range(n):
    print(out[i])




Measured memory_bytes: 6028
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = "";
		s += in.next();
		s += in.next();
		s += in.next();
		if ( Integer.parseInt(s)%4 == 0 ) 
			System.out.println("YES");
		else 
			System.out.println("NO");
	}
}

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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,M,Q;
  cin >> N >> M >> Q;
  vector<vector<int>> sum(N+2,vector<int>(N+2,0));
  rep(i,M){
    int l,r;
    cin >> l >> r;
    sum.at(l).at(r)++;
  }
  for(int i=N;i>=1;i--){
    for(int j=1;j<=N;j++){
      sum.at(i).at(j) = sum.at(i).at(j) + sum.at(i+1).at(j) + sum.at(i).at(j-1) - sum.at(i+1).at(j-1);
    }
  }

  rep(_,Q){
    int p,q;
    cin >> p >> q;
    cout << sum.at(p).at(q) << endl;
  }

  return 0;
}

Measured memory_bytes: 4256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

void ABC084D()
{
	int Q;
	cin >> Q;
	vector<int> primes(100001);
	primes[0] = 1;
	primes[1] = 1;
	for (int i = 2; i < 317; ++i)
	{
		if (primes[i] == 1)
			continue;
		for (int j = 2; j * i < 100001; ++j)
		{
			primes[j*i] = 1;
		}
	}
	vector<int> primeOnly; primeOnly.reserve(1000);
	for (int i = 0; i < 100001; ++i)
		if (primes[i] == 0)
			primeOnly.push_back(i);

	vector<int> prime2Only; prime2Only.reserve(1000);
	for (int i = 0; i < static_cast<int>(primeOnly.size()); ++i)
	{
		int p2 = (primeOnly[i] + 1) / 2;
		auto p = lower_bound(primeOnly.cbegin(), primeOnly.cend(), p2);
		if (p != primeOnly.cend() && *p == p2)
			prime2Only.push_back(primeOnly[i]);
	}

	for (int i = 0; i < Q; ++i)
	{
		int l, r;
		cin >> l >> r;

		auto pl = lower_bound(prime2Only.cbegin(), prime2Only.cend(), l);
		auto pr = upper_bound(prime2Only.cbegin(), prime2Only.cend(), r);
		int x = pl == prime2Only.cend() ? 0 : pr - pl;
		cout << x << endl;
	}
}
int main()
{
	ABC084D();
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
 
using namespace std;
int n,nr4,nr2,x,nr1;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if(x%4==0) nr4++;
        else if (x%2==0) nr2++;
        else nr1++;
    }
    if(nr2)
    {
        if(nr1<=nr4) cout<<"Yes";
        else cout<<"No";
        return 0;
    }
 
    if(nr1<=nr4+1) cout<<"Yes";
    else cout<<"No";
    return 0;
}

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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

const int INF=1001001001;
int N,M,K,Q;
vpint G[100000];
int dist[100000];

int par[100000];
set<int>querys[100000];

int find(int x){
    return x==par[x]?x:par[x]=find(par[x]);
}

int ans[100000];

signed main(){
    scanf("%lld%lld%lld%lld",&N,&M,&K,&Q);
    rep(i,M){
        int a,b,c;
        scanf("%lld%lld%lld",&a,&b,&c);
        a--;b--;
        G[a].pb(pint(b,c));
        G[b].pb(pint(a,c));
    }

    fill_n(dist,N,INF);
    priority_queue<pint,vector<pint>,greater<pint>>que;
    rep(i,K){
        int v;
        scanf("%lld",&v);
        v--;
        dist[v]=0;
        que.push(pint(0,v));
    }

    while(que.size()){
        int c,v;
        tie(c,v)=que.top();
        que.pop();
        if(dist[v]<c)continue;
        for(auto p:G[v]){
            if(dist[p.fi]<=c+p.se)continue;
            dist[p.fi]=c+p.se;
            que.push(pint(dist[p.fi],p.fi));
        }
    }

    vector<tuple<int,int,int>>edges;

    rep(i,N){
        par[i]=i;
        for(auto p:G[i]){
            if(i>p.fi)continue;
            edges.pb(make_tuple(min(dist[i],dist[p.fi]),i,p.fi));
        }
    }

    rep(i,Q){
        int a,b;
        scanf("%lld%lld",&a,&b);
        a--;b--;
        querys[a].insert(i);
        querys[b].insert(i);
    }

    sort(all(edges));reverse(all(edges));

    rep(i,edges.size()){
        int a,b,c;
        tie(c,a,b)=edges[i];
        a=find(a);b=find(b);
        if(a==b)continue;
        if(querys[a].size()<querys[b].size())swap(querys[a],querys[b]);
        each(it,querys[b]){
            if(querys[a].find(*it)!=querys[a].end()){
                ans[*it]=c;
                querys[a].erase(*it);
            }
            else{
                querys[a].insert(*it);
            }
        }
        par[b]=a;
    }

    rep(i,Q)printf("%lld\n",ans[i]);
    return 0;
}

Measured memory_bytes: 60048
n=int(input())
a=list(map(int,input().split()))
plus=[a[i] for i in range(n) if a[i]>=0]
l_plus=len(plus)
minus=[a[i] for i in range(n) if a[i]<0]
l_minus=len(minus)
x_cal=[]
y_cal=[]
if n==2:
  a.sort()
  print(a[1]-a[0])
  print(a[0],a[1])
else:
  if plus!=[] and minus!=[]:
    if l_plus>1:
      x_cal.append(minus[0])
    for j in range(1,l_plus-1):
      x_cal.append(x_cal[-1]-plus[j])
    for k in range(1,l_plus):
      y_cal.append(plus[k])
    if l_plus>1:
      y_last=x_cal[-1]-y_cal[-1]
    else:
      y_last=minus[0]
    x_cal.append(plus[0])
    for j in range(1,l_minus):
      x_cal.append(x_cal[-1]-minus[j])
    for k in range(1,l_minus):
      y_cal.append(minus[k])
    y_cal.append(y_last)
    print(x_cal[-1]-y_cal[-1])
    for ii in range(n-1):
      print(x_cal[ii],y_cal[ii])
  elif minus==[]:
    a.sort()
    print(sum(a)-2*a[0])
    x_cal.append(a[0])
    for ij in range(1,n-2):
      x_cal.append(x_cal[-1]-a[ij])
    for jj in range(0,n-2):
      y_cal.append(a[jj+1])
    y_cal.append(x_cal[-1]-y_cal[-1])
    x_cal.append(a[-1])
    for ii in range(n-1):
      print(x_cal[ii],y_cal[ii])
  else:
    a.sort()
    print(a[-1]*2-sum(a))
    x_cal.append(a[-1])
    for ij in range(1,n-2):
      x_cal.append(x_cal[-1]-a[ij])
    for jj in range(0,n-2):
      y_cal.append(a[jj+1])
    x_cal.append(x_cal[-1]-y_cal[-1])
    y_cal.append(a[0])
    for ii in range(n-1):
      print(x_cal[ii],y_cal[ii])

Measured memory_bytes: 14936
import sys

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())

# [[素因数,数]]を出力
def fctr1(n):
    f = []
    c = 0
    r = int(n ** 0.5)
    for i in range(2, r + 2):
        while n % i == 0:
            c += 1
            n = n // i
        if c != 0:
            f.append([i, c])
            c = 0
    if n != 1:
        f.append([n, 1])
    return f


f = fctr1(N)

ans = 0
for n, v in f:
    c = 1
    while 0 < v:
        v -= c
        c += 1

        if v >= 0:
            ans += 1

print(ans)


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(obj) (v.begin(obj),v.end(obj))
#define COUT(x) cout<<(x)<<endl;

int main(){
    ll n,a,b,c,d,e;
    cin >> n;
    ll num[5]={};
    ll min1 = LINF;
    REP(i,5){
        cin >> num[i];
        if(min1>num[i]) min1 = num[i];
    } 
    COUT((n+min1-1)/min1+4)
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = a/500;
		long c = a%500/5;
		long result = 1000 * b + 5 * c;
		System.out.println(result);
	}

}


Measured memory_bytes: 22736
S = input()
if 0 < int(S[:2]) < 13 and 0 < int(S[2:]) < 13:
    print('AMBIGUOUS')
elif 0 < int(S[:2]) < 13:
    print('MMYY')
elif 0 < int(S[2:]) < 13:
    print('YYMM')
else:
    print('NA')

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

using namespace std;

using ll = long long;

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

    ll n, x;
    cin >> n >> x;

    ll ans = 0;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (x < a[i]) {
            ans += a[i] - x;
            a[i] = x;
        }
    }

    for (int i = 1; i < n; ++i) {
        if (x < a[i - 1] + a[i]) {
            int diff = a[i - 1] + a[i] - x;
            if (diff <= a[i]) a[i] -= diff;
            else a[i] = 0;
            ans += diff;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <fstream>

using namespace std;

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll k;
    cin >> k;
    cout << 50 << endl;
    int cur = 0;
    for (int i = 0; i < k % 50; i++) {
        cout << k / 50 + 50 << ' ';
        cur++;
    }
    while (cur < 50) {
        cout << k / 50 + 49 - k % 50 << ' ';
        cur++;
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#define pi 3.14159
using namespace std;

 
int main(){
	while(1) {
		int N;
		cin >> N;
		if(N == 0) break;
		int a[401][401];
		for(int j = 0; j < 401; j++) {
				for(int k = 0; k < 401; k++) {
					a[j][k] = -1;
				}
		}
		int y = 200, x = 200;
		a[200][200] = 0;
		for(int i = 0; i < N-1; i++) {
			int n, d;
			cin >> n >> d;
			for(int j = 0; j < 401; j++) {
				for(int k = 0; k < 401; k++) {
					if(a[j][k] == n) {
						y = j;
						x = k;
						break;
					}
				}
			}
			if(d == 0) a[y][x - 1] = i+1;
			if(d == 1) a[y + 1][x] = i+1;
			if(d == 2) a[y][x + 1] = i+1;
			if(d == 3) a[y - 1][x] = i+1;
		}

		int maxW = 0, maxH = 0, minW = 401, minH = 401;
		for(int j = 0; j < 401; j++) {
			for(int k = 0; k < 401; k++) {
				if(a[j][k] >= 0) {
					x = k;
					if(x > maxW) maxW = x;
					if(x < minW) minW = x;
				}
				if(a[k][j] >= 0) {
					y = k;
					if(y > maxH) maxH = y;
					if(y < minH) minH = y;
				}
			}
		}
		int W = maxW - minW + 1, H = maxH - minH + 1;;
		cout << W << " " << H <<endl;
	}
				


	return 0;
}

Measured memory_bytes: 1788
n, m = map(int, input().split())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors


prime_list = make_divisors(m)
max_ = 0
for i in prime_list:
    if i <= m/n and i > max_:
        max_ = i
print(max_)

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
typedef vector<ll> vll;
typedef vector<int> vi;
const ll N = 1e6 + 10;
const int M = 1e9 + 7;
const double eps = 1e-9;

int main() {
    int n, k;
    cin >> n >> k;
    vll v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    ll sum = 0;
    sort(all(v));
    for (int i = 0; i < k; ++i) {
        sum += v[i];
    }
    cout << sum << endl;
}



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

int main() {
    int n, l;
    while (cin >> n >> l, n) {
        using P = pair<pair<int, char>, int>;
        #define pos first.first
        #define dir first.second
        #define idx second
        vector<P> ants(n);
        for (int i = 0; i < n; i++) {
            P &p = ants[i];
            cin >> p.dir >> p.pos;
            p.idx = i + 1;
        }
        int cnt = 0;
        pair<char, int> lst;
        while (!ants.empty()) {
            cnt++;
            for (auto &p: ants) {
                if (p.dir == 'L') p.pos--;
                else p.pos++;
            }
            sort(ants.begin(), ants.end());
            for (int i = 0; i < ants.size() - 1; i++) {
                if (ants[i].pos == ants[i + 1].pos) {
                    ants[i].dir = 'R';
                    ants[i + 1].dir = 'L';
                }
            }
            lst = {'Z', -1};
            for (auto it = ants.begin(); it != ants.end(); ++it) {
                if (it->pos < 1 || l <= it->pos) {
                    lst = min(lst, {it->dir, it->idx}); ants.erase(it); it--;
                }
            }
        }
        cout << cnt << " " << lst.second << endl;
    }
    return 0;
}


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

int main()
{
  string text = "-";
  int length, n, h, count;

  while(1)
  {
    cin >> text;
    if(text == "-") break;
    cin >> n;
    count = 0;
    
    //calculate
      
    length = text.size();
    for(int i = 0; i < n; i++)
    {
      cin >> h;
      count += h;
      if(length < count)
      {
        count -= length;
      }
    }
      
    //out
    
    if(count == length)
    {
      count = 1;
    }
    else
    {
      count++;
    }
    
    for(int i = 0; i < length; i++)
    {
      cout << text[count - 1];
        
      if(count == length)
      {
        count = 1;
      }
      else
      {
        count++;
      }
    }
    cout << endl;
  }
  return 0;
}


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

int bubbleSort(int A[], int N) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		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;
				sw++;
			}
		}
	}
	return sw;
}

int main() {
	int A[100], N, sw;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];

	sw = bubbleSort(A, N);

	for (int i = 0; i < N; i++) {
		if (i) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;

	return 0;
}


Measured memory_bytes: 3104
#include <stdio.h>
int array[200];
int main(void)
{
	
	int i, k = 0, n, max;
	
	while (scanf("%d", &n) != EOF){
		array[n]++;
		k++;
	}
	max = 0;
	for (i = 1; i <= k; i++){
		if (max < array[i])max = array[i];
	}
	for (i = 1; i <= k; i++){
		if (max == array[i]){
			printf("%d\n", i);
		}
	}
	
	return (0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
char s[6];
int main()
{
	int i,cnt=0;
	scanf("%s",s);
	for(i=0;i<strlen(s);i++)
	{
		if(s[i]=='2')
			cnt++;
	}
	printf("%d",cnt);
	return 0;
}

Measured memory_bytes: 384
import itertools


h, w, k = map(int, input().split())

if w == 1:
    print(1)
    exit()

mod = 10**9 + 7
path = [[i, i+1] for i in range(w-1)]
DP = [[0]*(h+1) for _ in range(w)]
DP[0][0] = 1

for height in range(h):
    for pos in range(w):
        down_unable = {pos}
        left_unable = {pos-1, pos}
        right_unable = {pos, pos+1}

        down_count = 1
        left_count = 1
        right_count = 1
        for pick in range(1, 1 + w//2):
            all_pattern = list(itertools.combinations(path, pick))

            for pattern in all_pattern:
                check = set()
                possible = True
                for a, b in pattern:
                    if check & {a, b}:
                        possible = False
                        break
                    check |= {a, b}
                if not possible:
                    continue
                if not check & down_unable:
                    down_count += 1
                if not check & left_unable:
                    left_count += 1
                if not check & right_unable:
                    right_count += 1

        if pos == 0:
            DP[pos][height+1] += DP[pos][height] * down_count % mod
            DP[pos+1][height+1] += DP[pos][height] * right_count % mod

        elif pos == w-1:
            DP[pos][height+1] += DP[pos][height] * down_count % mod
            DP[pos-1][height+1] += DP[pos][height] * left_count % mod
        else:
            DP[pos][height+1] += DP[pos][height] * down_count % mod
            DP[pos+1][height+1] += DP[pos][height] * right_count % mod
            DP[pos-1][height+1] += DP[pos][height] * left_count % mod

print(DP[k-1][h] % mod)


Measured memory_bytes: 49900
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	//static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	
	
	
	
	//for(int i=0;i<N;i++) {}
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		
		double X=sc.nextDouble();
		boolean V=true;
		for(int i=0;V;i++) {
			
			double t=Math.pow(i, 5);
			
			for(int a=0;V;a++) {
				
				double tt=Math.pow(a, 5);
				
				
				
				if(t-tt==X||-t+tt==X||t+tt==X) {
					
					if(t-tt==X)p(i+" "+a);
					else if(-t+tt==X)p(-i+" "+(-a));
					else if(t+tt==X)p(i+" "+(-a));
					V=false;
				}
				if(t-tt<X&&-t+tt>X&&t+tt>X) {
					break;
				}
				
				
			}
			
			
			
		}
		
		
		
		
		
		
		
	}
	

	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int la,lb,lc;
    string a,b,c;
    cin >>a>>b>>c;

    la = a.length();
    lb = b.length();
    lc = c.length();

    if(a[la-1]==b[0] && b[lb-1]==c[0])flag=true;

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    if(flag)cout << "YES" <<endl;
    else cout << "NO" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
using lint = long long;
string S;
int K, back;

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

    cin>>S>>K;K--;
    for(int i = 0; i < S.length(); i++) {
        if(S[i] == '1') {
            if(!K) {
                cout<<"1\n";
                break;
            }
            K--;
        }
        else {
            cout<<S[i]<<'\n';
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
var a = require("fs").readFileSync("/dev/stdin", "utf8").split("\n")[1].split(" ").map(e => parseInt(e, 10));
function Main(p) {
  var acc = 0, cnt = 0;
  for(var i of a) {
    acc += i;
    if (p) {
      if (acc >= 0) {
        cnt += 1 + acc;
        acc = -1;
      }
      p = false;
    } else {
      if (acc <= 0) {
        cnt += 1 - acc;
        acc = 1;
      }
      p = true;
    }
  }
  return cnt;
}
console.log(Math.min(Main(false), Main(true)));

Measured memory_bytes: 29676
#include <stdio.h>

int main()
{
	long int a, b, x, r,dum;

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

	x = a * b;

	if (a < b)
	{
		dum = a;
		a = b;
		b = dum;
	}

	r = a % b;
	while (r != 0)
	{
		a = b;
		b = r;
		r = a % b;
	}

	printf("%ld\n", x / b);


	return 0;
}

Measured memory_bytes: 128
import sys
import copy
input = sys.stdin.readline

N=int(input())

T=list(map(int,input().split()))

T.sort()
count=0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if T[i]+T[j]>T[k] and T[i]!=T[j] and T[j]!=T[k] and T[k]!= T[i]:
                count+=1
print(count)

Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef vector<LL> vl;
typedef pair<LL, LL> pl;
typedef vector<pair<LL, LL>> VP;
typedef tuple<LL, LL, LL> tl;
const LL N=pow(10, 9)+7;
#define endl "\n"
#define REP(i, a, b) for(LL i=a; i<b; i++)
#define RREP(i, a, b) for(LL i=a; i>b; i--)
#define WE(i) while(i--)
#define PB push_back
#define PF pop_front
#define MP make_pair
#define MT make_tuple
#define F first
#define S second

LL sod(LL a)
{
    LL sum=0;
    while(a!=0)
    {
        sum=sum+a%10;
        a=a/10;
    }
    return sum;
}

LL num1(LL a)
{
    LL s=0;
    while(a!=0){
        if(a%2==1){
            s++;
        }
        a=a/2;
    }
    return s;
}

LL bmod(string s, LL a)
{
    LL res=0;
    REP(i, 0, s.length()){
        res=(10*res+(LL)s[i]-'0')%a;
    }
    return res;
}

void pd(LL n) 
{ 
    LL ans=0, x=sqrt(n);
    if(x%1==0){
        REP(i, 1, x+1){
            if(n%i==0){
                ans+=2;
            }
            if(n==i*i){
                ans--;
            }
        }
    }
    else{
        REP(i, 0, x){
            if(n%i==0){
                ans+=2;
            }
        }
    }
    cout << ans << endl;
}

LL solve()
{
    LL n;
    cin >> n;
    LL a[n+1], b[n+1];
    REP(i, 1, n+1){
    	cin >> a[i];
    }
    b[1]=0;
    b[2]=abs(a[2]-a[1]);
    REP(i, 3, n+1){
    	if((b[i-1]+abs(a[i]-a[i-1]))<(b[i-2]+abs(a[i]-a[i-2]))){
    		b[i]=b[i-1]+abs(a[i]-a[i-1]);
    	}
    	else{
    		b[i]=b[i-2]+abs(a[i]-a[i-2]);
    	}
    }
    cout << b[n] << endl;
    return 0;
}

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
    LL T=1;
    //cin >> T;

    WE(T){
        solve();
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  vector<int> T(N);
  for (int i = 0; i < N; i++) cin >> S.at(i) >> T.at(i);
  string X;
  cin >> X;

  for (int i = 0; i < N; i++)
    if (S.at(i) == X) cout << accumulate(T.begin() + i + 1, T.end(), 0);
}

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

int main(){
    
    ll a,v; 
    cin >> a >> v;
    ll b,w;
    cin >> b >> w;
    ll t;
    cin >> t;
    
    if(abs(a-b) <= (v-w)*t) cout << "YES" << endl;
    else cout << "NO" << endl;
}


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

const int INF = 1001001001;
const int mod = 1000000007;

ll pow(ll base, ll order) {
	ll ans = 1;
	rep(i,order - 1) ans *= base;
	return ans;
}

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

int main() {
	int a, b, h, m;
	cin >> a >> b >> h >> m;

	double pi = 2.0*acos(0.0);
	double anga = 2.0*pi/12/3600, angb = 2.0*pi/3600; //unit: 1/sec
	double lengx, lengy;
	double t;
	t = 3600*h + 60*m;
	lengx = a*cos(anga*t) - b*cos(angb*t);
	lengy = a*sin(anga*t) - b*sin(angb*t);
	cout << fixed << setprecision(10) << sqrt(lengx*lengx + lengy*lengy) << endl;
	return 0;
} 

Measured memory_bytes: 4128
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

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

	int N,M;
	cin >> N >> M;
	bool flg[200001][2] = {};
	for(int i=0; i<M; i++){
		int a,b;
		cin >> a >> b;
		if(a > b) swap(a,b);
		if(a == 1){
			flg[b][0] = true;
			if(flg[b][1]){
				cout << "POSSIBLE" << endl;
				return 0;
			}
		}
		if(b == N){
			flg[a][1] = true;
			if(flg[a][0]){
				cout << "POSSIBLE" << endl;
				return 0;
			}
		}
	}
	cout << "IMPOSSIBLE" << endl;

	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define pb push_back
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define _max(v) *max_element(v.begin(), v.end())
#define _min(v) *min_element(v.begin(), v.end())

int main() 
{
    io;
   string s; cin >>s;
   ll ans=0, i=0;
   while(s[i]!='\0')
   {
       ans+=s[i]-'0';
       i++;
   }
   if(ans%9==0) cout << "Yes\n";
   else cout << "No\n";
	return 0;
}


Measured memory_bytes: 3744
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> grid(h);
    for(int i = 0; i < h; i++)
    {
        cin >> grid[i];
    }
    vector<int> alphabet(26, 0);
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            alphabet[grid[i][j] - 'a']++;
        }
    }
    auto check = [&]()
    {
        int odd = 0;
        int even = 0;
        for(int i = 0; i < 26; i++)
        {
            if(alphabet[i] == 1)
            {
                odd++;
            }else if(alphabet[i] == 2)
            {
                even++;
            }
        }
        return make_pair(odd, even);
    };
    for(int i = 0; i < 26; i++)
    {
        alphabet[i] = alphabet[i] % 4;
    }
    pair<int, int> result = check();
    //evenの数のチェックが必要
    if(h % 2 == 0 && w % 2 == 0)
    {
        //すべて0である必要がある
        if(result.second == 0 && result.first == 0)
        {
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        return 0;
    }else if(h % 2 != 0 && w % 2 != 0)
    {
        //奇数，奇数
        //h - 1個までの2だったらYes
        int temp = (h - 1) / 2 + (w - 1) / 2;
        if(result.first == 1 && result.second <= temp)
        {
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else{
        //奇数，偶数
        //h or w / 2個までの2だったらYes
        int temp = h % 2 == 0 ? h : w;
        if(result.first == 0 && result.second <= temp / 2)
        {
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}


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

int partition(int a[], int p, int r){
    int x = a[r];
    int i = p - 1;
    for(int j = p; j < r; j++)
        if(a[j] <= x) swap(a[++i], a[j]);
    swap(a[++i], a[r]);
    return i;
}

int main(){
    int n; cin >> n;
    int a[n]; rep(i, n) cin >> a[i];

    int p = partition(a, 0, n-1);
    rep(i, n){
        (i == p) ? printf("[%d]", a[i]) : printf("%d", a[i]);
        if(i < n-1) printf(" ");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 3480
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <queue>

#define ll long long
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

template<typename T> T gcd(T a, T b){ return (a % b)? gcd(b, a%b) : b; }
template<typename T> T lcm(T a, T b){ return a * b / gcd(a, b); }

int main(void){
    int n, m, c;
    cin >> n >> m >> c;
    int b[m];
    REP(i,m) cin >> b[i];
    int a[n][m];
    REP(i,n) REP(j,m) cin >> a[i][j];

    int ctr = 0;
    REP(i,n){
        ll tmp = 0;
        REP(k,m){
            tmp += a[i][k] * b[k];
        }
        if(tmp + c >0) ctr++;
    }
    cout << ctr << endl;
    
    return 0;
}

Measured memory_bytes: 3532