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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
    int N,C;
    cin >> N >> C;
    VVI D(C+1,VI(C+1)), c(N+1,VI(N+1));
    for (int i = 1; i <= C; i++) {
        for (int j = 1; j <= C; j++) {
            cin >> D[i][j];
        }
    }
    VVI count_mod(3,VI(C+1,0));
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            cin >> c[i][j];
            int t = (i + j) % 3;
            count_mod[t][c[i][j]]++;
        }
    }

    LL ans = INT64_MAX;
    for (int mod0_color = 1; mod0_color <= C; mod0_color++) {
        for (int mod1_color = 1; mod1_color <= C; mod1_color++) {
            if (mod1_color == mod0_color) {
                continue;
            }
            for (int mod2_color = 1; mod2_color <= C; mod2_color++) {
                if (mod0_color == mod2_color or mod1_color == mod2_color) {
                    continue;
                }
                LL iwakan = 0;
                for (int i = 1; i <= C; i++) {
                    iwakan += D[i][mod0_color] * count_mod[0][i];
                    iwakan += D[i][mod1_color] * count_mod[1][i];
                    iwakan += D[i][mod2_color] * count_mod[2][i];
                }
                ans = min(ans,iwakan);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define endl '\n'
const int INF = (1 << 30);
using namespace std;
typedef long long int ll;

void solve(){
    string s;
    int K, op = 'z'+1;
    cin >> s >> K;
    auto end = s.end();
    for(auto it = s.begin(); it!=end; it++){
        if(*it != 'a'){
            int loss = (op - *it);
            if(loss <= K){
                K -= loss;
                *it = 'a';
            }
        }
    }
    end--;
    *end = (((*end - 'a') + K) % 26)+ 'a';
    cout << s << endl;
}

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

    solve();
}


Measured memory_bytes: 592
import sys


def input(): return sys.stdin.readline().strip()


def resolve():
    n = int(input())
    l = list(map(int, input().split()))
    check=[False]*8
    jiyu=0
    for i in l:
       if i<3200:
           check[i//400]=True
       else:
           jiyu+=1
    cnt=0
    for j in check:
        if j:
            cnt+=1
    if cnt==0:
        print(1,jiyu)
    else:
        print(cnt,cnt+jiyu)
resolve()

Measured memory_bytes: 38256
#include<iostream>
//#include<math.h>
using namespace std;

int main(){
  int n,k;
  cin>>n>>k;
  double ans=1.0;
  double sum=0;
  double tmp;
  for(int i=0;i<n;i++){
    tmp=i+1;
    for(int i1=0;tmp<k;i1++){
      tmp=tmp*2;}
    ans=1.0*(double)(i+1)/((double)n*tmp);
    sum+=ans;}
  printf("%.12f\n",sum);
  //  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){

    int s;
    int hour,min,sec;

    scanf("%d", &s);

    hour = s / 3600;
    s %= 3600;
    min = s / 60;
    s %= 60;
    sec = s;

    printf("%d:%d:%d\n", hour, min, sec);

    return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;
int main() {
  int W, H, x, y;
  cin >> W >> H >> x >> y;
  cout << (double) W * H / 2 << " ";
  if (W % 2 == 0 && H % 2 == 0 && W / 2 == x && H / 2 == y) {
	  cout << 1 << endl;
	}
  else {
	  cout << 0 << endl;
	}
  return 0;
}


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

using namespace std;

vector <int> vec;

typedef long long ll;
typedef pair<ll, ll> pl;
typedef vector <ll> vl;
typedef set <ll> sl;
typedef vector <pair <ll, ll>> vll;
typedef map <string, int> msi;


int main() {
	ios::sync_with_stdio(false);



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

	sort(vec.begin(), vec.end());

	cout << vec[n - 1] - vec[0];


	return 0;
}


Measured memory_bytes: 256
N,M = list(map(int, input().split()))
ab = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x:x[1])

bef=-1
cnt = 0
for one in ab:
    if one[0]<=bef and bef<=one[1]:
        continue
    else:
        bef = one[1]-1
        cnt+=1
print(cnt)

Measured memory_bytes: 65240
#include<stdio.h>
int main()
{
    int n,flag = 0;
    scanf("%d",&n);
    int a,b;
    scanf("%d%d",&a,&b);
    for(int i=a; i<=b; ++i){
        if(i%n==0){
            flag = 1;
            break;
        }
    }
    if(flag){
        printf("OK\n");
    }
    else
        printf("NG\n");
    return 0;
}


Measured memory_bytes: 1608
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int N = sc.nextInt();
    HashSet<Integer> set = new HashSet<Integer>();
    
    for(int i=0; i<N; i++){
      set.add(sc.nextInt());
    }
    
    int ans = X;
    int min = Integer.MAX_VALUE;
    for(int i = 0; i<=200; i++){
      if(set.contains(i)){
        continue;
      }
      int gap = Math.abs(X - i);
      if(gap < min){
        ans = i;
        min = gap;
      }
    }
    System.out.println(ans);
  }
}
 

Measured memory_bytes: 35828
//
//   insert code here...cpp
//  AtCoder Regular Contest 090
//
//  Created by Huang,Zhiqiang on 2018/2/11.
//  Copyright © 2018年 Huang,Zhiqiang. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

typedef long long ll;

vector<pair<int,int>> ne[100005];
ll pos[100005] = { 0 };
bool visited[100005] = { false };
int N, M;
bool valid = true;

void dfs(int node, ll x) {
    if (!valid) {
        return;
    }
    visited[node] = true;
    pos[node] = x;
    for (int i = 0; i < ne[node].size(); i++) {
        int next = ne[node][i].first;
        int step = ne[node][i].second;
        if (visited[next]) {
            if (pos[next] - pos[node] != step) {
                valid = false;
                return;
            }
        } else {
            dfs(next, pos[node] + step);
        }
    }
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int l, r, d;
        cin>> l >> r >> d;
        ne[l].push_back(make_pair(r, d));
        ne[r].push_back(make_pair(l, -d));
    }
    for (int i = 1; i <= N; i++) {
        if (!visited[i]) {
            dfs(i, 0);
        }
        if (!valid) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


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

using namespace std;


#define PI 3.14159265
#define int long long


main(){

	int n, m; cin >> n >> m;


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

	map <int, int> mp;

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



	int cnt = 0, ans = 0;

	auto it = mp.begin();

	while(cnt < m){
		int temp = min(m - cnt, it->second);

		ans += it->first * temp;
		cnt += temp;

		it = next(it);
	}


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

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

int main() {

	string s, t; cin >> s >> t;
	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == t[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3588
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: u64
    }
    let mut sum: u64 = 0;
    for i in 1..n+1 {
        if i % 3 != 0 && i % 5 != 0 {
            sum += i;
        }
    }
    println!("{}", sum);
}


Measured memory_bytes: 2168
#include <iostream>
using namespace std;
int main(){
  for(int w,h;cin>>w>>h,w;){
    int n,dp[20][20]={}; dp[1][1]=1;
    cin>>n;
    for(int i=0,a,b;i<n&&cin>>a>>b;i++) dp[b][a]=-1;
    for(int i=1;i<h+1;i++) for(int j=1;j<w+1;j++) if(~dp[i][j]) dp[i][j]+=(~dp[i][j-1]?dp[i][j-1]:0)+(~dp[i-1][j]?dp[i-1][j]:0);
    cout<<dp[h][w]<<endl;
  }
  return 0;
}




Measured memory_bytes: 3064
import sys
inf=1000002
sys.setrecursionlimit(inf)
from collections import deque
h,w,k=map(int,input().split())
x1,y1,x2,y2=map(int,input().split())
c=[input() for i in range(h)]
dp=[[inf if c[i][j]=="." else -1 for j in range(w)] for i in range(h)]
now=deque()
now.append([x1-1,y1-1])
dp[x1-1][y1-1]=0
#kの更新が遅い
def bfs(d):
    global h,w,k,dp,now,x2,y2
    l=len(now)
    if l==0:
        return
    dp_sub=deque()
    cand=set()
    for i in range(l):
        x,y=now.popleft()
        for j in range(1,min(k+1,w-y)):
            if dp[x][y+j]==inf:
                dp_sub.append([x,y+j,d])
                #dp[x][y+j]=d
                cand.add((x,y+j))
                #now.append([x,y+j])
            else:
                break
        for j in range(1,min(k+1,y+1)):
            if dp[x][y-j]==inf:
                dp_sub.append([x,y-j,d])
                #dp[x][y-j]=d
                cand.add((x,y-j))
                #now.append([x,y-j])
            else:
                break
        for j in range(1,min(k+1,h-x)):
            if dp[x+j][y]==inf:
                dp_sub.append([x+j,y,d])
                #dp[x+j][y]=d
                cand.add((x+j,y))
                #now.append([x+j,y])
            else:
                break
        for j in range(1,min(k+1,x+1)):
            if dp[x-j][y]==inf:
                dp_sub.append([x-j,y,d])
                #dp[x-j][y]=d
                cand.add((x-j,y))
                #now.append([x-j,y])
            else:
                break
    while dp_sub!=deque([]):
        e=dp_sub.popleft()
        dp[e[0]][e[1]]=e[2]
    for i in cand:
        now.append(i)
    bfs(d+1)
bfs(1)
print(dp[x2-1][y2-1] if dp[x2-1][y2-1]!=inf else -1)

Measured memory_bytes: 1015364
#include <stdio.h>

int main(void){
	
	int i,j,W,H;
	scanf("%d %d",&H, &W);
	while(W!=0 && H!=0){
		for(i=1;i<=H;i++){
			for(j=1;j<=W;j++){
				printf("#");
			}
		printf("\n");
		}
	printf("\n");
	
	scanf("%d %d",&H, &W);
	}
	return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> data(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
  	for (int j = 0; j < W; j++){
    	cin >> data.at(i).at(j);
    }
  }
  
  for (int i = 0; i < data.size(); i++) {
    for (int j = 0; j < W; j++){
    	if (data.at(i).at(j) == '#') {
        	break;
        }
      	else if (j == W - 1) {
          data.erase(data.begin() + i);
          i--;
        }
    }
  }
  
  for (int j = 0; j < W; j++) {
    for (int i = 0; i < data.size(); i++){
    	if (data.at(i).at(j) == '#') {
        	break;
        }
      	else if (i == data.size() - 1) {
        	for (int k = 0; k < data.size(); k++) {
            	data.at(k).at(j) = 'X';
            }
        }
    }
  }
  
  for (int i = 0; i < data.size(); i++) {
  	for (int j = 0; j < W; j++){
      	if (data.at(i).at(j) == 'X'){
        	continue;
        }
    	cout << data.at(i).at(j);
    }
    cout << endl;
  }
  
}




Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    //char s[n];
    vector<char> s(n);  
    for(int i=0;i<n;i++) cin >> s[i];
    
    int count=0;
    for(int i=0;i<n;i++){
        if(s[i]==s[i+1]){
            count+=0;
        } else {
            count++;
        } 
                //if(s[i]!=s[i+1]) break;
        }
   cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const ll maxx=1e18;

ll a[100005];

signed main()
{
	ll n;cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]==0){
			cout<<0<<endl;
			return 0;
		}	
	}
	ll sum=1;bool flag=0;
	for(int k=0;k<n;k++){
		sum*=a[k];
		if(sum>maxx||sum<a[k]){
			flag=1;
			break;
		}
	}
	if(flag)cout<<-1<<endl;
	else cout<<sum<<endl;
	
	return 0;
}

