akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "random"
#include "string"
#include "bitset"
#include "algorithm"
#include "map"
#include "queue"
#include "list"
#include "set"
#include "climits"
#include "iomanip"

using namespace std;
using ll = long long int;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S = "AIZUNYAN";
	string T = "AIDUNYAN";
	sort(T.begin(), T.end());
	string D;
	cin >> D;
	int pos = 0;
	while (pos + 8 <= D.size()) {
		string s = D.substr(pos, 8);
		sort(s.begin(), s.end());
		if (s == T) {
			for (int i = 0; i < 8; i++) D[pos + i] = S[i];
			pos += 8;
		}
		else {
			pos++;
		}
	}
	cout << D << endl;
}


Measured memory_bytes: 3240
S = str(input())
s = list(S)

if s[0] == s[1] == s[2] == s[3]:
    print("No")
elif s[0] == s[1] and s[2] == s[3]:
        print("Yes")
elif s[0] == s[2] and s[1] == s[3]:
        print("Yes")
elif s[0] == s[3] and s[1] == s[2]:
        print("Yes")
else:
        print("No")


Measured memory_bytes: 3064
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    S=list(input())
    S[5]=" "
    S[13]=" "
    print(''.join(map(str, S)))
    
main()


Measured memory_bytes: 38384
#include <math.h>
#include <utility>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main(){

	int n,w;

	for ( int num = 1;; num++ ) {

		cin >> w;
		if ( w == 0 ) break;
		cin >> n;

		int input1,input2;
		char input3;
		vector<int> value;
		vector<int> weight;
		for ( int i = 0; i < n; i++ ) {
			cin >> input1 >> input3 >> input2;
			value.push_back(input1);
			weight.push_back(input2);
		}

		vector<int> check;
		check.push_back(0);
		for ( int i = 0; i < w; i++ ) {
			check.push_back(-1);
		}
		int value_sum = 0;
		int weight_sum = w+1;

		for ( int i = 0; i < n; i++ ) {
			for ( int j = w - weight[i]; j >= 0; j-- ) {
				if ( check[j] != -1 ) {
					check[ j+weight[i] ] = max( check[ j+weight[i] ], check[j] + value[i] );
					if ( check[ j+weight[i] ] > value_sum ) {
						value_sum = check[ j+weight[i] ];
						weight_sum = j+weight[i];
					}else if ( check[ j+weight[i] ] == value_sum ) {
						weight_sum = min( weight_sum, j+weight[i] );
					}
				}
			}
		}
		cout << "Case " << num << ":" << endl << value_sum << endl << weight_sum << endl;
	}
	return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, X, M;
    cin >> N >> X >> M;

    map<ll ,ll> T;

    vector<ll> A;

    ll ans = 0;
    ll now;
    ll d = 0;
    ll count = 0;
    ll loop = 0;
    ll start = 0;
    ll end = 0;
    bool check = false;
    for(ll i=1; i<=min(N, M); i++){
        // cout << i << endl;
        if(check == true && count == d) break;
        if(i==1){
            now = X;
            ans += X;
            T[now] = i;
            continue;
        }
        now = (now*now) % M;

        // nowがすでに存在しているなら
        if(check == false && (T[now] > 0)){
            // cout << "end" << endl;
            check = true;
            start = T[now];
            end = i;
            d = i - T[now] - 1;
            A.resize(d);
            continue;
        }
        T[now] = i;

        if(check){
            if(count == 0){
                A[count] = now;
            }
            else{
                A[count] = A[count-1] + now;
            }
            count++;
        }
    }

    ans = 0;
    if(check == false){
        for(ll i=1; i<=min(N, M); i++){
            if(i==1){
                now = X;
                ans += now;
            }
            else{
                now = (now*now) % M;
                ans += now;
            }
        }
        cout << ans << endl;
        return 0;
    }

    // cout << start << " " << end << endl;
    ll dis = end-start;

    vector<ll> B(end+1, 0);

    ans = 0;
    for(ll i=1; i<=end; i++){
        if(i==1){
            now = X;
            ans += now;
            B[i] = X;
        }
        else{
            now = (now*now) % M;
            ans += now;
            B[i] = B[i-1] + now;
        }
    }
    ans += ((N-end)/dis) * (B[end] -B[start]);

    if((N-end) % dis != 0){
        ll c = (N-end) % dis;
        ans += B[start+c] - B[start];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7216
import java.util.*;
import java.awt.*;

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

        int h = sc.nextInt();
        int w = sc.nextInt();
        int k = sc.nextInt();
        long e = 1000000007;

        long[][] dp = new long[h+1][w];
        dp[0][0] = 1;

        for (int i = 1; i <= h; i++) {
            for (int j = 0; j < w; j++) {
                dp[i][j] += (dp[i-1][j] * tmp(w-j-2) * tmp(j-1)) % e;
                if (j-1 >= 0) {
                    dp[i][j] += (dp[i-1][j-1] * tmp(w-j-2) * tmp(j-2)) % e;
                }
                if (j+1 < w) {
                    dp[i][j] += (dp[i-1][j+1] * tmp(w-j-3) * tmp(j-1)) % e;
                }
                dp[i][j] %= e;
            }
        }

        System.out.println(dp[h][k-1]);
    }

    public static long tmp(int x) {
        long ret = 1;

        if (x == 1) {
            ret = 2;
        } else if (x == 2) {
            ret = 3;
        } else if (x == 3) {
            ret = 5;
        } else if (x == 4) {
            ret = 8;
        } else if (x == 5) {
            ret = 13;
        } else if (x == 6) {
            ret = 21;
        }

        return ret;
    }
}


