akhauriyash/Code-Regression huggingface dataset:
using System.Linq;
using System.Collections.Generic;
using System;

public class S : IComparable
{
    public int from { get; set; }
    public int to { get; set; }
    public int id { get; set; }
    public int CompareTo(object obj)
    {
        var x = (S)obj;
        if (this.from > x.from) return 1;
        else if (this.from == x.from) return 0;
        else return -1;
    }
}

public class Hello
{
    public static void Main()
    {
        var first = true;  
        while (true)
        {
            if (first) first = false;
            else Console.WriteLine();
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var ss = new List<S>();
            ss.Add(new S { from = 0, to = 1000000000 ,id = -1});
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                var cmd = line[0];
                if (cmd == "W")
                {
                    var id = int.Parse(line[1]);
                    var a = int.Parse(line[2]);
                    cmdW(ss, id, a);
                }
                else if (cmd == "D")
                {
                    var id = int.Parse(line[1]);
                    cmdD(ss, id);
                }
                else
                {
                    var p = int.Parse(line[1]);
                    Console.WriteLine(cmdR(ss,p ));
                }
            }
        }
    }
    public static int cmdR (List<S> ss, int p )
    {
        var a = ss.Where(x => x.from <= p && x.to >= p).First();
        return a.id;
    }
    public static void cmdD (List<S> ss, int id)
    {
        foreach (var x in ss.Where(y => y.id == id))
            x.id = -1;
    }
    public static void cmdW (List<S> ss , int id , int a)
    {
        var w = new S();
        var write = false;
        foreach (var x in ss.Where(y =>y.id == -1))
        {
            if (x.to - x.from + 1 > a)
            {
                w.to = x.to;
                x.to = x.from + a - 1;
                w.id = x.id;
                x.id = id;
                w.from = x.to + 1;
                write = true;
                break;
            }
            else if (x.to - x.from + 1 == a) { x.id = id; break; }
            else { x.id = id; a -= x.to - x.from + 1; }
        }
        if (write) { ss.Add(w); ss.Sort(); }
    }
}




Measured memory_bytes: 9968
import fractions
N,X = map(int,input().split())

x = list(map(int,input().split()))
st = []
x.append(X)

x.sort()

gcd = 0

for i in range(N):
    if i == 0:
        gcd = x[i+1]-x[i]
    else:
        gcd = fractions.gcd(gcd,x[i+1]-x[i])
    st.append(x[i+1]-x[i])
print(gcd)



Measured memory_bytes: 16240
#!/usr/bin/python3
import math

def so(x):
    if x % 2 == 0:
        return False
    max = int(math.sqrt(x))
    for i in range(3, max + 1, 2):
        if x % i == 0:
            return False
    return True

n = int(input())

finds = []
i = 2
while len(finds) < n:
    x = 5 * i - 1
    if so(x):
        finds.append(x)
    i += 1

print(*finds)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
//declaring
int A,B;
//input
cin>>A>>B;
//process
if (A>=1 && A<=13){
if (B>=1 && B<=13){
if (A==B){
  cout <<"Draw";
}else if (A==1){
  cout<<"Alice";
}else if (B==1){
  cout<<"Bob";
}else if (A>B){
  cout<<"Alice";
}else{
  cout <<"Bob";
}



}





}









}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
    char s[2*100000];
    scanf("%s\n", s);
    size_t len = strlen(s);
    
    size_t count = 0;
    for (size_t i = 0; i < len; i++) {
        char c;
        scanf("%c", &c);
        if (c != s[i]) {
            count++;
        }
    }
    
    printf("%zu\n", count);
    
    return 0;
}

