akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
string alp="abcdefghijklmnopqrstuvwxyz";

int main(){
    ll N,K;
    cin >> N >> K;
    vector<Pll> p(N);;
    rep(i,N){
        ll t,d;
        cin >> t >> d;
        p[i]=Pll(d,t);
    }
    sort(p.begin(),p.end());
    reverse(p.begin(),p.end());
    ll ans=0,count=0;
    map<ll,ll> m;
    rep(i,K){
        count+=p[i].first;
        m[p[i].second]++;
    }
    ll s=m.size();
    count+=s*s;
    ans=count;
    ll checked=K-1,last=K-1;
    for (int i=checked;i>=0;i--){
        if (m[p[i].second]>1){
            count-=p[i].first;
            m[p[i].second]--;
            bool update=false;
            for (int j=last+1;j<N;j++){
                if (m[p[j].second]==0){
                    count+=p[j].first;
                    m[p[j].second]++;
                    last=j;
                    s++;
                    update=true;
                    break;
                }
            }
            if (update){
                count+=s*2-1;
                ans=max(ans,count);
            }
            else {
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5760
str=list(input())
str2=list(input())
if(str2==str):
    print("Yes")
    exit()
for i in range(len(str)):
    var=str[-1]
    del str[-1]
    str.insert(0,var)
    if(str==str2):
        print("Yes")
        flag=True
        exit()
print("No")

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
  long long a,b,c,d,n;
  cin >>a>>b>>c>>d;
  cin>>n;
  long long p,q;
  p=min(min(4*a,2*b),c);
  q=min(2*p,d);
  long long r=n%2;
  n/=2;
  long long ans=p*r+q*n;
  
  cout<<ans<<endl;
  return 0;
  }

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 123450
#endif

int N,M,Q;

void solve() {
    cin>>N;
    string ans;
    while(N) {
        N--;
        char c = N%26+'a';
        ans.push_back(c);
        N/=26;
    }
    reverse(ALL(ans));
    cout << ans << endl;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

int main(){
	ll a;
  	cin >> a;
  cout << a*a;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i, j;
	string s, t, ans = "";
	cin >> s >> t;
	vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1, 0));
	rep(i, s.size()) {
		rep(j, t.size()) {
			dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
			if (s[i] == t[j])
				chmax(dp[i + 1][j + 1], dp[i][j] + 1);
		}
	}
	i = s.size();
	j = t.size();
	while (i > 0 && j > 0) {
		while (j > 0 && dp[i][j - 1] == dp[i][j])
			j--;
		while (i > 0 && dp[i - 1][j] == dp[i][j])
			i--;
		i--;
		j--;
		if (i < 0 || j < 0)
			break;
		ans += s[i];
	}
	reverse(ans.begin(), ans.end());
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 38500
#!/usr/bin/env python3
import sys

INF = 10**9


def dfs(cur, l, ia, ib, ic):
    if(cur == N):
        return abs(ia-A) + abs(ib-B) + abs(ic-C) - 30 if min(ia,ib,ic) > 0 else INF

    ret0 = dfs(cur+1, l, ia, ib, ic)
    ret1 = dfs(cur+1, l, ia+l[cur], ib, ic) + 10
    ret2 = dfs(cur+1, l, ia, ib+l[cur], ic) + 10
    ret3 = dfs(cur+1, l, ia, ib, ic+l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)


def solve(N: int, A: int, B: int, C: int, l: "List[int]"):
    print(dfs(0,l,0,0,0))

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    global N, A, B, C, l
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    l = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A, B, C, l)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  int s=0;
  for(int i=0;i<k;i++){
    if(a>0){
      s++;
      a--;
    }else if(b>0){
      b--;
    }else{
      s--;
      c--;
    }
  }
  cout<<s<<endl;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

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

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

    int N;
    cin >> N;
    vector<P> p;
    ll smax = 0;
    vector<ll> W(N + 1), S(N + 1), V(N + 1);
    for (int i = 1; i <= N; i++)
    {
        cin >> W[i] >> S[i] >> V[i];
        p.push_back(P(W[i] + S[i], i));
        smax = max(smax, S[i]);
    }
    sort(p.begin(), p.end());
    // dp[i][j] := i 番目まで見て重さjの時の価値最大値
    vector<vector<ll>> dp(N + 1, vector<ll>(2 * smax + 1, -1e15));
    dp[0][0] = 0;
    for (int i = 1; i <= N; i++)
    {
        int idx = p[i - 1].second;
        ll w = W[idx], s = S[idx], v = V[idx];
        for (int j = 0; j <= 2 * smax; j++)
        {
            dp[i][j] = dp[i - 1][j];
            if (w <= j && j - w <= s)
            {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w] + v);
            }
        }
    }
    ll res = 0;
    for (int j = 0; j <= 2 * smax; j++)
    {
        res = max(res, dp[N][j]);
    }
    cout << res << endl;
}


