akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    
    bool ans = false;
    for (auto v : g[0]) {
        for (auto u : g[v]) {
            ans |= (u == n-1);
        }
    }
    
    if (ans) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}

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

int main()
{
    int arr[5];
    for(int i=0;i<5;i++)cin >> arr[i];

    int curr_min = 0;
    int min_val = 9;
    for(int i=0;i<5;i++)
    {
        if(arr[i]%10!=0 && arr[i]%10<min_val)
        {
            min_val = arr[i]%10;
            curr_min = i;
        }
    }
    int ans = 0;
    for(int i=0;i<5;i++)
    {
        if(i!=curr_min){
            double x = (double)arr[i]/10;
            x = ceil(x);
            ans+= 10*x;
            //cout << ans << " ";
        }
    }

    ans+=arr[curr_min];

    cout << ans;
}

Measured memory_bytes: 256
import bisect

N = int(input())
Ls = list(map(int, input().split()))
Ls.sort()

# O(N^2 * logN)の全探索で解く
ans = 0
for a_i in range(N):
    for b_i in range(a_i+1, N):
        c_i = bisect.bisect_left(Ls, Ls[a_i]+Ls[b_i])
        if c_i > b_i:
            ans += c_i - b_i - 1
        else:
            pass

print(ans)

# from itertools import combinations
# import numpy as np
#
# n = int(input())
# hoge = list(map(int, input().split()))
# hoge.sort()
#
# # hoge = np.sort(l)
# ll = []
# ans = 0
#
# def triangle(target, v1, v2):
#     return target < v1 + v2
#
# for i in range(len(hoge)):
#     for j in range(i + 1, len(hoge)):
#         left = hoge[j]
#         right = hoge[-1] + 1
#         while left + 1 < right:
#             mid = (left + right) / 2
#             if triangle(mid, hoge[i], hoge[j]):
#                 ans += len(hoge[hoge >= mid])
#                 break
#             else:
#                 left = mid
#
# print(ans)

"""3回目
# 事前の各要素xより大きい要素個数を求める
for v in hoge:
    ll.append([v, len(hoge[v <= hoge])])

# 事前にコンビネーションを確保する。ループはしない！
combi = np.array([[sum(v), v[1]] for v in combinations(hoge, 2)])

print(combi)
print(combi[:, 0])
print(ll)

# 要素のループをもう一度回し、各
for v, cnt in ll:
    print(v, cnt, len(combi[(v < combi[:, 0]) & (combi[] < v)]), sep=',')
    ans += cnt * len(combi[v < combi])

print(ans)

"""


"""2回目 comnbinationループがだめ
for v in combinations(hoge, 2):
    s = sum(v)
    ans += len(hoge[(v[1] < hoge) & (hoge < s)])

"""



"""1
これだとTLEが出る
combinationの全パターンを数え上げると遅すぎる
ソート済み配列 × なにかで組み合わせを数え上げる必要

from itertools import combinations

n = int(input())
l = map(int, input().split())

ans = 0

for v in combinations(l, 3): # combination を使ってループした時点ででn^2
    if v[0] < v[1] + v[2] and v[1] < v[0] + v[2] and v[2] < v[0] + v[1]:
        ans += 1

print(ans)
"""