Measured memory_bytes: 4392
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1e5 + 10;
int a[MAXN], val[MAXN], val1[MAXN], ans[MAXN];
int n;
vector <int> vctr;
void find(int now, int cnt) {
    // cout << now << ':' << cnt << ' ';
    int next = lower_bound(vctr.begin(), vctr.end(), now) - vctr.begin() - 1;
    if (next == -1) {
        val1[now] += cnt;
        return;
    }
    val[next] += cnt * (now / vctr[next]);
    find(now % vctr[next], cnt);
}
int32_t main () {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    int q;
    cin >> q;
    for (int i = 1; i <= q; ++i) 
        cin >> a[i];
    a[0] = n;
    for (int i = q; i >= 0; --i)
        if (vctr.empty() || vctr.back() > a[i])
            vctr.push_back(a[i]);
    reverse(vctr.begin(), vctr.end());
    int sz = vctr.size();
    ++val[sz - 1];
    while (!vctr.empty()) {
        auto now = vctr.back();
        vctr.pop_back();
        find(now, val[--sz]);
    }
    for (int i = n; i ; --i)
        ans[i] = ans[i + 1] + val1[i];
    for (int i = 1; i <= n; ++i)    
        cout << ans[i] << '\n';
    return 0;
}

Measured memory_bytes: 5748
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int[] a = new int[n];

		for(int i=0;i<n;i++)a[i]=sc.nextInt();
		long sum=0,min=Long.MAX_VALUE;
		for(int i=1;i<100;i++) {
			for(int j=0;j<n;j++) {
				sum+=Math.pow(a[j]-i, 2);
			}
			min=Math.min(min, sum);
			sum=0;
		}
		System.out.println(min);
	}
}



