akhauriyash/Code-Regression huggingface dataset:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
   h = int(input())
   w = int(input())
   n = int(input())
   p = max(h,w)
   if n % p == 0:
       print(n//p)
   else:
       print(n//p+1)

if __name__ == "__main__":
    main() #endline===============================================
    

Measured memory_bytes: 5816
// Add compile option "-std=c++11" for C++11 compile.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

// Macro
#define rep(i, N) for(int i=0; i<(int)N; i++)
#define rrep(i, N) for(int i=(int)N-1; i>=0; i--)

// Type
template <typename T> using P = pair<T, T>;
using ll = long long;
using ull = unsigned long long;

// Constants
const ll INF = 1e18;
const ll MOD = 1000000007;

int main() {
  string s;
  cin >> s;

  int _max = 0;
  int len = 0;
  rep(i, s.length()) {
    if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
      len++;
      _max = max(_max, len);
    } else {
      len = 0;
    }
  }

  cout << _max << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict, deque, Counter
import math
 
# import copy
from bisect import bisect_left, bisect_right
# import heapq
 
# sys.setrecursionlimit(1000000)
 
# input aliases
input = sys.stdin.readline
 
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
 
INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def getmoji(k):
    return chr(ord("a") + k)

def main():
    n, k = getList()
    s = getS()

    ko, fuko = 0, 0
    for i, j in zip(s, s[1:]):
        if i == j:
            ko += 1
        else:
            fuko += 1
    print(ko + min(k*2, fuko))


if __name__ == "__main__":
    main()
   

Measured memory_bytes: 73952
#include<bits/stdc++.h>
using namespace std;
#define N 200000
#define mp make_pair
int n;
pair<int, int> a[N];

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        int tmp; scanf("%d", &tmp);
        a[i] = mp(tmp, i);
    }
    sort(a + 1, a + 1 + n);
    for(int i = 1; i <= n; i++) printf("%d ", a[i].second);
}

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


int main()
{
string s ; cin >> s;
int n = s.size();
deque <char> q;
for (int i= 0;  i < n ; i++)q.push_back(s[i]);
int rev=0;
int w ;cin >> w;
while (w--){
    int t ;cin >> t ;
    if (t==1)rev++;
    else {
        int f ; char c; cin >> f>>c;
        if (f==1)
            {if (rev%2==0)
                q.push_front(c);
                else
                    q.push_back(c);
            }
            else {
                if (rev%2==0)
                    q.push_back(c);
                else
                    q.push_front(c);
            }

    }
}

if (rev%2==0)
    for (auto it:q)cout << it ;
else {
    reverse(q.begin(),q.end());
    for (auto it:q)cout <<it;
}



}


Measured memory_bytes: 896
import java.util.*;
public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int n = sc.nextInt();
        final int k = sc.nextInt();
        final String s = sc.next();
        System.out.println(s.substring(0, k - 1) + 
            s.substring(k - 1, k).toLowerCase() + 
            s.substring(k, s.length()));
    }
}


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

