akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/


const int MA = 100;
const int MA2 = MA + 1;
int A, B, D[10][10];
int C[MA2][MA2];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> A >> B;
    rep(x, 0, A) rep(y, 0, B) cin >> D[x][y];

    rep(a, 0, A) rep(b, 0, B) {
        int x = a + 1, y = b + 1;
        rep(i, 0, MA2) rep(j, 0, MA2) chmax(C[i][j], D[a][b] - i * x - j * y);
    }

    rep(a, 0, A) rep(b, 0, B) {
        int x = a + 1, y = b + 1;
        int d = inf;
        rep(i, 0, MA2) rep(j, 0, MA2) chmin(d, i * x + j * y + C[i][j]);
        if (d != D[a][b]) {
            printf("Impossible\n");
            //printf("[%d %d]\n", d, D[a][b]);
            return;
        }
    }

    vector<tuple<int, int, int>> edges;
    rep(i, 0, MA) edges.push_back(make_tuple(i, i + 1, -1));
    rep(i, 0, MA) edges.push_back(make_tuple(MA2 + i, MA2 + i + 1, -2));
    rep(i, 0, MA2) rep(j, 0, MA2) edges.push_back(make_tuple(i, MA2 * 2 - 1 - j, C[i][j]));

    printf("Possible\n");
    printf("%d %d\n", MA2 * 2, edges.size());
    fore(t, edges) {
        int a, b, c;
        tie(a, b, c) = t;
        a++; b++;
        if (c == -1) printf("%d %d X\n", a, b);
        else if (c == -2) printf("%d %d Y\n", a, b);
        else printf("%d %d %d\n", a, b, c);
    }
    printf("1 %d\n", MA2 * 2);
}


Measured memory_bytes: 704
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int ans=0;
  cin>>s;
  size_t size=s.length();
  for(int i=0;i<size/2;i++){
    if(s[i]!=s[size-i-1]) ans++;
  }
  cout<<ans<<"\n";
  return(0);
}
  


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    long long int N,H,W,i,j,k,ans,count,cost,tmp;
    long long int S[200010];
    long long int Ssum[200010];
    string T;
    bool flag;
    count=0;
    ans=std::pow(10,18);
    flag=false;
    cin >>N;
    
        if (N==3 || N==5 || N==7){
            cout <<"YES"<<endl;
        }
        else{
            cout <<"NO"<<endl;
        }
    

    
    

    return 0;
    
}


Measured memory_bytes: 3568
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	var n = toInt(input[0]);
	var ws = [];
	for(var i = 0; i < n; i++){
		ws[i] = input[i+1];
	}
	var x,y;
	for(var i = 1; i < n; i++){
		for(var j = 0; j < i; j++){
			if(ws[i]===ws[j]){
				console.log('No');
				return 0;
			}
		}
		x = ws[i-1];
		y = ws[i];
		if(x[x.length-1]!==y[0]){
			console.log('No');
			return 0;
		}
	}
	
	console.log('Yes');
}

Measured memory_bytes: 22076
#include <iostream>
#include <string>
#include <vector>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
using namespace std;

int A,B,C,X,Y;
const int N = 1e5 + 10;
const int INF = 1e9;

int main()
{
  cin >> A >> B >> C >> X >> Y;

  int price_min = INF;
  REP(i,0,N) {
    int price = i * 2 * C + max(0, X-i) * A + max(0, Y-i) * B;
    // price_min = min(price_min, price);
    if (price < price_min) price_min = price;
  }

  cout << price_min << endl;
  return 0;
}

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

int main() {

    string S, T;
    cin >> S >> T;

    int ans = 10000;
    int cnt = 0;

    for (int i = 0; i < S.size() - T.size() + 1; ++i) {
        for (int j = i; j < T.size()+i; ++j) {
            if (S[j] != T[j-i]) cnt++;
        }

        ans =  min(ans, cnt);
        cnt = 0;
    }

    cout << ans << endl;


    return 0;
}

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

int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	int N;
	cin >> N;
	int tmp = (double) N / 1.08;
	if((int)(tmp*1.08) == N) {
		cout << tmp;

	} else if ((int)((tmp+1)*1.08) == N) {
		cout << (tmp+1);

	} else {
		cout << ":(";

	}


	return 0;
}



Measured memory_bytes: 256
s=input()+"1"
up=int(s[0]=="<")
do=1-up
ans=0
for i in range(1,len(s)):
  if s[i]=="1":
    ans += ((up*(up-1))>>1) + ((do*(do-1))>>1) + max(up,do)
  elif s[i-1]==">" and s[i]=="<":
    ans += ((up*(up-1))>>1) + ((do*(do-1))>>1) + max(up,do)
    up,do=1,0
  elif s[i]=="<":
    up+=1
  else:
    do+=1
