akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
import java.util.stream.Collectors;
public class Main {
	public static void main(String[] args){
		FastScanner sc = new FastScanner(System.in);
		int N = Integer.parseInt(sc.nextLine());
		List<Long> list = Arrays.stream(sc.nextLine().split(" ",0)).map(Long::valueOf).collect(Collectors.toList());
		int count = 0;
		boolean hasZero = false;
		for (long i : list) {
			if (i == 0) {
				hasZero = true;
				break;
			} else if (i < 0) {
				count++;
			}
		}

		long out = list.stream().mapToLong(Math::abs).sum();
		if (! (hasZero || count%2 == 0) ) {
			long min = list.stream().mapToLong(Math::abs).min().getAsLong();
			out-= min*2;
		}

		System.out.println(out);
	}

}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

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

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

        return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 48988
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 500000
 
struct Node {
  int key;
  struct Node *parent,*left,*right;
};

struct Node *NIL,*root;

void inorder(struct Node *);
void preorder(struct Node *);
void insert(int);

int main(){

  int i,n,x;
  char command[N][10];


  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",command[i]);
    if(strcmp(command[i],"insert")==0){
      scanf("%d",&x);
      insert(x);
    }
    if(strcmp(command[i],"print")==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }  
  return 0;
}

    
void inorder(struct Node *x){
  if(x==NIL) return;
  inorder(x->left);
  printf(" %d",x->key);
  inorder(x->right);
}


void preorder(struct Node *x){
  if(x==NIL) return;
  printf(" %d",x->key);
  preorder(x->left);
  preorder(x->right);
}
 



void insert(int k){

  struct Node *y=NIL;
  struct Node *x=root;
  struct Node *z;
  z=malloc(sizeof(struct Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key)
      x=x->left;
    else 
      x=x->right;
  }
  z->parent=y;

  if(y==NIL)
    root=z;
  else if(z->key < y->key)
    y->left=z;
  else y->right=z;
}
 

Measured memory_bytes: 28920
n, k = map(int, input().split())
a = list(map(int, input().split()))

for i in range(k):
	im = [0 for _ in range(n+1)]
	for i, x in enumerate(a):
		im[max(i-x, 0)] += 1
		im[min(i+x+1, n)] -= 1
	nxt = [im[0]]
	for i in range(1, n):
		nxt.append(nxt[-1] + im[i])
	a = nxt
	if min(a) == n:
		break

print(*a)

Measured memory_bytes: 185920
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  if(S == "SUN"){
    cout << 7 << endl;
  }else if(S == "MON"){
    cout << 6 << endl;
  }else if(S == "TUE"){
    cout << 5 << endl;
  }else if(S == "WED"){
    cout << 4 << endl;
  }else if(S == "THU"){
    cout << 3 << endl;
  }else if(S == "FRI"){
    cout << 2 << endl;
  }else  if(S == "SAT"){
    cout << 1 << endl;
  }
}

Measured memory_bytes: 764
X, Y = map(int, input().split())
MOD = 10 ** 9 + 7

if (X + Y) % 3 != 0:
    print(0)
    exit()
if abs(X - Y) > (X + Y) // 3:
    print(0)
    exit()
    
n = (X + Y) // 3 + 1
k = ((X - Y) + n + 1) // 2


SIZE = max(n, k)

g1 = [1, 1]      # 元テーブル
g2 = [1, 1]      # 逆元テーブル
inverse = [0, 1] # 逆元テーブル計算用テーブル

def comb(n, r, mod):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod

