akhauriyash/Code-Regression huggingface dataset:
n = int(input())
w = []
hantei = []
ans = ''
for i in range(n):
    w.append(input())
hantei.append(w[0])
for i in range(1,n):
    if w[i - 1][-1] == w[i][0] and w[i] not in hantei:
        ans = 'Yes'
        hantei.append(w[i])
    else:
        ans = 'No'
        break
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <set>
#include <map>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define for_p(i, a, b) for(int i = a; i < b; i++)
#define for_m(i, a, b) for(int i = a - 1; i >= b; i--)

//a = s1.size();
//vector<string> s1;
//string s2 = accumulate( s1.begin(), s1.end(), string() );

using namespace std;

int main()
{
  int a = 0 , b = 0, c = 0, d = 0, e = 0, f = 0;
  int i = 0, j = 0;
  double d1 = 0, d2 = 0, d3 = 0, d4 = 0, d5 = 0, d6 = 0;
  int a1[300000], a2[300000], a3[300000];
  char s1[200000], s2[200000], s3[200000];
  
  cin >> a >> b >> c;
  
  for(i = 0; i < c; i++){
    cin >> a1[i];
    a3[i] = 0;
    if(i < a){
      a2[i] = b;
    }
  }
      
  for(i = 0; i < c; i++){    
    a3[a1[i] - 1]++;
  }
  for(i = 0; i < a; i++){
    a2[i] = b - (c - a3[i]);
  }
  for(i = 0; i < a; i++){
    if(a2[i] >= 1){
      cout << "Yes" << endl;
    }else{
      cout << "No" <<endl;
    }
  }
}



Measured memory_bytes: 3328
package main

import (
	"fmt"
)

const (
	// MOD is .
	MOD = 1000000000 + 7
	// MOD = 13
)

func main() {
	var n, a, b int
	fmt.Scanf("%d %d %d", &n, &a, &b)
	res := modPow(2, n) + 2*MOD - combMod(n, a) - combMod(n, b) - 1
	fmt.Println(res % MOD)
	// fmt.Println(combMod(n, a))
}

func combMod(n, k int) int {
	if k == 0 {
		return 1
	}
	res := n
	div := k
	for i := 1; i < k; i++ {
		res = res * (n - i) % MOD
		div = div * (k - i) % MOD
	}
	div = modPow(div, MOD-2)
	return res * div % MOD
}