Measured memory_bytes: 21844
#c 
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = [0] * M
B = [0] * M
for i in range(M):
    A[i], B[i] = map(int, input().split())
a=[1]*N
for x in range(M):
    if H[A[x]-1]>H[B[x]-1]:
        a[A[x]-1]*=1
        a[B[x]-1]*=0
    elif H[A[x]-1]==H[B[x]-1]:
        a[A[x]-1]*=0
        a[B[x]-1]*=0
    else:
        a[A[x]-1]*=0
        a[B[x]-1]*=1
sum=0
for y in a:
    sum+=y
print(sum)

Measured memory_bytes: 84880
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[10][10];
    for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cin>>s[i][j];
}cout<<endl;}
cout<<s[0][0]<<s[1][1]<<s[2][2]<<endl;
return 0;
}

Measured memory_bytes: 3628
#include <vector>
#include <cstdio>
using namespace std;
void D(int n,vector<int>*v,int*b){
	b[n]=1;
	for(int i=0;i<v[n].size();i++)if(!b[v[n][i]])D(v[n][i],v,b);
}
main(){
	int m,n,i,j,next,d[259];
	for(;scanf("%d%d",&m,&n)>1;puts(i<=n+1?"NG":"OK")){
		d[0]=d[n+1]=0;
		for(i=1;i<=n;i++)scanf("%d",d+i);
		vector<int>vf[259],vr[259];
		for(i=0;i<=n;i++)for(j=1;j<=m;j++){
			next=i+j;
			if(next>n+1)next=n+1;
			next+=d[next];
			if(next>n+1)next=n+1;
			if(next<0)next=0;
			vf[i].push_back(next),vr[next].push_back(i);
		}
		int bf[259]={0},br[259]={0};
		D(0,vf,bf),D(n+1,vr,br);
		for(i=0;i<=n+1;i++)if(bf[i]&&!br[i])break;
	}
}

Measured memory_bytes: 1076
// LNU_Algotesters
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <fstream>
#include <complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 100 * 1000 + 47;


int A[MAX];
LL DP[MAX];


