akhauriyash/Code-Regression huggingface dataset:
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn diff(a: u32, b: u32) -> u32 {
    if a > b {
        a - b
    } else {
        b - a
    }
}

fn main() {
    let s: String = read();
    let sv: Vec<char> = s.chars().collect();

    let mut cv: Vec<char> = vec![];
    let mut xv: Vec<u32> = vec![];
    let mut i: usize = 0;
    let mut cnt = 0;
    while i < sv.len() && sv[i] == 'x' {
        i += 1;
        cnt += 1;
    }
    while i < sv.len() {
        if sv[i] == 'x' {
            cnt += 1;
        } else {
            xv.push(cnt);
            cnt = 0;
            cv.push(sv[i]);
        }
        i += 1;
    }
    xv.push(cnt);

    for i in 0..cv.len() {
        if i >= cv.len() - 1 - i {
            break;
        }
        if cv[i] != cv[cv.len() - 1 - i] {
            println!("-1");
            return;
        }
    }

    let mut ans: u32 = 0;
    for i in 0..xv.len() {
        if i >= xv.len() - 1 - i {
            break;
        }
        ans += diff(xv[i], xv[xv.len() - 1 - i]);
    }

    println!("{}", ans);
}


Measured memory_bytes: 6396
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap

def eratosthenes(n):
    p = [1]
    t = [True] * n

    t[1] = True
    for i in range(2, int(math.ceil(math.sqrt(n)))):
        if t[i]:
            p.append(i)
            for j in range(2*i, n, i):
                t[j] = False

    for j in range(i+1, n):
        if t[j]:
            p.append(j)

    return p


@mt
def slv(N):
    ps = eratosthenes(100)
    ps.pop(0)
    c = Counter()
    for i in range(2, N+1):
        n = i
        while n not in ps:
            for p in ps:
                if n % p == 0:
                    c[p] += 1
                    n //= p
                    break
        c[n] += 1

    c2 = len(list(filter( lambda x: x>=2, c.values())))
    c4 = len(list(filter( lambda x: x>=4, c.values())))
    c14 = len(list(filter( lambda x: x>=14, c.values())))
    c24 = len(list(filter( lambda x: x>=24, c.values())))
    c74 = len(list(filter( lambda x: x>=74, c.values())))
    ans = 0
    if c2 >= 3 and c4 >= 2:
        ans += (c4*(c4-1)//2) * (c2-2)
    if c4 > 0 and c14 > 0:
        ans += (c4-1) * c14
    
    if c2 > 0 and c24 > 0:
        ans += (c2-1) * c24
    if c74 > 0:
        ans += c74
    return ans


def main():
    N = read_int()
    print(slv(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6724
n=int(input())
xy=[]
for i in range(n):
    xy.append([int(x) for x in input().split()])

import itertools
import math
p=list(itertools.permutations(range(n)))

dist=0
for i in range(len(p)):
    for j in range(1,n):
        dist+=math.sqrt((xy[p[i][j-1]][0]-xy[p[i][j]][0])**2+(xy[p[i][j-1]][1]-xy[p[i][j]][1])**2)
print(dist/len(p))


Measured memory_bytes: 7972
import math
n, d = map(int, input().split())
x = [
  list(map(int, input().split()))
  for _ in range(n)
]
count = 0
for i in range(n):
  for j in range(i+1, n):
    distance = math.sqrt(sum([
      (a - b) ** 2
      for a, b in zip(x[i], x[j])
    ]))
    if distance == int(distance):
      count += 1
print(count)


Measured memory_bytes: 3060
#include <stdio.h>

int main(void) {
  int n;
  int i;
  int m;
  long long sum = 0, min, max;

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &m);
    sum += m;
    if(i == 0) {
      min = m;
      max = m;
    }
    if (m > max)
      max = m;
    if (m < min)
      min = m;
  }

  printf("%lld %lld %lld\n", min, max, sum);
  
  return 0;
}



Measured memory_bytes: 1992
#include <iostream>
#include <string>
#include <set>
using namespace std;
int main(){
	set<string> se;
	string s;
	int k;
	cin >> s >> k;
	for(int i=0;i<s.size();i++){
		for(int j=1;j<6;j++){
			if(i+j<=s.size()){
				se.insert(s.substr(i,j));
			}
		}
	}
	auto itr = se.begin();
	for(int i=0;i<k-1;i++)++itr;
	cout << *itr << endl;
}

Measured memory_bytes: 1664
#include <string>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string.h>
#include <utility>
#include <queue>
#include <stack>
#include <iomanip>
#include <ctype.h>
#include <map>
#include <set>
#include <stdio.h>
#include <assert.h>
#include <ctype.h>
#include <sstream>
#include <math.h>
#include <time.h>
#include <iostream>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <tuple>
#include <cmath>
#include <stdio.h>      /* printf, fgets */
#include <stdlib.h>
#include <fstream>

using namespace std;

typedef long long LL;

#define FOR(i,n) for(int i = 0;i < n;i++)
#define MP make_pair
#define PB push_back
#define ALL(a) (a).begin(),(a).end()
#define PII pair<int, int>
#define PLL pair<long long, long long>
#define CLEAR(a) memset(a, 0, sizeof(a))
#define ERASE(a) memset(a, -1, sizeof(a))
#define INF 2000000007LL
#define y1 uu1
#define y2 uu2
const double EPS = 1E-12;
const double PI = acos(-1.0);
const LL mod = 1000000007;

using namespace std;

int n;
vector<LL> a;
LL x, sum;

int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0);
  cin >> n;

  FOR(i, n) {
    cin >> x;
    a.push_back(x);
    sum += x;
  }

  LL cur = 0;
  LL bst = sum;
  FOR(i, n) {
    cur += a[i];
    bst = min(bst, abs(cur - (sum - cur)));
  }
  cout << bst << endl;
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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