int main() {
	// your code goes here
	int n; cin>>n;
	vector<int> a(n + 1, 0);
	for(int i = 0; i < n - 1; i++){
		int x; cin>>x;
		++a[x];
	}
	for(int i =1; i <= n; i++){
		cout<<a[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 4048
class abc_164:
    
    def __init__(self):
        pass
    
    def A(self):
        sw=list(map(int,input().split()))
        print("unsafe") if sw[1]>=sw[0] else print("safe")
        pass
    
    def B(self):
        pass
        
    def C(self):
        pass
    
    def D(self):
        pass
    
    def E(self):
        pass
    
    def F(self):
        pass
    
    
if __name__=='__main__':
    obj=abc_164()
    obj.A()

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

int main() {
  int n;
  int area[21][21];
  vector<string> texts;
  while (cin >> n && n) {
    rep(i, 21) {
      rep(j, 21) { area[i][j] = 0; }
    }
    rep(i, n) {
      int point[2];
      cin >> point[0] >> point[1];
      area[point[0]][point[1]] = 1;
    };
    int op, pos[] = {10, 10};
    cin >> op;
    rep(i, op) {
      string arrow;
      int dis;
      cin >> arrow >> dis;
      if (area[pos[0]][pos[1]] == 1) area[pos[0]][pos[1]] = 0;
      if (arrow == "N") {
        rep(j, dis) {
          pos[1]++;
          // cout << "pos: " << pos[0] << " " << pos[1] << endl;
          if (area[pos[0]][pos[1]] == 1) area[pos[0]][pos[1]] = 0;
        }
      }
      if (arrow == "S") {
        rep(j, dis) {
          pos[1]--;
          if (area[pos[0]][pos[1]] == 1) area[pos[0]][pos[1]] = 0;
        }
      }
      if (arrow == "E") {
        rep(j, dis) {
          pos[0]++;
          if (area[pos[0]][pos[1]] == 1) area[pos[0]][pos[1]] = 0;
        }
      }
      if (arrow == "W") {
        rep(j, dis) {
          pos[0]--;
          if (area[pos[0]][pos[1]] == 1) area[pos[0]][pos[1]] = 0;
        }
      }
    }
    string text = "Yes";
    rep(i, 21) {
      rep(j, 21) {
        if (area[i][j] == 1) text = "No";
      }
    }
    texts.push_back(text);
  }
  rep(i, texts.size()) { cout << texts[i] << endl; }
  return 0;
}



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

int main(){
  int N,M;
  cin>>N>>M;
  vector<string> A(N),B(M);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  for(int i=0;i<M;i++){
    cin>>B.at(i);
  }
  
  bool flag=false;
  for(int i=0;i<N-M+1;i++){
    for(int j=0;j<N-M+1;j++){
      flag=true;
      for(int k=0;k<M;k++){
        for(int l=0;l<M;l++){
          if(A.at(i+k).at(j+l)!=B.at(k).at(l)){
            flag=false;
            break;
          }
        }
        if(!flag){
          break;
        }
      }
      if(flag){
        break;
      }
    }
    if(flag){
      break;
    }
  }
  if(flag){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define log(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  string s;cin>>s;
  s[1] = (s[1] == 'B')? 'R' : 'B';
  print(s);
  return 0; 
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "../../../debug_print.hpp"
#else
#define debug(...)
#endif
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr long double PI = 3.14159265358979323846264338327950288419716939937510;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    int N, K;
    scan(K, N);
    debug("hello");
    if (500 * K < N) {
        print("No");
    } else {
        print("Yes");
    }

    return 0;
}

Measured memory_bytes: 384
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(1,n):
    if(a[i-1]+a[i]>x):
        if(a[i-1] > x):
            eat = (a[i-1] - x) + a[i]
            a[i] -= a[i]
            a[i-1] -= a[i-1] - x
            ans += eat
        else:
            eat = (a[i-1] + a[i]) - x
            a[i] -= eat
            ans += eat
print(ans)

Measured memory_bytes: 14592
#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(){
   int n, m;
   cin >> n >> m;
   vector<int> box;
   rep(i,n){
      int a;
      cin >> a;
      box.push_back(a);
   }
   int sum = 0;
   rep(i, n){
      sum += box.at(i);
   }
   int limit = 0;
   limit = sum / (4 * m);
   if(sum % (4 * m) != 0) limit++; 
   sort(box.rbegin(),box.rend());
   int take = 0;
   take = box.at(m-1);
   if(take >= limit) cout << "Yes";
   else cout << "No";

   return 0;  
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod

int main(){
	ll x,y;
	cin>>x>>y;
	ll ans=0;
	if(x<=3)ans+=400000-x*100000;
	if(y<=3)ans+=400000-y*100000;
	if(x==1&&y==1)ans+=400000;
	cout<<ans<<endl;
}


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

using namespace std;

#define FaSt ios::sync_with_stdio(0),cin.tie(0);
#define random uniform_int_distribution<long long>(1, 2000000000000000LL)(rng)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() * ((uint64_t) new char | 1));

const int N = 10004;
long long n, ans;
vector<long long> v;

int main() 
{
    FaSt
    cin >> n;
    for (long long i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            v.push_back(i);
            if (i != n / i) v.push_back(n / i);
        }
    }
    
    sort(v.begin(), v.end());
    
    long long pre = 0;
    for (int i = 1; i < v.size(); i++)
    {
        if (n / v[i] == n % (v[i] - 1))
        {
            ans += v[i] - 1;
        }
    }
    
    cout << ans;
}

Measured memory_bytes: 384
while True:
     H,W=map(int,input().split())
     1<=H,W<=300
     if H==0&W==0:
          break
     for i in range(0,H):
          for j in range(0,W):
               if (i+j)%2==0:
                    print("#",end='')
               else:
                    print(".",end='')
          print()
     print()


Measured memory_bytes: 7008
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main()
{
   
    int n;
    cin >> n;
    map<int, int>f;
    set<int>t;
    vector<int>r;
    int q = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (!f[x]) {
            t.insert(x); r.push_back(x);
        }
        f[x]++;
        q ^= x;
       

    }

    if (n % 3) {
        if (t.size() == 1 && f[0] == n)cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }

    if (q) {
        cout<<"No"<<endl;
    }
    else {
        cout << "Yes" << endl;
  
    }

    
    return 0;

}


Measured memory_bytes: 7800
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define fir first
#define sec second
using namespace std;
const int mod = 998244353;
inline int mul(int x, int y) {return (ll)x * y % mod;}
inline int add(int x, int y) {return x + y >= mod ? x + y - mod : x + y;}
inline int sub(int x, int y) {return x >= y ? x - y : x - y + mod;}
int mi[201];
inline int cal(int x)
{
    if (x <= 2) return 0;
    return sub(mi[x], add(1, add(x, x * (x - 1) / 2)));
}
int n, x[201], y[201];
pii get(int i, int j)
{
    int a = x[i] - x[j], b = y[i] - y[j];
    int g = __gcd(a, b);
    a /= g; b /= g;
    return {a, b};
}
int main()
{
    scanf("%d", &n); mi[0] = 1;
    for (int i = 1; i <= n; i++) 
    {
        scanf("%d%d", &x[i], &y[i]);
        mi[i] = mul(mi[i - 1], 2);
    }
    int ans = cal(n);
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++)
        {
            pii v1 = get(i, j);
            int cnt = 0;
            for (int k = j + 1; k <= n; k++) if (v1 == get(i, k)) cnt++;
            ans = sub(ans, sub(mi[cnt], 1));
        }
    printf("%d\n", ans);
    return 0;
}

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

int main() {
  int N, M;
  int cnt=0;
  int cnt2p=0;
  int ans = 0;
  int preans = 0;

  cin >> N >> M;
  
  vector<int> k(M);
  vector<int> kcnt(M);
  vector<int> Msum(M);
  vector<int> p(M);
  vector<vector<int>> s(M, vector<int>(N));
  for(long i = 0; i < M; i++){
    cin >> k[i];
    kcnt[i] = 0;
    Msum[i] = 0;
    for(long j = 0; j < k[i]; j++){
      cin >> s[i][j];
    }
  }
  
  for(long j = 0; j < M; j++){
    cin >> p[j];
  }

    // {0, 1, ..., n-1} の部分集合の全探索
    for (int bit = 0; bit < (1<<N); ++bit) {
        vector<int> S;
        for (int i = 0; i < N; ++i) {
            if (bit & (1<<i)) { // i が bit に入るかどうか
              for(int j = 0; j < M; j++){
                for(int cnt = 0; cnt < k[j]; cnt++){
                  //各電球について対象スイッチ確認
                  if(s[j][cnt] == i+1){
                    Msum[j]++;
                  }
                }
              }
            }
        }
        
        //それぞれの電球について
        //スイッチの点灯数を確認
        for(int i = 0; i < M; i++){
          if(p[i] == Msum[i]%2){
            preans++;
          }
        }
        if(preans == M){
          ans++;
        }
        
        //次のループに向けて初期化
        for(int i = 0; i < M; i++){
          kcnt[i] = 0;
          Msum[i] = 0;
        }
          preans = 0;

    }

    cout << ans << endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val mod = 1000000007L
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toInt() }
    val colors = IntArray(3)
    var ans = 1L
    for (i in 0 until n) {
        val x = colors.filter { it == a[i] }.count()
        ans *= x
        ans %= mod
        for (j in 0 until 3) {
            if (colors[j] == a[i]) {
                colors[j]++
                break
            }
        }
    }
    println(ans)
}


Measured memory_bytes: 58116
#include<bits/stdc++.h>
using namespace std;
typedef struct node
{
	int a[51][51];
	struct node operator *(const struct node & tmp)
	{
		struct node ret;
		memset(ret.a,0,sizeof(ret.a));
		int k,i,j;
		for(k=1;k<=50;k++)
			for(i=1;i<=50;i++)
				for(j=1;j<=50;j++)
					if(a[i][k]&&tmp.a[k][j])
						ret.a[i][j]=(ret.a[i][j]+(long long)a[i][k]*tmp.a[k][j])%1000000007;
		return ret;
	}
}NODE,*PNODE;
NODE ans,g;
int main()
{
	int n,i,j,flag=0,s=0;
	long long k;
	scanf("%d %lld",&n,&k);
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			scanf("%d",&g.a[i][j]);
	while(k)
	{
		if(k%2)
		{
			if(!flag)
			{
				ans=g;
				flag=1;
			}
			else
				ans=ans*g;
		}
		g=g*g;
		k/=2;
	}
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			if(ans.a[i][j])
				s=(s+ans.a[i][j])%1000000007;
	printf("%d",s);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);

int have[101]={0};
int d;
int a;
for(int i = 0;i<k;i++){
    scanf("%d",&d);
    for(int j=0;j<d;j++){
scanf("%d",&a);
     have[a]++;   
    }
}

int sum = 0;
for(int i = 1;i<=n;i++){
    //printf("%d ",have[i]);
    if(have[i]==0){
        sum++;
    }
}
 //printf("\n");
 printf("%d",sum);
    return 0;
}

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