Measured memory_bytes: 160640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int n;
    cin >> n;
    int taro = 0, hanako = 0;
    rep(i, n) {
        string s, t;
        cin >> s >> t;
        if (s == t) {
            taro++;
            hanako++;
        }
        else if(s > t) taro+=3;
        else hanako+=3;
    }
    cout << taro << ' ' << hanako << endl;

    return 0;
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a;
  cin >> n >> a;
  int count=0;
  for(int i=0; i<a; i++){
    int b;
    cin >> b;
    count += b;
  }
  if(count > n){cout << -1 << endl;}
  else{cout << n - count << endl;}
}
  


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, x, N) for (long long i = x; i < (N); i++)
using namespace std;
int main()
{
	long long H;
	cin >> H;
	long long sum = 1;
	int count = 0;
	long long b = 2;
	vector<long long> a(40);
	a[0] = 1;
	rep(i, 1, 41)
	{
		a[i] = a[i - 1] + b;
		b *= 2;
	}
	while (sum < H)
	{
		sum *= 2;
		count++;
	}
	if (sum > H)
	{
		count--;
	}
	cout << a[count] << endl;
}


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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define ull unsigned long long
#define ld long double

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
template <class T>
using VVV = V<V<V<T>>>;

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
#define rep1(i, n) rep1(i, 1, n + 1)

// #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
// #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()  //

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, -1, 1, 1, -1};

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(15);
    //    cout << std::setfill('0') << std::setw(2);

    long long N;
    std::cin >> N;
    std::vector<std::string> s(N);
    for (int i = 0; i < N; i++) {
        std::cin >> s[i];
    }
    long long M;
    std::cin >> M;
    std::vector<std::string> t(M);
    for (int i = 0; i < M; i++) {
        std::cin >> t[i];
    }

    map<string, int> mp;
    rep(i, N) mp[s[i]]++;
    rep(i, M) mp[t[i]]--;

    int ans = 0;
    for (auto a : mp) {
        ans = max(ans, max(0, a.second));
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  int n,k;scanf("%d%d",&n,&k);
  double ret=0;
  
  for(int i=1;i<=n;i++){
    double tmp=1.0/n;
    int now=i;
    while (now<k){
      now*=2;//1→2→4→8,2→4→8,3→6ってやるやつ
      tmp/=2;//毎回表出さなきゃいけないからその度に×(1/2)
    }
   ret+=tmp;
  }
  printf("%.12f\n",ret);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define N 100001
#define INFTY 1000000000
#define true 1
#define false 0



typedef struct{
  char c;
  int num;
}C;

int n; //外部変数
C l[N],r[N];

int partition(C a[],int p,int r){
  int x,i,j;
  C temp;
  x=a[r].num;
  i=p-1;

  for(j=p;j<r;j++){
    if(a[j].num<=x){
      i++;
      temp=a[i];
      a[i]=a[j];
      a[j]=temp;
    }
  }
  temp=a[i+1];
  a[i+1]=a[r];
  a[r]=temp;  
  return i+1;
}

void quicksort(C a[],int p,int r){
  int q;
  if(p>r)return;
  q=partition(a,p,r);
  quicksort(a,p,q-1);
  quicksort(a,q+1,r);
}

void merge(C A[],int left,int mid,int right){
  int n1,n2,i,j,k;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++)l[i]=A[left+i];
  for(i=0;i<n2;i++)r[i]=A[mid+i];
  
  l[n1].num=INFTY;
  r[n2].num=INFTY;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(l[i].num<=r[j].num){
      A[k]=l[i];
      i++;
    }
    else {
      A[k]=r[j];
      j++;
    }
  }
}

void mergesort(C A[],int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergesort(A,left,mid);
    mergesort(A,mid,right);
    merge(A,left,mid,right);
  }
}