Measured memory_bytes: 21332
import math
import pprint
import fractions
import collections
import itertools
from decimal import *
A,B=map(str,input().split())
A=int(A)
B=str(B)
num=int(B[0])*100+int(B[2])*10+int(B[3])
#print(A,num)
print((A*num)//100)


Measured memory_bytes: 72576
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] temp = scanner.nextLine().split(" ");
		int n = Integer.parseInt(temp[0]);
		int m = Integer.parseInt(temp[1]);

		String[] numb      = scanner.nextLine().split(" ");
		Queue<Long> que = new PriorityQueue<Long>(Collections.reverseOrder());

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

			Long x = Long.parseLong(numb[i]);
			que.add(x);

		}

		for(int i = 0; i < m; i++) {

			Long min = (long)que.poll() / 2;
			que.add(min);

		}
		long ans = 0;
		for(int i = 0; i < n; i++) {

			ans += que.poll();

		}

		System.out.println(ans);

		}

}

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

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

    while(m--){
        int x;
        cin >> x;
        n -= x;
    }
    if(n < 0){
        cout << "-1" << endl;
    }else{
        cout << n << endl;
    }

}

Measured memory_bytes: 3640
require 'set'

loop do
  n, m, k = gets.split.map(&:to_i)
  break if n == 0
  balls = [Set.new, Set.new]
  pegs = (0..n).map { (0..n).map { 0 } }

  winner = win_at = nil
  k.times do |i|
    x, y = gets.split.map(&:to_i)
    next if winner
    z = (pegs[x][y] += 1)
    balls[i % 2] << [x, y, z]
    [1, 0, -1].repeated_permutation(3) do |diff|
      next if diff == [0, 0, 0]
      dx, dy, dz = diff
      r = 0
      r += 1 while balls[i % 2].include?( [x+(r+1)*dx, y+(r+1)*dy, z+(r+1)*dz] )
      l = 0
      l -= 1 while balls[i % 2].include?( [x+(l-1)*dx, y+(l-1)*dy, z+(l-1)*dz] )
      if r - l + 1 >= m
        winner = i % 2
        win_at = i + 1
        break
      end
    end
  end

  if winner == 0
    puts "Black #{win_at}"
  elsif winner == 1
    puts "White #{win_at}"
  else
    puts 'Draw'
  end