def main():
    N, W = [int(x) for x in input().split()]
    shina = []
    for i in range(N):
        a, b = [int(x) for x in input().split()]
        shina.append([a, b])

    dp = [[0 for i in range(N + 1)] for j in range(W + 1)]

    for i in range(N - 1, -1, -1):
        for j in range(W + 1):
            if shina[i][0] > j:
                dp[j][i] = dp[j][i + 1]
            else:
                dp[j][i] = max(dp[j][i + 1], dp[j - shina[i][0]][i + 1] + shina[i][1])

    ans = 0
    for j in range(W + 1):
        ans = max(ans, max(dp[j]))

    print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 130140
#include <iostream>
using namespace std;
 
int N, M, Q, L[200009], R[200009], X[509][509], C[509][509];
 
int main() {
	cin >> N >> M >> Q;
	for (int i = 1; i <= M; i++) {
		cin >> L[i] >> R[i]; X[L[i]][R[i]]++;
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) C[i][j] = C[i][j - 1] + X[i][j];
	}
	for (int i = 1; i <= Q; i++) {
		int p, q; cin >> p >> q;
		int sum = 0;
		for (int j = p; j <= q; j++) sum += C[j][q] - C[j][p - 1];
		cout << sum << endl;
	}
	return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int, int> pint;