int isStable(C a[],C b[]){
  int i,flag=1;
  for(i=0;i<n;i++){
  if(memcmp(&a[i],&b[i],sizeof(a[i]))!=0)flag=0;
  }
  if(flag)return true;
  else return false;
}

int main(){
  int i,x;
  C A[N],B[N];
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf(" %c %d",&A[i].c,&A[i].num);
    B[i]=A[i];
  }
  mergesort(B,0,n);
  quicksort(A,0,n-1);
  if(isStable(A,B))printf("Stable\n");
  else printf("Not stable\n");

  for(i=0;i<n;i++){
    printf("%c %d\n",A[i].c,A[i].num);


  }



  return 0;
}




Measured memory_bytes: 4044
n,k= map(int, input().split())
a=list(map(int, input().split()))
b=[0]*n
y=a[0]
# 少なくともどこまで伸ばすべきか
for i in range(n):
    y=max(y,a[i])
    b[i]=y

ans=pow(10,12)
for i in range(2**(n-1)):
    H=[]
    for j in range(1,n):
        if (i>>(j-1))&1:
            H.append(j)

    if len(H)==k-1:
        cnt = 0
        x = b[0]+1
        for l in range(len(H)):
            if x>=b[H[l]]:
                cnt+=x-a[H[l]]
                x+=1
            else:
                if b[H[l]]==a[H[l]]:
                    x=b[H[l]]+1
                else:
                    cnt+=x-a[H[l]]
                    x=b[H[l]]+1

        ans=min(cnt,ans)

if k==1:
    print(0)
else:
    print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    long a,b,x,ans;
    cin>>a>>b>>x;
    long n;
    n=a%x;
    a=a-n;
    if(n==0){
        ans=(b-a)/x+1;
    }else{
        ans=(b-a)/x;
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 256
def main():
    from collections import deque
    import sys
    input = sys.stdin.readline

    H, W = map(int, input().split())
    sy, sx = (int(x) - 1 for x in input().split())
    gy, gx = (int(x) - 1 for x in input().split())
    G = [input().rstrip() for _ in range(H)]

    dq = deque()
    dq.append((sy, sx, 0))

    INF = H * W + 10

    ctr = [[INF] * W for _ in range(H)]
    ctr[sy][sx] = 0

    while dq:
        y, x, cnt = dq.popleft()
        if cnt > ctr[y][x]:
            continue

        if y > 0 and G[y - 1][x] == '.' and ctr[y - 1][x] > cnt:
            dq.appendleft((y - 1, x, cnt))
            ctr[y - 1][x] = cnt
            if y - 1 == gy and x == gx:
                print(cnt)
                return

        if x > 0 and G[y][x - 1] == '.' and ctr[y][x - 1] > cnt:
            dq.appendleft((y, x - 1, cnt))
            ctr[y][x - 1] = cnt
            if y == gy and x - 1 == gx:
                print(cnt)
                return

        if y < H - 1 and G[y + 1][x] == '.' and ctr[y + 1][x] > cnt:
            dq.appendleft((y + 1, x, cnt))
            ctr[y + 1][x] = cnt
            if y + 1 == gy and x == gx:
                print(cnt)
                return

        if x < W - 1 and G[y][x + 1] == '.' and ctr[y][x + 1] > cnt:
            dq.appendleft((y, x + 1, cnt))
            ctr[y][x + 1] = cnt
            if y == gy and x + 1 == gx:
                print(cnt)
                return

        ncnt = cnt + 1
        for dr in range(-2, 3):
            ny = y + dr
            if ny < 0 or ny >= H:
                continue
            for dc in range(-2, 3):
                nx = x + dc
                if nx < 0 or nx >= W:
                    continue
                if G[ny][nx] == '.' and ctr[ny][nx] > ncnt:
                    dq.append((ny, nx, ncnt))
                    ctr[ny][nx] = ncnt

        if ctr[gy][gx] <= cnt:
            print(cnt)
            return

    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 116808
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int idx = sc.nextInt();
		int[] datas = {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};
		for(int i = 0; i < 32; i++) {
			if(i+1 == idx) {
				System.out.println(datas[i]);
			}
		}
	}
}


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

main :: IO ()
main = do
  a:b:_ <- (map read . words) <$> getLine
  putStrLn $ show (area a b) ++ " " ++ show (perimeter a b)

area :: Int -> Int -> Int
area a b = a * b