Measured memory_bytes: 1908
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
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; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
const ll INF = 1e18;
template <typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, y; cin >> n >> y;
    REP(i, n+1)REP(j, n+1){
        ll k = n - i - j;
        if(k < 0) continue;
        if(10000 * i + 5000 * j + 1000 * k == y){
            cout << i << " " << j << " " << k << endl;
            return 0;
        }
    }
    cout << -1 << " "<< -1 << " " << -1 << endl;
}

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

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void __print(vector<bool> x){cerr<<"{";int f=x.size();for(auto i:x){cerr<<i;(--f !=0)?cerr<<",":cerr<<"";}cerr<<"}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
//void __print(vector<bool> x) {int f = 0; cerr << '{'; for (auto i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
//void _print() {cerr << "]\n";}

#ifndef ONLINE_JUDGE
#define ANTHRO(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define ANTHRO(x...)
#endif

template<typename... T>
void read(T&... args) {
	((cin >> args), ...);
}

template<typename... T>
void writ(T&&... args) {
	((cout << args << " "), ...);
}
#define ll long long
#define MOD 1000000007
#define INF (ll)1e18
#define EPS 1e-9
/*
	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    No, nothing good starts in a getaway car
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n; cin>>n;
    set<string> s;
    for(ll i=0;i<n;i++){
		string st; cin>>st;
		s.insert(st);
	}
	cout<<s.size();
    return 0;
}


Measured memory_bytes: 19240
#include<stdio.h>
#include <string.h>
int isPrime(int x){
	int i;
	if(x<2) return 0;
	else if(x==2) return 1;
	if(x%2==0) return 0;
	for(i=3;i*i<=x;i+=2){
		if(x%i==0) return 0;
	}
	return 1;
}
int p,cnt,cnt2,food;
int n,d=0,g,kakaku[31],flag,youso[1000001]={0};
int main()
{
	scanf("%d %d",&n,&p);
	while(1){
		//memset(youso, 0, sizeof(youso));
		
		if(n==0&&p==0){
			break;
		}
		for(cnt=1;cnt<=n;cnt++){
			scanf("%d",&food);
			youso[food]=1;
			kakaku[cnt]=food;
		}
		for(cnt=0;cnt<=p;cnt++){
			if(youso[cnt]==1){
				for(cnt2=1;cnt2<=n;cnt2++){
					if(cnt+kakaku[cnt2]<=p){
						youso[cnt+kakaku[cnt2]]=1;
					}
				}
			}
		}
		flag=0;
		for(cnt=p;cnt>=0;cnt--){
			if(youso[cnt]==1){
				g=cnt;
				d=isPrime(g);
				if(d==1){
					flag=1;
					d=cnt;
					printf("%d\n",d);
					break;
				}
			}
		}
		if(flag==0){
			printf("NA\n");
		}
		d=0;
		flag=0;
		for(int i=0;i<1000001;i++){
			youso[i]=0;
		}
		scanf("%d %d",&n,&p);
	}
	return 0;
}

Measured memory_bytes: 6516
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <numeric>
#include <mutex>
#include <cmath>
#include <set>
#include <climits>
#include <math.h>
#define lli long long int
#define ll long long
#define mod 1000000007
#define pii pair<int,int>
#define mp make_pair

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

int main(){
    ll N, K, S;
    cin >> N >> K >> S;
    ll a = 0;
    ll X = S+1;
    if(S == 1e9){
       rep(i, N){
        	if(a == K) {
            	cout << 1 << " ";
            	continue;
        	}
        	a++;
        	cout << S << " ";
    	}
    } 
    else{ 
    	rep(i, N){
        	if(a == K) {
            	cout << X << " ";
            	continue;
        	}
        	a++;
        	cout << S << " ";
    	}
    }
    return 0;
}

Measured memory_bytes: 1280
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define erep(i,n) for (int i = 0; i <= (n); ++i)
#define brep(i,n) for (int i = n; i >= 0; i--)
#define PI 3.14159265359
using namespace std;
using P = pair<int,int>;
using ll = long long;
using Graph = vector<vector<int> > ;
const int INF = 100005;
const int MAX_K = 55;
const int MAX_W = 200005; 
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// ユークリッド互除法
unsigned gcd(unsigned a, unsigned b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

/*
int main() {
    // 前処理
    COMinit();

    // 計算例
    cout << COM(100000, 50000) << endl;
}
*/

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  ll r,g,b;
  r = g = b = 0;
  rep(i,n){
    if(s[i]=='R') r++;
    else if(s[i] == 'G' ) g++;
    else if(s[i] == 'B') b++;
  }
  ll ans = r * g * b;
  ll out = 0;
  rep(i,n-2){
    for(int j = i+1; j < n-1; j++){
      int k = 2*j-i;
      if(k >= n) continue;
      if(s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) out++;
    }
  }

  ans = ans - out;

  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int N;
	double loc;

	double maximum = -1,x,h;

	scanf("%d %lf",&N,&loc);

	for(int loop = 0; loop < N; loop++){
		scanf("%lf %lf",&x,&h);
		maximum = max(maximum,h/x);
	}

	printf("%.10lf\n",maximum*loc);

	return 0;
}

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

int main()
{
	string s;
	cin >> s;
	if (s[0] == s[1] && s[1] == s[2]) {
		puts("Yes");
	}
	else if (s[1] == s[2] && s[2] == s[3]) {
		puts("Yes");
	}
	else {
		puts("No");
	}
	return 0;
}


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

class Main {
    public static void main(String[] args) {

        String[] indexToAlphabet = {"A", "B", "C"};
        Map<String, Integer> alphabetToIndex = new HashMap<>();
        for(int cur = 0; cur < indexToAlphabet.length; cur++){
            alphabetToIndex.put(indexToAlphabet[cur], cur);
        }

        Integer[] cup = {1, 0, 0};
        List<String[]> splitStringList = readStdInput(",");

        for(String[] stringLine : splitStringList){
            swap(cup, alphabetToIndex.get(stringLine[0]).intValue(), alphabetToIndex.get(stringLine[1]).intValue());
        }

        for(int cur = 0; cur < cup.length; cur++){
            if(cup[cur] == 1){
                formatPrintln("%s", indexToAlphabet[cur]);
                break;
            }
        }
    }

