akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=310;
int n,minl[N][N];
bool imp[N][N];
ll ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			scanf("%d",&minl[i][j]);
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++){
				if(minl[i][k]+minl[k][j]<minl[i][j]){
//					cout<<i<<" "<<j<<" "<<k<<endl;
					puts("-1\n");
					return 0;
				}
				if(i==j||i==k||j==k) continue;
				if(minl[i][k]+minl[k][j]==minl[i][j]) imp[i][j]=1; 
			}
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++) if(!imp[i][j]) ans+=minl[i][j];
	cout<<ans<<endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define R freopen("555input.txt","r",stdin);
#define W freopen("output.txt","w",stdout);
#define N 100005
struct num
{
    int x,id;
    bool operator<(const num&T)
    {
        if(x==T.x)return T.id<id;
        return x<T.x;
    }
}a[3*N];
LL sum1,sum2,ans;
int i,n;
int main()
{
    
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i].x);
        a[i].id=1;
    }
    for(;i<2*n;i++)
    {
        scanf("%d",&a[i].x);
        a[i].id=2;
    }
    for(;i<3*n;i++)
    {
        scanf("%d",&a[i].x);
        a[i].id=3;
    }
    sort(a,a+3*n);
    LL cur1=0,cur3=n;
    for(i=0;i<3*n;i++)
    {
        if(a[i].id==1)
        cur1++;
        else if(a[i].id==3)cur3--;
        else ans+=cur1*cur3;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 2560
class UnionFind():
    def __init__(self,size):
        self.table=[i for i in range(size)]
        self.rank=[0 for _ in range(size)]
        
    def find(self,x):
        if self.table[x]==x:
            return x
        else:
            self.table[x]=self.find(self.table[x])
            return self.table[x]

    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return

        if self.rank[x]<self.rank[y]:
            self.table[x]=y
        else:
            self.table[y]=x
            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1
                
    def same(self,x,y):
        return self.find(x)==self.find(y)
            
            

n,m=map(int,input().split())
p=list(map(int,input().split()))
un=UnionFind(n)

for _ in range(m):
    x,y=map(int,input().split())
    un.union(x-1,y-1)

ans=n

for i in range(n):
    if un.find(p[i]-1)!=un.find(i):
        ans-=1
print(ans)


Measured memory_bytes: 14452
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map{it.toInt()}

    var cnt = 0

    for (v in a) {
        if (v == cnt + 1) {
            cnt++
        }
    }

    if (cnt == 0) {
        println(-1)
    } else {
        println(N - cnt)
    }
}


Measured memory_bytes: 84708
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i,m,n) for(int i = m;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
int main() {
  lli A,B=1,C=0,D=0,F=0;
  cin >> A;
  vector<int>P{1,2,4,8,16,32,64,128};
  rep(i,1,9){
    if(P[i]>A){
      Out(P[i-1]);
      break;
  }
  }
}

Measured memory_bytes: 256
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
# endregion
N = ri()
d = [2 ** i for i in range(10)][::-1]
for i in d:
    if i <= N:
        print(i)
        exit()


Measured memory_bytes: 65772
n,k = map(int,input().split())
ans = 0
mod = 10**9+7
for i in range(k,n+2):
  if i == n+1:
    ans += 1
  else:
    ans += (n*(n+1)//2)%mod-((n-i)*(n-i+1)//2)%mod-(((i-1)*i)//2)%mod+1
print(ans%mod)

Measured memory_bytes: 9204
// In the name of God

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	vector<string> k = {"ABC", "ARC"};
	string s;
	cin >> s;
	cout << k[(find(k.begin(), k.end(), s) - k.begin()) ^ 1];
	
	return 0;
}


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

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 2 * 100 * 100 + 17;

ll n, p[MAXN], b[MAXN], a[MAXN], fen[MAXN];

void add(int x) {
	for (;x <= n; x += x & -x)
		fen[x]++;
}
int get(int x) {
	int res = 0;
	for (; x; x -= x & -x)
		res += fen[x];
	return res;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> p[i], a[p[i] + 1]++, b[1]++, b[p[i]]--;
	for (int i = 1; i <= n; i++)
		a[i] += a[i - 1], b[i] += b[i - 1];
	for (int i = n; i; i--) {
		int t = get(p[i]);
		a[p[i]] -= t;
		b[p[i]] -= n - i - t;
		add(p[i]);
	}
	for (int i = 1; i <= n; i++)
		cout << a[i] + i * (n + 1) << ' ';
	cout << endl;
	for (int i = 1; i <= n; i++)
		cout << b[i] + (n - i + 1) * (n + 1) << ' ';
	cout << endl;
	return 0;
}


Measured memory_bytes: 1280
import java.util.*;

public class Main {

    private static final int MOD = 1_000_000_007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S1 = sc.next();
        String S2 = sc.next();
        System.out.println( solve(N, S1, S2) );
    }

    private static int solve(int N, String S1, String S2) {
        long ans;
        boolean prev_tate;
        int i;
        if( S1.charAt(0) == S2.charAt(0) ) {
            //　縦
            prev_tate = true;
            i = 1;
            ans = 3;

        } else {
            // 横
            prev_tate = false;
            i = 2;
            ans = 6;
        }

        while( N > i ) {
            if( S1.charAt(i) == S2.charAt(i) ) {
                if( prev_tate ) {
                    ans = ans * 2 % MOD;
                }
                i++;
                prev_tate = true;

            } else {
                if( prev_tate ) {
                    ans = ans * 2 % MOD;
                } else {
                    ans = ans * 3 % MOD;
                }
                i = i+2;
                prev_tate = false;
            }
        }
        return (int)ans;
    }
}