perimeter :: Int -> Int -> Int
perimeter a b = 2 * a + 2 * b

Measured memory_bytes: 3600
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d=0,cou=1;
  cin>>a>>b;
  for(int i=0;i<a;i++){
    cin>>c;
    d+=c;
    if(d<=b)
      cou++;
  }
  cout<<cou<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define vi_a vector<int>a;
#define p_b push_back
#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)
#define sz(x) (int)x.size()
#define endl "\n"
using namespace std;
signed main()
{
    string a,b;
    cin>>a;
    for(ll i=0;i<a.length();i++){
        cout<<'x';
    }
}


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

def main():
    cnt = 0
    n = int(input())
    for i in range(1,n+1,2): # 奇数だけ繰り返す
        k = 0
        for m in range(1,i+1):
            if i % m == 0:
                k += 1
        if k == 8:
            cnt += 1
    print(cnt)

if __name__=="__main__":
    main()


Measured memory_bytes: 63060
import bisect

n = 10**5+100
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)

x=int(input())
y=bisect.bisect_left(primes,x)
print(primes[y])

Measured memory_bytes: 62056
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mx=3234566667;
vector<ll>v;


void lun(ll num)
{
    if(num>mx)
    {
        return;
    }
    v.push_back(num);
    lun((num*10)+(num%10));
    if(num%10>0)
    {
        lun((num*10)+(num%10)-1);
    }
    if(num%10<9)
    {
        lun((num*10)+(num%10)+1);
    }
}
int main()
{
    for(ll i=1;i<=9;i++)
    {
        lun(i);
    }
    sort(v.begin(),v.end());
    ll n;
    cin>>n;
    cout<<v[n-1]<<endl;
    return 0;
}


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

#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)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const long long MOD = 1e9 + 7;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

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

///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    int M; cin >> M;
    ll dsum = 0;
    ll dnum = 0;

    REP(i,M){
        ll d,c; cin >> d >> c;
        dsum += d * c;
        dnum += c;
    }

    ll ans = (dnum - 1);
    if (dsum >= 10){
        ans += ((dsum - 9) + 8) / 9;
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
 
void solve(){
	string a;
	cin>>a;
	ll n=a.size();
	ll ans=n*(n-1)/2;
	map<char,ll>mp;
	for(int64_t i=0;i<n;++i){
		//両端が同じ文字列はそれぞれ1つ右へ(左へ)動かして得られる文字列と変わらない。逆に両端が違うならば違う文字列になる
		//よって全ての選び方から同じ文字を選ぶ組み合わせを引けばよい
		mp[a[i]]++;
	}
	for(auto x:mp){
		ans-=x.second*(x.second-1)/2;
	}
	cout<<ans+1<<"\n";
}
 
signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 848
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<int>a[m];
  rep(i,m){
    int k;
    cin>>k;
    rep(j,k){
      int s;
      cin>>s;
      s--;
      a[i].push_back(s);
    }
  }
  vector<int>p(m);
  rep(i,m){
    cin>>p.at(i);
  }
  int ans=0;
  for (int tmp = 0; tmp < (1 << n); tmp++) {
    bitset<10> s(tmp);
    bool ex=true;
    vector<int>e(m,0);
    rep(i,n){
      if(s.test(i)){
        rep(j,m){
          rep(k,a[j].size()){
            if(a[j].at(k)==i){
              e.at(j)++;
            }
          }
        }
      }
    }   
    rep(i,m){
      if(e.at(i)%2!=p.at(i)){
        ex=false;
      }
    }
    if(ex){
      ans++;
    }
  }  
  cout<<ans<<endl;  
}

Measured memory_bytes: 256
i = [int(input()) for i in range(4)]

if i[0]<i[1]:
  train = i[0]
elif i[1]<=i[0]:
  train = i[1]
  
if i[2]<i[3]:
  bus= i[2]
elif i[3]<=i[2]:
  bus= i[3]

print(train+bus)

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

using namespace std;
const int LEN = 1e2 + 10;
int Array[LEN];

void print(int n) {
    for (int i = 0; i < n - 1; i++) {
        printf("%d ", Array[i]);
    }
    printf("%d\n", Array[n - 1]);
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &Array[i]);
    }
    print(n);
    for (int i = 1; i < n; i++) {
        int val = Array[i], j = i - 1;
        while (j >= 0 && Array[j] > val) {
            swap(Array[j], Array[j + 1]);
            j -= 1;
        }
        Array[j + 1] = val;
        print(n);
    }
    return 0;
}