end


Measured memory_bytes: 6992
def get_adjacent(lists, pos, hw):
	h, w = hw
	x, y = pos
	adjacents = []
	for adjust_y, adjust_x in ((0, 1), (1, 0), (0, -1), (-1, 0)):
		if 0 <= y+adjust_y < h and 0 <= x+adjust_x < w:
			adjacents.append(lists[y+adjust_y][x+adjust_x])
	return adjacents

h, w = map(int, input().split(" "))
s = [input() for i in range(h)]

for y in range(h):
	for x in range(w):
		if s[y][x] == "#":
			if "#" not in get_adjacent(s, (x, y), (h, w)):
				print("No")
				exit()
print("Yes")

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

int main(){
    string s,t;
    cin >> s;
    cin >> t;
    int ans=0;
    for(int i=0;i<(int)s.size();i++){
        if(s[i]!=t[i]){ans++;}
    }
    cout << ans <<"\n";
}


Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
char mp[1005][1005];
int dp[1005][1005];
int main()
{
   //freopen("t5.in","r",stdin);
   //freopen("t5.out","w",stdout);
   //ios::sync_with_stdio(false);
   //cin.tie(0); cout.tie(0);
    int i,j,n,m;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
    {
        scanf("%s",mp[i]+1);
    }
    for(i=1;i<=n;i++)
    for(j=1;j<=m;j++)
        dp[i][j]=9999999;
    for(i=1;i<=n;i++)
    for(j=1;j<=m;j++)
    {
        if(i==1&&j==1)
        {
            if(mp[i][j]=='#')
            dp[i][j]=1;
            else dp[i][j]=0;
        }
        else if(i==1)
        {
            dp[i][j]=dp[i][j-1];
            if(mp[i][j]=='#'&&mp[i][j-1]!='#')dp[i][j]++;
        }
        else if(j==1)
        {
            dp[i][j]=dp[i-1][j];
             if(mp[i][j]=='#'&&mp[i-1][j]!='#')dp[i][j]++;
        }
        else
        {

            if(mp[i][j]=='#')
            {
                if(mp[i-1][j]=='#')dp[i][j]=min(dp[i][j],dp[i-1][j]);
                else dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
                if(mp[i][j-1]=='#')dp[i][j]=min(dp[i][j],dp[i][j-1]);
                else dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
            }
            else
             dp[i][j]=min(dp[i-1][j],dp[i][j-1]);
        }
    }
cout<<dp[n][m];
/*
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
            printf("%d  ",dp[i][j]);
        puts("");
    }
*/
    return 0;
}


Measured memory_bytes: 2688
#include<iostream>

using namespace std;