Measured memory_bytes: 3188
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a[] = new int[3 * N];
		for(int i = 0; i < 3 * N; i++) {
			a[i] = sc.nextInt();
		}
		
		Arrays.sort(a);
		long ans = 0;
		for(int i = 3 * N - 2; i >= N; i -= 2) {
			ans += a[i];
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 92340
#include<bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define int long long int
#define ld long double
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define r0 return 0;
#define tc int t;cin>>t;while(t--)
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define vi vector<int>
#define vii vector<long long int>
#define SORT(v) sort(v.begin(),v.end());
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define md 998244353
#define inf 1000000000000000 //1e15
#define gcd __gcd
#define lcm(a,b) ((a)*(b))/gcd(a,b)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define crap ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
int min(int a,int b){
    return (a<b)?a:b;
}
int max(int a,int b){
    return (a>b)?a:b;
}
int fp(int a,int b){
    if(b==0) return 1;
    int x=fp(a,b/2);
    x=(x*x)%mod;
    if(b&1) x=(x*a)%mod;
    return x;
}
int factorial(int n)
{
    int fact=1;
    for(int i=2;i<=n;i++)
    fact=fact*i;
    
    return fact;
}
int ncr(int n,int r)
{
    return factorial(n)/(factorial(r)*factorial(n-r));
}
void c_p_c()
{
    crap;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
signed main()
{
    c_p_c();
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int xo=0;
    for(int i=0;i<n;i++)
        xo^=a[i];
    for(int i=0;i<n;i++)
        a[i]^=xo;
    for(int i=0;i<n;i++)
        cout<<a[i]<<" ";
    cout<<endl;
}

Measured memory_bytes: 5140
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, a[N];
long long ans = 0;
long long MAX = 4e18;
long long dfs(int d, long long r) {
  if(r >= MAX) r = MAX;
  if(r < 0) {
    cout << "-1\n";
    exit(0);
  }
  if(d == n) {
    if(r < a[d]) {
      cout << "-1\n";
      exit(0);
    }
    ans += a[d];
    return a[d];
  }
  long long ret = dfs(d + 1, (r - a[d]) * 2);
  ans += min(ret + a[d], r);
  return min(ret + a[d], r);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for(int i = 0; i <= n; i++) {
    cin >> a[i];
  }
  if(n == 0 && a[0] == 1) {
    cout << 1 << '\n';
    exit(0);
  }
  dfs(0, 1 - a[0]);
  cout << ans << '\n';
}

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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
   int x, y, z; // 椅子幅、人幅、隙間幅
   cin >> x >> y >> z;
   x -= z;
   int unit = y + z;
   int a = x / unit;
   cout << a << endl;

   return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
#a = int(input())
a,b,c,d = map(int,input().split())
#a = [int(i) for i in input().split()]

i = 1
while True:
    if c <= 0:
        print("Yes")
        break
    elif a <= 0:
        print("No")
        break
    elif i % 2 != 0:
        c -= b
        i += 1
    else:
        a -= d
        i += 1
    #print(i, a, c)


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

typedef long long ll;

const int INF = 1e9 + 10;
const ll INFLL = 3e18;

int main(){
	
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	
	string s, t;
	cin >> s;
	cin >> t;
	
	reverse(t.begin(), t.end());
	if(t == s) cout << "YES\n";
	else cout << "NO\n";
	
	return 0;
}

Measured memory_bytes: 256
// If I can't Make It then I Should Try Harder
#include<bits/stdc++.h>
#define ll  long long
#define isc ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ld long double
#define ss string
#define ww while
#define vl vector<ll>
#define pb push_back
#define in insert
#define vec vector
#define itr iterator
#define gt goto
#define rep(i,n,j) for(ll i=n;i<j;i++)
#define pll pair<ll,ll>
#define bft bool f=true
#define bff bool f=false
#define F first
#define S second
using namespace std;


ll kmm(ll a, ll b) {
	return(a*b) / __gcd(a, b);
}

const ll mod = 1e9+7,INF=8e18;
const ll N = 1e5+5;
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

ll comb(ll x,ll y){
    if(x==y || y==0)    return 1;
    return ((comb(x-1,y-1))+(comb(x-1,y)))%mod;
}


ll a,b;

int main() {
    isc;
    cin >> a >> b;
    if(a>=10)   cout << b << '\n';
    else    cout << 100*(10-a)+b << '\n';


	return 0;
}


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

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

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int x, a; cin >> x >> a;
  if (x < a) cout << 0 << endl;
  else cout << 10 << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<math.h>
using namespace std;
int main() {
	int num, retu=0;
		int *train = new int[10];
		while (cin >> num) {
			if (num == 0) {
				cout << train[retu-1]<<endl;
				retu--;
			}
			else {
				train[retu] = num;
					retu++;
			}
	}
	return 0;
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=110000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll gcd(ll x, ll y){
  if(x%y==0)return y;
  return gcd(y,x%y);
}
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  ll n,k;
  string s;
  cin >> n >> k >> s;
  vector<int>num;
  if(s[0]=='0')num.push_back(0);
  for(int i=0;i<n;){
    int j=i;
    while(j<n && s[j]==s[i])j++;
    num.push_back(j-i);
    i=j;
  }
  vector<int>sum(num.size()+1,0);
  rep(i,num.size()){
    sum[i+1]=sum[i]+num[i];
  }
  int ans=0;
  for(int l=0;l<sum.size();l+=2){
    int r=l+k*2+1;
    if(r>=sum.size())r=sum.size()-1;
    chmax(ans,sum[r]-sum[l]);
  }
  cout << ans << endl;
    
  
}

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

int main() {
  int A,B,C;
  cin>>A>>B>>C;
  
  int ans=max({10*A+B+C, A+10*B+C, A+B+10*C});
  
  cout<<ans<<endl;
  
}


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

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

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

    vector<ll > V(N+10, 0);
    vector<ll > C(N+10, 0);

    for(ll i = 0; i < N; i++){
        cin >> V[i];
    }
    for(ll i = 0; i < N; i++){
        cin >> C[i];
    }

    ll ans = 0;
    //bit全列挙
    for(ll i = 0; i <= (1<<N); i++){
        //ビットの位置を数える
        ll x = 0;
        ll y = 0;
        //cout << i << endl;
        for(ll j = 0; j < N; j++){
            //右シフトして最下位で立っているかどうか判定
            if((i >> j) & 1 == 1){
                //cout << V[j] << " " << C[j] << endl;
                x += V[j];
                y += C[j];
            }
        }
        ans = max(x - y, ans);
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
{-# LANGUAGE TupleSections #-}
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
import Control.Monad.State (State, evalState, gets, modify)
import Data.Map.Strict (Map, lookup, insert, empty)
import Data.Bits
import Debug.Trace 
import qualified Data.Set as S

main :: IO ()
main = readLine >>= main'
    where
        main' [n, k] = readLine >>= print . solve n k 

solve :: Int -> Int -> [Int] -> Int
solve n k as = foldl' ff 0 [40,39..0] -- cs
    where
        bsvs = V.fromList $ scanl (+) 0 as
        bs = [bsvs V.! i - bsvs V.! j | i <- [1..n], j <- [0..(i - 1)]]--, i - j + k - 1 <= n]
        cs = filter (\(_, s) -> S.size s >= k) $ map count [40,39..0]
        count e = (v,) . S.fromList $ filter (\b -> b .&. v /= 0) bs
            where
                v = shiftL 1 e

        ff acc e 
            | length xs >= k = next
            | otherwise = acc
            where
                v = shiftL 1 e
                next = acc + v
                xs = filter (\b -> b .&. next == next) bs 

                {-
        ff (acc, ps) (v, s)
            | S.size t >= k = (acc + v, t)
            | otherwise = (acc, ps)
            where
                t = S.filter (flip S.member ps) s

        dbs = [(i - j, bsvs V.! i - bsvs V.! j) | i <- [1..n], j <- [0..(i - 1)]]
        (smalls, bigs) = partition (\(x, _) -> x <= n - k + 1) dbs
        res1 = maximum $ map snd smalls

        calc recf ((x : xs), c)
            | c == 0 = return $ complement 0
            | otherwise = max <$> recf (xs, c) <*> ((x .&.) <$> recf (xs, c - 1))
        calc _ (_, c)
            | c > 0 = return 0
            | otherwise = return $ complement 0
-}

readLine :: IO [Int]
readLine = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

type Memoizer a b = a -> State (Map a b) b

run :: (Ord a) => (Memoizer a b -> Memoizer a b) -> a -> b
run f = flip evalState empty . memoizeFix f

memoizeFix :: (Ord a) => (Memoizer a b -> Memoizer a b) -> Memoizer a b
memoizeFix f x = gets (Data.Map.Strict.lookup x) >>= maybe (f (memoizeFix f) x >>= ((<$) <*> (modify . Data.Map.Strict.insert x))) return

Measured memory_bytes: 30076
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> a(n),v,v2;
    map<int, int> mp;
    int cnt = 0;
    rep(i,n){
        cin >> a[i];
        if(!mp[a[i]]){
            cnt++;
            v.push_back(a[i]);
        }
        mp[a[i]]++;
    }
    int ans = 0;
    for(auto e:v){
        v2.push_back(mp[e]);
    }
    sort(v2.begin(), v2.end());
    cnt -= k;
    rep(i,cnt){
        ans += v2[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 12660
#include <stdio.h>
int main(void){
int S;
int h,m,s;
scanf("%d" ,&S);
h=S/3600;
m=(S-3600*h)/60;
s=S-3600*h-60*m;
printf("%d:%d:%d\n",h,m,s);
return 0;
}



Measured memory_bytes: 2084
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var S string
	fmt.Scan(&S)
	nums := toNums(S)
	sum := 0
	bit := len(S) - 1
	for mask := 0; mask < 1<<uint(bit); mask++ {
		plus := make([]bool, bit)
		for i := 0; i < bit; i++ {
			plus[i] = 1<<uint(i)&mask > 0
		}
		sum += calc(nums, plus)
	}
	fmt.Println(sum)
}

func toNums(str string) []int {
	var nums []int
	for _, r := range str {
		n, _ := strconv.Atoi(string(r))
		nums = append(nums, n)
	}
	return nums
}

func calc(nums []int, plus []bool) int {
	sum := 0
	n := nums[0]
	for i, b := range plus {
		if b {
			n = n*10 + nums[i+1]
		} else {
			sum += n
			n = nums[i+1]
		}
	}
	return sum + n
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,cnt=0,ans=0;
	cin>>n;
	vl v(n);
	rep(i,n)cin>>v[i];
	rep(i,n){
		if(v[i])cnt++;
		else {
			chmax(ans,cnt);
			cnt=0;
		}
	}
	chmax(ans,cnt);
	cout<<ans+1<<endl;
}



Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin >> s >> t;
  int cnt=0;
  for(int i=0;i<s.size();i++){
    if(s[i]==t[i]){
      cnt++;
    }
  }
  cout << cnt << endl;
}

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


Measured memory_bytes: 19004
using System;

class Program
{
	static void Main()
	{
		bool[] A = new bool[52];
		int D = int.Parse(Console.ReadLine());
		for (int i = 0; i < D; i++)
		{
			string[] sD = Console.ReadLine().Split(' ');
			if (sD[0] == "S")
				A[int.Parse(sD[1]) - 1] = true;
			if (sD[0] == "H")
				A[int.Parse(sD[1]) + 12] = true;
			if (sD[0] == "C")
				A[int.Parse(sD[1]) + 25] = true;
			if (sD[0] == "D")
				A[int.Parse(sD[1]) + 38] = true;
		}
		for (int i = 0; i < 13; i++)
			if (!A[i])
				Console.WriteLine("{0} {1}", "S", i + 1);
		for (int i = 13; i < 26; i++)
			if (!A[i])
				Console.WriteLine("{0} {1}", "H", i - 12);
		for (int i = 26; i < 39; i++)
			if (!A[i])
				Console.WriteLine("{0} {1}", "C", i - 25);
		for (int i = 39; i < 52; i++)
			if (!A[i])
				Console.WriteLine("{0} {1}", "D", i - 38);
	}
}

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

using namespace std;
#define int long long int
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define vi vector <int>
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define piii pair< int,pair<int,int> >
#define tiii tuple <int,int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(v) v.rbegin(),v.rend()
#define endl '\n'
#define matrix vector <vector <int> >
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define NAYAN freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define N 500006
#define mod 1000000007
#define mod2 998244353
#define inf 1e17

int dp[100001];
int a[N];
int n,k;

int solve(int id)
{
    if(id==n-1)
    {
        return 0;
    }
    if(id>=n)
        return inf;
    if(dp[id]!=-1)
        return dp[id];

    dp[id]=inf;
    int i;
    for(i=1;i<=k;i++)
    {
        dp[id]=min(dp[id],solve(id+i)+abs(a[id+i]-a[id]));
    }
   
    return dp[id];
}

int32_t main()  
{
    boost
    // #ifndef ONLINE_JUDGE 
    // NAYAN
    // #endif
    
    

    cin >> n >> k;

    
    memset(dp,-1,sizeof dp);
    int i;
    
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }

    int ans=solve(0);

    cout << ans;



   


}

Measured memory_bytes: 6784
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int manju[20010];
int lis[504][2];
int fie[504][20010];
int main(){
    for(int i=0;i<504;i++){
        for(int j=0;j<20006;j++){
            fie[i][j]=2000000000;
        }
    }
    fie[0][0]=0;
    int M,N;
    cin>>M>>N;
    for(int i=0;i<M;i++)cin>>manju[i];
    for(int i=0;i<N;i++)cin>>lis[i][0]>>lis[i][1];
    for(int i=0;i<N;i++){
        for(int j=0;j<20003;j++){
            fie[i+1][j]=min(fie[i+1][j],fie[i][j]);
            if(j+lis[i][0]<20009)fie[i+1][j+lis[i][0]]=min(fie[i+1][j+lis[i][0]],fie[i][j]+lis[i][1]);
        }
    }
    int saitei=2000000001;
    for(int i=20002;0<=i;i--){
        saitei=min(saitei,fie[N][i]);
        fie[N][i]=min(fie[N][i],saitei);
    }
    sort(manju,manju+M);
    int manrui[10001]={0};
    for(int i=M-1,j=1;0<=i;i--,j++){
        manrui[j]=manrui[j-1]+manju[i];
    }
    int ans=0;
    for(int i=0;i<=10001;i++)ans=max(ans,manrui[i]-fie[N][i]);
    /*

    for(int i=0;i<20;i++)printf("[%d]",manrui[i]);
    puts("");
    for(int i=0;i<20;i++)printf("[%d]",fie[N][i]);
    puts("");
    */

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

Measured memory_bytes: 40656
s = input()
c = 0

if len(s) % 2 == 0:
    for i in range(len(s)//2,len(s)):
        if s[i] == s[-i-1]:
            pass
        else:
            c += 1
            
else:
    for i in range(len(s)//2 + 1,len(s)):
        if s[i] == s[-i-1]:
            pass
        else:
            c += 1
            
print(c)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  string a,b,c;
  cin >> a >> b >> c;
  string ans = "";
  ans += a[0]-'a'+'A';
  ans += b[0]-'a'+'A';
  ans += c[0]-'a'+'A';
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = n; i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
	char c;
	cin >> c;
	if (islower(c)) cout << 'a' << endl;
	else cout << 'A' << endl;
	return 0;
}

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

int main()
{
  int a1, a2, a3, t;
  cin >> a1 >> a2 >> a3;
  if (a1 > a2) { t = a1; a1 = a2; a2 = t; }
  if (a2 > a3) { t = a2; a2 = a3; a3 = t; }
  if (a1 > a2) { t = a1; a1 = a2; a2 = t; }
  cout << a1 << ' ' << a2 << ' ' << a3 << endl;
  return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <map>
#include <algorithm>
#include <stack>
#include <cstring>
 
#define ll long long
#define MP make_pair
#define PB push_back
#define P push
#define f first
#define se second
#define S size()
#define B begin()
#define E end()
#define rB rbegin()
#define rE rend()
#define PI acos(-1)

 
const int N = 1e5 + 100;
const int M = 1e6 + 100;
const ll oo = 1e18;
 
ll n, m, k, t, q, h, a, b, d, c, e, w, x, y, z;
using namespace std;


int ai[N], bi[N], ci[N], dp[N][3];




int main() {

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



	
	dp[0][0] = ai[0], dp[0][1] = bi[0], dp[0][2] = ci[0];


	for(int i = 1; i < n; i++) {
		for(int j = 0; j < 3; j++) {

			if(j == 0){
				dp[i][j] = max(dp[i - 1][1] + ai[i], dp[i - 1][2] + ai[i]);
			}
			if(j == 1){
				dp[i][j] = max(dp[i - 1][0] + bi[i], dp[i - 1][2] + bi[i]);
			}
			if(j == 2){
				dp[i][j] = max(dp[i - 1][0] + ci[i], dp[i - 1][1] + ci[i]);
			}
			
		}
	}


	

	cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
    
    return 0;
}




Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int n,m;
int main(){
    cin>>n>>m;
    long long sum=1;
    long long ans1=1;
    long long ans2=1;
    if(abs(n-m)==1){
    	for(int i=1;i<=n;i++){
    	    ans1=ans1*i%1000000007;
		}
		for(int i=1;i<=m;i++){
    	    ans2=ans2*i%1000000007;
		}
		sum=ans1*ans2%1000000007;
		cout<<sum<<endl; 
	}else if(n==m){
		for(int i=1;i<=n;i++){
			ans1=ans1*i%1000000007;
		}
		for(int i=1;i<=m;i++){
			ans2=ans2*i%1000000007;
		}
		sum=ans1*ans2*2%1000000007;
		cout<<sum<<endl;
	}else{
		cout<<"0"<<endl;
	}
    return 0;
}

Measured memory_bytes: 256
def gen(chars):
  a = [0] * 26
  for c in chars:
    a[ord(c) - 97] += 1
  return tuple(a)

n = int(input())
m = dict()
r = 0
for s in map(gen, [input() for _ in range(n)]):
  m[s] = m.get(s, 0) + 1
  r += m[s] - 1
print(r)


Measured memory_bytes: 43024
#include<iostream>
using namespace std;
int main(){
  while(1){
    int n;
    cin>>n;
    if(!n)
      break;
    unsigned int sum=0;
    int tmp[n];
    for(int i=0;i<n;i++){
      cin>>tmp[i];
      sum+=tmp[i];
    }
    int ava=sum/n;
    int cnt=0;
    for(int i=0;i<n;i++){
      if(tmp[i]<=ava)
        cnt++;
    }
    cout<<cnt<<endl;
  }
  return 0;
}



Measured memory_bytes: 3056
S=input()
L=len(S)
a=0
b=0
c=0
for i in range(L):
    if S[i]=="a":
        a+=1
    elif S[i]=="b":
        b+=1
    elif S[i]=="c":
        c+=1

if 1>=max(a,b,c)-min(a,b,c)>=0:
    print("YES")
else:
    print("NO")

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b;
  while(cin >> a >> b && a && b){
    vary(int,v,5,0);
    v[0] += a+b;
    REP(i,1,5){
      cin >> a >> b;
      v[i] += a+b;
    }
    cout << char(distance(v.begin(),max_element(all(v))) + 'A') << " " << *max_element(all(v))<<endl;
  }
  return 0;
}

Measured memory_bytes: 3008
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define enter "\n"

typedef long long ll;



int atcoder(){
    //入力
    int h,w;
    cin >> h >> w;
    vector<string> v;
    REP(i,h){
        string tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    bool ans = true;
    
    //処理
    REP(i,h){
        REP(j,w){
            if(v[i][j] == '#'){
                if(i==0){
                    if(v[i+1][j]=='.' && (v[i][abs(j-1)]=='.' && v[i][j+1]=='.')){
                        ans=false;
                    }
                }else if(i==h-1){
                    if(v[i-1][j]=='.' && (v[i][abs(j-1)]=='.' && v[i][j+1]=='.')){
                        ans = false;
                    }
                }else{
                    if((v[i-1][j]=='.' && v[i+1][j]=='.') && (v[i][abs(j-1)]=='.' && v[i][j+1]=='.')){
                        ans = false;
                    }
                }
            }
        }
    }
    
    //出力
    if(ans) cout << "Yes" << enter;
    else cout << "No" << enter;
    return 0;
}

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


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N;
  vector<int> D(N);
  for (int i = 0; i < N; i++) {
    cin >> D[i];
  }
  cin >> M;
  vector<int> T(M);
  for (int i = 0; i < M; i++) {
    cin >> T[i];
  }
  sort(D.begin(), D.end());
  sort(T.begin(), T.end());
  int j = 0;
  for (int i = 0; i < M; i++) {
    int t = T[i];
    while (j < N && t > D[j]) {
      j++;
    }
    if (t != D[j]) {
      cout << "NO" << '\n';
      return 0;
    }
    j++;
  }
  cout << "YES" << '\n';
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void){

	int i, j,a,b;
	while(1){
		scanf("%d %d", &a,&b);
		if(a==0 && b==0){
			break;
		}
		for(i=0;i<a;i++){	/*???a????¨?b???*/
			for(j=0;j<b;j++){
			printf("#");
		}
		printf("\n");
	}
	printf("\n");
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i,n)cin >> v[i];
  vector<ll> s(n+1,0);
  rep(i,n)s[i+1] = s[i]+v[i];
  ll res = 1ll << 60;
  auto bs = [&](int left,int right,ll val,vector<ll> &k,ll g){
    while(right-left > 1){
      int mid = (right+left)/2;
      if(s[mid]-g >= (val+1)/2)right = mid;
      else left = mid;
    }
    if(abs(val-2*(s[right]-g)) <= abs(val-2*(s[left]-g)))k.push_back(s[right]-g),k.push_back(val-s[right]+g);
    else k.push_back(s[left]-g),k.push_back(val-s[left]+g);
  };
  for(int i = 2;i < n-1;i++){
    ll l = s[i],r = s[n]-s[i];
    vector<ll> a;
    bs(1,i,l,a,0);
    bs(i+1,n,r,a,l);
    ll mn = 0;
    rep(g,4)rep(gg,4)if(g != gg)mn = max(mn,abs(a[g]-a[gg]));
    res = min(res,mn);
  }
  cout << res << endl;



  return 0;
}

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

int main()
{
	ll n;
	cin >> n;
	ll ans = 0;
	ans += n/11*2;
	n%=11;
	if(n>6)ans+=2;
	else if(n)ans ++;	
	cout << ans << endl;
}


Measured memory_bytes: 3644
#include <iostream>
using namespace std;
int main()
{
	int N,price;
		while(cin>>N){
		if(N==0) break;
			for(int i=0;i<9;i++){
			cin>>price;
			N=N-price;
			}
			cout<<N<<endl;
		}
	return 0;
}

Measured memory_bytes: 1160
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class CColoringColorfully {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            int nbChanges = solve1(s);
            out.println(nbChanges);
        }

        private int solve1(String s) {
            return Math.min(solve1(s, s.length() - 1, s.charAt(s.length() - 1) == '0'),
                    solve1(s, s.length() - 1, s.charAt(s.length() - 1) == '1'))
                    ;
        }

        private int solve1(String s, int pos, boolean endWith0) {
            if (pos == 0) {
                return s.charAt(0) == '0' == endWith0 ? 0 : 1;
            }

            int nbChanges1 = solve1(s, pos - 1, !endWith0);
            if ((s.charAt(pos) == '0') != endWith0)
                nbChanges1++;

            return nbChanges1;
        }

    }
}



Measured memory_bytes: 42148
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N, K;
  cin>>N>>K;

  Int num = (N-1) * (N-2) / 2;
  if(K > num){
    cout<<-1<<endl;
    return 0;
  }

  Int m = 0;
  vector<vector<Int> > G(N);
  for(Int i=1;i<N;i++) G[0].push_back(i), m++;

  for(Int i=1;i<N && num != K;i++)
    for(Int j=i+1;j<N && num != K;j++){
      G[i].push_back(j);
      m++;
      num--;
    }


  cout<<m<<endl;
  for(Int i=0;i<N;i++)
    for(Int to:G[i]) cout<<i+1<<" "<<to+1<<endl;

  return 0;
}


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

int kaijo(int n){
  int res=1;
  while (n>1){
    res*=n;
    n--;
  }
  return res;
}

int order(vector<int> &v, set<int> s, int index){
  if (index==v.size()) return 0;
  int count=0;
  for (int i: s){
    if (v[index]==i){
      s.erase(v[index]);
      return count*kaijo(v.size()-index-1)+order(v,s,index+1);
    }
    else count++;
  }
}

int main(){
  int n;
  cin>> n;
  vector<int> p(n),q(n);
  for (int i=0; i<n; i++) cin>>p[i];
  for (int i=0; i<n; i++) cin>>q[i];
  set<int> s;
  for (int i=1; i<=n; i++) s.insert(i);
  cout<< abs(order(p,s,0)-order(q,s,0)) <<endl;
}

Measured memory_bytes: 256
// from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
      r: i32
    };
    println!("{}", 3 * r * r)
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define inf 1ll<<62
#define N 20
#define int long long
using namespace std;