print(ans)

Measured memory_bytes: 44528
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

bool judge(int bit, vector<vector<pair<int, int>>> &v) {
  for (int i = 0; i < v.size(); i++) {
    if (!(bit & (1 << i))) {
      continue;
    }
    
    // その人の証言をそれぞれ確認する
    for (auto &xy : v[i]) {
      int x = xy.first;
      int y = xy.second;
      if (y == 1 && !(bit & (1 << x))) {
        return false;
      }

      if (y == 0 && (bit & (1 << x))) {
        return false;
      }
    }
  }

  return true;
}

int main(int argc, const char *argv[])
{
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> v(n);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    v[i].resize(a);
    for (int j = 0; j < a; j++) {
      cin >> v[i][j].first >> v[i][j].second;
      --v[i][j].first;
    }
  }

  int res = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    if (judge(bit, v)) {
      int cnt = 0;
      for (int i = 0; i < n; i++) {
        if (bit & (1 << i)) {
          cnt++;
        }
      }

      res = max(res, cnt);
    }
  }

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

Measured memory_bytes: 256
'use strict'
function Main(input) {
  const Ant = input.split("\n").map(Number);
  Ant.pop();
  let dist = Ant[5];
  Ant.pop();
  // console.log({ Ant, AnA, dist });

  let result = true;

  if (Ant[4] - Ant[0] > dist) {
    result = false;
}

  console.log(result ? 'Yay!' : ':(');

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
ll w, h, p;
vpll v;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> w >> h;
  FOR(i, 0, w){
    cin >> p;
    v.pb(mp(p, 0));
  }
  FOR(i, 0, h){
    cin >> p;
    v.pb(mp(p, 1));
  }
  ll ans = 0;
  w++;
  h++;
  sort(rng(v));
  for(pll p: v){
    if(p.se){
      ans += w * p.fi;
      h--;
    }else{
      ans += h * p.fi;
      w--;
    }
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;

ll dp[105][100009], w[105], v[105];
ll solve(ll i, ll sum);
ll n, W;


int main() {
	cin >> n >> W;
	for (ll i = 0; i < n; i++) {
		cin >> w[i] >> v[i];
	}
	for (ll i = 0; i < 105; i++) {
		for (ll j = 0; j < 100009; j++) {
			dp[i][j] = -1;
		}
	}
	cout << solve(0, 0) << "\n";
}

ll solve(ll i, ll sum) {
	if (sum > W) {
		return -LLONG_MAX;
	}
	auto &ans = dp[i][sum];
	if (ans != -1) {
		return ans;
	}
	ans = 0;
	if (i == n) {
		return ans;
	} 
	ans = max(solve(i + 1, sum + w[i]) + v[i], solve(i + 1, sum));
	return ans;
}

Measured memory_bytes: 82304
m, n = map(int, input().split())
nums = list(map(int, input().split()))
 
a = 0
for i in range(n):
  if i == n-1:
    dif = m + nums[0] - nums[i]
  else:
    dif = nums[i+1] - nums[i]
  a = max(a, dif)

print(m-a)

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

int main() {
  int n;
  cin >> n;
  int count = 0;
  string ans = "No";
  rep(i, n) {
    int d1, d2;
    cin >> d1 >> d2;
    if (d1 == d2)
      count++;
    else
      count = 0;
    if (count >= 3) {
      ans = "Yes";
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>

int main()
{
    int N, K;
    std::cin >> N >> K;

    long S;
    std::vector<double> es(N + 2);

    double ess;
    long nCount = N + 1;
    for (auto i=1; i<nCount; ++i)
    {
        int p;
        std::cin >> p;
        double e = (1 + p) / 2.0;
        ess += e;
        es[i] = ess;
    }

    double maxSk = 0;
    int count = N - K + 1;
    for (auto i=0; i<count; ++i)
    {
        double Sk = es[i + K] - es[i];
        if (maxSk < Sk)
            maxSk = Sk;
    }

    std::cout << std::fixed;
    std::cout << std::setprecision(12) << maxSk << std::endl;
}


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

string o, e;

int main(){
	cin >> o >> e;
	for (int i = 0; i < o.size(); i++){
		if (o.size() - e.size() == 1 && o.size() - i == 1) {
			cout << o[i];
		}
		else {
			cout << o[i] << e[i];
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int max = 0;
		int not10min = Integer.MAX_VALUE;
		for(int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if(a % 10 != 0) {
				not10min = Math.min(not10min, a);
			}
			max += a;
		}
		if(max % 10 != 0) {
			System.out.println(max);
		} else if(not10min!=Integer.MAX_VALUE){
			System.out.println(max-not10min);
		} else {
			System.out.println(0);
		}
	}
}

Measured memory_bytes: 23892
"use strict";

const permutateWithRepetitions = (
  permutationOptions,
  permutationLength
) => {
  if (permutationLength === 1) {
    return permutationOptions.map(permutationOption => [permutationOption]);
  }

  // Init permutations array.
  const permutations = [];

  // Get smaller permutations.
  const smallerPermutations = permutateWithRepetitions(
    permutationOptions,
    permutationLength - 1
  );

  // Go through all options and join it to the smaller permutations.
  permutationOptions.forEach((currentOption) => {
    smallerPermutations.forEach((smallerPermutation) => {
      permutations.push([currentOption].concat(smallerPermutation));
    });
  });

  return permutations;
}

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const S = arg[1].split("").map(n=>parseInt(n));

    // 最大で1000通りしかありえない
    const digits = [0,1,2,3,4,5,6,7,8,9];
    
    const combos = permutateWithRepetitions(digits, 3);
    
    let cnt = 0;
    let list = [];
    //console.log(combos.join("\n"))
    
    for(let i in combos) {
        let digit1 = combos[i][0];
        let digit2 = combos[i][1];
        let digit3 = combos[i][2];
        
        let nowCheking = digit1;
        let trueCnt = 0
        let flag1 = false;
        let flag2 = false;
        let flag3 = false;
        
        let temp = [];
        
        
        for(let j=0; j<N; j++) {
            if(S[j] === digit1 && flag1 !== true) {
                flag1 = true;
            } else if(S[j] === digit2 && flag1 && flag2 !== true) {
                flag2 = true;
            } else if(S[j] === digit3 && flag1 && flag2) {
                flag3 = true;
            }
        }
        
        
        if(flag1 && flag2 && flag3) {
            // console.log("3桁を作ることが出来る")
            // console.log("digit1:" + digit1);
            // console.log("digit2:" + digit2);
            // console.log("digit3:" + digit3);
            // console.log("-------")
            cnt++;
        }
    }
    
    console.log(cnt)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 9988
#include <iostream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true;

    for (auto next_v : G[v]) {
        if (seen[next_v]) continue;
        dfs(G, next_v);
    }
}

int main() {
    int H, h, W, w;
    cin >> H >> W;
    cin >> h >> w;

    auto res = (H - h) * (W - w);

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
// D.

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	long long d[300][300], w[300][300];
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			cin >> d[i][j];
			w[i][j] = d[i][j];
		}
	}
	for (int k = 0; k < n; ++k) {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				w[i][j] = min(w[i][j], w[i][k] + w[k][j]);
			}
		}
	}
	long long ans = 0;
	for (int i = 0; ans >= 0 && i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (w[i][j] < d[i][j]) {
				ans = -1;
				break;
			}
			bool e = false;
			for (int k = 0; k < n; ++k) {
				if (i != k && j != k && w[i][k] + w[k][j] == d[i][j]) {
					e = true;
					break;
				}
			}
			if (!e) {
				ans += d[i][j];
			}
		}
	}
	cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;

#define pb push_back
#define mp make_pair

#define mod 1000000007

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define vin(v, n) for (int i = 0; i < (int)(n); i++) cin >> (v)[i];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll x, n;
	cin >> x >> n;

	vll nums(n);
	unordered_set<ll> ar;
	for (ll i = 0; i < n; i++) {
		ll a;
		cin >> a;
		ar.insert(a);
	}

	ll lb = x, rb = x;

	while (ar.find(lb) != ar.end() && ar.find(rb) != ar.end()) {
		lb--;
		rb++;
	}

	if (ar.find(lb) == ar.end()) cout << lb;
	else cout << rb;
}


