akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      int a = Integer.parseInt(sc.next());
      int b = Integer.parseInt(sc.next());
      int c = Integer.parseInt(sc.next());
      int d = Integer.parseInt(sc.next());
      String result = "No";
      if (Math.abs(a - b) <= d && Math.abs(b - c) <= d)
        result = "Yes";
      else if (Math.abs( a - c) <= d)
        result = "Yes";

      System.out.println(result);
    }
  }
}


Measured memory_bytes: 23764
A, B, C, X, Y = map(int, input().split())
s1 = A * X + B * Y
if X <= Y:
    c = C * 2 * X
    b = B * (Y - X)
    s2 = b + c
    s3 = C * 2 * Y
    print(min(s1, s2, s3))
else:
    c = C * 2 * Y
    a = A * (X - Y)
    s2 = a + c
    s3 = C * 2 * X
    print(min(s1, s2, s3))


Measured memory_bytes: 3064
#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() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
void solve(){
    int n;
    long long stool = 0;
    cin>>n;
    vector<int> v;
    for(int i=0;i<n;i++){
        int vv;
        cin>>vv;
        v.push_back(vv);
    }
    // debug(v);
    // int mxc = v[0];
    int mxg = v[0];
    for(int i=1;i<n;i++){
        if(v[i]<mxg)
            stool+= (mxg - v[i]);
        else{
            mxg = v[i];
        }
        // debug(stool);
    }
    cout<<stool;
}
int main(){
int t;
// cin>>t;
t = 1;
while(t-->0)
    solve();
return 0;
}

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

int main()
{
    int n;
    cin >> n;
    set<string> s;
    string prev;
    for(int i=0; i<n; i++){
        string cur;
        cin >> cur;
        if(i == 0){
            prev = cur;
            s.insert(cur);
            continue;
        }
        
        if(s.count(cur) != 0 || prev[prev.size()-1] != cur[0]){
            cout << "No" << endl;
            return 0;
        }
        prev = cur;
        s.insert(cur);
    }
    
    cout << "Yes" << endl;
    return 0;
}

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

// Begin Header {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

#define all(x) x.begin(), x.end()
#define rep(i, n) for (intmax_t i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

constexpr size_t    operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t  operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };

constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;

template <class T, class Compare = less<>>
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template <class T, class Compare = greater<>>
using MinHeap = priority_queue<T, vector<T>, Compare>;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

template <class T>
inline istream& operator>>(istream &is, vector<T> &vec) {
    for (auto &e: vec) {
        is >> e;
    }
    return is;
}

inline void output() { cout << "\n"; }
template <class Head, class... Tail>
inline void output(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) {
        cout << " ";
    }
    output(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e: vec) {
        os << e << delim[&e == &vec.back()];
    }
    return os;
}

template <class T>
inline vector<T> makeVector(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeVector<T>(initValue, args...))>(sz, makeVector<T>(initValue, args...));
}

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template <class T>
inline bool chmax(T &a, const T &b) noexcept {
    return b > a && (a = b, true);
}

template <class T>
inline bool chmin(T &a, const T &b) noexcept {
    return b < a && (a = b, true);
}

template <class T>
inline T diff(const T &a, const T &b) noexcept {
    return a < b ? b - a : a - b;
}
// End Header }}}

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

    var(intmax_t, N, a, b);

    if (N == 1) {
        output((a != b) ? 0 : 1);
    } else if (a > b) {
        output(0);
    } else {
        output(a + (N - 1) * b - ((N - 1) * a + b) + 1);
    }

    return 0;
}


Measured memory_bytes: 256
from sys import stdin
from itertools import accumulate

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li2 = list(accumulate(li))
ma = sum(li)

rui = 100000000000

for s in range(n-1):
    rui = min(rui,abs(ma-2*li2[s]))

print(rui)

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
    int k,a,b;
    scanf("%d\n%d %d",&k,&a,&b);
    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            printf("OK");
            goto skip;
        }
    }
    printf("NG");
    skip:
    return 0;
}


Measured memory_bytes: 1736
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int cmp(const void *a,const void *b){
    if(*(int*)a>*(int*)b){return -1;}
    else if(*(int*)a<*(int*)b){return 1;}
    else {return 0;}
}
int min(int a,int b){

    if(a>=b){return b;}
    return a;
}

int main(void){
    int count=0;
char s[105],t[105];
char tmp[1];
scanf("%s",s);
scanf("%s",t);

//回転&比較
for(int i=0;s[i]!='\0';i++){
    if(strcmp(s,t)==0){printf("Yes\n");return 0;}
    else{
        tmp[0]=t[strlen(t)-1];
        for(int j=strlen(t)-2;j!=-1;j--){
            t[j+1]=t[j];
        }
        t[0]=tmp[0];
        //printf("%s\n",t);
    }
}
printf("No");
}

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

int main(){
   int n;
   cin >> n;
   map<string,bool> g;
   for(int i=0;i<n;i++){
      string s,str;
      cin>> s >> str;

      if(s == "insert") g[str] = true;
      else if(s == "find"){
         if(g[str]) cout << "yes" << endl;
         else cout << "no" << endl;
      }
      //cout << "A"<<endl;
   }

   return 0;
}



Measured memory_bytes: 52476
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int T,H,W,N,dx[]={0,0,-1,1},dy[]={-1,1,0,0};
char f[20][20],c;