int n,a[N];

int dfs(int l,int r,int lp,int rp){
	if(l>r)return 0;
	int ans=inf;
	for(int j=l;j<=r;j++)
		ans=min(ans,dfs(l,j-1,lp,lp+rp)+dfs(j+1,r,lp+rp,rp)+(lp+rp)*a[j]);
	return ans;
}

signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	printf("%lld",a[1]+a[n]+dfs(2,n-1,1,1));
}

Measured memory_bytes: 256
main :: IO ()
main = do
  [a,b,k] <- map read . words <$> getLine
  putStrLn $ takahashi a b k

takahashi :: Int -> Int -> Int -> String
takahashi a b 0 = (show a) ++ " " ++ (show b)
takahashi a b k = aoki (a`div`2) (b+(a`div`2)) (k-1)

aoki :: Int -> Int -> Int -> String
aoki a b 0 = (show a) ++ " " ++ (show b)
aoki a b k = takahashi (a+(b`div`2)) (b`div`2) (k-1)

Measured memory_bytes: 508
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
    int d,n,ans=1;
    scanf("%d%d",&d,&n);
    for(int i=1;i<=d;i++)
        ans*=100;
    if(n==100)
        ans*=101;
    else
    ans*=n;
    printf("%d\n",ans);
    return 0;
}


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