int main()
{
	bool result = true;
	string in;
	cin >> in;
	int i = 0;

	while(i < in.length())
	{
		if(in.substr(i,2) != "hi")
		{
			result = false;
			break;
		}
		i += 2;
	}
	if (result)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 52;
//
//
int n, m, q;
// vector<int> query[MAX];
ll ans;
void check(int idx, int val, vector<int>& temp, vector<vector<int>>& query){
    if(val > m)
        return ;
    if(idx == n+1){
        // return ;
        ll t = 0;
        // for(int i = 1; i <= n; i++)
        //     cout<<temp[i]<<" ";
        // cout<<"\n";
        for(auto itr : query)
            t += ((temp[itr[1]] - temp[itr[0]] == itr[2])? itr[3] : 0);
        ans = max(ans, t);
        // cout<<t<<"\n";
        return ;
    }
    for(int i = val; i <= m; i++){
        temp[idx] = i;
        check(idx+1, i, temp, query);
    }
}
void solve(){
    cin>>n>>m>>q;
    ans = 0;
    vector<vector<int>> query(q, vector<int>(4));
    for(int i = 0; i < q; i++){
        for(int j = 0; j < 4; j++)
            cin>>query[i][j];
    }

    // for(auto itr : query)
    //     cout<<itr[0]<<"\n";
    vector<int> temp(n+10);
    check(1, 1, temp, query);
    cout<<ans;
}
int main(){ 
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}

Measured memory_bytes: 3576
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

#define REP(i, b, e) for(int i = b ; i < e ; i++)
#define rep(i, n) REP(i, 0, n)

struct Dress{
  int A, B, C;
};

const int MAX = 210;

bool canWear(int temp, Dress d){
  return (d.A <= temp && temp <= d.B);
}

int main(){
  int D, N;
  while(cin >> D >> N){
    vector<Dress> dress(MAX);    
    vector<int> temp(MAX);
    rep(i, D) cin >> temp[i];
    rep(i, N) cin >> dress[i].A >> dress[i].B >> dress[i].C;
    
    int dp[MAX][MAX];
    memset(dp, -1, sizeof(dp));
    rep(i, N) if(canWear(temp[0], dress[i])) dp[0][i] = 0;
    
    REP(i, 1, D){
      REP(j, 0, N){
	REP(k, 0, N){
	  if(dp[i-1][j] == -1) continue;
	  if(!canWear(temp[i], dress[k])) continue;
	  dp[i][k] = max(dp[i][k], dp[i-1][j] + abs(dress[j].C - dress[k].C));
	}
      }
    }
    
    int ans = -1;
    rep(i, N) ans = max(ans, dp[D-1][i]);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1376
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>

using namespace std;
const int N = 1e3 + 500;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 57;
const int LN = 22;
const int SN = 320;

long long n, m, u, v, k, t, q, x, d, p, a, b, c, s;

string sa, sb;
int arr[N][N];
int ctr[N];
int res[N];
int main() {
   ios::sync_with_stdio(false);cin.tie(0);
   cin >> n;
   for (int i = 1; i <= n; ++i) {
      ctr[i] = 1;
      for (int j = 1; j <= n - 1; ++j) cin >> arr[i][j];
   }
   
   int ii = 1;
   int tot = 0;
   for (ii = 1; ii <= n * (n - 1) / 2; ++ii) {
      int done = 0;
      
      for (int i = 1; i <= n; ++i) {
         if (ctr[i] == n) continue;
         int j = arr[i][ctr[i]];
         if (arr[j][ctr[j]] == i) {
            res[done++] = i;
         }
      }
      if (done == 0) {
         cout << -1 << endl;
         return 0;
      }
      for (int i = 0; i < done; ++i) ctr[res[i]]++;
      tot += done / 2;
      if (tot == n * (n - 1) / 2) break;
   }
   cout << ii << endl;
}



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

namespace ConsoleApp2
{
    using static System.Console;
    using static System.Math;

    class Program
    {
        static void Main(string[] args)
        {
            A = int.Parse(ReadLine());
            B = int.Parse(ReadLine());
            C = int.Parse(ReadLine());
            D = int.Parse(ReadLine());
            E = int.Parse(ReadLine());
            Solve();
        }

        static int A, B, C, D, E;

        static void Solve()
        {
            var array = new[] { A, B, C, D, E }.OrderBy(x => (x - 1) % 10).ToArray();
            var ans = array.Skip(1).Select(x => x % 10 == 0 ? x : (x / 10) * 10 + 10).Aggregate(array[0], (a, s) => a + s);
            WriteLine(ans);
        }
    }
}


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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int k = s.size();
    int o_cnt = 0;
    REP(i, k)if(s[i] == 'o') o_cnt++;
    if(15 - k + o_cnt >= 8) cout << "YES" << ln;
    else cout << "NO" << ln;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    int a,b;
    int x = 0;
    cin >> k;
    cin >> a >> b;
    for(int i=a; i <= b; i++)
    {
        if(i%k==0)
        {
            x = 1;
            break;
        }
    }
    if(x==1)
        cout << "OK" << endl;
    else
        cout << "NG" << endl;
    return 0;
}

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void puts_all(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;

const f80 eps = 1e-12;

int main(){
  f80 a,b,c;

  while(cin >> a >> b >> c){
    puts_all((f80)(a + b - c) + std::sqrt(a*b) * 2.0 < -eps ? "Yes" : "No");
  }


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;
void solve(){
  int n; cin >> n;
  map<int, int> mp;
  if(n % 2 == 1) mp[0]++;
  for(int i = 0; i < n; i++){
    int a; cin >> a;
    mp[a / 2]++;
  }
  for(int i = 0; i < (n - 1) / 2; i++){
    if(mp[i] != 2){
      cout << 0 << endl;
      return;
    }
  }
  long long ans = 1;
  for(int i = 0; i < (n - 1) / 2; i++){
    ans *= 2;
    ans %= 1000000007;
  }
  if(n % 2 == 0) ans *= 2;
  cout << ans % 1000000007 << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define REP(i, t) for(int i = 0; i < t; i++)

int main()
{
    int N, K;
    cin >> N >> K;
    bool b = 0;
    int ans = K;
    REP(i, N - 1) ans *= (K - 1);
    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin >> N;
	vector<int>A(N);
	for (int i = 0; i < N; i++){
		cin >> A[i];
		if (A[i] % 2 == 0 && A[i] % 3 != 0 && A[i] % 5 != 0) {
			cout << "DENIED" << endl;
			return 0;
		}
	}
	cout << "APPROVED" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
const ll INF = 1001001001;
int main() {
  int n,m,l;
  cin >> n >> m >> l;
  vector<vector<ll>> dist(n,vector<ll>(n,INF));
  rep(i,n) dist.at(i).at(i) = 0;
  rep(i,m){
    int a,b,c;
    cin >> a >> b >> c;
    --a;--b;
    dist.at(a).at(b)=dist.at(b).at(a)=c;
  }
  rep(k,n)rep(i,n)rep(j,n) dist.at(i).at(j) = min(dist.at(i).at(j),dist.at(i).at(k)+dist.at(k).at(j));
  vector<vector<ll>> dist2(n,vector<ll>(n,INF));
  rep(i,n)rep(j,n){
    if(dist.at(i).at(j) <= l) dist2.at(i).at(j) = 1;
  }
  rep(k,n)rep(i,n)rep(j,n) dist2.at(i).at(j) = min(dist2.at(i).at(j),dist2.at(i).at(k)+dist2.at(k).at(j));
  int q;
  cin >> q;
  rep(i,q){
    int s,t;
    cin >> s >> t;
    --s;--t;
    ll ans = dist2.at(s).at(t)-1;
    if(dist2.at(s).at(t)==INF)cout << -1 <<endl;
    else cout << ans <<endl;
  }
}

    
  
  
  
  

Measured memory_bytes: 1920
#include<stdio.h>
#include<string.h>

#define ll long long

ll min(ll x, ll y){
  if (x>y){
    return y;
  }else{
    return x;
  }
}

ll max(ll x, ll y){
  if (x<y){
    return y;
  }else{
    return x;
  }
}



int main(void){
  ll H,W;

  scanf("%d%d",&H,&W);

  if(H%3==0 || W%3==0){
    printf("0\n");
    return 0;
  }

  ll ans;
  ans = min(H,W);

  ll s1,s2,s3;
  ll mx,mn;
  for(ll r = 1; r < W; r++){
    s1 =   r   *   H    ;
    s2 = (W-r) * (H/2)  ;
    s3 = (W-r) * (H-H/2);

    mx = max(max(s1,s2),s3);
    mn = min(min(s1,s2),s3);

    ans = min(ans,mx-mn);
  }

  int tmp;
  tmp = H; H = W; W = tmp;
  for(ll r = 1; r < W; r++){
    s1 =   r   *   H    ;
    s2 = (W-r) * (H/2)  ;
    s3 = (W-r) * (H-H/2);

    mx = max(max(s1,s2),s3);
    mn = min(min(s1,s2),s3);

    ans = min(ans,mx-mn);
  }

  printf("%lld\n",ans);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;
const string YES = "Yes";
const string NO = "No";

string S;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> S;
    solve();
}

// S は A または B から成る
// |S| = 3

// string S
// バスが運行することになる駅の組み合わせが存在する場合は Yes を、存在しない場合は No を出力せよ。
void solve(){
    cout<<(S[0]==S[1]&&S[1]==S[2]?NO:YES)<<endl;
}


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

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file
#else

#endif



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Togliere nei problemi con query online

    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int res = 0;
    res += min(A, K);
    K -= min(A, K);
    K -= min(B, K);
    res -= K;
    cout << res << "\n";
}


Measured memory_bytes: 3588
#include<stdio.h>
#define INF 10000000
int main()
{
  int n,i,j,l,k,q;
  scanf("%d",&n);
  int p[n+3];
  int alt[n+1];
  int m[n+3][n+3];
  for(i=0;i<n;i++){
    if(i==n-1)scanf("%d%d",&p[i],&p[i+1]);
    else scanf("%d%d",&p[i],&alt[i]);
  }
  for(i=1;i<=n;i++){
    m[i][i]=0;
  }
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=INF;
      for(k=i;k<j;k++){
        q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
        if(m[i][j]>q){
          m[i][j]=q;
        }
      }
    }
  }
  printf("%d\n",m[1][n]);
  return 0;
}


Measured memory_bytes: 2104
#include <stdio.h>
int main()
{
    int a, b, c, x;
    int ans = 0;
    scanf("%d%d%d%d", &a, &b, &c, &x);
    for (int i = 0; i <= a && i * 500 <= x; i++)
    {
        for (int j = 0; j <= b && i * 500 + j * 100 <= x; j++)
        {
            for (int k = 0; k <= c && i * 500 + j * 100 + k * 50 <= x; k++)
            {
                if (i * 500 + j * 100 + k * 50 == x)
                {
                    ans++;
                }
            }
        }
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    int A = 0, B = 0, C = 0;
    for (int i = 0; i < N; i++) {
        int a, b, c; cin >> a >> b >> c;
        tie(A, B, C) = make_tuple(a + max(B, C), b + max(C, A), c + max(A, B));
    }
    cout << max({A, B, C}) << endl;
}

Measured memory_bytes: 256
#[allow(unused_macros, dead_code)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
#[allow(unused_macros, dead_code)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
#[allow(unused_macros, dead_code)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        S: String,
    }

    let s: Vec<char> = S.chars().collect();
    let mut next0 = vec![-1; n + 1];

    next0[0] = 0;
    let mut prev = 0;
    for i in 1..(n + 1) {
        if s[i] == '0' {
            for j in (prev + 1)..(i + 1) {
                next0[j] = i as i64;
            }
            prev = i;
        }
    }

    let mut ans = vec![];
    let mut cur: i64 = n as i64;
    while true {
        if cur <= m as i64 {
            ans.push(cur);
            break;
        }
        let nxt = next0[cur as usize - m];
        if cur == nxt {
            println!("-1");
            return;
        }
        ans.push(cur - nxt);
        cur = nxt;
    }

    ans.reverse();
    for a in ans {
        print!("{} ", a);
    }
}


Measured memory_bytes: 6524
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <typename T>
// using o_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #define sfind(i) find_by_order(i)
// #define ord(i) order_of_key(i)
typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
using cd = complex<double>;
const double pi = acos(-1);
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
#define vi vector<int>
#define vl vector<ll>
#define _max(vec) (*max_element(all(vec)))
#define _min(vec) (*min_element(all(vec)))
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define ral(name) name.rbegin(), name.rend()
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):0LL)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define endl '\n'  //....????
#define int ll
vector<ll> ft(1, 1LL);