ll solve(ll h) {
    if (h == 1) {
        return 1;
    } else {
        return 1 + solve(h / 2) * 2;
    }
}
int main() {
    ll h;
    cin >> h;

    cout << solve(h) << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 300000000000000000
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll n,m;cin>>n>>m;
    V<ll>x(n),y(n),z(n);
    for(ll i=0;i<n;i++){
        cin>>x[i]>>y[i]>>z[i];
    }
    ll ans=-INF;
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            for(int k=0;k<2;k++){
                V<ll>v(n);
                for(ll q=0;q<n;q++){
                    if(i==0)v[q]+=x[q];
                    else v[q]-=x[q];
                    if(j==0)v[q]+=y[q];
                    else v[q]-=y[q];
                    if(k==0)v[q]+=z[q];
                    else v[q]-=z[q];
                }
                sort(all(v));
                reverse(all(v));
                ll tmp=0;
                for(ll q=0;q<m;q++)tmp+=v[q];
                chmax(ans,tmp);
            }
        }
    }
    cout<<ans<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------





































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

using namespace std;

int main()
{
 
  map<int,int> mp;
  int n;
  cin>>n;
  for(int i = 1;i<=100;i++)
  {
      for(int j = 1;j<=100;j++)
      {
          for(int k = 1;k<=100;k++)
          {
              int num = i*i + j*j + k*k + i*j + j*k + i*k;
              mp[num]++;
          }
      }
  }
  for(int i = 1;i<=n;i++)
  {
      cout<<mp[i]<<"\n";
  }
  
  return 0;
}

Measured memory_bytes: 5404
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    ll n, m, k, x, i;
    cin >> n >> m >> k;
    ll kk = k;
    ll a[n+1] = {0};
    while(kk--){
        cin >> x;
        a[x]++;
    }
    for(ll i = 1; i <= n; i++){
        x = m - k + a[i];
        a[i] = max(0ll, x);
        if(a[i] == 0){
            cout << "No\n";
        }
        else{
            cout << "Yes\n";
        }
    }
    return 0;
}

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

using namespace std;

int a;
int res = 1;