int main(){
	cin>>T;
	while(T--){
		cin>>H>>W;
		int x,y,d;
		rep(i,H)rep(j,W){
			cin>>f[i][j];
			if(f[i][j]=='^'){y=i;x=j;d=0;}
			if(f[i][j]=='v'){y=i;x=j;d=1;}
			if(f[i][j]=='<'){y=i;x=j;d=2;}
			if(f[i][j]=='>'){y=i;x=j;d=3;}
		}
		cin>>N;
		rep(i,N){
			cin>>c;
			if(c=='U'){
				d=0;f[y][x]='^';
				if(y>0&&f[y-1][x]=='.'){
					y--;
					f[y][x]='^';
					f[y+1][x]='.';
				}
			}
			if(c=='D'){
				d=1;f[y][x]='v';
				if(y<H-1&&f[y+1][x]=='.'){
					y++;
					f[y][x]='v';
					f[y-1][x]='.';
				}
			}
			if(c=='L'){
				d=2;f[y][x]='<';
				if(x>0&&f[y][x-1]=='.'){
					x--;
					f[y][x]='<';
					f[y][x+1]='.';
				}
			}
			if(c=='R'){
				d=3;f[y][x]='>';
				if(x<W-1&&f[y][x+1]=='.'){
					x++;
					f[y][x]='>';
					f[y][x-1]='.';
				}
			}
			if(c=='S'){
				int bx=x,by=y;
				while(bx>=0&&bx<=W-1&&by>=0&&by<=H-1){
					bx+=dx[d];by+=dy[d];
					if(f[by][bx]=='*'){f[by][bx]='.';break;}
					if(f[by][bx]=='#')break;
				}
			}
		}
		rep(i,H)rep(j,W)cout<<f[i][j]<<(j<W-1?"":"\n");
		if(T)cout<<endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
double maxvolume(double s) 
{ 
    // finding length 
    double length = s / (3.00000000); 
  
    s -= length; 
  
    // finding breadth 
    double breadth = s /(2.00000000); 
  
    // finding height 
    double height = s - breadth; 
  
    return length * breadth * height; 
} 
int main() {
  double l;
  
  cin>>l;
  l=l+0.0000000;
  cout<<setprecision(10)<<maxvolume(l)<<endl;
   return 0;
}


Measured memory_bytes: 256
N = int(input())

XS = set(); YS = set()

P = []
for i in range(N):
    x1, y1, x2, y2 = map(int, input().split())
    XS.add(x1); XS.add(x2)
    YS.add(y1); YS.add(y2)
    P.append((x1, y1, x2, y2))

X = sorted(XS); Y = sorted(YS)
MX = {x: i for i, x in enumerate(X)}
MY = {y: i for i, y in enumerate(Y)}

H = len(Y); W = len(X)
S = [[0]*(W+1) for i in range(H+1)]
for x1, y1, x2, y2 in P:
    p1 = MY[y1]; q1 = MX[x1]
    p2 = MY[y2]; q2 = MX[x2]

    S[p1][q1] += 1
    S[p1][q2] -= 1
    S[p2][q1] -= 1
    S[p2][q2] += 1

for i in range(H):
    for j in range(W):
        S[i][j+1] += S[i][j]
for j in range(W):
    for i in range(H):
        S[i+1][j] += S[i][j]
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j]:
            ans += (Y[i+1] - Y[i]) * (X[j+1] - X[j])
print(ans)



Measured memory_bytes: 343356
n = int(input())
a = list(map(int, input().split()))
a.sort()

if a[0] == 0:
    print(0)
    exit()
else:
    ans = a[0]
    for i in range(1, len(a)):
        ans *= a[i]
        if ans > 10**18:
            print("-1")
            exit()
    
    
    print(ans)

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

int main()
{
    auto values = array<int, 3>{};
    for (auto& x : values) cin >> x;
    sort(begin(values), end(values));
    cout << (values[0] + values[1] == values[2] ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<utility>
#include<deque>
using namespace std;
#define MOD 1000000007
typedef long long ll;

int main(){
    int m,d,ans=0;
    scanf("%d %d",&m,&d);
    for(int i=1;i<=m;i++){
        for(int j=22;j<=d;j++){
            int a=j%10;
            int b=j/10;
            if(a>=2&&a*b==i){
                ans++;
            }
        }
    }
    printf("%d\n",ans);
}

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

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

  int a, b, c; cin >> a >> b >> c;
  int M = max({a, b, c});
  int sum = a+b+c;

  if(sum%2 != M*3%2) ++M;
  int ans = (M*3 - sum)/2;
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	static String change(String str){
		StringBuffer sb = new StringBuffer(str);
		String tmp;
		tmp = sb.reverse().toString();
		return tmp;
	}
	public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	Set<String> set = new HashSet<String>();
	int m;
	String str;
	String[] strage = new String[2];
	m = s.nextInt();
	
	while(m-->0){
		str = s.next();
		set.clear();
	for(int i=1;i<str.length();i++){
		strage[0]=str.substring(0, i);
		strage[1]=str.substring(i);

		set.add(strage[0]+strage[1]);
		set.add(strage[1]+strage[0]);
		set.add(change(strage[0])+strage[1]);
		set.add(strage[1]+change(strage[0]));
		set.add(strage[0]+change(strage[1]));
		set.add(change(strage[1])+strage[0]);
		set.add(change(strage[0])+change(strage[1]));
		set.add(change(strage[1])+change(strage[0]));
	}
		System.out.println(set.size());
	}
	s.close();
}
}

Measured memory_bytes: 52884
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val ab = (1..n).map {
        val (a, b) = readLine()!!.split(" ").map(String::toInt)
        Pair(a, b)
    }.sortedByDescending { e -> e.first + e.second }
    var ap = 0L
    var bp = 0L
    for (i in 0 until n) {
        if (i % 2 == 0) {
            ap += ab[i].first
        } else {
            bp += ab[i].second
        }
    }
    println(ap - bp)
}