Measured memory_bytes: 21844
import sys
readlines = sys.stdin.readlines
write = sys.stdout.write
def solve():
    mp = {}
    for line in readlines():
        v = int(line)
        mp[v] = mp.get(v, 0) + 1
    ma = max(mp.values())
    ans = [k for k, v in mp.items() if v == ma]
    ans.sort()
    write("\n".join(map(str, ans)))
    write("\n")
solve()


Measured memory_bytes: 5604
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<cstring>
#include<sstream>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}


int main()
{
    int a, b,c;
    cin >> a >> b >> c;
    if (b-a==c-b) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=111;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,m,f[maxn][maxn][2];
char mp[maxn][maxn];
int main(){
	n=read();m=read();
	FOR(i,1,n) scanf("%s",mp[i]+1);
	MEM(f,0x3f);
	if(mp[1][1]=='#') f[1][1][1]=1;
	else f[1][1][0]=0;
	FOR(i,1,n) FOR(j,1,m){
		if(i==1 && j==1) continue;
		if(i!=1){
			if(mp[i][j]=='#') f[i][j][1]=min(f[i][j][1],min(f[i-1][j][1],f[i-1][j][0]+1));
			else f[i][j][0]=min(f[i][j][0],min(f[i-1][j][1],f[i-1][j][0]));
		}
		if(j!=1){
			if(mp[i][j]=='#') f[i][j][1]=min(f[i][j][1],min(f[i][j-1][1],f[i][j-1][0]+1));
			else f[i][j][0]=min(f[i][j][0],min(f[i][j-1][1],f[i][j-1][0]));
		}
	}
	printf("%d\n",min(f[n][m][0],f[n][m][1]));
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	int a, b, m, i, j, k, aa, bb, cc, ans;
	cin >> a >> b >> m;
	vector<int> ca(a), cb(b);
	for (i = 0; i < a; i++) cin >> ca[i];
	for (i = 0; i < b; i++) cin >> cb[i];
	aa = *min_element(ca.begin(), ca.end());
	bb = *min_element(cb.begin(), cb.end());
	ans = aa + bb;

	while (m--) {
		cin >> aa >> bb >> cc;
		ans = min(ans, ca[aa - 1] + cb[bb - 1] - cc);
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

int main()
{
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int longest_dist  = 0;
    int prev = -1;
    ll pathlen = 0;
    for (int i = 0; i < n; i++) {
        int j = (i + 1) % n;
        int n = a[i];
        int m = a[j];

        if (n > m) {
            m += k;
        }
        int dist = abs(m - n);
        if (dist > longest_dist) {
            longest_dist  = dist;
        }
        prev = dist;
        pathlen += dist;
    }
    pathlen -= longest_dist;
    
    cout << pathlen << endl;
    return 0;
}


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

int main(){
    int a, b;
    cin >> a >> b;
    int ans = a + b;
    ans = max(ans, a - b);
    ans = max(ans, a*b);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

struct edge{
    ll s,t,w;
    edge(ll s, ll t, ll w) : s(s), t(t), w(w) {}

    bool operator<(const edge &another){
        return w < another.w;
    }
};

// ll check_d[300][300]={};
// // ll mat_dij[300][300];
// set<ll> neighbors[300];
// ll dijkstra(ll from, ll to, ll n){
//     rep(i,n)rep(j,n)mat_dij[i][j]=1LL<<60;
//     rep(i,n)mat_dij[i][i]=0;
//     priority_queue<ll> pq;
//     pq.push(from);
//     do{
//         ll now = pq.top();
//         pq.pop();
//         for(auto i:neighbors[now]){
//             if(mat_dij[from][i]>check_d[from][now]+check_d[now][i]){
//                 mat_dij[from][i]=check_d[from][now]+check_d[now][i];
//                 mat_dij[i][from]=mat_dij[from][i];
//                 DEBUG{printf("push : %lld\n",i);}
//                 pq.push(i);
//             }
//         }
//     }while(!pq.empty());
//     return mat_dij[from][to];
// }

int main(void) {
    ll n;
    cin>>n;
    ll d[n][n];
    ll min_d[n][n];
    rep(i,n)rep(j,n){
        cin >>d[i][j];
        min_d[i][j]=d[i][j];
    }
    rep(k,n)rep(i,n)rep(j,n){
        min_d[i][j]=min(min_d[i][j],min_d[i][k]+min_d[k][j]);
    }
    rep(i,n)rep(j,n){
        if(d[i][j]!=min_d[i][j]){
            cout << -1 << endl;
            return 0;
        }
    }
    ll res=0;
    rep(i,n)rep(j,n){
        ll tmp=1LL<<60;
        rep(k,n){
            if(k==i||k==j)continue;
            tmp=min(tmp, d[i][k]+d[k][j]);
        }
        if(tmp>d[i][j])res+=d[i][j];
    }
    res/=2;
    cout << res << endl;
    return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

const int maxn = 2e5 + 7;
const int mod = 998244353;

char s[maxn];
set<char> ss;

int main()
{
	scanf("%s",s);
	for(int i=0;i<3;i++)
		ss.insert(s[i]);
	printf("%s\n",ss.size()==2?"Yes":"No");
	return 0;
}




Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
 
#define $(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define pii pair<int, int>
#define pb push_back
#define vec vector
#define beg begin
#define dbg(x) cout << #x << " = " << x << endl;
 
template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}
 
template<class T> istream& operator>>(istream &str, vector<T> &a) {
    for (auto &i : a) {
        str >> i;
    }
    return str;
}
 
template<class T> ostream& operator<<(ostream &str, pair<T, T> &a) {
    str << a.first << " " << a.second;
    return str;
}
 
template<class T> istream& operator>>(istream &str, pair<T, T> &a) {
    str >> a.first >> a.second;
    return str;
}
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();    
    return 0;
}
 
const int MOD = 998244353, MAXN = 5000 + 10, INF = 1e18 + 10, BASE = 37; 
 
void solve() {
    int n, s;
    cin >> n >> s;
    vec<int> a(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }

    vec<vec<int>> dp(n + 2, vec<int>(s + 2));
    dp[0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= s; ++j) {
            dp[i][j] = dp[i - 1][j] * 2 % MOD;
            if (j - a[i] >= 0) {
                dp[i][j] = (dp[i][j] + dp[i - 1][j - a[i]]) % MOD;
            }
        }
    }

    cout << dp[n][s] << endl;
}

Measured memory_bytes: 73624
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) x.begin(),x.end()
#define db(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

  int N;
  ll T;

  cin>>N>>T;

  ll mincost=INF;
  ll ct=0;
  ll benefit=0;

  rep(i,N){
    ll cost; cin >> cost;
    mincost=min(mincost,cost);
    if(cost-mincost>benefit){
      benefit=cost-mincost;
      ct=1;
    }
    else if(cost-mincost == benefit){
      ct++;
    }
  }

  cout << ct <<"\n";

}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#ifndef ONLINE_JUDGE
#define OJ \
    freopen("input.txt", "r", stdin); \
    //freopen("output.txt", "w", stdout);