    private static void formatPrint(String format, Object... args) {
        System.out.print(String.format(format, args));
    }

    private static void formatPrintln(String format, Object... args) {
        formatPrint(format, args);
        System.out.println();
    }

    private static List<String[]> readStdInput(String delim) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String buffer = null;

        List<String[]> splitStringList = new ArrayList<>();

        try {
            while ((buffer = br.readLine()) != null) {

                if(buffer.isEmpty()){
                    break;
                }
                splitStringList.add(buffer.split(delim));
            }
            br.close();
        } catch (IOException e) {
        }

        return splitStringList;
    }

    private static <T> void swap(T[] array, int leftIndex, int rightIndex){
        T temp = array[leftIndex];
        array[leftIndex] = array[rightIndex];
        array[rightIndex] = temp;
    }
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> cost(N+1);
    for(int i = 1 ; i <= N ;i++)
        cin >> cost[i];
    int INF = 1e6 + 5;
    vector<int>dp(N+1,INF);
    dp[1] = 0;

    for(int  i = 2 ; i <= N ; i++)
    {
        dp[i] = min (  dp[i-1]+abs(cost[i] - cost[i-1]) , dp[i-2]+abs(cost[i] - cost[i-2]));
    }

    cout << dp[N];
    return 0;


}

Measured memory_bytes: 3956
#include "bits/stdc++.h"

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "Yes"
#define NO  "No"

using namespace std;

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

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  flag = true;

  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  int k; cin >> k;
  sort(a.begin(), a.end());
  num = a[0] + a[1] + a[2] * pow(2, k);
  
  cout << num << endl;
  // cout << (flag ? YES : NO) << endl;
  
  return 0;
}


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

int n, m, temp, ans, a[305][305];