Measured memory_bytes: 81156
#include<stdio.h>
int main(void){
	int k;
	int dp[200100]={0};
	int deque[200200],s,l;
	int cost[200200];
	int look,see;
	scanf("%d",&k);
	deque[0]=1;l=1;
	cost[0]=1;
	while(l){
		look=deque[s];
		see=cost[s];
		s=(s+1)%200000;l--;
		if(dp[look]==0||dp[look]>see){
			dp[look]=see;
			if(dp[(look+1)%k]==0||dp[(look+1)%k]>see+1){
				deque[(s+l)%200000]=(look+1)%k;
				cost[(s+l)%200000]=see+1;
				l++;
			}
			if(dp[look*10%k]==0||dp[look*10%k]>see){
				s=(s+199999)%200000;
				l++;
				deque[s]=look*10%k;
				cost[s]=see;
			}
		}
	}
	printf("%d\n",dp[0]);
	return 0;
}


Measured memory_bytes: 3224
#!/usr/bin/env python3
import sys

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

def solve(N: int, p: "List[int]"):
    count = 0
    for i, x in enumerate(p):
        if i + 1 != x:
            count += 1
    if count <= 2:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    p = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, p)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
n,a=map(int,input().split())
x=list(map(int,input().split()))
x.insert(0,0)
dp=[[[0]*(n*a+1) for _ in range(n+1)]for _ in range(n+1)]
dp[0][0][0]=1

for i in range(n+1):
    for j in range(n+1):
        for k in range(n*a+1):
            if  i>=1 and k<x[i]:
                dp[i][j][k]=dp[i-1][j][k]
            elif i>=1 and j>=1 and k>=x[i]:
                dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i]]

ans=0
for i in range(1,n+1):
    ans+=dp[n][i][i*a]

print(ans)


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

