akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,p,a[120000];
int main(){
	cin>>n>>m>>p;
	for(int i=0;i<m;i++){
		cin>>a[i];
		a[i]-=p;a[i]+=n;
		a[i]%=n;
	}
	sort(a,a+m);
	int ret=0;
	ret=min(a[m-1],n-a[0]);
	for(int i=0;i<m-1;i++){
		int V=a[i],W=n-a[i+1];
		if(V>W)swap(V,W);
		int X=2*V+W;
		ret=min(ret,X);
	}
	cout<<ret*100<<endl;
	return 0;
}

Measured memory_bytes: 1220
a = int(input())
b = int(input())
c = int(input())
total = int(input())
count = 0

for p in range(a+1):
    for q in range(b+1):
        for r in range (c+1):
            if (500*p) + (100*q) + (50*r) == total:
                count = count + 1;


print(count);

Measured memory_bytes: 3060
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
    String s = scan.next();
    char s1 = s.charAt(0);
    char s2 = s.charAt(1);
    char s3 = s.charAt(2);
    if(s1 != s2){
      if(s1 != s3 && s2 != s3){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAX=1e3+5;
char a[MAX][MAX];
LL DP[MAX][MAX];
LL mod = 1e9+7;

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>a[i][j];
            
        }
    }
    if(a[1][1] == '#')
    {
        cout << 0 <<endl;
        exit(0);
    }
    DP[1][1] = 1;
    for(int i=2;i<=m;i++)
    {
        if(a[1][i] == '#')
        {
            DP[1][i] = 0;
            continue;
        }
        DP[1][i] = (DP[1][i-1]%mod + DP[0][i]%mod)%mod;
    }
    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i][j] == '#')
                DP[i][j] = 0;
            else 
                DP[i][j] = (DP[i][j-1]%mod + DP[i-1][j]%mod)%mod;
        }
    }
    cout << DP[n][m] << endl;
    return 0;
}

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


