akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys
from collections import deque
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7


def debug(*x):
    print(*x, file=sys.stderr)


def solve(H, W, Ch, Cw, Dh, Dw, data):
    # data = list(data.reshape(-1))
    N = HEIGHT * WIDTH
    visited = [0] * N

    start = (Ch + 1) * WIDTH + (Cw + 1)
    goal = (Dh + 1) * WIDTH + (Dw + 1)
    q = []
    nextJump = set()
    q.append(start)

    currentDistance = 0
    while True:
        while q:
            p = q.pop()
            if p == goal:
                return currentDistance
            if visited[p]:
                continue
            for dx in [-2, -1, 0, +1, +2]:
                for dy in [-WIDTH * 2, -WIDTH, 0, WIDTH, WIDTH * 2]:
                    nextJump.add(p + dx + dy)
            visited[p] = 1
            for d in [-1, +1, -WIDTH, +WIDTH]:
                if data[p + d] and not visited[p + d]:
                    q.append(p + d)

        # no continuous cell
        for p in nextJump:
            if not data[p]:
                continue
            if visited[p]:
                continue
            q.append(p)

        currentDistance += 1
        nextJump = set()
        if not q:
            return -1


def readMap(H, W):
    global SENTINEL, HEIGHT, WIDTH
    SENTINEL = 2
    HEIGHT = H + SENTINEL * 2
    WIDTH = W + SENTINEL * 2
    data = [0] * (HEIGHT * WIDTH)
    ok = ord(".")
    for i in range(H):
        S = input().strip()
        y = (i + SENTINEL) * WIDTH
        for j in range(W):
            data[y + (j + SENTINEL)] = 1 if S[j] == ok else 0
    return data


def main():
    # parse input
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())
    D = readMap(H, W)
    print(solve(H, W, Ch, Cw, Dh, Dw, D))


# tests
T1 = """
4 4
1 1
4 4
..#.
..#.
.#..
.#..
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
1
"""

T2 = """
4 4
1 4
4 1
.##.
####
####
.##.
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
-1
"""

T3 = """
4 4
2 2
3 3
....
....
....
....
"""
TEST_T3 = """
>>> as_input(T3)
>>> main()
0
"""