int main(){
  char s;
  
  cin >> s;
  
  if(s=='a'||s=='i'||s=='u'||s=='e'||s=='o')
  {
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
  return 0;
}


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

int main()
{
    int a[3];
    scanf("%d%d%d", &a[0], &a[1], &a[2]);
    int ans = 301;
    /*for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            for(int k = 0; k < 3; k++)
            {
                if(i != j && j != k && k != i)
                {
                    ans = std::min(ans, abs(a[i] - a[j]) + std::min( abs(a[j] - a[k]), abs(a[i] - a[k])));
                }
            }
        }
    }
    printf("%d",ans);*/
    printf("%d\n", std::max(std::max(a[0], a[1]), a[2]) - std::min(std::min(a[0], a[1]), a[2]));
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

int main(){
  ll n;cin>>n;
  string s;cin>>s;
  vb zoo(n);
  bool ok=false;
  rep(k,0,2){
    zoo[0]=k;
    rep(j,0,2){
      zoo[1]=j;
      rep(i,2,n){
        if((zoo[i-1]&&s[i-1]=='o')||(!zoo[i-1]&&s[i-1]=='x')){
          zoo[i]=zoo[i-2];
        }
        else{
          zoo[i]=!zoo[i-2];
        }
      }
      if((zoo[0]&&s[0]=='o')||(!zoo[0]&&s[0]=='x')){
          if(zoo[1]==zoo[n-1]){
            if((zoo[n-1]&&s[n-1]=='o')||(!zoo[n-1]&&s[n-1]=='x')){
              if(zoo[n-2]==zoo[0])ok=true;
            }
            else{
              if(zoo[n-2]!=zoo[0])ok=true;
            }
          }
    
        }
      else{
        if(zoo[1]!=zoo[n-1]){
          if((zoo[n-1]&&s[n-1]=='o')||(!zoo[n-1]&&s[n-1]=='x')){
              if(zoo[n-2]==zoo[0])ok=true;
            }
            else{
              if(zoo[n-2]!=zoo[0])ok=true;
            }
        }
      }
      if(ok){
        rep(i,0,n){
          if(zoo[i])cout<<"S";
          else cout<<"W";
        }
        cout<<endl;
        break;
      }
    }
    if(ok)break;
  }
  if(!ok)cout<<-1<<endl;
}


Measured memory_bytes: 3780
n,k=gets.split;a=[*0..9]-gets.split.map(&:to_i)
(puts n;exit)if !i1=(0...n.size).find{|i|!a.find{|e|e==n[i].to_i}}
i2=i1.downto(0).find{|i|a.find{|e|e>n[i].to_i}}||-1
puts"#{i2<0?a[0]>0?a[0]:a[1]:n[0...i2]+a.find{|e|e>n[i2].to_i}.to_s}"+a[0].to_s*(n.size-i2-1)

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
long long n,ans;
int main () {
	scanf("%lld",&n);
	for (long long i=2;i*i<=n;i++) {
		if (n%i==0) {
			int cnt=0;
			while (n%i==0) {cnt++,n/=i;}
			int cur=1,res=0;
			while (cnt>=cur) {
				cnt-=cur,res++;
				cur++;
			}
			ans+=res;
		}
	}
	if (n>1) {ans++;}
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,m;
ll x;
pair<int,pii> es[2521];
bool white[2521];

int dat[1252];
void init(){
  REP(i,1252)dat[i]=-1;
}
int root(int x){
  return dat[x]<0?x:dat[x]=root(dat[x]);
}
bool unite(int a,int b){
  a = root(a);
  b = root(b);
  if(a!=b){
    if(dat[a]>dat[b])swap(a,b);
    dat[a] += dat[b];
    dat[b] = a;
    return true;
  }
  return false;
}

vector<pii> g[1252];
int dep[1252];
void dfs(int p,int bef,int d){
  dep[p] = d;
  for(pii P : g[p]){
    int to = P.first;
    if(to==bef)continue;
    dfs(to,p,d+1);
  }
}

int main(){
  scanf("%d%d",&n,&m);
  scanf("%lld",&x);
  REP(i,m){
    int u,v,w;
    scanf("%d%d%d",&u,&v,&w);
    --u; --v;
    es[i] = make_pair(w,pii(u,v));
  }
  sort(es,es+m);
  // mst
  ll cost = 0;
  int uses = 0;
  init();
  vi eees;
  REP(i,m){
    int u = es[i].second.first;
    int v = es[i].second.second;
    int w = es[i].first;
    if(root(u)!=root(v)){
      white[i] = true;
      eees.push_back(i);
    }
    if(i==m-1 || es[i+1].first != w){
      for(int j : eees){
        int uu = es[j].second.first;
        int vv = es[j].second.second;
        int ww = es[j].first;
        if(unite(uu,vv)){
          cost += w;
        }
      }
      uses += (int)eees.size();
      eees.clear();
    }
  }
  if(cost > x){
    puts("0");
    return 0;
  }
  if(cost == x){
    ll ans = 1;
    REP(i,uses)ans = ans * 2 % MOD;
    ans -= 2;
    REP(i,m-uses)ans = ans * 2 % MOD;
    printf("%lld\n",ans);
    return 0;
  }
  int blacks = 0;
  int blackcnt = m - uses;
  REP(i,m){
    if(white[i])continue;
    ll xx = cost + (ll)es[i].first - x;
    int u = es[i].second.first;
    int v = es[i].second.second;
    init();
    REP(i,m)if(white[i] && es[i].first < xx){
      unite(es[i].second.first, es[i].second.second);
    }
    if(root(u)==root(v))continue;
    REP(i,m)if(white[i] && es[i].first == xx){
      unite(es[i].second.first, es[i].second.second);
    }
    if(root(u)!=root(v)){
      blackcnt--;
    }else{
      blacks++;
    }
  }
  ll ans = 1;
  REP(i,blacks)ans = ans * 2 % MOD;
  ans--;
  REP(i,blackcnt-blacks)ans = ans * 2 % MOD;
  ans = ans * 2 % MOD;
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }

int main(){
	ll x,n ;
	cin >> x >> n ;
	vll a(n) ;
	for(auto &i:a) cin >> i ;
	ll ans = -1000 ;
	ll mn = INF ;
	for(int i=-110;i<=110;i++){
		bool ok = true ;
		for(int j=0;j<n;j++) if(a.at(j)==i) ok = false ;
		if(ok){
			if(mn>abs(x-i)){
				ans = i ;
				mn = abs(x-i) ;
			}
		}
	}
	cout << ans << endl ;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace I_am_an_idiot
{
    class Program
    {
        static void Main(string[] args)
        {
            int s, w;
            string[] a;
            a = Console.ReadLine().Split(' ');
            s = Convert.ToInt32(a[0]);
            w = Convert.ToInt32(a[1]);
            if (s > w) Console.WriteLine("safe"); else Console.WriteLine("unsafe");
            return;
        }
    }
}



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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  int n,k;
  string s;
  cin >> n >> k >> s;
  k--;
  if(s[k]=='A')s[k]='a';
  if(s[k]=='B')s[k]='b';
  if(s[k]=='C')s[k]='c';
  cout << s << endl;
}

Measured memory_bytes: 256
import java.util.*;

import static java.lang.System.*;

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

        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int vMax = 100001;
        int[][] count = new int[2][vMax];   //偶数番号、奇数番号それぞれで出てきた数字の出現回数
        for (int i = 0; i < n; i++) {
            int num = a[i];
            count[(i % 2)][num]++;
        }

        int[] countMax = new int[2];
        int[] countMaxNum = new int[2];
        int[] countSecondMax = new int[2];
        for (int i = 1; i < vMax; i++) {
            for (int j = 0; j < 2; j++) {
                if (countMax[j] < count[j][i]) {
                    countSecondMax[j] = countMax[j];
                    countMax[j] = count[j][i];
                    countMaxNum[j] = i;
                } else if(countSecondMax[j] < count[j][i]) {
                    countSecondMax[j] = count[j][i];
                }
            }
        }

        int ans = n;
        // 同じ文字列だったら
        if (countMaxNum[0] == countMaxNum[1]) {
            ans -=  Math.max(countMax[0] + countSecondMax[1], countSecondMax[0] + countMax[1]);
        } else {
            for (int i = 0; i < 2; i++) {
                ans -= countMax[i];
            }
        }

        out.println(ans);
    }
}


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

int main() {
  //定義
  int a, b;  //平均の素材　小数点なし
  int ave;   //小数点なしの平均
  double aa,bb; //平均の素材　小数点あり
  double aveave;//小数点ありの平均
  //入力
  cin >> a >> b;
  aa = (double)a;
  bb = (double)b;  
  
  //計算
  ave=(a+b)/2;
  aveave=(aa+bb)/2;
 
  //判定＆表示
  if(ave != aveave)
  {
    cout << ave+1 << endl;
  }
  else
  {
    cout << ave << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int r,g,b,n,ans=0;
  cin>>r>>g>>b>>n;
  for(int i=0;i<=n;i+=r){
    for(int j=0;i+j<=n;j+=g){
      if((n-(i+j))%b==0) ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */

int main () {

	int D;

	// 整数の数の読込み
	scanf("%d", &D);

	printf("Christmas");
	for(int i = D; i < 25; i++)
		printf(" Eve");
	printf("\n");

	return 0;
}


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

int lcs(string str1, string str2)
{
	int len[1001][1001] = { 0 };

	int len1 = str1.length();
	int len2 = str2.length();
	str1 = " " + str1;
	str2 = " " + str2;

	for (int i = 0; i <= len1; i++)
		for (int j = 0; j <= len2; j++) len[i][j] = 0;

	for (int i = 1; i <= len1; i++)
	{
		for (int j = 1; j <= len2; j++)
		{
			if (str1[i] == str2[j]) len[i][j] = len[i - 1][j - 1] + 1;
			else len[i][j] = max(len[i - 1][j], len[i][j - 1]);
		}
	}
	return len[len1][len2];
}

int main()
{
	int n;
	string str1, str2;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> str1 >> str2;
		cout << lcs(str1, str2) << endl;
	}

	return 0;
}

Measured memory_bytes: 7064
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

int main() {
	int h1,m1,h2,m2,k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int ans;
	if(m2>=m1) {
		ans = (h2 - h1) * 60 + (m2 - m1) - k;
	}
	else {
		ans = (h2 - h1) * 60 - (m1-m2) - k;
	}
	cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0,d=0, x = 0, y = 0, z = 0,n=0,m=0, maxy = 0, mini = 9999, counter = 0, s = 0, endp = 0, checker = 0;
std::vector <char> vec{}, vecsec{}, vecth{};
long long int iremono[100001];
long long int iremono2[100001],check[100001];
std::vector<unsigned long long int>kinds{}, ans{}, kaku{};
char moji, moji2;
bool okada = false, okada2 = false;
std::string output, output2, input, one, two;
char rev[100001];
unsigned long long int kakunou2[101][101] = {};
unsigned long long int M, A, R, C, H;

int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int kaizyo(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}
int main()
{
	cin >>input;
	cout << "2018" << input.substr(4, 6) << endl;
}

Measured memory_bytes: 256
H, W, K = map(int, input().split())
s = [list(input()) for _ in range(H)]

c = [[0 for _ in range(W)] for _ in range(H)]

# 1×ｗの一次元の配列で考える。分割したマスをそれぞれホワイトチョコをカウントする
# データを加工してから貪欲法を行う

# bit全探索: 横線で割るパターン全てについて、縦線での折り方を考える
ans = (H-1) * (W-1)
for div in range(1<<(H-1)):
    g = 0 # g: 横線で分割するグループ番号（０、１、２...）
    id = [0] * H #何行目であるかを識別するid: i=1なら　グループiになる
    for i in range(H):
        id[i] = g
        if div>>i&1: # 2進法でdivのi桁目が1の時、そこで分割する
            g += 1 #分割線がきたらgを増やす
    g += 1 # グループ数は分割線+１になる
    #　集計に使うｃ配列を初期化
    for i in range(g):
        for j in range(W):
            c[i][j] = 0
    # グループごとを各列ごとのホワイトチョコを集計する
    for i in range(H):
        for j in range(W):
            c[id[i]][j] += int(s[i][j])

    num = g - 1 #すでに横線で折った回数（グループ数-１）
    now = [0] * g #現状で何個のホワイトチョコがあるか
    # 各グループの縦割りの確認
    def add(j):
        for i in range(g):
            now[i] += c[i][j] #ｊ列目のホワイトチョコを足していく
        for i in range(g):
            
            if now[i] > K: return False
        return True

    for j in range(W):
        if not (add(j)): # ホワイトチョコがKを超えていれば、縦で織る。
            num += 1
            now = [0] * g
            if not (add(j)):
                num = (H-1) * (W-1)
                break
    #print(g, c, num) # 横割りの回数、各グループの集計、最終的に折った回数
    ans = min(ans, num) # 割った回数値の最小を更新 

print(ans)

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

int main() {
    char c;
    cin >> c;
    if (c == 'A') {
        cout << 'T' << endl;
    } else if (c == 'T') {
        cout << 'A' << endl;
    } else if (c == 'C') {
        cout << 'G' << endl;
    } else {
        cout << 'C' << endl;
    }
    return 0;
}


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

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector <string> vs;

#define forl(i,a,b) for (int i = a; i < b; i++)
#define rfor(i,b,a) for (int i = b; i >= a; i--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define srt(x) sort(x.begin(), x.end())
#define sumup(x) accumulate(x.begin(), x.end(), 0)
#define PI 3.141592653589793238
#define MOD 1000000007

int c=0, h, w, k;
char a[6][6], b[6][6];
void copy_matrix() {
    forl(i,0,h) {
        forl(j,0,w) {
            b[i][j] = a[i][j];
        }
    }
}
void color(int i, int j) {
    for(int l=0; l<h; l++) {
        if(i&(1<<l)) {
            for(int p=0; p<w; p++) {
                b[l][p] = '$';
            }
        }
    }
    for(int l=0; l<w; l++) {
        if(j&(1<<l)) {
            for(int p=0; p<h; p++) {
                b[p][l] = '$';
            }
        }
    }
}
void check() {
    int bl = 0;
    forl(i,0,h) {
        forl(j,0,w) {
            if(b[i][j]=='#') bl++;
        }
    }
    if(bl==k) c++;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>h>>w>>k;

    forl(i,0,h) {
        forl(j,0,w) {
            cin>>a[i][j];
        }
    }// input done
    for(int i=0; i<(1<<h); i++) {
        for(int j=0; j<(1<<w); j++) {
            copy_matrix();
            color(i,j);
            check();
        }
    }    
    cout<<c<<"\n";
}
// almost copied from shivam_bhalla 's program (for learning).

Measured memory_bytes: 3604
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;

namespace Fish.aizu
{
	public static class AizuOnlineJudge
	{
		public static int[] SplitToInts(string line)
		{
			return line.Split(' ').Select(x => int.Parse(x)).ToArray();
		}
		public static double[] SplitToDoubles(string line)
		{
			return line.Split(' ').Select(x => double.Parse(x)).ToArray();
		}
		public static long[] SplitToLongs(string line)
		{
			return line.Split(' ').Select(x => long.Parse(x)).ToArray();
		}
		public static int Main()
		{
			Compute(Console.In, Console.Out);
			return 0;
		}
		
		public static void Compute(TextReader reader, TextWriter writer)
		{
			var vv = SplitToInts(reader.ReadLine());
			var R = vv[0];
			var C = vv[1];
			var table = new int[R + 1, C + 1];
			
			for (var r = 0; r < R; r++)
			{
				var v = SplitToInts(reader.ReadLine());
				var sum = 0;
				for (var c = 0; c < C; c++)
				{
					table[r,c] = v[c];
					sum += v[c];
				}
				table[r,C] = sum;
			}
			for (var c = 0; c < C + 1; c++)
			{
				var sum = 0;
				for (var r = 0; r < R; r++)
				{
					sum += table[r,c];
				}
				table[R,c] = sum;
			}
			
			for (var r = 0; r < R + 1; r++)
			{
				for (var c = 0; c < C + 1; c++)
				{
					writer.Write(table[r,c]);
					
					if (c != C)
					{
						writer.Write(' ');
					}
				}
				writer.WriteLine();
			}
		}
	}
}

Measured memory_bytes: 6148
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

int main() {
	ll x; cin >> x;
	double y = 100.0;
	int ans = 0;
	ll r = 1.0;
	while (y < x) { 
		y += r;
		r = y / 100;
		ans++;
	}
	dunk(ans);
	return 0;
}


Measured memory_bytes: 3632
def countingSort(A):
    k = max(A)
    n = len(A)
    C = [0 for i in range(k+1)]

    #C[i]にAの要素としてのiの出現数を記録する
    for i in range(n):
        C[A[i]] += 1

    #print(C)

    #C[i]にi以下の数の出現数を記録する
    for i in range(1,k+1):
        C[i] += C[i-1]

    #print(C)

    B = [0 for i in range(n)]

    for i in range(n-1,-1,-1):
        B[C[A[i]]-1] = A[i]
        C[A[i]] -= 1
    
    return B

N = int(input())
A = list(map(int,input().split()))
ans = countingSort(A)
print(' '.join(map(str,ans)))



Measured memory_bytes: 241916
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define repl(k,n) for(k=0;k<n;++k)

int main() {
	string N;
	cin >> N;
	int i;
	int all=0;
	for (i = 0; i < N.size(); i++) {
		int a = N[i]-'0';
		all += a;
	}
	if (all % 9 == 0) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 3748
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = a/3600;
        int c = (a%3600)/60;
        int d = a%60;

        System.out.println(b+":"+c+":"+d);
    }
}


Measured memory_bytes: 26196
#include<cstdio>
const int MaxN=200010,MaxM=200010;
int N,M;
char s[MaxN];
struct edge{int to;edge*next;}E[MaxM*2],*ne=E,*fir[MaxN];
void link(int u,int v){*ne=(edge){v,fir[u]};fir[u]=ne++;}
bool del[MaxN];
int fa[MaxN],fb[MaxN];
int stk[MaxN];
int main(){
	scanf("%d%d%s",&N,&M,s+1);
	for(int i=0,u,v;i<M;i++)scanf("%d%d",&u,&v),link(u,v),link(v,u);
	int*top=stk;
	for(int i=1;i<=N;i++){
		for(edge*e=fir[i];e;e=e->next)
			s[e->to]=='A'?fa[i]++:fb[i]++;
		if(!fa[i]||!fb[i])del[*top++=i]=1;
	}
	while(top>stk){
		int v=*--top;
		for(edge*e=fir[v];e;e=e->next)if(!del[e->to]){
			s[v]=='A'?fa[e->to]--:fb[e->to]--;
			if(!fa[e->to]||!fb[e->to])del[*top++=e->to]=1;
		}
	}
	for(int i=1;i<=N;i++)if(!del[i])return puts("Yes"),0;
	puts("No");
}

Measured memory_bytes: 10240
#include <stdio.h>

int main(void){
	int n, i, j;
	int min;
	int max;
	scanf("%d",&n);
	int a[n];

	for(i = 0; i < n; i++){
		scanf("%d",&a[i]);
	}

	min = a[0];
	max = -2147483648;
	for(i = 1; i < n; i++){
		if(a[i] - min > max) max = a[i] - min;
		if(min > a[i]) min = a[i];
	}

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

	return 0;
}

Measured memory_bytes: 2580
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
	string S;
    cin>>S;
    ll len=S.size();
    ll mod=1e9+7;
    int dp[len+1][13];
    rep(i,len+1){
        rep(j,13) dp[i][j]=0;
    }
    dp[0][0]=1;
    
    ll deg=1;
    ll p=0;
    for(ll i=len-1; i>=0; i--){
        if(S[i]=='?'){
            for(int k=0; k<10; k++){
                for(int j=0; j<13; j++){
                    dp[p+1][(k*deg+j)%13]+=dp[p][j];
                    dp[p+1][(k*deg+j)%13]%=mod;
                }
            }
        }else{
            int k=S[i]-'0';
            for(int j=0; j<13; j++){
                dp[p+1][(k*deg+j)%13]+=dp[p][j];
                dp[p+1][(k*deg+j)%13]%=mod;
            }
        }
        deg*=10;
        deg%=13;
        p++;
    }
    cout<<dp[len][5]<<endl;;
}

Measured memory_bytes: 5504
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <utility>

using namespace std;

int main(){
    int A,B,C;
    int a;
    cin >> A >> B >> C;
    int m = max(A,B);
    m = max(m, C);
    int dif = 3*m -(A + B + C); 
    if(dif % 2 == 0)cout << dif / 2 << endl;
    else{
        cout << (dif - 1) / 2 + 2 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  string S,T,U;
  cin >> S >> T;
  map<char,char> mp;
  bool chars[26];
  REP(i,26)chars[i] = false;
  REP(i,S.size()){
    if(mp[S[i]] == 0)
      mp[S[i]] = T[i];
    if(mp[S[i]] != 0 && mp[S[i]] != T[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  REP(i,26){
    if(mp['a'+i] != 0){
      if(chars[mp['a'+i]-'a'] == true){
        cout << "No" << endl;
        return 0;
      }
      chars[mp['a'+i]-'a'] = true;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 776
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int> > vvi;
typedef vector<vector<double> > vvd;

int main(){


    int x, y;
    cin >> x >> y;

    string s = to_string(x) + to_string(y);
    int z = stoi(s);
    int sqrt_z = (int)sqrt(z);

    if( z == (sqrt_z*sqrt_z) ) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
import Data.List (uncons)
import Data.Maybe (fromJust)

solve [_] _ _ d = d
solve (a:as) l r d = solve as (l+a) (r-a) $ if n < d then n else d
  where n = abs ((l+a) - (r-a))

main :: IO ()
main = do
  _ <- read <$> getLine :: IO Int
  (a,as) <- fromJust.uncons.map read.words <$> getLine :: IO (Integer,[Integer])
  print $ solve as a (sum as) $ abs (sum as-a)


Measured memory_bytes: 59772
#include<cstdio>
using namespace std;
long long n,p,ans=1;
int main()
{
	scanf("%lld%lld",&n,&p);
	if(n==1) {printf("%lld",p);return 0;}
	else {
		for(long long i=2;;++i) {
			long long now,j;
			for(now=i,j=1;;++j,now*=i) {
				if(j!=n&&now>p/i) {printf("%lld",ans);return 0;}
				else if(now>p) {printf("%lld",ans);return 0;}
				if(j==n) break;
			}
			if(now<=p&&p%now==0) ans=i;
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll MOD = 1e9+7;
ll LLINF = 1LL << 60;
int INF = INT_MAX;

int main(){
    int a,b; cin>>a>>b;
    string s; cin>>s;
    bool ok=true;
    rep(i,0,a+b+1){
        if(i==a){
            if(s[a]!='-') ok=false;
        }else{
            if(s[i]=='-') ok =false;
        }
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		int C=sc.nextInt();
		int K=sc.nextInt();
		int A2=A;
		int B2=B;
		int C2=C;
		for(int i=0;i<K;i++) {
			A2=A2*2;
		}
		int A3=A2+B+C;
		for(int i=0;i<K;i++) {
			B2=B2*2;
		}
		int B3=A+B2+C;
		for(int i=0;i<K;i++) {
			C2=C2*2;
		}
		int C3=A+B+C2;
		int max=A3;
		if(max<B3) {
			max=B3;
		}
		if(max<C3) {
			max=C3;
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 22740
#include <iostream>
#include <set>

int main(void) {
    int q;
    std::cin >> q;

    std::multiset<int> my_multiset{};
    for (int i = 0; i < q; ++i) {
        int kind;
        std::cin >> kind;

        int x;
        switch (kind) {
            case 0:
                /// insert
                std::cin >> x;
                my_multiset.insert(x);
                std::cout << my_multiset.size() << std::endl;
                break;
            case 1:
                /// find
                std::cin >> x;
                std::cout << my_multiset.count(x) << std::endl;
                break;
            case 2:
                /// delete
                std::cin >> x;
                my_multiset.erase(x);
                break;
            case 3:
                /// dump
                int l, r;
                std::cin >> l >> r;
                for (auto iter = my_multiset.lower_bound(l);
                     iter != my_multiset.upper_bound(r); ++iter)
                    std::cout << *iter << std::endl;
        }
    }
}


Measured memory_bytes: 12332
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};

namespace mp = boost::multiprecision;
const int MAX=510000;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  mp::cpp_int x,k,d;
  cin >> x >> k >> d;
  if(x==0 && k%2==0)cout << 0 << endl;
  else if(x==0 && k%2==1)cout << d << endl;
  else if(x>0 && x-k*d>=0)cout << abs(x-k*d) << endl;
  else if(x<0 && x+k*d<=0)cout << abs(x+k*d) << endl;
  else if(x>0 && x-k*d<0){
    k-=abs(x)/d;
    x-=(abs(x)/d)*d;
    if(k%2==0)cout << abs(x) << endl;
    else cout << abs(x-d) << endl;
  }
  else if(x<0 && x+k*d>0){
    k-=abs(x)/d;
    x+=(abs(x)/d)*d;
    if(k%2==0)cout << abs(x) << endl;
    else cout << abs(x+d) << endl;
  }
  return 0;
}

Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.useDelimiter(System.getProperty("line.separator"));
        int n = sc.nextInt();
        String data = sc.next();

        //String???Int????????????
        String[] datas = data.split(" ");

        Card[] cardsBubble = bubbleSort(getCards(datas,n),n);
        System.out.println("Stable");
        Card[] cardsSelect = selectionSort(getCards(datas,n),n);
        isStable(cardsBubble, cardsSelect, n);
	}



	private static void isStable(Card[] cardsBubble, Card[] cardsSelect, int n) {
		boolean stable=true;
		for(int i=0; i<n; i++){
			if(!cardsBubble[i].suit.equals(cardsSelect[i].suit)){
				stable = false;
				break;
			}
		}
		if(stable){
			System.out.println("Stable");
		}else{
			System.out.println("Not stable");
		}
	}



	private static Card[] getCards(String[] datas, int n) {
		Card[] cards = new Card[n];
		for(int i=0; i<datas.length; i++){
			cards[i] = new Card(datas[i].substring(0, 1), Integer.parseInt(datas[i].substring(1, 2)));
		}
		return cards;
	}

	static class Card{
		public String suit;
		public int value;
		public Card(String suit, int value){
			this.suit = suit;
			this.value = value;
		}
		public Card(){
		}
	}


	private static Card[] bubbleSort(Card[] cards, int n) {
		boolean flag = true;
		for(int i=0; flag==true; i++){
			flag = false;
			//bubble sort
			for(int j=0; j<n-1; j++){
				if(cards[j].value > cards[j+1].value){
					Card tmp = new Card(cards[j].suit, cards[j].value);
					cards[j] = cards[j+1];
					cards[j+1] = tmp;
					flag = true;
				}
			}
		}
		disp(cards,n);
		return cards;
	}


	private static Card[] selectionSort(Card[] cards, int n) {
		for(int i=0; i<n; i++){
			int minj= i;
			for(int j=i; j<n; j++){
				if(cards[j].value < cards[minj].value) minj = j;
			}
			//???????????????????§??????????????´???¨????°?????´????????????????
			Card tmp = new Card(cards[i].suit, cards[i].value);
			cards[i] = cards[minj];
			cards[minj] = tmp;
		}
		disp(cards,n);
		return cards;
	}



	private static void disp(Card[] cards, int n) {
		for (int i = 0; i < n; i++) {
			System.out.print(cards[i].suit + cards[i].value);
			if(i!=n-1)System.out.print(" ");
		}
		System.out.println();
	}

}

Measured memory_bytes: 26400
using System;

namespace TestProject
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			string s = Console.ReadLine();
			int len = s.Length;
			int count = 0;
			for (int i = 0; i < len / 2; i++)
			{
				switch (s[i])
				{
					case '(':
						if (s[len - 1 - i] != ')')
							count++;
						break;
					case ')':
						if (s[len - 1 - i] != '(')
							count++;
						break;
					default:
						if (s[len - 1 - i] != s[i])
							count++;
						break;
				}
			}
			if (len % 2 == 1)
			{
				char c = s[len / 2];
				string test = "iw ";
				if (!test.Contains(c.ToString()))
				{
					count++;
				}
			}
			Console.WriteLine(count);
		}
	}
}

Measured memory_bytes: 9748