Measured memory_bytes: 3660
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */

#include <iostream>
#include <fstream>

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

class ATakahashiCalendar {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n,d;
        in >> n >> d;
        int ans=0;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=d;j++){
                if(j%10>=2&&j/10>=2&&(j%10)*(j/10)==i){
                    ans++;
                }
            }
        }
        out << ans << endl;
	}
};


int main() {
	ATakahashiCalendar solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
from math import sqrt

if __name__ == '__main__':
    Q = int(input())
    values = [list(map(int, input().split())) for _ in range(Q)]
    As, Bs = zip(*values)

    # As = [1]
    # Bs = [4]

    for A, B in zip(As, Bs):
        A, B = min(A, B), max(A, B)

        # A = B
        if A == B:
            print(2 * A - 2)
            continue

        # A + 1 = B
        if A + 1 == B:
            print((A - 2) + (B - 2) + 1)
            continue

        C = int(sqrt(A * B))
        if C == sqrt(A * B):
            C -= 1

        # C(C + 1) >= AB
        if C * (C + 1) >= A * B:
            print(2 * C - 2)
            continue

        # C^2 < AB
        if C ** 2 < A * B:
            print(2 * C - 1)
            continue


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

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main() {
  int n;
  cin >> n;

  ll l[n];
  l[0] = 2;
  l[1] = 1;

  rep(i,2,n+1){
    l[i] = l[i-2] + l[i-1];
  }
  
  printf("%lld\n",l[n]);

	return 0;
}

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

int main() {
    int a[3];rep(i,3)cin>>a[i];
    sort(a,a+3);
    int ans = 1;
    rep(i,2)if(a[i+1]!=a[i])++ans;
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3648
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'

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

const int INF = 1e9;
int h, w;
char board[1010][1010];
int dis[1010][1010];
int sx, sy;

int bfs(){
  queue<pii> q;

  rep(i, h){
    rep(j, w){
      if (board[i][j] == '#'){
        q.push(pii(i, j)); dis[i][j] = 0;
      }
    }
  }

  while (!q.empty()){
    pii p = q.front(); q.pop();
    for (int i = 0; i < 4; ++i){
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (nx >= 0 && nx < h && ny >= 0 && ny < w && dis[nx][ny] == INF && board[nx][ny] == '.'){
        dis[nx][ny] = dis[p.first][p.second] + 1; board[nx][ny] = '#'; q.push(pii(nx, ny));
      }
    }
  }

  int mx = -1;
  for (int i = 0; i < h; ++i){
    for (int j = 0; j < w; ++j){
      mx = max(mx, dis[i][j]);
    }
  }

  return mx;
}

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

  cin >> h >> w;
  rep(i, h){
    rep(j, w) cin >> board[i][j];
  }

  rep(i, 1010){
    rep(j, 1010) dis[i][j] = INF;
  }

  print(bfs());

  return 0;
}

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

using namespace std;

tuple<int,int,int> points[(int)1e5+10];
int movi[] = {0,0,-1,1};
int movj[] = {1,-1,0,0};
int n;

double solve(double t){
    double minx = 1e12;
    double maxx = -1e12;
    double miny = 1e12;
    double maxy = -1e12;

    for(int i=0;i<n;++i){
        double x = get<0>(points[i]);
        double y = get<1>(points[i]);
        int dir = get<2>(points[i]);
        x = x + t * movi[dir];
        y = y + t * movj[dir];
        minx = min(minx, x);
        maxx = max(maxx, x);
        miny = min(miny, y);
        maxy = max(maxy, y);
    }

    return (maxx-minx) * (maxy-miny);
}

int main(){

    cout << setprecision(9) << fixed;

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    map<char,int> change;
    change['U'] = 0;
    change['D'] = 1;
    change['L'] = 2;
    change['R'] = 3;

    cin >> n;

    int x, y;
    char dir;
    for(int i=0;i<n;++i){
        cin >> x >> y >> dir;
        points[i] = make_tuple(x,y,change[dir]);
    }

    double left = 0, right = 1e12;
    for(int i=0;i<200;++i){
        double m1 = left+(right-left)/3;
        double m2 = left+2*(right-left)/3;
        if(solve(m1) < solve(m2)) right = m2;
        else left = m1;
    }

    cout << solve(left) << '\n';

    return 0;
}


Measured memory_bytes: 1408
X,N = map(int,input().split())
p = list(map(int,input().split()))

list_a = []
for a in range(-102,102):
    if a not in p:
        list_a.append(abs(X-a))

m = X - min(list_a)
l = X + min(list_a)
if m not in p:
    print(m)
else:
    print(l)


Measured memory_bytes: 9180
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int n; cin >> n;
	string S; cin >> S;

	int cnt = 0;

	for (int i = 0; i < n; ++i) {
		string si; cin >> si;
		int len = si.length();

		for (int j = 0; j < len; ++j) {
			if (si[j] == S[0]) {
				for (int k = 1; k < len; ++k) {
					for (int l = 1; l < len; ++l) {
						if (j + k * l >= len) break;
						if (si[j + k * l] != S[l]) break;
						if (l == S.length() - 1) {
							cnt++;
							goto next;
						}
					}
				}
			}
		}
		next:;
	}

	cout << cnt << endl;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds; 
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw;pw = pw*pw;ex>>=1;}return ans;}
ll pwm(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
template<typename T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//st.order_of_key(num)->number of elements < num
//st.find_by_order(i)->iterator of ith element in sorted order starting from zero
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mkp make_pair
//#define int long long int
//Binary_Search->dp->greedy
//auto check = [&](ll x){};
void solve(){
	int n;
	cin>>n;
	vl vec(n);
	cin>>vec;
	vl dp(n),pre(n);
	dp[0]=0;
	dp[1]=max(vec[0],vec[1]);
	pre[0]=vec[0];
	for(int i=2;i<n;i++){
		if(i&1) dp[i]=max(pre[i-1],vec[i]+dp[i-2]);
		else{
			dp[i]=max(dp[i-1],vec[i]+dp[i-2]);
			pre[i]=pre[i-2]+vec[i];
		}
	}
	cout<<dp[n-1]<<endl;
	
	
}
int main(){
int t=1;
//scanf("%d",&t);
while(t--){
	solve();
}
return 0;
}    
 

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

int main() {
    int N;  cin >> N;
    vector<char> S(N);
    for (int i = 0; i < N; ++i) {
        char c; cin >> c;
        S[i] = c;
    }
    S.erase(unique(S.begin(), S.end()), S.end());
    cout << S.size() << endl;
}


Measured memory_bytes: 384
from collections import Counter


class UnionFind:
    def __init__(self, n):
        # total number of nodes.
        self.n = n
        # node id -> root node id
        self._root_table = list(range(n))
        # root node id -> group size
        self._size_table = [1] * n

    def find(self, x):
        """Returns x's root node id."""
        r = self._root_table[x]
        if r != x:
            # Update the cache on query.
            r = self._root_table[x] = self.find(r)
        return r

    def union(self, x, y):
        """Merges two groups."""
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        # Ensure that x is the larger (or equal) group.
        if self._size_table[x] < self._size_table[y]:
            x, y = y, x

        self._size_table[x] += self._size_table[y]
        self._root_table[y] = x

    def size(self, x):
        return self._size_table[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self._root_table) if x == i]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())