T4 = """
4 5
1 2
2 5
#.###
####.
#..##
#..##
"""
TEST_T4 = """
>>> as_input(T4)
>>> main()
2
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()


Measured memory_bytes: 128568
# include <iostream>
# include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>

using namespace std;
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl '\n'
int main(void) {
    fast_cin();

    int n;
    cin >> n;

    int yen = 1000;

    while (n>0) {
        n -= yen;
    }
    cout << -n << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
 
void read (int&a) {
	a = 0; char k = getchar(); int f = 1;
	for(;!isdigit(k); k = getchar()) if (k == '-') f = -1;
	for(; isdigit(k); k = getchar()) a = a * 10 + k - '0';
	a *= f;
}
 
const int N = 200000 + 5, mod = 1000000007;
int fpow (int base, int v) {
	int tot = 1;
	for(; v; v >>= 1, base = 1LL * base * base % mod) if (v & 1) tot = 1LL * tot * base % mod;
	return tot;
}
void add (int&a, int b) { a = (a + b) % mod; }
vector<int> G[N], D[N];
int n, sz[N], dep[N];
 
void dfs (int u, int f) {
	dep[u] = dep[f] + 1;
	D[ dep[u] ].push_back (u);
	for (int i = 0; i < (signed)G[u].size(); ++i) if (G[u][i] != f) {
		dfs (G[u][i], u);
	}
}
 
int stk[N], top, dp[N], sum0[N], pow2[N];
 
int dp0(int x) { return (pow2[sz[x]] - dp[x] + mod) % mod; }
 
void upd (int x, int y) {
	sz[y] += sz[x];
	dp[y] = 1LL * dp[y] * fpow (sum0[y], mod - 2) % mod;
	sum0[y] = 1LL * sum0[y] * dp0(x) % mod;
	add (dp[y], 1LL * dp[x] * fpow(dp0(x), mod - 2) % mod);
	dp[y] = 1LL * dp[y] * sum0[y] % mod;
}

int fa[N], L[N], llca[N];
int Find (int u) { return u == fa[u] ? u : fa[u] = Find (fa[u]); }

void tarjan (int u, int f) {
	if (L[u]) llca[L[u]] = Find (L[u]);
	for (int i = 0; i < (signed)G[u].size(); ++i) if (G[u][i] != f) {
		tarjan (G[u][i], u);
		fa[G[u][i]] = u;
	}
}

int main ()
{
	read (n); n++;
	pow2[0] = 1; for(int i = 1; i <= n; ++i) pow2[i] = 1LL * pow2[i - 1] * 2 % mod;
	for (int i = 2; i <= n; ++i) {
		int x; read (x); ++x;
		G[x].push_back (i), G[i].push_back (x);
	}
	dfs (1, 0);

	for (int i = 1; i <= n; ++i) fa[i] = i;
	for (int i = 1; i <= n; ++i) for (int j = 0; j < (signed)D[i].size() - 1; ++j) L[D[i][j + 1]] = D[i][j];
	tarjan (1, 0);

	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		int nowdep = i;
		if (!D[i].size()) break;
		stk[ top = 1 ] = D[i][0], dp[D[i][0]] = 1, sum0[D[i][0]] = 1, sz[D[i][0]] = 1;
		for (int j = 1; j < (signed)D[i].size(); ++j) {
			int p = D[i][j], lca = llca[stk[top]];
 
			dp[p] = 1, sum0[p] = 1, sz[p] = 1;
 
			while(dep[ stk[top] ] > dep[lca]) {
				if (top == 1 || dep[stk[top - 1]] < dep[lca]) { dp[lca] = 0, sum0[lca] = 1, sz[lca] = 0; upd (stk[top], lca); }
				else upd(stk[top], stk[top - 1]);
				top--;
			}
			if (top == 0 || stk[top] != lca) stk[++top] = lca;
			stk[++top] = p;
		}
		for (int i = top; i > 1; --i) upd (stk[i], stk[i - 1]);
		int tans;
		add (ans, tans = 1LL * pow2[n - (signed)D[nowdep].size()] * dp[stk[1]] % mod);
	}
	printf ("%d\n", ans);
	return 0;
}

Measured memory_bytes: 40064
import java.util.*;

public class Main {

    int INF = Integer.MAX_VALUE;

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] p = new int[N];
        int c = 0;
        long ans = 0;
        for (int i = 0; i < N; i++) {
            p[i] = sc.nextInt();
            if (p[i] == i + 1) {
                c++;
            } else if (c <= 1) {
                ans += c;
                c = 0;
            } else if (c % 2 == 0) {
                ans += c / 2;
                c = 0;
            } else {
                ans += c / 2 + 1;
                c = 0;
            }
        }
        if (c <= 1) {
            ans += c;
            c = 0;
        } else if (c % 2 == 0) {
            ans += c / 2;
            c = 0;
        } else {
            ans += c / 2 + 1;
            c = 0;
        }

        System.out.println(ans);
    }
}

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

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
const lld MAXN = 1e4;

int main()
{
	lld d,w,h,n;

	while(1)
	{
		cin >> d >> w >> h;
		if (d==0 && w==0 && h==0)
		{
			break;
		}
		lld di = min(d*d+w*w, w*w+h*h);
		di = min(di,h*h+d*d);

		cin >> n;
		for(int i = 0; i < n; i++)
		{
			lld r;
			cin >> r;

			if (4*r*r > di)
			{
				cout << "OK" << endl;
			}else
			{
				cout << "NA" << endl;
			}

		}
	}
	return 0;
}

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

int main()
{
    string s;
    cin >> s;
    int a = 0;
    int b = 0;
    int ans = s.size();
    for (int i = 0; i < s.size(); i++)
    {
        char c;
        if (i % 2 == 0)
            c = '0';
        else
            c = '1';

        if (c != s[i])
            a++;
    }
    for (int i = 0; i < s.size(); i++)
    {
        char c;
        if (i % 2 == 1)
            c = '0';
        else
            c = '1';

        if (c != s[i])
            b++;
    }
    cout << min(a, b) << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
long long int max(long long int a,long long int b);
int i,j,k;
int R,C,K;
int r,c,v;
int table[3001][3001];
long long int ret;
long long int dp[3001][3001][4];

int main(void)
{

    scanf("%d %d %d",&R,&C,&K);
    for (i=0;i<3001;i++){
        for (j=0;j<3001;j++){
            table[i][j]=0;
        }
    }
    for (i=0;i<3001;i++){
        for (j=0;j<3001;j++){
            for (k=0;k<4;k++){
                dp[i][j][k]=0;
            }
        }
    }
    for (i=0;i<K;i++){
        scanf("%d %d %d",&r,&c,&v);
        table[r-1][c-1]=v;
    }
    for (i=0;i<R;i++){
        for (j=0;j<C;j++){
            for (k=2;k>=0;k--){
                dp[i][j][k+1]=max(dp[i][j][k+1],dp[i][j][k]+table[i][j]);
            }
            for (k=0;k<4;k++){
                if (i<R-1) dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]);
                if (j<C-1) dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
            }
        }
    }
    ret=dp[R-1][C-1][0];
    for (i=0;i<4;i++){
        ret=max(ret,dp[R-1][C-1][i]);
    }
    printf("%lld",ret);
    return 0;
}

long long int max(long long int a,long long int b){
    if (a<b) return b;
    else return a;
}


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

public class Main{
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    int N = Integer.parseInt(in.readLine());

    Map<Integer, List<Integer>> v = new HashMap<>();
    for(int i=0;i<N+1;i++){
      v.put(i, new ArrayList<Integer>());
    }
    for(int i=0;i<N-1;i++){
      Integer[] ab = Arrays.stream(in.readLine().split(" ")).map(Integer::parseInt).toArray(Integer[]::new);
      v.get(ab[0]).add(ab[1]);
      v.get(ab[1]).add(ab[0]);
    }
    int[] fenecDist = new int[N+1];
    Arrays.fill(fenecDist, -1);
    int[] snukeDist = new int[N+1];
    Arrays.fill(snukeDist, -1);
    dfs(fenecDist, v, 1, 0);
    dfs(snukeDist, v, N, 0);

    // System.out.println(Arrays.toString(fenecDist));
    // System.out.println(Arrays.toString(snukeDist));

    int[] fScore = new int[N+1];
    for(int i=1;i<=N;i++){
      if(fenecDist[i] <= snukeDist[i]){
        fScore[i] = 1;
      }
    }
    if(Arrays.stream(fScore).sum()>N/2){
      System.out.println("Fennec");
    }else{
      System.out.println("Snuke");
    }
  }

  public static void dfs(int[] dist, Map<Integer, List<Integer>> v, int start, int depth){
    if(dist[start]>-1){
      return;
    }
    dist[start] = depth;
    for(int i: v.get(start)){
      dfs(dist, v, i, depth+1);
    }
  }
}


Measured memory_bytes: 98704
import java.util.*;

public class Main {
    private static final int M =  1000000007;

    private static long solve(int N, int K, int[] a) {
        int[] ways = new int[K+1];
        int[] next = new int[K+1];
        ways[0] = 1;

        for (int ai: a) {
            int s = 0;
            for (int i = 0; i <= K; i++) {
                int add = ways[i];
                int remove = (i-ai-1 >= 0) ? ways[i-ai-1]: 0;
                s = (s + add - remove) % M;
                if (s < 0) s += M;

                next[i] = s;
            }

            int[] tmp = ways;
            ways = next;
            next = tmp;
        }

        return ways[K];
    }

    public static long run(Scanner scanner) {
        int N = scanner.nextInt();
        int K = scanner.nextInt();
        int[] a = new int[N];
        for (int i=0; i < N; i++) a[i] = scanner.nextInt();
      
        return solve(N, K, a);
    }

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            System.out.println(run(scanner));
        }
        //Tests.run();
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    cout << (n+110) / 111 * 111 << endl;

    return 0;
}

Measured memory_bytes: 256
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=float('inf')
for i in range(M):
    x,y,c=map(int,input().split())
    ans=min(ans,a[x-1]+b[y-1]-c)

a.sort()
b.sort()
ans=min(ans,a[0]+b[0])

print(ans)

Measured memory_bytes: 18656
#include <bits/stdc++.h>
using namespace std;
long long n,i,nr,x,aux;
int main()
{
    cin>>n;
    if(n%2==0)
        for(i=5;i<=n;i=i*5)
            nr=nr+n/(i*2);
    cout<<nr;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.function.*;
import java.lang.*;
import java.io.*;

class MathLib{
    static long gcd(long a, long b){
        if(a<0) a = -a;
        if(b<0) b = -b;
        if(a>b){
            long t = a;
            a = b;
            b = t;
        }
        while(a>0){
            long r = b%a;
            b = a;
            a = r;            
        }
        return b;
    }
    static long lcm(long a, long b){
        return a / gcd(a,b) * b;
    }
    static boolean isPrime(long N){
        if(N%2==0) return false;
        for(long i=3; i*i<=N; i+=2){
            if(N%i==0) return false;
        }
        return true;
    }

    static List<Integer> primeList(int max){
        boolean[] prime = new boolean[max+1];
        Arrays.fill(prime, true); prime[0]=false; prime[1]=false;
        ArrayList<Integer> list = new ArrayList<>();
        for(int n=2; n<=max; n++) if(prime[n]){
            list.add(n);
            if(n*n<=max) for(int m=2*n; m<=max; m+=n) prime[m]=false;
        }
        return list;
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(MathLib.lcm(N, 360) / N);
    }
}



Measured memory_bytes: 35824
#include <stdio.h>

int main() {
  int number_of_cookies_a, number_of_cookies_b;
  scanf("%d %d", &number_of_cookies_a, &number_of_cookies_b);
  if(number_of_cookies_a % 3 != 0 && number_of_cookies_b % 3 != 0 && (number_of_cookies_a + number_of_cookies_b) % 3 != 0) {
    printf("Impossible\n");
  } else {
    printf("Possible\n");
  }
  return 0;
}


Measured memory_bytes: 128
use std::io::{BufRead, Write};
use std::io;

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut s = String::new();
    input.read_line(&mut s).unwrap();
    let _ = s.trim().parse::<usize>().unwrap();
    s.clear();
    input.read_line(&mut s).unwrap();
    let a = s.split_whitespace()
        .map(|s| s.parse::<i64>().unwrap())
        .collect::<Vec<_>>();
    let result = [true, false]
        .iter()
        .map(|&initial| {
            let mut flag = initial;
            let mut total = 0;
            let mut cost = 0usize;
            for &i in &a[0..] {
                total += i;
                if total == 0 || (total > 0) != flag {
                    cost += (total - if flag { 1 } else { -1 }).abs() as usize;
                    total = if flag { 1 } else { -1 };
                }
                flag ^= true;
            }
            cost
        })
        .min()
        .unwrap();
    writeln!(output, "{}", result).unwrap();
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v = Vec::<u8>::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }
    #[test]
    fn case1() {
        test("4
1 -3 1 0\n",
             "4\n");
    }
    #[test]
    fn case2() {
        test("5
3 -6 4 -5 7\n",
             "0\n");
    }
    #[test]
    fn case3() {
        test("6
-1 4 3 2 -5 4\n",
             "8\n");
    }
}


Measured memory_bytes: 6396
//
// Created by Mahmoud Rashad on 11/27/19.
//

#include <bits/stdc++.h>


using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<ii, ii>> vii;

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int n, k;
    cin >> n >> k;
    map<int, int> mp;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        mp[x]++;
    }
    vector<int> toSort;
    for (auto it : mp)
        toSort.push_back(it.second);
    sort(toSort.begin(), toSort.end());
    int ans = 0;
    for (int i = 0; (int)toSort.size() - i > k; ++i) {
        ans += toSort[i];
    }
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 10744
#include<stdio.h>
int main(){
  int n,m,a,b,ans[55]={},i;
  scanf("%d%d",&n,&m);
  for(i=0;i<m;i++){
    scanf("%d%d",&a,&b);
    ans[a-1]++;
    ans[b-1]++;
  }
  for(i=0;i<n;i++){
    printf("%d\n",ans[i]);
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, T;
    cin >> N >> T;
    vector<pair<int, int>> time_cost(N);
    for(int i = 0; i < N; i++) {
        int c, t;
        cin >> c >> t;
        time_cost.at(i) = make_pair(t, c);
    }
    
    int ans = 100000;
    for(int i = 0; i < N; i++) {
        if(time_cost.at(i).first > T) continue;
        ans = min(ans, time_cost.at(i).second);
    }
    if(ans == 100000) cout << "TLE" << endl;
    else cout << ans << endl;
    
}


Measured memory_bytes: 256
N,K=map(int, input().split())

#a,b,c全てKの倍数
#mod　足してKになるようにする→modがK/2
modk=0
modhalf=0
for i in range(1,N+1):
  if i%K==0:
    modk+=1
  if K%2==0 and i%K==(K//2):
    modhalf+=1
    

ans=0
if modk>=1:
  ans+=(modk)**3
if modhalf>=1:
  ans+=modhalf**3

print(ans)
#print(modk, modhalf)

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

int main (){
  vector<int>v(3);
  for(int i= 0; i <3; i++){
    cin >> v[i];
    }
  sort(v.begin(),v.end());
  
  cout << (v[0] + (v[2]*10 +v[1]))<<endl;
  
  return 0;
  }

Measured memory_bytes: 256
#ifdef DBG1
#define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <functional>

#ifdef DBG1
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#else
#define dbg(...)
#endif

using namespace std;

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

const int P = 998244353;

int sum(int a, int b) {
  if ((a += b) >= P) {
    a -= P;
  }
  return a;
}

int diff(int a, int b) {
  if ((a -= b) < 0) {
    a += P;
  }
  return a;
}

int &add(int &a, int b) {
  return a = sum(a, b);
}

int &subtract(int &a, int b) {
  return a = diff(a, b);
}

int prod(int a, int b) {
  return int(ll(a) * b % P);
}

int power(int a, int n) {
  int b = 1;
  while (n) {
    if (n & 1) { b = prod(a, b); }
    a = prod(a, a);
    n /= 2;
  }
  return b;
}

const int MAXN = 3010;
int dp[MAXN][MAXN];
int dp2[MAXN][MAXN];

bool solve() {
  int a, b, c, d;
  if (scanf("%d%d%d%d", &a, &b, &c, &d) != 4) return false;

  dp[a][b] = 1;
  for (int y = b + 1; y <= d; ++y) {
    dp[a][y] = prod(dp[a][y - 1], a);
  }
  for (int x = a + 1; x <= c; ++x) {
    for (int y = b; y <= d; ++y) {
      if (y > b) {
        dp2[x - 1][y] = prod(x, dp2[x - 1][y - 1]);
      }
      add(dp2[x - 1][y], prod(dp[x - 1][y], y));

      dp[x][y] = prod(dp[x - 1][y], y);
      add(dp[x][y], dp2[x - 1][y - 1]);
//      for (int k = 1; y - k >= b; k++) {
//        add(dp[x][y], prod(dp2[x - 1][y - k], power(x, k - 1)));
//      }
//      dp[x][y] = prod(dp[x][y], y);
    }
  }

  printf("%d\n", dp[c][d]);
  return true;
}

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


Measured memory_bytes: 74248
import java.util.Scanner

object Main {

  case class Ope(maxCard: Int, score: Long)

  def read() = {
    val sc = new Scanner(System.in)
    val n, m = sc.nextInt()
    val cards = IndexedSeq.fill(n)(sc.nextLong())
    val opes = IndexedSeq.fill(m)(Ope(sc.nextInt(), sc.nextLong()))
    (n, m, cards, opes)
  }


  def solve(n: Int, m: Int, cards: IndexedSeq[Long], opes: IndexedSeq[Ope]): Long = {
    val sCard = cards.sorted // 昇順
    val sOpes = opes.sortBy(_.score)(Ordering[Long].reverse)

    // 操作による増加量の計算
    def simulate(cardIdx: Int, opeIdx: Int, diff: Long): Long = {
      if (cardIdx >= n || opeIdx >= m) diff
      else {
        val currentOpe = sOpes(opeIdx)
        val diff0 = (cardIdx until math.min(cardIdx + currentOpe.maxCard, n))
          .map(i => math.max(currentOpe.score - sCard(i), 0)).sum
        simulate(cardIdx + currentOpe.maxCard, opeIdx + 1, diff + diff0)
      }
    }

    val diff = simulate(0, 0, 0)
    sCard.sum + diff
  }

  def main(args: Array[String]): Unit = {
    val (n, m, cards, opes) = read()
    val result = solve(n, m, cards, opes)
    println(result)
  }
}

Measured memory_bytes: 117956
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,n)   for (int i = 0; i < (n); ++i)
#define sort(a)    sort((a).begin(), (a).end());
#define uniq(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define find(a,x)  find((a).begin(), (a).end(), (x)) != (a).end()
#define reverse(a) reverse((a).begin(), (a).end());
#define out(d) cout << (d);
#define outl(d) std::cout<<(d)<<"\n";
#define Yes() printf("Yes\n");
#define No() printf("No\n");
#define YES() printf("YES\n");
#define NO() printf("NO\n");
#define ceil(x, y) ((x + y - 1) / (y))

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

static const ll MOD = 1000000007; // 10^9 + 7
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c) {
  stack<int> S;
  S.push(r);
  color[r] = c;

  while (!S.empty()) {
    int u = S.top(); S.pop();
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (color[v] == NIL) {
        color[v] = c;
        S.push(v);
      }
    }
  }
}

void assignColor() {
  int id = 1;
  rep(i, n) color[i] = NIL;
  rep(u, n) {
    if (color[u] == NIL) dfs(u, id++);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));

  int s, t, m, q;
  cin >> n >> m;

  rep(i, m) {
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  assignColor();

  cin >> q;

  rep(i, q) {
    cin >> s >> t;
    if (color[s] == color[t]) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
}



Measured memory_bytes: 8984
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 200000

int main() {
	int x, y, z;
	int s, ans;
	scanf("%d", &x);
	ans = x * x * 3;

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


	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#define findmax(a,b) (a)>(b)?(a):(b)
#define findmin(a,b) (a)<(b)?(a):(b)
#define inout freopen("in.txt","r",stdin);freopen("out.txt","w",stdout)
#define swap(a,b) (a)+=(b);(b)=(a)-(b);(a)-=(b)
#define quicksort(a,n) qsort(a,n,sizeof(a[0]),cmp)
#define inputarr(a,n) for(int i=0;i<n;i++){scanf("%d",&a[i]);}
#define printarr(a,n) for(int i=0;i<n;i++){printf("%d ",a[i]);}puts("");
int cmp(const void *a,const void *b){return *(int *)a - *(int *)b;}
 
int main() {
    
	//inout;

	char s[25];

	scanf("%s", s);

	for(int i = 0; i < 3; i++){
		printf("%c", s[i]);
	}


}

Measured memory_bytes: 1620
#include<bits/stdc++.h>
using namespace std;
void insertionSort(vector<int> &A,int n,int g,int &cnt){
     for (int i=g;i<n;i++){
          int v = A[i];
          int j = i - g;
          while (j >= 0 && A[j] > v){
              A[j+g] = A[j];
              j = j - g;
              cnt++;
          }
          A[j+g] = v;
    }
}
void shellSort(vector<int> &A, int n,int &cnt){
     int m=0;
     while(pow(3,m+1)<=2*n+1) m++;
     int g[m];
     for(int i=0;i<m;i++){
         g[i] = (pow(3,i+1)-1)/2;
     }
     reverse(g,g+m);
     cout << m << endl;
     for(int i=0;i<m-1;i++) cout << g[i] << " ";
     cout << g[m-1] << endl;
     for (int i = 0;i<m;i++){
         insertionSort(A, n, g[i],cnt);
     }
}
int main(){
    int n,cnt = 0;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    shellSort(a,n,cnt);
    cout << cnt << endl;
    for(int i=0;i<n;i++) cout << a[i] << endl;
}


Measured memory_bytes: 6724
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	dp := make([]cint, n+10)
	for i := 1; i < n+10; i++ {
		dp[i] = math.MaxInt64 >> 1
	}
	for i := 0; i < n; i++ {
		dp[i+1].minAs(dp[i] + 1)
		p := 6
		for i+p < n+10 {
			dp[i+p].minAs(dp[i] + 1)
			p *= 6
		}
		p = 9
		for i+p < n+10 {
			dp[i+p].minAs(dp[i] + 1)
			p *= 9
		}
	}
	fmt.Fprintln(writer, dp[n])
}

type cint int64

func (ct *cint) minAs(x cint) *cint {
	*ct = ct.min(x)
	return ct
}
func (ct *cint) maxAs(x cint) *cint {
	*ct = ct.max(x)
	return ct
}
func (ct cint) min(x cint) cint {
	if ct > x {
		return x
	}
	return ct
}
func (ct cint) max(x cint) cint {
	if ct < x {
		return x
	}
	return ct
}


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

using namespace std;

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

    vector<int> app(N); // 各りんごの味
    vector<bool> appb(N,false); // 各りんごの味がマイナスならばtrue、プラスならばfalse;
    for(int i=0;i<N;i++) // （りんごの数）回回す;
    {
        app.at(i) = L + i; // にゅう
        if(app.at(i) < 0) appb.at(i) = true;
    }

    int total = accumulate(app.begin(),app.end(),0);

    int minapp = 1000000000;
    int minnum = 0;

    for(int i=0;i<N;i++)
    {
        app.at(i) = abs(app.at(i));
        if(minapp > app.at(i))
        {
            minapp = app.at(i);
            minnum = i;
        }
    }

    int answer = total;

    if(appb.at(minnum)==true)
    {
        answer += minapp;
    }
    else
    {
        answer -= minapp;
    }

    cout << answer << endl;

    return 0;
}

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

int main()
{
  int n;
  cin >> n;
  bool flag=true;
  int k;
  for(int i=0; i<n; i++){
    cin >> k;
    if(k%2==0 && !(k%3==0 || k%5==0)) flag=false;
  }
  if(flag) cout << "APPROVED";
  else cout << "DENIED";
  
  return 0;
}

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

class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
          //input
          int num = Integer.parseInt(br.readLine());
          String[] block = br.readLine().split(" ");

          // for search
          int count = 1;
          List<Integer> list = new ArrayList<>();

          // search
          for(int i = 0; i < num; i++){
            if(Integer.parseInt(block[i]) == count){
              list.add(i);
              count++;
            }else{
              continue;
            }
          }

          if(list.size() == 0){
            System.out.println("-1");
          }else{
            System.out.println(num - list.size());
          }
      }
    }
}

Measured memory_bytes: 62640
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
class UnionFind{
private:
    vector<int> vec;
public:
    void init(int N){
        vec.resize(N);
        for(int a = 0;a < N;a++)
        {
            vec[a]=-1;
        }
    }
    int root(int a)
    {
        if(vec[a] < 0)return a;
        else return vec[a] = root(vec[a]);
    }
    bool connect(int a,int b)
    {
        a = root(a);
        b = root(b);
        if(a==b)return false;
        if(vec[a] > vec[b])swap(a,b);
        vec[a] += vec[b];
        vec[b] = a;
        return true;
    }
    bool check(int a,int b){
        a = root(a);
        b = root(b);
        if(a==b)return true;
        else return false;
    }
};
bool comp(const Edge& e1, const Edge& e2){
    return e1.value < e2.value;
}
LL kruskal(V<Edge> Edges,int N){
    sort(ALL(Edges), comp);
    UnionFind Uni;
    Uni.init(N);
    LL ans = 0;
    for(int a = 0;a < Edges.size();a++){
        Edge e = Edges.at(a);
        if(!Uni.check(e.from,e.to)){
            Uni.connect(e.from,e.to);
            ans += e.value;
        }
    }
    return ans;
}
int main(){
    CIN(N);
    V<Edge> vec;
    V<pair<LL,LL>> q;
    V<pair<LL,LL>> p;
    REP(a,N){
        LCIN(b);
        LCIN(c);
        q.pb(make_pair(b,a));
        p.pb(make_pair(c,a));
    }
    sort(ALL(p));
    sort(ALL(q));
    for(int a = 0;a < N-1;a++){
        Edge e(p.at(a).second,p.at(a+1).second,abs(p.at(a).first-p.at(a+1).first));
        Edge w(q.at(a).second,q.at(a+1).second,abs(q.at(a).first-q.at(a+1).first));
        vec.pb(e);
        vec.pb(w);
    }
    COUT(kruskal(vec,N));
    return 0;
}


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


struct SCC {
  struct csr {
    vector<int> start, elist;
    csr(int n, const vector<pair<int, int>> &edges)
      : start(n+1), elist(edges.size()) {
        for(pair<int, int> e:edges) {
          start[e.first+1]++;
        }
        for(int i = 1; i <= n; i++) {
          start[i] += start[i-1];
        }
        vector<int> counter = start;
        for(pair<int, int> e:edges) {
          elist[counter[e.first]++] = e.second;
        }
    }
  };
  int n;
  vector<pair<int, int>> edges;
  SCC(int n_) : n(n_) {}
  void add(int from, int to) {edges.emplace_back(from, to);}
  pair<int, vector<int>> scc_ids() {
    csr g(n, edges);
    int now_ord = 0, group_num = 0;
    vector<int> used, low(n), ord(n, -1), ids(n);
    used.reserve(n);
    auto dfs = [&](auto self, int v)->void {
      low[v] = ord[v] = now_ord++;
      used.push_back(v);
      for(int i = g.start[v]; i < g.start[v+1]; i++) {
        int to = g.elist[i];
        if(ord[to] == -1) {
          self(self, to);
          low[v] = min(low[v], low[to]);
        }
        else {
          low[v] = min(low[v], ord[to]);
        }
      }
      if(low[v] == ord[v]) {
        while(true) {
          int u = used.back();
          used.pop_back();
          ord[u] = n;
          ids[u] = group_num;
          if(u == v) break;
        }
        group_num++;
      }
    };
    for(int i = 0; i < n; i++) {
      if(ord[i] == -1) dfs(dfs, i);
    }
    for(int &x:ids) {
      x = group_num - 1 - x;
    }
    return {group_num, ids};
  }
  vector<vector<int>> scc() {
    pair<int, vector<int>> ids = scc_ids();
    int group_num = ids.first;
    vector<int> counts(group_num);
    for(int x:ids.second) counts[x]++;
    vector<vector<int>> groups(group_num);
    for(int i = 0; i < group_num; i++) {
      groups[i].reserve(counts[i]);
    }
    for(int i = 0; i < n; i++) {
      groups[ids.second[i]].push_back(i);
    }
    return groups;
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  SCC scc(n);
  for(int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    scc.add(a, b);
  }
  auto v = scc.scc();
  cout << v.size() << '\n';
  for(int i = 0; i < (int)v.size(); i++) {
    cout << v[i].size();
    for(int j = 0; j < (int)v[i].size(); j++) {
      cout << ' ' << v[i][j];
    }
    cout << '\n';
  }
}

Measured memory_bytes: 40068
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import itertools


def main():
    n, m, x = map(int, input().split())
    ca_list = []
    for _ in range(n):
        ca_list.append(list(map(int, input().split())))

    min_c = 10 ** 20
    for i in range(2 ** n):
        cur_c = 0
        a_list = [0] * m
        for j in range(n):
            is_use = i & (2 ** j)
            if is_use:
                cur_c += ca_list[j][0]
                a_list = [a_list[k] + ca_list[j][k + 1] for k in range(m)]
        if all(k >= x for k in a_list) and cur_c < min_c:
            min_c = cur_c
    print(min_c if min_c != 10 ** 20 else -1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9220
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<set>
#include<string> 
#include<vector>
#include<stack>
#include<queue> 
#define PI 3.14159265358979323846
typedef long long ll;
using namespace std;
const ll Mod=1e9+7;
ll gcd(ll a, ll b) 
{
    if (b == 0) return a;
    else gcd(b, a % b);
}
long long quick_mod(long long a,long long b)//a的b次方对Mod取余 
{
    long long ans = 1;
    a %= Mod; //对刚进来的a进行取模运算，避免后面第一次求平方运算溢出
    while(b)
    {
        if(b&1) //对二进制下的 b 进行按位与1运算，求二进制下 b 的最低位是否为1
            ans = ans * a % Mod; //对结果进行保存
        b>>=1; //二进制下的 b 右移一位，相当于十进制下的 b 除以2
        a = a * a % Mod; 
    }
    return ans % Mod;
}
const int inf=0x3f3f3f3f;
int main()
{
	ll h=0,n=0,ai=0,ans=0;
	cin>>h>>n;
	for(int i=0;i<n;i++)
	{
		scanf("%lld",&ai);
		ans+=ai;
	}
	if(ans>=h)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
} 






Measured memory_bytes: 256
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define PI             acos(-1.0)
#define IOS            ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ms(a,b)         memset(a, b, sizeof(a))
#define filein      freopen("input.txt", "r", stdin);
#define fileout     freopen("output.txt", "w", stdout);
#define debug       cout<<"Hello, i am in here."<<endl;
#define bit_cnt(mask) __builtin_popcountll(mask)
#define ll long long int
#define dst(u,v,x,y) sqrt((x*1.0-u*1.0)*(x*1.0-u*1.0)+(y*1.0-v*1.0)*(y*1.0-v*1.0))
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}
template <class T> inline T bpow(T p,T e){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p);p = (p * p);}return (T)ret;}
using namespace std;
const int MOD = (int)1e9+7;
void solve()
{
  ll n;
  cin>>n;
  bool ok=false;
  while(n!=0)
  {
    if(n%10==7){
      ok=true;
      break;
    }
    n/=10;
  }
  if(ok)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
int  main()
{
    IOS
    solve();
    return 0;
}


Measured memory_bytes: 3648
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace abc153
{
    class Program
    {
        static void Main(string[] args)
        {
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
			solve_abc153B();
        }

        public static void solve_abc153B()
        {
            int[] hn = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int h = hn[0];
            int n = hn[1];
            int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            for (int i = 0; i < n; i++)
            {
                h -= a[i];
            }
            if (h <= 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

        public static void solve_abc153A()
        {
            int[] ha =  Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            Console.WriteLine((ha[0] + ha[1] - 1) / ha[1]);
        }
    }
}


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

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    if ((a + b) % 2 == 0) ans = (a + b) / 2;
    else ans = (a + b) / 2 + 1;
    cout << ans << endl;
}


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

int main(){
    int n;
    cin >> n;
    int a[n];
    int ans[n + 1];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        ans[i] = 0;
    }
    ans[n] = 0;

    for(int i = n; i >= 1; i--){
        int k = i;
        int cou = 0;
        int now = 2;
        while(1){
            int s = k * now;
            if(s > n){
                break;
            }
            cou += ans[s];
            now++;
        }

        if(cou % 2 == 0){
            if(a[i - 1] == 1){
                ans[i]++;
            }
        }else{
            if(a[i - 1] == 0){
                ans[i]++;
            }
        }
    }

    int cou = 0;
    for(int i = 0; i <= n; i++){
        if(ans[i] == 1){
            cou++;
        }
    }

    cout << cou << endl;
    int k = 0;
    for(int i = 0; i <= n; i++){
        if(ans[i] == 1){
            if(cou == k + 1){
                cout << i << endl;
            }else{
                cout << i << " ";
            }
            k++;
        }
    }
}

Measured memory_bytes: 2432
#include<iostream>
using namespace std;
#include<bits/stdc++.h>
int main(){
  int n,sum=0;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  int k=*max_element(a.begin(),a.end());
  if(sum-k>k)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end() 

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;




int main(){
    string A,B;
    cin>>A>>B;
    int a,b;
    cin>>a>>b;
    string C;
    cin>>C;
    if(A==C){
        a--;
    }else{
        b--;
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())

using namespace std;

int main()
{
  ll H, W; cin >> H >> W;
  vector<vector<char>> grid(H, vector<char>(W));
  rep(i, 0, H) {
  	rep(j, 0, W) {
    	cin >> grid[i][j];
    }
  }
  vector<vector<ll>> L(H, vector<ll>(W));
  vector<vector<ll>> R(H, vector<ll>(W));
  vector<vector<ll>> U(H, vector<ll>(W));
  vector<vector<ll>> D(H, vector<ll>(W));
  for(ll i = 0; i < H; i++) {
  	for(ll j = 0; j < W; j++) {
    	if (grid[i][j] == '#') {
        	L[i][j] = 0;
        } else if (j == 0) {
        	L[i][j] = 1;
        } else {
        	L[i][j] = L[i][j - 1] + 1;
        }
    }
  }
  for(ll i = 0; i < H; i++) {
  	for(ll j = W - 1; j >= 0; j--) {
    	if (grid[i][j] == '#') {
        	R[i][j] = 0;
        } else if (j == W - 1) {
        	R[i][j] = 1;
        } else {
        	R[i][j] = R[i][j + 1] + 1;
        }
    }
  }
  for(ll j = 0; j < W; j++) {
  	for(ll i = 0; i < H; i++) {
    	if (grid[i][j] == '#') {
        	D[i][j] = 0;
        } else if (i == 0) {
        	D[i][j] = 1;
        } else {
        	D[i][j] = D[i - 1][j] + 1;
        }
    }
  }
  for(ll j = 0; j < W; j++) {
  	for(ll i = H - 1; i >= 0; i--) {
    	if (grid[i][j] == '#') {
        	U[i][j] = 0;
        } else if (i == H - 1) {
        	U[i][j] = 1;
        } else {
        	U[i][j] = U[i + 1][j] + 1;
        }
    }
  }
  ll maxBright = 0;
  for(ll i = 0; i < H; i++) {
  	for(ll j = 0; j < W; j++) {
    	ll bright = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3;
      	if (maxBright < bright) maxBright = bright;
    }
  }
  cout << maxBright << endl;
}

Measured memory_bytes: 129536
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define mem0(x) memset(x,0,sizeof(x))
#define meminf(x) memset(x,0x3f,sizeof(x))
#define VI vector<int>
#define VL vector<ll>
using namespace  std;

const int N = 1e3+5;
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	ll s; cin >> s;
	if (s == 1000000000000000000) {
		cout << 0 << " " << 0 << " " << 1000000000 << " " << 0 << " " << 0 << " " << 1000000000; 
        return 0;
	}
	ll x3 = 1000000000 - (s % 1000000000);
	ll y3 = s / 1000000000 + 1;

	cout << 0 << " " << 0 << " " << 1000000000 << " " << 1 << " " << x3 << " " << y3;
}

Measured memory_bytes: 3560
#include <stdio.h>

int main(void){
  int n,m;
  int sum = 0;
  scanf("%d %d",&n,&m);
  int a[n];
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    sum += a[i];
  }
  int temp =0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n-1-i;j++){
      if(a[j] < a[j+1]){
        temp =a[j];
        a[j] =a[j+1];
        a[j+1] = temp;
      }
    }
  }
  if(a[m-1]>=(double)sum/(4*m)){
    printf("Yes\n");
  }else printf("No\n");
  return 0;

}


Measured memory_bytes: 1624
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextInt();
		long b = sc.nextInt();
		long c = sc.nextInt();
		long d = sc.nextInt();
		if((a>=0&&b>=0)&&(c>=0&&d>=0)) {
			System.out.println( b*d );
		}else if((a>=0&&b>=0)&&(c<0&&d>=0)) {
			System.out.println( b*d );
		}else if((a>=0&&b>=0)&&(c<0&&d<0)) {
			System.out.println( a*d );
		}
		
		else if((a<0&&b>=0)&&(c>=0&&d>=0)) {
			System.out.println( b*d );
		}else if((a<0&&b>=0)&&(c<0&&d>=0)) {
			if (a*c<b*d) {
				System.out.println( b*d );
			}else {
				System.out.println( a*c );
			}
		}else if((a<0&&b>=0)&&(c<0&&d<0)) {
			System.out.println( a*c );
		}
		
		else if((a<0&&b<0)&&(c>=0&&d>=0)) {
			System.out.println( c*b );
		}else if((a<0&&b<0)&&(c<0&&d>=0)) {
			System.out.println( a*c );
		}else if((a<0&&b<0)&&(c<0&&d<0)) {
			System.out.println( a*c );
		}
		sc.close();
	}
}

Measured memory_bytes: 35644
#include<bits/stdc++.h>
using namespace std;
int n,m,ans,cnt,a[1005];
string s;
int main()
{
	cin>>n; 
    while(n)
    {
    ans+=n%10;
    n/=10;
	}
	if(ans==1)
	ans+=9;
	cout<<ans<<endl;
    return 0;
	} 

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

int main(){
    string s;
    cin >> s;
    set<char>   cs;
    for(int i = 0;i < s.size();i++) cs.emplace(s[i]);
    int ans = 1000;
    for(auto& c : cs){
        int count = 0;
        int an = 0;
        for(int i = 0;i < s.size();i++){
            if(s[i] == c)   count = 0;
            else    count++;
            an = max(an, count);
        }
        ans = min(ans, an);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;

int main()
{
	int s, t, u;

	cin >> s >> t >> u;
	if (u>=s&&u<=t)
		cout << "Yes";
	else
		cout << "No";
}

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

int main(){
    int n; cin >> n;
    vector<long long> a(n),b(n),c(n);
    rep(i,n) cin >> a[i];
    rep(i,n){
        b[i] = a[i] + i;
        c[i] = i - a[i];
    }
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    long long ans = 0;
    rep(i,n){
        long long res = b[i];
        auto l = lower_bound(c.begin(),c.end(),res);
        auto r = upper_bound(c.begin(),c.end(),res);
        ans += r-l;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8012
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private static final int INF = Integer.MAX_VALUE / 2;

    private void solve(Scanner sc) {
        String s = sc.nextLine();
        if (s.matches("\\AA[a-z]+C[a-z]+\\z")) {
            _out.println("AC");
        } else {
            _out.println("WA");
        }
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 21844