/*======================================================================*/
void solve(){
    int a,b, c, k;
    cin >> a >> b >> c >> k;
    while(k--){
        if(a < b and  b < c){cout << "Yes\n";return;}
        else if(c <= b)c *= 2;
        else if(b <= a)b *= 2;
    }
    if(a < b and b < c)cout << "Yes\n";
    else cout << "No\n";
}
signed main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 3688
#include <cstdio>

const int MAXN = 6005;

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

int f[MAXN][MAXN << 1];
int N, M;

void add( int &x, const int v ) { x += v; if( x >= M ) x -= M; }

int main()
{
	read( N ), read( M );
	int t = N * 3;
	f[0][t] = 1;
	for( int i = 1 ; i <= t ; i ++ )
		for( int j = - t ; j <= t ; j ++ )
		{
			if( j > -t ) add( f[i][j + t], f[i - 1][j + t - 1] ); //长度为1
			if( j < t && i >= 2 ) add( f[i][j + t], 1ll * f[i - 2][j + t + 1] * ( i - 1 ) % M ); //长度为2
			if( i >= 3 ) add( f[i][j + t], 1ll * f[i - 3][j + t] * ( i - 1 ) % M * ( i - 2 ) % M ); //长度为3 
		}
	int ans = 0;
	for( int i = 0 ; i <= t ; i ++ ) add( ans, f[t][i + t] );
	write( ans ), putchar( '\n' );
	return 0;
}

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

