akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#include<random>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (int)(Y);++(X))
#define reps(X,S,Y) for (int (X) = (int)(S);(X) < (int)(Y);++(X))
#define rrep(X,Y) for (int (X) = (int)(Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (int)(Y)-1;(X) >= (int)(S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"
#define cauto const auto

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
template<class A,class B> pair<A,B> operator+(const pair<A,B> &p,const pair<A,B> &q){ return {p.X+q.X,p.Y+q.Y};}
template<class A,class B,class C,class D> pair<A,B>& operator+=(pair<A,B> &p,const pair<C,D> &q){ p.X+=q.X; p.Y+=q.Y; return p;}
template<class A,class B> pair<A,B> operator-(const pair<A,B> &p,const pair<A,B> &q){ return {p.X-q.X,p.Y-q.Y};}
template<class A,class B,class C,class D> pair<A,B>& operator-=(pair<A,B> &p,const pair<C,D> &q){ p.X-=q.X; p.Y-=q.Y; return p;}
template<class A,class B> istream& operator>>(istream &is, pair<A,B> &p){ is>>p.X>>p.Y; return is;}
template<class T=ll> T read(){ T re; cin>>re; return move(re);}
template<class T=ll> T read(const T &dec){ T re; cin>>re; return re-dec;}
template<class T=ll> vector<T> readV(const int sz){ vector<T> re(sz); for(auto &x:re) x=read<T>(); return move(re);}
template<class T=ll> vector<T> readV(const int sz, const T &dec){ vector<T> re(sz); for(auto &x:re) x=read<T>(dec); return move(re);}
vv<int> readG(const int &n,const int &m){ vv<int> g(n); rep(_,m){ cauto a=read<int>(1),b=read<int>(1); g[a].pb(b); g[b].pb(a);} return move(g);}
vv<int> readG(const int &n){ return readG(n,n-1);}
const ll MOD=1e9+7; //998244353

#include <atcoder/all>
using namespace atcoder;

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	auto T=read();
	while(T--){
		cauto n=read();
		cauto m=read();
		cauto a=read();
		cauto b=read();
		cout<<floor_sum(n,m,a,b) NL;
	}
  return 0;
}


Measured memory_bytes: 3604
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    def calc(p, q):
        res = 0
        for i in range(D):
            res += (X[p][i] - X[q][i]) ** 2
        return res

    N, D = map(int, readline().split())
    X = []
    for _ in range(N):
        a = list(map(int, readline().split()))
        X.append(a)

    sq = set(x ** 2 for x in range(1000))
    
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            d = calc(i, j)
            if d in sq:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62168
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+5;
//int a[N];

int main()

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

    int n;

    cin >> n;

    for (int i = 0; i < n; i++) {

        for (int j = 0; j < n; j++) {

            if (i*4 + j*7 == n) {

                cout << "Yes";
                return 0;
            }
        }
    }

    cout << "No";

    return 0;
}


Measured memory_bytes: 256
def solve(string):
    n, *a = map(int, string.split())
    c = 1
    for _a in a:
        if c == _a:
            c += 1
    return str(-1 if c == 1 else n - c + 1)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 26180
#include<stdio.h>
#include<ctype.h>

int main(void)
{


char ch;
while(1) {
scanf("%c", &ch);
if(islower(ch)) printf("%c", toupper(ch));
else if(isupper(ch)) printf("%c", tolower(ch));
else printf("%c", ch);



if(ch=='\n') break;
}



return 0;
}


Measured memory_bytes: 2128
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
using namespace std;
long long x[100000];
long long x_diff[100000];
long long harmonic[100001];
const long long MOD = 1000000007;

long long power(long long m, long long n){
    long long res = 1;
    while(n > 0){
        if(n & 1) {
            res = (res * m) % MOD;
        }
        m = (m * m) % MOD;
        n >>= 1;
    }
    return res;
}

long long inverse(long long a){
    return power(a, MOD - 2);
}

int main(){
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> x[i];
  }
  for(int i = 0; i < N - 1; i++){
    x_diff[i] = x[i + 1] - x[i];
  }

  harmonic[1] = 1;
  for(int i = 2; i <= N; i++){
    harmonic[i] = (harmonic[i - 1] + inverse(i)) % MOD;
  }

  long long ans = 0;
  for(int i = 0; i < N - 1; i++){
    ans = (ans + (harmonic[i + 1] * x_diff[i]) % MOD) % MOD;
  }
  long long fact_tmp = 1;
  for(int i = 1; i <= N - 1; i++){
    fact_tmp = (fact_tmp * i) % MOD;
  }
  cout << (ans * fact_tmp) % MOD << endl;
  return 0;
}


Measured memory_bytes: 2560
from bisect import bisect_right
s=input()
t=input()
ns=len(s)
nt=len(t)
alp=[[] for i in range(26)]
for i in range(ns):
    alp[ord(s[i])-97].append(i)
