akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 ll n ;
 
 bool flag[405][405] ;
 ll   dp[405][405] ;

 ll f(ll a, ll b ,vector<ll> &A){
  if(flag[a][b]) return dp[a][b] ;
  else{
     if(a==b){
       flag[a][b]=0 ;
       dp[a][b]= 0 ;
       return 0 ;
     }
     else if(a==b-1){
      flag[a][b]=1 ;
      dp[a][b]=A[a]+A[b] ;
      return A[a]+A[b] ;
    }
  else{
    ll ans= INF ;
    rep2(i,a,b-1){
     chmin(ans, f(a,i,A)+f(i+1,b,A)) ;
    }
    rep2(i,a,b) ans+= A[i] ;
    flag[a][b]=1 ;
  dp[a][b]=ans ;
    return ans ;
  }
  
  }
}

 int main(){
   cin>> n ;
   vector<ll> A(n) ;
  rep(i,n){
   cin>>A[i] ;
  }
   rep(i,405){
    rep(j,405){
      flag[i][j]=0 ;
      dp[i][j]=0 ;
    }
  }
  
   cout<< f(0,n-1,A)<<endl ; 

   return 0 ;
 }



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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		int n;
		cin >> n;
		vector<int> a(n, 0), b(n, 0);
		for(int i=0; i<n; i++)cin >> a[i];
		for(int i=0; i<n; i++)cin >> b[i];
		for(int i=1; i < n; i+=2)swap(a[i], b[i]);
		int inf = 1000000000;
		int ans = inf;
		for(int i=0; i < (1<<n); i++){
			if(__builtin_popcount(i) != (n+1)/2)continue;

			vector<pair<int, int>> c(n);
			for(int j=0; j < n; j++){
				if(i & (1 << j))c[j] = make_pair(a[j], 0);
				else c[j] = make_pair(b[j], 1);
			}
			int t = 0;
			for(int j=0; j < n; j++){
				int idx = -1;
				int val = 1e9;
				for(int k = j; k < n; k ++){
					if(c[k].second != j % 2)continue;
					if(c[k].first < val){
						idx=k;
						val = c[k].first;
					}
				}
				while(idx > j){
					swap(c[idx], c[idx-1]);
					t++;
					idx--;
				}
			}
			bool flag = true;
			for(int j = 0; j < n-1; j++){
				if(c[j].first > c[j+1].first)flag = false;
				if(c[j].second != j % 2)flag = false;
			}
			if(flag)updmin(ans, t);
		}
		if(ans == inf)ans = -1;
		cout << ans << "\n";
		
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 256
x, y, a, b, c = map(int, input().split())
p = sorted(map(int, input().split()))[::-1]
q = sorted(map(int, input().split()))[::-1]
r = sorted(map(int, input().split()))[::-1]

x, y = x-1, y-1
z = 0
red, green = 0, 0
ans = 0
while True:
    finish = True
    if p[x] <= q[y] or y < 0:
        if z < c and p[x] < r[z]:
            x -= 1
            z += 1
            finish = False
    elif p[x] >= q[y] or x < 0:
        if z < c and q[y] < r[z]:
            y -= 1
            z += 1
            finish = False
    if finish:
        break
print(sum(p[:x+1]) + sum(q[:y+1]) + sum(r[:z]))


Measured memory_bytes: 23072
N = int(input())
HP = list(map(int, input().split()))

def gcd(a, b):
    mod = 1

    while (mod > 0):
        mod = a % b
        a = b
        b = mod
    
    return (a)

gc = HP[0]

for i in range(1, N):
    gc = gcd(gc, HP[i])
    # print(gc)

print(gc)

Measured memory_bytes: 14224
# -*- coding: utf-8 -*-
from itertools import combinations_with_replacement
def main():
    n, m, q = map(int, input().split())
    xs = []
    for i in range(q):
        xs.append(list(map(int, input().split())))
    max = 0
    for suretu in combinations_with_replacement(range(1, m + 1), n):
        wa = 0
        for x in xs:
            a, b, c, d = x
            if suretu[b - 1] - suretu[a - 1] == c:
                wa += d
        if wa > max:
            max = wa
    print(max)
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 9116
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;