typedef vector<int> vii;
typedef vector<int> vint;

#define X first
#define Y second
#define rep(i,n) for(int i=0; i<(n); i++)
#define repp(i,a,b) for(int i=a; i<=(b); i++)
#define repp2(i,b,a) for(int i=b; i>=(a); i--)
#define fiint(a,val) memset(a, (val), sizeof(a))
#define mp make_pair
#define pb push_back
#define aint(c) (c).begin(), (c).end()
#define uni(c) c.resize(distance(c.begin(), unique(aint(c))))
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sc(num) scanf("%intd",&num)
//#define ONLINE
#ifdef ONLINE
FILE *fin = freopen("great.in","r",stdin);
FILE *fout = freopen("great.out","w",stdout);
#endif

int mod= 1e9 + 7, mod1=1e9+9;
const int N=100005;

int a[N];
int main(){
    io;
    
    int n;
    cin>>n;
    int an=0;
    rep(i,2*n)cin>>a[i];
    sort(a,a+2*n);
    for(int i=0;i<2*n;i+=2)an+=a[i];
    cout<<an;
    
    return 0;
}

Measured memory_bytes: 764
n=int(input())
a=list(map(int, input().split()))
ans=[0]*n
for i in range(n):
    if n%2 > 0:
        if i % 2 > 0:
            ans[int((n+i)/2)]=a[i]
        else:
            ans[int((n-i-1)/2)]=a[i]
    else:
        if i % 2 > 0:
            ans[int((n-i-1)/2)]=a[i]
        else:
            ans[int((n+i)/2)]=a[i]
print( *ans)

Measured memory_bytes: 26180
#include <string>
#include <sstream>
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>

using namespace std;




class Main {
public:
	int error(vector<int> vec, int num) {
		int sum = 0;

		for (int i = 0;i < vec.size();i++) {
			sum += (vec[i] - num) * (vec[i] - num);
		}
		return sum;
	}

	int minNumber(vector<int> vec) {
		int mn = INT_MAX;
		int mx = INT_MIN;
		for (int i = 0;i < vec.size();i++) {
			mn = min(mn, vec[i]);
			mx = max(mx, vec[i]);
		}

		int minError = INT_MAX;
		int minNum = mn;
		for (int x = mn;x <= mx;x++) {
			int err = error(vec, x);
			if (err < minError) {
				minError = err;
				minNum = x;
			}
		}

		return minError;
	}
};

int main()
{
	Main m;
	int n;
	vector<int> vec;

	cin >> n;
	for (int i = 0;i < n;i++) {
		int inp;
		cin >> inp;
		vec.push_back(inp);
	}

	cout << m.minNumber(vec) << endl;

    return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


const int cm = 1 << 17;
char cn[cm], * ci = cn, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}

int main() {
	fread(cn, 1, cm, stdin);
	int N = 0;
	while ((ct = *ci++) >= '0') N = N * 10 + ct - '0';

	int fu = 0;
	int saishou = 1e9;
	ll goukei = 0;
	rep(i, N) {
		if (ci - cn + 16 > cm) {
			if ((ct = getcha()) == '-') { fu ^= 1; ct = getcha(); }
			int A = ct - '0';
			while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
			goukei += A;
			chmin(saishou, A);
		}
		else {
			if ((ct = *ci++) == '-') { fu ^= 1; ct = *ci++; }
			int A = ct - '0';
			while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
			goukei += A;
			chmin(saishou, A);
		}
	}

	if (fu) goukei -= saishou * 2;

	printf("%lld", goukei);

	Would you please return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n,m,a,b,c;
	string str;
	cout << fixed << setprecision(10);
	cin>>a;
	cout<<3*a*a;


	cout<<endl;
} 


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> V(N);
    for (int i = 0; i < N; ++i) cin >> V[i];

    int ans = 0;
    for (int l = 0; l <= K; ++l) {
        for (int r = 0; r <= K - l; ++r) {
            if (l + r > N) break;
            int d = K - l - r;
            int now = 0;
            vector<int> s;
            for (int i = 0; i < l; ++i) {
                now += V[i];
                s.push_back(V[i]);
            }
            for (int i = N - r; i < N; ++i) {
                now += V[i];
                s.push_back(V[i]);
            }
            sort(s.begin(), s.end());
            for (int i = 0; i < d; i++) {
                if (i >= s.size()) break;
                if(s[i] > 0) break;
                now -= s[i];
            }
            ans = max(ans, now);
        }
    }

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

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