#else
#define OJ ;
#endif
#define fo(int, i, l, r) for ( int i = l ; i < r ; ++ i)
#define srtV(a) sort(a.begin(),a.end())
void solve()
{
    string s,t;
    cin>>s;
    cin>>t;
    int k=s.size()-t.size()+1,i;
    int ans=t.size();
    for(int i=0;i<k;++i)
    {
        int curAns=0;
        for(int j=0;j<t.size();++j)
        {
            if(s[i+j]!=t[j])
                curAns++;
        }
        ans=min(ans,curAns);
    }
    cout<<ans<<"\n";
}
signed main()
{
    OJ
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //int _t;cin>>_t;while(_t--)
    solve();
    return 0;
}

Measured memory_bytes: 3656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
  static InputReader in;
  static PrintWriter out;
  
  static class Solution {
    void solve() throws IOException {
      int[] height = new int[10];
      int first;
      int second;
      int third;
      
      
      height[0] = in.nextInt();
      int max = height[0];
      int memmax = 0;
      
      for (int i = 1; i < 10; i++) {
        height[i] = in.nextInt();
        max = Math.max(max, height[i]);
        if (max == height[i]) {
          memmax = i;
        }
      }
      first = max;
      
      height[memmax] = -1;
      max = height[0];
      memmax = 0;
      for (int i = 1; i < 10; i++) {
        max = Math.max(max, height[i]);
        if (max == height[i]) {
          memmax = i;
        }
      }
      second = max;
      
      height[memmax] = -1;
      max = height[0];
      memmax = 0;
      for (int i = 1; i < 10; i++) {
        max = Math.max(max, height[i]);
        if (max == height[i]) {
          memmax = i;
        }
      }
      third = max;
      
      out.println(first);
      out.println(second);
      out.println(third);
      
//      End solve()
    }
//    End Solution
}


  public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
}


  static class InputReader {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }

    public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    }

    public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken());
    }

    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    }

    public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    }

  }

}