for i in range(2, SIZE):
    g1.append((g1[-1] * i) % MOD)
    inverse.append((-inverse[MOD % i] * (MOD // i) ) % MOD)
    g2.append((g2[-1] * inverse[-1]) % MOD)

print(comb(n - 1, k - 1, MOD))

Measured memory_bytes: 118928
def main():
    from itertools import combinations
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    cc = combinations(range(n), (n-1)//2+1)
    m = 10**9
    if n == 1:
        print(0)
        return
    for c in cc:
        memo1 = []
        memo2 = []
        for i in c:
            if i % 2 == 0:
                memo1.append((a[i], i))
            else:
                memo1.append((b[i], i))
        for i in set(range(n))-set(c):
            if i % 2 == 1:
                memo2.append((a[i], i))
            else:
                memo2.append((b[i], i))
        memo1.sort()
        memo2.sort()
        memo = []
        for i in range(n//2):
            memo.append(memo1[i])
            memo.append(memo2[i])
        if n % 2 == 1:
            memo.append(memo1[i+1])
        flag = 0
        for i in range(n-1):
            if memo[i][0] > memo[i+1][0]:
                flag = 1
                break
        if flag == 1:
            continue
        memo = [i for j, i in memo]
        cnt = 0
        for i in range(n-1):
            for j in range(i+1, n):
                if memo[i] > memo[j]:
                    cnt += 1
        m = min(cnt, m)
    if m == 10**9:
        print(-1)
    else:
        print(m)


main()


Measured memory_bytes: 3188
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
inline int read(){int now=0;register char c=getchar();for(;!isdigit(c);c=getchar());
for(;isdigit(c);now=now*10+c-'0',c=getchar());return now;}
#define For(i, x, y) for(int i=x;i<=y;i++)  
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))  
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);  
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);  
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long  
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second 
typedef vector<int> VI;
const double eps = 1e-9;
const int maxn = 110;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7; 
int N,M,K;
int MAP[maxn][maxn];
int main(){
	Sca2(N,M);
	N--;M--;
	for(int i = 1; i <= 20; i += 2){
		for(int j = 1; j <= 100; j += 2){
			if(M){
				MAP[i][j] = 0;
				M--;
			}else{
				MAP[i][j] = 1;
			} 
		}
		for(int j = 2; j <= 100; j += 2){
			MAP[i][j] = 1;
		}
	}
	for(int i = 2; i <= 20;i += 2){
		for(int j = 1 ; j<= 100; j ++){
			MAP[i][j] = 1;
		}
	}
	for(int i = 1; i <= 100; i ++){
		MAP[21][i] = 1;
		MAP[22][i] = 0;
	}
	for(int i = 23; i <= 43; i += 2){
		for(int j = 1; j <= 100; j += 2){
			if(N){
				MAP[i][j] = 1;
				N--;
			}else{
				MAP[i][j] = 0;
			}
		}
		for(int j = 2; j <= 100; j += 2){
			MAP[i][j] = 0;
		}
	}
	for(int i = 24; i <= 43; i += 2){
		for(int j = 1; j <= 100; j ++){
			MAP[i][j] = 0;
		}
	}
	cout << 43 << " " << 100 << endl;
	for(int i = 1; i <= 43; i ++){
		for(int j = 1; j <= 100; j ++){
			if(MAP[i][j] == 0) printf("#");
			else printf(".");
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 10000

int main()
{
  int i,j,n,q;
  int S[N],key,c=0; // keyは数列T

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    S[n]=key;
    for(j=0;S[j]!=key;j++){
    }
    if(j==n) continue;
    c++;
  }
  printf("%d\n",c);

  return 0;
}
  



Measured memory_bytes: 2048
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAX 10e200000+1

int main(void){

    int i, ans=0, num = '0';
    char N[200001];

    scanf("%s",N);

    for(i = 0;i < strlen(N);i++){
        ans += N[i] - num;
        //printf("%d\n",ans);
    }

    if(ans % 9 != 0) printf("No\n");
    else printf("Yes\n");
    return 0;
}

Measured memory_bytes: 1856
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
 
struct node{
    int val;
    node *lch,*rch;
    node(int val):val(val){}
};
 
node *make(string s){
    int stk=0;
    rep(i,s.size()){
        if(s[i]=='(')stk++;
        else if(s[i]==')')stk--;
        else if(s[i]=='['){
            if(stk)continue;
            string l=s.substr(1,i-2);
            int cur=i+1,val=0;
            while(s[cur]!=']'){
                val=val*10+s[cur]-'0';
                cur++;
            }
            cur++;
            string r=s.substr(cur+1,s.size()-cur-1);
            node *t=new node(val);
            t->lch=make(l);
            t->rch=make(r);
            return t;
        }
    }
    return NULL;
}
 
string tostring(int a){
    stringstream ss;
    ss<<a;
    return ss.str();
}
 
string dfs(node *s,node *t){
    if(s==NULL||t==NULL)return "";
    return "("+dfs(s->lch,t->lch)+")["+tostring(s->val+t->val)+"]("+dfs(s->rch,t->rch)+")";
}
 
signed main(){
    string S,T;
    cin>>S>>T;
    node *s=make(S);
    node *t=make(T);
    cout<<dfs(s,t)<<endl;
    return 0;
}

Measured memory_bytes: 3388
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        int b = input.nextInt();
        int flag = b * 2 + 1;
        if(a % flag == 0) System.out.println(a / flag);
        else System.out.println(a / flag + 1);
    }
}


Measured memory_bytes: 21972
n = int(input())
x,u = [0]*n,['0']*n
Otoshidama = 0
for i in range(n):
  a = input().split()
  x[i] = float(a[0])
  u[i] = a[1]
  if(u[i] == 'JPY'):
    Otoshidama += x[i]
  else:
    Otoshidama += (x[i] *  380000.0)

print(Otoshidama)

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{  int i,n,t,j,max,min,a[200000];
   scanf("%d",&n); 
   for(i=0;i<n;i++)
   scanf("%d",&a[i]);
   max=-2000000000;
   min=a[0];
   for(i=1;i<n;i++)
   {  if(max>=a[i]-min) max=max; else max=a[i]-min;
      if(min<=a[i])  min=min; else min=a[i];
   }
   printf("%d\n",max);
   return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
	char num[10];

	cin >> num;
	int flag = 0;
	for (int i = 1; i < 4; ++i) {
		if (num[i] == num[i - 1]) flag = 1;
	}
	if (flag) printf("Bad\n");
	else cout << "Good" << endl;
	return 0;
}


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

using namespace std;

int main(void)
{
    char c[3][3];
    cin >> c[0][0] >> c[1][0] >> c[2][0];
    cin >> c[0][1] >> c[1][1] >> c[2][1];
    cin >> c[0][2] >> c[1][2] >> c[2][2];

    cout << c[0][0] << c[1][1] << c[2][2] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {

  int a,b,t,c;
  
  std::cin >> a;
  std::cin >> b;
  std::cin >> t;
  
  if((1 <= a) || (a <= 20) || (1 <= b) || (b <= 20) || (1 <= t) || (t <= 20) ) {
  
    
    c = (t + 0.5) / a;    
    std::cout <<   c * b ;
    
  
  }
  


}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	Scanner sc;
	int[] A;
	int N;

	public Main() {
		sc = new Scanner(System.in);
	}
	
	private void calc() {
		N = sc.nextInt();
		A = new int[N];
		for (int i = 0; i < N; i++) A[i] = sc.nextInt();
		double s = 0d;
		for (int i = 0; i < N; i++) s += 1d/A[i];
		System.out.println(1d/s);
		System.out.flush();
	}

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

}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fs first
#define sc second
#define mp make_pair
using namespace std;
typedef double D;
typedef pair<D,int> pii;

int main(){
  int h,w;
  string f[999];
  cin.tie(0);
  std::ios::sync_with_stdio(0);
  cin >> h >> w;

  vector<pii> v;
  rep(i,h){
    cin >> f[i];
    rep(j,w){
      if( f[i][j]=='#'&&(i==0||f[i-1][j]=='.') ){
	v.push_back(mp((D)(h-i)/j,-1));
	v.push_back(mp((D)(h-i)/(j+1),1));
      }
      if( f[i][j]=='#'&&(j==w-1||f[i][j+1]=='.') ){
	v.push_back(mp((D)(h-i)/(j+1),-1));
	v.push_back(mp((D)(h-i-1)/(j+1),1));
      }
    }
  }

  int res = 0, tmp = 1;
  sort(v.begin(),v.end());
  rep(i,v.size())res = max(res,tmp += v[i].sc);
  cout << res << endl;
}

Measured memory_bytes: 11440
input_num = int(input())
line = input().split(" ")
over_flg = False
if ("0" in line):
    print("0")
else:
    output = 1
    for i in range(input_num):
        output = output * int(line[i])
        if output > 10 ** 18:
            over_flg = True
            break
    if over_flg:
        print("-1")
    else:
        print(output)

Measured memory_bytes: 73140
import java.io.IOException;
import java.util.Arrays;

public class Main{
    public static void main(String[] a) throws IOException {
		int set,i,j;
		int s1,s2,s3;
		int[] array = new int[3];
		String[] stock = new String[3];
		java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
		String Input = in.readLine();

		set = Integer.parseInt(Input);

		for(i = 0;i < set;i++){
			Input = in.readLine();
			stock = Input.split(" ");

			for(j = 0;j < 3;j++)
				array[j] = Integer.parseInt(stock[j]);
			
			Arrays.sort(array);

			if(Math.pow(array[0],2) + Math.pow(array[1],2) == Math.pow(array[2],2)){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
    }
}

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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> bounce(n + 1);
  for (int i = 1; i < n + 1; i++) {
    cin >> bounce.at(i);
  }
  bounce.at(0) = 0;
  for (int i = 1; i < n + 1; i++) {
    bounce.at(i) += bounce.at(i - 1);
  }
  int ans = 0;
  for (int i = 0; i < n + 1; i++) {
    if (bounce.at(i) <= x) {
      ans++;
    }
  }
  cout << ans << endl;
}

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


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    r = 0
    b = 0
    ans = 0
    for l in range(N):
        while r < N and A[r] & b == 0:
            b |= A[r]
            r += 1
        ans += r - l
        b = b ^ A[l]

    print(ans)




if __name__ == '__main__':
    main()



Measured memory_bytes: 24372
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

int main() {
	int A, B; cin >> A >> B;
	int ans = A + B;
	if (ans < 10)cout << ans << "\n";
	else cout << "error" << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

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

	map<int, int> A;

	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		A[tmp]++;
	}

	priority_queue<pair<int, int>> pq;

	for (auto a : A) {
		pq.push(make_pair(a.first, a.second));
	}

	while (!pq.empty()) {
		auto i = pq.top(); pq.pop();
		if (i.second < 2) continue;
		if (i.second == 2 || i.second == 3) {
			while (!pq.empty()) {
				auto j = pq.top(); pq.pop();
				if (j.second < 2) continue;

				cout << (long long)i.first * j.first << endl;
				return 0;
			}
		}
		else {
			cout << (long long)i.first * i.first << endl;
			return 0;
		}
	}

	cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 6136
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		int K = int.Parse(str[2]);
		var listM = new List<int>[N];
		var listK = new List<int>[N];
		for(var i=0;i<N;i++){
			listM[i] = new List<int>();
			listK[i] = new List<int>();
		}
		var uf = new UnionFind(N);
		int[]C = new int[N];
		for(var i=0;i<N;i++){
			C[i] = 1;
		}
		for(var i=0;i<M;i++){
			string[] str2 = Console.ReadLine().Split();
			int m1 = int.Parse(str2[0]);
			int m2 = int.Parse(str2[1]);
			listM[m1-1].Add(m2-1);
			listM[m2-1].Add(m1-1);
			uf.Unite(m1-1,m2-1);
			int c1 = C[m1-1];
			int c2 = C[m2-1];
			C[m1-1] = c1+c2;
			C[m2-1] = c1+c2;
		}
		var uf2 = new UnionFind(N);
		for(var i=0;i<K;i++){
			string[] str2 = Console.ReadLine().Split();
			int m1 = int.Parse(str2[0]);
			int m2 = int.Parse(str2[1]);
			listK[m1-1].Add(m2-1);
			listK[m2-1].Add(m1-1);
			uf2.Unite(m1-1,m2-1);
		}
      	int[]D = new int[N];
		for(var i=0;i<N;i++){
          Console.Error.Write(uf.Root(i)+" ");
          D[uf.Root(i)]++;
        }
		for(var i=0;i<N;i++){
			int ct = D[uf.Root(i)]-1;
			Console.Error.Write(ct+" ");
			for(var j=0;j<listM[i].Count;j++){
				if(uf.Root(i)==uf.Root(listM[i][j])){
					ct--;
				}
			}
			for(var j=0;j<listK[i].Count;j++){
				if(uf.Root(i)==uf.Root(listK[i][j])){
					ct--;
				}
			}
			Console.Write(ct+" ");
		}
	}
}
public class UnionFind
{
    private int[] data;
	public UnionFind(int size){
        data = new int[size];
        for (int i = 0; i < size; i++) data[i] = -1;
    }
    public bool Unite(int x, int y){
        x = Root(x);
        y = Root(y);
        if (x != y){
            if (data[y] < data[x]){
                var tmp = y;
                y = x;
                x = tmp;
            }
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
	public bool IsSameGroup(int x, int y){
        return Root(x) == Root(y);
    }
    public int Root(int x){
        return data[x] < 0 ? x : data[x] = Root(data[x]);
    }
}

Measured memory_bytes: 37220
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
using namespace std;

int main(){
    int k,t;
    cin >> k >> t;
    int mx=0;
    for(int i=0;i<t;i++){
        int a;
        cin >> a;
        mx=max(mx,a);
    }
    cout << max((mx-(k+1)/2)*2-(k+1)%2, 0) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <utility>
#include <algorithm>
#include <stdlib.h>
using namespace std;


main(){
	int n;
	scanf("%d",&n);
	vector<int> a(n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	
	vector<pair<int,int> > b(n);
	for(int i=0;i<n;i++)b[i]=make_pair(a[i],i);
	sort(b.begin(),b.end());
	
	int c0=0,c1=0;
	for(int i=0;i<n;i++){
		if(i%2==0)c0++;
		if(i%2==0&&b[i].second%2==0)c1++;
	}
	printf("%d\n",c0-c1);
}

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

L = [0] * 87
L[0] = 2
L[1] = 1

def cal(N: int):
    n = L[N]
    if n != 0:
        return n
    L[N] = cal(N-1)+ cal(N-2)
    return L[N]

def solve(N: int):
    print(cal(N))

    return


# Generated by 1.1.7.1 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()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61700
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String number = scanner.next();
        int modulo = scanner.nextInt();
        long lots = 1000000007;

        long[][] exact = new long[number.length() + 1][modulo];
        long[][] less = new long[number.length() + 1][modulo];
        exact[0][0] = 1;

        for (int i = 1; i <= number.length(); ++i) {
            for (int m = 0; m < modulo; ++m) {
                for (int d = 0; d <= 9; ++d) {
                    less[i][m] += less[i - 1][mod(m - d, modulo)];
                    less[i][m] %= lots;
                }

                int digit = number.charAt(i - 1) - '0';
                for (int d = 0; d < digit; ++d) {
                    less[i][m] += exact[i - 1][mod(m - d, modulo)];
                    less[i][m] %= lots;
                }

                exact[i][m] += exact[i - 1][mod(m - digit, modulo)];
                exact[i][m] %= lots;
            }
        }

        long res = exact[number.length()][0] + less[number.length()][0];
        res = (res + lots - 1) % lots;

        System.out.println(res);
    }

    public static int mod(int val, int modulo) {
        int res = val % modulo;
        return res < 0 ? res + modulo : res;
    }

}


Measured memory_bytes: 57172
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin >> a >> b;
    print((a+b) % 24);

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;

using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
#define endl        	"\n"
#define int         	long long int  
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define pll         	pair<ll,ll>
#define vec     		vector<ll>
#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod     		1000000007

ll mod_pow(ll a,ll b)
{
    ll res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    
    return res;
}

void solve()
{
	ll n,x,y;
	
	cin>>n>>x>>y;
	
	vector<ll> ans(n,0);
	
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			ll mi = min(j-i,abs(y-j)+1+abs(x-i));
			
			ans[mi]++;
		}
	}
	