Measured memory_bytes: 3208
#include<cstdio>
#include<algorithm>
using namespace std;
char p[51][52];
int main() {
	int i, j, W, B;
	scanf("%d%d", &W, &B);
	for (i = 1; i <= 50; i++)for (j = 1; j <= 50; j++)p[i][j] = '.';
	printf("100 50\n");
	W--, B--;
	for (i = 2; i < 50; i += 2) {
		for (j = 2; j < 50; j += 2) {
			if (B) {
				B--;
				p[i][j] = '#';
			}
		}
	}
	for (i = 1; i <= 50; i++)printf("%s\n", p[i] + 1);
	for (i = 1; i <= 50; i++)for (j = 1; j <= 50; j++)p[i][j] = '#';
	for (i = 2; i < 50; i += 2) {
		for (j = 2; j < 50; j += 2) {
			if (W) {
				W--;
				p[i][j] = '.';
			}
		}
	}
	for (i = 1; i <= 50; i++)printf("%s\n", p[i] + 1);
}

Measured memory_bytes: 128
def to_digit(f):
  u = int(f)
  d = f - u
  us = ""
  if u == 0:
    us = "0" * 8
  else:
    cnt = 8
    while u:
      if cnt == 0:
        return ("DAME", "DESU!!")
      cnt -= 1
      us += str(u % 2)
      u //= 2
    us += "0" * cnt
    us = us[::-1]

  ds = ""
  cnt = 4
  acc = 1
  while d > 0:
    if cnt == 0:
      return ("DAME", "DESU!!")
    cnt -= 1
    acc /= 2
    if d >= acc:
      d -= acc
      ds += "1"
    else:
      ds += "0"
  ds += "0" * cnt
  return (us, ds)

while True:
  f = float(input())
  if f < 0:
    break
  us, ds = to_digit(f)
  if us == "DAME":
    print("NA")
  else:
    print(us, ds, sep=".")


Measured memory_bytes: 5588
// 入力マクロ
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
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! {
        n: usize,
        a: [usize; n]
    }

    let mut a = a;
    a.sort();
    if !(a.iter().enumerate().all(|t| (t.0 + 1) / 2 * 2 == *t.1) || 
        a.iter().enumerate().all(|t| t.0 / 2 * 2 + 1 == *t.1)) {
        println!("0");
    } else {
        println!("{}", solve(n));
    }
}

fn solve(n: usize) -> usize {
    let mut res = 1;
    for _i in 0..(n/2) {
        res *= 2;
        res %= 1_000_000_007;
    }
    res
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
int n,m,cnt;
long long pw[305];
bitset<305> bas[305];
bool add(bitset<305> b)
{
	for (int i=m-1;i>=0;i--)
	{
		if (b[i])
		b^=bas[i];
	}
	for (int i=m-1;i>=0;i--)
	{
		if (b[i])
		{
			bas[i]=b;
			return 1;
		}
	}
	return 0;
}
int main()
{
	scanf("%d%d",&n,&m);
	pw[0]=1;
	for (int i=1;i<=300;i++)
	pw[i]=(2*pw[i-1])%mod;
	for (int i=0;i<n;i++)
	{
		bitset<305> cur;
		for (int j=0;j<m;j++)
		{
			int a;
			scanf("%d",&a);
			cur[j]=a;
		}
		cnt+=add(cur);
	}
	printf("%lld",(pw[n]-pw[n-cnt]+mod)%mod*pw[m-1]%mod);
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    private static Scanner scan;

    public static void main(String[] args) {
        scan = new Scanner(System.in);
        List<Integer> list = new ArrayList<Integer>();
        int value;
        for (int i = 0; i < 10; i++) {
            value = scan.nextInt();
            if (value <= 10000) {
                list.add(value);
            }
        }
        Collections.sort(list);
        System.out.println(list.get(9));
        System.out.println(list.get(8));
        System.out.println(list.get(7));
    }
}

Measured memory_bytes: 17176
/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1; const double eps = 1e-6, ldeps = 1e-9;
struct Dbg { static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto o(C *x)->decltype(os << *x, 0);
template<class C> static char o(...);
template<class C> typename enable_if<sizeof o<C>(0)!=1,Dbg&>::type operator<<(const C &x) {os<<x; return *this;}
template<class C> Dbg &dump(C b, C e) {
    for (struct{C i;int j;} i={(*this<<"\n[",b),0}; i.i!=e and i.j<26; i.i++, i.j++) *this<<", "+2*(i.i==b)<<*i.i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof o<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator<<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator<<(const pair<B, C> &x) {return *this<<'{'<<x.first<<", "<<x.second<<'}';}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 105;

int n, a[mxn];

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        ans += (i&1) and (a[i]&1);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3584
# -*- coding: utf-8 -*-
#C
import sys
#import math

n = int(input())

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
a = []
tm=0
for i in range(0,n+1):
	tm+=hoge[i]
	a.append(hoge[i])
#print(a)
#print(tm)


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



for i in range(0,n):
	if(a[i]>=b[i]):
		a[i]=a[i]-b[i]
	else:
		b[i]-=a[i]
		a[i]=0
		if(a[i+1]>=b[i]):
			a[i+1]=a[i+1]-b[i]
		else:
			a[i+1]=0

tm2 = 0
for i in range(0,n+1):
	tm2+=a[i]
#print(a)
#print(tm2)
print(tm-tm2)



Measured memory_bytes: 24512
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    long long a,b;
    cin>>a>>b;
    if((a*b)%2==0)
    {
        cout<<"Even"<<endl;
        return 0;
    }
    cout<<"Odd"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

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; }

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } 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, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) dump_func(__VA_ARGS__)
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/