int main()
{
    
    //freopen("in.txt", "r", stdin);
    //ios::sync_with_stdio(false); cin.tie(0);
    
    int n, e, t;
    scanf("%d%d%d", &n, &e, &t);
    FOR(i, 0, n)
        scanf("%d", A + i);
    
    FOR(i, 0, n+1)DP[i] = INF;
    
    DP[0] = 0;
    multiset<LL> S, SS;
    SS.insert(0);
    int idx = 0;
    FOR(i, 0, n)
    {
        DP[i+1] = DP[i] + t;
        while(idx < i && 2 * (A[i] - A[idx]) > t)
        {
            SS.erase(SS.find(DP[idx]));
            S.insert(DP[idx] - 2 * A[idx]);
            idx++;
        }
        
        if (!SS.empty())
        {
            DP[i+1] = min(DP[i+1], *SS.begin() + t);
        }
        if (!S.empty())
        {
            DP[i+1] = min(DP[i+1], *S.begin() + 2 * A[i]);
        }
        
        SS.insert(DP[i+1]);
        
    }
    cout << e + DP[n] << endl;
}





Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
string a;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie();
	cout.tie();
	cin >> a;
	if(a[2]==a[3]&&a[4]==a[5]){
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
from itertools import permutations
def check(a,b):
    na=len(a)
    nb=len(b)
    rt=[0]*na
    for i in range(na):
        fl=True
        for j in range(min(na-i,nb)):
            if a[i+j]!=b[j] and a[i+j]!='?' and b[j]!='?':
                fl=False
                break
        if fl:
            rt[i]=1
    return rt+[1]

def tri_check(idx):
    id1,id2,id3=idx
    a,b,c=[strs[i] for i in idx]
    ab,bc,ac=chMat[id1][id2],chMat[id2][id3],chMat[id1][id3]
    na,nb,nc=map(len,(a,b,c))
    rt=na+nb+nc
    al,ar=na,nb
    for l in range(na+1):
        for r in range(l,na+nb+1):
            if ab[l]==1 and (nb<r-l or bc[r-l]==1) and ac[min(na,r)]==1:
                        alt=max(na,l+nb,r+nc)
                        if alt<rt:
                            rt=alt
    return rt
    
a=input()
b=input()
c=input()
na,nb,nc=map(len,(a,b,c))
ans=10**5
strs=[a,b,c]
chMat=[[check(strs[i],strs[j]) if i!=j else [] for j in range(3)]for i in range(3)]

for i in permutations(range(3)):
    x=tri_check(i)
    ans=min(ans,x)

print(ans)



Measured memory_bytes: 55152
n = int(input())
s0=list(str(n))
ans=0

if len(s0)==1:
    print(n)
    exit()

if len(s0)==2:
    for i in range(1,n+1):
        s1=list(str(i))
        if s1[-1]=='0':
            continue
        if s1[0]==s1[-1]:
            ans+=1
        if int(s1[-1])*10+int(s1[0])<=n:
            ans+=1
    print(ans)
    exit()

for i in range(1,n+1):
    s1=list(str(i))
    if s1[-1]=='0':
        continue
    if s1[0]==s1[-1]:
        ans+=1
    for j in range(2,len(s0)):#nより小さい桁数のものを足す
        ans+=10**(j-2)
    if int(s0[0])>int(s1[-1]):#nより入れ替えた数の最高位数が小さいとき、全て足す
        ans+=10**(len(s0)-2)
    elif s0[0]==s1[-1]:#nと入れ替えた数の最高位数が同じ時
        ans+=int(''.join(s0[1:len(s0)-1]))+1
        if int(s0[-1])<int(s1[0]):
            ans-=1
print(ans)


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

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

    int N;
    cin >> N;
    vector<int> H(N);
    rep(i, N) cin >> H[i];
    
    int minH = H[0];
    int res = 1;
    for (int i = 1; i < N; ++i) {
        if (H[i] >= minH) {
            ++res;
            minH = H[i];
        }
    }

    cout << res << "\n";
}

Measured memory_bytes: 256
N,L=[int(x) for x in input().split()]

Aji = [L+i-1 for i in range(1,N+1)]
EAT = abs(Aji[0])

for i in range(N):
    if abs(EAT) > abs(Aji[i]):
        EAT = Aji[i]
        
ans = sum(Aji) - EAT

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 1e5 + 10;
int N;
LL a[MAX];