alpl=[len(alp[i]) for i in range(26)]
ans=0
now=-1
for i in range(nt):
    if alpl[ord(t[i])-97]==0:
        exit(print(-1))
    b=bisect_right(alp[ord(t[i])-97],now)
    if b==alpl[ord(t[i])-97]:
        now=alp[ord(t[i])-97][0]
        ans+=ns
        if i==nt-1:
            ans+=(now+1)
    else:
        now=alp[ord(t[i])-97][b]
        if i==nt-1:
            ans+=(now+1)
print(ans)

Measured memory_bytes: 79544
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pt(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;



int main(void) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if(b<=c || d<=a) {
        pt(0);
        return 0;
    }
    
    pt(min(b, d)-max(a, c));
    
    
    
    
}

























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

if h%3 == 0 or w%3 == 0:
    print(0)
    exit()

#print(h, w)
min_ = float('inf')
for i in range(1, h):
    s1 = w*i
    s2 = (h-i)*(w//2)
    s3 = (h-i)*(w-w//2)
    d = max([s1, s2, s3]) - min([s1, s2, s3])
    #print(i, s1, s2, s3, d)
    min_ = min(min_, d)

    s2 = ((h-i)//2)*w
    s3 = ((h-i) - (h-i)//2)*w
    d = max([s1, s2, s3]) - min([s1, s2, s3])
    #print(i, s1, s2, s3, d)
    min_ = min(min_, d)

#print('-')

for i in range(1, w):
    s1 = h*i
    s2 = (w-i)*(h//2)
    s3 = (w-i)*(h-h//2)
    d = max([s1, s2, s3]) - min([s1, s2, s3])
    #print(i, s1, s2, s3, d)
    min_ = min(min_, d)

    s2 = ((w-i)//2)*h
    s3 = ((w-i) - (w-i)//2)*h
    d = max([s1, s2, s3]) - min([s1, s2, s3])
    #print(i, s1, s2, s3, d)
    min_ = min(min_, d)

print(min_)

Measured memory_bytes: 43100
#include<iostream>
#include<vector>
#include<string>

#define yes "Yes"
#define no "No"
#define black '#'

using namespace std;

bool check_in_campus(int H,int W,int TH,int TW){
    bool result;
    result = true;
    // 一つでもチェックが通るとfalseになって戻せない
    if(TH < 0){
        result = false;
    }
    if(TW < 0){
        result = false;
    }
    if( H <= TH) {
        result = false;
    }
    if( W <= TW){
        result = false;
    }
    return result;
}

bool solver(int height,int width,vector<string> campus){
    bool result;
    result = true;
    // 上→右→下→左
    vector<int> dh = {1,0,-1,0};
    vector<int> dw = {0,1,0,-1};
    for(int j=0;j<height;j++){
        for(int k=0;k<width;k++){
            if(campus.at(j).at(k) == black){
                int blackCount;
                blackCount = 0;
                for(int dir=0;dir < 4;dir++){
                    int nowH,nowW;
                    nowH = j+dh.at(dir);
                    nowW = k+dw.at(dir);
                    bool incampus;
                    incampus = false;
                    incampus = check_in_campus(height,width,nowH,nowW);
                    if(incampus){
                        if(campus.at(nowH).at(nowW) == black){
                            blackCount++;
                        }
                        
                    }
                }
                if(blackCount == 0){
                    result=false;
                }
            }
            // campus != black は処理無し
        }
    }
    return result;
}

int main(void){
    bool answer;
    answer=true;
    int H,W;
    cin >> H >> W;
    vector<string> s;
    s.clear();
    for(int j=0;j<H;j++){
        string si;
        cin >> si;
        s.push_back(si);
    }
    answer = solver(H,W,s);
    if(answer){
        cout << yes << endl;
    }
    else{
        cout << no << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
typedef long double ld;
const char sp = ' ';

using namespace boost::multiprecision;
using namespace std;

int main(void){
    ll count=0;
    ll N, D;
    cin>>N>>D;
    D=D*D;
    rep(i, N){
        ll X, Y;;
        cin>>X>>Y;
        if(X*X+Y*Y<=D) count++;
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, l, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
#define sort(v) sort(v.begin(), v.end())
#define sortr(v) sort(v.rbegin(), v.rend())
void chmin(int &a, int b) {if(a > b) a = b;}
void chmax(int &a, int b) {if(a < b) a = b;}

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    double a, b, c, d;
    cin >> a >> b >> c >> d;
    if(ceil(c/b) - ceil(a/d) >= 1) cout << "No";
    else cout << "Yes";
}

Measured memory_bytes: 3712
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  n <- getInt
  as <- getIntVec n

  let p = (10^9 + 7) :: Int
      s = V.sum as

      solve i s res | i >= (n-1) = res
                    | otherwise = let a = as V.! i
                                      s' = (s - a) `mod` p
                                      res' = (res + a * s' `mod` p) `mod` p
                                  in solve (i+1) s' res'

  print $ solve 0 s 0


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

int main(void){
	int i;
	int w[10];
	int k[10];
	for(i = 0;i < 10;++i){
		cin >> w[i];
	}

	for(i = 0;i < 10;++i){
		cin >> k[i];
	}

	sort(w, w+10);
	sort(k, k+10);

	cout << w[9]+w[8]+w[7] << " " << k[9]+k[8]+k[7] << endl;
}

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

struct Dice{
	int f[7];
	void move(char dir){
		int sw;
		switch(dir){
		case 'E':
			sw = f[1];
			f[1] = f[4];
			f[4] = f[6];
			f[6] = f[3];
			f[3] = sw;
			break;
		case 'N':
			sw = f[1];
			f[1] = f[2];
			f[2] = f[6];
			f[6] = f[5];
			f[5] = sw;
			break;
		case 'S':
			sw = f[1];
			f[1] = f[5];
			f[5] = f[6];
			f[6] = f[2];
			f[2] = sw;
			break;
		case 'W':
			sw = f[1];
			f[1] = f[3];
			f[3] = f[6];
			f[6] = f[4];
			f[4] = sw;
			break;
		}
	}
};

int main() {
	Dice dice;
	for(int i = 1; i <= 6; ++i){
		cin >> dice.f[i];
	}
	string com;
	cin >> com;
	int n = com.length();
	for(int i = 0; i < n; ++i){
		dice.move(com[i]);
	}
	cout << dice.f[1] << endl;
	return 0;
}

Measured memory_bytes: 1204
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();

    int[] oddCount = new int[100010];
    int[] evenCount = new int[100010];

    for (int i = 0; i < n; i++) {
      if (i % 2 == 0) {
        int e_ = sc.nextInt();
        evenCount[e_]++;
      } else {
        int o_ = sc.nextInt();
        oddCount[o_]++;
      }
    }

    sc.close();

    int oddMaxCount = 0;
    int oddMaxNumber = 0;
    for (int i = 0; i < 100010; i++) {
      if (oddMaxCount < oddCount[i]) {
        oddMaxCount = oddCount[i];
        oddMaxNumber = i;
      }
    }

    int evenMaxCount = 0;
    int evenMaxNumber = 0;
    for (int i = 0; i < 100010; i++) {
      if (evenMaxCount < evenCount[i]) {
        evenMaxCount = evenCount[i];
        evenMaxNumber = i;
      }
    }

    int oddSecondCount = 0;
    for (int i = 0; i < 100010; i++) {
      if (oddSecondCount < oddCount[i] && i != oddMaxNumber) {
        oddSecondCount = oddCount[i];
      }
    }

    int evenSecondCount = 0;
    for (int i = 0; i < 100010; i++) {
      if (evenSecondCount < evenCount[i] && i != evenMaxNumber) {
        evenSecondCount = evenCount[i];
      }
    }

    int min = 0;

    if (oddMaxNumber != evenMaxNumber) {
      min += n / 2 - oddMaxCount;
      min += n / 2 - evenMaxCount;
    } else {

      int min1 = n / 2 - oddMaxCount;
      min1 += n / 2 - evenSecondCount;
      
      int min2 = n / 2 - evenMaxCount;
      min2 += n / 2 - oddSecondCount;
      
      min = Math.min(min1, min2);
    }

    System.out.println(min);

  }

}

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

using namespace std;

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

int n;

signed main()
{
    cin >> n;
    int index[n + 1];
    vector<int> p(n);
    rep(i, n)
    {
        cin >> p[i];
        index[p[i]] = i;
    }
    int ans = 0;
    multiset<int> temp;
    temp.insert(-1);
    temp.insert(-1);
    temp.insert(n);
    temp.insert(n);

    temp.insert(index[n]);

    int w, x, y, z;
    int c;

    for (int i = n - 1; i > 0; i--)
    {
        int j = index[i];

        auto itr = temp.lower_bound(j);
        y = *itr;
        itr++;
        z = *itr;

        itr = temp.lower_bound(j);
        itr--;
        x = *itr;
        itr--;
        w = *itr;
        c = (x - w) * (y - j) + (j - x) * (z - y);
        ans += i * c;
        temp.insert(j);
    }

    cout << ans << endl;

    return 0;
}


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

int main(void){
  int number, manipulate_number;
  cin >> number >> manipulate_number;

  string s;
  cin >> s;

  vector<int> nums;
  int now = 1;
  int cnt = 0;
  for(int i = 0; i < number; i++){
    if(s[i] == (char)('0' + now)) cnt++;
    else{
      nums.emplace_back(cnt);
      now ^= 1;
      cnt = 1;
    }
  }
  if(cnt != 0) nums.emplace_back(cnt);

  if(nums.size() % 2 == 0) nums.emplace_back(0);


  int add_range = 2 * manipulate_number + 1;
  int ans = 0;
  for(int i = 0; i < nums.size(); i += 2){
    int tmp = 0;
    int left = i;
    int right = min(i + add_range, (int)nums.size());
    for(int j = left; j < right; j++){
      tmp += nums[j];
    }
    ans = max(tmp, ans);
  }
  cout << ans << endl;
  return 0;
}

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

#define  req(i,r,k) for(int i=k;i<r;i++)
#define  rep(i,r) req(i,r,0)

const long long int INF = 100000000000000;

long long int dp[1002][1002];

int main() {

    for(int a=1;1;a++){
        int w,n;
        scanf(" %d",&w);
        if(w==0) break;
        scanf(" %d",&n);
        pair<int,int> t[n];
        char c;
        rep(i,n){
            scanf(" %d%c%d",&t[i].first,&c,&t[i].second);
        }

        rep(i,w){
            dp[0][i] = 0;
            dp[i][0] = 0;
        }

        dp[0][0] = 0;
        rep(i,n+1) {
            rep(j,w+1) {
                if(j >= t[i].second) {
                    dp[i+1][j] = max(dp[i][j], dp[i][j - t[i].second] + t[i].first);
                }
                else{
                    dp[i+1][j] = dp[i][j];
                }
            }
        }
        long long int maxvalue=0,thenweight=0;

        rep(i,w+1){
            //cout << dp[i] << " " << i << " " << thenweight << endl;
            if(maxvalue < dp[n][i]){
                maxvalue = dp[n][i];
                thenweight = i;
            }
        }

        //printf("Case %d:\n%lld\n%lld\n",a,maxvalue,thenweight);
        cout << "Case " << a << ':' << endl;
        cout << maxvalue << endl;
        cout << thenweight << endl;
    }
    return 0;
}

Measured memory_bytes: 10976
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(int argc, char** argv) {
   int N, L;
   cin >> N >> L;

   string s[N];

   for (int i = 0; i < N; i++) {
      cin >> s[i];
   }

   sort(s, s + N);
   for (int i = 0; i < N; i++) {
      cout << s[i];
   }
   cout << endl;

   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <limits.h>
using namespace std;

int main() {
    
    int N;
    long long T;
    long long a;
    long long def_max = 0;
    int count = 0;
    
    long long min = LLONG_MAX;
    long long high = 0;
    
    cin >> N;
    cin >> T;
    
    cin >> a;
    
    min = a;
    high = a;
    
    for ( int i = 1; i < N; i++ ) {
        
        cin >> a;
        
        if ( min > a ) {
            min = a;
            high = a;
        }
        else if ( high < a ) {
            high = a;
            if ( def_max < (high-min) ) {
                def_max = high-min;
                count = 0;
            }
            else if ( def_max == high-min ) { count++; }
        }
    }
    
    cout << count + 1 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
const int mxn = 1e7+2;

void solve()
{
    int n;
    cin >> n;
    ll sum = 0;
    vector<int> a(n+1, 0);
    for(ll i = 1; i<=n; i++)
    {
        for(int j = i; j<=n; j+=i)
        {
            a[j]++;
        }
    }
    for(ll i = 1; i<=n; i++)
    {
        sum += (ll)a[i]*i;
    }

    cout << sum;
}


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


Measured memory_bytes: 42248
import math

a = input()

d = {}

for ai in a:
    if ai in d:
        d[ai] += 1
    else:
        d[ai] = 1

ans = len(a) * (len(a) -1) // 2 + 1

for k in d:
    ans -= d[k] * (d[k] -1) // 2
print(ans)


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

int main()
{
  int N; cin >> N;
  int ABC[100005][5] = {};
  for (int i = 1; i <= N; i++)
  {
    cin >> ABC[i][1] >> ABC[i][2] >> ABC[i][3];
  }
  
  int mx_happy[100005][5] = {};
  mx_happy[1][1] = ABC[1][1];
  mx_happy[1][2] = ABC[1][2];
  mx_happy[1][3] = ABC[1][3];
  
  for (int j = 2; j <= N; j++)
  {
    mx_happy[j][1] = ABC[j][1] + max(mx_happy[j - 1][2], mx_happy[j - 1][3]);
    mx_happy[j][2] = ABC[j][2] + max(mx_happy[j - 1][3], mx_happy[j - 1][1]);
    mx_happy[j][3] = ABC[j][3] + max(mx_happy[j - 1][1], mx_happy[j - 1][2]);
  }
  
  int ans = max({mx_happy[N][1], mx_happy[N][2], mx_happy[N][3]});
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 4096
import java.util.*;

public class Main {

    private static int N;
    private static int[][][] F;
    private static int[][] P;

    public static void inputNFP() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        F = new int[N][5][2];
        P = new int[N][11];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < 5; j++) {
                for (int k = 0; k < 2; k++) {
                    F[i][j][k] = sc.nextInt();
                }
            }
        }
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < 11; j++) {
                P[i][j] = sc.nextInt();
            }
        }
    }

    public static void main(String[] args) {
        inputNFP();
        int max = -1 * Integer.MIN_VALUE;
        int[] M = new int[10];
        for (int dec = 1; dec < 1024; dec++) {
            String binary = Integer.toBinaryString(dec);
            int bin = Integer.parseInt(binary);
            for (int i = 9; i >= 0; i--) {
                M[i] = bin % 10;
                bin /= 10;
            }
            int profits = 0;
            for (int i = 0; i < N; i++) {
                int count = 0;
                for (int j = 0; j < 10; j++) {
                    if(M[j] == 1 && F[i][j/2][j%2] == 1) {
                        count++;
                    }
                }
                profits += P[i][count];
            }
            max = Math.max(max, profits);
        }
        System.out.println(max);
    }

}


Measured memory_bytes: 26208
n = int(input())
ar = list(map(int, input().split()))
count = {}
for val in ar:
    if val not in count:
        count[val] = 1
    else:
        count[val] += 1
ones = 0
twos = 0
for val in count:
    if count[val] % 2 == 0:
        twos += 1
    else:
        ones += 1
if twos % 2 == 0:
    print(ones + twos)
else:
    print(ones + twos - 1)


Measured memory_bytes: 18272
#!/usr/bin/env python3
# min に合わせてそれが端にない限りはそこで２つに分割
# index もつけてzip sort するか
# 全部なくなるまで続ける
n = int(input())
a = list(map(int,input().split()))
def solve(a,n):
    if len(a) == 0: return 0
    if len(a) == 1: return a[0]-n
    idx = a.index(min(a))
    #print(min(a),n)
    return solve(a[:idx],min(a))+ min(a)-n +solve(a[idx+1:],min(a))
print(solve(a,0))

Measured memory_bytes: 38384
#include<iostream>
int main(){
	while(true){
		int H, W,a,b,c,d;
		std::cin >> H >> W;
		if (H == 0 && W == 0){
			break;
		}
		else{
			for (a = 1; a <= H; a++){
				for (b = 1; b <= W; b++){
					if (a == 1 || b == 1||a==H||b==W){
						std::cout << "#";
					}
					else{
						std::cout << ".";
					}
				}
				std::cout << "\n";
			}
		}
		std::cout << "\n";
	}
}

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

int main(){
    int a,b;
    int price;
    int takeout,eatin;
    int nashi = 0;

    cin >> a;
    cin >> b;

    for(price=1;price<100000;price++){
        takeout = price*0.08;
        eatin = price*0.1;
        if((takeout==a)&&(eatin==b)){
             cout << price << endl;
            break;
        }
        
    if(price==99999){
        cout << "-1" << endl;
    }
    }
    return 0;
}

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

int main(){
	int n,y,a,b,c;
	
	cin>>n>>y;  
	
	for(a=0;a<=y/10000;a++)    
	  for(b=0;b<=y/5000;b++)   
	  {
	  	    c=n-a-b;
	    	if(c>=0&&a*10000+b*5000+c*1000==y)
	    	{
	    		cout<<a<<" "<<b<<" "<<c;
	    		return 0;
	    	}
	  }
	
	cout<<"-1 -1 -1";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ll N; cin >> N;
    vector<ll> a(3*N);
    for (ll i=0;i<3*N;i++) cin >> a[i];
    sort(a.begin(),a.end());
    ll res = 0;
    for (ll i=N;i<3*N;i+=2) res += a[i];
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main()
{
	int w, h, x, y;
	cin >> w >> h >> x >> y;
	double ans = (double)w * h / 2;
	int num = (w == x * 2 && h == y * 2) ? 1 : 0;
	cout << ans << " " << num << endl;
}


Measured memory_bytes: 256
//#pragma comment(linker,"/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
const int INF=0x3f3f3f3f;
#define _for(i, a, b) for (int i = (a); i < (b); ++i)
#define _rep(i, a, b) for (int i = (a); i <= b; ++i)
const int max_number=1000000;



int main()
{
    int a,h,m,s;
    cin >> a;
    h = a / 3600;
    m = (a - h * 3600) / 60;
    s = a - h * 3600 - m * 60;
    cout << h <<":"<<m<<":"<<s<< endl;
    return 0;

}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N,L;
  cin>>N>>L;
ll t=0;
  for(ll i=0;i<N;i++) {
    t+=L+i;
  }
  
  if(L<0&&L+N-1<0) {
t-=L+N-1;
  }
  else if(L>0) {
t-=L;
  }
  
  cout<<t<<endl;
}
  
  
  
  
  

Measured memory_bytes: 3612
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
int main() {
  ll n, a, b;
  scanf("%lld%lld%lld", &n, &a, &b);
  if ((max(a, b) - min(a, b)) % 2LL == 0LL) {
    printf("%lld\n", max(a, b) - (a + b) / 2LL);
  } else {
    printf("%lld\n", min(min(a, b) - 1LL, n - max(a, b)) +
                         (max(a, b) - min(a, b) + 1) / 2LL);
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    int n;
    cin>>n;
    ll a[3*n];
    ll back[2*n];
    map<ll,ll> backmp,backsum;
    priority_queue<ll, vector<ll>, greater<ll> > que;
    priority_queue<ll> que2;
    ll vala[n+1]={},valb[n+1]={};
    rep(i,3*n)cin>>a[i];
    ll tmp=0;
    rep(i,n){
        que.push(a[i]);
        tmp+=a[i];
    }
    vala[0]=tmp;
    tmp=0;
    for(int i=2*n;i<3*n;i++){
        que2.push(a[i]);
        tmp+=a[i];
    }
    valb[0]=tmp;
    for(int i=0;i<n;i++){
        que.push(a[n+i]);
        vala[i+1]=vala[i]+a[n+i]-que.top();
        que.pop();
        que2.push(a[2*n-1-i]);
        valb[i+1]=valb[i]-que2.top()+a[2*n-1-i];
        que2.pop();
    }
    DEBUG{
        rep(i,n+1)cout << vala[i] << " ";
        cout << endl;
        rep(i,n+1)cout << valb[i] << " ";
        cout << endl;

    }
    ll res=vala[0]-valb[n];
    rep(i,n){
        res=max(res,vala[i+1]-valb[n-i-1]);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 6516
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  string s,t;
  cin >> s >> t;
  ll n = s.size();
  bool can = true;
  vector<ll> sc(26,-1),tc(26,-1);
  for(int i=0;i<n;i++){
    if(sc[s[i]-'a']==-1){
      sc[s[i]-'a'] = t[i];
    }
    if(tc[t[i]-'a']==-1){
      tc[t[i]-'a'] = s[i];
    }
    if(sc[s[i]-'a']!=t[i]){
      can = false;
      break;
    }
    if(tc[t[i]-'a']!=s[i]){
      can = false;
      break;
    }
  }
  if(can) cout <<"Yes\n";
  else cout <<"No\n";
}


Measured memory_bytes: 916
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int f[5009];
int a[5009];
ll sum=0;
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        sum+=min(a[i],k);
        a[i]=min(a[i],k);
    }
    sort(a+1,a+1+n);
    f[0]=1;
    for(int i=n;i>=0;i--)
    {
        int flag=1;
        for(int j=k-1;j>=k-sum&&j>=0;j--)
        {
            if(f[j])
            {
                flag=0;
            }
        }
        if(flag)
        {
            cout<<i<<endl;
            return 0;
        }
        for(int j=k-1;j>=a[i];j--)f[j]|=f[j-a[i]];
        sum-=a[i];
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;

const int MOD=1000000007;
int INF=100100100100100;

signed main(){
  int a,b,c;cin>>a>>b>>c;
  if(c-b==b-a)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.List
main = do
  [n,m,l]<-map (read::String->Int) . words <$> getLine
  a <-  map (map (read::String->Int) .words) <$> (replicateM n getLine)
  b <-  map (map (read::String->Int) .words) <$> (replicateM m getLine)
  putStr $ unlines $ map (unwords . map show) $ mult a b

mult :: Num a => [[a]] -> [[a]] -> [[a]]
mult a b = [map (sum . zipWith (*) r) $ transpose b | r <- a]

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

int main() {
  string s;
  cin >> s;
  for(int i = 0; i < 3; i++) {
  if(s[i] == '1') s[i] += 8;
  else if(s[i] == '9') s[i] -= 8;
  }
  cout << s;

   return 0;
}

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

int main() {
  string s;
  cin >> s;
  int count = 0;
  for(int i=0; i < s.size()/2; i++) {
    if(s[i] != s[s.size()-1-i]) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
//#define int ll

const int md = 1000000007;
const int INF = 1<<30;



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

    int x1 = 0;

    rep(i,n){
        x1 += int(pow(-1,i))*a[i];
    }

    cout << x1 << " ";
    int prev = x1;

    rep(i,n-1){
        cout << 2*a[i] - prev << ((i == n-2) ? '\n' : ' ');
        prev = 2*a[i] - prev;
    }
}


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

#define FOR(i,a,b)  for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cerr << #a << " = " << a << endl

const int inf = 1001001001;
const int mod = (int)1e9+7;
//const ll inf = 1e15;
//const ll mod = 1e9+7;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};

int N, M, Q, score=0;
vector<int> a, b, c, d;

void dfs(vector<int> A) {
    if(A.size() == N+1) {
        int now = 0;
        REP(i, Q) {
            if (A[b[i]] - A[a[i]] == c[i]) {
                now += d[i];
            }
            score = max(now, score);
        }
        return;
    }

    A.push_back(A.back());
    while (A.back() <= M) {
        dfs(A);
        A.back()++;
    }
}

int main() {
    cin >> N >> M >> Q;
    a = b = c = d = vector<int>(Q);
    REP(i, Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(vector<int>(1, 1));
    cout << score << endl;
}


Measured memory_bytes: 3596
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(a: int, b: int, c: int):
    tmp = c - a - b
    if tmp > 0 and 4 * a * b < tmp * tmp:
        ret = YES
    else:
        ret = NO
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    c = int(next(tokens))  # type: int
    solve(a, b, c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n,d,ans=0;
    cin>>n>>d;
    rep(i,n){
        int x,y;
        cin>>x>>y;
        if(x*x+y*y<=d*d)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,c,d;
  string s;
  cin >> n >> a >> b >> c >> d >> s;
  a--;b--;c--;d--;
  bool flag1=false,flag2=true,flag3=false;
  if(c<d)flag1=true;
  for(int i=1;i<n;i++){
    if(s[i-1]=='#'&&s[i]=='#'&&a<i&&i<=max(c,d))flag2=false;
    if(b<=i&&i<=d){
      if(s[i-1]=='.'&&s[i]=='.'&&s[i+1]=='.')flag3=true;
    }
  }
  bool ans=false;
  if(flag2){
    if(flag1)ans=true;
    else if(flag3)ans=true;
  }
  puts(ans?"Yes":"No");
  //cout << flag1<<flag2<<flag3<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
typedef long long ll;
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.first<<","<<v.second;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const vector<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template <typename Head> void dump(Head &&head) {
  cerr << head;
  dump();
}
template <typename Head, typename... Tail>
void dump(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  dump(forward<Tail>(tail)...);
}
#define debug(...)                                                               \
  do {                                                                         \
    cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = ";                        \
    dump(__VA_ARGS__);                                                         \
  } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

const ll LINF = 1LL << 60;
const int INF = 1001001001;

/////////////////////////////////////////////////////////////////////


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

  ll n; cin >> n;
  ll q; cin >> q;

  dsu d(n);
  for (int i=0; i<q; i++){
    int t,u,v; cin>>t>>u>>v;
    if (t==0) d.merge(u, v);
    else {
      if (d.same(u, v)) cout << 1 << endl;
      else cout << 0 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3852
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int h = sc.nextInt();
            int w = sc.nextInt();
            if((h == 0)&&(w == 0)){
                break;
            }
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w;j++){
                    if(i%2==0){
                      if(j%2==0){
                          System.out.print("#");
                      }
                      else{
                          System.out.print(".");
                      }
                    }
                    else{
                        if(j%2==0){
                            System.out.print(".");
                        }
                        else{
                            System.out.print("#");
                        }
                    }
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }
}


Measured memory_bytes: 35332
import sys
import socket
from heapq import heappush, heappop

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('d1.in')


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


def read_str_list():
    return input().split()


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


def read_str():
    return input()


def dijkstra(a, s):
  i0, j0 = s

  debug = i0 == 1 and j0 == 2

  H = len(a)
  W = len(a[0])
  inf = 1000
  d = [[inf]*W for i in range(H)]
  d[i0][j0] = 0
  q = []
  item = (0, i0, j0)
  heappush(q, item)
  for i in range(H):
    for j in range(W):
      if a[i][j] == '#':
        continue
      v = 0 if (i, j) == s else inf
      item = (v, i, j)
      # heappush(q, item)
  
  # print('q:', q)

  while q != []:
    v, i, j = heappop(q)
    di = [-1, 1, 0, 0]
    dj = [0, 0, -1, 1]
    for k in range(4):
      ii = i + di[k]
      jj = j + dj[k]
      if not (0 <= ii < H and 0 <= jj < W):
        continue
      if a[ii][jj] == '#':
        continue
      
      # if debug:
      #   print(' ', i, j, ii, jj, d, d[i][j] + 1, d[ii][jj])

      if d[i][j] + 1 < d[ii][jj]:
        d[ii][jj] = d[i][j] + 1
        item = (d[i][j] + 1, ii, jj)
        heappush(q, item)
      # print('  ',  d[ii][jj])  
  return d


def main():
    H, W = read_int_list()
    a = [read_str() for i in range(H)]
    res = 0
    for i in range(H):
      for j in range(W):
        if a[i][j] == '#':
          continue
        s = (i, j)
        d = dijkstra(a, s)
        
        # print('  d:', d)
        # break

        for k in range(H):
          for l in range(W):
            if a[k][l] == '#':
              continue
            if d[k][l] > res:
              res = d[k][l]

    print(res)


main()


Measured memory_bytes: 3700
S = input()
for i in range(len(S)-2):
  for j in [i+1,i+2]:
    if S[i] == S[j]:
      print(i+1,j+1)
      exit()
if len(S) == 2 and S[0]==S[1]:
  print(1,2)
  exit()
print('-1 -1')


Measured memory_bytes: 3188
S = input()
N = len(S)
A = S[:(N-1)//2]
B = S[(N+3)//2-1:]
def f(s):
    k = 0
    b = s[::-1]
    for i in range(len(s)):
        if s[i]==b[i]:
            k+=1
    return True if k==len(s) else False
print("Yes" if f(S) and f(A) and f(B) else "No")

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
const static int tx[] = {0,1,1,1,0,-1,-1,-1};
const static int ty[] = {-1,-1,0,1,1,1,0,-1};
 
static const double EPS = 1e-10;

struct Player {
  int pos;
  int cost;
  
  Player(int _p,int _c) : pos(_p), cost(_c) {}
  bool operator <(const Player& p) const{
    return cost < p.cost;
  }
  bool operator >(const Player& p) const{
    return cost > p.cost;
  }
};

int stage[100000];
int dp[100000];

int main(){
  int N;
  
  while(~scanf("%d",&N)){
    memset(dp,0x3f,sizeof(dp));
    memset(stage,0,sizeof(stage));

    for(int i=0;i<N;i++){
      scanf("%d",stage+i);
    }

    priority_queue<Player,vector<Player>,greater<Player> > que;
    que.push(Player(0,0));
    while(!que.empty()){
      Player player = que.top(); 
      que.pop();
      for(int spots=1;spots<=6;spots++){
	int next = player.pos + spots;
	if(next >= N-1){
	  dp[N-1] = min(dp[N-1],player.cost+1);
	  continue;
	}

	while(stage[next] != 0){
	  next += stage[next];
	  if(stage[next] != 0 && dp[next] > player.cost + 1){
	    dp[next] = player.cost + 1;
	  }
	  else{
	    break;
	  }
	}

	if(dp[next] > player.cost + 1){
	  dp[next] = player.cost + 1;
	  que.push(Player(next,player.cost+1));
	}
      }
    }

    printf("%d\n",dp[N-1]);
  }
}

Measured memory_bytes: 1984
#include <stdio.h> 
 #include <math.h> 
 
 
 int main(){ 
     double x1, y1, x2, y2, distance; 
     scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2); 
     distance=sqrt((pow(x2-x1, 2)+pow(y2-y1, 2))); 
     printf("%f\n", distance); 
 
 
     return 0; 
 } 



Measured memory_bytes: 2088
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;


int main() {
	int n, m, X, Y,x[110],y[110];
	cin >> n >> m >> X >> Y;
	for (int i = 1; i <= n;i++) {
		cin >> x[i];
	}
	for (int i = 1; i <= m; i++) {
		cin >> y[i];
	}
	for (int i = -100; i <= 100;i++) {
		int count = 0;
		if (X<i&&i<=Y) {
			count++;
		}
		for (int j = 1; j <= n; j++) {
			if (x[j] < i) {
				count++;
			}
		}
		for (int j = 1; j <= m; j++) {
			if (y[j] >= i) {
				count++;
			}
		}
		if (count==n+m+1) {
				cout << "No War" << endl;
				return 0;
			}
	}
	cout << "War" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cstdlib>
using namespace std;
 
int main(){
  	
  	int a[5];
  	int k;
  	for(int i = 0;i<5 ; i++)cin >> a[i];
  	cin >> k;

  	string flag = "Yay!";
  	int diff;
  	for(int i = 0;i<5;i++){

     	for(int j = 0;j<5;j++){
          	

    		if(abs(a[i]-a[j])>k){
              flag=":(";
            }
    	} 
    }

	cout << flag <<endl;
   	
 
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	//reader := []byte("1000 1 1000")
	var n int
	fmt.Scanf("%d", &n)

	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &arr[i])
	}

	total := 0
	min := arr[0]
	for _, v := range arr {
		//fmt.Println(i, v)
		if v >= min {
			min = v
			continue
		} else {
			//fmt.Printf("[%d]=%d (%d)\t%d\n", i, v, (min - v), min)
			total += (min - v)
		}

	}

	fmt.Println(total)

}

Measured memory_bytes: 6488