int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    vector<ll> X(N);
    cin >> X;
    ll ans = 0;
    rep(i,N-1){
        if((X[i+1] - X[i])*A < B)ans += (X[i+1] - X[i]) * A;
        else ans += B;
    }
    cout << ans << endl;
}


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

using namespace std;

int main(void) {

	int w, h;
	cin >> w >> h;

	vector< pair<int, char> > edge(w + h, make_pair(0, '*'));
	for (int i = 0; i < w; ++i) {
		cin >> edge[i].first;
		edge[i].second = 'x';
	}
	for (int i = w; i < w + h; ++i) {
		cin >> edge[i].first;
		edge[i].second = 'y';
	}
	sort(edge.begin(), edge.end());


	long long x = w + 1, y = h + 1;
	long long sum = 0, num = 0, total = x * y - 1; 

	for (int i = 0; i < edge.size(); ++i) {
		if (edge[i].second == 'x') {
			sum += edge[i].first * y;
			num += y;
			--x;
			if (num >= total) {
				sum -= edge[i].first * (num - total);
				break;
			}
		}
		if (edge[i].second == 'y') {
			sum += edge[i].first * x;
			num += x;
			--y;
			if (num >= total) {
				sum -= edge[i].first * (num - total);
				break;
			}
		}
	}

	cout << sum << endl;
	return 0;

}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,x;
	cin>>a>>b>>c>>x;
	int ans=0;
	for(int i=0;i<a+1;i++){
		for(int j=0;j<b+1;j++){
			for(int k=0;k<c+1;k++){
				int sum=i*500+j*100+k*50;
				if(sum==x){ans++;}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
def main():
    inp=list(map(lambda x:int(x),input().split()))
    A=inp[0]
    B=inp[1]

    res=B
    if A>=6 and A<=12:
        res=res//2
    elif A<=5:
        res=0

    print(res)

if __name__=="__main__":
    main()
    


Measured memory_bytes: 2940
import java.util.Scanner;

//Clock Short Hand and Long Hand
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t--!=0){
			String[] s = sc.next().split(":");
			int h = Integer.parseInt(s[0]);
			int m = Integer.parseInt(s[1]);
			double x = h*30.0 + 30.0*m/60.0;
			double y = m*6;
			double d = Math.min(Math.abs(x-y), Math.abs(y-x));
			if(d>=180)d = 360-d;
			System.out.println(0<=d&&d<30?"alert":90<=d&&d<=180?"safe":"warning");
		}
	}
}

Measured memory_bytes: 29300
s = list(input())
p = [0 for i in range(2019)]
n = len(s)
ans = 0
kar = 0
dig = 1
for i in range(n):
    kar = (kar + int(s[n-1-i])*dig)%2019
    dig = (dig*10)%2019
    p[kar] += 1