int main(void) {
    cin >> N;
    REP(i, N) {
        cin >> a[i + 1];
    }
    sort(a, a + N + 1);
    int ans = 0;
    REP(i, N) {
        if ((a[i + 1] - a[i]) % 2) {
            ans ^= (N - i);
        }
    }
    DEBUG(ans)
    cout << (ans == 0 ? "second" : "first") << endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

signed main() {
    int h, w;
    cin >> h >> w;
    int sum;
    int odd = w / 2;
    int even = w / 2;
    if (h == 1 || w == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (w % 2)
        odd++;
    if (h % 2)
        sum = odd * (h / 2 + 1) + even * (h / 2);
    else
        sum = odd * (h / 2) + even * (h / 2);
    cout << sum << endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]

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

fn main() {
    input!{
        S: String,
    }
    let mut S = S;
    let mut flag = true;

    'outer: while flag {
        for match_lang in ["dream", "dreamer", "erase", "eraser"].iter() {
            if S.ends_with(match_lang) {
                for _ in 0..match_lang.len() {
                    S.pop();
                }
                continue 'outer;
            }
        }
        flag = false;
    }
    println!("{}", if S.is_empty() { "YES" } else { "NO" });
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <math.h>


double deg_rad( int angle){

	return angle * M_PI / 180;

}


int main(){

	int a, b, c;
	double side, h, c_rad;	

	scanf( "%d %d %d", &a, &b, &c );

	c_rad = deg_rad( c );
	h = b * sin( c_rad );
	side = sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(c_rad));

	printf( "%lf ", a*h/2 );
	printf( "%lf ", a+b+side );
	printf( "%lf\n", h );

	return 0;
}

Measured memory_bytes: 636
H, W = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
ch, cw, dh, dw = ch - 1, cw - 1, dh - 1, dw - 1
S = [input() for _ in range(H)]

from collections import deque

def is_valid(h, w):
    if 0 <= h < H and 0 <= w < W and S[h][w] == '.':
        return True
    else:
        return False

Dh = (1, 0, -1, 0)
Dw = (0, 1, 0, -1)

INF = float('inf')
dist = [[INF] * W for _ in range(H)]
dist[ch][cw] = 0
q = deque([(ch, cw)])

while q:
    ph, pw = q.popleft()
    for k in range(4):
        nh, nw = ph + Dh[k], pw + Dw[k]
        if is_valid(nh, nw):
            if dist[nh][nw] > dist[ph][pw]:
                dist[nh][nw] = dist[ph][pw]
                q.appendleft((nh, nw))
    for nh in range(ph - 2, ph + 3):
        for nw in range(pw - 2, pw + 3):
            if is_valid(nh, nw):
                if dist[nh][nw] > dist[ph][pw] + 1:
                   dist[nh][nw] = dist[ph][pw] + 1
                   q.append((nh, nw))

print(-1) if dist[dh][dw] == INF else print(dist[dh][dw])


Measured memory_bytes: 98548
#include <bits/stdc++.h>
using namespace std;
const int N = 550;
int n,m;
int a[N][N], used[N][N];
int S, T, tot, to[N * N * 2], nex[N * N * 2], final[N * 2], f[N * N * 2];
int e[N][N], ans[N][N];

void _link(int x, int y, int fl) {
	to[++tot] = y, nex[tot] = final[x], final[x] = tot;
	f[tot] = fl;
}

void link(int x, int y, int fl) {
	_link(x, y, fl), _link(y, x, 0);
}

int dis[N * 2];

void bfs() {
	for(int i = 1; i <= T; i++) dis[i] = -1;
	static int Q[N * 2]; int h = 0, t = 0;
	Q[++t] = S;
	dis[S] = 0;
	while(h < t) {
		int x = Q[++h];
		for(int i = final[x]; i; i = nex[i]) if(f[i]) {
			int y = to[i]; if (dis[y] == -1) {
				dis[y] = dis[x] + 1;
				Q[++t] = y;
			}
		}
	}
}

int go(int x,int flow) {
	if (x == T) return flow;
	int used = 0;
	for(int i = final[x]; i; i = nex[i]) if(f[i] && dis[x] + 1 == dis[to[i]]) {
		int y = to[i];
		int take = go(y, min(f[i], flow - used));
		used += take;
		f[i] -= take;
		f[i ^ 1] += take;
		if (used == flow) return used;
	}
	return used;
}

void work(int col) {
	tot = 1;
	memset(final, 0, sizeof final);
	S = n + n + 1, T = S + 1;
	for(int i = 1; i <= n; i++) {
		link(S, i, 1);
		for(int j = 1; j <= m; j++) if (!used[i][j]) {
			e[i][j] = tot + 1;
			link(i, n + 1 + (a[i][j] - 1) / m, 1);
		}
	}

	for(int i = 1; i <= n; i++) {
		link(n + i, T, 1);
	}

	while(bfs(), dis[T] != -1)
		go(S, 1e9);

	for(int i = 1; i <= n; i++) 
		for(int j = 1; j <= m; j++) if (!used[i][j]) {
			if (f[e[i][j]] == 0) {
				ans[i][col] = a[i][j];
				used[i][j] = 1;
				break;
			}
		}
}

int g[N];
int main() {
	//int gg = clock();
	//freopen("d.in","r",stdin);
	//freopen("d.out","w",stdout);
	cin>>n>>m;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) scanf("%d", &a[i][j]);//, a[i][j] = (i - 1) * m + j;
	}

	for(int i = 1; i <= m; i++) {
		//cerr<<i<<endl;
		work(i);
	}

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

	for(int i = 1; i <= m; i++) {
		for(int j = 1; j <= n; j++) g[j] = ans[j][i];
		sort(g + 1, g + 1 + n);
		for(int j = 1; j <= n; j++) ans[j][i] = g[j];
	}
	
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) printf("%d ",ans[i][j]);
		printf("\n");
	}
	//cerr<<clock()-gg<<endl;
}