H, W = map(int, map(int, input().split()))
grid = []
for i in range(H):
    grid.append(input())
uf = UnionFind(H * W)
for i in range(H):
    for j in range(W):
        nid = i * W + j
        c = grid[i][j]
        if i > 0 and grid[i - 1][j] != c:
            uf.union(nid, (i - 1) * W + j)
        if i < H - 1 and grid[i + 1][j] != c:
            uf.union(nid, (i + 1) * W + j)
        if j > 0 and grid[i][j - 1] != c:
            uf.union(nid, i * W + (j - 1))
        if j < W - 1 and grid[i][j + 1] != c:
            uf.union(nid, i * W + (j + 1))

whites = Counter()
for i in range(H):
    for j in range(W):
        if grid[i][j] == ".":
            whites[uf.find(i * W + j)] += 1
ans = 0
for i in range(H):
    for j in range(W):
        if grid[i][j] == "#":
            ps = whites[uf.find(i * W + j)]
            ans += ps

print(ans)


Measured memory_bytes: 92948
#include <stdio.h>

int main(){
	int a=0;
  	int b=0;
  	int c=0;
	
	scanf("%d",&a);
	scanf("%d",&b);
 	scanf("%d",&c);
  	int tmp=a-b;
  	if(tmp>c){
    	c=0;
    }else{
    	c=c-tmp;
    }
	printf("%d",c);

	return 0;

}

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

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define EACH(begin, end) for(auto itr = (begin); itr != (end); itr++)

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;