def main():
    N, M = map(int, input().split())
    mod = (10**9)+7
    if abs(N-M) >= 2:
        print(0)
    else:
        ans = 1
        for n in range(1, N+1):
            ans = ans * n % mod
        for m in range(1, M+1):
            ans = ans * m % mod
        if N == M:
            ans = ans * 2 % mod
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38768
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <cctype>
#include <cstdlib>
#include <set>
#include <map>
#include <sstream>
using namespace  std;
#define  ll long long
#define mINF(a) memset(a,INF,sizeof(a))
#define m0(a) memset(a,0,sizeof(a))
#define mf1(a) memset(a,-1,sizeof(a))
#define lson i<<1,l,l+r>>1
#define rson i<<1|1,((l+r)>>1)+1,r
typedef pair<ll,ll>P;
static const ll INF=1e18;
static const ll len=1e5+7;
ll ans[len];
int main()
{
	ll x,y,t;
	while(cin>>x>>y) 
	{
		if(x==y)puts("-1");
		else
		{
			ll sum=0,w=0;
			for(ll i=2*x;i<=INF;i+=x)
			{
				sum++;
				if(i%y!=0)
				{
					w=1;
					t=i;
					break;
				}
				if(sum>=y)
					break;
			}
			if(!w)puts("-1");
			else printf("%lld\n",t);
		}
	}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
struct dic{
	string str;
	int n;
};

int main(){
	string a,stmp;
	int b,d = 0,i,j,itmp;
	dic c[101];
	while(cin >> a >> b){
		c[d].str = a;
		c[d].n = b;
		++d;
	}
	for(i = 0;i < d;i++){
		for(j = d - 1;j > i;j--){
			if(c[i].str > c[j].str){
				stmp = c[j].str;
				c[j].str = c[i].str;
				c[i].str = stmp;
				itmp = c[j].n;
				c[j].n = c[i].n;
				c[i].n = itmp;
			}
			else if(c[i].str == c[j].str){
				if(c[i].n > c[j].n){
					itmp = c[j].n;
					c[j].n = c[i].n;
					c[i].n = itmp;
				}
			}
		}
	}
	for(i = 0;i < d;i++){
		cout << c[i].str << endl;
		cout << c[i].n;
		while(c[i].str == c[i+1].str){
			++i;
			cout << " " << c[i].n;
		}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <queue>
#include <vector>
#include <cstring>
using namespace std;
typedef pair<int, int> pii;

struct Info {
    int y, x, d;
    Info(int yy, int xx, int dd) : y(yy), x(xx), d(dd) {}
};

int yy, xx, sy, sx, ey, ex, d[1010][1010], dy[] = {-1, 1, 0, 0}, dx[] = {0, 0, -1, 1};
char s[1010][1010];

struct comp {
    bool operator()(Info a, Info b) {
        return a.d > b.d;
    }
};

priority_queue<Info, vector<Info>, comp> pq;

bool check(int y, int x) {
    return 1 <= y && y <= yy && 1 <= x && x <= xx;
}

int main() {
    memset(d, 0xff, sizeof(d));
    scanf("%d%d%d%d%d%d", &yy, &xx, &sy, &sx, &ey, &ex);
    for (int i = 1 ; i <= yy ; i++) {
        scanf("%s", &s[i][1]);
    }
    d[sy][sx] = 0;
    pq.push(Info(sy, sx, 0));
    while (!pq.empty()) {
        int cy = pq.top().y, cx = pq.top().x, cur = pq.top().d, ny, nx, nd;
        pq.pop();
        for (int i = 0 ; i < 4 ; i++) {
            ny = cy + dy[i], nx = cx + dx[i], nd = cur;
            if (!check(ny, nx) || s[ny][nx] != '.') continue;
            if (d[ny][nx] == -1 || nd < d[ny][nx]) {
                d[ny][nx] = nd;
                pq.push(Info(ny, nx, nd));
            }
        }
        nd = cur + 1;
        for (ny = cy - 2 ; ny <= cy + 2 ; ny++) {
            for (nx = cx - 2 ; nx <= cx + 2 ; nx++) {
                if (!check(ny, nx) || s[ny][nx] != '.') continue;
                if (d[ny][nx] == -1 || nd < d[ny][nx]) {
                    d[ny][nx] = nd;
                    pq.push(Info(ny, nx, nd));
                }
            }
        }
    }
    printf("%d", d[ey][ex]);
}


Measured memory_bytes: 8304
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> accum(n+1, 0);
    rep(i, n) {
        cin >> a[i];
        accum[i+1] = accum[i] + a[i];
    }
    ll ans = 1e18;
    for (int i = 1; i <= n; ++i) {
        ll tmp_num1 = accum[n] - accum[i];
        ll tmp_num2 = accum[i];
        ans = min(ans, abs(tmp_num1 - tmp_num2));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6412
function main(input) {
  input = input.trim();
  const [a,b] = input.split(" ").map(Number);

  if(a+b>=24){
    console.log((a+b)-24);
  }else{
    console.log(a+b);
  }
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 30600
#include <bits/stdc++.h>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
using ll = long long;
using namespace std;
// O(log N)　keyのある場所を返す。なかったら-1を返す
int search(int key, vector<int> a){
  int right = a.size();
  int left = 0;
  while(right >= left){
    int middle = left + (right - left) / 2;
    if(a[middle] == key) return middle; //keyが入ってる場所を返す
    else if(a[middle] > key) right = middle - 1;
    else if(a[middle] < key) left = middle + 1;
  }
  //なければ-1を返す
  return -1;
}
// O(N^2) babble sort
int main(){
  int n,z,w;
  cin >> n >> z >> w;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  if(n >= 2){
    cout << max(abs(a[n - 1] - a[n - 2]), abs(a[n - 1] - w));
  }else{
    cout << abs(a[0] - w) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}




int main() {
	int n, w;
	cin >> n >> w;
	vector<ll> v(n);
	vector<ll> c(n);
	rep(i,n){
		cin >> c[i] >> v[i];
	}
	vector<vector<ll>> dp(n + 1, vector<ll>(w+1, 0));
	rep(i,n){
		rep(j,w+1){
			if(j - c[i] >= 0)
				dp[i + 1][j] = max(dp[i][j], dp[i][j - c[i]] + v[i]);
			else
				dp[i + 1][j] = dp[i][j];
		}
	}
	cout << dp[n][w] << endl;

	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n;
int a[200000];

int main() {
    scanf("%d", &n);
    forn(i, n) {
        scanf("%d", a + i);
    }
    if (a[0] != 0) {
        cout << -1 << endl;
        return 0;
    }
    LL ans = 0;
    for (int i = 1; i < n; ++i) {
        if (a[i] > a[i - 1] + 1) {
            cout << -1 << endl;
            return 0;
        }
        if (a[i] == a[i - 1] + 1) {
            ans += 1;
        } else {
            ans += a[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
package main

import (
  "fmt"
)

func main() {
  var n,m int

  fmt.Scan(&n)
  fmt.Scan(&m)

  fmt.Println(combination(n,2)+combination(m,2))
}

func permutation(n int, k int) int {
    v := 1
    if 0 < k && k <= n {
        for i := 0; i < k; i++ {
            v *= (n - i)
        }
    } else if k > n {
        v = 0
    }
    return v
}

func factorial(n int) int {
    return permutation(n, n - 1)
}

func combination(n int, k int) int {
    return permutation(n, k) / factorial(k)
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll MOD = 1000000007;
ll INF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------

//-----------------------------------------

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string s;
  cin >> s;
  ll cnt = 0;
  ll m = s.size();
  REP(i,m) cnt += s[i] - '0';

  if(cnt % 9 == 0) yes();
  else no();
    
    
  return 0;
}



Measured memory_bytes: 3780
n,m=map(int,input().split())
A=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append([a,b])
A.sort()
katta=0
okane=0
while katta<m:
    
    if A[0][1]+katta<m:
        okane+=A[0][0]*A[0][1]
        katta+=A[0][1]
        A.pop(0)
    else:
        okane+=(m-katta)*A[0][0]
        break
print(okane)
        


Measured memory_bytes: 20064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n,k;
  cin >> n >> k;
  int a[n];
  rep(i,n)cin >> a[i];
  int l=0,r=INF;
  auto check = [&](int x){
    int res=0;
    rep(i,n){
      res += (a[i]+x-1)/x-1;
    }
    return res<=k;
  };
  while(r-l>1){
    int mid=(l+r)/2;
    if(check(mid))r=mid;
    else l=mid;
  }
  cout << r << endl;
}

Measured memory_bytes: 4368
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC061A
{
	class Program
	{
		static void Main(string[] args)
		{
			int A, B, C;
			var word = Console.ReadLine().Split(' ');
			A = int.Parse(word[0]);
			B = int.Parse(word[1]);
			C = int.Parse(word[2]);
			if (A <= C && C <= B)
			{
				Console.WriteLine("Yes");
			}
			else Console.WriteLine("No");
			{
				Console.ReadKey();
			}

		}
	}
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

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

  if(m == 1) {
    cout << 0 << endl;
  }
  else {
    cout << n - m << endl;
  }

  return 0;
}


Measured memory_bytes: 256
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define MOD 1000000007
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

int n, ans;
int arr[100005];
bool visited[100005];

int main(){
    ios::sync_with_stdio(0);
    cin >> n;
    forn(i,n) cin >> arr[i], arr[i]--;
    clean(visited,0);

    int actual = 0;
    ans = 0;
    while(!visited[actual]){
        if(actual == 1){
            break;
        }
        ans++;
        visited[actual] = 1;
        actual = arr[actual];
    }

    if(actual == 1){
        cout << ans << "\n"; 
    }else{
        cout << "-1\n";
    }
    return 0;
}

Measured memory_bytes: 768
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>

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

typedef struct{
	int wrong[11];
	int correct;
	int p_time;
	int num;
}Team;

int T, P, R;

bool judge(const Team rL, const Team rR){
	bool temp;
	if (temp = rL.correct > rR.correct)
		return(temp);
	else if (temp = rL.correct == rR.correct){
		if (temp = rL.p_time < rR.p_time)
			return(temp);
		else if (temp = (rL.p_time == rR.p_time&&rL.num < rR.num))
			return(temp);
	}
		return(temp);
}

void sswap(Team *a, Team *b){
	Team temp = *a;
	*a = *b;
	*b = temp;
}
void solve(Team team[]){
	rep(i, 0, T - 1)
	for (int j = T - 1; j > i; j--)
	{
		if (team[j].correct > team[j - 1].correct)
			sswap(team + j, team + j - 1);
		else if (team[j].correct == team[j - 1].correct){
			if (team[j].p_time < team[j - 1].p_time)
				sswap(team + j, team + j - 1);
			else if (team[j].p_time == team[j - 1].p_time&&team[j].num < team[j - 1].num)
				sswap(team + j, team + j - 1);
		}



	}
}

int main(){

	cin >> T >> P >> R;
	while (T != 0){
		Team team[51] = { { 0 }, 0, 0 };
		rep(i, 0, T)team[i].num = i + 1;
		rep(i, 0, R){
			int t, p, time;
			char str[20];
			cin >> t >> p >> time >> str;
			t--;
			if (strcmp(str, "WRONG")){
				team[t].correct++;
				team[t].p_time += time + team[t].wrong[p] * 1200;
			}
			else{
				team[t].wrong[p]++;
			}

		}
		//solve(team);
		sort(team, team + T, judge);
		rep(i, 0, T){
			cout << team[i].num << " " << team[i].correct << " " << team[i].p_time << endl;
		}
		cin >> T >> P >> R;
	}
	return(0);
}

Measured memory_bytes: 1196
import java.util.Scanner;

class Main {
    private static char[] expr;
    private static int ptr;

    private static void consume(char c) {
        assert expr[ptr] == c : "expected " + c + ", but got " + expr[ptr];
        ptr++;
    }

    private static boolean expression() {
        do {
            consume('(');
            if (clause()) {
                consume(')');
                return true;
            } else {
                consume(')');
            }
        } while (ptr < expr.length && expr[ptr++] == '|');
        assert ptr == expr.length;
        return false;
    }

    private static boolean clause() {
        int[] assigments = new int['z' + 1];
        boolean result = true;
        do {
            if (!literal(assigments)) {
                result = false;
            }
        } while (expr[ptr++] == '&');
        ptr--;
        return result;
    }

    private static boolean literal(int[] assigments) {
        int x;
        if (expr[ptr] == '~') {
            ptr++;
            x = 1;
        } else {
            x = -1;
        }
        if (assigments[expr[ptr]] == x) {
            ptr++;
            return false;
        } else {
            assigments[expr[ptr]] = -1 * x;
            ptr++;
            return true;
        }
    }

    private static void solve() {
        final Scanner scanner = new Scanner(System.in);

        while (true) {
            String input = scanner.next();
            if (input.equals("#")) {
                break;
            }
            Main.ptr = 0;
            Main.expr = input.toCharArray();
            System.out.println(expression() ? "yes" : "no");
        }
    }

    public static void main(String... args) {
        solve();
    }
}

Measured memory_bytes: 12000
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		ArrayList<PriorityQueue<Integer>> pque = new ArrayList<PriorityQueue<Integer>>();

		int n = in.nextInt(), loop = in.nextInt();
		for(int i = 0; i < n ; i++) {
			PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
			pque.add(pq);
		}

		for(int i = 0; i < loop; i++) {
			int odr = Integer.parseInt(in.next()), index = Integer.parseInt(in.next());

			switch(odr) {
				case 0:
					pque.get(index).add(Integer.parseInt(in.next()));
					break;

				case 1:
					if(!pque.get(index).isEmpty()) {
						out.println(pque.get(index).peek());
					}
					break;

				case 2:
					if(!pque.get(index).isEmpty()) {
						pque.get(index).poll();
					}
					break;
			}
		}
		out.flush();
		in.close();

	}

}





Measured memory_bytes: 114456
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int gcd(int a, int b){ //最大公約数
  if(!a) return b;
  if(!b) return a;
  if(a % b == 0) return b;
  return gcd(b, a % b);
}
int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  vi left(n), right(n);
  for(int i = 1; i < n; i++) left[i] = gcd(left[i - 1], a[i - 1]);
  for(int i = n - 2; i >= 0; i--)right[i] = gcd(right[i + 1], a[i + 1]);
  int ans = 0;
  rep(i, n) ans = max(ans, gcd(left[i], right[i]));
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

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

  int f[110][10];
  int p[110][11];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> f[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
  }

  int ans = -(1 << 30);
  for (int i = 1; i < 1 << 10; i++) {
    int sub = 0;
    for (int j = 0; j < n; j++) {
      int cnt = 0;
      for (int k = 0; k < 10; k++) {
        cnt += i >> k & 1 && f[j][k];
      }
      sub += p[j][cnt];
    }
    ans = max(ans, sub);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		// 計算
		String result = "Balanced";
		if(a+b > c+d) result = "Left";
		if(a+b < c+d) result = "Right";
		
		
		// 出力
		System.out.println(result);
	}
	
}

Measured memory_bytes: 22732
#include<bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define per(i,n) for(int i=n-1;i>=0;++i)
#define rep1(i,n) for(int i=1; i<=n; ++i)
#define per1(i,n) for(int i=n; i>=1; ++i)
#define debug cout << "line : " << __LINE__ << " debug" << endl
#define Dcout(N) cout << setprecision(20) << N << endl
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF 1e8
#define MOD 1000000007
typedef long long ll;

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

      ll a,b,n; cin >> a >> b >> n;

      if(b==1){
          cout << 0 << endl;
          return 0;
      }

      if(n<b){
          cout << a*n/b << endl;
      }else{
          ll x = b-1;
          cout << a*x/b << endl;
      }


      return 0;
}


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

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define mod 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define COUT(v) cout << v << endl;

int main() {
  int N;

  cin >> N;

  int high = 0;
  int total = 0;
  int p;
  for (int i = 0; i < N; i++) {
    cin >> p;
    high = max(p, high);
    total += p;
  }

  total -= high;
  total += high / 2;

  COUT(total);

  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

sat = 0

for i in range(n):
  sat += b[a[i]-1]
  
  if i > 0 and a[i-1] == a[i]-1:
    sat += c[a[i]-2]

print(sat)

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


void solve () {
    int x, y, tx, ty;
    cin >> x >> y >> tx >> ty;
    for (int i = 0; i < abs(x - tx); i++) {
        cout << "R";
    }
    for (int i = 0; i < abs(y - ty); i++) {
        cout << "U";
    }
    for (int i = 0; i < abs(x - tx); i++) {
        cout << "L";
    }
    for (int i = 0; i < abs(y - ty) + 1; i++) {
        cout << "D";
    }
    for (int i = 0; i < abs(x - tx) + 1; i++) {
        cout << "R";
    }
    for (int i = 0; i < abs(y - ty) + 1; i++) {
        cout << "U";
    }
    cout << "L";
    cout << "U";
    for (int i = 0; i < abs(x - tx) + 1; i++) {
        cout << "L";
    }
    for (int i = 0; i < abs(y - ty) + 1; i++) {
        cout << "D";
    }
    cout << "R";

}

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


Measured memory_bytes: 3596
from collections import deque

while True:
    w, h = map(int, input().split())
    if w == 0 and h == 0:
        break
    else:
        m = []
        d = deque()
        for i in range(h):
            r = input()
            m.append(list(r))
            s = r.find('@')
            if s != -1:
                d.append((s, i))
        while len(d):
            rw, rh = d.popleft()
            m[rh][rw] = 'Y'
            if 0 < rw and m[rh][rw-1] == '.':
                d.append((rw-1, rh))
                m[rh][rw-1] = 'Y'
            if rw < w-1 and m[rh][rw+1] == '.':
                d.append((rw+1, rh))
                m[rh][rw+1] = 'Y'
            if 0 < rh and m[rh-1][rw] == '.':
                d.append((rw, rh-1))
                m[rh-1][rw] = 'Y'
            if rh < h-1 and m[rh+1][rw] == '.':
                d.append((rw, rh+1))
                m[rh+1][rw] = 'Y'
        a = 0
        for i in m:
            a += i.count('Y')
        print(a)


Measured memory_bytes: 6008
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF MOD
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int h, w, k;

int cnt(vector<string> s, bool retu, int n) {
    int ret = 0;
    if (retu) {
        rep(i,h) {
            if (s[i][n] == '#') ret++;
        }
    }
    else {
        rep(i,w) {
            if (s[n][i] == '#') ret++;
        }
    }
    return ret;
}


int main() {
    cin >> h >> w >> k;
    Int ans = 0;
    vector<string> c(h);
    rep(i,h) cin >> c[i];
    for (int p = 0; p < (1<<h); p++) {
        for (int q = 0; q < (1<<w); q++) {
            int black = 0;
            vector<string> cop = c;
            rep(i,h) {
                rep(j,w) {
                    if (q & (1<<j) || p & (1<<i)) continue;
                    if (c[i][j] == '#') black++;
                }
            }
            if (black == k) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
using namespace std;          
int main(){
  int a[4],b[4],i,n;

  while(cin >> a[0] >> a[1] >> a[2] >> a[3], !cin.eof()){
    cin >> b[0] >> b[1] >> b[2] >> b[3];
    int hit = 0, num =0,blow = 0;

    for(i=0; i<4; i++){
      if(a[i] == b[i]){
	hit++;
      }
    }
    for(i=0; i<4; i++){
      for(n=0; n<4; n++){
	if(a[i] == b[n]){
	  num++;
	}
      }
    }
    blow = num - hit;
    cout << hit << ' ' << blow << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int n;
	cin >> n;
	int ans = (int)(pow(10, 9));
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		int divcnt = 0;
		while(a % 2 == 0){
			a /= 2;
			divcnt++;
		}
		if(ans > divcnt) ans = divcnt;
	}

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

Measured memory_bytes: 256
main :: IO()
main = do
    n <- readLn
    a <- readLn
    b <- readLn
    c <- readLn
    d <- readLn
    e <- readLn
    print $ (ceil n (min' [a,b,c,d,e])) + 4


min' :: [Int] -> Int
min' ls
    | length ls == 1					= head ls
    | head ls < last ls 				= min' $ init ls
    | otherwise							= min' $ tail ls

ceil :: Int -> Int -> Int
ceil num1 num2 = if (mod num1 num2) == 0 then div num1 num2 else (div num1 num2) + 1

Measured memory_bytes: 508
import collections
w = list(input())
w = collections.Counter(w)
w_count = w.most_common()
flag = 0

for i in range(len(w_count)):
    if int(w_count[i][1]) % 2 == 1:
        flag = 1

if flag == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3316
# https://atcoder.jp/contests/abc144/tasks/abc144_d
from math import radians, sin, cos, tan, degrees, atan
a, b, x = map(int, input().split())

# ans = a * b * (b * tan(radians(45))) / 2
# print(ans, tan(radians(45)))
# x = a * b * (b * tan(radians(ans))) / 2
# 2 * x / (a * b) = (b * tan(radians(ans)))
# 2 * x / (a * b) / b = tan(radians(ans))

if a * a * b / 2. <= x:
    ans = degrees(atan(2 * (a * a * b - x) / (a * a * a)))
else:
    ans = 90 - degrees(atan((2 * x) / (a * b * b)))
print(ans)

Measured memory_bytes: 62344
#include <bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i = 0; i < n; i++)
#define pb push_back
#define all(c) c.begin(),c.end()


int main()
{

    int n;
    cin >> n;
    int a[n+1] = {};
    for(int i = 2; i<=n; i++)
    {
        int x; cin >> x;
        a[x]++;
    }
    for(int i =1; i <=n; i++)
    {
        cout << a[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 4376
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b;
	cin>>a>>b;
	if(a>=13)puta(b);
	else if(a<=5)puta(0);
	else puta(b/2);
	return 0;
}

Measured memory_bytes: 256
main = do
  n <- readLn :: IO Int
  as <- map read . words <$> getLine :: IO [Int]
  putStrLn $ if check as then "APPROVED" else "DENIED"

check as = foldl (&&) True $ map checkItem as
    where checkItem a | odd a = True
                      | otherwise = mod a 3 == 0 || mod a 5 == 0


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 5;
long long dn[N] = {};
bool isp[N] = {};
void build() {
    fill(dn, dn + N, 1);
    for (int i = 2; i < N; i++)
        if (!isp[i]) {
            for (long long j = 1LL * i * i; j < N; j += i)
                isp[j] = true;
            for (long long j = i, p = 1; j < N; j *= i, p++)
                for (int k = j; k < N; k += j)
                    dn[k] = dn[k] / p * (p + 1);
        }
}
int main() {
    build();
    long long ans = 0;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        ans += dn[i] * i;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 91488
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ull i=0; i<n; ++i)
#define FOR(i, s, e) for(ull i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ull N; cin >> N;
  vector<ull> P(100010,0);
  rep(i,N) {
    ull A; cin >> A;
    P[A]++;
  }
  ull sum = 0;
  rep(i,P.size()) {
    sum += i*P[i];
  }
  ull Q; cin >> Q;
  vector<ull> S(Q);
  rep(i,Q) {
    ull B, C; cin >> B >> C;
    sum += C*P[B];
    sum -= B*P[B];
    P[C] += P[B];
    P[B] = 0;
    S[i] = sum;
  }
  for(auto s:S) cout << s << endl;
}

Measured memory_bytes: 4752
#include <iostream>
#include <cstring>

int seq[25] = {0, 31,};

int main() {
    std::string str;
    std::cin >> str;
    int a = (str[0] - '0') * 10 + (str[1] - '0');
    int b = (str[2] - '0') * 10 + (str[3] - '0');
    if (a > 12 && b > 12) {
        std::cout << "NA";
    } else if (a <= 12 && b <= 12 && a > 0 && b > 0) {
        std::cout << "AMBIGUOUS";
    } else if (a == 0 || b == 0) {
        if (a == 0 && b > 12) std::cout << "NA";
        else if (b == 0 && a > 12) std::cout << "NA";
        else if (a == 0 && b == 0) std::cout << "NA";
        else if (a > b) std::cout << "MMYY";
        else if (a < b) std::cout << "YYMM";
    } else {
        if (a <= 12) {
            std::cout << "MMYY";
        } else if (b <= 12) std::cout << "YYMM";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e10;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int M,K;
    cin >> M >> K;
    if(K > pow(2,M)-1) {
        cout << -1 << endl;
        return 0;
    }
    if(M == 1) {
        if(K == 0) cout << "0 0 1 1" << endl;
        else cout << -1 << endl;
        return 0;
    }
    if(M == 0) {
        cout << "0 0" << endl;
        return 0;
    }
    for(int i = 0; i < pow(2,M); i++) {
        if(i == K) {
            continue;
        }
        cout << i << " ";
    }
    cout << K << " ";
    for(int i = pow(2,M)-1; i >= 0; i--) {
        if(i == K) {
            continue;
        }
        cout << i << " ";
    }
    cout << K << endl;
}


Measured memory_bytes: 3928
//あらためて見るとこの問題全然わからない

//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int A[2][200000], B[2][200000];
	int kazuA[29] = {}, kazuB[29] = {};
	rep(i, N) {
		int a = getint();
		A[0][i] = a; 
		rep(j, 28) kazuA[j] += a >> j & 1;
	}
	rep(i, N) {
		int b = getint();
		B[0][i] = b;
		rep(j, 28) kazuB[j] += b >> j & 1;
	}
	int kotae = 0;
	rep(i, 28) {
		int p = i & 1;
		auto Amae = A[p];
		auto Bmae = B[p];
		auto Atugi = A[!p];
		auto Btugi = B[!p];

		int kazu[2];
		kazu[0] = 0;
		kazu[1] = N - kazuB[i];
		rep(j, N) Btugi[kazu[Bmae[j] >> i & 1]++] = Bmae[j];

		int kazu0 = 0;
		int kazu1 = N - kazuA[i];

		int kari = N & kazuA[i] & 1;
		int d = (1 << i) - 1;
		int d2 = 1 << i;
		int k1 = N - kazuB[i];
		int k2 = N;
		int k3 = N - kazuB[i];
		int k4 = N;

		rep(j, N) {
			if (Amae[j] >> i & 1) {
				while (k1 > 0 && (Amae[j] & d) + (Btugi[k1 - 1] & d) >= d2) k1--;
				while (k2 > kazu[0] && (Amae[j] & d) + (Btugi[k2 - 1] & d) >= d2) k2--;
				kari ^= k1 ^ k2;

				Atugi[kazu1++] = Amae[j];
			}
			else {
				while (k3 > 0 && (Amae[j] & d) + (Btugi[k3 - 1] & d) >= d2) k3--;
				while (k4 > kazu[0] && (Amae[j] & d) + (Btugi[k4 - 1] & d) >= d2) k4--;
				kari ^= k3 ^ k4;

				Atugi[kazu0++] = Amae[j];
			}
		}
		kotae += (kari & 1) << i;
	}

	int d2 = 1 << 28;
	int k = N;
	int kari = N;
	rep(j, N) {
		while (k > 0 && (*A)[j] + (*B)[k - 1] >= d2) k--;
		kari ^= k;
	}
	kotae += (kari & 1) << 28;

	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 3456
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

N,M=map(int,input().split())
S=input()
T=input()

C=N*M//gcd(max(N,M),min(N,M))
n=C//N
m=C//M

i=0
j=0
ans=C
while i<C and j<C:
    if  i==j:
        if S[i//n]!=T[j//m]:
            ans=-1
        i+=n
        j+=m
    elif i<j:
        i+=n
    else:
        j+=m
print(ans)

Measured memory_bytes: 3316
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    void solve(Scanner sc, PrintWriter pw) {
        char c = sc.next().charAt(0);
        pw.println(Character.isUpperCase(c) ? 'A' : 'a');
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        new Main().solve(sc, pw);
        pw.flush();
        pw.close();
        sc.close();
    }
}


Measured memory_bytes: 35768
#include <iostream>
#include <cstdio>
#include <algorithm>

#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define pre(i, a, b) for(int i = a; i >= b; i --)

using namespace std;

typedef long long ll;

const int maxn = 1000 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int n, m;
char map[maxn][maxn];
int f[maxn][maxn];

int read()
{
	int x;
	scanf("%d", &x);
	return x;
}

void input()
{
	n = read(), m = read();
	rep(i, 1, n)
	{
		rep(j, 1, m)
		{
			cin >> map[i][j];
		}
	}
}

void work()
{
	f[1][1] = 1;
	rep(i, 1, n)
	{
		rep(j, 1, m)
		{
			if(i >= 2 && map[i - 1][j] == '.')
			{
				f[i][j] = (f[i][j] + f[i - 1][j]) % mod;
			}
			if(j >= 2 && map[i][j - 1] == '.')
			{
				f[i][j] = (f[i][j] + f[i][j - 1]) % mod;
			}
		}
	}
}

void output()
{
	printf("%d", f[n][m] % mod);
}

int main()
{
	input();
	work();
	/*
	rep(i, 1, n)
	{
		rep(j, 1, m)
			cout << f[i][j] << " ";
		cout << endl;
	}
	*/
	output();
}

Measured memory_bytes: 5248
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

signed main(){
    
    while(1){
        int n, m; cin >> n >> m;
        if(!n) break;
        vector<vector<int>> gl(n, vector<int> (n, INF));
        vector<vector<int>> gs(n, vector<int> (n, INF));
        for(int i = 0; i < m; i++){
            int x, y, t; char sl; cin >> x >> y >> t >> sl;
            x--;
            y--;
            if(sl == 'L') gl[x][y] = gl[y][x] = t;
            if(sl == 'S') gs[x][y] = gs[y][x] = t;
        }
        

        // 自分の場所へは 0
        for(int i = 0; i < n; i++){
            gl[i][i] = 0;
            gs[i][i] = 0;
        }

        // ワーシャル 2 発
        for(int k = 0; k < n; k++){
            for(int i = 0; i < n; i++){
                for(int j = 0; j < n; j++){
                    gl[i][j] = min(gl[i][j], gl[i][k] + gl[k][j]);
                    gs[i][j] = min(gs[i][j], gs[i][k] + gs[k][j]);
                }
            }
        }


        int r; cin >> r;
        vector<int> z(r);
        for(int i = 0; i < r; i++){
            cin >> z[i];
            z[i]--;
        }
        vector<vector<int>> dp(r, vector<int> (n, INF));
        dp[0][z[0]] = 0;
        for(int i = 0; i < r - 1; i++){
            for(int j = 0; j < n; j++){
                if(dp[i][j] == INF) continue;

                // 次に行くのは z[i + 1]
                int cur = z[i];
                int nxt = z[i + 1];

                // 陸路で行く
                if(gl[cur][nxt] != INF) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + gl[cur][nxt]);

                // 徒歩で船があるところまで行って、船で適当な頂点まで行って、そっから徒歩
                for(int v = 0; v < n; v++){
                    if(gl[cur][j] != INF && gs[j][v] != INF && gl[v][nxt] != INF) dp[i + 1][v] = min(dp[i + 1][v], dp[i][j] + gl[cur][j] + gs[j][v] + gl[v][nxt]);
                }
            }
        }
        
        /*
        for(int i = 0; i < r; i++){
            for(int j = 0; j < n; j++){
                cout << dp[i][j] << " ";
            }
            cout << endl;
        }
        */

        int ans = INF;
        for(int j = 0; j < n; j++) ans = min(ans, dp[r - 1][j]);
        cout << ans << endl;
    
    }

    return 0;
}



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


int main() {
	using i64 = long long;
	int n, m, q;
	::std::cin >> n >> m >> q;
	auto t = ::std::vector<::std::vector<i64>>(n + 1, ::std::vector<i64>(n, 0));
	while(m--) {
		int l, r;
		::std::cin >> l >> r;
		--l;
		--r;
		++t[0][r];
		--t[l + 1][r];
	}
	for (int i = 0;i < n;++i)
		for (int j = 1;j < n;++j)
			t[i][j] += t[i][j - 1];
	for (int i = 1;i < n;++i)
		for (int j = 0;j < n;++j)
			t[i][j] += t[i - 1][j];
	while (q--) {
		int l, r;
		::std::cin >> l >> r;
		--l;
		--r;
		::std::cout << t[l][r] << ::std::endl;
	}
	return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    ll n, k;
    cin >> n >> k;

    vector<long double> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        v[i] = v[i] * (v[i] + 1) / 2 / v[i];
    }

    /*
    for (size_t i = 0; i < n; i++){
        cout << v[i] << " ";
    }
    cout << endl;
    */

    long double ans = accumulate( v.begin(), v.begin() + k , (long double)0.0 );
    long double tmp = ans;
    for (size_t i = 0; i < n - k; i++)
    {
        tmp -= v[i];
        tmp += v[i + k];
        ans = max( ans, tmp );
    }
    
    cout << setprecision(10) << ans << endl;


}

Measured memory_bytes: 3328
from bisect import bisect_right
from collections import deque

n = int(input())
a = [int(input()) for _ in range(n)]

c, ans = deque(), 0

for i in range(n):   
    t = bisect_right(c, a[i]-1) - 1
    if t < 0: c.appendleft(a[i])
    else: c[t] = a[i]

print(len(c))


Measured memory_bytes: 8052
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;
const int MOD = 1000000007;

struct UnionFind {
	vi data;
	UnionFind(int size) : data(size, -1) {}
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool find(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int main() {
	int N;
	cin >> N;
	vector<string> a(N);
	vi x(N);
	UnionFind uf(N);
	map<string, int> index;
	REP(i, N) {
		cin >> a[i] >> x[i];
		index[a[i]] = i;
	}

	int M;
	cin >> M;
	string s, t;
	REP(i, M) {
		cin >> s >> t;
		uf.unite(index[t], index[s]);
	}

	vi cost(N, INF), num(N, 0);
	REP(i, N) {
		int r = uf.root(i);
		cost[r] = min(cost[r], x[i]);
		num[r]++;
	}

	int ans = 0;
	REP(i, N) {
		if (cost[i] != INF) {
			ans += cost[i] * num[i];
		}
	}

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

Measured memory_bytes: 3752
#include <iostream>
using namespace std;
int a, b, c;
int z[200];
int f[302][302][302];
int solve(int a, int b, int c) {
	if (a > 300 || b > 300 || c > 300) return 1000;
	if (f[a][b][c] != 1000) return f[a][b][c];
	int z[10];
	z[0] = solve(a + 1, b + 1, c); 
	z[1] = solve(a + 1, b, c + 1);
	z[2] = solve(a, b + 1, c + 1);
	z[3] = solve(a + 2, b, c);
	z[4] = solve(a, b + 2, c);
	z[5] = solve(a, b, c + 2);
	int mn = z[0];
	for (int j = 1; j <= 5; j++) mn = min(mn, z[j]);
	f[a][b][c] = mn + 1;
	return mn + 1;
}
int main() {
	// your code goes here
	for (int i = 0; i <= 300; i++)
	for (int j = 0; j <= 300; j++)
	for (int k = 0; k <= 300; k++) f[i][j][k] = 1000;
	for (int i = 0; i <= 300; i++) f[i][i][i] = 0;
	cin >> a >> b >> c;
	cout << solve(a, b, c);
	return 0;
}

Measured memory_bytes: 107520
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#include <stdlib.h>
#include <time.h>
#include <chrono>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

ll d;
vector<ll> c(26 + 1, 0);
vector<vector<ll>> s(365 + 1, vector<ll>(26 + 1, 0));

ll scoring(vector<int> t)
{
    ll ans = 0;
    vector<ll> last(26 + 1, 0);

    for (int i = 1; i <= d; i++)
    {
        ans += s[i][t[i]];
        ans -= c[t[i]] * (i - last[t[i]]) * (i - last[t[i]] - 1) / 2;
        last[t[i]] = i;
    }

    for (int i = 1; i <= 26; i++)
    {

        ans -= c[i] * (d - last[i] + 1) * (d - last[i]) / 2;
    }

    return ans;
}

int main(void)
{
    srand(time(NULL));
    cin >> d;

    for (int i = 1; i <= 26; i++)
    {
        cin >> c[i];
    }

    for (int i = 1; i <= d; i++)
    {
        for (int j = 1; j <= 26; j++)
        {
            cin >> s[i][j];
        }
    }

    vector<int> BestT(d + 1, 1);

    for (int i = 1; i <= d; i++)
    {
        BestT[i] = rand() % 26 + 1;
    }

    double BestScore = scoring(BestT);
    double score;

    auto start = chrono::system_clock::now();
    vector<int> t(d + 1, 1);

    double T0 = 1e6;
    double T1 = 1e3;
    double TL = 1980;

    ll count = 0;

    while (1)
    {
        ll msec;

        msec = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - start).count();

        if (msec >= TL)
        {
            break;
        }

        double T = powf(T0, 1 - msec / TL) * powf(T1, msec / TL);

        t = BestT;

        t[rand() % d + 1] = rand() % 26 + 1;

        score = scoring(t);

        if (exp((score - BestScore) / T) > 0.5)
        {
            BestT = t;
            BestScore = score;
        }
    }

    for (int i = 1; i <= d; i++)
    {
        printf("%d\n", BestT[i]);
    }
}


Measured memory_bytes: 4460
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    vector<int> v(n), c(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    for (int i = 0; i < n; i++) cin >> c[i];
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += max(0, v[i] - c[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384