for i in range(2019):
    ans += p[i]*(p[i]-1)//2
    if i == 0:
        ans += p[i]
print(ans)

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

int main(){
  map<string, int> M;
  int q, query, x;
  string key;
  scanf("%d", &q);
  for(int i = 0; i < q; i++){
    scanf("%d", &query);
    if(query == 0){
      cin >> key >> x;
      //scanf("%s %d", &key, &x);
      M[key] = x;
    }else{
      cin >> key;
      //scanf("%s", &key);
      printf("%d\n", M[key]);
    }
  }
  return 0;
}


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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){ a=max(a,b);}


int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	int h, w;
	cin >>h >>w;
	vector<string> ba(h);
	rep(i, h) cin >>ba[i];
	
	vector<VI> xs(h, VI(w, -1)), ys(h, VI(w, -1));
	rep(i,h) if(ba[i][0] =='.') xs[i][0]=1;
	rep(i, h) rep(j,w) if(ba[i][j]=='#') xs[i][j]=0;
	rep(i,h) rep(j,w) if(xs[i][j]==-1) xs[i][j] = xs[i][j-1] +1;
	rep(i,h) repr(j,w-2,0) if(xs[i][j]>0 && xs[i][j] < xs[i][j+1])
		xs[i][j] = xs[i][j+1];
	//for(auto xl: xs){for(auto x :xl) cerr<<x<<" "; cerr<<"\n";}
	rep(j, w) if(ba[0][j]=='.') ys[0][j] =1;
	rep(j, w) rep(i,h) if(ba[i][j]=='#') ys[i][j]=0;
	rep(j,w) rep(i, h) if(ys[i][j]==-1) ys[i][j] = ys[i-1][j] +1;
	rep(j,w) repr(i,h-2,0) if(ys[i][j]>0 && ys[i][j] < ys[i+1][j])
		ys[i][j] = ys[i+1][j];
	//for(auto xl: ys){for(auto x :xl) cerr<<x<<" "; cerr<<"\n";}
	
	ll ans =0;
	rep(i, h) rep(j,w) ans = max<ll>(ans, xs[i][j]+ys[i][j]);
	cout <<ans -1 <<"\n";
	return 0;
}



Measured memory_bytes: 35968
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var a = cin.ReadInt;
            var b = cin.ReadInt;
            var diff = Abs(a-b);
            if (diff > 1) {
                WriteLine(Max(a,b)*2-1);
            } else {
                WriteLine(a+b);
            }
        }

        private double MultipleCeil(double value, double multiple) {return Math.Ceiling(value / multiple) * multiple;}

    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const int MAXN = 500005;
const int mod = 1e9 + 7;

int n, a[MAXN];
lint dp[MAXN];
map<int, lint> mp;

int main(){
	scanf("%d",&n);
	for(int i=1; i<=n; i++) scanf("%d",&a[i]);
	dp[n + 1] = 1;
	for(int i=n; i; i--){
		dp[i] = dp[i + 1];
		if(a[i] != a[i + 1]) dp[i] += mp[a[i]];
		dp[i] %= mod;
		mp[a[i]] = dp[i];
	}
	cout << dp[1] << endl;
}


Measured memory_bytes: 17024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 4223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int amax=0;
struct edge { ll to, cost, time; };
vector<edge> G[200];
vector<P> cd(200);
VI d(600000,LINF);

void dijkstra(int s) {
	d[s] = 0;
	priority_queue<P, vector<P>, greater<P> > que;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second/amax;
		if (d[p.second] < p.first) continue;
		REP(i,G[v].size()) {
			edge e = G[v][i];
			bool ok=1;
			int have = p.second%amax;
			for(int j=0;ok;j++){
				if(have>=amax){
					ok=0;
					have=amax-1;
				}
				if(have>=e.cost){
					if(d[e.to*amax+have-e.cost]>d[p.second]+e.time+(cd[v].second*j)){
						d[e.to*amax+have-e.cost]=d[p.second]+e.time+(cd[v].second*j);
						que.push(P(d[e.to*amax+have-e.cost], e.to*amax+have-e.cost));
					}
				}
				have+=cd[v].first;
			}
		}
	}
}