Measured memory_bytes: 24300
n = list(map(int,input().split()))

sum = 0
num = 0
nm = [1,0,-1]
c = n[3]
cu =0


for i in n:
    if c == 0:
        break
    if i > c:
        sum+= nm[num]*c
        break
    if i <= c:
        sum += nm[num] * i
        c-=i
        num+=1




print(sum)


Measured memory_bytes: 9192
# coding:utf-8
import heapq

N, M = map(int, input().split(' '))
A_rev = [int(n) * -1 for n in input().split(' ')]

heapq.heapify(A_rev)

for i in range(M):
    d, m = divmod(heapq.heappop(A_rev), 2)
    if m != 0: d += 1
    heapq.heappush(A_rev, d)

print(-sum(A_rev))

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

using namespace std;

#define debug(x) cout << #x << "::" << x << endl;
#define debug2(x, y) cout << #x << "::" << x << " " << #y << "::" << y << endl;
#define debug3(x, y, z) cout << #x << "::" << x << " " << #y << "::" << y <<" "<< #z << "::" << z << endl;

#define For(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;
const ll mod = 1e9 + 7;
const int MAX = 5 * 1e3 + 5;
typedef pair<int, int> pii;

void add(ll &a, ll b)
{
    a = (a + b) % mod;
    if (a < 0) a += mod;
}

int main() {

    int n;
    cin>>n;

    vector<vector<int>> a(n,vector<int>(n));

    For(i,0,n){
        For(j,0,n) cin>>a[i][j];
    }
    int perm = 1<<n;
    vector<ll> dp(perm+1);
    dp[0] = 1;
    For(mask,0,perm-1){
        int men = __builtin_popcount(mask);
        //debug(men);
        For(women,0,n){
            if(a[men][women] && !(mask&(1<<women))) {
                add(dp[mask|1<<women],dp[mask]);
            }
        }
    }

    cout<<dp[perm - 1]<<endl;

    return 0;

}

Measured memory_bytes: 16640
#include<iostream>

using namespace std;

int main(){
  int N;
  int count;

  cin >> N;
  count = 0;

  for(int i=1; i<=N; i++){
    int div_c = 0;
    if(i%2 == 0) continue;

    for(int j=1; j<=i; j++){
      if(i%j == 0) div_c++;
      if(div_c > 8) break;
    }

    if(div_c == 8) count++;
  }

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {

			int n = sc.nextInt();
			int m = sc.nextInt();

			int[] wrongCounts = new int[n];
			boolean[] corrects = new boolean[n];
			int totalAC = 0;

			for( int i = 0 ; i < m ; i++ ) {
				int index = sc.nextInt() - 1;
				String ans = sc.next();

				if ( corrects[index]) {
					// no count
				}
				else if ( ans.equals("WA")) {
					wrongCounts[index]++;
				}
				else if ( ans.equals("AC")) {
					corrects[index] = true;
					totalAC++;
				}
			}

			//calc total Wrong count
			//				int totalWrong = Arrays.stream(wrongCounts).sum();
			int totalWrong = 0;
			for(int i = 0 ; i < n ; i++ ) {
				if ( corrects[i]) {
					totalWrong += wrongCounts[i];
				}
			}

			System.out.println(String.format("%d %d", totalAC, totalWrong));

		}
	}
}

Measured memory_bytes: 66208
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
def pf(x):
  ret={}
  for i in range(2,int(x**0.5)+1):
    while x%i==0:
      ret[i]=ret.get(i,0)+1
      x//=i
  if x>1:
    ret[x]=1
  return ret