	for(int i=1;i<n;i++)
	{
		cout<<ans[i]<<endl;
	}
}
 
signed main()
{
 
    fast;
 
    ll t;
    
    t=1;
    
    //cin>>t;
    
    while(t--)
    {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 256
N=int(input())
T=list(map(int,input().split(" ")))
M=int(input())
drink=[list(map(int,input().split(" "))) for _ in range(M)]
def_sum=sum(T)

for i in range(M):
  print(def_sum-(T[drink[i][0]-1]-drink[i][1]))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int min (int a, int b){
	if (a<b) return a;
  	else return b;
}
int main (){
	int n; cin >> n;
  	vector<int> a(n);
  	for(int i=0;i<n;i++){cin>>a[i];}
  	if (n==1){cout << 0; return 0;}
  	if (n==2){cout << abs(a[0] - a[1]); return 0;}
  	vector<int> dp(n);
  	dp[n-1]=0;
  	dp[n-2]=abs(a[n-2]-a[n-1]);
  	for(int i=n-3;i>=0;i--){
    	dp[i] = min(dp[i+1] + abs(a[i+1] - a[i])
                    , dp[i+2] + abs(a[i+2] - a[i]));
    }
  	cout << dp[0];
}



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

int main() {
  int N;
  cin >> N;
  double b_ans=0;
  rep(i,N) {
    double a;
    cin >> a;
    b_ans += 1/a;
  }
  double ans = 0;
  ans = 1/b_ans;
  cout <<ans<< endl;
}

Measured memory_bytes: 256
const Debug = function () {
    const stdin = function (text) {

    };

    return stdin;
};


const Release = function () {
    const fs = require('fs');
    const stdin = function (text) {
        if (text) console.log(text);
        return fs.readFileSync('/dev/stdin', 'utf8');
    }
    return stdin;
};


const debug = false;

const stdin = debug ? Debug() : Release();
const input = stdin().split('\n').map(x => parseInt(x));

const X = input[0];
const A = input[1];
const B = input[2];

const c = (X - A) % B;
console.log(c);

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

int N;
int a[111111];
int b[111111];
int c[111111];
int dp[111111][3];
int main(){
    cin >> N;
    for(int i=0; i<N; i++)
        cin >> a[i] >> b[i] >> c[i];


    for(int i=0; i<=N; i++)
        for(int j=0; j<3; j++)
            dp[i][j] = 0;

    for(int i=0; i<N; i++){
        dp[i+1][0] = max(dp[i+1][0], max(dp[i][1], dp[i][2]) + a[i]);
        dp[i+1][1] = max(dp[i+1][1], max(dp[i][2], dp[i][0]) + b[i]);
        dp[i+1][2] = max(dp[i+1][2], max(dp[i][0], dp[i][1]) + c[i]);
    }
    int ans = max(dp[N][0], max(dp[N][1], dp[N][2]));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define prints(x, y) cout<<(x)<<" "<<(y)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define r_rep(i, n) for(int i = n; i >= 0; i--)
#define ll long long int
#define pb push_back

const long long INF = 1LL << 60;

int main() {
  int a, b;
  cin >> a >> b;
  print(a*b);
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 1000 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
long long k;
long long a[N], b[N];

bool read() {
    if (!(cin >> n >> k))
        return false;

    for (int i = 0; i < n; ++i)
        cin >> a[i];

    return true;
}

bool check(long long d, long long k) {
    for (int i = 0; i < n; ++i)
        b[i] = a[i] % d;

    sort(b, b + n);

    for (int l = 0, r = n - 1; l < r; ) {
        auto cur = min(b[l], d - b[r]);
        b[l] -= cur;
        b[r] += cur;
        k -= cur;
        if (b[l] == 0) ++l;
        if (b[r] == d) --r;
    }

    for (int i = 0; i < n; ++i)
        if (b[i] % d != 0 || k < 0)
            return false;

    return true;
}

void solve() {
    auto sum = accumulate(a, a + n, 0ll);
    auto ans = 1ll;

    for (auto d = 1ll; d * d <= sum; ++d)
        if (sum % d == 0) {
            if (check(d, k)) ans = max(ans, d);
            if (check(sum / d, k)) ans = max(ans, sum / d);
        }

    cout << ans << endl;
}
 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();
 
    return 0;
}
 


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod 1000000007
#pragma GCC optimize ("-O2")
#define mod2 998244353
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector <vector <int>>
#define v4096 vector <vector <lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli,lli>
#define m32 map<int,int>
#define m64it map<lli,lli>::iterator
#define m32it map<int,int>::iterator
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ist insert
#define endl "\n"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<pair<lli,int>, null_type,less<pair<lli,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define p_q priority_queue 
#define min_p_q priority_queue <int,vt <int>,greater <int>>
using namespace std;
using namespace __gnu_pbds; 
template <typename T> 
void DEBUG_ARR(vt<T> a){
	f(i,0,a.size())cout<<a[i]<<" ";
	cout<<"\n";
}

int main() { 
    fastio;
    lli n;
    cin>>n;
    if(n&1){
        cout<<0<<"\n";
    }
    else{
        n/=2;
        lli ans=0;
        while(n!=0){
            ans+=n/5;
            n/=5;
        }
        cout<<ans<<"\n";
    }
    return 0; 	
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <iostream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <valarray>
#include <vector>
#include <utility>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define REP(i, n) for((i) = 0; (i) < (n); i++)
#define FOR(i, a, n) for((i) = (a); (i) < (n); i++)

using namespace std;

const int INF = 1000000000;
const double PI = acos(-1);

typedef long long ll;

#define MAXN 260

int i, j, n, ans, grid[MAXN][MAXN], hor[MAXN][MAXN], ver[MAXN][MAXN], diagp[MAXN][MAXN], diago[MAXN][MAXN];
string str;

void reset() {
    memset(grid, 0, sizeof(grid));
    memset(hor, 0, sizeof(hor));
    memset(ver, 0, sizeof(ver));
    memset(diagp, 0, sizeof(diagp));
    memset(diago, 0, sizeof(diago));
}

int main(void) {
    while(scanf("%d", &n) == 1 && n != 0) {
        reset();
        ans = 0;
        REP(i, n) {
            cin >> str;
            REP(j, n) {
                grid[i][j] = str[j] - '0';
                if(grid[i][j] == 1) {
                    if(j - 1 >= 0) {
                        hor[i][j] = hor[i][j - 1] + 1;
                    } else {
                        hor[i][j] = grid[i][j];
                    }
                    if(i - 1 >= 0) {
                        ver[i][j] = ver[i - 1][j] + 1;
                    } else {
                        ver[i][j] = grid[i][j];
                    }
                    if(i - 1 >= 0 && j - 1 >= 0) {
                        diagp[i][j] = diagp[i - 1][j - 1] + 1;
                    } else {
                        diagp[i][j] = grid[i][j];
                    }
                    if(i - 1 >= 0 && j + 1 < n) {
                        diago[i][j] = diago[i - 1][j + 1] + 1;
                    } else {
                        diago[i][j] = grid[i][j];
                    }
                }
                ans = max(ans, hor[i][j]);
                ans = max(ans, ver[i][j]);
                ans = max(ans, diagp[i][j]);
                ans = max(ans, diago[i][j]);
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 2556
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

struct UF {
    vector<int> par, rank, si;

    void init(int n){
        par.assign(n, 0);
        rank.assign(n, 0);
        si.assign(n, 1);
        iota(par.begin(), par.end(), 0);
    }

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

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        
        if(rank[x] < rank[y]){
            par[x] = y;
            si[y] += si[x];
        } else{
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
            si[x] += si[y];
        }
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }
} uf;

ll N, M, Q;
vector<pi> v;

int main() {
    cin >> N >> M >> Q;
    uf.init(N);
    rep(i,Q) {
        int a, b, c;
        cin >> a >> b >> c;
        if (c == 0) uf.unite(a,b);
        else v.push_back(pi(a,b));
    }
    if (v.size() == 0) {
        if (M == N-1) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }
    if (M == N-1) {
        cout << "No" << endl;
        return 0;
    }
    rep(i,v.size()) {
        if (uf.same(v[i].first, v[i].second)) {
            cout << "No" << endl;
            return 0;
        }
    }
    ll cnt = 0;
    rep(i,N) {
        if (uf.find(i) == i) cnt++;
    }
    if (cnt == 2) {
        cout << "No" << endl;
        return 0;
    }
    if (M > N + cnt*(cnt-3)/2) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 2552
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
#define out(x) cout<<x<<"\n";
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
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;
}


ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}
 
ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}

using namespace std;

void solve()
{
	int n, m;
	cin >> n >> m;
	vector<ll> x(n), y(n), z(n);
	rep(i,n){
		cin >> x[i] >> y[i] >> z[i];
	}
	ll ans = 0;
	REP(a, -1, 2)REP(b, -1, 2) REP(c, -1, 2)
	{
		if(a==0)
			continue;
		if(b==0)
			continue;
		if(c==0)
			continue;
		vector<vector<ll>> dp(n + 5, vector<ll>(n + 5,-INF));
		dp[0][0] = 0;
		rep(i, n)
		{
			rep(j,i+1){
				chmax(dp[i + 1][j + 1], dp[i][j] + a * x[i] + b * y[i] + c * z[i]);
				chmax(dp[i + 1][j], dp[i][j]);
			}
		}
		chmax(ans,dp[n][m]);
	}
	cout << ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 8220
def main():
    N, A, B = map(int, input().split())
    result = N
    if (A % 2 == 0 and B % 2 == 0) or  (A % 2 == 1 and B % 2 == 1):
        result = abs(A - B) // 2
    else:
        if A - 1 < N - B:
            result = ((B - 1) - (A - 1 + 1)) // 2 + (A - 1 + 1)
        else:
            result = ((N - A) - (N - B + 1)) // 2 + (N - B + 1)

    print(int(result))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
 
const ll MOD = 1e9+7;
const double PI  = 3.14159265358;
const double eps = 1e-8;
 
#define INF 2147483647
#define X first
#define Y second
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define FILL(v,n) memset(v,n,sizeof(v))
#define EB emplace_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep1n(i,n)	for(int i=1;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie();cout.tie();
 
#define MXN 1000000 //10^6

int main(){
	int n;
	long long ans;
	bool b[11], ft[11];
	char c;
	vector<int> v, ct;
	 
	ans = 0;
	 
	cin>>n;
	v.resize(n);
	ct.resize(n+1);
	rep(i,n){
		cin>>c;
		v[i] = c - '0';
	}
	
	FILL(b, 0);
	FILL(ft, 0);
	ct[n] = 0;
	for(int i=n-1;i>=0;i--){
		if(b[v[i]] == false)
			ct[i] = ct[i+1]+1;
		else
			ct[i] = ct[i+1];
		b[v[i]] = true;
	}
	
	rep(i,n-1){
		if(ft[v[i]] == 0){
			FILL(b, 0);
			for(int j=i+1;j<n;j++){
				if(b[v[j]] == 0){
					ans += ct[j+1];
					b[v[j]] = 1;
				}
			}
			ft[v[i]] = 1;
		}	
	}
	cout<<ans;
}







Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<numeric>
#include<algorithm>
#include<tuple>
#include<cmath>

typedef unsigned long long ull;
typedef long long ll;

ll DENOM = 1000000000LL + 7LL;
using namespace std;

int main(){
    int k;
    string s;
    cin >> k >> s;
    for (int i=0; i<s.size(); ++i){
        if(i==k){
            cout << "...";
            break;
        }
        cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3044
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e3+9;
const double ep=1e-7;
const int mod=998244353;
const double pi=acos(-1);
const int INF=-1e9;
#define mk make_pair
#define PII pair<int,int>
#define PIII pair<int,PII >
#define PIL pair<int,ll>
#define PLI pair<ll,int>
#define eb emplace_back
typedef long long ll;
ll n,k,p[maxn],c[maxn],ans=-1e9;
int main()
{
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++)scanf("%lld",&p[i]);
	for(int i=1;i<=n;i++)scanf("%lld",&c[i]);
	for(int i=1;i<=n;i++)
	{
		ll now=i,num=0,sum=0;
		do{
			now=p[now];
			sum+=c[now];
			num++;
		}while(now!=i);
		now=i;
		ll ss=0;
		for(int j=1;j<=min(k,num);j++)
		{
			now=p[now];
			ss+=c[now];
			ans=max(ans,ss);
			ans=max(ans,ss+sum*((k-j)/num));
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 3884
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    if((B-A)%2 == 0){
        cout << (B-A)/2 << endl;
    }
    else{
        cout << min(A-1, N-B) + 1 + (B-A-1)/2 << endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>h>>w>>x>>y;
    if((h*w)%2==1&&(x+y)%2==1)Cout("No");
    else Cout("Yes");
    return 0;
}




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

long long int n, mat[100+1][100+1], len[100+1];

int main(void){
  int i, j, k, l;

  scanf("%d", &n);
  
  for(int i=1; i<=n; i++){
    scanf("%d %d", &len[i-1], &len[i]);
  }
  
  for(l=2; l<=n; l++){
    for(i=1; i<=n-l+1; i++){
      j=i+l-1;
      mat[i][j]=INT_MAX;

      for(k=i; k<=j-1; k++){
	mat[i][j]=min(mat[i][j], mat[i][k]+mat[k+1][j]+len[i-1]*len[k]*len[j]);
      }
    }
  }

  printf("%d\n", mat[1][n]);
  
  return 0;
}



Measured memory_bytes: 3260
#ifdef __LOCAL
  #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

int main(){
  ll n; cin >> n;
  if(n==1){
    cout << "YES" << endl;
    return 0;
  }
  vector<int> a(n);
  ll sum=0;
  rep(i,n){
    cin >> a[i];
    sum+=a[i];
  }
  vector<itn> tol(n);
  rep(i,n) tol[i]=a[i]-a[(i-1+n)%n];
  int mx=0;
  rep(i,n) chmax(mx,tol[i]);
  ll cnt=0;
  rep(i,n){
    if((mx-tol[i])%n){
      cout << "NO" << endl;
      return 0;
    }
    cnt+=(mx-tol[i])/n;
  }
  if(sum==n*(n+1)/2*cnt) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3984
//Code is like humor. When you have to explain it, it’s bad.
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <bits/stdc++.h>
#define MOD 1000000007
#define MOD1 998244353
#define endl "\n"
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mkp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pairs;
typedef map<int,int> maps;
typedef vector <int> VI;
typedef std::multimap<int, pair<int,int>>::iterator MMIPIterator;
typedef std::map<int, int>::iterator MIIIterator;
double pi = 2 * acos(0.0);


int32_t main()  {
    fastio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    #endif
    
    unordered_map <string,int> mp;
    string s;
    int n;
    cin>>n;
    forn(i,n) {
        cin>>s;
        mp[s] ++;
    }
    cout << mp.size() << endl;
    
    return 0;
    
}



Measured memory_bytes: 17688
#include<stdio.h>
#define MAX 100005
#define NIL -1

typedef struct {
  int parent;
  int right;
  int left;
} _T;
_T T[MAX];

void print(int u){
 
 int i=T[u].parent, depth=0;
 while(i!=NIL){
   i = T[i].parent;
   depth++;
   }
        if(depth==0){
    printf("node %d: parent = %d, depth = %d, root, ",u,T[u].parent,depth);
    }
	else if(T[u].left==NIL){
    printf("node %d: parent = %d, depth = %d, leaf, ",u,T[u].parent,depth);
    }
	else{
    printf("node %d: parent = %d, depth = %d, internal node, ",u,T[u].parent,depth);
    }
  
	i = T[u].left;
  printf("[");
  if(i!=NIL){
   printf("%d",i);
   }
  
     while (i!=-1){
       i = T[i].right;
       if(i!=NIL){
	 printf(", %d", i);
       }
     }
     printf("]\n");
}

int main(){
  int i, j, d, v, c, l, n;
 /*d = degreenumber, v = Vertexnumber, c = current*/
 scanf("%d", &n);
  
	for(i=0;i<n;i++){
   T[i].parent = T[i].left = T[i].right = NIL;
   }
  
	   for ( i = 0; i < n; i++ ){
    
    scanf("%d %d",&v,&d);
    
 for(j=0;j<d;j++){
      scanf("%d",&c);
      T[c].parent = v;
      
	       if(j==0){
		 T[v].left = c;
	       }
	       else if(j>0){
		 T[l].right = c;
	       }
      l = c;
      
	       }
    }
		
	for (i=0;i<n;i++){
    print(i);
    }
 return 0;
}

Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;
#define debug(var) cout << #var << ": " << var << endl;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
using ll = long long;
using ull = unsigned long long;
using vvint = vector<vector<int>>;
constexpr ll mod = 1e9 + 7;

int main() {

  int N, Q; cin >> N >> Q;
  vector<int> par(N, -1);//各頂点の親を格納(親がいないときは-1を格納)
  vector<int> ans(N, 0);
  rep(i, N - 1) {
	int a, b; cin >> a >> b;
	a--; b--;
	par[b] = a;
  }
  rep(i, Q) {
	int p, x; cin >> p >> x;
	p--;
	ans[p] += x;
  }
  rep(i, N) {
	if (par[i] != -1) {//もし親がいたら
	  ans[i] += ans[par[i]];
	}
  }

  rep(i, N)cout << ans[i] << " ";

  return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lint N, M, K;
    cin >> N >> M >> K;
    vector<lint> A(N);
    REP(i, N) cin >> A[i];
    vector<lint> B(M);
    REP(i, M) cin >> B[i];
    vector<lint> S(M+1);
    REP(i, M) S[i+1] = S[i] + B[i];
    int ans = 0;
    lint Asum = 0;
    REP(i, N+1) {
        if(Asum > K) break;
        int l = 0;
        int r = M+1;
        while(r-l > 1) {
            int m = (l+r) / 2;
            if(Asum + S[m] <= K) {
                l = m;
            } else {
                r = m;
            }
        }
        if(i + l > ans) ans = i + l;
        if(i != N) Asum += A[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 7948
#include <bits/stdc++.h>
using namespace std;
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;

int main(){
  int N;
  double x;
  string u;
  cin >> N;
  double ans = 0;
  for(int i=0; i<N; i++){
    std::cin >> std::setprecision(15) >> x;
    cin >> u;
    if(u=="JPY"){
      ans+=x;
    }
    else{
      ans+=x*380000;
    }
  }
  std::cout << std::fixed << std::setprecision(15) << ans << endl;
}


Measured memory_bytes: 256