#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define REP(i, n) for (long long i = 0; i < (n); i++)
const ll INF = 1LL << 60;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
};
ll modpow(ll m, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        ll t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
signed main() {
    ll n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    ll l = (n * m) / __gcd(n, m);
    if (s[0] != t[0]) {
        cout << -1 << endl;
        return 0;
    }
    map<ll, ll> cnt;
    map<ll, ll> cnt2;
    for (int i = 1; i < n; i++) {
        cnt[(l / n) * i + 1]++;
        cnt2[(l / n) * i + 1] = i;
    }
    for (int i = 1; i < m; i++) {
        if (cnt[(l / m) * i + 1] > 0) {
            if (s[cnt2[(l / m) * i + 1]] != t[i]) {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << l << endl;
}

Measured memory_bytes: 18892
import math
def factoring(n,dict_count = {}):
    sup = math.floor(pow(n,1/2))
    n_new = n
    for i in range(2,sup + 1):
        if n % i == 0:
            n_new = n // i
            if i in dict_count:
                dict_count[i] += 1
            else:
                dict_count[i] = 1
            break
    if n == n_new:
        if n_new in dict_count:
            dict_count[n_new] += 1
        else:
            dict_count[n_new] = 1
        return sorted(list(dict_count.items()))
    return factoring(n_new,dict_count)
N,P = map(int,input().split())
result = factoring(P)
ans = 1
for e in result:
  ans *= pow(e[0],e[1] // N)
print(ans)

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

const long long MOD = 998244353;

int main() {
    int N, M, K;
    std::cin >> N >> M >> K;

    auto pow = [](long long a, int n) {
        long long res = 1;
        for (; n; n >>= 1) {
            if (n & 1) res = res * a % MOD;
            a = a * a % MOD;
        }
        return res;
    };

    std::vector<long long> fact(N + 1), inv_fact(N + 1);
    fact[0] = 1;
    for (int i = 1; i <= N; i++)
        fact[i] = fact[i - 1] * i % MOD;
    inv_fact[N] = pow(fact[N], MOD - 2);
    for (int i = N; i > 0; i--)
        inv_fact[i - 1] = inv_fact[i] * i % MOD;

    auto comb = [&fact, &inv_fact](int n, int r) {
        if (n < r) return 0LL;
        long long tmp = inv_fact[n - r] * inv_fact[r] % MOD;
        return fact[n] * tmp % MOD;
    };

    long long ans = 0;
    for (int i = 0; i <= K; i++) {
        ans += (comb(N - 1, i) * M) % MOD * pow(M - 1, N - i - 1) % MOD;
        ans %= MOD;
    }

    std::cout << ans << "\n";
}

Measured memory_bytes: 6340
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int i,ans=0;
    string s;
    cin>>s;
    for (i=0;i<4;i++)
    {
        if (s[i]=='+')
            ans++;
        else
            ans--;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define ff first
#define ss second
#define BASE 1000000000
ll n,k,ans=0;
vector<vector<pair<ll,ll> > > testm;
#define ss second
void solve(ll curr, ll is_h,vector<bool> hon) {
    vector<bool> hon2 = hon;
    if(curr<n) {
        hon2[curr+1] = 1;
        solve(curr+1,1,hon2);
        if(is_h) {
            hon2[curr]=0;

            solve(curr,!is_h,hon2);
        }
        return;
    }
    REP(_,2) {
        ll f=true;
        hon[n]=_;
        FOR(i, 1, n + 1) {
            if (hon[i] && f)
                REP(j, testm[i].size()) {
                    if (f)
                        if (hon[testm[i][j].ff] != testm[i][j].ss) {
                            f = false;
                            break;
                        }
                }
        }
        if (f) {
            ll c = 0;
            FOR(i, 1, n + 1) {
                c += hon[i];
            }
            ans = max(c, ans);
        }
    }
}
int main() {

    cin>>n;
    testm.resize(n+1);
    FOR(i,1,n+1) {
        cin>>k;
        testm[i].resize(k);
        REP(j,k) {
            cin>>testm[i][j].ff>>testm[i][j].ss;
        }
    }
    vector<bool> hon(n+1,0);
    hon[1]=1;
    solve(1,1,hon);
    cout<<ans;
}

Measured memory_bytes: 256
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,n) for(int i=0;i<n;i++)
#define lop(i,a,b) for(int i=a;i<=b;i++)
#define int long long int
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
#define mp make_pair
#define sz(a) int((a).size())
#define pb push_back
#define tr(container, it) for(auto it = container.begin(); it != container.end(); it++)
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define so(v) sort(all(v))
#define sod(v) sort(allr(v))
#define mfind(c, element) (c.find(element) != c.end())
#define gfind(c, element) (find(all(c),element) != c.end())
#define gfindindex(c, element) (find(all(c),element)-c.begin())
#define vp(x) cout << #x << " --> " << x << endl;
#define cp1(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define cpp1(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define ccp1(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define bsnp np3(low,high,mid);
#define hmm1 high=mid-1;
#define lmp1 low=mid+1;
#define hmp1 high=mid+1;
#define lmm1 low=mid-1;
#define fi first
#define se second
#define endl "\n"
#define np1(x) cout<<#x<<"="<<x<<'\n'
#define np2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define np3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};//comparison used for sorting set<pair<i,i>,cmp>
bool myComparison(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
//increasing ordr basedd on 2nd
};
int n,m;
vvi edges;
vector<bool> visited;
int sz;
void dfs(int c)
{
    visited[c]=true;
    sz++;
    for(auto u:edges[c])
    {
        if(!visited[u])
        dfs(u);
    }
}
main()
{ 
IOS;

cin>>n>>m;
int x,y;
edges.clear();visited.clear();
edges.resize(n+1);
visited.resize(n+1,false);
map<pii,int> M;
loop(i,m)
{
    cin>>x>>y;
    if(M[{x,y}]) continue;
    M[{x,y}]=1;
    M[{y,x}]=1;
    edges[x].pb(y);
    edges[y].pb(x);
    
}
int ans=0;
lop(i,1,n)
if(!visited[i])
{sz=0;dfs(i);ans=max(ans,sz);}

cout<<ans<<endl;


return 0;
}

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

using namespace std;
const long long  mod =1e9+7;
const int maxn = 1e5 + 100;
long long a[maxn][5];
char str[maxn];
long long ans = 0;
int main()
{
    while(~scanf("%s",str + 1))
    {
        int len = strlen(str + 1);
        a[0][1]=a[0][2]=a[0][3]=0;
        long long x=1;
        for(int i=1; i<=len; i++)
        {
            if(str[i]=='?')
            {
                a[i][1]=(a[i-1][1]*3+ x          )%mod;
                a[i][2]=(a[i-1][2]*3+a[i-1][1]  )%mod;
                a[i][3]=(a[i-1][3]*3+a[i-1][2]  )%mod;
                x=(x*3)%mod;
            }
            else if(str[i]=='A')
            {
                a[i][1]=(x   +a[i-1][1])%mod;
                a[i][2]=a[i-1][2];
                a[i][3]=a[i-1][3];
            }
            else if(str[i]=='B')
            {
                a[i][1]=a[i-1][1];
                a[i][2]=(a[i-1][1]+a[i-1][2])%mod;
                a[i][3]=a[i-1][3];
            }
            else if(str[i]=='C')
            {
                a[i][1]=a[i-1][1];
                a[i][2]=a[i-1][2];
                a[i][3]=(a[i-1][2]+a[i-1][3])%mod;
            }
        }
        printf("%lld\n",a[len][3]%mod);

    }
    return 0;
}


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

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;

	vector<vector<char>> matrix(n, vector<char>(m));

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

	vector<int> emptyRows(n);
	for (int i = 0; i < n; i++)
	{
		bool isPossible = true;
		for (int j = 0; j < m; j++)
		{
			if (matrix[i][j] == '#')
			{
				isPossible = false;
				break;
			}
		}
		if (isPossible)
		{
			emptyRows[i] = 1;
		}
	}

	vector<int> emptyCols(m);
	for (int j = 0; j < m; j++)
	{
		bool isPossible = true;
		for (int i = 0; i < n; i++)
		{
			if (matrix[i][j] == '#')
			{
				isPossible = false;
				break;
			}
		}

		if (isPossible)
		{
			emptyCols[j] = 1;
		}
	}

	for (int i = 0; i < n; i++)
	{
		if (emptyRows[i])
		{
			continue;
		}

		for (int j = 0; j < m; j++)
		{
			if (!emptyCols[j])
			{
				cout << matrix[i][j];
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 256