int main() {
    cin >> a;
    for(int i = 2; i * i <= a; i++) {
        int k = i * i;
        while(k * i <= a) k *= i;
        res = max(res, k);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e18 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

ll dp[101][100010];

int main() {
  ll n,wei; 
  cin >> n >> wei;
  vector<ll> w(n), v(n);

  rep(i,n) {
    scanf("%lld %lld", &w[i], &v[i]);
  }

  // 品物
  for (int i = 0; i < n; ++i) {
    // 重さ
    for (int j = 0; j <= wei; ++j) {
      if (j < w[i]) dp[i+1][j] = dp[i][j];
      else dp[i+1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
    }
  }

  cout << dp[n][wei] << endl;
}

Measured memory_bytes: 78336
N = list(input())
n = len(N) - 1
a = ["+"] * n
ev = []
for bit in range(1 << n):
    for i in range(n + 1):
        ev.append(N[i])
        if bit & (1 << i):
            ev.append(a[i])
    ev.append("+")
ev = "".join(ev)[:-1]
print(eval(ev))


Measured memory_bytes: 4120
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <iomanip>

using namespace std;


int main(void)
{
     int n;
    while(cin>>n){
       
        double w,h;
        scanf(",%lf,%lf",&w,&h);
        //cin>>n>>w>>h;
        double bmi = w/(h*h);
        if(bmi>=25.0)cout<<n<<endl;
    }
    
}

Measured memory_bytes: 1264
main(N,n,x,y,t){for(;scanf("%d",&n)*n;)for(x=y=!printf("Case %d:\n",N++);++x>n?puts(""),x=++y<n:1;printf("%3.f",~-t*t/2+(t&1?x:y+1)-pow(t>n?t-n:0,2)))t=x+y;}

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

int main(){
  int n,q;
  int a[100];

  while((cin>>n>>q)&&(n != 0)&&(q != 0)){
    for(int i=0;i<100;i++){
      a[i] = 0;
    }
    for(int i=0;i<n;i++){
      int m;
      cin >> m;
      for(int j=0;j<m;j++){
        int date;
        cin >> date;
        a[date]++;
      }
    }
    int max=0;
    for(int i=1;i<100;i++){
      if(a[max]<a[i]) max=i;
    }
    if(a[max]>=q)
      cout << max << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}

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

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

long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}

long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
 
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int a[202345];
int b[202345];

int main(){
	int n;
	
	cin >> n;
	
	REP(i,n){
		scanf("%d", &a[i]);
	}
	
	int f;
	int be = n/2;
	
	if (n%2 == 0) f = 0;
	else f = 1;
	
	REP(i,n){
		if (f){
			b[be-i] = a[i];
			be -= i;
		}
		else {
			b[be+i] = a[i];
			be += i;
		}
		
		f = !f;
	}
	
	REP(i,n){
		if (i) printf(" ");
		printf("%d", b[i]);
	}
	
	puts("");
	
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 +7;
typedef long long ll;
inline int read(){
    int x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9'){
        x = (x<<1) + (x<<3) + (ch^48);
        ch = getchar();
    }
    return x * f;
}
int a[88];
int main()
{
    int n = read();
    for (int i = 1; i <= n; i++)
        a[i] = read();
    ll sum = 1000, cnt = 0;
    for (int i = 1; i <= n; i++) {
        if(a[i] < a[i + 1]) {
            cnt += sum / a[i];
            sum = sum - sum / a[i] * a[i];
        }
        else if(a[i] > a[i + 1]) {
            sum += cnt * a[i];
            cnt = 0;
        }
    }
    sum += cnt * a[n];
    printf("%lld\n", sum);
}


Measured memory_bytes: 3692
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

double EPS = 1e-10;

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) {
		return 0;
	}
	return a + b;
}

struct P {
	double x, y;
	P() {}
	P(double x, double y) : x(x), y(y) {
	}
	P operator + (P p) {
		return P(add(x, p.x), add(y, p.y));
	}
	P operator - (P p) {
		return P(add(x, -p.x), add(y, -p.y));
	}
	P operator * (double d) {
		return P(x * d, y * d);
	}
	double dot(P p) {
		return add(x * p.x, y * p.y);
	}
	double det(P p) {
		return add(x * p.y , -y * p.x);
	}
};

bool cmp_x(const P& p, const P& q) {
	if (p.x != q.x) {
		return p.x < q.x;
	}
	return p.y < q.y;
}

vector<P> convex_hull(P* ps, int n) {
	sort(ps, ps + n, cmp_x);
	int k = 0;
	vector<P> qs(n*2);

	for (int i = 0; i < n; i++) {
		while (k > 1 && (qs[k-1] - qs[k-2]).det(ps[i] - qs[k-1]) <= 0) {
			k--;
		}
		qs[k++] = ps[i];
	}
	for (int i = n-2, t = k; i >= 0; i--) {
		while (k > t && (qs[k-1] - qs[k-2]).det(ps[i] - qs[k-1]) <= 0) {
			k--;
		}
		qs[k++] = ps[i];
	}
	qs.resize(k-1);
	return qs;
}

P ps[10];

int main() {
	char c;
	while (cin >> ps[0].x >> c >> ps[0].y >> c >> ps[1].x >> c >> ps[1].y >> c >> ps[2].x >> c >> ps[2].y >> c >> ps[3].x >> c >> ps[3].y) {
		vector<P> qs = convex_hull(ps, 4);
		if (qs.size() == 4) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

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

int main(void) {
	int i, q, r, t, f, start = 200000, len = 0;
	char c, s[500000];

	scanf("%s", &s[start]);
	scanf("%d", &q);
	len = strlen(&s[start]);
	for (i = 0; i < q; i++) {
		scanf("%d", &t);
		if (t == 1) {
			r++;
			r %= 2;
		}
		else {
			scanf("%d %c", &f, &c);
			if (r == 1) {
				if (f == 1) {
					f = 2;
				}
				else {
					f = 1;
				}
			}
			if (f == 1) {
				s[start - 1] = c;
				start--;
			}
			else {
				s[start + len] = c;
				s[start + len + 1] = '\0';
			}
			len++;
		}
	}
		if (r == 0) {
			printf("%s", &s[start]);
		}
		else {
			for (i = start + len - 1; i >= start; i--) {
				printf("%c", s[i]);
			}
		}

	



	return 0;
}

Measured memory_bytes: 768
use std::io::stdin;


fn main() {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let s:Vec<char> = st.trim().chars().collect();
    let (mut g, mut p):(usize, usize) = (0,0);
    for i in s.iter() {
        if &i == &&'g'{
            g += 1;
        } else {
            p += 1;
        };
    };
    let n = s.len();
    println!("{}", n/2 - p);
}

Measured memory_bytes: 4352
#include <iostream>
#include <stack>
using namespace std;
#define int long long int
stack<int> path;
signed main()
{
    int n, k;
    cin >> n >> k;
    int a[n + 1];
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    int count = 0, dist = 0, sz = 0, vis[n + 1] = {0}, i = 1, flag = 0, vertex;
    while (!vis[i])
    {
        path.push(i);
        vis[i] = 1;
        i = a[i];
    }
    vertex = i;
    while (path.size())
    {
        int v = path.top();
        path.pop();
        count++;
        if (v == vertex)
        {
            sz = count;
            count = 0;
            flag = 1;
        }
        else if (v == 1)
            dist = count;
    }
    if (k <= dist)
    {
        int cur = 0, start = 1;
        while (cur < k)
        {
            start = a[start];
            cur++;
        }
        cout << start << endl;
    }
    else
    {
        k = k - dist;
        k = k % sz;
        int cur = 0, start = vertex;
        while (cur < k)
        {
            start = a[start];
            cur++;
        }
        cout << start << endl;
    }
    return 0;
}

Measured memory_bytes: 8348
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
bool s[111111];
int main(void){
  s[0] = s[1] = true;
  for(int i = 2; i*i < 111111; i++){
    if(s[i]) continue;
    for(int j = i*2; j < 111111; j+=i){
      s[j] = true;
    }
  }

  int n,p;
  while(cin >> n >> p && ~n){
    vector<int> v;
    vector<int> c;
    for(int i = n+1; (int)v.size() < 100; i++){
      if(!s[i]) v.push_back(i);
    }
    for(int i = 0; i < 100; i++){
      for(int j = i; j < 100; j++){
	c.push_back(v[i]+v[j]);
      }
    }
    sort(c.begin(),c.end());
    cout << c[p-1] << endl;
  }
}

Measured memory_bytes: 1384
#include<stdio.h>
#define MAX 100000

int A[MAX],n;

int partition(int p,int r){
	int x,i,j,t;
	x=A[r];
	i=p-1;
	for(j=p;j<r;j++){
		if(A[j]<=x){
			i++;
			t=A[i];
			A[i]=A[j];
			A[j]=t;
		}
	}
	t=A[i+1];
	A[i+1]=A[r];
	A[r]=t;
	return i+1;
}

int main(){
	int i,q;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	q=partition(0,n-1);
	
	for(i=0;i<n;i++){
		if(i){
			printf(" ");
		}
		if(i==q){
			printf("[");
		}
		printf("%d",A[i]);
		if(i==q){
			printf("]");
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <vector>
 
using namespace std;
 
int main() {
    int N,count =0;
    cin >> N;
    vector<int> arr(N,0);
 
    for ( int i = 0; i < N; i++)
    {
        cin >> arr[i];
    }
 
    for (int j = 0; j < N; j++)
    {
        int num;
 
        num = arr[j];
 
        if (j + 1 == arr[num - 1])
        {
            count = count + 1;
        }
    }
 
    cout << count / 2 <<endl;
 
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll keta(ll n){
    ll ans = 0;
    while(n>0){
        n/=10;
        ans++;
    }
    return ans;
}
int main(){
    ll n;
    cin >> n;
    ll ans = INF;
    for(ll i = 1;i*i<=n;i++){
        if(n%i==0){
            ll j =n/i;
            ans = min(max(keta(i),keta(j)),ans); 
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);
const int MAX_V = 1000;

int main() {
  int N, W; cin >> N >> W;
  vi w(N), v(N);
  rep(i, N) cin >> w[i] >> v[i];

  vvi dp(N, vi(N*MAX_V+1, INFL));
  dp[0][0] = 0;
  dp[0][v[0]] = w[0];
  REP(i, 1, N) {
    rep(j, N*MAX_V+1) {
      if (j+v[i] >= N*MAX_V+1) continue;
      dp[i][j] = min(dp[i][j], dp[i-1][j]);
      dp[i][j+v[i]] = min(dp[i][j+v[i]], dp[i-1][j] + w[i]);
    }
  }
  ll ans = 0;
  rep(i, N*MAX_V+1) {
    if (dp[N-1][i] <= W) {
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 79488
#include <iostream>

using namespace std;

int N,M;

int main(){
    cin >> N >> M;
    long long t = 0;
    long long c = 1 << M;
    t += c * (N-M) * 100;
    t += c * M * 1900;
    cout << t << endl;
    return 0;
}

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

using namespace std;

#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

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

    int a, b;
    cin >> a >> b;
    int res = a - 1;
    if(a <= b) ++res;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	string s;
	cin>>s;
	string t=s;
	reverse(s.begin(),s.end());
	for(int i=0;i<s.length();i++){
		if(s[i]=='b'){
			s[i]='d';
		}else if(s[i]=='d'){
			s[i]='b';
		}else if(s[i]=='p'){
			s[i]='q';
		}else if(s[i]=='q'){
			s[i]='p';
		}
	}
	if(s==t){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#define F first
#define S second
#define PLL pair<ll, ll>

using namespace std;

typedef long long ll;

ll n, k;
ll b[100005];
pair<ll, ll> a[100005];
priority_queue<PLL, vector<PLL>, greater<PLL> > pq;
priority_queue<PLL> pq2;
ll now;
ll ans;
ll cnt;

int main()
{
    scanf("%lld%lld", &n, &k);
    for(ll i = 0; i < n; i++)
    {
        scanf("%lld%lld", &a[i].S, &a[i].F);
    }
    sort(a, a + n, greater<pair<ll, ll> >());
    for(ll i = 0; i < k; i++)
    {
        now += a[i].F;
        b[a[i].S]++;
        if(b[a[i].S] == 1) cnt++;
        pq.push(a[i]);
    }
    for(ll i = k; i < n; i++)
    {
        pq2.push(a[i]);
    }
    ans = now + cnt * cnt;
    while(!pq.empty() && !pq2.empty())
    {
        PLL t1 = pq.top();
        PLL t2 = pq2.top();
        if(b[t1.S] <= 1)
        {
            pq.pop();
            continue;
        }
        if(b[t2.S] > 0)
        {
            pq2.pop();
            continue;
        }
        pq.pop(), pq2.pop();
        b[t1.S]--;
        b[t2.S]++;
        now -= t1.F, now += t2.F;
        cnt++;
        ans = max(ans, now + cnt * cnt);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 5236
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var XN = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var X = XN[0];
            var N = XN[1];
            var pi = new int[N];
            if (N == 0)
            {
                var tmp = Console.ReadLine();
            }
            else
            {
                pi = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            }
            if (N == 0)
            {
                Console.WriteLine(X);
                return;
            }

            var hash = new HashSet<int>();
            for (var i = 0; i < pi.Length; i++)
            {
                hash.Add(pi[i]);
            }
            var answer = 0;
            var d = 0;
            while (true)
            {
                var left = X - d;
                var right = X + d;
                if (!hash.Contains(left))
                {
                    answer = left;
                    break;
                }
                if (!hash.Contains(right))
                {
                    answer = right;
                    break;
                }
                d++;
            }

            Console.WriteLine(answer);
        }
    }
}


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

int main () {
    long long int i, j, ans, x = 1, y = 1, min_n;
    long long int n; cin >> n;
    min_n = n + 1;
    for (i = 1; i <= sqrt(n); i++) {
        j = n / i;
        if (n == i * j) {
            if (i + j <= min_n) {
                x = i;
                y = j;
            }
        }
    }

    ans = (x - 1) + (y - 1);
    cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> f(n), p(n);
  for (int i = 0; i < n; i++)
    cin >> f[i];
  for (int i = 0; i < n; i++)
    cin >> p[i];
  vector<bool> win(n);
  sort(p.begin(), p.end());
  auto pp = p;
  int num = 0;
  multiset<ll> s;
  for (int i = 0; i < n; i++) {
    auto it = upper_bound(pp.begin(), pp.end(), f[i]);
    if (it != pp.end()) {
      win[i] = true;
      pp.erase(it);
      num++;
    }
    s.insert(f[i]);
  }
  vector<ll> ans(n);
  auto g = [&](int i) {
    auto it = s.begin();
    vector<ll> t;
    for (int j = 0; t.size() < num; j++) {
      if (p.size() - 1 - j == i)
        continue;
      assert(p.size() - 1 - j >= 0);
      t.push_back(p[p.size() - 1 - j]);
    }
    reverse(t.begin(), t.end());
    for (int j = 0; j < num; j++) {
      assert(it != s.end());
      if (t[j] <= *it) {
        return false;
      }
      it++;
    }
    return true;
  };

  for (int i = 0; i < n; i++) {
    int l = 0, r = p.size();
    while (l < p.size() && p[l] <= f[i])
      l++;
    num--;
    s.erase(s.find(f[i]));
    if (l < r && g(l)) {
      int l = 0, r = p.size();
      while (l < p.size() && p[l] <= f[i])
        l++;
      assert(l < r);

      while (r - l > 1) {
        int m = (l + r) / 2;
        if (g(m)) {
          l = m;
        } else {
          r = m;
        }
      }
      ans[i] = p[l];
      p.erase(p.begin() + l);
    } else {
      num++;
      s.insert(f[i]);
      l = 0;
      while (r - l > 1) {
        int m = (l + r) / 2;
        if (g(m)) {
          l = m;
        } else {
          r = m;
        }
      }
      ans[i] = p[l];
      p.erase(p.begin() + l);
      continue;
    }
  }

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

  return 0;
}


Measured memory_bytes: 3472
#include <stdio.h>
 
int main(void) {
  int K;
  int A;
  int B;
  int C;
  scanf("%d", &K);
  scanf("%d", &A);
  scanf("%d", &B);
  for (int i = A; i <= B; i++) {
    if (i % K == 0) {
      printf("%s\n", "OK");
      return 0;
    }
  }
  printf("%s\n", "NG");
  return 0;
}

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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define ll long long
#define ll long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  

const int MOD = 1e9 + 7;

int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
    }
    vector<int> dp(k+1, 0);
    dp[k] = 1;
    for(int i=0;i<n;i++)
    {
        vector<int> dummy(k+2, 0);
        for(int j=0;j<=k;j++)
        {
            if(dp[j])
            {
                int left = max(0LL, j-a[i]);
                dummy[left] = (dummy[left] + dp[j])%MOD;
                dummy[j+1] = (dummy[j+1] - dp[j] + MOD)%MOD;
            }
        }
        //update dp
        int curr = 0;
        for(int j=0;j<=k;j++)
        {
            curr = (curr+dummy[j])%MOD;
            dp[j] = curr;
        }
    }
    cout  << dp[0] << "\n";

    return 0;
}



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

int N;
vector<int> L;

int main(void) {
	cin >> N;
	L.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> L[i];

	sort(L.begin(), L.end());
	int ans = 0;
	for (int i = 0; i < N - 2; ++i) {
		for (int j = i + 1; j < N - 1; ++j) {
			vector<int>::iterator itr;
			itr = lower_bound(L.begin() + j + 1, L.end(), L[i] + L[j]);
			if (itr != L.end()) {
				int id = int(itr - L.begin());
				int cnt = id - j - 1;
				ans += cnt;
			}
			else {
				int cnt = N - j - 1;
				ans += cnt;
			}
		}
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())

if h == 1 or w == 1:
    ans = 1
elif h % 2 == 0:
    ans = h//2 * w
elif w % 2 == 0:
    ans = w//2 * h
else:
    hh = h // 2
    wh = w // 2
    ans = (hh + 1) * (wh + 1) + hh * wh

print(ans)

Measured memory_bytes: 3060
N = int(input())
S = input().rstrip()
A, B, c1, c2 = [], [], 0, 0
for s in S:
    if s=="W": c1 += 1
    A.append(c1)
for s in reversed(S):
    if s=="E": c2 += 1
    B.append(c2)
B.reverse()
res = float("inf")
A += [0]
B += [0]
for i in range(N):
    res = min(A[i-1] + B[i+1], res)
print(res)

Measured memory_bytes: 113628
import java.util.Scanner;

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

        int a = in.nextInt();
        int b = in.nextInt();
        int m = a * b;
        int s = 2 * a + 2 * b;
        System.out.println(m + " " + s);
    }
}

Measured memory_bytes: 26124
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[310000];
    int n,m;
    scanf("%d%d",&n,&m);
    if(n&1)
    {
        for(int i=1; i<=m; i++)
        {
            a[i]=(n+1)/2;
        }
        int last=m;
        for(int i=1; i<=m/2; i++)
            if(a[last]==1) last--;
            else
            {
                a[last]--;
                for(int j=last+1; j<=m; j++)
                    a[j]=n;
                last=m;
            }

        for(int i=1; i<=last; i++)
        {
            printf("%d ",a[i]);
        }
       // printf("%d\n",a[last]);
    }
    else
    {
        printf("%d ",n/2);
        for(int i=2; i<=m; i++)
        {
            printf("%d ",n);
        }
        //printf("%d\n",n);
    }
    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
using namespace std;

main() {
    int N; cin >> N;
    map<int,int> m;
    rep(i,N){
        int a; cin >> a;
        m[a]++;
    }
    int sum=0;
    for(auto p:m){
        sum+=p.second-1;
    }
    cout << (sum%2==0 ? m.size() : m.size()-1) << endl;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; string c; cin>>n>>c;
	int ans=0;
	for(int i=0,r=n-1;i<n&&i<r;++i){
		if(c.at(i)=='R')continue;
		while(r>0&&c.at(r)!='R')--r;
		if(c.at(r)=='R'&&i<r){
			swap(c.at(i),c.at(r));
			++ans;
		}
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 3776
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
map<string, ll> mp;
int main(){
	string s; ll c;
	while (cin >> s) {
		if (s == "END_OF_FIRST_PART")break;
		cin >> c;
		mp[s] = c;
	}
	while (cin >> s) {
		if (s == "0")break;
		stack<ll> t;
		int n = s.length();
		ll sum = 0;
		bool unknown = false;
		rep(i, n) {
			if ('A' <= s[i] && s[i] <= 'Z') {
				string u; u += s[i];
				if (i + 1 < n&&'a' <= s[i + 1] && s[i + 1] <= 'z') {
					i++; u.push_back(s[i]);
				}
				ll c = mp[u];
				if (c == 0)unknown = true;
				int chk = i;
				while (i + 1 <= n && '0' <= s[i + 1] && s[i + 1] <= '9') {
					i++;
				}
				if (chk == i) {
					sum += c;
				}
				else {
					sum += c * stoll(s.substr(chk + 1, i - chk));
				}
			}
			else if (s[i] == '(') {
				t.push(sum); sum = 0;
			}
			else if (s[i] == ')') {
				int chk = i;
				while (i + 1 <= n && '0' <= s[i + 1] && s[i + 1] <= '9') {
					i++;
				}
				if(i!=chk) {
					sum *= stoll(s.substr(chk + 1, i - chk));
				}
				sum += t.top(); t.pop();
			}
			else {
				unknown = true;
			}
		}
		if (unknown)cout << "UNKNOWN" << endl;
		else cout << sum << endl;
	}
	return 0;
}


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

const ll MAXN = 200000;

ll N, ans=0, tmp=0;
vector<ll> A(MAXN, 0), G1(MAXN, 0), G2(MAXN, 0);

int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

signed main(){
    cin >> N;
    for(int i=0;i<N;i++) {
        cin >> A[i];
        if(!i) G1[i]=A[i];
        else G1[i]=gcd(A[i],G1[i-1]);
    }
    for(int i=N-1;i>=0;i--) {
        if(i==N-1) G2[i]=A[i];
        else G2[i]=gcd(A[i],G2[i+1]);
    }
    ans = max(G1[N-2],G2[1]);
    for(int i=1;i<N-1;i++) {
        ans = max(ans, gcd(G1[i-1],G2[i+1]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
<?php
$button[1] = array('.', ',', '!', '?', ' ');
$button[2] = array('a', 'b', 'c');
$button[3] = array('d', 'e', 'f');
$button[4] = array('g', 'h', 'i');
$button[5] = array('j', 'k', 'l');
$button[6] = array('m', 'n', 'o');
$button[7] = array('p', 'q', 'r', 's');
$button[8] = array('t', 'u', 'v');
$button[9] = array('w', 'x', 'y', 'z');

fscanf(STDIN, "%d", $n);

while ($n--) {
  fscanf(STDIN, "%s", $str);
  
  $ans = "";
  $push = "";
  $cnt = 0;
  for ($i = 0; $i < strlen($str); $i++) {
    $ch = $str[$i];
    if ($ch == 0) {
      if ($cnt) {
        $ans .= $button[$push][($cnt - 1) % count($button[$push])];
        $cnt = 0;
      }
    } else {
      $push = $ch;
      $cnt++;
    }
  }
  
  print $ans . "\n";
}

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

using namespace std;
#define BUF (100005)
#define ll long long 

int n,k;
int x[BUF];
int y[BUF];

int d[4003][4003];
int m[4003][4003];

void show(void){

	cout << "d----------\n";
	for(int i=0;i<2*k;i++) {
		for(int j=0;j<2*k;j++) cout << d[j][i];
		cout << "\n";
	}
	
	cout << "m----------\n";
	for(int i=0;i<2*k;i++) {
		for(int j=0;j<2*k;j++) cout << m[j][i];
		cout << "\n";
	}
}

int main(void){
	cin >> n >> k;
	for(int i=1;i<=n;i++){
		int tx,ty;
		char tc;
		cin >> tx >> ty >> tc;
		//change all white to black.
		if(tc=='W')ty+=k;

		//move all point to 0~2k-1.
		x[i] = tx%(2*k);
		y[i] = ty%(2*k);

		if(x[i]<k && y[i]<k){
			x[i]+=k;
			y[i]+=k;
		}
		if(x[i]<k && y[i]>=k){
			x[i]+=k;
			y[i]-=k;
		}

//		cout << x[i] << "," << y[i] << "\n";
	}

	//check all corner.
	for(int i=1;i<=n;i++){
		d[max(x[i]-k+1,0)][max(y[i]-k+1,0)]++;
		d[    x[i]+1     ][    y[i]+1     ]++;
		d[max(x[i]-k+1,0)][    y[i]+1     ]--;
		d[    x[i]+1     ][max(y[i]-k+1,0)]--;
	
		d[max(x[i]-k+1,0)][    y[i]+k+1   ]++;
		d[    x[i]+1     ][    y[i]+1+2*k ]++;
		d[max(x[i]-k+1,0)][    y[i]+1+2*k ]--;
		d[    x[i]+1     ][    y[i]+k+1   ]--;

		d[   x[i]+k+1    ][max(y[i]-k+1,0)]++;
		d[   x[i]+1+2*k  ][    y[i]+1     ]++;
		d[   x[i]+k+1    ][    y[i]+1     ]--;
		d[   x[i]+1+2*k  ][max(y[i]-k+1,0)]--;
	
		d[    x[i]+1     ][    y[i]+1     ]++;
		d[    x[i]+1 +k  ][    y[i]+1 +k  ]++;
		d[    x[i]+1     ][    y[i]+1 +k  ]--;
		d[    x[i]+1 +k  ][    y[i]+1     ]--;

		d[   x[i]+k+1    ][    y[i]+k+1       ]++;
		d[   x[i]+1+2*k  ][    y[i]+1+2*k     ]++;
		d[   x[i]+k+1    ][    y[i]+1+2*k     ]--;
		d[   x[i]+1+2*k  ][    y[i]+k+1       ]--;
	
	}

	int ans = 0;
	int st=0;
	for(int j=0;j<3*k;j++) {
		st=0;
		for(int i=0;i<3*k;i++){
			//first line
			st+=d[i][j];
			if(j==0) m[i][j] = st;
			else  m[i][j]=m[i][j-1]+st; 	
			ans = max(ans,m[i][j]);
		}
	}

//	show();
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 111872
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Omar Yasser
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, Scanner sc, PrintWriter out) {
            int n = sc.nextInt();
            String res = sc.next();
            int open = 0, close = 0;
            for (int i = 0; i < n; i++) {
                if (res.charAt(i) == '(') {
                    open++;
                } else {
                    if (open > 0) open--;
                    else close++;
                }
            }
            while (open > 0) {
                open--;
                res += ")";
            }
            while (close > 0) {
                close--;
                res = "(" + res;
            }
            out.println(res);
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader f) {
            br = new BufferedReader(f);
        }

        public String next() {
            while (st == null || !st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                }
            return st.nextToken();
        }

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

    }
}



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

int main(){
    ll N;
    cin >> N;
    ll sum=0;
    rep(i, N){
        if(((i + 1) % 3 != 0) && ((i + 1) % 5 != 0)){
            sum += i + 1;
        }
    }
    cout << sum << endl;
    return 0;
}

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

int main() {
    int K,S;
    cin >> K >> S;
    
    int ans = 0;

    for(int i = 0; i <= K; i ++){
        for(int j = 0; j <= K; j ++){
            if(i + j <= S && i + j + K >= S){
                ans ++;
            }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define max(l,r) ((l)>(r)?l:r)
#define min(l,r) ((l)<(r)?l:r)
#define swap(l,r) {ll tp=l;l=r;r=tp;}
const ll MOD = 1000000007;

int main(){
    //input
    int n;
    scanf("%d", &n);

    //solve
    
    //output
    if(n >= 30) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 1660
#include <iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  long int min,max,sum=0,x;
  bool f=true;
  
  for(int i=0; i<n; i++){
    cin>>x;
    sum+=x;
    
    //最初の1回だけ初期化
    if(f){
      min=x;
      max=x;
      f=false;
    }
    //2回目以降値の更新
    else{
      if(x<min){ min=x;}
      if(x>max){ max=x;}
    }

  }
    cout <<min<<" "<<max<<" "<<sum<<endl;
  return 0;
}



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

int n, c[500], s[500], f[500];

int main(){
    cin >> n;

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

    for(int i = 1; i <= n; i++){
        int t = 0;
        for(int j = i; j < n; j++){
            if(t < s[j]){
                t = s[j];
            }
            else{
                if(t % f[j] != 0){
                    t += f[j] - t%f[j];
                }
            }
            t += c[j];
        }
        printf("%d\n", t);
    }

    return 0;
}

Measured memory_bytes: 256
# Dinic's algorithm
from collections import deque
class Dinic:
    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def add_edge(self, fr, to, cap):
        forward = [to, cap, None]#(行き先、容量、逆辺の参照)
        forward[2] = backward = [fr, 0, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def add_multi_edge(self, v1, v2, cap1, cap2):
        edge1 = [v2, cap1, None]
        edge1[2] = edge2 = [v1, cap2, edge1]
        self.G[v1].append(edge1)
        self.G[v2].append(edge2)

    def bfs(self, s, t):
        self.level = level = [None]*self.N
        deq = deque([s])
        level[s] = 0
        G = self.G
        while deq:
            v = deq.popleft()
            lv = level[v] + 1
            for w, cap, _ in G[v]:
                if cap and level[w] is None:
                    level[w] = lv
                    deq.append(w)
        return level[t] is not None

    def dfs(self, v, t, f):
        if v == t:
            return f
        level = self.level
        for e in self.it[v]:
            w, cap, rev = e
            if cap and level[v] < level[w]:
                d = self.dfs(w, t, min(f, cap))
                if d:
                    e[1] -= d
                    rev[1] += d
                    return d
        return 0

    def flow(self, s, t):
        flow = 0
        INF = 10**10
        G = self.G
        while self.bfs(s, t):
            *self.it, = map(iter, self.G)
            f = INF
            while f:
                f = self.dfs(s, t, INF)
                flow += f
        return flow
inf = 10**9
H, W = map(int, input().split())
a = [list(input()) for _ in range(H)]
D = Dinic(H+W+2)
for i in range(H):
    for j in range(W):
        if a[i][j] == 'S':
            D.add_edge(0, i+1, inf)
            D.add_edge(0, j+1+H, inf)
        elif a[i][j] == 'T':
            D.add_edge(i+1, H+W+1, inf)
            D.add_edge(j+1+H, H+W+1, inf)
        elif a[i][j] == 'o':
            D.add_edge(i+1, j+1+H, 1)
            D.add_edge(j+1+H, i+1, 1)
ans = D.flow(0, H+W+1)
print(ans if ans<inf else -1)







Measured memory_bytes: 48604
#include <stdio.h>
int main(void){
  int A, B,C,num_1,num_2,num_3,D;
  int result;
  scanf("%d%d%d", &A,&B,&C);
  num_1 =A;
  num_2 =B;
  num_3 =C;


  if (num_1 < num_2){
    num_1 = B;
    num_2 =A;
  }

  if (num_1 < num_3){
    num_1 =C;
    num_3 =A;
  }

  if (num_2 < num_3){
  D = num_2 ;
    num_2 =num_3;
    num_3 =D;
  }

  result = num_1*10 + num_3 +num_2;

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

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define MAXN (int)(2*1e5 + 1)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define MOD2 (lli) 998244353  
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};

int n;
vector<int> Ai, Bi, Ci;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    Ai.push_back(a);
  }

  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    Bi.push_back(a);
  }

  for(int i=0;i<n-1;i++){
    int a;
    cin >> a;
    Ci.push_back(a);
  }

  int last = -1;
  int ans = 0;
  for(auto i : Ai){
    if(last == -1){
      ans += (Bi[i-1]);
    } else {
      if(i == last + 1){
        ans += (Bi[i-1]);
        ans += (Ci[last-1]);
      } else {
        ans += (Bi[i-1]);
      }
    }
      last = i;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256