Measured memory_bytes: 9344
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		sc.close();
		for(int i = 1; i <= 1000; i++) {
			if(A * i % B == C) {
				System.out.println("YES");
				System.exit(0);
			}
		}
		System.out.println("NO");
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    int n, m, s, t;
    double mn = INF, sum, mx;
    vector<int> g[666];
    double dp[666][666] = {};
    cin>>n>>m;
    rep(i, m){
        cin>>s>>t;
        s--, t--;
        g[s].push_back(t);
    }
    rep(i, n){
        dp[i][n - 1] = 0;
        rev(j, n - 1){
            sum = mx = 0.0;
            each(p, g[j]){
                sum += dp[i][p];
                chmax(mx, dp[i][p]);
            }
            dp[i][j] = sum / g[j].size() + 1;
            if(i == j && g[j].size() > 1){
                dp[i][j] = (sum - mx) / (g[j].size() - 1) + 1;
            }
        }
        chmin(mn, dp[i][0]);
    }
    cout<<mn;
}

Measured memory_bytes: 6016
#include <cstdio>
#include <cstring>

#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) REP(i, 0, n)
typedef unsigned long long ll;

#define INF (1<<20)
int mado[100][100], pic[4][50][50], offset[4];

int main()
{
	int n, m;
	while (scanf("%d%d", &n, &m), n) {
		rep(i, n) rep(j, n) scanf("%d", &mado[i][j]);
		rep(i, m) rep(j, m) scanf("%d", &pic[0][i][j]);

		rep(k, 3) rep(i, m) rep(j, m)
			pic[k+1][i][j] = pic[k][m-1-j][i];
		rep(k, 4) {
			offset[k] = 0;
			rep(j, m) { if (pic[k][0][j] > -1) break; offset[k]++; }
		}

		int resk, resx, resy;
		resk = resx = resy = INF;
		rep(k, 4) rep(i, n-m+1) rep(j, n-m+1) {
			bool ok = true;
			rep(x, m) rep(y, m) {
				if (pic[k][x][y] > -1 && (pic[k][x][y] ^ mado[i+x][j+y]) != 0) {
					ok = false;
					goto NEXT;
				}
			}
			if (resx > i || resx == i && resy > j) {
				resk = k;
				resx = i;
				resy = j + offset[k];
//{rep(i, m) { rep(j, m) printf("%2d ", pic[resk][i][j]);puts(""); }}
			}
NEXT:;
		}
		if (resx == INF) {
			puts("NA");
		}
		else {
			printf("%d %d\n", resy+1, resx+1);
		}
	}
	return 0;
}

Measured memory_bytes: 848
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, K = MAP()
P = LIST()
C = LIST()

check = [0]*N 
score = []

for i in range(N):
	if check[i]:
		continue

	tmp = []
	while check[i] == 0:
		check[i] = 1
		i = P[i]-1
		tmp.append(C[i])
	score.append(tmp)