int main()
{
    string s;
    cin >> s;
    int a = 0,b = s.size();

    while(s[a] != 'A'){
        a++;
    }
    while(s[b] != 'Z'){
        b--;
    }
    cout << b - a + 1 << endl;
}

Measured memory_bytes: 640
#include <stdio.h>

int main()
{
    int n,k,i,j,temp,snack;
    scanf("%d %d",&n,&k);
    int snukes[n];
    for(i=0;i<n;i++)
        snukes[i]=1;

    for(i=0;i<k;i++)
    {
        scanf("%d",&temp);
        for(j=0;j<temp;j++)
        {
            scanf("%d",&snack);
            snukes[snack-1]=0;
        }
    }
    snack=0;
    for(i=0;i<n;i++)
    {
        if(snukes[i])
            snack++;
    }

    printf("%d",snack);

    return 0;
}


Measured memory_bytes: 1700
import math
A, B = map(int, input().split())

A_orgn = A
B_orgn = B
# A = n1 * n2 * n3   , B = n1 * n2 * n5とする
# 答えが n1 * n2 * n3 * n5 

dict_a = {}
dict_b = {}
if A == 1:
    dict_a[1] = 1
  
for i in range(2,int(math.sqrt(A))+1):
    if A % i == 0:
        while(1):
            A //= i
            if i not in dict_a:
                dict_a[i] = 1
            else:
                dict_a[i] += 1
            if A % i != 0:
                break
if A != 1:
    dict_a[A] = 1

if B == 1:
    dict_b[1] = 1
for i in range(2,int(math.sqrt(B))+1):
    if B % i == 0:
        while(1):
            B //= i
            if i not in dict_b:
                dict_b[i] = 1
            else:
                dict_b[i] += 1
            if B % i != 0:
                break
if B != 1:
    dict_b[B] = 1
#print(dict_a)
#print(dict_b)

sum = 1
for i in range(max(A_orgn, B_orgn)+1):
    #print(i)
    if (i not in  dict_a) and ( i in dict_b):
        
        sum *= i ** dict_b[i] 
        #print("====",i, "====",sum)
    elif (i in dict_a) and ( i not in dict_b):
        
        sum *= i ** dict_a[i]
        #print("||||",i, "||||", sum)
    elif (i in dict_a) and ( i in dict_b):
        
        sum *= i ** max(dict_a[i], dict_b[i])
        #print("????",i,"????", sum)
print(sum)    

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

#define INF 2000000000

int dp[20010][260];
int c[20],x[20010];