ll N = 0;
ll M;
vector<int> k;
vector<vector<int>> s;
vector<int> p;
ll ret = 0;

void input() {
  IN(N);
  IN(M);
  int tmp;
  REP(i, M) {
    IN(tmp);
    k.pb(tmp);
    vector<int> v;
    REP(j, k[i]) {
      IN(tmp);
      v.pb(tmp);
    }
    s.pb(v);
  }
  REP(i, M) {
    IN(tmp);
    p.pb(tmp);
  }
}

void solve() {
  int end = (int)pow(2.0, (float)N);
  REP(i, end) {
    vector<int> digit;
    REP(j, N) {
      int ord = (int)pow(2.0, (float)j);
      int d = (i/ord)%2;
      digit.pb(d);
    }
    
    bool suc = true;
    REP(j, M) {
      int total = 0;
      REP(x, k[j]) {
        if (digit[ s[j][x]-1 ]) {
          total++;
        }
      }
      suc &= (total%2 == p[j]);
    }
    if (suc) {
      ret++;
    }
  }
  PRINT(ret);
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

class Main {
	static List<Integer> list = new ArrayList<Integer>();
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		for (int i = 0; i < 10; i++) {
			list.add(scan.nextInt());
		}
		Collections.sort(list, Comparator.reverseOrder());
		for(int i=0;i<3;i++){
			System.out.println(list.get(i));
		}
	}
}

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

// Optimization

//#pragma GCC optimize("O3")
#define endl '\n'

// Shortcut

#define int long long
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) Fora(iiii, a) cout << iiii << ' '; cout << endl;
#define PrintVl(a) Fora(iiii, a) cout << iiii << endl;
#define PrintA(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << ' '; cout << endl;
#define PrintAl(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