int main() {
	int N; cin >> N;
	if (N == 1) {
		puts("Hello World");
	}
	if (N == 2) {
		int A, B; cin >> A >> B;
		cout << A + B << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<math.h>
using namespace std;
#define MAX 200005
#define MOD 1000000007
#define EPS 0.00000000001
#define INF 998244353
int zeros;
vector<long long> neg,pos,third;
int main()
{
    int N,i,K;
    scanf("%d %d",&N,&K);
    long long inp;
    for(i=0;i<N;i++)
    {
        scanf("%lld",&inp);
        if(inp==0) zeros++;
        else if(inp>0) pos.push_back(inp);
        else neg.push_back(inp);
    }
    if(pos.size()>0) sort(pos.begin(),pos.end());
    if(neg.size()>0) sort(neg.begin(),neg.end());
    long long ans=1;
    if(K==N)
    {
        if(zeros==0)
        {
            for(i=0;i<pos.size();i++)
            {
                ans=(ans*pos[i])%MOD;
            }
            for(i=0;i<neg.size();i++)
            {
                ans=(ans*neg[i])%MOD;
            }
            ans=(MOD+ans)%MOD;
        }
        else ans=0;
    }
    else if(pos.size()==0)
    {
        if(K%2)
        {
            if(zeros>0) ans=0;
            else
            {
                for(i=0;i<K;i++)
                {
                    ans=(ans*(-neg[neg.size()-1-i]))%MOD;
                }
                ans=(MOD-ans)%MOD;

            }
        }
        else
        {
            if(neg.size()<K) ans=0;
            else
            for(i=0;i<K;i++)
            {
                ans=(ans*(-neg[i]))%MOD;
            }
        }
    }
    else if((int) (pos.size())+(int) (neg.size())<K) ans=0;
    else
    {
        if(K%2)
        {
            ans=pos[pos.size()-1];
            pos.pop_back();
            K--;
        }
        K=K/2;
        long long temp;
        while(pos.size()>1)
        {
            temp=pos[pos.size()-1];
            pos.pop_back();
            temp=temp*pos[pos.size()-1];
            pos.pop_back();
            third.push_back(temp);
        }
        for(i=0;i+1<neg.size();i=i+2)
        {
            temp=neg[i];
            temp=(temp*neg[i+1]);
            third.push_back(temp);
        }
        if(third.size()>0) sort(third.begin(),third.end());
        for(i=0;i<K;i++)
        {
            third[third.size()-1]=third[third.size()-1]%MOD;
            ans=(ans*third[third.size()-1])%MOD;
            third.pop_back();
        }
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 6604
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n,m,q;
vector<ll> G[200000];
bool dp[200000][11];
ll color[200000];

void query(ll v,ll d,ll c) {
	if(dp[v][d]) 
		return;

	REP(i,d + 1)
		dp[v][i] = true;

	if(color[v] == 0) {
		color[v] = c;
	}

	if(d == 0) 
		return;

	REP(i,G[v].size()) {
		query(G[v][i],d - 1,c);
	}
}

ll v[200000],d[200000],c[200000];

int main(){
	cin >> n >> m;
	REP(i,m) {
		ll a,b;
		cin >> a >> b;
		a--;b--;

		G[a].pb(b);G[b].pb(a);
	}
	cin >> q;

	REP(i,q) {
		cin >> v[i] >> d[i] >> c[i];
	}

	RREP(i,q) {
		query(v[i] - 1,d[i],c[i]);
	}

	REP(i,n) {
		cout << color[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 16884
#include <bits/stdc++.h>
#define pii pair<int,int>
#define mp make_pair
#define ll long long

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int minCost(int a[],vector<int> &dp,int n,int i)
{
	if(i==n-1)
	{
		return 0;
	}
	if(dp[i]!=-1)
	{
		return dp[i];
	}
	if(i+1<n)
	{
		int one=minCost(a,dp,n,i+1);
		dp[i]=abs(a[i]-a[i+1])+one;
	}
	if(i+2<n)
	{
		int two=minCost(a,dp,n,i+2);
		dp[i]=min(dp[i],abs(a[i]-a[i+2])+two);
	}
	return dp[i];
}

int main()
{
	fastio
	int n,i;
	cin>>n;
	int a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	vector<int> dp(n,-1);
	cout<<minCost(a,dp,n,0);
}

Measured memory_bytes: 10288
#include <bits/stdc++.h>
using namespace std;
 
int main(){
int n;
  cin >> n ;
  for(int i=1;i<50000;++i){
    if(i*108/100 == n){
      cout << i << endl;
      return 0;
      }
    }
  cout << ":(" << endl;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

x, n= na()
p = na()
a = x
b = x
for i in range(100):
  if (b in p) == False:
    print(b)
    break
  elif (a in p) == False:
    print(a)
    break
  else:
    a = a+1
    b = b-1

Measured memory_bytes: 9204
#!/usr/bin/env python3

def solve(n, x, bs):
    cs = sorted(bs)
    res = 0
    for c in cs:
        if c <= x:
            x -= c
            res += 1
        else:
            break
    if x > 0 and res == n:
        res -= 1
    return res


def main():
    n, x = (int(z) for z in input().split())
    bs = [int(b) for b in input().split()]
    res = solve(n, x, bs)
    print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>

std::vector<std::string> solv(int N) {
  if (N == 1) return {"a"};

  auto const& rec = solv(N-1);
  std::vector<std::string> ret;

  for (auto const& s : solv(N-1)) {
    char d='a';
    for (auto const c : s) {
      d = std::max(c, d);
    }
    std::string t = s;
    t.push_back('a');
    for (char c='a'; c<d+2; c++) {
      t[N-1] = c;
      ret.push_back(t);
    }
  }

  return ret;
}

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

  for (auto const& s : solv(N)) {
    std::cout << s << '\n';
  }

  return 0;
}


Measured memory_bytes: 9764
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		for(int i = 0; i < 3; i++){
			System.out.print(sc.next().charAt(i));
		}
		System.out.println();
	}

}


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

namespace AtCoder0621
{
	class Program
	{
		static void Main(string[] args)
		{
			C();
		}

		static void C()
		{
			var n = long.Parse(Console.ReadLine());
			var cur = 26L;
			int chars = 1;
			while (n > cur)
			{
				n -= cur;
				cur *= 26L;
				chars++;
			}
			n -= 1;
			var l = new char[chars];
			chars--;
			while (chars >= 0)
			{
				l[chars--] = (char)('a' + n % 26);
				n /= 26;
			}

			Console.WriteLine(new string(l));
		}

		static void B()
		{
			var ints = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
			var k = ints[1];
			var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
			Array.Sort(a);

			Console.WriteLine(a.Take(k).Sum());
		}

		static void A()
		{
			var s = Console.ReadLine();
			if (s == s.ToLower())
				Console.WriteLine('a');
			else
				Console.WriteLine('A');
		}
	}
}


Measured memory_bytes: 27536
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String ss = sc.nextLine();
    StringBuilder sb = new StringBuilder();
    int j = 0;
    for (int i = 0; i < ss.length(); ++i) {
      switch (ss.charAt(i)) {
        case '1':
          sb.append("1");
          ++j;
          break;
        case '0':
          sb.append("0");
          ++j;
          break;
        case 'B':
          if (j > 0) {
            sb.delete(j - 1, j);
            --j;
          }
      }
    }
    System.out.println(sb.toString());
  }
}


Measured memory_bytes: 21204
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Tag
{
public:
    string name;
    int x1, y1, x2, y2;
    int num;
};

void readTag(string& s, int& i, vector<Tag>& tag)
{
    Tag t;
    int j = s.find('>', i);
    t.name = s.substr(i+1, j-i-1);
    i = j + 1;

    j = s.find('<', i);
    istringstream iss(s.substr(i, j-i));
    char c;
    iss >> t.x1 >> c >> t.y1 >> c >> t.x2 >> c >> t.y2;
    i = j;

    t.num = 0;
    while(s[i+1] != '/'){
        ++ t.num;
        readTag(s, i, tag);
    }
    tag.push_back(t);

    i = s.find('>', i) + 1;
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        string s;
        cin >> s;
        int i = 0;
        vector<Tag> tag;
        readTag(s, i, tag);

        for(int i=0; i<n; ++i){
            int x, y;
            cin >> x >> y;
            unsigned j;
            for(j=0; j<tag.size(); ++j){
                if(tag[j].x1 <= x && x <= tag[j].x2 && tag[j].y1 <= y && y <= tag[j].y2){
                    cout << tag[j].name << ' ' << tag[j].num << endl;
                    break;
                }
            }
            if(j == tag.size()){
                cout << "OUT OF MAIN PANEL 1" << endl;
            }
        }
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>

#define loop(i,a,b) for(int i=a; i<b; i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
    int a[5];
    while(scanf("%d,%d,%d,%d,%d",&a[0],&a[1],&a[2],&a[3],&a[4])!=EOF){
        sort(a,a+5);
        int n=0;
        rep(i,4)loop(j,i+1,5){
            if(a[i]==a[j])n++;
        }
        bool st=true;
        rep(i,4)if(a[i]+1!=a[i+1])st=false;
        if(a[0]==1&&
           a[1]==10&&
           a[2]==11&&
           a[3]==12&&
           a[4]==13) st=true;

        string ans;
        if(n==6)
            ans="four card";
        else if(n==4)
            ans="full house";
        else if(st)
            ans="straight";
        else if(n==3)
            ans="three card";
        else if(n==2)
            ans="two pair";
        else if(n==1)
            ans="one pair";
        else
            ans="null";
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1220
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int a = sc.nextInt();
        int b = sc.nextInt();
        int sa = b - a;
        int sum = 0;
        for (int i = sa; i > 0; i--) {
            sum += i;
        }
        System.out.println(sum - b);
    }
}

Measured memory_bytes: 23764
#include<stdio.h>

#define MAX 100000

int main(){
  int n, i, x, A[MAX], p, j, r, m;
  scanf("%d",&n);

  for(i=1 ; i<=n ; i++)scanf("%d",&A[i]);

  p = 1;
  r = n;
  x = A[r];
  i = p-1;

  for(j=p ; j<r ; j++){
    if(A[j] <= x){
      i = i+1;
      m = A[i];
      A[i] = A[j];
      A[j] = m;
    }
  }
    m = A[i+1];
    A[i+1] = A[r];
    A[r] = m;

    r = i+1;
    
    for(i=1 ; i<=n ; i++){
      if(i!=1)printf(" ");
      if(i == r)printf("[");
      printf("%d",A[i]);
      if(i == r)printf("]");
    }

    printf("\n");
    return 0;
}



Measured memory_bytes: 2084
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<unordered_map>
#include<map>
#include<string>
#include<cstring>
#include<stack>
#include<cmath>

#define vint vector<int>
#define vstr vector<string>
#define vll vector<long long>
#define ll long long
#define pf printf
#define sf scanf
#define sfd(n) scanf("%d", &n)
#define sflf(n) scanf("%lf", &n)
#define sfll(n) scanf("%lld", &n)
#define pfd(n) printf("%d", n)
#define pflf(n) printf("%lf", n)
#define pfll(n) printf("%lld", n)
#define pft	printf("\t")
#define pfn printf("\n")
#define pfk printf(" ")
#define PI 3.1415926
#define MAX 100000
#define M 1e18

using namespace std;

//bool F(ll* num, ll max, int len, int* f) {
//	int i=0;
//	for( i=0; i<len-1; i++ ) {
//		if( f[i]==0&&max%num[i]!=0 ) {
//			break;
//		}
//		f[i] = 1;
//	}
//	if( i>=len-1 ) {
//		return true;
//	}else {
//		return false;
//	}
//}

int main() {
//	int n;
//	sfd(n);
//	ll* num = new ll[n];
//	int* flag = new int[n]();
//	for( int i=0; i<n; i++ ) {
//		sfll(num[i]);
//	}
//	sort(num, num+n);
//	ll ans = num[n-1], l = 2;
//	while( true&&ans<=M ) {
//		if( F(num, ans, n, flag) ) {
//			break;
//		}
//		ans = num[n-1]*l;
//		l++;
//	}
//	pfll(ans);



	int n;
	sfd(n);
	ll* num = new ll[n];
	set<ll> p;
	ll ans = 0;
	for( int i=0; i<n; i++ ) {
		sfd(num[i]);
		p.insert(num[i]);
	}
	sort(num, num+n);
	int len = p.size();
//	pfd(len);
//	pfn;
	if( n-len>=2 ) {
		ll a = 0, b = 0, i;
		for( i=n-1; i>0; i-- ) {
			if( num[i]==num[i-1] ) {
				a = num[i];
				break;
			}
		}
		for( i=i-2; i>0; i-- ) {
			if( num[i]==num[i-1] ) {
				b = num[i];
				break;
			}
		}
		ans = a*b;
	}
	pfll(ans);
	
	return 0;
}

Measured memory_bytes: 5760
import java.util.Scanner;

//Aizu Chicken
public class Main{

	static int q1, b, c1, c2, q2;

	static boolean f(int a){
		return !(b<c1*a || a+(b-c1*a)/c2<q1);
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			q1 = sc.nextInt();
			if(q1==0)break;
			b = sc.nextInt();
			c1 = sc.nextInt();
			c2 = sc.nextInt();
			q2 = sc.nextInt();
			int l = 0;
			int r = q2;
			while(r-l>1){
				int mid = (l+r)/2;
				if(f(mid))l = mid;
				else r = mid;
			}
			if(r>0&&f(r))System.out.println(r+" "+(b-c1*r)/c2);
			else if(l>0&&f(l))System.out.println(l+" "+(b-c1*l)/c2);
			else System.out.println("NA");
		}
	}
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int h, w, k;
	cin >> h >>w >>k;
	vector<string> s(h);
	rep(i, h) cin >>s[i];
	//int bsm=0;
	//rep(i, h) rep(j, w) if(s[i][j]=='#') bsm++;
	//if(bsm < k) {cout <<"0\n"; return 0;}
	
	//VI tt(w), yk(h);
	//rep(i, h) rep(j, w) yk[i] += s[i][j] =='#';
	//rep(j, w) rep(i, h) tt[j] += s[i][j] =='#';
	
	int p=h+w;
	ll ans =0;
	rep(i, 1<<p){
		set<int> st;
		rep(j, p) if(i>>j &1) st.insert(j);
		auto ck =s;
		for(auto j: st){
			if(j<h) rep(k, w) ck[j][k]='%';
			else rep(k, h) ck[k][j-h] ='%';
		}
		int csm=0;
		rep(y, h) rep(x, w) if(ck[y][x]=='#') csm++;
		if(csm == k){
			ans++;
		}
	}
	cout <<ans <<"\n";
	return 0;
}


Measured memory_bytes: 3664
A,B,C,X = [int(input()) for i in range(4)]
n,a=0,0
while a<A+1:
  b=0
  while b<B+1:
    x=a*500+b*100
    b+=1
    if X<x:continue
    if (X-x)<=C*50:n+=1
  a+=1
print(n)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll calc(ll n){
    ll ret=1,k=mod-2;
    while(k){
        if(k%2)ret=ret*n%mod;
        n=n*n%mod;
        k>>=1;
    }
    return ret;
}

int main(){
    int n;cin>>n;
    ll fact[101010],invfact[101010],inv[101010];
    inv[0]=inv[1]=1;
    fact[0]=invfact[0]=1;
    REP(i,1,n)inv[i+1]=calc(i+1);
    rep(i,n){
        fact[i+1]=fact[i]*(i+1)%mod;
        invfact[i+1]=invfact[i]*inv[i+1]%mod;
    }
    ll sum[101010];
    sum[1]=1;
    rep(i,n)sum[i+2]=(sum[i+1]+inv[i+2])%mod;
    ll a[n];
    ll ans=0;
    rep(i,n){
        cin>>a[i];
        ans+=a[i]*(sum[n-i]+sum[i+1]-1)%mod;
        ans%=mod;
    }
    cout<<ans*fact[n]%mod<<endl;
    return 0;
}

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

int main() {
  string S;
  int N,na,nb;
  na=0;
  nb=0;
  cin >> S;
  vector<char> a(2);
  a={'0','1'};
  N=S.size();
  for(int i=0;i<N;i++){
    int j=(i%2);
    if(S.at(i)==a.at(j)){
      na++;
    }
  }
  for(int i=0;i<N;i++){
    int j=(i%2);
    if(S.at(i)!=a.at(j)){
      nb++;
    }
  }
    cout << min(na,nb) << endl;
}

Measured memory_bytes: 512
program main
  implicit none
  integer :: A,B,out
  integer :: i
  read(*,*) A,B
  out = 0
  do i=1,2
     if (A>B) then
        out=out+A
        A=A-1
     else
        out=out+B
        B=B-1
     end if
  end do
  write(*,'(i0)') out
end program main

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;

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

    ll n, q;
    cin >> n >> q;
    vector<ll> a(n), x(q);
    rep(i, n) cin >> a[i];
    rep(i, q) cin >> x[i];

    rep(i, q){
        ll r = 0;
        ll sm = a[0];
        ll res = 0;
        for(ll l = 0; l < n; ++l){
            if(l > 0) sm -= a[l-1];
            while(r < n && sm <= x[i]){
                ++r;
                sm += a[r];
            }

            res += r-l;
        }

        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 3552
#!/usr/bin/env python3
import sys


def isATCG(s):
    if s in "ATCG":
        return True
    return False

def solve(S: str):
    S1 = [0] * len(S)

    c = 0
    for i in range(len(S)):
        if isATCG(S[i]):
            c += 1
        else:
            c = 0
        S1[i] = c

    print(max(S1))

        

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

int main(){
    int n;
    cin >> n;
    int x[101], y[101], h[101];
    for(int i=0; i<n; i++){
        cin >> x[i] >> y[i] >> h[i];
    }

    for(int cx=0; cx<=100; cx++){
        for(int cy=0; cy<=100; cy++){

            vector<int> H;
            for(int i=0; i<n; i++){
                if(h[i]!=0){
                    H.push_back(h[i] + abs(x[i]-cx) + abs(y[i]-cy));
                }
            }
            int height = H[0];
            bool isok = true;
            for(auto itr = H.begin(); itr != H.end(); itr++) {
                if(*itr != H[0]){
                    isok = false;
                    break;
                }
            }
            for(int i=0; i<n; i++){
                if(h[i] != max(0, height - abs(x[i]-cx) - abs(y[i]-cy))){
                    isok = false;
                    break;
                }
            }
            if(isok){
                cout << cx << " " << cy << " " << height << endl;
                return 0;
            }
 
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; typedef long long ll;
int main(){ 
  int N,K;cin >> N >> K;
  vector<ll> x(N); vector<ll> y(N);
  for(int i = 0; i < N; i++){ cin >> x[i] >> y[i];}
  ll ans = 1e40;
  for(int l = 0; l < N; l++){
    for(int r = 0; r < N; r++){
      for(int u = 0; u < N; u++){
        for(int d = 0; d < N; d++){
          ll xl = x[l]; ll xr = x[r]; ll yu = y[u]; ll yd = y[d];
          if( xl>=xr || yu <= yd){ continue;}
          int cnt = 0;
          for(int i = 0; i < N; i++){
            if( xl <= x[i] && x[i] <= xr && yd <= y[i] && y[i] <= yu){ 
              cnt++;}}
          if( cnt == K){ ans = min( ans, (xr-xl)*(yu-yd));}
                                   
                                   }}}}
                                   
     cout << ans<< endl; return 0;}
                                   
  
           

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
static const int64_t mod=1000000007;
int64_t f(int64_t x,int64_t y){
if(y==0)
  return 1;
  else if(y%2==0)
    return (f(x,y/2)*f(x,y/2))%mod;
  else
    return (((x*f(x,y/2))%mod)*f(x,y/2))%mod;

}
int main(){
int64_t N,K;
  cin>>N>>K;
  int64_t ans=N-K+1;
  cout<<N-K+1<<endl;
  for(int64_t i=2;i<=K;i++){
  int64_t a=(N-K+2-i);
    int64_t b=(K+1-i);
    int64_t c=f(i*(i-1),mod-2);
    ans=(((ans*a)%mod)*((b*c)%mod))%mod;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
/* ex5_3
   moka223711 */

#include <stdio.h>
#define ROW 101 // マス目の行の上限
#define COL 101 // マス目の列の上限

int main(void){
    // br = black_row, bc = black_column
    // 黒が少なくとも1マス含まれている行,列を記録する 0で初期化
    int row, col, i, j, br[ROW]={0}, bc[COL]={0};
    // マス目の配色を受け取る2次元配列
    char sq[ROW][COL];
    scanf("%d %d", &row, &col);
	
    for(i = 0; i < row; i++){
        for(j = 0; j < col; j++){
            // マス目の配色を受け取り、黒が1マスでも含まれている行と列はbr[i], bc[j]を1に変える
            scanf(" %c", &sq[i][j]);
            if(sq[i][j]=='#'){
                br[i] = 1;
                bc[j] = 1;
            }
        }
    }
    for(i = 0; i < row; i++){
        // 上から1行ずつ出力していく
        // 黒が1マスも含まれない行(すべて白の行)は飛ばす
        if(br[i] != 0){
            // このfor文が実行される行には黒が少なくとも1マス含まれている
            for(j = 0; j < col; j++){
                // 黒が1マスも含まれない列(すべて白の列)は飛ばす
                if(bc[j] != 0){
                    // マス目を出力
                    printf("%c", sq[i][j]);
                }
            }
            // 改行を出力
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(){
    int k,a,b,c,t;
    scanf("%d %d %d %d",&a,&b,&c,&k);
    if(k<=a) {t=k;}
    else if(k<=a+b) {t=a;}
    else  {t=a-(k-a-b);} 
    printf("%d",t);
    return 0;
}

Measured memory_bytes: 1732
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  string s;
  get(s);
  int i = 0, j = s.size() - 1;
  int ans = 0, xcnt = 0;
  while (i < j) {
    xcnt = 0;
    while (i < s.size() && s[i] == 'x') {
      i++;
      xcnt++;
    }
    while (j >= 0 && s[j] == 'x') {
      j--;
      xcnt--;
    }
    if (s[i] != s[j]) {
      print(-1);
      return 0;
    }
    i++;
    j--;
    ans += abs(xcnt);
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main{
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) {

    FastReader sc = new FastReader();

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

    int h[] = new int[n];
     int cost[] = new int[n];
        for(int i=0; i<n; i++){
         h[i] = sc.nextInt();
    }
        cost[0] = 0;
        cost[1] = Math.abs(h[1]-h[0]);
        for(int i=2; i<n; i++){
            cost[i] = Integer.MAX_VALUE;
            for(int j=i-1; j>=i-k && j>=0; j--){
                cost[i] = Math.min(cost[j]+Math.abs(h[i]-h[j]),cost[i]);
            }
        }
        System.out.println(cost[n-1]);
    }

}


Measured memory_bytes: 32900
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	bool flag=0;
	for(float i=1;i<=10000;i++){
		if(floor(i*0.08)==a&&floor(i*0.1)==b){
			flag=1;
			cout<<i<<endl;
			break;
		}
	}
	if(!flag)cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int n,r;
	
	while(cin >> n >> r){
		if(!(n|r)) break;
		int pos = 0;
		vector<pair<int,int> > inst(r);
		for(int i=0;i<r;i++){
			cin >> inst[i].first >> inst[i].second;
		}
		
		reverse(inst.begin(), inst.end());
		
		for(int i=0;i<r;i++){
			if(pos < inst[i].second){
				pos += inst[i].first-1;
			}else if(pos < inst[i].first + inst[i].second-1){
				pos -= inst[i].second;
			}
		}
		cout << n - pos << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define INF 1e9
#define All(x) (x).begin(),(x).end()
#define Cout(x) cout << (x) << endl
typedef long long ll;
using namespace std;

int main(){
    int N;
    cin>>N;
    vector<int> P(N),Q(N);

    REP(i,N){
        cin>>P[i];
    }
    REP(i,N)cin>>Q[i];
    int cnt=0,a_P,a_Q;
    vector<int> v(N);
    iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
    do {
        cnt++;
        int p=0,q=0;
        for(int x=0;x<N;x++){
            if(P[x]==v[x])p++;
            else break;
            //cout<<v[x];
        }
        //cout<<endl;
        for(int x=0;x<N;x++){
            if(Q[x]==v[x])q++;
            else break;
        }
        if(p==N)a_P=cnt;
        if(q==N)a_Q=cnt;
    } while( next_permutation(v.begin(), v.end()) );     // 次の順列を生成

    cout<<abs(a_Q - a_P)<<endl;
}

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

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

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; 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)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N);
  rep(i, N) cin >> x[i];
  vector<int> y(M);
  rep(i, M) cin >> y[i];

  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  int max_x = max(x[N-1], X);
  int min_y = min(y[0], Y);
  if (max_x < min_y) {
    cout << "No ";
  }
  cout << "War\n";
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		long k = sc.nextLong();
		int[] a = new int[s.length()];
		int c = 0;
		a[c]++;

		for (int i = 0; i < s.length() - 1 ; i++ ) {
			if ( s.charAt(i) != s.charAt(i+1) ) {
				c++;
			}
			a[c]++;
		}

		if ( c == 0 ) {
			// 全部同じ文字	
			long d = (long)s.length() * k / 2l ;
			System.out.println(d);
			System.exit(0);
		}

		long ct = 0;
		for (int i = 1; i < c ; i++ ) {
			ct = ct + ( (long)a[i] / 2l ) * k ;
		}

		if ( s.charAt(0) == s.charAt(s.length()-1) ) {
			// 先頭＝終端なら、k-1回は連結で計算	
			ct = ct + ( ((long)a[0]+(long)a[c]) / 2l ) * (k-1) ;
			// 1回は別個に計算	
			ct = ct + (long)a[0] / 2l ;
			ct = ct + (long)a[c] / 2l ;
		} else {
			// 先頭≠終端なら、k回とも別個に計算	
			ct = ct + ( (long)a[0] / 2l ) * k ;
			ct = ct + ( (long)a[c] / 2l ) * k ;
		}
		// 出力
		System.out.println(ct);
	}
}

Measured memory_bytes: 21844
/*    ####################  */
/*   # I_LOVE_THUY_LINH #  */
/*  ####################  */
#include <bits/stdc++.h>
#define ll long long
#define db double
#define ld long double
#define ii pair<int,int>
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define matrix vector<vector<ll>>
#define fir first
#define sec second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define sz(a) int((a).size())
#define ms(s,val) memset(s,val,sizeof(s))
#define bitcount(n) __builtin_popcountll(n)
#define getbit(s,k) ((s >> k)&1)
#define turnbit(s,k) (s | (1<<k))
#define offbit(s,k) (s & ~(1<<k))
#define flipbit(s,k) (s ^ (1<<k))
#define prec(n) fixed<<setprecision(n)
#define sqr(x) (ll)(x)*(ll)(x)
#define lcm(a,b) ((ll)a/__gcd((ll)a,(ll)b)*(ll)(b))
#define gcd(a,b) __gcd(a,b)
using namespace std;
const int INF = int(1e9);

int H , A;
int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> H >> A;
    cout << (H / A) + (H % A != 0);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<sstream>
#include<utility>
using namespace std;
pair<int,string> f(string s){
  stringstream ss(s);
  int n;string res;
  ss>>n>>res;
  return make_pair(n,res);
}
int main(){
  string s;
  int ans = 0;
  while(cin>>s){
    while(true){
      while((s[0]<'0'||'9'<s[0]) && s.size()!=0)s=s.substr(1);
      if(s.size()==0)break;
      pair<int,string> tmp;
      tmp= f(s);
      ans += tmp.first;
      s = tmp.second;
    }
  }
  cout<<ans<<endl;
}

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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main ()
{
    fastio
    lli a[3] , sum = 0 ;
    loopcin(3 , a) ;

    sort(a , a+ 3) ;
    sum += a[1] - a[2] + a[0] - a[1] ;

    cout << abs(sum) ;


    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
// This file is a "Hello, world!" in D language by DMD for wandbox.
import std.stdio;
import std.algorithm;
import std.conv;
import std.string;
import std.array;
import std.range;

void main()
{
  int n = readln.chomp.to!int;
  int[] a = readln.chomp.split.map!(to!int).array;
  int[] b = new int[](n + 1);
  int ofs = n / 2;
  foreach (i, v; a) {
    if (i % 2) {
      b[ofs + (i + 1) / 2] = v;
    } else {
      b[ofs - i / 2] = v;
    }
  }
  int[] c;
  foreach (v; b) {
    c ~= v;
  }
  if (n % 2 == 0) {
    c = c.retro.array;
  }
  c = c[0..n];
  c.map!(to!string).join(" ").writeln;
}

// DMD reference:
//   https://dlang.org/dmd-linux.html

// D language references:
//   https://dlang.org
//   http://www.kmonos.net/alang/d/ ( Japanese )


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int n;
	cin >> n;

	int p[n], q[n];
	rep(i, n){
		cin >> p[i];
		p[i]--;
		q[p[i]] = i;
	}

	int mx = 0;
	int cnt = 0;
	int t = -1;

	rep(i,n){
		if(q[i] > t){
			cnt++;
		}else{
			mx = max(mx, cnt);
			cnt = 1;
		}
		t = q[i];
	}
	mx = max(mx, cnt);

	cout << n - mx << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void){
  int a, b, c, t;
  scanf("%d %d %d", &a, &b, &c);
  if(a > b){
    t = a;
    a = b;
    b = t;
  }
  if(b > c){
    t = b;
    b = c;
    c = t;
  }
  if(a > b){
    t = a;
    a = b;
    b = t;
  }
  printf("%d %d %d\n", a, b, c);

  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr int MOD = 1000000007;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

void warshall_floyd(VVL& graph) {
	ll n = graph.size();
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				graph[j][k] = std::min(graph[j][k], graph[j][i] + graph[i][k]);
			}
		}
	}
}

VL prime_decomposition(ll n) {
	ll i = 2;
	VL table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace_back(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace_back(n);
		return table;
	}
	return table;
}

int main() {
	int n;
	cin >> n;
	VVL graph = VVL(n, VL(n));
	REP(i, n) {
		REP(j, n) {
			cin >> graph[i][j];
		}
	}

	ll sum = 0;
	FOR(i, 0, n) {
		FOR(j, i + 1, n) {
			bool flg = true;
			REP(k, n) {
				if (i == k || j == k) { continue; }
				if (graph[i][j] > graph[i][k] + graph[k][j]) {
					cout << -1 << endl;
					return 0;
				}
				if (graph[i][j] == graph[i][k] + graph[k][j]) {
					flg = false;
					break;
				}
			}
			if (flg) { sum += graph[i][j]; };
		}
	}
	cout << sum << endl;
}

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

int main() {
    int s; cin >> s;
    vector<int> a(1000001,0);
    bool b = true;
    int i = 1;
    while(b){
        int &c = a[s];
        if(c == 0){
            c = i;
            if(s%2 == 0){
                s /= 2;
            }
            else{
                s = 3*s+1;
            }
            i++;
        }
        else{
            cout << i << endl;
            b = false;
        }
    }
}


Measured memory_bytes: 4096
n, m = gets.chomp.split(' ').map(&:to_i)
list = m.times.map { gets.chomp.split(' ').map(&:to_i) }

list = list.sort_by{|_a, b| b }
count = 0
cut = 0
list.each do |a, b|
  next if a < cut
  count += 1
  cut = b
end
puts count


Measured memory_bytes: 12664
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<ctime>
using namespace std;

const int N=370;
const int M=30;

int D,ans,T,d,q,start;
int s[N][M],lst[M],c[M],t[N],cnt[N][M];

int calc(){
	int sum=0;
	for (int i=1;i<=26;i++) lst[i]=0;
	for (int i=1;i<=D;i++){
		sum+=s[i][t[i]];
		lst[t[i]]=i;
		for (int j=1;j<=26;j++) sum-=c[j]*(i-lst[j]);
	}
	return max(sum+1000000,0);
}

bool time_out(){
	return clock()-start>1950;
}

int main(){
	start=clock();
	scanf("%d",&D);
	for (int i=1;i<=26;i++) scanf("%d",&c[i]);
	for (int i=1;i<=D;i++)
		for (int j=1;j<=26;j++) scanf("%d",&s[i][j]);
	for (int i=1;i<=D;i++) t[i]=1;
	ans=calc();
	while (!time_out()){
		for (int d=1;d<=D;d++)
			for (int q=1;q<=26;q++){
				int sum,tmp;
				tmp=t[d];
				t[d]=q; sum=calc();
				if (sum>ans) ans=sum;
				else t[d]=tmp;
			}
	}
	for (int i=1;i<=D;i++) printf("%d\n",t[i]);
	return 0;
}

Measured memory_bytes: 3876
#include <iostream>
#include <algorithm>
#include <cmath>

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

	long long val = 1;
	for (long long i = 1; i*i <= m; ++i) {
		if (m%i == 0) {
			auto j = m / i;
			if (j >= n)
				val = std::max(val, i);
			if (i >= n)
				val = std::max(val, j);

		}
	}
	std::cout << val << std::endl;
	return 0;
}


Measured memory_bytes: 256
//#define _USE_MATH_DEFINES // for C++
//#include <cmath>
#include <stdio.h>
//#include <vector>

using namespace std;



int main(){
	
	int n;
	int A[100];
	int flag = 1;
	int buf;
	int cnt = 0;

	scanf("%d", &n);
	for (int i = 0; i < n; i++)	scanf("%d", &A[i]);

	while (flag){
		flag = 0;
		for (int j = n - 1; j > 0; j--){
			if (A[j] < A[j - 1]){
				buf = A[j - 1];
				A[j - 1] = A[j];
				A[j] = buf;
				flag = 1;
				cnt++;
			}
		}
	}

	printf("%d", A[0]);
	for (int i = 1; i < n; i++) printf(" %d", A[i]);
	printf("\n%d\n", cnt);

	return 0;
}

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

#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int INF = 1e9 + 7;


int main(void)
{
	FAST
	
	int n; cin >> n;
	int all = 0;
	vector<int> a(n);
	for(int i = 0; i < n; i++)
	{
		int x; cin >> x;
		a[i] = x;
		all ^= x;
	}

	for(int i = 0; i < n; i++)
	{
		cout << (a[i] ^ all) << ' ';
	}
	

	return 0;
}


Measured memory_bytes: 3912
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str, T: str):
    return YES if T[:-1] == S else NO


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    print(solve(S, T))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 8992
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

/*
 UnionFind
 */
struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};


template<class Type>
Type solve(Type res = Type()){
    int N,M; cin >> N >> M;

    UnionFind UF(N);
    for(int i = 0; i < M;i++){
        int A,B; cin >> A >> B;
        A--; B--;
        UF.unionSet(A,B);
    }
    set<int> st;
    for(int i = 0; i < N;i++){
        st.emplace(UF.root(i));
    }

    res = (int)st.size()-1;
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    //solve<ll>(0);
    cout << fixed << setprecision(12) << solve<ll>() << endl;
    return 0;
}

Measured memory_bytes: 7628
#include <bits/stdc++.h>
using namespace std;
#define M 4010
#define rep(i,x,y) for(int i=(x);i<=(y);++i)
struct Edge{
	int u,v,Next;
} G[M];
int n,k;
int head[M],tot;
inline void add(int u,int v){
	G[++tot]=(Edge){u,v,head[u]};
	head[u]=tot;
}
int f[M][2010];
int g[M][2010];
inline void dfs(int x,int fa){
	for(int i=head[x];i!=-1;i=G[i].Next){
		if(G[i].v==fa)continue;
		dfs(G[i].v,x);
	}
	rep(j,0,n){
		for(int i=head[x];i!=-1;i=G[i].Next){
			if(G[i].v==fa)continue;
			g[x][j+1]+=f[G[i].v][j];
		}
	}
	f[x][0]=1;
	rep(j,1,k){
		for(int i=head[x];i!=-1;i=G[i].Next){
			if(G[i].v==fa)continue;
			int wt=min(k-j,j);
			f[x][j]=max(f[x][j],1+f[G[i].v][j-1]+g[x][wt]-(wt-1>=0?f[G[i].v][wt-1]:0));
		}
	}
	rep(i,1,k)f[x][i]=max(f[x][i-1],f[x][i]);
}
int main() {
	scanf("%d%d",&n,&k);
	memset(head,-1,sizeof(head));
	rep(i,1,n-1){
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);add(v,u);
	}
	dfs(1,0);
	int ans=0;
	rep(j,1,n)rep(i,0,k){
		ans=max(ans,f[j][i]);
	}
	printf("%d\n",n-ans);
}

Measured memory_bytes: 35200