int main() {
    std::string S;
    std::cin >> S;
    if (S.substr(S.size()-1) == "s") {
        std::cout << S + "es" << std::endl;
    } else {
        std::cout << S + "s" << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if((a==1 && b==2) || (a==2 && b==1))
    cout<<"3";
    else if((a==1 && b==3) || (a==3 && b==1))
    cout<<"2";
    else
    cout<<"1";
}


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

int main()
{
    string S;
    cin >> S;

    const char acgt[4] = {'A', 'C', 'G', 'T'};
    int size = 0;
    int count = 0;
    for (int i = 0; i < (int)S.size(); ++i)
    {
        int tmp = count;
        rep(j, 4)
        {
            if (S[i] == acgt[j])
            {
                ++count;
                break;
            }
        }
        if (tmp == count)
        {
            size = max(size, count);
            count = 0;
        }
    }
    cout << max(size, count) << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int coin = 0;

    if (a > b) {
        coin += a;
        a--;
    }
    else {
        coin += b;
        b--;
    }

    if (a > b) {
        coin += a;
        a--;
    }
    else {
        coin += b;
        b--;
    }

    cout << coin << endl;

    return 0;
}



Measured memory_bytes: 256
num = input().split(' ')
data = [int(num[i]) for i in range(3)]

result = data[0] // (data[1] + data[2]) * data[1]
if(data[0] % (data[1] + data[2]) >= data[1]):
    key = data[1]
else:
    key =  data[0] % (data[1] + data[2])
result += key

print(result)


Measured memory_bytes: 3060
import math


def main():
    n = int(input())
    a = []
    for i in range(1, (int)(math.sqrt(n)) + 1):
        if n % i == 0:
            if i != 1:
                a.append(i - 1)
            if n // i - 1 != 0:
                a.append((n // i) - 1)
    ans = 0
    for i in range(len(a)):
        if a[i] != 1 and (n // a[i] == n % a[i]):
            ans += a[i]
    print(ans)


main()


Measured memory_bytes: 9224
var
  n,i,j,k,t,root:longint;
  a:array[1..100000] of integer;
  x:char;
  first,next,last,b:array[1..100000] of longint;
begin
  i:=0;
  while not eoln do
    begin
      n:=n+1;
      read(x);
      if x='1'
        then a[n]:=1
        else a[n]:=0;
    end;
  if (a[1]=0)or(a[n]=1)
    then
      begin
        writeln(-1);
        halt;
      end;
  for i:=2 to n do
    if (a[i]=1)and(a[n-i]=0)
      then
        begin
          writeln(-1);
          halt;
        end;
  root:=1;
  for i:=2 to n do
    if a[i-1]=0
      then writeln(root,' ',i)
      else
        begin
          writeln(root,' ',i);
          root:=i;
        end;
end.


Measured memory_bytes: 1664
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

s = sum(B)
for i in range (N-1):
    if A[i] + 1 == A[i+1]:
        s += C[A[i]-1]

print(s)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
   
using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define deb(x) cout << #x << "=" << x << endl
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define vi vector<int>
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define mod 1000000007
#define int long long
set < ll> primes;
 
int n,m;

bool isvalid(int x,int y)
{
    return (x>=0 && x<n && y>=0 && y<m);
}
int dx[]={0,0,1,-1,-1,1,1,-1};
int dy[]={1,-1,0,0,-1,1,-1,1};
void Sieve(ll n) 
{ 
    bool prime[n+1];
	for(ll i=0;i<n+1;++i)
		prime[i]=true;
    for (ll p=2;p*p<=n;++p) 
    {
        if (prime[p] == true) 
        {  
            for (ll i=2*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    }  
    for(ll p=2; p<=n; p++) 
       if (prime[p]) 
		primes.insert(p);  
}

ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
        return gcd(b % a, a); 
} 
ll powermod(ll x, ll y){
    if(y==0)
    return 1;
        
    if(y%2==0)
    return (powermod(x,y/2)*powermod(x,y/2))%mod;
    else
    return (((powermod(x,y/2)*powermod(x,y/2))%mod)*x)%mod;
}

void solve()
{
   int a,b,c;
   cin>>a>>b>>c;
   
   cout<<c<<" "<<a<<" "<<b;
}



 
 

int32_t main()
{
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t=1;
    //cin>>t;
    for(int ind=1;ind<=t;ind++)
    {
        // cout<<"Case #"<<ind<<": "<<" ";
        
        solve();
    }
    
    
    
    
   
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    unsigned long long int sum=0;
    for (int i = 1; i <= n; ++i)
    {
        if (!(i%3 == 0 || i%5 ==0))
        {
            sum+=i;
        }
        
    }
    cout<<sum;

    return 0;
}

Measured memory_bytes: 3636
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
   
    int a,b,c;
    cin>>a>>b>>c;
    
    int s[3]={a,b,c};
    sort(s,s+3);
    
    if(s[0]==5 && s[1]==5 && s[2]==7){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    
    
    
    
    return 0;
   
}






Measured memory_bytes: 256
card = [[int(i) for i in input().strip().split()] for _ in range(3)]
n = int(input())
flag = [[False, False, False], [False, False, False], [False, False, False]]

for _ in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if card[i][j] == b:
                flag[i][j] = True

is_bingo = any([
    any(all(flag[i][j] for i in range(3)) for j in range(3)),
    any(all(flag[i][j] for j in range(3)) for i in range(3)),
    flag[0][0] and flag[1][1] and flag[2][2],
    flag[2][0] and flag[1][1] and flag[0][2],
])

print("Yes" if is_bingo else "No")

Measured memory_bytes: 38384
import sys
input = sys.stdin.readline
from math import sqrt

N,K=map(int,input().split())
M=[tuple(map(int,input().split())) for i in range(N)]

def cross_coor(x0,y0,c0,x1,y1,c1): # 二円の交点
    if (c1-c0)**2<=(x1-x0)**2+(y1-y0)**2<=(c0+c1)**2:
        x2,y2=x1-x0,y1-y0
        a=(x2**2+y2**2+c0**2-c1**2)/2

        xa=(a*x2+y2*sqrt((x2**2+y2**2)*(c0**2)-a**2))/(x2**2+y2**2)+x0
        ya=(a*y2-x2*sqrt((x2**2+y2**2)*(c0**2)-a**2))/(x2**2+y2**2)+y0

        xb=(a*x2-y2*sqrt((x2**2+y2**2)*(c0**2)-a**2))/(x2**2+y2**2)+x0
        yb=(a*y2+x2*sqrt((x2**2+y2**2)*(c0**2)-a**2))/(x2**2+y2**2)+y0

        return [(xa,ya),(xb,yb)]
    else:
        return False

OK=1<<31
NG=0

while OK-NG>10**(-8):
    mid=(OK+NG)/2
    
    CANDI=[]
    for i in range(N):
        x0,y0,c0=M[i]
        CANDI.append((x0,y0))
        for j in range(i+1,N):
            x1,y1,c1=M[j]
            CR=cross_coor(x0,y0,mid/c0,x1,y1,mid/c1)
            if CR:
                CANDI.extend(CR)

    for z,w in CANDI:
        count=0
        for x,y,c in M:
            if (c**2)*((x-z)**2+(y-w)**2)<=(mid+10**(-8))**2:
                count+=1
            
        if count>=K:
            OK=mid
            break
    else:
        NG=mid

print((OK+NG)/2)

Measured memory_bytes: 53356
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<i64>();
    let (sx, sy, tx, ty) = (line[0], line[1], line[2], line[3]);

    // 1
    for _ in 0..(tx-sx){
        print!("R");
    }
    for _ in 0..(ty-sy){
        print!("U");
    }

    // 2
    for _ in 0..(tx-sx){
        print!("L");
    }
    for _ in 0..(ty-sy){
        print!("D");
    }

    //3
    print!("D");
    for _ in 0..(tx-sx)+1{
        print!("R");
    }
    for _ in 0..(ty-sy)+1{
        print!("U");
    }
    print!("L");

    //4
    print!("U");
    for _ in 0..(tx-sx)+1{
        print!("L");
    }
    for _ in 0..(ty-sy)+1{
        print!("D");
    }
    println!("R");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
#define debug(x) cout << x << endl
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1<<30;
const ll LINF = 1LL<<61;
const ll MOD = 1000000007;

int main()
{
    string s, t;
    cin >> s >> t;
    int ans = INF;
    int n = s.size(), m = t.size();
    rep(i,n)
    {
        if(i + m > n) break;
        // cout << "a";
        int cnt = 0;
        rep(j,m)
        {
            if(s[i+j] != t[j]) cnt++;
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define ljc 1000000007
using namespace std;
/*
C_{a_i+b_i+a_j+b_j}^{a_i+a_j}
等价于(-a_i,-b_i)->(a_j,b_j)的方案数（只能上右移）
\sum_{i=1}^n\sum_{j=i+1}^n C_{a_i+b_i+a_j+b_j}^{a_i+a_j}
=\sum_{i=1}^n([i+1,n])点到(a_i,a_j)的距离
直接 dp
最后容斥。 
*/
#ifdef Fading
#define gc getchar
#endif
#ifndef Fading
inline char gc(){
    static char now[1<<16],*S,*T;
    if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
    return *S++;
}
#endif
inline ll read(){
    register ll x=0,f=1;char ch=gc();
    while (!isdigit(ch)){if(ch=='-')f=-1;ch=gc();}
    while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}
    return (f==1)?x:-x;
}
int n,MX,dp[4003][4003];
inline ll fast_pow(ll a,ll b,ll p){
	ll t=1;a%=p;
	while (b){
		if (b&1) t=t*a%p;
		b>>=1;a=a*a%p;
	}	
	return t;
}
ll inv[100001],a[200201],b[200201],fac[100001];
inline void init(int n){
	inv[0]=inv[1]=fac[0]=fac[1]=1;
	for (ll i=2;i<=n;i++) fac[i]=fac[i-1]*i%ljc;
	for (ll i=2;i<=n;i++) inv[i]=(ljc-(ljc/i)*inv[ljc%i]%ljc)%ljc;
	for (ll i=1;i<=n;i++) inv[i]=inv[i-1]*inv[i]%ljc;
}
signed main(){
	n=read();
	init(8000);
	for (int i=1;i<=n;i++){
		a[i]=read(),b[i]=read();MX=max(MX,max(a[i],b[i]));
	}
	for (int i=1;i<=n;i++){
		dp[-a[i]+MX][-b[i]+MX]++;
	}
	for (int i=0;i<=2*MX;i++){
		for (int j=0;j<=2*MX;j++){
			dp[i+1][j]=(dp[i+1][j]+dp[i][j])%ljc;
			dp[i][j+1]=(dp[i][j+1]+dp[i][j])%ljc;
		}
	}
	ll ans=0;
	for (int i=1;i<=n;i++){
		ans=(ans+dp[a[i]+MX][b[i]+MX])%ljc;
	 	ans=(ans-fac[2*a[i]+2*b[i]]*inv[2*b[i]]%ljc*inv[2*a[i]]%ljc+ljc)%ljc;
	}
	ans=ans*fast_pow(2,ljc-2,ljc)%ljc;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 129408
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::cmp::{min, max};
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input!{
        n: i32,
    }
    let mut ans = 0;
    for number in (1..(n + 1)).rev(){
        let strnum = number.to_string();
        if strnum.len() %2 == 1{
            ans+=1;
        }
    }
    println!("{}", ans);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

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

using namespace std;




int main(){

	long long a, b; cin >> a >> b;


	set <long long> s1, s2;


	for(long long i = 2; i * i <= a; i++){
		while(a % i == 0){
			s1.insert(i);
			a /= i;
		}
	}

	if(a != 1){
		s1.insert(a);
	}


	for(long long i = 2; i * i <= b; i++){
		while(b % i == 0){
			s2.insert(i);
			b /= i;
		}
	}

	if(b != 1){
		s2.insert(b);
	}

	int ans = 0;

	for(auto it : s1){
		if(s2.find(it) != s2.end()){
			ans++;
		}
	}


	cout << ans + 1 << endl;


	return 0;
}

Measured memory_bytes: 256
def convertDatetime(t):
    t = int(t)
    h = t // (60*60)
    m = (t % (60*60)) // 60
    s = ((t % (60*60)) % 60)

    print(str(h) + ':' + str(m) + ':' + str(s))

def main():
    T = input()
    convertDatetime(T)

if __name__ == '__main__':
    main()



Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 2e9
#define mod 1000000007LL
#define eps 0.0001
#define ALL(x) (x).begin(), (x).end()
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define SZ(x) ((ll)(x).size())
#define sum(x) accumulate(ALL(x), 0LL)//?
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; }
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    string S1, S2;
    cin >> N >> S1 >> S2;
    ll res;
    if (S1.at(0) == S2.at(0)){
        res = 3;
    }else{
        res = 6;
    }
    FOR(i, 1, N){
        if(S1.at(i) != S1.at(i-1) && S2.at(i) != S2.at(i-1)){
            if (S1.at(i-1) == S2.at(i-1)){
                res*=2;
                res%=mod;
            }else if(S1.at(i) == S2.at(i)){
                res*=1;
                res%=mod;
            }else{
                res*=3;
                res%=mod;
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  long int n,i,x,min = 10000000000000;
  scanf("%ld",&n);
  for(i = 1 ; i * i <= n ; i++)
    {
      if(n % i == 0)
        {
          x=n/i;

          if(min >= i + x - 2)
            {
              min = i + x - 2;
            }
        }

    }
  printf("%ld\n",min);
  return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <stack>
#include <string>
#include <cstdlib>
#include <queue>
using namespace std;

typedef struct {
	string name;
	int t;
}P;

queue <P> u;

int main(){
	int n, q,sum=0;
	P tmp;
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		cin >> tmp.name >> tmp.t;
		u.push(tmp);
	}
	while (!u.empty()) {
		tmp = u.front();
		u.pop();
		int c= min(q, tmp.t);
		tmp.t -= c;
		sum += c;
		if (tmp.t > 0) u.push(tmp);
		else cout << tmp.name << " " << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 6324
#pragma GCC optimize(2,3,"Ofast","unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define in inline
namespace fast_io
{
	char buf[1<<12],*p1=buf,*p2=buf,sr[1<<23],z[23],nc;int C=-1,Z=0,Bi=0,ny;
	in char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
	in ll read()
	{
		ll x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;Bi=1;if(nc<0)return nc;
		x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48),Bi++;return x*ny;
	}
	in db gf() {int a=read(),y=ny,b=(nc!='.')?0:read();return (b?a+(db)b/pow(10,Bi)*y:a);}
	in int gs(char *s) {char c,*t=s;while(c=gc(),c<=32);*s++=c;while(c=gc(),c>32)*s++=c;return s-t;}
	in void ot() {fwrite(sr,1,C+1,stdout);C=-1;}
	in void flush() {if(C>1<<22) ot();}
	template <typename T>
	in void write(T x,char t)
	{
		int y=0;if(x<0)y=1,x=-x;while(z[++Z]=x%10+48,x/=10);
		if(y)z[++Z]='-';while(sr[++C]=z[Z],--Z);sr[++C]=t;flush();
	}
	in void write(char *s) {int l=strlen(s);for(int i=0;i<l;i++)sr[++C]=*s++;sr[++C]='\n';flush();}
};
using namespace fast_io;
#define pb push_back
const int N=1e7+5,M=1e6+5;
int n,p[M],m[N];
ll ans,d[N];
bool vis[N];
int main()
{
	n=read();
	d[1]=1;
	for(int i=2;i<=n;i++){
		if(!vis[i])p[++p[0]]=i,d[i]=2,m[i]=2;
		for(int j=1;j<=p[0]&&i*p[j]<=n;j++){
			vis[i*p[j]]=1;
			if(!(i%p[j])){
				d[i*p[j]]=d[i]/m[i]*(m[i]+1);
				m[i*p[j]]=m[i]+1;
				break;
			}
			d[i*p[j]]=d[i]*2,m[i*p[j]]=2;
		}
	}
	for(int i=1;i<=n;i++)ans+=i*d[i];
	cout<<ans;
	return ot(),0;
}
//Author: disangan233

Measured memory_bytes: 133132
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
  	int N;
    cin >> N;
    string S[N];

    for(int i=0;i<N;i++){
      cin >> S[i];
    }
    sort(S, S+N);
    /*for(int i=0;i<N;i++){
      cout << S[i] <<endl;
    }
    */

    int M = 0;
    int i = 0;

    while(i<N-1){
      int cnt = 1;
      while(i+1<N && S[i]==S[i+1]){
        cnt++;
        i++;
      }
      //cout << cnt <<endl;
      M = max(cnt, M);
      i++;
    }

    //cout << endl;
    //cout << M <<endl;

    i = 0;
    while(i<N){
      int cnt = 1;
      while(i+1<N && S[i]==S[i+1]){
        cnt++;
        i++;
      }
      if(M==cnt){
        cout << S[i] <<endl;
      }
      i++;
    }


  	return 0;
}



Measured memory_bytes: 14208
from itertools import combinations_with_replacement
from math import gcd
K = int(input())
memo = {}
ans = 0
for a,b,c in combinations_with_replacement(range(1,K+1),3):
  v = gcd(a, gcd(b,c))
  n = len(set([a,b,c]))
  ans += v if n==1 else (3*v if n==2 else 6*v)
print(ans)

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

#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

void solve()
{
	ll n;
	cin>>n;
	ll a[n+1],cnt=0;
	for(ll i=1;i<=n;i++) 
	{
		cin>>a[i];
		if(i%2==1 && a[i]%2==1) cnt++;
	}
	cout<<cnt;
}

int main()
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n;
  cin >> n;

  vector<int> a(n);
  REP(i,n) cin >> a[i];
  
  vector<int> b(n);
  REP(i,n) cin >> b[i];
  
  vector<int> c(n);
  REP(i,n) cin >> c[i];
  
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());

  //2段目にbの小さい方からi番目を選ぶ組み合わせをd[i]とする
  //これは、b[i]の値よりも真に小さいaの要素の個数
  vector<int> d(n);
  REP(i,n) d[i] = lower_bound(a.begin(),a.end(),b[i]) - a.begin();

  //3段目にc[i]をおく組み合わせを計算
  //これは、bのc[i]よりも小さい要素の選び方の総和なので、累積和的に前計算できる
  //e[i]:bの小さい方からi個を取れるときの取り方
  vector<int> e(n+1,0);
  REP(i,n) e[i+1] = e[i]+d[i];

  //各c[i]について組み合わせを計算
  int ans = 0;
  REP(i,n) ans += e[lower_bound(b.begin(),b.end(),c[i])-b.begin()];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4352
#include<iostream>
using namespace std;
#define df 0
typedef long int li;
li dc=0;
void rem(li& you,li& others,int n);
int main(){
  if(df) printf("*debug mode*\n");
  int n; cin >> n;
  li a[n],s=0;
  
  li y[n],oth[n],sum=0;
  for(int i=0;i<n;i++){
    dc+=df;
    cin >> y[i];
    s+=y[i];
    y[i]+=sum;
    oth[i]=0;
    rem(y[i],oth[i],n);
    if(df)printf("[%d,%d] ",y[i],oth[i]);
    sum+=oth[i];
  }
  if(df)printf("\n");
  while(sum){
    for(int i=0;i<n;i++){
      dc+=df;
      sum-=oth[i];
      y[i]+=sum;
      oth[i]=0;
      rem(y[i],oth[i],n);
      if(df)printf("[%d,%d] ",y[i],oth[i]);
      sum+=oth[i];
    }
    if(df)printf("\n");
  }
  for(auto& x: y) sum+=x;
  cout << s-sum <<"\n";

  if(df)printf("loop: %ld",dc);
}


void rem(li& you,li& others,int n){
  while(you>=n || others >=n){
    dc+=df;
    li m=min(you,others)-n+1;
    if(m>0){
      you-=m;
      others-=m;
    }
    others+=you/n;
    you%=n;
    you+=others/n*(n-1);
    others=others%n+others/n*(n-2);
  }
}

/// confirm df==0 ///

Measured memory_bytes: 256