//#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a))
#define mset1(a) memset(a, 1, sizeof(a))
#define msetn1(a) memset(a, -1, sizeof(a))
#define msetinf(a) memset(a, 0x3f, sizeof(a))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());

// Data Structure

#define pque priority_queue
#define mts multiset
#define y0 _y0_
#define y1 _y1_
#define div divi
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 2e5 + 5, mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e18 + 7;
const ll infll = 1e18 + 7;



signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int x; cin >> x;
    int ans = x / 500 * 1000; x %= 500;
    ans += x / 5 * 5;
    cout << ans;
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

s=input()
if s[-1]=='s':
    print(s+'es')
else:
    print(s+'s')

Measured memory_bytes: 61744
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int n, m, k; cin >> n >> m >> k;
	vector<long long> a(n), b(m);
	vector<long long> prefa(n+1, 0), prefb(m+1, 0);
	for (auto &i : a)
		cin >> i;
	for (auto &i : b)
		cin >> i;
	for (int i = 0; i < n; ++i)
		prefa[i+1] = prefa[i] + a[i];
	for (int i = 0; i < m; ++i)
		prefb[i+1] = prefb[i] + b[i];
	int ans = 0;
	for (int i = 0; i <= n; ++i) {
		if (prefa[i] > k) break;
		int rem = k - prefa[i];
		auto it = --upper_bound(begin(prefb), end(prefb), rem);
		ans = max(ans, i + int(it - begin(prefb)));
	}
	cout << ans << '\n';
}

Measured memory_bytes: 9532
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int h[n];
  for(int i=0;i<n;i++)
    cin>>h[i];
  int dp[n+1];
  dp[1]=0;
  dp[2]=abs(h[0]-h[1]);
  for(int i=3;i<=n;i++)
  {
    dp[i]=min(dp[i-1]+abs(h[i-1]-h[i-2]),dp[i-2]+abs(h[i-1]-h[i-3]));
  }
  cout<<dp[n];
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


void solve(){
    int n,a;
    cin >> n >> a;
    if(n%500<=a) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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


Measured memory_bytes: 256
main = do line <- getLine
          putStrLn . watch $ line

watch :: String -> String
watch secStr = let sec = read secStr :: Int
                   s = show . snd . sec2min $ sec
                   m = show . snd . min2hour . fst . sec2min $ sec
                   h = show . fst . min2hour . fst . sec2min $ sec
               in  h ++ ":" ++ m ++ ":" ++ s

sec2min :: Int -> (Int,Int)
sec2min s = s `quotRem` 60

min2hour :: Int -> (Int,Int)
min2hour m = m `quotRem` 60

Measured memory_bytes: 3656
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(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());
    if(b<=c||d<=a){out.println(0);}else{
    out.println(abs(max(a,c)-min(b,d)));}
}
}

Measured memory_bytes: 23892
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>

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

using namespace std;

const double EPS=1e-8;

struct point{
	double x,y;
	point():x(0),y(0){}
	point(double x,double y):x(x),y(y){}
	point operator+(const point &a)const{ return point(x+a.x,y+a.y); }
	point operator-(const point &a)const{ return point(x-a.x,y-a.y); }
};

point operator*(double c,const point &a){ return point(c*a.x,c*a.y); }

double abs(const point &a){ return sqrt(a.x*a.x+a.y*a.y); }

struct circle{
	point c;
	double r;
	circle():c(point(0,0)),r(0){}
	circle(const point &c,double r):c(c),r(r){}
};

bool cover(const circle &C,const point &p){
	return abs(C.c-p)<C.r+EPS;
}

int get_intersect(const circle &C1,const circle &C2,vector<point> &res){
	double r1=C1.r,r2=C2.r;
	point p1=C1.c,p2=C2.c;

	double d=abs(p1-p2);
	if(d<EPS && abs(r1-r2)<EPS){ // C1==C2
		return -1;
	}
	else if(r1+r2<d-EPS || d+EPS<abs(r1-r2)){
		return 0;
	}
	else{
		double a=(r1*r1-r2*r2+d*d)/(2*d);
		double h=sqrt(max(r1*r1-a*a,0.0));
		point tmp1=p1+a/d*(p2-p1);
		point tmp2=h/d*(p2-p1);
		if(abs(tmp2)<EPS){
			res.push_back(tmp1);
			return 1;
		}
		else{
			res.push_back(point(tmp1.x-tmp2.y,tmp1.y+tmp2.x));
			res.push_back(point(tmp1.x+tmp2.y,tmp1.y-tmp2.x));
			return 2;
		}
	}
}