int main() {
	int n, m, s; 
	cin >> n >> m >> s;
	REP(i,m){
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		u--; v--;
		G[u].push_back({v,a,b});
		G[v].push_back({u,a,b});
		amax=max(amax,a*(n-1));
	}
	REP(i,n){
		cin >> cd[i].first >> cd[i].second;
	}
	amax++;
	dijkstra(min(s,amax-1));
	for(int i=1;i<n;i++){
		ll ans=LINF;
		REP(j,amax){
			ans=min(ans,d[i*amax+j]);
		}
		cout << ans << endl;
	}
	return 0;
}


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


int main() {
    int N;
    cin >> N;
    vector<long int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    bool odd = true;
    for (int i = 0; i < N; ++i) {
        if (A[i] % 2 != 0) odd = false;
    }
    if (odd) {
        cout << "second" << endl;
    } else {
        cout << "first" << endl;
    }

}

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

#define MOD 1000000007
#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define MODADDSET(d) if ((d) >= MOD) d -= MOD;
#define MODADDWHILESET(d) while ((d) >= MOD) d -= MOD;

#define cint(d) scanf("%d", &d)
#define cint2(a, b) scanf("%d %d", &a, &b)
#define cint3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define cint4(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)

#define clong(d) scanf("%lld", &d)
#define clong2(a, b) scanf("%lld %lld", &a, &b)
#define clong3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define clong4(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

using namespace std;

typedef long long int slong;

#define MAXN 100000
#define LOGN 16

long long int power(int base, int exp)
{
	if (exp == 0)
	{
		return 1;
	}
	else
	{
		long long int ans;
		
		if (exp % 2)
		{
			ans = base*power(base, exp - 1);
		}
		else
		{
			ans = power(base, exp/2);
			ans *= ans;
		}
		
		MODSET(ans);
		
		return ans;
	}
}

long long int power(int base, int exp, long long int mod)
{
	if (exp == 0)
	{
		return 1;
	}
	else
	{
		long long int ans;
		
		if (exp % 2)
		{
			ans = base*power(base, exp - 1, mod);
		}
		else
		{
			ans = power(base, exp/2, mod);
			ans *= ans;
		}
		
		if (ans >= mod)
		{
			ans %= mod;
		}
		
		return ans;
	}
}

int arr[MAXN+5];

int main()
{
    #ifdef VSP4
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

	int n, i, j, d, ans;
	
	cint(n);
	
	for (i = 1; i <= n; i++)
	{
		cint(arr[i]);
	}
	
	ans = 0;
	
	for (i = 1; i <= n; i++)
	{
		if (arr[arr[i]] == i)
		{
			ans++;
		}
	}
	
	cout << ans/2;
	
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>
#include <sstream>

using namespace std;
const long long P = 1000000007;
const long long INF = 1LL << 60;

int main() {
  long long a,b,c,k;
  cin >> a >> b >> c >> k;
  if(k % 4 == 1 || k % 4 == 3) {
    cout << b-a << endl;
  }else if(k % 4 == 2 || k % 4 == 0) {
    cout << a-b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import fractions
n=int(input())
a=list(map(int,input().split()))
l=[a[0]]
r=[a[-1]]
for i in range(n-2):
    l.append(fractions.gcd(l[i],a[i+1]))
    r.append(fractions.gcd(r[i],a[n-i-2]))
ans=0
for t in range(n):
    if t==0:
        gcd=r[-1]
    elif t==n-1:
        gcd=l[-1]
    else:
        gcd=fractions.gcd(l[t-1],r[-1-t])
    if ans<gcd:
        ans=gcd
print(ans)


Measured memory_bytes: 16128
import Foundation

func readInts() -> [Int]{
    return readLine()!.split(separator: " ").map { Int($0)! }
}
func readInt() -> Int {
    return Int(readLine()!)!
}

func main() {
    let hw = readInts()
    let (h, w) = (hw[0], hw[1])
    if h == 1 || w == 1 {
        print(1)
        return
    }
    let multiplied = h * w
    print(multiplied.isMultiple(of: 2) ? multiplied / 2: multiplied / 2 + 1)
}

main()



Measured memory_bytes: 13492
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N;
vector<int> W;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  W.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> W[i];
  }

  int ans = INF;
  for (int i = 1; i < N; i++) {
    int S1 = 0, S2 = 0;
    for (int j = 0; j < i; j++) {
      S1 += W[j];
    }
    for (int j = i; j < N; j++) {
      S2 += W[j];
    }
    ans = min(ans, abs(S2 - S1));
  }

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

Measured memory_bytes: 256