bool C(int ppl)
{
    bool choose[305]; //choose i-th sport
    memset(choose, true, sizeof(choose));

    while(true) {
        int cnt[305]; //count of i-th sport
        memset(cnt, 0, sizeof(cnt));
        bool used = true;

        for(int i=1; i<=n; i++) {
            int now = 1; //place of i-th sport that can be choose
            for(now=1; now<=m; now++) {
                if(choose[a[i][now]]) break;
            }
            if(now > m) return false;
            cnt[a[i][now]]++;
            if(cnt[a[i][now]] > ppl) {
                choose[a[i][now]] = false;
                used = false;
            }
        }
        if(used) return true;
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
            cin >> a[i][j];

    int lb=1, ub=n, mid=0;
    while(lb<=ub) {
        mid = (lb+ub)/2;
        if(C(mid)) {
            ans = mid;
            ub = mid-1;
        }
        else lb = mid+1;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
using System;

namespace abc143A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            if (A > B * 2 )
            {
                int C;
                C = A - B * 2;
                Console.WriteLine(C);
            }
            else
            {
                Console.WriteLine(0);
            }
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

ll gcd(ll x, ll y){
  return y ? gcd(y, x%y) : x;
}
ll lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
 
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm

void solve(){
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    --A;
    cout << B - (B / C + B / D - B / lcm(C, D)) - (A - (A / C + A / D - A / lcm(C, D))) << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
struct edge{
    ll p;//点
    ll w;//辺の重み*-1
};
vector<vector<edge> > graph(100000);
vector<ll> res(100000);
ll v,e,r;//vは頂点,eは辺,rは始点
void dijkstra(){
  for(int i = 0;i < v;i++)res[i] = pow(10,18);
    res[r] = 0;
    priority_queue<pair<ll,ll> > que;//重み、頂点
    que.push(make_pair(0,r));
    while(!que.empty()){
        edge now;
        now.p = que.top().second;
        now.w = que.top().first * -1;
        que.pop();
        if(res[now.p] < now.w)continue;
        for(int i = 0;i < graph[now.p].size();i++){
            if(res[graph[now.p][i].p] > now.w + graph[now.p][i].w){
                res[graph[now.p][i].p] = now.w + graph[now.p][i].w;
                que.push(make_pair(res[graph[now.p][i].p] * -1,graph[now.p][i].p));
            }
        }
    }
}
int main(){
  cin >> v >> e;
  for(int i = 0;i < e;i++){
    ll a,b;
    cin >> a >> b;
    a--,b--;
    ll c = 0;
    edge memoa = {b,c};
    edge memob = {a,c};
    graph[a].push_back(memoa);
    graph[b].push_back(memob);//無向グラフのときはこれを追加
  }
  ll ans = 0;
  for(int i = 0;i < v;i++){
    for(int j = 0;j < graph[i].size();j++){
      edge change = {graph[i][j].p,1};
      graph[i][j] = change;
      r = 0;
      dijkstra();
      bool bridge = false;
      for(int k = 0;k < v;k++){
        if(res[k] != 0)bridge = true;
      }
      //cout << "a" << endl;
      if(bridge)ans++;
      change = {graph[i][j].p,0};
      graph[i][j] = change;
    }
  }
  cout << ans << endl;
}



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

int main(){
  int N;
  cin>>N;
  if(N%10==2||N%10==4||N%10==5||N%10==7||N%10==9){
  cout<<"hon";
  }
  if(N%10==0||N%10==1||N%10==6||N%10==8){
  cout<<"pon";
  }
  if(N%10==3){
  cout<<"bon";
  }
}

Measured memory_bytes: 3588
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 1e9
int a[101];
int main()
{
    int n,i,mm,mn,j;
    while(scanf("%d",&n)!=EOF)
    {
            for(i=0;i<n;i++)
            scanf("%d",&a[i]);
        sort(a,a+n);
        mn=a[0];
        mm=a[n-1];
        int m,num=0;
        m=a[0];
        int cost=maxn;
        for(i=mn;i<=mm;i++)
        {
            int tot=0;
            for(j=0;j<n;j++)
            {
                tot+=(i-a[j])*(i-a[j]);
            }
            cost=min(cost,tot);
        }
        printf("%d\n",cost);
    }
}


Measured memory_bytes: 256
#include <iostream>

 

using namespace std;

 

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if (a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if (b <= a && a <= c)
        cout << b << " " << a << " " << c << endl;
    else if (c <= b && b <= a)
        cout << c << " " << b << " " << a << endl;
    else if (b <= c && c <= a)
        cout << b << " " << c << " " << a << endl;
    else
        cout << c << " " << a << " " << b << endl;
}


Measured memory_bytes: 3116
s=input()
t=input()
u=''
v=[]
count=0

for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if t[j]==s[i+j] or s[i+j]=='?':
            count+=1
    if count==len(t):
        for k in range(len(s)):
            if i<=k<=i+len(t)-1:
                u+=t[k-i]
            elif s[k]=='?':
                u+='a'
            else:
                u+=s[k]
                    
                    
        v.append(u)
        u=''
    count=0
if v==[]:
    print('UNRESTORABLE')
else:
    print(min(v))
                

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

int main()
{
    char c;
    cin.get(c);
    while (c != '\n')
    {
        if(c >= 'A' && c <= 'Z')
        {
            c += 'a'-'A';
        }
        else if (c >= 'a' && c <= 'z')
        {
            c += 'A' - 'a';
        }
        cout << c ;
        cin.get(c) ;
    }
    cout << endl ;
    return 0;
}



Measured memory_bytes: 3100
#include <iostream>

int main() {
    std::ios_base::sync_with_stdio(false);

    int alphas[26] = {};
    char c;

    while (! (std::cin >> c).eof() ) {
        c = tolower(c);
        if ('a' <= c && c <= 'z') alphas[c - 'a']++;
    }

    for (int i = 0; i < 26; i++) {
        std::cout << (char)(i + 'a') << " : " << alphas[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 1176
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		List<Integer> list = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			list.add(sc.nextInt());
		}

		int list_size = list.size();

		Set<Integer> set = new HashSet<>(list);
		int set_size = set.size();
		
		int dist = list_size - set_size;
		if(dist % 2 == 0) {
			System.out.println(set_size);
		} else {
			System.out.println(set_size - 1);
		}
	}
}



Measured memory_bytes: 60844
import math
import string


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


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


s = input()
a = 0
b = 0
x = 753
for i in range(len(s)-2):
    a = int(s[i:i+3])
    b = abs(753-a)
    x = min(x, b)
print(x)


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

int dig(int n){
    if(n == 0)return 1;
    int ret = 0;
    while(n)ret++, n/=10;
    return ret;
}

int main(){
    int a, b;
    while(cin >> a >> b){
        int c = a + b;
        cout << dig(c) << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cctype>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

char encode(int n){
  if(n < 26) return 'a' + n;
  return 'A' + n - 26;
}

int decode(char c){
  if(islower(c)) return c - 'a';
  return c - 'A' + 26;
}

int main(){
  while(const int n = getInt()){
    vector<int> v(n);
    REP(i,n) v[i] = getInt();

    char buff[256];
    scanf("%s", buff);

    for(char *s = buff; *s; s++){
      cout << encode((decode(*s) + 52 - v[(s - buff) % v.size()]) % 52);
    }
    cout << endl;
  }
  return 0;
}

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

typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<int>v(N);
    cin >> v.at(0);
    for(int i = 1; i < N; i++){
        // 大きければ-1しておく
        int tmp;
        cin >> tmp;
        if(tmp > v.at(i-1)){
            v.at(i) = tmp -1;
        } else { 
            v.at(i) = tmp;
        }

    }

    // 広義体調増加かチェックする
    bool ans = true;
    int tmp = v[0];
    for(int i = 1; i < v.size(); i++){
        if(v.at(i) < tmp){
            ans = false;
            break;
        } else { 
            tmp = v.at(i);
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>

using namespace std;
int main() {
	int a;
	cin >>a;
	if (a/100 == a%10) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  string a,b;cin>>a>>b;
  reverse(a.begin(),a.end());
  if(a==b)cout<<"YES";
  else cout<<"NO";
  }


Measured memory_bytes: 23680
#include <iostream>
#include <algorithm>

using namespace std;

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

    int n;
    cin >> n;

    int ans = 0;
    int amin = n + 1;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a < amin) {
            ans++;
        }

        amin = min(amin, a);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")
 
#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 10000000000000000 //1e16
 
// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
 
 
// using namespace __gnu_pbds;
using namespace std;
 
using ll  = long long;
using vi  = vector<int>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;
 
int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}



void solve()
{
    int t,n,m,i,k,r,l,u,v,w,j,s,sum=0,pos,flag=0,count=0;
    string S,T,U; 
     int a,b,c;
    cin>>a;
  cout<<a+a*a+a*a*a;
}
 
 
signed main()
{
    #ifndef ONLINE_JUDGE 
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}


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

bool isprime[1000002];

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

int main()
{
	ll a,b;
	cin >> a >> b;
	for(ll i = 2;i*i<=1e12;i++)
	{
		if(isprime[i]==0)
		{
			for(int j = i*2;j<=1000000;j+=i)
			{
				isprime[j]=1;
				//cout<<j<<endl;
			}
		}
	}
	isprime[0]=isprime[1]=0;
	int cnt = 0;
	for(ll i = 2;i<=1000000;i++)
	{
		if(a%i==0&&b%i==0)
		{
			cnt++;
		}
		while (a%i==0&&b%i==0)
		{
			a/=i;
			b/=i;
		}
	}
	if(gcd(a,b)!=1)cnt++;
	cout<<cnt+1<<endl;
	return 0;
}

Measured memory_bytes: 1280
import java.util.*;

public class Main {

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

		int n = scanner.nextInt();
		int m = scanner.nextInt();

		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < m; i++) {
			list.add(scanner.nextInt());
		}

		int sum = list.stream().reduce(0, Integer::sum);
		int result = (sum <= n) ? n - sum : -1;
		System.out.println(result);

		scanner.close();
	}

}


Measured memory_bytes: 46748
// AtCoder Beginner Contest 135
// Practice
// C - City Savers
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string> 
#include <vector>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, int> PLI;
typedef pair<int, int> PII;
const ll mxsize = 1e5 + 15;
const ll linf = 1e9;
const long double inf = 10000000000.0;
#define fastIO                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
const ll mod = 1e9 + 7;
/******************************************* IMPORTANT CODE SNIPPETS ************************************************/ 
 
ll pow(ll x, ll n) {
  if (n == 0)
    return 1ll;
  ll temp;
  temp = pow(x, n / 2);
  if (n % 2 == 0)
    return temp * temp;
  else
    return x * temp * temp;
}
 
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
 
int sum_digit(int val) {
  if (val < 0)
    return -1;
  if (val == 0)
    return 0;
  int ans = 0;
  while (val > 0) {
    ans = ans + val % 10;
    val = val / 10;
  }
  return ans;
}
 
ll count_div(ll l, ll r, ll val) {
  if (l % val == 0)
    return (((r / val) - (l / val)) + 1);
  else
    return ((r / val) - (l / val));
}
 
int powmod(int x, int y, int m) {
  int res = 1;
  // x = x % mod;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % m;
    cout << res << endl;
    y = y / 2;
    cout << x << endl;
    x = (x * x) % m;
  }
  // cout << res << endl;
  return res;
}
/******************************************** CODE STARTS FROM HERE *************************************************/ 
 
int main()
{
  fastIO;
  int N;
  cin >> N;
  vector < int > A(N + 1);
  vector < int > B(N);
  for(int i = 0 ; i <= N ; i++) cin >> A[i];
  for(int i = 0 ; i < N ; i++) cin >> B[i];
  long long int ans = 0;
  for(int i = 0 ; i < N ; i++)
  {
    if(A[i] <= B[i])
    {
      int kill = B[i] - A[i];
      ans = ans + A[i] + min(kill , A[i + 1]);
      A[i + 1] = max(A[i + 1] - kill , 0);
    }
    else
    {
      ans = ans + B[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
    string str;
    cin >> str;
    
    long long int K;
    cin >> K;
    
    int num=0;
    char can='1';
    for(int i=0; i<str.size(); i++) {
        if(str[i]!='1') {
            can=str[i];
            num=i;
            break;
        }
    }
    
    if(K<=num) {
        cout << 1 << endl;
    } else {
        cout << can << endl;
    }


    return 0;
    
}

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

int main() {
    int x, y, z;
    cin >> x >> y >> z;

    cout << x*y/2 << endl;
    return 0;
}

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

int main(){
    int a,b;
    while(1){
        cin >> a >> b;
        if(a == 0 && b == 0){
            break;
        }
        for(int i = 0; i < a; ++i){
            for(int j = 0; j < b; ++j){
                cout << "#" << flush;
            }
            cout << endl;
        }
        cout << endl;
    }
}

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

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = 2e18;
constexpr int MOD = 998244353;
constexpr int MAXN = 2e5 + 3;

/// INDEX THE ARRAY BY 1!!!
class BIT {
private:
  vector<int> bit;
  int n;

private:
  int low(const int i) { return (i & (-i)); }

  // point update
  void bit_update(int i, const int delta) {
    while (i <= this->n) {
      this->bit[i] += delta;
      i += this->low(i);
    }
  }

  // point query
  int bit_query(int i) {
    if (i <= 0)
      return 0;
    int sum = 0;
    while (i > 0) {
      sum += bit[i];
      i -= this->low(i);
    }
    return sum;
  }

public:
  BIT(const vector<int> &arr) { this->build(arr); }

  BIT(const int n) {
    // OBS: BIT IS INDEXED FROM 1
    // THE USE OF 1-BASED ARRAY IS RECOMMENDED
    this->n = n;
    this->bit.resize(n + 1, 0);
  }

  // build the bit
  void build(const vector<int> &arr) {
    // OBS: BIT IS INDEXED FROM 1
    // THE USE OF 1-BASED ARRAY IS RECOMMENDED
    assert(arr.front() == 0);
    this->n = (int)arr.size() - 1;
    this->bit.resize(arr.size(), 0);

    for (int i = 1; i <= this->n; i++)
      this->bit_update(i, arr[i]);
  }

  // point update
  void update(const int i, const int delta) {
    assert(1 <= i), assert(i <= this->n);
    this->bit_update(i, delta);
  }

  // prefix query
  int query(const int i) {
    assert(1 <= i), assert(i <= this->n);
    return this->bit_query(i);
  }

  // range query
  int query(const int l, const int r) {
    return this->bit_query(r) - this->bit_query(l - 1);
  }
};

// #define MULTIPLE_TEST_CASES
void solve() {
  int n;
  cin >> n;

  int k;
  cin >> k;

  vii arr;
  for (int i = 1; i <= k; ++i) {
    int x, y;
    cin >> x >> y;
    arr.eb(x, y);
  }

  BIT bit(n);
  bit.update(1, 1);
  for (int i = 2; i <= n; ++i) {
    int cur = 0;
    for (auto [l, r] : arr) {
      cur += bit.query(i - r, i - l);
      cur %= MOD;
    }
    bit.update(i, cur);
  }
  cout << bit.query(n, n) << endl;
}

signed main() {
  // freopen(".in", "r", stdin);
  // freopen(".out", "w", stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);

  int t = 1;
#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}

Measured memory_bytes: 4772
#pragma comment(linker, "/STACK:512000000")
#include <bits/stdc++.h>
#ifdef AIM
#include <sys/resource.h>
#endif
using namespace std;

#define all(a) a.begin(), a.end()
typedef long long li;
typedef long double ld;
void solve(__attribute__((unused)) bool);
void precalc();
clock_t start;
#define FILENAME ""

int main() {
#ifdef AIM
  string s = FILENAME;
//    assert(!s.empty());
  freopen("/home/alexandero/ClionProjects/cryptozoology/input.txt", "r", stdin);
//freopen("/home/alexandero/ClionProjects/cryptozoology/output.txt", "w", stdout);
#else
//    freopen(FILENAME ".in", "r", stdin);
//    freopen(FILENAME ".out", "w", stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    start = clock();
    int t = 1;
#ifndef AIM
  cout.sync_with_stdio(0);
  cin.tie(0);
#endif

#ifdef AIM
  const rlim_t kStackSize = 256 * 1024 * 1024;
  struct rlimit rl;
  int result;

  result = getrlimit(RLIMIT_STACK, &rl);
  if (result == 0)
  {
    if (rl.rlim_cur < kStackSize)
    {
      rl.rlim_cur = kStackSize;
      result = setrlimit(RLIMIT_STACK, &rl);
      if (result != 0)
      {
        fprintf(stderr, "setrlimit returned result = %d\n", result);
      }
    }
  }
#endif

  precalc();
  cout.precision(10);
  cout << fixed;
  //cin >> t;
  int testNum = 1;
  while (t--) {
      //cout << "Case #" << testNum++ << ": ";
      solve(true);
  }
  cout.flush();
#ifdef AIM1
    while (true) {
      solve(false);
  }
#endif

#ifdef AIM
  cout.flush();
  auto end = clock();

  usleep(10000);
  print_stats(end - start);
  usleep(10000);
#endif

    return 0;
}

template<typename T>
T binpow(T q, T w, T mod) {
    if (!w)
        return 1 % mod;
    if (w & 1)
        return q * 1LL * binpow(q, w - 1, mod) % mod;
    return binpow(q * 1LL * q % mod, w / 2, mod);
}

template<typename T>
T gcd(T q, T w) {
    while (w) {
        q %= w;
        swap(q, w);
    }
    return q;
}
template<typename T>
T lcm(T q, T w) {
    return q / gcd(q, w) * w;
}

template <typename T>
void make_unique(vector<T>& a) {
    sort(all(a));
    a.erase(unique(all(a)), a.end());
}

template<typename T>
void relax_min(T& cur, T val) {
    cur = min(cur, val);
}

template<typename T>
void relax_max(T& cur, T val) {
    cur = max(cur, val);
}

void precalc() {
}

#define int li
const int mod = 1000000007;

void solve(__attribute__((unused)) bool read) {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<int> sums(n + 1, 0);
  for (int i = 1; i < sums.size(); ++i) {
    sums[i] = (sums[i - 1] + binpow(i, mod - 2, mod)) % mod;
  }
  int res = 0;
  for (int w = 0; w < 2; ++w) {
    for (int i = 0; i < n; ++i) {
      res += a[i] * (sums[i + 1] - w);
      res %= mod;
      if (res < 0) res += mod;
    }
    reverse(all(a));
  }
  for (int i = 1; i <= n; ++i) {
    res = res * i % mod;
  }
  cout << res << endl;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pil = pair<int, ll>;

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(N), B(M), C(M);
	vector<pii> D(M);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	for (int j = 0; j < M; j++)
	{
		cin >> B[j] >> C[j];
		D[j] = pii(C[j], B[j]);
	}
	sort(A.begin(), A.end());
	sort(D.rbegin(), D.rend());

	int ti = 0;
	bool is_finished = false;
	for (int j = 0; j < M; j++)
	{
		int b = D[j].second, c = D[j].first;
		for (int ii = ti; ii < ti + b and ii < N; ii++)
		{
			if (A[ii] < c)
				A[ii] = c;
			else
				is_finished = true;
			if (ii == N - 1)
				is_finished = true;
		}
		if (is_finished)
			break;
		ti += b;
	}

	ll ans = 0;
	for (int i = 0; i < N; i++)
	{
		ans += A[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2176
object Main extends App {
  val Array(n, k) = io.StdIn.readLine().split(' ').map(_.toInt)
  val k2 = k * 2
  var (sum, white) = (0, 0)
  val matrix = Array.fill(k2)(Array.fill(k2)(0))
  (0 to n-1).foreach { i =>
    val temp = io.StdIn.readLine().split(' ')
    if (temp(2) == "B") {
      sum = sum + 1
      matrix(temp(0).toInt % k2)(temp(1).toInt % k2) += 1
    }
    else {
      sum = sum - 1
      white = white + 1
      matrix(temp(0).toInt % k2)(temp(1).toInt % k2) -= 1
    }
  }
  for {
    i <- (0 to k2-1)
    j <- (1 to k2-1)
  } matrix(i)(j) += matrix(i)(j-1)
  for {
    j <- (0 to k2-1)
    i <- (1 to k2-1)
  } matrix(i)(j) += matrix(i-1)(j)
  val cnt =
    (matrix(k-1)(k-1)) +
    (matrix(k2-1)(k2-1) - matrix(k-1)(k2-1) - matrix(k2-1)(k-1) + matrix(k-1)(k-1))
  var max = Math.max(cnt, sum - cnt)
  for { 
    i <- (0 to k-1)
    j <- (0 to k-1)
  } {
    val cnt = 
      (matrix(i)(j)) +
      (matrix(i+k)(j+k) - matrix(i+k)(j) - matrix(i)(j+k) + matrix(i)(j)) +
      (matrix(k2-1)(j) - matrix(i+k)(j)) +
      (matrix(i)(k2-1) - matrix(i)(j+k)) +
      (matrix(k2-1)(k2-1) - matrix(k2-1)(j+k) - matrix(i+k)(k2-1) + matrix(i+k)(j+k))
    max = Math.max(Math.max(cnt, sum - cnt), max)
  }
  print(max + white)
}


Measured memory_bytes: 78940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 987654321;
const ll MOD = 1000000007;
//const long double PI = (acos(-1));
//const long double EPS = 0.0000000001;
int dy[2] = {0, 0};
int dx[2] = {-1, 1};

int a, b, q;
set<ll> s;
set<ll> t;

int main(void) {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); 
	cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	cin >> a >> b >> q;
	ll x;
	s.insert(100000000001);
	s.insert(-100000000001);
	t.insert(100000000001);
	t.insert(-100000000001);
	rep(i,0,a) {
		cin >> x;
		s.insert(x);
	}
	rep(i,0,b) {
		cin >> x;
		t.insert(x);
	}

	rep(query,0,q) {
		ll x;
		cin >> x;

		ll ret = 100000000001;

		vl c;
		vl d;

		auto it = s.upper_bound(x);
		c.pb(*it);
		c.pb(*(--it));
		it = t.upper_bound(x);
		d.pb(*it);
		d.pb(*(--it));

		rep(i,0,2) rep(j,0,2) {
			ll nx = c[i];
			ll nnx = d[j];
			ll cand = abs(nx-x) + abs(nnx-nx);
			ret = min(ret, cand);
			nx = d[j];
			nnx = c[i];
			cand = abs(nx-x) + abs(nnx-nx);
			ret = min(ret, cand);
		}

		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
 
int main()
{
	int n;
	cin >> n;
	vector<int> f(n), s(n), t(n);
	map<int, int> fm, sm, tm;
	int sum[n] = {};
	REP(i, n){
		cin >> f[i] >> s[i] >> t[i];
		fm[f[i]]++;
		sm[s[i]]++;
		tm[t[i]]++;
	}

	REP(i, n){
		if (fm[f[i]] == 1) sum[i] += f[i];
		if (sm[s[i]] == 1) sum[i] += s[i];
		if (tm[t[i]] == 1) sum[i] += t[i];
	}

	REP(i, n){
		cout << sum[i] << endl;
	}
}



Measured memory_bytes: 3132
#include<stdio.h>
int main(){
	int l[10],r[10]={-1};
	int i,j,k,c[10],n=0;
	for(i=0;i<10;i++){
		c[i]=11;
	}
	for(i=0;i<10;i++){
		scanf("%d",&l[i]);
	}
	for(j=0;j<10;j++){
		for(i=0;i<10;i++){
			for(k=0;k<10;k++){
				if(c[k]==i){
					n=1;
				}
			}
			if(!(n==1)){
				if(l[i]>=r[j]){
					r[j]=l[i];
					c[j]=i;
				}
			}
			n=0;
		}
	}
	for(i=0;i<3;i++){
		printf("%d\n",r[i]);
	}
	return 0;
}

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

int main() {
  int A, B, n, a, b;
  cin >> A >> B;
  n = B/100-A/100-1;
  a = A/100*100+A/1000%10*10+A/10000;
  b = B/100*100+B/1000%10*10+B/10000;
  if ( A <= a ){
    n++;
  }
  if ( B >= b ){
    n++;
  }
  cout << n << endl;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // cout << fixed << setprecision(10);
    int n, k;
    cin >> n >> k;
    vector<ll> h(n + 1);
    rep(i, 1, n + 1) cin >> h[i];

    vector<vector<ll>> dp(n + 1, vector<ll>(n - k + 1, 1e18));
    dp[0][0] = 0;

    rep(x, 1, n + 1) rep(y, 1, n - k + 1) {
        rep(i, 0, x) dp[x][y] =
            min(dp[x][y], dp[i][y - 1] + max(0LL, h[x] - h[i]));
    }

    ll ans = 1e18;
    rep(i, 0, n + 1) ans = min(ans, dp[i][n - k]);
    cout << ans << endl;

    return 0;
}

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

class Dice
{
private :
    int top;
    int under;
    int right;
    int left;
    int front;
    int back;
public :
    Dice (int x, int y, int z) {
        top = x;
        under = 7 - x;
        front = y;
        back = 7 - y;
        left = z;
        right = 7 - z;
    }

    void South ();
    void North ();
    void West ();
    void East ();
    void Right ();
    void Left ();
    int Top ();
};

void Dice::South () {
    int tmp = top;
    top = back;
    back = under;
    under = front;
    front = tmp;
}

void Dice::North () {
    int tmp = top;
    top = front;
    front = under;
    under = back;
    back = tmp;
}

void Dice::East () {
    int tmp = top;
    top = right;
    right = under;
    under = left;
    left = tmp;
}

void Dice::West () {
    int tmp  = top;
    top = left;
    left = under;
    under = right;
    right = tmp;
}

void Dice::Right () {
    int tmp = front;
    front = left;
    left = back;
    back = right;
    right = tmp;
}

void Dice::Left () {
    int tmp = front;
    front = right;
    right = back;
    back = left;
    left = tmp;
}

int Dice::Top () {
    return top;
}

int main ()
{
    int n;
    while(cin >> n, n) {
        Dice dice(1,2,3);
        int sum = 1;
        for (int i = 0; i < n; i++) {
            string str;
            cin >> str;
            if (str == "North") dice.North();
            else if (str == "South") dice.South();
            else if (str == "East") dice.East();
            else if (str == "West") dice.West();
            else if (str == "Left") dice.Left();
            else dice.Right();

            sum += dice.Top();
        }

        cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 1216