int main(){
	for(int n;scanf("%d",&n),n;){
		double x[10],y[10],l[10];
		rep(i,n) scanf("%lf%lf%lf",x+i,y+i,l+i);

		double lo=0,hi=*min_element(l,l+n);
		rep(_,100){
			double mi=(lo+hi)/2;

			circle C[10];
			rep(i,n) C[i]=circle(point(x[i],y[i]),sqrt(l[i]*l[i]-mi*mi));

			vector<point> P;
			rep(i,n) P.push_back(C[i].c);
			rep(i,n) rep(j,i) get_intersect(C[i],C[j],P);
			bool ok=false;
			rep(i,P.size()){
				ok=true;
				rep(j,n) if(!cover(C[j],P[i])) ok=false;
				if(ok) break;
			}

			if(ok) lo=mi;
			else   hi=mi;
		}

		printf("%f\n",lo);
	}

	return 0;
}

Measured memory_bytes: 1104
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
 
typedef long long ll;
typedef pair<int, int> ii;

int main() {
	int x, y;
	cin >> x >> y;
	
	cout << x + y + 1 - __gcd(x, y) << endl;
	
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF (1<<29)
 
int main()
{
    int n, m;
    while (cin >> n >> m, n) {
        vector<int> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        vector<int> b(n);
        for (int i = 0; i < n; i++) {
            for (int j = 0; ; j++) {
                int c = a[i] * j;
                if (c > m) break;
                b[i] = c;
            }      
        }
        int bmin = *min_element(b.begin(), b.end());
 
        vector<int> num;
        for (int i = 0; i < n; i++) {
            if (bmin == b[i]) {
                num.push_back(i);
            }
        }
     
        if (num.size() == 1) {
            cout << num[0] + 1 << endl;
        } else {
            int amin = INF;
            for (int i = 0; i < (int)num.size(); i++) {
                amin = min(amin, a[num[i]]);
            }
            vector<int> num2;
            for (int i = 0; i < (int)num.size(); i++) {
                if (amin == a[num[i]]) {
                    num2.push_back(num[i]);
                }
            }
            if (num2.size() == 1) {
                cout << num2[0] + 1 << endl;
            } else {
                cout << n << endl;
            }
        }
    } 
    return 0;
}

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

#define MAX 1000000

main(){
    bool H[MAX+1];
    int T[MAX+1];
    for ( int i = 0; i <= MAX; i++ ){
	H[i] = false;
	T[i] = 0;
    }

    H[1] = H[2] = H[3] = H[5] = true;
    for ( long long i = 1; i <= MAX; i *= 2 ){
	for ( long long j = 1; j <= MAX; j *= 3 ){
	    if ( i*j > MAX ) continue;
	    for ( long long k = 1; k <= MAX; k *= 5 ){
		if ( i*j*k > MAX ) continue;
		H[i*j*k] = true;
	    }
	}
    }
    for ( int i = 1; i <= MAX; i++ ){
	T[i] += T[i-1];
	if ( H[i] ) T[i]++;
    }

    int l, r;
    while( cin >> l && l ){
	cin >> r;
	int a = T[r] - T[l];
	if ( H[l] ) a++;
	cout << a << endl;
    }
    
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



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

    int n;
    cin >> n;
    int maxi, mini;
    rep(i, n) {
        string s;
        cin >> s;
        sort(all(s));
        mini = stoi(s);
        sort(all(s), greater<>());
        maxi = stoi(s);
        cout << maxi - mini << endl;
    }
    return 0;
}


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

using namespace std;
 
#define rep(i,k,n) for(i=k;i<n;i++)
#define repr(i,k,n) for(i=k;i>=n;i--)
#define ll long long
#define pb(i) push_back(i)
 
int main(void)
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	/*ll t;
	cin >> t;
	while(t--)
	{*/
		string s;
		ll i;
		cin >> s;
		ll n=s.length();
		rep(i,0,((n-1)/2))
		{
			if(s[i]!=s[n-1-i])
			{
				cout << "No";
				return 0;
			}
		}

		rep(i,0,((n-1)/2)/2)
		{
			if(s[i]!=s[((n-1)/2)-1-i])
			{
				cout << "No";
				return 0;
			}
		}

		rep(i,((n-1)/2)+1,n)
		{
			if(s[i]!=s[n-1-i])
			{
				cout << "No";
				return 0;
			}
		}

		cout << "Yes";
	//}

}

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