int main(){

    int n,m;

    while(true){
        cin >> n >> m;
        if(n + m == 0)break;
        for(int i = 0;i < m;i++)cin >> c[i];
        for(int i = 0;i < n;i++)cin >> x[i];
        for(int i = 0;i < n+1;i++){
            for(int j = 0;j < 257;j++){
                dp[i][j] = INF;
            }
        }       
        dp[0][128] = 0;

        for(int i = 0;i < n;i++){
            for(int j = 0;j <= 255;j++){
                for(int k = 0;k < m;k++){
                    int ne = j + c[k];
                    ne = max(ne,0);
                    ne = min(255,ne);
                    dp[i+1][ne] = min(dp[i+1][ne], dp[i][j] + (x[i]-ne)*(x[i]-ne) );
                //    if(dp[i+1][ne] != INF)printf("dp[%d][%d] = %d\n",i+1,ne,dp[i+1][ne]);
                    
                }
            }
        }
        int ans = INF;
        for(int i = 0;i <= 255;i++) ans = min(ans,dp[n][i]);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 23452
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
const ll MAXN = 1001;
ll sum[MAXN],a[MAXN];
ll n,A,B;
ll dp[MAXN][MAXN];
map<ll,ll>ma;
void C(){
	dp[1][1] = 1;
	for(ll i = 0;i <= 151;i ++) dp[i][0] = 1;
	for(ll i = 2;i <= 151;i ++)
		for(ll j = 1;j <= 151;j ++)
			dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1]; 
}

bool cmp(ll a,ll b){
	return a > b;
}

void solve(){
	C();
	cin >> n >> A >> B;
	for(ll i = 1;i <= n;i ++)
		scanf("%lld",&a[i]),ma[a[i]] ++;
	sort(a + 1,a + n + 1,cmp);
	ll sum = 0;
	double pingjun = 0.0;
	for(ll i = 1;i <= A;i ++) sum += a[i];
	pingjun = (double)sum / (double)A;
	ll pos = 0;
	for(ll i = A;i >= 1;i --){
		if(a[i] != a[i - 1]){
			pos = i;
			break;
		}
	}
	ll ans = 0;
	if(pos == 1)
		for(int i = A;i <= B;i ++) ans += dp[ma[a[A]]][i];
	else ans = dp[ma[a[A]]][A - pos + 1];
	printf("%.8lf\n",pingjun);
	printf("%lld\n",ans);
	return;
}
int main(){
	solve();
	return 0;
}

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

int m(int x) { return x; }
template <typename... Ts>
int m(int x, Ts... xs) {
  return min(x, m(xs...));
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << m(a + b, b + c, c + a);
  return 0;
}

Measured memory_bytes: 3620
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val xy = (0 until n).map { sc.next().toDouble() to sc.next().toDouble() }
    println(problem145c(n, xy))
}

fun problem145c(n: Int, xy: List<Pair<Double, Double>>): Double {
    /**
     * 辞書順で順列の次の組み合わせにarrayを書き換える
     */
    fun nextPermutation(array: IntArray): Boolean {
        var i = array.size - 1
        while (i > 0 && array[i - 1] >= array[i]) i--
        // Now i is the head index of the suffix
        // Are we at the last permutation already?
        if (i <= 0) return false
        // Let array[i - 1] be the pivot
        // Find rightmost element that exceeds the pivot
        var j = array.size - 1
        while (array[j] <= array[i - 1]) j--
        // Now the value array[j] will become the new pivot
        // Assertion: j >= i
        // Swap the pivot with j
        var temp = array[i - 1]
        array[i - 1] = array[j]
        array[j] = temp
        // Reverse the suffix
        j = array.size - 1
        while (i < j) {
            temp = array[i]
            array[i] = array[j]
            array[j] = temp
            i++
            j--
        }
        // Successfully computed the next permutation
        return true
    }

    val intArray = (0 until n).toList().toIntArray()
    val sum = mutableListOf<Double>()
    var last = true
    while (last) {
        val list = DoubleArray(n) { 0.0 }
        for (i in 1 until n) {
            list[intArray[i - 1]] = Math.sqrt(
                (Math.pow(Math.abs(xy[intArray[i - 1]].first - xy[intArray[i]].first), 2.0)) +
                (Math.pow(Math.abs(xy[intArray[i - 1]].second - xy[intArray[i]].second), 2.0))
            )
        }
        sum.add(list.sum())
        last = nextPermutation(intArray)
    }
    return sum.average()
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

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

  s += "@";

  ll ans = 0;

  ll start = -1;
  for (ll i = 0; i < s.size(); i++) {
    char c = s[i];
    if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
      if (start == -1) {
        start = i;
      }
    } else {
      if (start >= 0) {
        ans = max(ans, i - start);
        start = -1;
      }
    }
  }

  cout << ans << endl;
}


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

int main(){
    int N;
    string S;
    cin >> N >> S;
    bool judL, judR = false;
    int cnt =0;
    int ans =0;

    for(int i=1; i<=N-1; i++){
        cnt =0;

        for(char c = 'a'; c <= 'z'; c++){
            judL =false; judR =false;

            for(int j=0; j<=i; j++){
                if(S[j] == c){
                    judL = true;
                }
            }

            for(int k=i+1; k<=N; k++){
                if(S[k] == c){
                    judR = true;
                }
            }

            if(judL && judR){
                cnt++;
            }

        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256