func modPow(a, n int) int {
	if n == 0 {
		return 1
	}
	res := 1
	for p := n; p > 0; p >>= 1 {
		if p&1 == 1 {
			res = res * a % MOD
		}
		a = a * a % MOD
	}
	return res
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using order_statistics_tree = tree<T,null_type,less_equal<T>,rb_tree_tag,
  tree_order_statistics_node_update>;
vector<int> u, v, ost;
signed main(){
    int n;
    cin >> n;
    u.resize(n); v.resize(n);
    for(auto& i: u) cin >> i;
    for(auto& i: v) cin >> i;
    int ans = 0;
    if(n&1){
        for(auto j: v)ans^=j;
        for(auto j: u)ans^=j;
    }
    for(int i = 28, t = (1<<29)-1; i >=0; i--, t>>=1){
        for(auto&j: v)j&=t;
        sort(v.begin(),v.end());
        int cnt = 0;
        for(auto j: u)cnt^=v.end()-upper_bound(v.begin(),v.end(), t^j&t);
        ans^=(cnt&1)<<i+1;
    }
    cout << ans <<endl;
}


Measured memory_bytes: 1792
function Main (input) {
  const inputs = input.split(/\s/g).map((num) => parseInt(num));
  const half = 16 / 2;
  const isEnable = inputs[0] <= half && inputs[1] <= half;
  console.log('%s', isEnable ? 'Yay!' : ':(');
}

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


Measured memory_bytes: 7372
DAMMY = -1

num_node, num_edge = gets.chomp.split.map(&:to_i)

array = Array.new(1 + num_node) { [] }
num_edge.times do
  edge = gets.chomp.split.map(&:to_i)
  array[edge[0]] << edge[1]
  array[edge[1]] << edge[0]
end

goals = [DAMMY] * (num_node + 1)
que = [1]

until que.empty?
  a = que.shift

  array[a].each do |b|
    next unless goals[b] == DAMMY
    goals[b] = a
    que.push(b)
  end
end

goals.shift # 0
goals.shift # 1

puts "Yes"
print goals.join("\n")


Measured memory_bytes: 33504
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

constexpr int P = 1000000007;
vector<int> f;
void init(int n) {
    f = vector<int>(n + 1);
    f[0] = 1;
    for (int i = 1; i <= n; i++) {
        f[i] = (int64_t)f[i - 1] * i % P;
    }
}
int64_t pow(int n, int k) {
    int64_t r = 1, t = n;
    for (; k != 0; k /= 2) {
        if (k & 1) r = r * t % P;
        t = t * t % P;
    }
    return r % P;
}
int64_t inv(int n) {
    return pow(n, P - 2);
}
int64_t comb(int n, int k) {
    if (n < k || k < 0) return 0;
    return (int64_t)f[n] * inv((int64_t)f[k] * f[n - k] % P) % P;
}


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

    init(h + w - 2);

    int64_t r = 0;
    for (int j = b; j < w; j++) {
        r += comb(j + h - a - 1, h - a - 1) * comb(w - 1 - j + a - 1, a - 1) % P;
    }

    cout << r % P << endl;

    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define ll long long
const int N = 1e6 + 10;
using namespace std;
ll n,k;
ll a[N];
ll ans=0;
int main() {
  ios::sync_with_stdio(false);
  cin>>n>>k;
  for(ll i=0;i<n;i++)
      cin>>a[i];
  sort(a,a+n);
  for(ll i=0;i<n-k;i++){
      ans+=a[i];
  }
  cout<<ans<<endl;
    return 0;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(10);

}

signed main() {
	ll x, t;

	cin >> x >> t;

	cout << max((int)0, (int)(x - t)) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int linesearch(int *a,int k,int n);
int main()
{
  int i,j,n,m,alt,cnt=0,iden;
  scanf("%d",&n);
  int a[n+1];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  scanf("%d",&m);
  for(j=0;j<m;j++){
    scanf("%d",&alt);
    iden=linesearch(a,alt,n);
    if(iden==1){
      cnt++;
    }
  }
  printf("%d\n",cnt);
  return 0;
}
  int linesearch(int *a, int k,int n){
  int i=0;
  a[n]=k;
  while(a[i]!=k){
    if(i==n-1)return 0;
     i++;
  }
  return 1;
}



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

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 998244353;
    static vector<modint> factorial;

    modint(): num(0) {};
    modint(ll num_): num((num_ + MOD) % MOD) {
        assert(num >= 0 && num < MOD);
    }
    modint(const modint &r): num(r.num) {}
    operator ll() const { return num; }

    template <typename T>
    void check_type(const T &num_) const {
        assert(num_ >= 0 && num_ < MOD);
        static_assert(is_integral<T>() || is_same<T,modint>(), "T is not integral.");
    }

    template <typename T>
    modint operator+(const T &r) const { check_type(r); return modint(num + r); }
    template <typename T>
    modint operator-(const T &r) const { check_type(r); return modint(num - r); }
    template <typename T>
    modint operator*(const T &r) const { check_type(r); return modint(num * r); }
    template <typename T>
    modint operator/(const T &r) const { check_type(r); return num * pow(r, MOD-2); }

    template <typename T>
    modint operator+=(const T &r) { return *this = *this + r; }
    template <typename T>
    modint operator-=(const T &r) { return *this = *this - r; }
    template <typename T>
    modint operator*=(const T &r) { return *this = *this * r; }
    template <typename T>
    modint operator/=(const T &r) { return *this = *this / r; }

    static modint pow(const modint &x, const ll &r) {
        if(r == 0) return 1;
        return pow(x*x, r/2) * modint(r&1 ? x : modint(1));
    }

    static modint fact(int n){
        if((int)factorial.size() <= n) {
            int size = factorial.size();
            factorial.resize(n+1);
            for (int k = size; k <= n; k++) {
                factorial[k] = factorial[k-1] * k;
            }
        }
        return factorial[n];
    }

    static modint C(int n, int r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }

    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
};
vector<modint> modint::factorial = {1};
#define fact(n) modint::fact(n)
#define C(n,r) modint::C(n,r)
#define H(a,b) C(a+b, a)


int main(void){
    int n;
    cin >> n;
    modint sum = 0;
    for (int i = n/2+1; i <= n; i++) {
        sum += C(n,i) * modint::pow(2,n-i) * 2;
    }
    cout << modint::pow(3,n) - sum << endl;
    return 0;
}


Measured memory_bytes: 117376
#include <bits/stdc++.h>
using namespace std;
 
//Made with <3 by MinumCoklatPanas
typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// cout << "yo\n";
	int n,m;
	cin >> n >> m;
	int sum = 0;
	for (int i = 1 ; i <= m ; i++)
	{
		int ta;
		cin >> ta;
		sum += ta;
	}
	int ans = max(-1,n - sum);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3656
import random


def gcd(a, b):
    if a == 0:
        return b
    return gcd(b % a, a)


def lcm(a, b):
    return (a * b) / gcd(a, b)


n,x,t= map(int, input().split())
if (n%x==0):
    print((n//x)*t)
else:
    print((n//x+1)*t)


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

int main() {
	string S;
	cin >> S;
	int ans = 0;
	int hikakuAns = 0;

	for(int i = 0; i < S.size(); i++)
	{
		
		if (S.at(i) != 'A' && S.at(i) != 'C' && S.at(i) != 'G' && S.at(i) != 'T' ) {
			continue;
		}

		hikakuAns = 0;

		for(int j = 0; j < (S.size() - i); j++)
		{
			int nextChar = i + j;
			if (S.at(nextChar) == 'A' || S.at(nextChar) == 'C' || S.at(nextChar) == 'G' || S.at(nextChar) == 'T' ) {
				hikakuAns++;
			} else {
				break;
			}
		}

		if (ans < hikakuAns) {
			ans = hikakuAns;
		}
		
		
		
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc092/tasks/abc092_b

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n, d, x;
    cin >> n >> d >> x;
    int ans = x;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        for (int j = 0; j < d; j += a)
            ans++;
    }

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


Measured memory_bytes: 3604
using System;
class paiza
{
  static public void Main(string[] args)
  {
    string input_st = Console.ReadLine();
    char[] separator = new char[] {' '};
    string[] input = input_st.Split(separator);
    
    int A = int.Parse(input[0]);
    int B = int.Parse(input[1]);
    int K = int.Parse(input[2]);
    int min = 0;
    if(A < B)
      min = A;
    else
      min = B;
    int current_K = 0;
    int i = 0;
    for(i = min;i > 0;i--)
    {
      if(A % i == 0 && B % i == 0)
      {
        current_K++; 
        //Console.WriteLine("Current K = " + current_K + " i = " + i);
        if(current_K == K)
          break;
      }
    }
    Console.WriteLine(i);
  }
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class Data{
public:
	int index,height;
};

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

	int N=in();
	auto S=vecin(N);
	sort(ALL(S));
	S.erase(unique(ALL(S)),S.end());
	N=in();
	auto T=vecin(N);
	sort(ALL(T));

	vector<int> U;
	set_intersection(ALL(S),ALL(T),inserter(U,U.end()));

	out(U.size());

	return 0;
}



Measured memory_bytes: 3196
Uses    crt,math;
Var     a,b,h,m,i,j,k,n:longint;
angle1,angle2,res:extended;
st:string;
begin
clrscr;
readln(a,b,h,m);
angle1:=0.5*(h*60+m);
angle2:=6*m;
angle1:=abs(angle1-angle2);
angle1:=min(360-angle1,angle1);
writeln(sqrt(a*a+b*b-2*a*b*cos((angle1)/180*pi)):0:20);
end.




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


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

	vector<int> A(N),B(N);

	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	
	for (int i = 0; i < N; i++) {
		B.at(A.at(i)-1) = i+1;
		
	}
	
	for (int i = 0; i < N; i++) {
		cout << B.at(i) << " "<<endl;
	}
}

Measured memory_bytes: 1664
p = 0
t = 0
N,M = map(int, input().split())
s = []
c = []
for i in range(M):
  s.append(0)
  c.append(0)
for i in range(M):
  s[i], c[i]=map(int, input().split())
number=[1]
for k in range(N-1):
  number.append(10)
for i in range(M):
  for j in range(M):
    if (s[i]==s[j]) and (c[i]!=c[j]):
      p = 1
for i in range(M):
  number[s[i]-1]=c[i]
number = [0 if z==10 else z for z in number]
h = 0
k = 0
while h<=M-1 and k==0:
  k=1
  if c[h]==0:
    k = 0
  h+=1
if N==1 and h==M and k!=1:
  p = 2
if number[0]==0 and N!=1 and p!=2:
  p=1
if p==0:
  for i in range(N):
    print(number[i], end="")
if p==1:
  print(-1)
if p==2:
  print(0)

Measured memory_bytes: 9268
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <deque>
#include <bitset>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i) = 0; (i) <= (n); (i)++)
using namespace std;

int A, B;
int D[100][100];

int F[101][101];
int G[101][101];

void Set(int p, int q)
{
	int min_f = INT_MAX;

	for (int f = 0; f <= 100; f++)
	{
		bool is_update = false;

		REP(x, A) REP(y, B)
		{
			int d = p * (x + 1) + q * (y + 1) + f;
			if (D[x][y] > d)
			{
				is_update = false;
				goto BREAK;
			}
			if (G[x][y] > d && D[x][y] == d)
			{
				is_update = true;
			}
		}
	BREAK:
		if (is_update)
		{
			min_f = MIN(f, min_f);
		}
	}

	if (min_f <= 100)
	{
		F[p][q] = min_f;

		REP(x, 101) REP(y, 101)
		{
			int d = p * (x + 1) + q * (y + 1) + min_f;
			G[x][y] = MIN(G[x][y], d);
		}
	}
}

signed main()
{
	cin >> A >> B;
	REP(a, A)
	{
		REP(b, B)
		{
			cin >> D[a][b];
		}
	}
	REP(i, 101) REP(j, 101)
	{
		F[i][j] = 100;
		G[i][j] = 100;
	}

	REP(p, 101) REP(q, 101)
	{
		Set(p, q);
	}

	REP(x, A) REP(y, B)
	{
		int min = INT_MAX;
		REP(p, 101) REP(q, 101)
		{
			int d = p * (x + 1) + q * (y + 1) + F[p][q];
			min = MIN(min, d);
		}
		if (D[x][y] != min)
		{
			cout << "Impossible" << endl;
			exit(0);
		}
	}

	cout << "Possible" << endl;
	cout << "202 10401" << endl;
	REP(i, 100) cout << (i + 1) << " " << (i + 2) << " X" << endl;
	REP(i, 100) cout << (i + 102) << " " << (i + 103) << " Y" <<  endl;

	REP(p, 101) REP(q, 101)
	{
		cout << (p + 1) << " " << (202 - q) << " " << F[p][q] << endl;
	}

	cout << "1 202" << endl;
}

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

const int N = 1e+6 + 7;
string n;
long long int dp[N][10];

long long int solve(int i, int j)
{
    if (i >= n.size())
        return j;
    if(dp[i][j]==0)
    {
        if(n[i]+j=='10')
            dp[i][j]=solve(i+1,1);
        else 
            dp[i][j]=min(n[i]-'0'+j+solve(i+1,0),10-n[i]+'0'-j+solve(i+1,1));
    }
    return dp[i][j];
}
int main()
{
    cin >> n;
    reverse(n.begin(), n.end());
    long long int ans = 0;
    cout << solve(0,0);
}

Measured memory_bytes: 141956
import sys

cin = sys.stdin
# cin = open("in.txt", "r")

def line2N():
    return map(int, cin.readline().split())

n, c = line2N()
x = [0]*n
v = [0]*n
for i in range(n):
    x0, v0 = line2N()
    x[i] = x0
    v[i] = v0
c1 = [0]*n
m1 = [0]*(n+1)
c1[0] = -(x[0]-0) + v[0]
m1[0] = max(0, c1[0])
for i in range(1,n):
    c1[i] = c1[i-1] - (x[i]-x[i-1]) + v[i]
    m1[i] = max(m1[i-1], c1[i])
c2 = [0]*n
c2[n-1] = -(c - x[n-1]) + v[n-1]
m2 = [0]*(n+1)
m2[n-1] = max(0, c2[n-1])
for i in range(n-2, -1, -1):
    c2[i] = c2[i+1] - (x[i+1]-x[i]) + v[i]
    m2[i] = max(m2[i+1], c2[i])
ans0 = 0
for i in range(0, n-1):
    ans0 = max(ans0, c1[i] - x[i] + m2[i+1])
for i in range(n-1, 0, -1):
    ans0 = max(ans0, c2[i] - (c-x[i]) + m1[i-1])

print(max(ans0, m1[n-1], m2[0]))


Measured memory_bytes: 21932
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod  1000000007;
int N, K;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    vector<int> v(N);
    for(int i = 0; i < N; i++) cin >> v[i];
    sort(v.begin(), v.end(), greater<int>());
    int ans = 0;
    for(int i = 0; i < K; i++) ans += v[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = []
def is_prime(n):
    if n<2:return False
    for i in range(2,n):
        if i*i>n:break
        if n%i==0:return False
    return True
n = N
if is_prime(n):
    A.append(n)
    n=1
for i in range(2,N):
    if n%i==0:
        while n>1:
            A.append(i)
            n//=i
            if n%i!=0:break
    if n==1:break
print(str(N)+":",*A)


Measured memory_bytes: 5596
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let h: usize = input();
    let w: usize = input();

    let mut ans = usize::max_value();
    for i in 1..h {
        let h2 = (h - i) / 2;
        let h3 = h - i - h2;

        let s1 = i * w;
        let s2 = h2 * w;
        let s3 = h3 * w;

        let mx = std::cmp::max(s1, std::cmp::max(s2, s3));
        let mn = std::cmp::min(s1, std::cmp::min(s2, s3));
        ans = std::cmp::min(ans, mx - mn);

        let w2 = w / 2;
        let w3 = w - w2;

        let s1 = i * w;
        let s2 = (h - i) * w2;
        let s3 = (h - i) * w3;

        let mx = std::cmp::max(s1, std::cmp::max(s2, s3));
        let mn = std::cmp::min(s1, std::cmp::min(s2, s3));
        ans = std::cmp::min(ans, mx - mn);
    }

    for i in 1..w {
        let h2 = h / 2;
        let h3 = h - h2;

        let s1 = h * i;
        let s2 = h2 * (w - i);
        let s3 = h3 * (w - i);

        let mx = std::cmp::max(s1, std::cmp::max(s2, s3));
        let mn = std::cmp::min(s1, std::cmp::min(s2, s3));
        ans = std::cmp::min(ans, mx - mn);

        let w2 = (w - i) / 2;
        let w3 = w - i - w2;

        let s1 = h * i;
        let s2 = h * w2;
        let s3 = h * w3;

        let mx = std::cmp::max(s1, std::cmp::max(s2, s3));
        let mn = std::cmp::min(s1, std::cmp::min(s2, s3));
        ans = std::cmp::min(ans, mx - mn);
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}
int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  int ans=0;
  rep(i,0,n) cin>>a[i]>>b[i];
  rep(i,0,n) ans+=b[i]-a[i]+1;
  cout<<ans;
    
}

// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <utility>
#include <queue>
#include <cassert>
#define maxn 200005

using namespace std;
typedef long long ll;

int n;
char s[maxn];
ll cntw,ans;
int main(){
  scanf("%s",s + 1);
  n = strlen(s + 1);
  for(int i = 1;i <= n;i++){
    if(s[i] == 'W'){
      cntw++;
      ans += i - cntw;
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 384
import sys

MOD = 1000000007

def pow_mod(m, n):
    if n == 1:
        return m % MOD
    else:
        tmp = pow_mod(m, n / 2)
        if n % 2 == 0:
            return tmp * tmp % MOD
        else:
            return tmp * tmp * m % MOD
    
if __name__ == '__main__':
    line = sys.stdin.readline()
    m, n = line.split()
    m, n = int(m), int(n)
    
    sys.stdout.write(str(pow_mod(m, n)) + '\n')
        

Measured memory_bytes: 4224
#include <algorithm>
#include <cmath>   // abs() for float, and fabs()
#include <cstdlib> // abs() for integer
#include <iostream>
#include <list>
#include <map> //連想配列
#include <queue>
#include <set> //
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector> //動的配列

using namespace std;

/*
int check(int sum) {
  int i = 10e+09 + 7;
  if (sum >= i) {
    sum = sum - i;
    check(sum);
  }
  return sum;
}
*/
int main() {
  long int i = 10e+08 + 7;
  long int N, M;
  cin >> N >> M;
  if (abs(N - M) > 1) {
    cout << 0 << endl;
    return 0;
  }
  long int sum = 1;
  for (long int n = N; n >= 1; n--) {
    sum *= n;
    sum = sum % i;
  }
  for (long int m = M; m >= 1; m--) {
    sum *= m;
    sum = sum % i;
  }

  if (N == M) {
    sum *= 2;
    sum = sum % i;
    cout << sum << endl;
  } else {
    cout << sum << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
typedef vector<char> vc;
typedef vector<vc> vcc;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F first
#define S second
#define in insert
#define mina(a,b) (a)=min((a),(b));
#define maxa(a,b) (a)=max((a),(b));
const int INF = 1e9 + 7;
void solve(){
    int n; cin>>n;
    double ans=0;
    for(int i = 0; i < n; i++) {
        double t; cin>>t;
        string s; cin>>s;
        if(s=="JPY") ans+=t;
        else ans+=t*380000;
    }
    cout<<fixed<<setprecision(5)<<ans;

}
int main(){
    int T=1;
    //cin>>T;
    for(int i = 0; i < T; i++) solve(); 
}

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

int max(int a, int b){
  return a >= b ? a : b;
}
int min(int a, int b){
  return b >= a ? a : b;
}
int sei(int a){
  return a>0 ? a : 0;
}
int factorial(int n) {
    if (n > 0) return n*factorial(n - 1);
		else return 1;
}
int compare_up_int(const void *a, const void *b){
   return *(int*)a - *(int*)b;
}
int compare_down_int(const void *a, const void *b){
   return *(int*)b - *(int*)a;
}
int euclid(int a, int b){
  if(a < b){int tmp = a;a = b;b = tmp;}
  int r = a % b;
  if(r < 0) r += b;
  while(r != 0){
    a = b;b = r;r = a % b;
    if(r < 0) r += b;
  }
  return b;
}

int main(){
  int N;
  scanf("%d",&N);
  int num[N];
  for(int i=0;i<N;i++) scanf("%d",&num[i]);
  for(int i=0;i<N-1;i++){
    num[i+1]=euclid(num[i],num[i+1]);
  }
  printf("%d",num[N-1]);
  return 0;
}


Measured memory_bytes: 512
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();

    int N = Integer.parseInt(sc.next());
    int K = Integer.parseInt(sc.next());

    int[] h = new int[N];

    for (int i = 0; i < N; i++) {
      h[i] = Integer.parseInt(sc.next());
    }
    int ans = (int) 10e9;
    Arrays.sort(h);
    for (int j = 0; j <= N - K; j++) {
      if (h[j + K - 1] - h[j] < ans)
        ans = h[j + K - 1] - h[j];
    }

    System.out.println(ans);
  }
}

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        buflen = in.read(buffer);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen <= 0) {
        return false;
      }
    }
    return true;
  }

  private int readByte() {
    if (hasNextByte()) {
      return buffer[ptr++];
    } else {
      return -1;
    }
  }

  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }

  private void skipUnprintable() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
      ptr++;
    }
  }

  public boolean hasNext() {
    skipUnprintable();
    return hasNextByte();
  }

  public String next() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while (isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  public int nextInt() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    int n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public long nextLong() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }
}

Measured memory_bytes: 39052
// B.

#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
	int s, ans;
	cin >> s;
	vector<int> f(1000001);
	for (int i = 2; ; ++i) {
		if (s < f.size()) {
			f[s] = 1;
		}
		int next = s % 2 ? s * 3 + 1 : s / 2;
		if (f[next]) {
			ans = i;
			break;
		}
		s = next;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int a,b,ans=0;
	string s;
	cin>>a>>b;
	ans=(b+a-3)/(a-1);
    cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 0x3fffffff;


vector<int> edge[100005];
bool d[100005] = {};
bool b[100005] = {};
bool ans = false;
int start = -1;
int dfs(int n, int b){
	//cout << "dfs: " << n << " " << b << endl;
	//if( d[n] ){
	//	start = n;
	//	return -1;
	//}
	//d[n] = true;
	if( edge[n].size() == 1 ) return 1;
	vector<int> v;
	for(auto t: edge[n]) if(t != b){
		v.push_back( dfs(t, n) );
	}
	int odd = 0;
	int even = 0;
	for(auto t: v){
		if( t > 0 && (t % 2) ) odd++;
		if( t > 0 && (t % 2 == 0) ) even++;
		//if( t == 0 ) even++;
		//cout << t << " ";
	}
	//cout << endl;
	//cout << n << "," << b << "  odd:" << odd << " even:" << even << endl;
	if( odd > 1 ){
		ans = true;
		//cout << "true " << ret << endl;
	}
	//if( v.size() == even ) return 1;
	if( odd == 1 ) return 0;
	else return 1;
	return ( v.size()==1 ? v[0]+1 : -1 );
}

int find(int n, int b){
	if( edge[n].size() > 2 ) return n;
	for(auto t: edge[n]) if( t != b ){
		return find(t, n);
	}
	return b;
}

int main(){
	//ios_base::sync_with_stdio(0);
	int N;

	cin >> N;
	rep(i,N-1){
		int a, b;
		cin >> a >> b;
		a--; b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	rep(i,N){
		//cout << "loop" << endl;
		if( edge[i].size() == 1 ){
			//Fill( d, false );
			int st = edge[i][0];
			if( b[st] ) continue;
			b[ st ] = true;
			dfs( st, -1 );
			if( ans ) break;
			break;
		}
		//if( edge[i].size() > 2 ){
		//	//int st = find(edge[i][0], i);
		//	int st = i;
		//	if( b[st] ) continue;
		//	//Fill( d, false );
		//	b[ st ] = true;
		//	dfs( st, -1 );
		//	if( ans ) break;
		//}
	}

	cout << (ans ? "First" : "Second" ) << endl;

	return 0;
}


Measured memory_bytes: 5888
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<utility>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#define maxn 1010
#define INF 0x3f3f3f3f
#define LL long long
#define ULL unsigned long long
#define E 1e-8
#define mod 1000000007
#define P pair<int,int>
using namespace std;

int main()
{
    int a,b,c,d;
    while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF){
        int ans = min(a,b)+min(c,d);
        printf("%d\n",ans);
    }
    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	int n, a;
	cin >> n >> a;

	int cnt = n % 500;
	cout << (cnt - a <= 0 ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
void foreach_permutation(ll n, vector<ll> &vec) {
    ll indexes[n];
    for (ll i = 0; i < n; i++) indexes[i] = i+1;
    do {
        ll tmp=0LL;
        rep(i,n)tmp+=pow(10,i)*indexes[n-i-1];
        vec.push_back(tmp);
    } while (next_permutation(indexes, indexes + n));
}

int main(){
    ll n,ans,count=0;
    cin >> n;
    vector<ll> p(n),q(n);
    rep(i,n)cin >> p.at(i);
    rep(i,n)cin >> q.at(i);
    ll pin=0LL, qin=0LL;
    rep(i,n){
        pin+=pow(10,i)*p.at(n-i-1);
        qin+=pow(10,i)*q.at(n-i-1);
    }
    vector<ll> r(0);
    foreach_permutation(n, r);
    if(pin>qin)swap(pin,qin);
    rep(i,r.size()){
    	if(pin==r.at(i))ans=i;
    	if(qin==r.at(i))ans=i-ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main()
{ string a;int k=-1;vector<string>b;
  b.resize(0);
  cin>>a;
  for(int i=0;i<a.size();i++)
  { if(a[i]=='0')
    { b.resize(b.size()+1);
      b[++k]='0';
      }
    else if(a[i]=='1')
    { b.resize(b.size()+1);
      b[++k]='1';}
 else if(b.size()!=0){
          b.resize(b.size()-1);
          k--;
}}
   for(int i=0;i<b.size();i++)
    cout<<b[i];
 return 0;}
 

      

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<math.h>
#include<iomanip>
#include<cstdio>
	using namespace std;
	int main()
	{
		int ans = 0;
		int N, A, B,sum=0;
		cin >> N>>A>>B;
		for (int i = 1;i <= N;i++) {
			sum = 0;
			sum = ((i/10000)%10)+((i / 1000)%10) + ((i / 100)%10) + ((i / 10)%10) + (i % 10);
			if (sum >= A && sum <= B) ans += i;
		}
		cout << ans;
	}


Measured memory_bytes: 256
N,M = [int(i) for i in input().rstrip().split(' ')]
P = [0 for _ in range(N)]
ans,pen = 0,0
for _ in range(M):
    p,s = input().rstrip().split(' ')
    p = int(p) - 1
    if P[p] == -1:
        continue
    if s == "WA":
        P[p] += 1
    else:
        ans += 1
        pen += P[p]
        P[p] = -1
print(ans,pen)

Measured memory_bytes: 3888
def dict_update(val):
    s = input()
    if s not in v:
        v[s] = val
    else:
        v[s] += val


v = {}
n = int(input())
for i in range(n):
    dict_update(1)
m = int(input())
for j in range(m):
    dict_update(-1)
print(max(max(v.values()), 0))


Measured memory_bytes: 8992
#include "bits/stdc++.h"
using namespace std;
using namespace std;

int main() {
	int a, b, c;
	while (cin >> a >> b >> c) {
		if (a == -1 || b == -1 || c == -1)
			break;
		int second = 7200 - (a * 3600 + b * 60 + c);
		printf("%02d:%02d:%02d\n", second / 3600, second / 60%60, second % 60);
		second = second * 3;
		printf("%02d:%02d:%02d\n", second / 3600, second / 60 % 60,
				second % 60);
	}
}

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

const long long MOD = (long long)1e9 + 7;
const int h_max = 1001;
long long dp[h_max][h_max];
bool grid[h_max][h_max];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  #ifdef LOCAL_DEFINE
  freopen ("input.txt", "r", stdin);
  freopen ("output.txt", "w", stdout);
  #endif 
  int h, w;
  char cell;
  cin >> h >> w;
  for (int i = 0; i < h; ++i) {   
    for (int j = 0; j < w; ++j) {
      cin >> cell;
      grid[i][j] = cell == '.';
    }
  }
  dp[0][0] = 1L;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (i > 0 && grid[i - 1][j]) {
        dp[i][j] = (dp[i - 1][j] % MOD + dp[i][j] % MOD) % MOD;
      }
      if (j > 0 && grid[i][j - 1]) {
        dp[i][j] = (dp[i][j] % MOD + dp[i][j - 1] % MOD) % MOD;
      }
    }
  }
  cout << dp[h - 1][w - 1];
}

Measured memory_bytes: 9088
package main

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

type BufferedWriter interface {
    Printf(format string, a ...interface{})
    Flush()
}

type writerImpl struct {
    *bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
    return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
    fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
    impl.Writer.Flush()
}

type WordScanner interface {
    NextInt() int
    NextInt64() int64
    NextString() string
}

type wordScannerImpl struct {
    *bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
    s := bufio.NewScanner(reader)
    s.Split(bufio.ScanWords)
    return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
    impl.Scan()
    bb := impl.Bytes()
    i := 0
    for _, b := range bb {
        i *= 10
        i += int(b - '0')
    }
    return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
    impl.Scan()
    bb := impl.Bytes()
    i := int64(0)
    for _, b := range bb {
        i *= 10
        i += int64(b - '0')
    }
    return i
}

func (impl *wordScannerImpl) NextString() string {
    impl.Scan()
    return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
    defer writer.Flush()
    k, n := reader.NextInt64(), reader.NextInt64()
    aa := make([]int64, n)
    for i := int64(0); i < n; i++ {
        aa[i] = reader.NextInt64()
    }
    diffToPrev := make([]int64, n)
    diffToPrev[0] = aa[0] + k - aa[len(aa)-1]
    for i := int64(1); i < n; i++ {
        diffToPrev[i] = aa[i] - aa[i-1]
    }
    maxSoFar := diffToPrev[0]
    for i := int64(1); i < n; i++ {
        if diffToPrev[i] > maxSoFar {
            maxSoFar = diffToPrev[i]
        }
    }
    writer.Printf("%d\n", k - maxSoFar)
}


Measured memory_bytes: 4352
/*input
5
0 1 3 6 10
3 10
2 3 4
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
#define int ll
ll a[maxn];
vector<int> v;
int idx[maxn];
bool vis[maxn];
int ans[maxn];

vector<int> OAO;
int32_t main()
{
	IOS;
	int n;
	cin>>n;
	REP(i,n) cin>>a[i];

	ll m,k;
	cin>>m>>k;
	REP(i,n-1) v.pb(i);
	while(m--){
		int tmp;
		cin>>tmp;
		tmp-=2;
		swap(v[tmp],v[tmp+1]);
	}
	REP(i,n-1) idx[v[i]]=i;

	for(int i=0;i<n-1;i++) if(!vis[i]){
		int cur=i;
		OAO.clear();
		while(!vis[cur]){
			OAO.pb(cur);
			vis[cur]=1;
			cur=v[cur];
		}
		REP(i,SZ(OAO)) ans[OAO[i]]=OAO[(i+k)%SZ(OAO)];
	}
	int cur=a[0];

	cout<<cur<<'\n';
	for(int i=0;i<n-1;i++){
		cur+=a[ans[i]+1]-a[ans[i]];
		cout<<cur<<'\n';
	}
	return 0;
}


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

int main()
{
        int N, L;
        int A[100005];

        cin >> N >> L;

        int pos = -1;
        for ( int i = 0; i < N; i++ ) {
                cin >> A[i];
                if ( i > 0 && A[i] + A[i - 1] >= L ) pos = i - 1;
        }

        if ( pos == -1 ) {
                cout << "Impossible" << '\n';
        } else {
                cout << "Possible" << '\n';
                for ( int i = 0; i < pos; i++ ) {
                        cout << i + 1 << '\n';
                }
                for ( int i = N - 2; i > pos; i-- ) {
                        cout << i + 1 << '\n';
                }
                cout << pos + 1 << '\n';
        }
        
        return ( 0 );
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(ll, a, b, k);
  ll c = min(a, k);
  a -= c;
  k -= c;
  c = min(b, k);
  b -= c;
  k -= c;
  out(a, b);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// 解説AC。これでいいんかい。
using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  // ll N; cin >> N;
  ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  vector<ll> a(N); rep(i, N) cin >> a[i];
  
  ll ans = 1;
  
  bool ok = false;
  rep(i, N) {
    if(a[i]%2==1) ok = true;
  }
  rep(i, N-1) ans *= 2;
  if(!ok) {
    ans *= 2;
    if(K == 1) ans = 0;
  }

  cout << ans << endl;
  // cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3712
from fractions import gcd
from functools import reduce

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

n = int(input())
t = [int(input()) for _ in range(n)]

print(lcm_list(t))

Measured memory_bytes: 5076
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskF solver = new TaskF();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskF {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int height = in.nextInt();
			int width = in.nextInt();
			char[][] s = new char[height][];
			int sv = -1;
			int tv = -1;
			for (int r = 0; r < height; r++) {
				s[r] = in.next().toCharArray();
				for (int c = 0; c < width; c++) {
					if (s[r][c] == 'S') {
						sv = r * width + c;
					}
					if (s[r][c] == 'T') {
						tv = r * width + c;
					}
				}
			}
			int[] q = new int[height * width];
			int[] d = new int[height * width];
			int[] p = new int[height * width];
			final int infinity = 1000000000;
			for (int ans = 0; ; ans++) {
				Arrays.fill(p, -1);
				Arrays.fill(d, infinity);
				int qt = 0;
				int qh = 1;
				q[0] = sv;
				d[sv] = 0;
				while (qt < qh) {
					int v = q[qt++];
					if (v == tv) {
						break;
					}

					int r = v / width;
					int c = v % width;
					for (int nr = 0; nr < height; nr++) {
						int nc = c;
						if (s[nr][nc] == '.') {
							continue;
						}
						int u = nr * width + nc;
						if (d[u] > 1 + d[v]) {
							d[u] = 1 + d[v];
							p[u] = v;
							q[qh++] = u;
						}
					}
					for (int nc = 0; nc < width; nc++) {
						int nr = r;
						if (s[nr][nc] == '.') {
							continue;
						}
						int u = nr * width + nc;
						if (d[u] > 1 + d[v]) {
							d[u] = 1 + d[v];
							p[u] = v;
							q[qh++] = u;
						}
					}
				}
				if (d[tv] >= infinity) {
					out.println(ans);
					return;
				}
				if (d[tv] == 1) {
					out.println(-1);
					return;
				}
				for (int v = tv; v >= 0; v = p[v]) {
					int r = v / width;
					int c = v % width;
					if (s[r][c] == 'o') {
						s[r][c] = '.';
					}
				}
			}
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



Measured memory_bytes: 25952
def hms2s (t):
	l = t.split(":")
	return sum([0 if l[i] == "" else int(l[i]) * (60**(2-i)) for i in range(3)])
while 1:
	n = int(raw_input())
	if n == 0: break
	train = []
	for i in range(n):
		inputs = raw_input().split(" ")
		train.append((hms2s(inputs[0]),1))
		train.append((hms2s(inputs[1]),0))
	train.sort(key = lambda x : (x[0],x[1]))
	moving = 0
	max_move = 0
	for t in train:
		if t[1]:
			moving += 1
			max_move = max(moving, max_move)
		else:
			moving -= 1
	print max_move 

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

namespace IO {
    #define gc getchar()
    template <typename T>
    inline void read(T& x) {
        x = 0; bool f = 1; char ch;
        for (ch = gc; ch < '0' || '9' < ch; ch = gc) if (ch == '-') f ^= 1;
        for (; '0' <= ch && ch <= '9'; ch = gc) x = (x << 3) + (x << 1) + (ch ^ 48);
        x = f ? x : -x;
    }
    #undef gc
}

typedef long long ll;

const int MAXN = 2e5 + 10;

int n, arr[MAXN];
ll ans;

int main() {
    IO::read(n);
    rep(i, 1, n) IO::read(arr[i]);
    sort(arr + 1, arr + n + 1), reverse(arr + 1, arr + n + 1);
    ans += arr[1];
    int cnt = 1, i = 2;
    while (cnt <= n - 1) {
        if (cnt == n - 1) break;
        ans += 1ll * min(2, n - 1 - cnt) * arr[i];
        i++, cnt += min(2, n - 1 - cnt);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 4544