akhauriyash/Code-Regression huggingface dataset:
N = int(input())


def fac(n):
    att = []
    t = n
    for i in range(2, int(-(-n ** 0.5 // 1) + 1)):
        c = 0
        while (t % i == 0):
            c += 1
            t //= i
        if c:
            att += [[i, c]]
    if t != 1:
        att += [[t, 1]]
    if att == []:
        att += [[n, 1]]
    return att


MOD = 10 ** 9 + 7
t = 1
memo = {}
for i in range(2, N + 1):
    fl = fac(i)
    for f in fl:
        if f[0] in memo:
            memo[f[0]] += f[1]
        else:
            memo[f[0]] = f[1]
for m in memo:
    t = (t * (memo[m] + 1)) % MOD
t %= MOD
print(t)


Measured memory_bytes: 40560
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n,l; cin>>n>>l;
    vector<string>v(n);
    rep(i,n)cin>>v[i]; sort(all(v));
    rep(i,n)cout<<v[i]; cout<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MOD 1000000007
 
using namespace std;
 
bool cmpf(const pair<lli, lli> left, const pair<lli, lli> right) {
  	return left.first< right.first;
}
bool cmps(const pair<lli, lli> left, const pair<lli, lli> right) {
  	return left.second < right.second;
}
 
void dfs(lli ed, lli num, vector<map<lli,lli>>& vec){
    lli n=1;
    for(auto e: vec[num]){
        if(n == ed)n++;
        if(e.second != -1)continue;
        vec[num][e.first] = n;
        vec[e.first][num] = n;   
        dfs(n, e.first, vec);
        n++;
    }
}
 
lli gcd(lli a, lli b){
    if(a < b)return gcd(b, a);
    lli temp;
    while((temp = a%b)){
        a=b;
        b=temp;
    }
    return b;
}

struct nCr{
  vector<lli> f, rf;
  lli count=0;
  nCr(lli num): f(num), rf(num){
      count = num;
      f[0] = 1;
      rep1(i, num) f[i] = (f[i - 1] * i) % MOD;
      rep0(i, num+1) rf[i] = inv(f[i]);
  }
    
  lli inv(lli x) {
      lli res = 1;
      lli k = MOD - 2;
      lli y = x;
      while (k) {
          if (k & 1) res = (res * y) % MOD;
          y = (y * y) % MOD;
          k /= 2;
      }
      return res;
  }
  lli C(lli n, lli k) {
      lli a = f[n];
      lli b = rf[n-k];
      lli c = rf[k];
   
      lli bc = (b * c) % MOD;
   
      return (a * bc) % MOD;
  }
};

struct UF{
    vector<int> par,size;

    UF(int N) : par(N), size(N, 1){
        rep0(i,N)par[i] = i;
    }

    int root(int x){
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] = ry;
        size[ry] += size[rx];
    }

    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int getSize(int x){
        return size[root(x)];
    }
};
int main(){
  int N, M, K;

  cin >> N >> M >> K;
  UF uf(N+1);
  vector<pair<int,int>> vec;
  rep0(i,M){
    int a,b;
    cin >> a >>b;
    vec.emplace_back(a,b);
    uf.unite(a,b);
  }
  vector<lli> ans(N+1);
  rep1(i,N) {
    ans[i]= uf.getSize(i)-1;
  }
  for(auto e:vec){
    ans[e.first]--;
    ans[e.second]--;
  }
  rep1(i,K){
    int c,d;
    cin >> c >> d;
    if(uf.same(c,d)){
      ans[c]--;
      ans[d]--;
    }
  }

  rep1(i,N)cout << ans[i] << ' ';
}


Measured memory_bytes: 3700
// clang++ -std=c++14 -stdlib=libc++ -O2 ./*.cpp

#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <numeric>
// #include <bits/stdc++.h>
using namespace std;

#define size_t int
typedef long long ll;
// #define int long long
typedef vector<int> VI;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define debug(x) cerr << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug1(i, x) cerr << "(" << (i) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug2(i, j, x) cerr << "(" << (i) << ", " << (j) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
template <typename T> class vec2d : public vector<vector<T>> {
public:
    vec2d(int H, int W): vector<vector<T>> (H, vector<T>(W)) {
    }
};
template <typename T> istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template <typename T> ostream& operator << (ostream& os, vector<T>& vec){
  REP(i, vec.size()) {
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0);
        // cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

signed main(signed argc, char **argv) {
  int N;
  cin >> N;
  char S[N + 1];
  cin >> S;
  int mode = -1;
  int ans = 0;
  int s = 0;
  int d = 0;
  VI ss;
  VI dd;
  ss.reserve(N);
  dd.reserve(N);
  for (size_t i = 0; i < N; i++) {
    if (mode == 0) {
      if (S[i] == '#') {
        s++;
      } else {
        mode = 1;
        d++;
        if (i == N - 1) {
          ans += (s > d ? d : s);
          ss.push_back(s);
          dd.push_back(d);
          // debug1(i, s > d ? d : s);
        }
      }
    } else if (mode == 1) {
      if (S[i] == '#') {
        ans += (s > d ? d : s);
        ss.push_back(s);
        dd.push_back(d);
        // debug1(i, s > d ? d : s);
        s = 1;
        d = 0;
        mode = 0;
      } else {
        d++;
        if (i == N - 1) {
          ans += (s > d ? d : s);
          ss.push_back(s);
          dd.push_back(d);
          // debug1(i, s > d ? d : s);
        }
      }
    } else {
      if (S[i] == '#') {
        s++;
        mode = 0;
      }
    }
  }
  // debug(ss);
  // debug(dd);
  int sums = accumulate(ss.begin(), ss.end(), 0);
  // int sumd = accumulate(dd.begin(), dd.end(), 0);
  int min = sums;
  // cout << ans << endl;
  for (size_t i = ss.size() - 1; i >= 0; i--) {
    sums -= ss[i];
    sums += dd[i];
    // debug1(i, sums);
    if (min > sums) {
      min = sums;
    }
  }
  // cout << (sums < sumd ? sums : sumd) << endl;
  cout << min << endl;
  return 0;
}


Measured memory_bytes: 1280
import itertools


d, g = [int(i) for i in input().split()]
pc = [[int(i) for i in input().split()] for _ in range(d)]

ans = float("inf")
for bit in itertools.product((0, 1), repeat=d):
    score = 0
    solve = 0
    rest = set(range(d))

    for i in range(d):
        if bit[i] == 1:
            score += pc[i][0] * (i+1) * 100 + pc[i][1]
            solve += pc[i][0]
            rest.discard(i)

    if score < g:
        problem = max(rest)
        needs = -((-(g - score)) // ((problem+1)*100))
        n = min(pc[problem][0] - 1, needs)
        score += n * (problem+1) * 100
        solve += n
    if score >= g:
        ans = min(ans, solve)
print(ans)


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

using namespace std;
main(){
	char str[20];
	int len=0;
	int i;
	scanf("%s",str);

	len=0;
	while(str[len] != '\0') {
	len++;
	}

	for(i=len-1;i>=0;i--) {
	printf("%c",str[i]);
	}
	printf("\n");
}


Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;


int main() {
	int H, W, D; cin >> H >> W >> D;
	vector<pair<int, int>> pos(H*W + 2);
	vector<int> dp(H*W + 2, 0);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			int a; cin >> a;
			pos[a] = { i, j };
		}
	}

	for (int i = 0; i < D; i++) {
		int t = i;
		while (t + D <= H*W) {
			t += D;
			dp[t] = dp[t - D] + abs(pos[t].first - pos[t - D].first) + abs(pos[t].second - pos[t - D].second);
		}
	}
	int Q; cin >> Q;
	for (int i = 0; i < Q; i++) {
		int l, r; cin >> l >> r;
		cout << dp[r] - dp[l] << endl;
	}
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>

int main() {
  int N, P;
  std::cin >> N >> P;
  std::string S;
  std::cin >> S;

  std::vector<int> m(N + 1, -1); // m[i] = S[i, N) % P
  m[N] = 0;
  int pow = 1;
  for (int i = N; i > 0; --i) {
    pow = pow * 10 % P;
    m[i - 1] = (m[i] + pow * (S[i - 1] - '0')) % P;
  }

  if (P == 2 || P == 5) {
    long long res = 0;
    for (int r = 1; r <= N; ++r) {
      if ((S[r - 1] - '0') % P == 0)
        res += r;
    }
    std::cout << res << std::endl;
    return 0;
  }

  std::vector<long long> count(P, 0);
  for (int i = 0; i < N + 1; ++i)
    count[m[i]] += 1;

  long long res = 0;
  for (int p = 0; p < P; ++p) {
    if (count[p] < 1)
      continue;
    res += count[p] * (count[p] - 1) / 2;
  }
  std::cout << res << std::endl;
}


Measured memory_bytes: 1412
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define gc getchar
#define pc putchar
#define cs const

inline
ll getint(){
    re ll num;
    re char c;
    re bool f=0;
    while(!isdigit(c=gc()))f^=c=='-';num=c^48;
    while(isdigit(c=gc()))num=(num<<1)+(num<<3)+(c^48);
    return f?-num:num;
}

inline
void outint(ll a){
	static char ch[23];
	if(a==0)pc('0');
	while(a)ch[++ch[0]]=a-a/10*10,a/10;
	while(ch[0])pc(ch[ch[0]--]^48);
}

int n;
cs int N=100005;
int a[N];
int cnt[2][N];
ll sum[2];
int maxn[2],num[2],submaxn[2],subnum[2];


signed main(){
	n=getint();
	for(int re i=2;i<=n+1;++i){
		a[i]=getint();
		++cnt[i&1][a[i]];
		if(maxn[i&1]<cnt[i&1][a[i]]){
			if(num[i&1]==a[i]){
				maxn[i&1]=cnt[i&1][a[i]];
			}
			else {
				subnum[i&1]=num[i&1];
				submaxn[i&1]=maxn[i&1];
				maxn[i&1]=cnt[i&1][a[i]];
				num[i&1]=a[i];
			}
		}
		else if(cnt[i&1][a[i]]==maxn[i]&&num[i&1]!=a[i]){
			submaxn[i&1]=cnt[i&1][a[i]];
			subnum[i&1]=a[i];
		}
		else if(cnt[i&1][a[i]]>submaxn[i&1]){
			submaxn[i&1]=cnt[i&1][a[i]];
			subnum[i&1]=a[i];
		}
	}
	int ans;
	if(num[0]!=num[1])ans=n-maxn[0]-maxn[1];
	else ans=n-max(maxn[0]+submaxn[1],maxn[1]+submaxn[0]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1408
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[] a = new int[N+1];
		for(int i=1;i<=N;i++) {
			a[i] = sc.nextInt();
		}

		boolean[] visited = new boolean[N+1];


		sc.close();

		int p=1;
		int ans = 0;
		while(true) {
			if(p==2) {
				break;
			}

			if(visited[a[p]]) {
				ans = -1;
				break;
			}
			p = a[p];
			visited[p] = true;
			ans++;

		}
		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


Measured memory_bytes: 53020
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<functional>
#include<cassert>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<vint> vvint;

int main(void) {
	int a, b;
	cin >> a >> b;
	if (a < 10 && b < 10) {
		cout << a * b << endl;
	}
	else {
		cout << -1;
	}
}


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

int main() {
    string S;
    cin >> S;
    int ans=1;
    string mae="AAA";
    while (S.size()!=0){
        if(S.substr(0,1)!=mae){
            mae=S.substr(0,1);
            S=S.substr(1);
            ans++;
        }else{
            if(S.size()==1){
                ans--;
                break;
            }else{
                mae=S.substr(0,2);
                S=S.substr(2);
                ans++;
            }
        }
    }
    if(S.size()==0){
        ans--;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 772
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n, k;
    std::cin >> n >> k;

    int c = (n - 1) * (n - 2) / 2;
    if (k > c) {
        std::cout << -1 << std::endl;
        return 0;
    }

    std::cout << n - 1 + c - k << std::endl;
    auto out = [](int i, int j) { std::cout << i << " " << j << std::endl; };
    for (int i = 2; i <= n; i++) out(1, i);
    int r = c - k, v = 2;
    while (r > 0) {
        int j = std::min(r, n - v);
        for (int i = v + 1; i <= std::min(v + j, n); i++) out(v, i);
        r -= j;
        v++;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int k,a,b;
    scanf("%d", &k);
    scanf("%d %d", &a, &b);
    for(int i = a; i <= b; i++){
        if(i %k == 0){
            puts("OK");
            return 0;
        }
    }
    puts("NG");
    
    return 0;
}

Measured memory_bytes: 1656
import scala.io.StdIn

object Main extends App {
  val n = StdIn.readLine
  val ans = StdIn.readLine.split(" ").map(_.toInt)
    .sortWith( _ > _ ).toVector.par
    .zipWithIndex.map(e => if ((e._2 & 1) == 0) e._1 else -e._1)
    .sum

  println(ans)
}


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

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

    if (a > b) {
        n = b;
        b = a;
        a = n;
    }

    if (b > c) {
        n = c;
        c = b;
        b = n;
    }

    if (a > b) {
        n = b;
        b = a;
        a = n;
    }

    cout << a << " " << b << " " << c << endl;

    return 0;
}


Measured memory_bytes: 3084
import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]

N = int(input())
#X, Y = map(int,input().split())
A = list(map(int,input().split()))

ans = [0 for _ in range(N)]

for a in A:
    ans[a-1] += 1

print(*ans, sep='\n')

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

int n;
vector<int> a;

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

int l(int i) { // a[1]...a[i-1]のgcd
    if (i == 1) return  a[i];
    return gcd(l(i-1), a[i-1]);
}

int r(int i) { // a[i+1]...a[n]のgcd
    if (i == n-1) return  a[i+1];
    return gcd(a[i+1], r(i+1));
}

int m(int i) { // a[1]...a[n]のうちa[i]を除いた部分のgcd
    if (i == 1) return r(i);
    if (i == n) return l(i);
    return gcd(l(i), r(i));
}

int main() {
    cin >> n;
    a.resize(n+1);
    rep(i, n) {
        // if (i == 0) continue;
        cin >> a[i];
    }
    int max_v = 0;

    vector<int> l(n+1), r(n+1), m(n+1);
    // for (int i = 2; i <= n; i++) {
    //     l[i] = gcd(l[i-1], a[i-1]);
    // }
    // for (int i = n-1; i >= 1; i--) {
    //     r[i] = gcd(a[i+1], r[i+1]);
    // }
    rep(i, n) {
        int j = n-i+1;
        if (i == 1) {
            l[i] = 0;
            r[j] = 0;
        } else {
            l[i] = gcd(l[i-1], a[i-1]);
            r[j] = gcd(a[j+1], r[j+1]);
        }        
    }
    rep(i, n) {
        // if (i == 1) m[i] = r[i];
        // else if (i == n) m[i] = l[i];
        // else m[i] = gcd(l[i], r[i]);
        m[i] = gcd(l[i], r[i]);
        max_v = max(m[i], max_v);
    }
    // for (int i = 1; i <= n; i++) {
    //     // max_v = max(m(i+1), max_v);
    //     // max_v = max(m[i], max_v);
    // }
    printf("%d\n", max_v);
}

Measured memory_bytes: 4768
# 参考: https://atcoder.jp/contests/abc077/submissions/5869524
N = gets.to_i
AS = gets.chomp.split.map(&:to_i).sort
BS = gets.chomp.split.map(&:to_i).sort
CS = gets.chomp.split.map(&:to_i).sort

ans = 0
BS.each do |b|
  i = AS.bsearch_index { |a| a >= b } || N
  k = N - (CS.bsearch_index { |c| c > b } || N)
  ans += i * k
end
p ans

Measured memory_bytes: 26804
#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
int n,m,x;
map<int,int>mp;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",&x),++mp[x];
	scanf("%d",&m);
	for (int i=1;i<=m;++i){
		scanf("%d",&x);
		if (!mp[x]) return puts("NO"),0;else --mp[x];
	} 
	puts("YES");
	return 0;
}

Measured memory_bytes: 9600
x = int(input())
y = int(input())
z = int(input())
s = int(input())
a = 0
for i in range(x+1):
    for j in range(y+1):
        for k in range(z+1):
            if 500*i+100*j+50*k == s:
                a = a+1
print(a)


Measured memory_bytes: 3060
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class myon
{
    public static void Main(string[] args)
    {
        var myon = new myon();
    }

    public myon()
    {
        string[] input = Console.ReadLine().Split(' ');

        int[] intin = new int[3];
        for (int i = 0; i < 3; i++)
        {
            intin[i] = int.Parse(input[i]);
        }

        if (intin[0] < intin[1] && intin[0] < intin[2] && intin[1] > intin[2]) Console.WriteLine("Yes");
        else if (intin[1] < intin[0] && intin[1] < intin[2] && intin[0] > intin[2]) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
const long long llINF = 9223372036854775807;
const int INF = 2147483647;
const int maxn = 2e5 + 7;
const int maxm = 1e6 + 7;
const int ALP = 26;
const long long mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-8;

int n,k;
int r,s,p;
char T[maxn];
int val[maxn];
bool vis[maxn];
int ans;
int main()
{
	scanf("%d%d",&n,&k);
	scanf("%d%d%d",&r,&s,&p);
	scanf("%s",T+1);
	for(int i=1;i<=n;i++)
	{
		if(T[i]=='r')
			val[i]=p;
		if(T[i]=='s')
			val[i]=r;
		if(T[i]=='p')
			val[i]=s;
	}

	for(int i=1;i<=n;i++)
	{
		if(i<=k)
		{
			ans+=val[i];
			vis[i]=1;
		}
		else
		{
			if(T[i]!=T[i-k])
			{
				ans+=val[i];
				vis[i]=1;
			}
			else if(!vis[i-k])
			{
				ans+=val[i];
				vis[i]=1;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main(int, char**)
{
	int N;
	cin >> N;
	vector<int> A(N), B(N), C(N - 1);
	for (int i = 0; i < N; ++i)
	{
		int a;
		cin >> a;
		A[i] = a - 1;
	}
	for (int i = 0; i < N; ++i)
	{
		cin >> B[i];
	}
	for (int i = 0; i < N - 1; ++i)
	{
		cin >> C[i];
	}
	long total = 0;
	total += B[A[0]];
	for (int i = 1; i < N; ++i)
	{
		total += B[A[i]];
		if (A[i] == A[i - 1] + 1)
		{
			total += C[A[i - 1]];
		}
	}
	cout << total << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;

inline long long min(long long a, long long b)
{
	return a < b? a: b;
}

int main(int argc, char** argv)
{
	long long n, a, b;
	scanf("%lld%lld%lld", &n, &a, &b);
	printf("%lld\n", n / (a + b) * a + min(n % (a + b), a));
	return 0;
}

Measured memory_bytes: 128
def LCM(x, y):
    set1 = set(range(x, x*y+1, x))
    set2 = set(range(y, x*y+1, y))
    set3 = set1&set2
    return min(set3)
a, b = map(int, input().split())
print(LCM(a, b))

Measured memory_bytes: 20328
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
//#define int long long 
#define inf 1000000000
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111
	
	int dp[31][1<<20];
	int x[31][31];
	
	void solve(){

		FOR(i,0,31)FOR(i1,0,1<<20)dp[i][i1] = inf;
		FOR(i,0,31)FOR(i1,0,31)x[i][i1] = inf;
		ini(n);
		ini(n1);
		FOR(i,0,n1){
			ini(x1,tmp1,tmp);
			x[x1][tmp1] = tmp;
		}
		dp[0][1] = 0;
		FOR(i,0,1<<n){
			FOR(i1,0,n){
				if(dp[i1][i]!=inf){
					//out("start:",i1,"to",i);
					FOR(i2,0,n){
						if(!((1<<i2)&i)){
							dp[i2][i+(1<<i2)] = min(dp[i2][i+(1<<i2)],dp[i1][i]+x[i1][i2]);
							//out("in: ",i1,"i2: ",i2,"kore",dp[i2][i+(1<<i2)]);
						}
					}
					//out("end:",i1,"to",i);
				}
			}
		}
		int rick  = inf;
		FOR(i,0,n){
			rick  = min(rick,dp[i][(1<<n)-1]+x[i][0]);
		}
		if(rick == inf)rick = -1;
		out(rick);
	
		
		

		


		
		
	}























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}



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

using namespace std;

const int maxn=12;

int l[maxn][maxn];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, d;
	cin >> n >> d;
	for(int i=0; i<n; i++){
		for(int j=0; j<d; j++){
			cin >> l[i][j];
		}
	}
	int dist;
	int br=0;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			dist=0;
			for(int k=0; k<d; k++){
				dist+=(l[i][k]-l[j][k])*(l[i][k]-l[j][k]);
			}
			if((double)sqrt((double)dist)==(int)sqrt(dist)){
				br++;
			}
		}
	}
	cout << br << '\n';
	return 0;
}

Measured memory_bytes: 256
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,m = mi() 
alis = li()
for i in range(n):
    alis[i] //= 2

ima = alis[0] & -alis[0]
alis[0] //= ima
for i in range(1,n):
    tmp = alis[i] & -alis[i]
    if ima != tmp:
        print(0)
        exit()
    else:
        alis[i] //=ima

tmp = ima
#a>b
def gcd(a,b):
    if a < b:
        a,b = b,a
    while b!=0:
        a,b=b,a%b
    return a
#a>b
def lcm(a,b):
    return a*b // gcd(a,b)
ima = 1
for i in range(n):
    ima = lcm(alis[i],ima)
    if ima*tmp > m:
        print(0)
        exit()
ans = 0

tmm = m//(ima*tmp)
if tmm % 2 ==0:
    print(tmm//2)
else:
    print(tmm//2 +1)
   

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

int main(){
	vector<int> d(3);
	rep(i,3) cin >> d[i];
	sort(d.begin(),d.end());
	int ans = 0;
	if(d[0] % 2 != d[1] %2){
		ans++;
		d[0]++;
		d[2]++;
	}
	ans += d[2] - d[1] + (d[1] -d[0])/2;
	cout << ans << endl;
	return 0;
 }

Measured memory_bytes: 3608
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long int;

// to format a document: ctrl + K -> ctrl + D

int main() {
    int A, P;
    cin >> A >> P;
    cout << (A * 3 + P) / 2 << endl;

    return 0;
}


Measured memory_bytes: 768
s = input()

N = len(s)
if N == 2:
    if s[0] == s[1]:
        ans = ["1", "2"]
    else:
        ans = ["-1", "-1"]
else:
    ans = ["-1", "-1"]
    for i in range(N-2):
        if s[i] != s[i+1] and s[i+1] != s[i+2] and s[i+2] != s[i]:
            continue
        else:
            ans = [str(i+1), str(i+3)]
            break
            
print(" ".join(ans))

Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007

using namespace std;

int main(void) {
	int n;
	bool flag = false;
	long long int total = 0;
	int count = 0;

	cin >> n;

	vector<int> a(n * 3);
	FOR(i, 0, 3*n-1) {
		cin >> a[i];
	}
	sort(a.begin(),a.end());

	RFOR(i, 3*n-1, 1) {
		if (count >= n) {
			break;
		}
		if (flag == false) {
			flag = true;
		}
		else {
			flag = false;
			count++;
			total += a[i];
		}
	}
	cout << total << endl;
	return 0;
}

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

using namespace std;

int main(){

	int n , c = 0 , ans = 0;
	int count = 0 , cou = 0;
	string name , prob , newname;
	cin >> n;
	cin >> name;

	for(int i = 0; i < n; i++){
		cin >> prob;
		int flag = 0;
		for(int e = 0; e < prob.size(); e++){
			c = 0;
			
			for(int j = 0; j < prob.size(); j++){
				if(flag == 1) break;
					c++;
					newname = "";
					count = e;
				for(int k = 0; k < prob.size(); k++){
					newname += prob[count];
					count += c;
					if(newname.size() == name.size() || prob.size() < count){
						if(newname == name){
							ans++;
							flag = 1;
						}
						break;
					}
				}
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<pi> vpi;

#define debugone(x) cerr << #x << " " << x << endl;
#define debugtwo(x) cerr << #x << "-------------" << endl;for(auto &it: x) cerr << it << " ";cerr << endl;
#define debugthree(x, i, j) cerr << #x << "------------" << endl;cerr << "from " << i << " to " << j << endl;for(int k=i; k<=j; k++) cerr << x[k] << " ";cout << endl;

const int mod = (int)1e9 + 7;

int n, k;
int value[51];

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	
	cin >> n >> k;

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


	int maxi = (-1) * mod;

	for(int noOfOperations = 0; noOfOperations <= k; noOfOperations++){
		for(int take = 0; take <= noOfOperations; take++){
			if(take > n) break;

			for(int leftTake = 0; leftTake <= take; leftTake++){
				vector<int> v;


				int rightTake = take - leftTake;
				for(int i = 0; i < leftTake; i++){
					v.push_back(value[i]);
				}

				for(int i = 0; i < rightTake; i++){
					v.push_back(value[n - 1 - i]);
				}
				sort(v.rbegin(), v.rend());
				int give = noOfOperations - take;
				if(give > take) break;

				int tempSum = 0;
				for(int i = 0; i < (int)v.size(); i++){
					tempSum += v[i];
				}

				for(int i = 0; i < give; i++){
					tempSum -= (v[(int)v.size() - 1 - i]);
				}

				if(maxi < tempSum){
					maxi = tempSum;
					// debugone(tempSum);
					// debugone(leftTake);
					// debugone(rightTake);
					// debugone(give);

					// cerr << "\n\n";
				}
			}	
			
		}
	}


	cout << maxi << endl;
}	

Measured memory_bytes: 256
<?php

$map = [];
for($i = 0; $i < 3; $i++) {
    $map = array_merge($map, explode(" ", fgets(STDIN)));
}

function check_col($map) {
    for ($i = 0; $i < 3; $i++) {
        if ($map[$i * 3] < 0 && $map[$i * 3 + 1] < 0 && $map[$i * 3 + 2] < 0) {
            return true;
        }
    }
    return false;
}

function check_row($map) {
    for ($i = 0; $i < 3; $i++) {
        if ($map[$i] < 0 && $map[$i + 3] < 0 && $map[$i + 6] < 0) {
            return true;
        }
    }
    return false;
}

function check_cross($map) {
    if ($map[0] < 0 && $map[4] < 0 && $map[8] < 0) return true;
    if ($map[2] < 0 && $map[4] < 0 && $map[6] < 0) return true;
    return false;
}

$n = intval(fgets(STDIN));
for($i = 0; $i < $n; $i++) {
    $k = intval(fgets(STDIN));
    $idx = array_search($k, $map);
    if ($idx !== FALSE) {
        $map[$idx] = -1;
    }
}

echo check_col($map) || check_row($map) || check_cross($map) ? "Yes": "No";

Measured memory_bytes: 4856
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>

#define rep(i,n) for(int i=0; i < n; i++)
using ll =  long long;
using namespace std;


int main()
{
    int thp, tf, ahp, af;
    cin >> thp >> tf >> ahp >> af;
    
    while (thp > 0 && ahp > 0)
    {
        ahp -= tf;
        if (!ahp > 0) break;
        thp -= af;
    }
    if (ahp <= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStreamReader;
import java.util.ArrayList;
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;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        NotsoDiverse solver = new NotsoDiverse();
        solver.solve(1, in, out);
        out.close();
    }

    static class NotsoDiverse {
        int[] cnt = new int[200001];

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            for (int i = 0; i < N; i++) {
                cnt[in.nextInt()]++;
            }
            ArrayList<Integer> arr = new ArrayList<>();
            for (int i = 0; i < cnt.length; i++) {
                if (cnt[i] > 0) {
                    arr.add(cnt[i]);
                }
            }
            Collections.sort(arr);
            int ans = 0;
            for (int i = 0; i < arr.size() - K; i++) {
                ans += arr.get(i);
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



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

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

  cin >> n >> k;

  vector<int> h(n,0);

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

  sort(h.begin(), h.end());

  for(int i=0;i<n-k;i++) {
    ans += h[i];
    //    cout << h[i] << endl;
  }


  cout << ans << endl;

  return 0;
}


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

int gcd(int x, int y);

int main()
{
	//string cat;
	//cin >> cat;
	//for (int i = 0; i < 3; i++)
	//{
	//	if (cat[i] == '7')
	//	{
	//		cout << "Yes";
	//		exit(0);
	//	}
	//}
	//cout << "No";
	
	//long long num;
	//long long duck = 0;
	//cin >> num;
	//for (int i = 1; i <= num; i++)
	//{
	//	if (i % 3 == 0)continue;
	//	else if (i % 5 == 0)continue;
	//	duck += i;
	//}
	//cout << duck;

	int ans = 0;
	int dog;
	cin >> dog;
	for (int i = 1; i <= dog; i++)
	{
		for (int j = 1; j <= dog; j++) 
		{
			for (int k = 1; k <= dog; k++)
			{
				ans += gcd(i, gcd(j, k));
			}
		}
	}
	cout << ans;


	return 0;
}

int gcd(int x, int y)
{
	if (x%y == 0)
		return y;
	else
		return gcd(y, x%y);
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int n,k;
int mn[200001],mx[200001];
deque<int>qn,qx;
int a[200001];
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> k;k--;
	int ans=0;
	int st=0;
	int cnt=0;
	for(int i=1; i<=n ;i++){
		cin >> a[i];
		if(i!=1 && a[i]>a[i-1]) cnt++;
		else cnt=0;
		if(cnt>=k && st) ans++;
		else if(i>k+1 && a[qn.front()]>a[i-k-1] && a[qx.front()]<a[i]) ans++;
		if(cnt>=k) st=i;
		if(!qn.empty() && qn.front()==i-k) qn.pop_front();
		if(!qx.empty() && qx.front()==i-k) qx.pop_front();
		while(!qn.empty() && a[qn.back()]>a[i]) qn.pop_back();
		while(!qx.empty() && a[qx.back()]<a[i]) qx.pop_back();
		qn.push_back(i);qx.push_back(i);
	}
	cout << n-k-ans << endl;
}

Measured memory_bytes: 1920
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int a[9];
int main() {
	for(int i=0; i<6; i++) cin >> a[i];
	sort(a, a+5);
	cout << (a[4]-a[0]<=a[5] ? "Yay!" : ":(");
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int n;
signed main(){
    cin>>n;vector<int>v(n);
    for(int i=0;i<n;i++)cin>>v[i];
    sort(v.begin(),v.end());
    int ans = v[v.size()/2]-v[v.size()/2-1];
    cout<<ans<<endl;
}


Measured memory_bytes: 640
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    enum DayOfWeek
    {
        SUN,
        MON,
        TUE,
        WED,
        THU,
        FRI,
        SAT,
    }

    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var d = (int)Enum.Parse(typeof(DayOfWeek), s);
        Console.WriteLine(7 - d);
    }
}


Measured memory_bytes: 13396
#include<stdio.h>
 
#define INF 1000000
#define K 2000000
 
int n = 0;
int S[K];
 
void increase(int *S, int i, int key){
  int tmp;
 
  S[i] = key;
 
  while(i > 1 && S[i/2] < S[i]){
    tmp = S[i];
    S[i] = S[i/2];
    S[i/2] = tmp;
    i = i/2;
  }
}
 
void insert(int *S, int k){
  n += 1;
  S[n] = -INF;
  increase(S, n, k);
}
 
void maxHeapify(int *S, int i){
  int l, r, tmp, largest;
 
  l = 2*i;
  r = 2*i + 1;
 
  if(l <= n && S[l] > S[i]) largest = l;
  else largest = i;
 
  if(r <= n && S[r] > S[largest]) largest = r;
 
  if(largest != i){
    tmp = S[i];
    S[i] = S[largest];
    S[largest] = tmp;
    maxHeapify(S, largest);
  }
}
 
int extractMax(int *S){
  int max;
 
  max = S[1];
  S[1] = S[n];
  n--;
  maxHeapify(S, 1);
 
  return max;
}
 
int main(){
  int i=0, k, j, max[K];
  char chil[10];
 
  while(1){
    scanf("%s", chil);
 
    if(chil[0] == 'i'){
      scanf("%d", &k);
      insert(S, k);
    }
 
    else if(chil[1] == 'x'){
      max[i] = extractMax(S);
      i++;
    }
    else if(chil[1] == 'n') break;
  }
 
  for(j = 0; j < i; j++) printf("%d\n", max[j]);
 
  return 0;
}

Measured memory_bytes: 7188
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int m,n;
int x[110];

bool f(int c){
	int i,k=0,d=c;
	for(i=0;i<n;i++){
		d-=x[i];
		if(d<0){
			d=c-x[i];
			if(d<0)return false;
			k++;
		}
		if(k==m)return false;
	}
	return true;
}

int main() {
	while(cin>>m>>n,m){
		int i;
		for(i=0;i<n;i++)cin>>x[i];
		int a=1,b=1500000,c;
		while(a!=b){
			c=(a+b)/2;
			if(f(c)){
				b=c;
			}else{
				a=c+1;
			}
		}
		cout<<a<<endl;
	}
	return 0;
}

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

int main() {
  int H, W;
  scanf("%d%d", &H, &W);

  vector<vector<char>> grid(H + 2, vector<char>(W + 2, '0'));
  for (int i = 0; i < H + 2; i++) {
    for (int j = 0; j < W + 2; j++) {
      if (i == 0 || i == H + 1 || j == 0 || j == W + 1) {
        grid.at(i).at(j) = 'w';
      } else {
        char s;
        cin >> s;
        grid.at(i).at(j) = s;
      }
    }
  }
  int count = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (grid.at(i).at(j) == '#') {
        if (grid.at(i).at(j - 1) == '#') count++;
        if (grid.at(i).at(j + 1) == '#') count++;
        if (grid.at(i - 1).at(j) == '#') count++;
        if (grid.at(i + 1).at(j) == '#') count++;
        
        if (count == 0) {
          printf("No");
          return 0;
        } else {
          count = 0;
        }
      }
    }
  }

  printf("Yes");
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x1 = sc.nextInt();
		int y1 = sc.nextInt();
		int x2 = sc.nextInt();
		int y2 = sc.nextInt();
		int xdis = x2-x1;
		int ydis = y2-y1;
		System.out.println((x2-ydis)+ " " +(y2+xdis)+ " " +(x1-ydis)+ " " +(y1+xdis));

	}
}




Measured memory_bytes: 40028
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int tot=0,p[N];
bool vis[N];
int main()
{
    for(int i=2;i<N;i++)
        if(!vis[i])
    {
        p[++tot]=i;
        for(int j=i;j<N;j+=i)
            vis[j]=true;
    }
    int x;scanf("%d",&x);
    int ans=lower_bound(p+1,p+1+tot,x)-p;
    ans=p[ans];
    printf("%d\n",ans);
}


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

int main() {
  string s;
  cin >> s;
  stack<char> t;
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') {
      if (!t.empty() && (t.top() == '1')) {
        t.pop();
        ans += 2;
      }
      else {
        t.push(s[i]);
      }
    }
    else {
      if (!t.empty() && (t.top() == '0')) {
        t.pop();
        ans += 2;
      }
      else {
        t.push(s[i]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <string>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;

long long int L = 1000000007;

int main()
{
  long long int n,a,b,ans;
  cin >> n >> a >> b;
  ans = 0;
  long long int bef;
  cin >> bef;
  for(long long int i=2;i<= n;i++)
  {
    long long int tmp;
    cin >> tmp;
    if( (tmp - bef)*a < b )
    {
      ans += (tmp - bef)*a;
    }
    else
    {
      ans += b;
    }
    bef = tmp;
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k=LI()
  ans=0
  l=LI()

  for x in l:
    if x>=k:
      ans+=1
  return ans

# main()
print(main())


Measured memory_bytes: 14376
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
using namespace std;

int syc(long i,long Min,long Max){
	if(Min <= i && i <= Max){
		return 1;
	}else{
		exit(1);
		//return 0;
	}
}

int main(){
	int n;
	cin >> n;
	syc(n,3,50);
	char s[n];
	for(int i=0;i<n;i++){
		cin >> s[i];
	}
	
	int count = 0;
	for(int i=2;i<n;i++){
		if(s[i-2] == 'A' && s[i-1] == 'B' && s[i] == 'C'){
			count++;
		}
	}
	cout << count << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    int mai = 0;
    for(int i=0;i<n;i++){
        cin >> a.at(i);
        if(a.at(i)<0)mai++;
    }
    ll ans = 0;
    if(mai%2==0){
        for(int i=0;i<n;i++){
            ans+=abs(a.at(i));
        }
    }
    else{
        for(int i=0;i<n;i++){
            a.at(i)=abs(a.at(i));
        }
        sort(a.begin(),a.end());
        ans+=a.at(0)*-1;
        for(int i=1;i<n;i++){
            ans+=a.at(i);
        }
    }
    cout << ans << endl;
}
    



Measured memory_bytes: 640
#include <iostream>
#include <limits.h>
using namespace std;

int main() {
	int n, k, x[100010];
  	long long min = 300000200;
	cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> x[i];
	for (int i = 1; i <= n - k + 1; i++) {
	    if (x[i] <= 0 && x[i + k - 1] >= 0) {
	        if (min > - 2 * x[i] + x[i + k - 1]) min = - 2 * x[i] + x[i + k - 1];
	        if (min > 2 * x[i + k - 1] - x[i]) min = 2 * x[i + k - 1] - x[i];
	    }
	    else if (x[i] <= 0) {
	        if (min > - x[i]) min = - x[i];
	    }
	    else {
	        if (min > x[i + k - 1]) min = x[i + k - 1];
	    }
	}
	cout << min;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll  dp[207][207];

void warshall_floyd(int n) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < n; k++)
        dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k]);
}

ll func(vector<ll> X){
    ll dis=0;
    rep(i,X.size()-1){
        dis+=dp[X[i]][X[i+1]];
    }
    return dis;
}

int main(){
    ll N,M,R,A,B,L;
    vector<ll> r;
    cin >> N >> M >> R;
    rep(i,R){
        ll K;
        cin >> K;
        r.pb(K-1);
    }
    rep(i,N){
        rep(j,N){
            if(i==j){
                dp[i][j]=0;
            }
            else{
                dp[i][j]=INF;
            }
        }
    }
    rep(i,M){
        cin >> A >> B >> L;
        dp[A-1][B-1]=L;
        dp[B-1][A-1]=L;
    }

    warshall_floyd(N);

    ll  T = INF;
    sort(ALL(r));
    do{ 
        T =  min(T,func(r));
    } while (next_permutation(r.begin(), r.end()));
    cout << T << endl;
}

Measured memory_bytes: 512
s = input()
k = int(input())

# 1種類の文字の連続の場合
if len(set(s)) == 1:
    print(len(s) * k // 2)

else:
    count_l = []
    before_mozi = ''

    for mozi in s:
        if before_mozi == mozi:
            count_l[-1] += 1
        else:
            count_l.append(1)
        before_mozi = mozi

    # 先頭と末端の文字が同じ場合
    if s[0] == s[-1]:
        result = sum([x//2 for x in count_l[1:-1]]) * k + count_l[0]//2 + count_l[-1]//2 + (count_l[0] + count_l[-1])//2 * (k-1)

    else:
        result = sum([x//2 for x in count_l]) * k

    print(result)

Measured memory_bytes: 3188