ans = -INF
for x in score:
	x_acc = list(accumulate([0] + x + x))
	n = len(x)
	tmp_max = -INF

	for i, j in combinations(range(2*n+1), 2):
		if j-i <= min(K, n):
			if tmp_max < x_acc[j]-x_acc[i]:
				tmp_max = x_acc[j]-x_acc[i]
				cnt = j-i
	tmp_ans = -INF

	if 0 >= x_acc[n]:
		tmp_ans = tmp_max

	else:
		if cnt <= K%n:
			tmp_ans = x_acc[n]*(K//n) + tmp_max
		else:
			tmp_max2 = 0
			for i, j in combinations(range(2*n+1), 2):
				if j-i <= K%n:
					if tmp_max2 < x_acc[j]-x_acc[i]:
						tmp_max2 = x_acc[j]-x_acc[i]
			tmp_ans = max(x_acc[n]*(K//n-1)+tmp_max, x_acc[n]*(K//n) + tmp_max2)

	ans = max(ans, tmp_ans)

print(ans)


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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    bool flag=false;
    for(int i=0;i<=b;i++){
        if((a*i)%b==c)flag=true;
    }
    if(flag)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

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

int main() {
    using namespace std;
    constexpr unsigned long MOD = 998244353;
    unsigned long N;
    cin >> N;
    
    vector<pair<long, long>> robots;
    for(long x, d; cin >> x >> d; )robots.emplace_back(x, x + d);
    sort(robots.begin(), robots.end(), greater<>());
    
    vector<pair<long, unsigned long>> v;
    for(const auto& i : robots){
        unsigned long r{1};
        while(!v.empty() && v.back().first < i.second && ((r *= v.back().second) %= MOD))v.pop_back();
        v.emplace_back(i.first, r + 1);
    }
    cout << accumulate(v.begin(), v.end(), 1UL, [](auto i, auto j){return i * j.second % MOD;}) << endl;
    
    return 0;
}

Measured memory_bytes: 7020
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>

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

#define MAX_N   52
#define INF     1E8

using namespace std;

int alph[MAX_N][26] = { 0 };      // Si でアルファベット j がどれだけ使われているか
int n;
vector<char> ans;

int main()
{
    cin >> n;
    REP(i, n) {
        string str;
        cin >> str;
        REP(j, str.length()) {
            alph[i][str[j] - 'a']++;
        }
    }
    REP(i, 26) {
        int use = INF;
        REP(j, n) {
            use = min(use, alph[j][i]);
        }
        REP(j, use) {
            ans.push_back('a' + static_cast<char>(i));
        }
    }
    sort(ans.begin(), ans.end());
    REP(i, ans.size()) {
        printf("%c", ans[i]);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P ,ll> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9)+7;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()


int main() {
    int a, b;
    cin >> a >> b;
    if(a >= 13){
        cout << b << endl;
    }
    else if (a >= 6){
        cout << b/2 << endl;
    }
    else{
        cout << 0 << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////
int a[100005];
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  ll t=1;
  while(t--)
  {
    int n;
    cin>>n;
    int x;
    REP(i,n)
    {
        cin>>x;
        a[x]++;a[x-1]++;a[x+1]++;
    }
    cout<<*max_element(a,a+100005);
  }  
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
#define BOOST        std::ios::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define sp           <<" "<<
#define ll           long long
#define ld           long double
#define AZI(i,x)     for(auto i=x.begin();i!=x.end();i++)
#define AZ(x)        x.begin(),x.end()
#define P(x,y)       pair < x,y >
#define V(x)         vector < x >
#define fi           first
#define se           second
#define pb           push_back
#define mp           make_pair
#define PI           3.14159265358979323846264338327950288419716939937510
 
const ll mod=1e9+7,N=1e5+5,INF = 1e18;

ll n,W;
ld p[3005];
ld dp[3005]={}; // probability of i heads so far
int main() 
{ 
    BOOST

    cin >> n;

    for(int i=1;i<=n;i++)
        cin>>p[i];

    dp[0] = 1;

    for(int i=1;i<=n;i++)
    {
        for(int j=i;j>=0;j--)
        {
            dp[j]=dp[j]*(1-p[i]);
            if(j)
                dp[j]+=dp[j-1]*p[i]; 
        }
    }

    ld ans=0;
    
    for(int i=(n+1)/2;i<=n;i++)
    {
        ans+=dp[i];
    }

    cout << fixed << setprecision(10) << ans << endl;
    return 0; 
} 

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

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i, m, n) for(int i = (int)m; i < (int)n; i++)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;


/*FUNCs=================================================*/


/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    long double w, h, x, y; cin >> w >> h >> x >> y;

    cout << w*h/2;
    cout << " " <<(x*2 == w && y*2 == h ? 1 : 0) << '\n';
}

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

int main(){
	int n, a, b, c, d, minx;
	long long ans;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	scanf("%d",&n);
	minx = min(8 * a, 4 * b);
	minx = min(minx, 2 * c);
	minx = min(minx, d);
	ans = 1LL * n / 2 * minx;
	if (n & 1){
		minx = min(4 * a, 2 * b);
		minx = min(minx, c);
		ans += minx;
	}
	printf("%lld\n", ans);
	return 0;
}

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

int N, M, a, b, ret; vector<int> G[11];
void solve(int pos, int bit) {
    if (bit == (1 << N) - 1) {
        ret++;
        return;
    }
    for (int i : G[pos]) {
        if (!(bit & (1 << i))) {
            solve(i, bit + (1 << i));
        }
    }
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    solve(0, 1);
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
si = sys.stdin.readline


def main():
    l = [int(e) for e in si().split()]
    pn = set()
    if l[1] != 0:
        pn = set(int(e) for e in si().split())

    d = 0
    x = l[0]
    if x not in pn:
        print(x)
    else:
        while True:
            d += 1
            if x-d not in pn:
                print(x-d)
                break
            if x+d not in pn:
                print(x+d)
                break


if __name__ == '__main__':
    main()


Measured memory_bytes: 9404
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class APluralForm {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            String s = in.nextLine();

            if (s.endsWith("s")) {
                s = s.concat("es");

            } else {
                s = s.concat("s");
            }

            out.println(s);
        }

    }

    static class FastReader {
        BufferedReader br;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}



Measured memory_bytes: 25580
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> p;
int K,X,Y,i,j,n,x,y;
bool xf,yf,xyswap;
vector<p> def;
void pushdef(int x,int y) {
    if(xyswap)swap(x,y);
    def.push_back(p(xf?-x:x,yf?-y:y));
}
main(){
    cin>>K>>X>>Y;
    if(X<0)xf=1,X=-X;
    if(Y<0)yf=1,Y=-Y;
    if(X>Y)xyswap=true,swap(X,Y);
    if(X+Y&~K&1){cout<<-1;exit(0);}
    if(X+Y<K&&X+Y&1){
        pushdef(X,-K+X);
        pushdef((K+X-Y)/2,K-(K+X-Y)/2);
        pushdef(-(K+X-Y)/2,K-(K+X-Y)/2);
    }else{
        int U=X+Y,V=-X+Y-K;
        U-=U%K;
        if(X+Y<K||K&1&&((X+Y)/K&1)==(X+Y&1))U+=K;
        int a=(U-V)/2,b=(U+V)/2;
        if((X+Y)%K!=0)pushdef(X-a,Y-b),X=a,Y=b;
        for(;i<X/K;i++)pushdef(K,0);
        for(;j<Y/K;j++)pushdef(0,K);
        if(X%K!=0)pushdef(X%K,Y%K);
    }
    cout<<def.size()<<" ";
    for(n=0;n<def.size();n++)x+=def[n].first,y+=def[n].second,cout<<x<<" "<<y<<" ";
}


Measured memory_bytes: 3952
#!/usr/bin/env python3
#エイシングプログラミングコンテスト2019 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


dx,dy = [1,0,-1,0],[0,1,0,-1]
h,w = LI()
s = [input() for _ in range(h)]
que = deque()
ch = [[-1]*w for _ in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            if ch[i][j] < 0:
                ch[i][j] = 0
                que = deque()
                que.append((i,j))
                #a:= ルールを守りながら行ける#の数
                #b:= ルールを守りながら行ける.の数
                a,b = 1,0
                while que:
                    y,x = que.popleft()
                    for k in range(4):
                        nx,ny = x + dx[k], y + dy[k]
                        if 0 <= nx < w and 0 <= ny < h and ch[ny][nx] < 0:
                            if s[y][x] != s[ny][nx]:
                                if s[ny][nx] == '#':
                                    a += 1
                                else:
                                    b += 1
                                ch[ny][nx] = 0
                                que.append((ny,nx))
                ans += a*b
print(ans)


Measured memory_bytes: 49500
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007


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

 vector<double> v(N);
 for(int i = 0;i < N;i++) {
   cin >> v.at(i);
 }

 while(v.size() != 1) {
   sort(v.begin(),v.end());
   auto beg = v.begin();
   double a = *beg;
   v.erase(beg);
   double b = *beg;
   v.erase(beg);
   v.push_back((a+b)/2);
 }

 cout << setprecision(15) << v.at(0) << endl;

}


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

using namespace std;

const int N = 1e5 + 5;
int n;
int arr[N] , c[N] , cc[N];
int main() {
    scanf("%d" , &n);
    for (int i = 0 ;i < n ;i++)
        scanf("%d" , arr + i);

    c[0] = arr[0];
    cc[n - 1] = arr[n - 1];
    for (int i = 1 , j = n - 2 ;i < n ;i++ , j--) {
        c[i] = __gcd(c[i - 1] , arr[i]);
        cc[j] = __gcd(cc[j + 1] , arr[j]);
    }

    int mx = 0;
    for (int i = 0 ;i < n ;i++) {
        int all = 0;
        if (i > 0)
            all = c[i - 1];
        if (i < n - 1)
            all = __gcd(all , cc[i + 1]);
        mx = max(mx , all);
    }
    printf("%d" , mx);
}

Measured memory_bytes: 1408
# -*- coding: utf-8 -*-

K = int(input())
N = 50
q = K // N
r = K % N

a = [49 + q] * N

for i in range(N):
    if i < r:
        a[i] += N - r + 1
    else:
        a[i] -= r

print(N)
for i in range(N):
    print(a[i], end=' ')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  while(1){
    string a,b;
    int hit=0,brow=0;
    cin>>a>>b;
    if(a == "0" && b == "0"){
      break;
    }
    
    for(int i=0;i<4;i++){
      for(int j=0;j<4;j++){
	if(a[i] == b[j]){
	  if(i == j){
	    hit++;
	  }else{
	    brow++;
	  }
	  break;
	}
      }
    }
    cout<<hit<<" "<<brow<<endl;
  }
}

Measured memory_bytes: 1188
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt();
        final String s = scanner.nextLine();
        final char[] chars = s.toCharArray();

        final int[][] table = new int[n][n];

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (chars[i] == chars[j]) {
                    if (i == 0) {
                        table[i][j] = 1;
                        continue;
                    }

                    final int length = table[i - 1][j - 1];
                    table[i][j] = j - i == length ? length : length + 1;
                }
            }
        }

        int answer = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                answer = Math.max(answer, table[i][j]);
            }
        }

        System.out.println(answer);
    }

    static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

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

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

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

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

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