int main(){
    int n, k; cin >> n >> k;
    int R, S, P; cin >> R >> S >> P;
    string s; cin >> s;
    long long ans = 0;
    queue<char> que;
    for(int i = 0; i < n; i++){
        if(i < k){
            if(s.at(i) == 'r'){
                ans += P;
                que.push('p');
            }
            else if(s.at(i) == 's'){
                ans += R;
                que.push('r');
            }
            else{
                ans += S;
                que.push('s');
            }
        }
        else{
            char c = que.front(); que.pop();
            if(s.at(i) == 'r'){
                if(c != 'p'){
                    ans += P; 
                    que.push('p');
                }
                if(i + k >= n) continue;
                if(c == 'p' && s.at(i + k) == 's') que.push('s');
                if(c == 'p' && s.at(i + k) == 'r') que.push('r');
                if(c == 'p' && s.at(i + k) == 'p') que.push('r');
            }
            else if(s.at(i) == 's'){
                if(c != 'r'){
                    ans += R; 
                    que.push('r');
                }
                if(i + k >= n) continue;
                if(c == 'r' && s.at(i + k) == 'p') que.push('p');
                if(c == 'r' && s.at(i + k) == 's') que.push('s');
                if(c == 'r' && s.at(i + k) == 'r') que.push('s');
            }
            else if(s.at(i) == 'p'){
                if(c != 's'){
                    ans += S; 
                    que.push('s');
                }
                if(i + k >= n) continue;
                if(c == 's' && s.at(i + k) == 'r'){
                    que.push('r');
                }
                if(c == 's' && s.at(i + k) == 's'){
                    que.push('p');
                }
                if(c == 's' && s.at(i + k) == 'p'){
                    que.push('p');
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,n,t,p=0,a,b;
    string s;
    cin>>a>>b;
    int ara[a];
   for(i=0;i<a;i++){
    cin>>ara[i];
   }
   sort(ara,ara+a);
   for(i=0;i<a-b;i++){
      p+=ara[i];
   }
   cout<<p<<endl;


    return EXIT_SUCCESS;
}




Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <functional>
#include <utility>




using namespace std;





int main(void){
    
    int N,A,B;
    scanf("%d%d%d",&N,&A,&B);
    printf("%d %d", min(A,B), max(0, A+B-N));
    
    return 0;
}


Measured memory_bytes: 256
path = [list(map(int, input().split(" "))) for i in range(3)]

yes = False
for i in range(3):
    for j in range(2):
        passed = [path[i][j], path[i][1-j]]
        for k in range(3):
            if i == k: continue
            if path[k][0] == passed[1]:
                passed.append(path[k][1])
            elif path[k][1] == passed[1]:
                passed.append(path[k][0])
            else: 
                continue
            last = list({0, 1, 2} - set([i, k]))[0]
            if passed[-1] in path[last] and set(passed + path[last]) == set(range(1, 5)):
                yes = True
                
if yes:
    print('YES')
else:
    print("NO")

Measured memory_bytes: 3064
H,W=list(map(int,input().split(' ')))
if W==1:
    print(1)
    exit()
if H==1:
    print(1)
    exit()
if W%2==1 and H%2==1:
    print((W//2+1)*(H//2+1)+(W//2)*(H//2))
if W%2==0 and H%2==1:
    print((W//2)*(H//2+1)+(W//2)*(H//2))
if W%2==1 and H%2==0:
    print((W//2+1)*(H//2)+(W//2)*(H//2))
if W%2==0 and H%2==0:
    print((W//2)*(H//2)+(W//2)*(H//2))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll MOD = 1000000007;

int minElement(int array[], size_t size) {
    assert(array != NULL);
    assert(size >= 1);

    int min = array[0];
    for (size_t i = 1; i < size; ++i) {
        if (min > array[i]) {
            min = array[i];
        }
    }

    return min;
}
template <class T>
void print(const T &value) {
    cout << value << endl;
}

int main() {
    int A, B, M;
    cin >> A >> B >> M;
    int a[A], b[B], x[M], y[M], c[M];
    rep(i, A) cin >> a[i];
    rep(i, B) cin >> b[i];
    rep(i, M) cin >> x[i] >> y[i] >> c[i];

    int min_a = minElement(a, ARRAY_LENGTH(a));
    int min_b = minElement(b, ARRAY_LENGTH(b));
    int min_val = min_a + min_b;
    int tmp;

    rep(i, M) {
        tmp = a[x[i] - 1] + b[y[i] - 1] - c[i];
        if (tmp < min_val) min_val = tmp;
    }
    cout << min_val << endl;

    return 0;
}

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

// 引数: A, B、返り値: i番目以降を足したもの、処理内容: i番目以降の逆順を求める

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

  vector<int> a(4);

  a.at(0) = N % 10;
  a.at(1) = (N / 10) % 10;
  a.at(2) = (N / 100) % 10;
  a.at(3) = (N / 1000) % 10;

  if(a.at(0) == a.at(1) ||  a.at(1) == a.at(2) ||  a.at(2) == a.at(3)){
    cout << "Bad" << endl;
  }else{
    cout << "Good" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int area = a*b;
        int length = 2 * (a+b);
        System.out.println(area + " " + length);
        sc.close();
    }
}


Measured memory_bytes: 26220