def make_divisors(n):
  divisors=[]
  for i in range(1,int(n**0.5)+1):
    if n%i==0:
      divisors.append(i)
      if i!=n//i:
        divisors.append(n//i)

  divisors.sort()
  return divisors

D1=make_divisors(n)
D2=pf(n-1)
ans=0
cur=1
for i in D2.keys():
  cur*=D2[i]+1
ans+=cur

for i in D1:
  if i!=1:
    nn=n
    chk=False
    while nn%i==0:
      nn//=i
      chk=True
    if chk and nn%i==1:
      ans+=1
print(ans-1)




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

int main(){
  int n,a,b;
  cin>>a>>b;
  if(b==100)n=a*1000+b;
  else if(b>9)n= a*100+b;
  else n= a*10+b;
  for(int i=4;i<1000;i++){
	if(i*i == n){
      cout<<"Yes"<<endl;
      return 0;
    }else if(i*i >n) break;
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 256
N = int(input())
A_list = [0]
for i in range(N):
    A_list.append(int(input()))
A_flag = [False] * len(A_list)

idx = 1
count = 1
while True:
    if A_list[idx] == 2:
        print(count)
        break
    if A_flag[idx] is True:
        print(-1)
        break
    A_flag[idx] = True
    idx = A_list[idx]
    count += 1


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

int main(){
    string S,T,U;
    int A,B,result;
    cin >> S >> T >> A >> B >> U;
    if(U==S){
      cout << A-1 << " "<< B << endl;
    }else if(U==T){
      cout << A << " " << B-1 << endl;
    }else{
      cout << A << " " << B << endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
const int N = 10000000;
int lp[N+1];
vector<int> pr;
ll ans[N+1];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
 

    for (int i=2; i<=N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back (i);
        }
        for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
            lp[i * pr[j]] = pr[j];
    }

    ll n;
    cin>>n;
    ll anst=0;
    rep(i,1,n+1){
        if(i==1)ans[1]=1;
        else if(lp[i]==0)ans[i]=2;
        else{
            ll calc = i/lp[i];
            ll cont=0;
            while(calc%lp[i]==0){
                calc/=lp[i];
                cont++;
            }
            ans[i] = (ans[i/lp[i]]/(cont+1))*(cont+2);
        }
        anst+=i*ans[i];
    } 
    cout<<anst<<'\n';
    return 0;  
}

Measured memory_bytes: 123256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	double a, b, x;
	cin >> a >> b >> x;
	x /= a;
	double rad = (x <= a*b/2 ? atan2(b*b, 2*x) : atan2(2*(a*b-x), a*a));
	double ans = rad / (2*acos(-1)) * 360;
	cout << fixed << setprecision(12) << ans << endl;
	return 0;
}


Measured memory_bytes: 4072
#include <cstdio>
long long n, k, a, b, c[100005];
int main() {
	int i;
	scanf("%lld%lld", &n, &k);
	while(n--) scanf("%lld%lld", &a, &b), c[a] += b;
	for(i=1; k>0; i++) k -= c[i];
	printf("%d", --i);
	return 0;
}

Measured memory_bytes: 896
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		
		Scanner s=new Scanner(System.in);
		
		int a=s.nextInt();
		int b=s.nextInt();
		int t=s.nextInt();
		
		int ans=0,cur=a;
		
		while(cur<=t) {
			ans+=b;
			cur+=a;
		}
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 23764
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;

int main() {
    int start = 0, end = 0;
    cin >> start >> end;
    while(1) {
        bool flag = false;
        for(int i = start; i <= end; i++) {
            if (i % 4  == 0 && (i % 100 != 0 || i % 400 == 0)) {
                flag = true;
                cout << i << endl;
            }
        }
        if (!flag) {
            cout << "NA" << endl;
        }
        cin >> start >> end;
        if (!start && !end) return 0;
        cout << endl;
    }
}

Measured memory_bytes: 3092
N, K = (int(i) for i in input().split())  
h = [int(i) for i in input().split()] 

cost = [0] * N 

def mincost(m):
    if m == 0:
        return 0
    else:
        minc = 10000000000000000
        for i in range(1,K+1):
            if m - i >= 0:
                minc = min(minc , cost[m - i] + abs(h[m] - h[m - i]))
        return minc

for i in range(N):
    cost[i] = mincost(i)

print(cost[N-1])


Measured memory_bytes: 52464
#include<bits/stdc++.h>
using namespace std;
#define maxn 55
int n,m;
char mat[maxn][maxn];
int check(int i,int j){
	int tot=0;
	if ((i>0)&&(mat[i-1][j]=='#')) tot++;
	if ((i<n-1)&&(mat[i+1][j]=='#')) tot++;
	if ((j>0)&&(mat[i][j-1]=='#')) tot++;
	if ((j<m-1)&&(mat[i][j+1]=='#')) tot++;
	if (!tot) return 0;
	else return 1; 
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=0; i<n; i++) scanf("%s",mat[i]);
	int ans=1;
	for (int i=0; i<n; i++)
	  for (int j=0; j<m; j++)
	  if (mat[i][j]=='#'){
	  	ans&=check(i,j);
	  	if (!ans) break;
	  }
	if (ans) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

int N,X,L[120];

int main(){
    cin>>N>>X;
    for(int i=0;i<N;i++){
        cin>>L[i];
    }
    for(int i=1;i<N;i++){
        L[i]+=L[i-1];
    }
    int ans=N+1;
    for(int i=0;i<N;i++){
        if(L[i]>X){
            ans=i+1;
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> ii;

const int N = 1e5 + 5;
int n, t;
ii a[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> t;
        a[i] = {t, i + 1};
    }
    sort(a, a + n);
    for (int i = 0; i < n; ++i) {
        cout << a[i].second << ' ';
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 1664
import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.IArray             as IA
import qualified Data.Array.IO                 as AI
import qualified Data.Array.MArray             as MA
import qualified Data.Array.ST                 as STA
import qualified Data.Array.Unboxed            as AU
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import qualified Data.Graph                    as G
import           Data.Int
import qualified Data.IntMap                   as IM
import qualified Data.IntSet                   as IS
import           Data.List
import qualified Data.Map.Strict               as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence                 as SQ
import qualified Data.Set                      as S
import           Data.Time
import qualified Data.Tree                     as T
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt :: IO Int
readInt = fst . fromJust . BS.readInt <$> BS.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readIntLists :: Int -> IO [[Int]]
readIntLists n = replicateM n readInts

readInteger :: IO Integer
readInteger = fst . fromJust . BS.readInteger <$> BS.getLine

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegerLists :: Int -> IO [[Integer]]
readIntegerLists n = replicateM n readIntegers

readStrings :: IO [String]
readStrings = map BS.unpack . BS.words <$> BS.getLine

readStringLists :: Int -> IO [[String]]
readStringLists n = replicateM n <$> readStrings

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putList :: Show a => [a] -> IO ()
putList [n     ] = put n
putList (n : ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n     ] = putStr n
putStrList (n : ns) = do
  putStr n
  putStr " "
  putStrList ns

yesNoUpper b | b         = putStrLn "YES"
             | otherwise = putStrLn "NO"

yesNo b | b         = putStrLn "Yes"
        | otherwise = putStrLn "No"

divCeiling x n | b == 0    = a
               | otherwise = a + 1
  where (a, b) = x `divMod` n

main = do
  s <- getLine
  print $ solve s

solve s = sum $ zipWith max (f s [0]) (g (reverse s) [0])

f []         acc      = reverse acc
f ('<' : ss) (a : ac) = f ss (a + 1 : a : ac)
f ('>' : ss) ac       = f ss (0 : ac)

g []         acc      = acc
g ('>' : ss) (a : ac) = g ss (a + 1 : a : ac)
g ('<' : ss) ac       = g ss (0 : ac)


Measured memory_bytes: 89468
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
#include<unordered_map>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind
#define rt (a); return (a); 
#define Pint pair<int,int>
#define Pll pair<ll,ll>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}
int n,q;
hei(ll) seg, lazy;

void aaa(int k) {
	if (lazy[k] == 0)return ;
	if (k < n - 1) {
		lazy[k * 2 + 1] += lazy[k];
		lazy[k * 2 + 2] += lazy[k];
	}
	seg[k] += lazy[k];
	lazy[k] = 0;
}

void update(int a, int b, ll x,int k,int l,int r) {
	aaa(k);
	if (a<=l && b>=r) {
		lazy[k] += x;
		aaa(k);
	}
	else if(a<r&&l<b){
		update(a, b, x, k * 2 + 1, l, (l + r) / 2);
		update(a, b, x, k * 2 + 2, (l + r) / 2, r);
		seg[k] = seg[k * 2 + 1]+seg[k * 2 + 2];
	}
}

ll query(int a,int b,int k,int l,int r){
	aaa(k);
	if (l >= b || r <= a)return 0;
	if (a <=l  && b >= r) {
		return seg[k];
	}
	ll v1 = query(a, b, k*2+1, l, (l + r) / 2);
	ll v2 = query(a, b, k*2+2, (l + r) / 2, r);
	return v1 + v2;
}

int main() {
	int n, m;
	cin >> n >> m;
	hei(llint) dp(100001, 0);
	rep(i, 0, m) {
		int a;
		cin >> a;
		dp[a-1] = -1;
	}
	if (dp[0] != -1) {
		dp[0] = 1;
		if (dp[1] != -1)dp[1] = 2;
	}
	else {
		if (dp[1] != -1)dp[1] = 1;
	}
	rep(i, 2, n) {
		if (dp[i] == -1)continue;
		if (dp[i - 1] != -1)dp[i] += dp[i - 1];
		if (dp[i - 2] != -1)dp[i] += dp[i - 2];
		dp[i] %= mod;
	}
	cout << dp[n - 1] << endl;
	return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	std::pair<int, int> a[n];
	for (int i = 0; i < n; i++) a[i] = {ri(), i};
	std::sort(a, a + n, std::greater<>());
	int64_t dp[n + 1][n + 1];
	for (auto &i : dp) for (auto &j : i) j = -1000000000000000000;
	dp[0][0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int head = i + j;
			if (head >= n) continue;
			// go left
			dp[i + 1][j] = std::max(dp[i + 1][j], dp[i][j] + (int64_t) a[head].first * std::abs(a[head].second - i));
			// go right
			dp[i][j + 1] = std::max(dp[i][j + 1], dp[i][j] + (int64_t) a[head].first * std::abs(n - 1 - j - a[head].second));
		}
	}
	int64_t res = -1;
	for (int i = 0; i <= n; i++) res = std::max(res, dp[i][n - i]);
	printf("%" PRId64 "\n", res);
	return 0;
}


Measured memory_bytes: 35048
N = gets.chomp.to_i
xs = []
ys = []

N.times do
  x, y = gets.chomp.split(" ").map(&:to_i)
  xs << x
  ys << y
end

def distance(x1, y1, x2, y2)
  Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
end

$d = []
N.times do |i|
  r = []
  N.times do |j|
    r << distance(xs[i], ys[i], xs[j], ys[j])
  end
  $d << r
end

$r = []
def walk(visited, i, deep, r)
  if deep == N - 1 then
    $r << r
    return
  end
  N.times do |index|
    if i == index || visited.include?(index) then
      next
    end
    new_visited = visited.clone
    new_visited << i
    walk(new_visited, index, deep + 1, r + ", #{index+1}")
  end
end

def fact(n)
  return 1 if n == 1
  n * fact(n-1)
end

N.times do |i|
  walk([], i, 0, "#{i+1}")
end

s = 0
$r.each do |r|
  rr = r.split(",").map(&:to_i).map{|n| n-1}
  rr.size.times do |i|
    break if i == N - 1
    s += distance(xs[rr[i]], ys[rr[i]], xs[rr[i+1]], ys[rr[i+1]])
  end
end

puts s / (fact(N))

Measured memory_bytes: 8060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
lint lcm(lint a,lint b){
      return a/__gcd(a,b)*b;
  }
    
  int main(){
     lint N,M;
     cin>>N>>M;
     lint ans=1;
     if(abs(N-M)>1)cout<<0;
     else{
         rep(i,N){
                ans*=(i+1);
                ans%=MOD;
         }
          rep(i,M){
                ans*=(i+1);
                ans%=MOD;
         }
         if(N==M)ans*=2;
         ans%=MOD;
         cout<<ans;
     }
  }
  

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#define llint long long

using namespace std;

llint a, b;

llint calc(llint x)
{
	llint ret = (x+1)/2%2;
	for(int i = 1; i < 45; i++){
		llint r = x%(1LL<<(i+1));
		if(r < (1LL<<i)) continue;
		llint b = (r - (1LL<<i) + 1) % 2;
		ret |= (b << i);
	}
	return ret;
}

int main(void)
{
	cin >> a >> b;
	cout << (calc(b) ^ calc(a-1)) << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7

N, A, B = map(int, read().split())

def solve(N, A, B):
    if A > B:
        A, B = B, A
    if A == 1:
        return pow(2, N, MOD)
    dp1 = np.zeros((N, B), dtype=np.int64)  # その時点で確定している長さ集計
    dp2 = np.zeros((N, B), dtype=np.int64)  # もし右に十分な 0 があったとしたときの、長さ集計
    dp1_sum = np.zeros(N, dtype=np.int64)
    ans = 0
    for n in range(N):
        # そこで初めての 1 がたつ場合
        if n < A:
            dp1[n, 1] += 1
        else:
            if n + 1 < B:
                dp1[n, n + 1] += 1
        # ひとつ手前から 1 を立てて遷移した場合
        if n > 0:
            dp1[n, 1:] += dp1[n - 1, :-1]
        # 使えない個数の 0 をはさんで遷移した場合
        dp1[n, 1] += dp1_sum[max(0, n - A):n - 1].sum() % MOD
        # たくさんの個数の 0 をはさんで遷移した場合
        if n >= A + 1 < B:
            dp1[n, A + 1:B] += dp2[n - A - 1, 0:B - (A + 1)]
        dp1[n] %= MOD
        # 右を 0 埋めして足せるなら答に足す
        dp1_sum[n] = dp1[n].sum() % MOD
        if (N - n - 1) < A:
            ans += dp1_sum[n]
            ans %= MOD
        else:
            # あと N - n - 1 のびても B にならないような範囲
            M = B - (N - n - 1)
            if M > 0:
                ans += dp1[n, :M].sum() % MOD
        dp2[n] += dp1[n]
        dp2[n, 1:] += dp2[n - 1, :-1]
        dp1[n] %= MOD
        dp2[n] %= MOD
    x = pow(2, N, MOD) - ans
    return x % MOD

print(solve(N, A, B))

Measured memory_bytes: 417416
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, k; cin >> n >> k;
	int a = 0, b = 0;
	rep(i, n+1) {
		if (i == 0)continue;
		if (i%k == 0)a++;
		else if (k % 2 == 0 && i % k == k / 2)b++;
	}
	cout << a * a*a + b * b*b << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = str(input())
t = str(input())

if s == t:
    print(n)
    exit()

for i in range(1, n):
    s_ = s[i:n]
    t_ = t[0:n-i]
    if s_ == t_:
        ans = s[:i]+t
        print(len(ans))
        exit()
else:
    print(2*n)


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

using namespace std;

int main(){
	int N,M,C; cin>>N>>M>>C;
  vector<int> b(M);
  vector<vector<int>> a(N,vector<int>(M));
	for(int i=0;i<M;i++) cin>>b[i];
  for(int i=0;i<N;i++){
  	for(int j=0;j<M;j++){
    	cin>>a[i][j];
    }
  }
  int tmp=0,ans=0;
  for(int i=0;i<N;i++){
  	for(int j=0;j<M;j++){
    	tmp+=a[i][j]*b[j];
    }
    tmp+=C;
    if(tmp>0) ans++;
    tmp=0;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma region Macros
#define ll long long
#define ld long double
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
using P = pair<ll, ll>;
#define VEC(type, name, size)\
    V<type> name(size);\
    IN(name)
#define VVEC(type, name, h, w)\
    VV<type> name(h, V<type>(w));\
    IN(name)
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHAR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DOUBLE(...)\
    DOUBLE __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LD(...)\
    LD __VA_ARGS__;\
    IN(__VA_ARGS__)
template <class T> void scan(T a) { cin >> a; }
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(long double &a) { cin >> a; }
void scan(char a[]) { scanf("%s", a); }
void scan(string &a) { cin >> a; }
template <class T> void scan(V<T> &);
template <class T, class L> void scan(pair<T, L> &);
template <class T> void scan(V<T> &a) { for(auto &i : a) scan(i); }
template <class T, class L> void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) { scan(head); IN(tail...); }
template <class T> inline void print(T x){ cout << x << '\n';}
struct inputoutputfaster{
    inputoutputfaster(){
        ios::sync_with_stdio(false);\
        cin.tie(nullptr);
        cout << fixed << setprecision(15);
    }
}inputoutputfaster_;
template <class T> V<T> press(V<T> &x){ 
    V<T> res = x;
    sort(all(res));
    res.erase(unique(all(res)), res.end());
    REP(i, SZ(x)){
        x[i] = lower_bound(all(res), x[i]) - res.begin();
    }
    return res;
}
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; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T divup(T x, T y) {return (x+(y-1))/y;}
template <typename T> T pow(T a, long long n, T e = 1) {T ret = e; while (n) {if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
const ll INF = 1e18;
#pragma endregion

int main(){
    INT(d, t, s);
    Yes(s*t >= d);
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
  
using namespace std;
  
int main(){
    int n,m;
    int x[1000];
    int s[1000];
    int masu=0;
    while(true){
        masu=0;
    cin>>n>>m;
    if(n==0&&m==0){
        break;
    }
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<m;i++){
        cin>>s[i];
    }
    int i=0;
    while(true){
        masu+=s[i];
        if(masu>=n-1){
            cout<<i+1<<endl;
            break;
        }
        masu+=x[masu];
        if(masu>=n){
            cout<<i+1<<endl;
            break;
        }
        i++;
    }
    }
    return 0;
} 

Measured memory_bytes: 1168