Measured memory_bytes: 167600
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>
#include <cmath>

#define MOD 1000000007

using namespace std;

typedef long long ll;

typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vl> vvl;
typedef vector<vi> vvi;

typedef pair<ll, ll> pll;
typedef pair<int, int> pi;

typedef vector<pll> vpl;
typedef vector<pi> vpi;

typedef queue<ll> ql;
typedef queue<int> qi;

template <class T>
void printv(vector<T> vc) {
    for (auto e: vc) cout << e << " ";
    cout << endl;
}

template <class T>
void printvv(vector<T> vvc) { 
    for (auto vc: vvc) {
        for (auto e: vc) cout << e << " ";
        cout << endl;
    }
}

template <class T>
void printvp(vector<pair<T, T> > vp) {
    for (auto pT: vp) cout << pT.first << " " << pT.second << endl;
}

int main() {
    int n, k; cin >> n >> k;
    vi h(n);
    for (int i = 0; i < n; ++i) cin>> h[i];

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

    int ans = INT_MAX;
    int size = h.size();
    k -= 1;
    for (int i = 0; i < size; ++i) {
        if (i + k >= size) break;
        ans = min(ans, max(h[i], h[i+k]) - min(h[i], h[i+k]));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>


using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)

int main() {
	int h , a;
	cin >> h >> a;
	cout << (h + a - 1)  / a << endl;

	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x

template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}

signed main() {
    int h, n;
    cin >> h >> n;

    int dp[20001];
    rep(i, 20001) { dp[i] = INT_MAX; }
    dp[0] = 0;
    vector<pair<int, int>> v;
    int max = 0;
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        chmax(max, a);
        v.push_back(make_pair(a, b));
    }

    rep(i, h + max) {
        for (auto p: v) {
            if (i + p.first <= 20000) {
                chmin(dp[i + p.first], dp[i] + p.second);
            }
        }
    }

    int ans = INT_MAX;
    rep(j, max + 1) {
        chmin(ans, dp[j + h]);
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 3344
from collections import deque

n, q = map(int, input().split())
deq = deque()
for i in range(n):
    name, time = input().split();
    time = int(time)
    deq.append((time, name))
ans = []
cur = 0
while deq:
    time, name = deq.popleft()
    if time <= q:
        cur += time
        ans.append("%s %d" % (name, cur))
    else:
        cur += q
        deq.append((time - q, name))
print(*ans, sep="\n")



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

typedef long long ll;

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define AA(i) cout << i << endl;
#define AS(i) cout << i << " ";

const int INF = 1001001001;

const double PI = 3.14159;

using namespace std;

//vector<ll> memo(1000007, INF);

int main() {

    int a, b;
    cin >> a >> b;

    string aa = "", bb = "";

    rep(i, b) {
        aa += to_string(a);
    }

    rep(j, a) {
        bb += to_string(b);
    }

    string so[2] = {aa, bb};
    sort(so, so+2);

    AA(so[0]);
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout(val) cout << std::fixed << std::setprecision(20) << val;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
static const double pi = 3.141592653589793;
// if(nextH >= 0 && nextH < H && nextW >= 0 && nextW < W)

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

  int N; cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; ++i) cin >> A[i];
  sort(A.begin(), A.end(), greater<long long>());

  if (N % 2 == 0) {
      long long res = 0;
      for (int i = 0; i < N/2 - 1; ++i) res += A[i] * 2;
      res += A[N/2 - 1];
      res -= A[N/2];
      for (int i = N/2 + 1; i < N; ++i) res -= A[i] * 2;
      cout << res << endl;
  }
  else {
      long long res1 = 0;
      for (int i = 0; i < N/2 - 1; ++i) res1 += A[i] * 2;
      res1 += A[N/2 - 1] + A[N/2];
      for (int i = N/2 + 1; i < N; ++i) res1 -= A[i] * 2;

      long long res2 = 0;
      for (int i = 0; i < N/2; ++i) res2 += A[i] * 2;
      res2 -= A[N/2] + A[N/2 + 1];
      for (int i = N/2 + 2; i < N; ++i) res2 -= A[i] * 2;
      cout << max(res1, res2) << endl;
  }
}


Measured memory_bytes: 1024
n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
MOD = 10 ** 9 + 7
X = 0
Y = 0
for i in range(n - 1):
  t = x[i + 1] - x[i]
  X = (X + (i + 1) * (n - i - 1) * t) % MOD
for i in range(m - 1):
  t = y[i + 1] - y[i]
  Y = (Y + (i + 1) * (m - i - 1) * t) % MOD
print(X * Y % MOD)

Measured memory_bytes: 18624