akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
using namespace std;
void file(){
	#ifndef ONLINE_JUDGE
    	freopen("tst.txt", "r", stdin);
	#endif	
}
const int N=3e5+5,MAX=3e7,MOD=1e9+7;

int n,b,d;
int a[500][500];
int ans;
bool check(int i,int j){
	int ret = 0;
	for(int k=0;k<d;k++){
		ret += (a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
	}

	double wa = sqrt(ret);

	return (wa==(int)floor(wa));	
}
int main()
{	
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 	//file();
    	
 	scanf("%d %d",&n,&d);

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

 	

 	for(int i=0;i<n;i++){
 		for(int j=i+1;j<n;j++){
 			ans+=check(i,j);
 		}
 	}

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


}

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

int main() {
  int h, w;
  int a[500][500];
  std::cin >> h >> w;

  for (int j = 0; j < h; j++) {
    for (int i = 0; i < w; i++) {
      std::cin >> a[j][i];
    }
  }

  std::vector<std::string> s;
  s.reserve(h * w);

  for (int j = 0; j < h; j++) {
    for (int i = 1; i < w; i++) {
      if (a[j][i - 1] % 2 == 1) {
        a[j][i - 1]--;;
        a[j][i]++;
        std::string str;
        str += std::to_string(j + 1);
        str += " ";
        str += std::to_string(i);
        str += " ";
        str += std::to_string(j + 1);
        str += " ";
        str += std::to_string(i + 1);
        s.push_back(std::move(str));
      }
    }
  }

  for (int j = 1; j < h; j++) {
    if (a[j - 1][w - 1] % 2 == 1) {
      a[j - 1][w - 1]--;
      a[j][w - 1]++;
      std::string str;
      str += std::to_string(j);
      str += " ";
      str += std::to_string(w);
      str += " ";
      str += std::to_string(j + 1);
      str += " ";
      str += std::to_string(w);
      s.push_back(std::move(str));
    }
  }

  std::cout << s.size() << std::endl;
  for (const auto &i : s) {
    std::cout << i << std::endl;
  }
  return 0;
}


Measured memory_bytes: 11904
#include <stdio.h>
const int MOD=1e8+7;
const int N=2e3+10;
typedef long long int ll;
ll f[N];
ll mul(ll a,ll b){return (a*b)%MOD;}
ll add(ll a,ll b){return (a+b)%MOD;}
ll pow(ll a,int t){
    ll ans=1;
    while(t){
        if(t&1)ans=mul(ans,a);
        a=mul(a,a);
        t>>=1;
    }
    return ans;
}
ll rev(ll n){return pow(n,MOD-2);}
ll C(int n,int m){return mul(f[n],mul(rev(f[n-m]),rev(f[m])));}
int min(int a,int b){return a>b?b:a;}
int abs(int n){return n>0?n:-n;}
void out(ll n){
    printf("%lld ",n);
    return ;
}
int main(){
    int r,c,a1,a2,b1,b2;
    f[0]=f[1]=1;
    for(int i=2;i<N;i++)f[i]=mul(i,f[i-1]);
    scanf("%d%d%d%d%d%d",&r,&c,&a1,&b1,&a2,&b2);
    if((abs(a1-a2)<<1)==r){
        if((abs(b1-b2)<<1)==c)printf("%lld\n",mul(4,C((r+c)>>1,r>>1)));
        else printf("%lld\n",mul(2,C((r>>1)+min(abs(b1-b2),c-abs(b1-b2)),r>>1)));
    }
    else{
        if((abs(b1-b2)<<1)==c)printf("%lld\n",mul(2,C((c>>1)+min(abs(a1-a2),r-abs(a1-a2)),r>>1)));
        else printf("%lld\n",C(min(abs(a1-a2),r-abs(a1-a2))+min(abs(b1-b2),c-abs(b1-b2)),min(abs(a1-a2),r-abs(a1-a2))));
    }
}


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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9
#define MAX 1000

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;

int main(){
    int N;
    cin >> N;
    ll A[N];
    Rep(i,N)cin >> A[i];
    int ans = 0;
    Rep(i,N-1){
        if(A[i] < A[i+1])ans++;
    }
    cout << ans << endl;
    //cin >> N;
}


Measured memory_bytes: 3868
from collections import deque
m=[[1,0],[-1,0],[0,1],[0,-1]]
h,w=map(int,input().split())
l=list()
l.append('#'*(w+2))
for i in range(h):
    j=input()
    l.append('#'+j+'#')
l.append('#'*(w+2))
def bfs(a,b):
  s=[[-1 for j in i] for i in l]
  s[a][b]=0
  q=deque([[a,b]])
  while len(q)>0:
    x,y=q.popleft()
    for i,j in m:
      if l[x+i][y+j]=='.' and s[x+i][y+j]==-1:
        q.append([x+i,y+j])
        s[x+i][y+j]=s[x][y]+1
        num = s[x+i][y+j]
  return num
ans = []
for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.':
      ans.append(bfs(i,j))
print(max(ans))

Measured memory_bytes: 9476
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>
#include <queue>
#include <map>

#define fir first
#define sec second
#define sz(s) (s).size()
#define pb push_back
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define prfi(n) printf("%d", &n);
#define prfd(n) printf("%lf", &n);
#define All(s) (s).begin(), (s).end()
#define rep(i,j) for(int (i)=0;(i)<(j);(i)++)
#define For(i,j,k) for(int (i)=(j);(i)<(k);(i)++)
#define repd(i,j) for(int (i)=(j);(i)>=0;(i)--)
#define Ford(i,j,k) for(int (i)=(j);i>=(k);i--)
#define vfor(c,v) for(auto (c): v)
#define dump(x)  std::cout << #x << " = " << (x) << std::endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using ll = long long;
using pii = std::pair<int,int>;
using vi = std::vector<int> ;
using vvi = std::vector<vi> ;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vd = std::vector<double> ;
using vvd = std::vector<vd> ;
using qi = std::queue<int> ;
using vpii = std::vector<std::pair<int, int> >;
using namespace std;

const int Mod = (1e9) + 7;
const int max_n = 3 * (1e5) + 1;
const int max_m = 83 * (1e5) + 1;
const int INF = 1e9 + 19;
const ll INFL = 1e18 + 19;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
//_____________________________________Templates_________________________________________//

template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}

//mainly use for dynamic prog
template<class T1, class T2>
void update(T1 &a, T2 b){
  a += b;
  if(a > Mod) a %= Mod;
}

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}
//_____________________　following sorce code_________________________//
int n,m,k;
ll M;
int x;
//vvll dp(400, vll(400));
string S;
vll cost(1 << 16);
int a,b,c;
int h,w;
vi v;
vll u;

bool check(){
}

int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  IN(n,x);
  v = vi(n);
  rep(i,n)IN(v[i]);
  ll ans = 0;
  ans += max(0, v[0]-x);
  chmin(v[0], x);
  For(i,1,n){
    int sum = v[i-1] + v[i];
    if(sum > x){
      ans += sum - x;
      v[i] -= (sum - x);
      //OUT(ans);
      //OUT(v[i]);
    }
  }
  cout << ans << endl;
  //cout << fixed << setprecision(15) << ans << endl;
  return 0;
}

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

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void test_case() {
  int n;
  cin >> n;
  vector<int> P(n + 1);
  int bad = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> P[i];
    if (P[i] != i) {
      ++bad;
    }
  }
  if (bad <= 2) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  test_case();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int a[200000];
int main()
{
    ios::sync_with_stdio(false);
    string s;cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='7') return cout<<"Yes"<<endl,0;
    }
    cout<<"No"<<endl;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int n;cin >> n;
    map<string,int> mp;
    rep(i,n) {
        string s;cin >> s;
        mp[s]++;
    }
    cout << mp.size() << endl;
}


Measured memory_bytes: 19228
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    lint N;
    cin >> N;
    vec<vec<lint>> is_open(N);
    range(i, 0, N) {
        vec<lint> store(10);
        range(j, 0, 10) cin >> store.at(j);
        is_open.at(i) = store;
    }
    vec<vec<lint>> profit(N);
    range(i, 0, N) {
        vec<lint> profit_of_this_store(11);
        range(j, 0, 11) cin >> profit_of_this_store.at(j);
        profit.at(i) = profit_of_this_store;
    }

    lint max_profit = -(1LL << 62);
    range(bits, 1, 1 << 10) {
        lint p = 0;
        range(store, 0, N) {
            lint num_common_days = 0;
            range(day, 0, 10) {
                if (((bits >> day) & 1) && is_open.at(store).at(day)) num_common_days += 1;
            }
            p += profit.at(store).at(num_common_days);
        }
        max_profit = max(max_profit, p);
    }
    cout << max_profit << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void){
    int count;
    char tarohmaru[101], hanakosan[101];
    int Tpoint = 0, HP = 0;
    scanf("%d", &count);
    
    for(int i=0; i<count; i++){
        scanf("%s %s", tarohmaru, hanakosan);
        if(strcmp(tarohmaru, hanakosan) < 0){
            HP += 3;
        }else if(0 < strcmp(tarohmaru, hanakosan)){
            Tpoint += 3;
        }else{
            Tpoint++;
            HP++;
        }
    }
    printf("%d %d\n",Tpoint, HP);
}


Measured memory_bytes: 2100
import java.util.ArrayList;
import java.util.Scanner;

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

        String str = sc.nextLine();
        String[] strArray = str.split(" ");

        String str0 = strArray[0];
        String str1 = strArray[1];

        String strNum = sc.nextLine();
        String[] intArray = strNum.split(" ");

        int num1 = Integer.parseInt(intArray[0]);
        int num2 = Integer.parseInt(intArray[1]);

        String strans = sc.nextLine();

        if(strans.equals(str0)) {
        	System.out.print(num1-1 + " ");
        	System.out.print(num2);
        }
        else {
        	System.out.print(num1 + " ");
        	System.out.print(num2 - 1);
        }


	}

}


Measured memory_bytes: 21588
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	string A,B,C;
	cin >> A >> B >> C;
	
	cout << A[0] << B[1] << C[2] << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
#ifndef TKLIB_SEGTREE_HPP
#define TKLIB_SEGTREE_HPP

#include <vector>
#include <functional>

namespace tklib {

template <typename T, typename Op = std::plus<T>>
class Segtree {
private:
    std::size_t N;
    std::vector<T> data;
    T idelem;
    const Op &op;

public:
    Segtree(std::size_t n, T idelem, const Op &op = Op())
    : N(1), idelem(idelem), op(op) {
        while(N < n) N <<= 1;
        data.assign(2 * N, idelem);
    }

    template <typename InputIt>
    Segtree(InputIt first, InputIt last, T idelem, const Op &op = Op())
    : N(1), idelem(idelem), op(op) {
        std::vector<T> buffer(first, last);
        while(N < buffer.size()) N <<= 1;
        data.assign(2 * N, idelem);
        std::swap_ranges(buffer.begin(), buffer.end(), data.begin() + N);
        for(int i = N - 1; i > 0; --i) data[i] = op(data[2 * i], data[2 * i + 1]);
    }

    void update(std::size_t pos, T val) {
        for(data[pos += N] = val; pos >>= 1; ) {
            data[pos] = op(data[pos << 1], data[(pos << 1) + 1]);
        }
    }

    T query(std::size_t left, std::size_t right) {
        T vl = idelem, vr = idelem;
        for(left += N, right += N; left < right; left >>= 1, right >>= 1) {
            if(left & 1) vl = op(vl, data[left++]);
            if(right & 1) vr = op(data[--right], vr);
        }
        return op(vl, vr);
    }

    T operator[](std::size_t k) {
        return data[k + N];
    }
};

} // nasmespace tklib

#endif // TKLIB_SEGTREE_HPP

#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int main() {
    int N; cin >> N;
    vector<pair<int, int>> X(N);
    for(int i=0; i<N; ++i) cin >> X[i].first >> X[i].second;
    sort(begin(X), end(X));

    int const mod = 998244353;
    vector<int> dp(N + 1, 1);

    auto op = [](int a, int b){return max(a, b);};
    tklib::Segtree<int, decltype(op)> st(N - 1, 0, op);
    
    for(int i=N-1; i>=0; --i) {
        int k = lower_bound(begin(X), end(X), pair<int, int>(X[i].first + X[i].second, 0)) - begin(X);
        st.update(i, max(k, st.query(i + 1, k)));
        dp[i] = (dp[i + 1] + dp[st[i]]) % mod;
    }

    cout << dp[0] << '\n';
}

Measured memory_bytes: 4608
def resolve():
    '''
    code here
    '''
    import collections
    
    N = int(input())
    b_list = [int(item) for item in input().split()]
    a = collections.deque()

    is_True = True

    while is_True:
        stack = collections.deque()
        for i in range(len(b_list)):
            if i+1 == b_list[i]:
                # print(b_list[i])
                stack.append(b_list[i])
                # print(stack)
        if len(stack) == 0:
            is_True = False
            a = [-1]
        else:
            temp = stack.pop()
            a.append(temp)
            del b_list[temp-1]
            # print(b_list)

        if len(b_list) == 0:
            is_True = False

    for i in reversed(a):
        print(i)
if __name__ == "__main__":
    resolve()


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

int main()
{
    ll r,D,x;
    cin >> r >> D >> x;

    for(int i = 1; i <= 10; i++)
    {
        x = r * x - D;
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>



const int MAX_M = 100050;

int N, M;
int L[MAX_M], R[MAX_M];

int main(int argc, char **argv) {
    std::cin >> N >> M;
    for (int i = 1; i <= M; i++) {
        std::cin >> L[i] >> R[i];
    }

    int left = 0;
    int right = N;

    for (int i = 1; i <= M; i++) {
        left = std::max(left, L[i]);
        right = std::min(right, R[i]);
    }

    if (left <= right) {
        std::cout << right - left + 1 << std::endl;
    } else {
        std::cout << 0 << std::endl;
    }

    return 0;
}



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

int main() {
  int H, W;
  bool loop = true;
  while (loop) {
    cin >> H >> W;
    if ((H == 0) && (W == 0)) {
      loop = false;
      continue;
    }
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
	if ((i == 0) || (i == H-1)) {
          cout << "#";
	} else {
	  if ((j == 0) || (j == W-1)) {
            cout << "#";
	  } else {
            cout << ".";
          }
        }
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
using namespace std;
int main(){
	int N, A; 
	cin >> N >> A;
	int L = A;
	int R = A + N - 1;
	 int eat;
	 if (R <= 0)eat = R;  else if (L >= 0)eat = L;  else eat = 0;
	 int answer = (R + L) * (R - L + 1) / 2 - eat;
	 cout << answer << endl;
	 return 0;

}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe

readInt = fst . fromJust . BS.readInt
readString = map BS.unpack . BS.words

getInt = readInt <$> BS.getLine
getString = readString <$> BS.getLine

check :: String -> String -> String
check [] as = as
check (s : ss) as = check ss as'
  where
    as'
      | s `elem` as = as
      | otherwise = s : as

calc :: String -> String -> Int -> Int
calc _ [] n = n
calc xs (y : ys) n
  | n' > n = calc (y : xs) ys n'
  | otherwise = calc (y : xs) ys n
  where
    n' = length (check (intersect xs (y : ys)) [])

main = do
  n <- getInt
  [s] <- getString
  print $ calc "" s 0


Measured memory_bytes: 892
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template

//main
signed main(){
  int H,W,N;cin>>H>>W>>N;
  int sy,sx;cin>>sy>>sx;
  string s,t;cin>>s>>t;
  int l=1,r=W;
  int out=0;
  for(int i=N-1;i>=0;i--){
    if(t[i]=='R')l--;
    if(t[i]=='L')r++;
    l=max(1LL,l);
    r=min(W,r);
    if(s[i]=='R')r--;
    if(s[i]=='L')l++;

    if(r<l)out++;
  }
  if(sx<l||sx>r)out++;
  l=1;r=H;
  for(int i=N-1;i>=0;i--){
    if(t[i]=='D')l--;
    if(t[i]=='U')r++;
    l=max(1LL,l);
    r=min(H,r);
    if(s[i]=='D')r--;
    if(s[i]=='U')l++;

    if(r<l)out++;
  }
  if(sy<l||sy>r)out++;
  if(out)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
}


Measured memory_bytes: 776
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
from itertools import accumulate
from bisect import bisect_left

if N==0:
    print(0)
elif N>0:
    even = [0, 1]
    for i in range(1, 21):
        even.append(2**(i*2))
    cum = list(accumulate(even))
    idx = bisect_left(cum, N)
    maxi = cum[idx]-cum[idx-1]
    val = N-cum[idx-1]
    ans = ['1']
    up = maxi
    for i in range(maxi.bit_length()-1):
        up //= 2
        if val>up:
            if i%2==0:
                ans.append('0')
            else:
                ans.append('1')
            val -= up
        else:
            if i%2==0:
                ans.append('1')
            else:
                ans.append('0')
    print(''.join(ans))
elif N<0:
    N = -N
    even = [0]
    for i in range(21):
        even.append(2**(i*2+1))
    cum = list(accumulate(even))
    idx = bisect_left(cum, N)
    maxi = cum[idx]-cum[idx-1]
    val = N-cum[idx-1]
    ans = ['1']
    up = maxi
    for i in range(maxi.bit_length()-1):
        up //= 2
        if val>up:
            if i%2==0:
                ans.append('0')
            else:
                ans.append('1')
            val -= up
        else:
            if i%2==0:
                ans.append('1')
            else:
                ans.append('0')
    print(''.join(ans))

Measured memory_bytes: 62484
N,K = map(int,input().split())
ans = 0
coin_num = 0 # コインを振る回数
for v in range(1,N+1):
    l_num = v
    while l_num < K:
        coin_num += 1
        l_num *= 2
    ans += (1/N) * (0.5 ** coin_num)
    coin_num = 0
print(ans)


Measured memory_bytes: 3188
import java.util.*;
import java.util.Collections;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = Integer.parseInt(sc.next(), 16);
    int B = Integer.parseInt(sc.next(), 16);
    if (A > B) {
      System.out.println(">");
    } else if (B > A) {
      System.out.println("<");
    } else {
      System.out.println("=");
    }
  }
}


Measured memory_bytes: 23892
N = int(input())
a_list = list(map(int, input().split()))

dp = [[0] * (N + 1) for _ in range(N + 1)]

for i in range(1, N + 1):
    for l in range(N + 1 - i):
        r = l + i
        dp[l][r] = max(a_list[l] - dp[l+1][r], a_list[r-1] - dp[l][r-1])

print(dp[0][N])


Measured memory_bytes: 113372
N=int(input())
A=list(map(int,input().split()))

sb=0
for i in range(N-1):
    if i%2==0:
        sb += A[i+1]-A[i]
sm =A[N-1]
ans=[sm-sb]

for j in range(N-1):
    ans.append(int((A[j]-ans[j]/2)*2))
print(' '.join(str(k) for k in ans))

Measured memory_bytes: 19148
// Best practice
 
#include<bits/stdc++.h>
 
#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define prec(n) 	fixed<<setprecision(n)
#define ini(a, i) 	memset(a, i, sizeof(a))
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;
 
#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define debugp(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<"("<<i.x<<","<<i.y<<")"<<" "; cout<< "]" << endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << "[" << *it << ": " << a << "]\t";
    err(++it, args...);
}
 
// const int dx[4] = { -1, 1, 0, 0};
// const int dy[4] = {0, 0, -1, 1};
// int dX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
// int dY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
 
 
// Code from Here -------------------------------------------------------------------------------

signed main() {
	tezz
 

	int n;
	cin >> n;
	int a[n];
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	int pre[n+1];
	pre[n]=0;
	for(int i=n-1; i>=0; i--){
		pre[i] = (pre[i+1] + a[i])%MOD;
	}
	int ans = 0;
	for(int i=0; i<n; i++){
		ans = (ans + (pre[i+1] * a[i])%MOD)%MOD;
	}
	cout << ans << endl;
 
	return 0;
}  

Measured memory_bytes: 6764
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

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

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

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define debug(x) cout << #x <<" = " << x << endl
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define printvpair(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i].first  <<" " << v[i].second << endl;
#define printv(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i] << " "; cout << endl;

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = 1000000000;

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

const int N = 100001;
int a[N];
int main() {
	ios_base::sync_with_stdio(0);
	int a,b;
	cin >> a >> b;
	if (a == b){
		cout << "Draw\n";
	}
	else
	if (a == 1){
		cout << "Alice"<< endl;
	}
	else
	if (b == 1){
		cout << "Bob"<< endl;
	}
	else
	if (a > b){
		cout << "Alice";
	}else {
		cout << "Bob\n";
	}
  	return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())

using LL = long long;
template<class T, size_t D>
struct vec : vector<vec<T, D - 1>> {
  template<class... Args>
  vec(size_t n = 0, Args... args)
    : vector<vec<T, D - 1>>(n, vec<T, D - 1>(args...)) {}
};
template<class T>
struct vec<T, 1> : vector<T> {
  template<class... Args>
  vec(Args... args)
    : vector<T>(args...) {}
};

template<class T>
inline bool asMn(T& a, const T& b) { return a > b ? a = b, true : false; }
template<class T>
inline bool asMx(T& a, const T& b) { return a < b ? a = b, true : false; }
inline int nex(int i, int n) { return i == n - 1 ? 0 : i + 1; }
inline int pre(int i, int n) { return !i ? n - 1 : i - 1; }

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

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

  string s; cin >> s;
  vec<int, 2> f(sz(s), 2, -1);
  vec<bool, 2> trace(sz(s), 2, -1);
  if (s[0] == 'P' || s[0] == '?') {
    f[0][0] = 0;
  }
  if (s[0] == 'D' || s[0] == '?') {
    f[0][1] = 1;
  }

  for (int i = 0; i + 1 < sz(s); ++i) {
    for (int j = 0; j < 2; ++j) {
      if (~f[i][j]) {
        if (s[i + 1] == 'P' || s[i + 1] == '?') {
          if (asMx(f[i + 1][0], f[i][j])) {
            trace[i + 1][0] = j;
          }
        }
        if (s[i + 1] == 'D' || s[i + 1] == '?') {
          if (asMx(f[i + 1][1], f[i][j] + 1 + !j)) {
            trace[i + 1][1] = j;
          }
        }
      }
    }
  }

  string ans;
  for (int i = sz(s) - 1, j = f.back()[0] > f.back()[1] ? 0 : 1; ~i; --i) {
    ans += (j ? 'D' : 'P');
    j = trace[i][j];
  }
  reverse(all(ans));

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 28796
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>

using namespace std;
typedef long long lint;

const int MAXN = 2222;
int dp[MAXN][MAXN];
int maxDP[MAXN];
int minDP[MAXN];

int main() {
    int N, Z, W;
    cin >> N >> Z >> W;
    vector<int> a(N+1);
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
    }
    const auto A = [&](int i, char c) {
        if (i == 0) {
            return (c == 'X' ? Z : W);
        } else {
            return a[i];
        }
    };
    for (int y = N; y >= 0; y--) {
        for (int x = N; x >= 0; x--) {
            if (x == N || y == N) {
                dp[x][y] = abs(A(x, 'X') - A(y, 'Y'));
                if (x <= y) minDP[x] = dp[x][y];
                else maxDP[y] = dp[x][y];
            } else {
                if (x <= y) {
                    dp[x][y] = maxDP[y];
                    minDP[x] = min(minDP[x], dp[x][y]);
                } else {
                    dp[x][y] = minDP[x];
                    maxDP[y] = max(maxDP[y], dp[x][y]);
                }
            }
        }
    }
    cout << dp[0][0] << endl;
    return 0;
}

Measured memory_bytes: 18688
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define input(a,n) fr(i,0,n)cin>>a[i]
#define output(a,n) fr(i,0,n)cout<<a[i]<<" "
#define dbg cout<<"hurr"<<endl;
#define dbg2 cout<<"hurr2"<<endl;
#define md 1000000007
#define sp << " " <<
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);

int main()
{
    fast;
    ll n,w;
    cin >> n >> w;
    ll a[n+1],v[n+1],dp[n+1][w+1];
    fr(i,1,n+1)
        cin >> a[i] >> v[i];
    fr(i,0,n+1)
    {
        fr(j,0,w+1)
        {
            if(j==0 || i==0)
                dp[i][j]=0;
            else if(a[i]<=j)
                dp[i][j]=max( dp[i-1][j],dp[i-1][j-a[i]] + v[i] );
            else
                dp[i][j]=dp[i-1][j];
        }
    }
    cout << dp[n][w];
}

Measured memory_bytes: 79232
#include <iostream>

using namespace std;

int main(){
  int a, b, cnt, sum, cntSum;
  char c;
  cnt = sum = cntSum = 0;
  while(cin >> a >> c >> b){
    sum += a*b;
    cntSum += b;
    cnt++;
  }
  cout << sum << endl << (int)(((double)cntSum / (double)cnt)+0.5) << endl;
  return 0;
}

Measured memory_bytes: 1160
until (n = gets.to_i).zero?
  data = n.times.map {gets.chomp.split}
  scores = data.map {|n, *r| [n, r.count("0"), r.count("1")]}
               .sort {|a, b| (b[1] <=> a[1]).nonzero? || a[2] <=> b[2]}
  puts scores.map(&:first)
end


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

const int N = 2 * 1000 + 20;
int n, x, y, ans[N];

int dist(int i, int j) {
	return min(i - j, min(abs(i - x) + abs(j - y), abs(i - y) + abs(j - x)) + 1);
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> x >> y;
	x--;
	y--;
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++)
			ans[dist(j, i)]++;
	for (int i = 1; i < n; i++)
		cout << ans[i] << endl;
	return 0;
}


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


def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

def solve(A: int, B: int):
    print(A*B//gcd(A,B))
    return


# Generated by 1.1.6 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()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <cstdio>
 
#define NIL -1
const int MAX_N = 100000 + 5;
 
struct Node {
  int p, lc, rs;
};
 
Node node[MAX_N];
int n;
int id, k, c;
int d[MAX_N];
 
void setDepth(int i, int num) {
  d[i] = num;
  if (node[i].rs != NIL) setDepth(node[i].rs, num);
  if (node[i].lc != NIL) setDepth(node[i].lc, num + 1);
}
 
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    node[i].p = node[i].lc = node[i].rs = NIL;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &id, &k);
    int ls;
    for (int j = 0; j < k; j++) {
      scanf("%d", &c);
      node[c].p = id;
      if (j == 0) node[id].lc = c;
      else node[ls].rs = c;
      ls = c;
    }
  }
 
  for (int i = 0; i < n; i++) {
    if (node[i].p == NIL) {
      setDepth(i, 0);
      break;
    }
  }
   
  for (int i = 0; i < n; i++) {
    printf("node %d: parent = %d, depth = %d, ", i, node[i].p, d[i]);
    if (node[i].p == NIL) printf("root, ");
    else if (node[i].lc == NIL) printf("leaf, ");
    else printf("internal node, ");
    printf("[");
    for (int j = 0, c = node[i].lc; c != NIL; j++, c = node[c].rs) {
      if (j) printf(", ");
      printf("%d", c);
    }
    printf("]\n");
  }
  return 0;
}

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

int main(){
    int n, m, s;
    cin >> n >> m;
    vector<int> b(m);
    vector<vector<int>> a(n , vector<int>(m));
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> a.at(i).at(j);
        }
    }
        for(int i = 0; i < m; i++){
        cin >> b.at(i);
    }
    for (int i = 0; i < n; i++){
        int s = 0;
        for(int j = 0; j < m; j++){
          s +=  a.at(i).at(j) * b.at(j);
        }
        cout << s << endl;
    }
}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

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

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( a > b ) { a = b; return 1; } return 0; }

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

vector<int> G[100001];
int seenb[100001] = {};
int seenw[100001] = {};
int N;
int black = 0;
int white = 0;
int cnt = 0;

void dfsb( int v, int prev ){
    seenb[v] = cnt;
    for( auto nv : G[v] ){
        if( seenb[nv] || nv == 0 || nv == N - 1 ) continue;
        black++;
        cnt++;
        dfsb( nv, nv );
    }
    cnt--;
}

void dfsw( int v, int prev ){
    seenw[v] = cnt;
    for( auto nv : G[v] ){
        if( seenw[nv] || nv == 0 || nv == N - 1 ) continue;
        white++;
        cnt++;
        dfsw( nv, nv );
    }
    cnt--;
}

signed main(){
    cin >> N;
    REP( i, N - 1 ){
        int from, to; cin >> from >> to;
        from--, to--;
        G[from].push_back( to );
        G[to].push_back( from );
    }

    dfsb( 0, 0 );
    cnt = 0;
    dfsw( N - 1, N - 1 );

    int bt_w, bt_b;
    bt_w = bt_b = 0;
    REP( i, 100001 ) {
        if( seenw[i] && seenb[i] ){
            if( seenw[i] >= seenb[i] ) bt_b++;
            else bt_w++;
        }
    }

    if( bt_b + black <= bt_w + white ) cout << "Snuke" << endl;
    else cout << "Fennec" << endl;

}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
int32_t main()
{
  int n;
  cin>>n;
  int a[n],b[n],c[n];
  for(int i=0;i<n;i++)
  cin>>a[i];
  for(int i=0;i<n;i++)
  cin>>b[i];
  for(int i=0;i<n;i++)
  cin>>c[i];
  sort(a,a+n);
  sort(b,b+n);
  sort(c,c+n);
  // for(auto i:a)
  // cout<<i<<" ";
  // cout<<endl;
  // for(auto i:b)
  // cout<<i<<" ";
  // cout<<endl;
  // for(auto i:c)
  // cout<<i<<" ";
  // cout<<endl;
  int pre[n+1];
  pre[0]=0;
  
  for(int i=0;i<n;i++)
  {
     int y=n-(upper_bound(c,c+n,b[i])-c);
     pre[i+1]=y;
  }
  for(int i=1;i<=n;i++)
  pre[i]+=pre[i-1];
 
  int ans=0;
  for(int i=0;i<n;i++)
  {
    int p=(upper_bound(b,b+n,a[i])-b);
    ans+=pre[n]-pre[p];   
  
    }
    
  
  
  cout<<ans<<endl;
}

Measured memory_bytes: 6748
using System;

class CF2016RA
{
	static public void Main(string[] args)
	{
		double R1, R2;
		string[] vals = Console.ReadLine().Split(' ');
		R1 = double.Parse(vals[0]);
		R2 = double.Parse(vals[1]);
		Console.WriteLine((R1 * R2) / (R1 + R2));
	}
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define REP(i,n) for (long long i=0;i<(n);i++)
using namespace std;
template<typename V,typename Weight>
class Dijekstra {
private:
	struct edge {
		Weight dist;V node;V prev;
		bool operator<(edge const& a) const {
			return dist < a.dist;
		}
		bool operator>(edge const& a) const {
			return dist > a.dist;
		}
	};
	//vector<V> trace;
	vector<vector<pair<V,Weight>>> E;
	V sz;
public:
	Weight inf = numeric_limits<Weight>::max();
	vector<Weight> D;
	Dijekstra(V v) :
		E(v),sz(v),D(v,inf) {}

	void inline addEdgeDirected(V from,V to,Weight dis){
		E[from].push_back(make_pair(to,dis));
	}
	void inline addEdgeUndirected(V from,V to,Weight dis){
		E[from].push_back(make_pair(to,dis));
		E[to].push_back(make_pair(from,dis));
	}

	V size() {return sz;}
	Weight & operator[] (V n) { if (0 <= n && n < sz) return D[n];} 

	void dijekstra(V start){
		priority_queue<pair<Weight,V>,vector<pair<Weight,V>>,greater<pair<Weight,V>>> que;
		D[start] = 0;
		que.push(make_pair(0,start));
		while(!que.empty()){
			pair<Weight,V> cur = que.top();que.pop();
			Weight d = cur.first;
			V v = cur.second;
			if (D[v] < d) continue; //既により最適が見つかっている
			for(V i = 0;i < E[v].size();i++){
				V next = E[v][i].first;
				Weight newCost = d + E[v][i].second;
				if (D[next] > newCost) {
					D[next] = newCost;
					que.push(make_pair(newCost,next));
				}
			}
		}
	}
/*
	vector<V> show_trace(V start,V goal){ // startからgoalの最短距離上のノード
		vector<V> ret;
		for (V node = goal;node != start;node = trace[node]) ret.push_back(node);
		ret.push_back(start);
		return ret; // 配列の先頭がgoal,末尾がstart
	}
*/
};

int main(void){
	long V,E,R;
	long s,t,d;
	cin >> V >> E >> R;
	Dijekstra<long,long> dij(V);

	REP(i,E){
		cin >> s >> t >> d;
		dij.addEdgeDirected(s,t,d);
	}
	dij.dijekstra(R);
	REP(i,V) {
		if (dij[i] == dij.inf) cout << "INF" << endl;
		else cout << dij[i] << endl;
	}

	return 0;
}





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

using namespace std;

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

int main()
{
  int a, L;
  while(cin >> a >> L, (a|L)) {
    map<int, int> m;
    int idx = 0;
    for(;;) {
      string str = to_string(a);
      if( m.find(a) != m.end() ) {
        int v = m[a];
        cout << v << " " << a << " " << (idx - v) << endl;
        break;
      }
      m[a] = idx++;

      while(str.size() < (unsigned long)L) {
        str.append("0");
      }

      string left( str ); sort(left.begin(), left.end(), greater<char>());
      string right( str ); sort(right.begin(), right.end());

      a = stoi(left) - stoi(right);
    }
  }

  return 0;
}

Measured memory_bytes: 1260
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  struct node *next;
  struct node *prev;
  unsigned int key;
};

typedef struct node *Nodepointer;

Nodepointer nil;

Nodepointer listsearch(int);
void init(void);
void printList(void);
void deleteNode(Nodepointer);
void deleteFirst(void);
void deleteLast(void);
void delete(int);
void insert(int);



int main(){
  int key,n,i;
  int size = 0;
  char com[20];
  int np=0 , nd=0;
  scanf("%d",&n);
  init();
  for(i=0;i<n;i++){
    scanf("%s %d",com,&key);
    if(com[0] == 'i'){insert(key); np++; size++;}
    else if(com[0] == 'd'){
      if(strlen(com) > 6){
	if(com[6] == 'F') deleteFirst();
	else if(com[6] == 'L') deleteLast();
      } else {
	  delete(key); nd++;
      }
      size--;
    }
  }

    printList();
    return 0;
}



void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}


void printList(){
  Nodepointer cur = nil->next;
  int isf =1;
  while(1){
    if(cur == nil){
      break;
    }
    if(isf == 0){
      printf(" ");
    }
    printf("%d",cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}


void deleteNode(Nodepointer t){
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  Nodepointer t = nil->next;
  if(t == nil){
    return;
  }
  deleteNode(t);
}

void deleteLast(){
  Nodepointer t = nil->prev;
  if(t == nil){
    return;
  }
  deleteNode(t);
}

void delete(int key){
  Nodepointer t=listsearch(key);
  if(t == NULL){
    return;
  }
  deleteNode(t);
}

void insert(int key){
  Nodepointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

Nodepointer listsearch(int key){
  Nodepointer cur;
  for(cur = nil->next;cur!=nil;cur=cur->next){
    if(cur->key == key){
      return cur;
    }
  }
  return NULL;
}



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

const int N = 1e5+10;
int a[N],b[N];
int val[N];
int main(){
    int n,m;
    cin >> n >> m;
    int ok = 1;
    for(int i=1;i<=n;++i)  val[i] = -1;
    for(int i=1;i<=m;++i){
        cin >> a[i] >> b[i];
        if(val[a[i]] == -1 || val[a[i]]==b[i]) val[a[i]] = b[i];
        else ok = 0;
    }
    if(val[1] == 0 && n!=1) ok = 0;
    if(!ok){
        cout << "-1\n";
    }
    else{
        if(n==1){
            if(val[1] == -1)    cout << 0;
            else cout << val[1];
            return 0;
        }

        if(val[1]==-1)  cout << 1;
        else cout << val[1];
        for(int i=2;i<=n;++i){
            if(val[i]!=-1)  cout << val[i];
            else cout << 0 ;
        }
        cout << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007
#define INF 1000000000000
#define EPS 0.00000000001
typedef long long ll;

ll power(ll x, ll y) // x^y
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
        {
            res = res * x % MOD;
        }
        x = x * x % MOD;
        y >>= 1;
    }
    return res;
}

ll comb(ll n, ll k) // nCr
{
    k = min(k, n - k);
    ll nnn = 1;
    for (ll i = n - k + 1; i <= n; i++)
    {
        nnn *= i;
        nnn %= MOD;
    }
    ll kkk = 1;
    for (ll i = 1; i <= k; i++)
    {
        kkk *= i;
        kkk %= MOD;
    }
    return (nnn * power(kkk, MOD - 2)) % MOD;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    //---------------------------------------------

    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n){
        cin>>a[i];
    }
    sort(rall(a));
    int ans=0;
    int memo=0;
    int wo;
    Rep(i,1,n){
        memo=ans;
        ans=max(ans,min(a[i],a[0]-a[i]));
        if(ans!=memo){
            wo=a[i];
        }
    }
    cout<<a[0]<<" "<<wo<<endl;
}


Measured memory_bytes: 640
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>
using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	if(b%a==0){
		cout<<a+b<<endl;
	}else{
		cout<<b-a<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int n,d,a;
int main()
{
	cin>>n>>d>>a;
	int ans=0;
	while(n--)
	{
		int x;
		cin>>x;
		if(d%x==0)
		ans+=d/x;
		else
		ans+=d/x+1;
	}
	cout<<ans+a;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

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();
		}
		
		long sum = Math.abs(a[0])+ Math.abs(a[n-1]);
		for(int i=1;i<n;i++){
			sum+=Math.abs(a[i]-a[i-1]);
		}
		
		StringBuilder sb = new StringBuilder();
		sb.append(sum-Math.abs(a[0])-Math.abs(a[1]-a[0]) + Math.abs(a[1])+"\n");
		for(int i=1;i<n-1;i++){
			sb.append(sum-Math.abs(a[i]-a[i-1])-Math.abs(a[i+1]-a[i])+Math.abs(a[i+1]-a[i-1])+"\n");
		}
		sb.append(sum-Math.abs(a[n-1])-Math.abs(a[n-2]-a[n-1]) + Math.abs(a[n-2])+"\n");
		System.out.print(sb);
	}
}

Measured memory_bytes: 64080
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int main(void){
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	for(int i = 0; i < N; i++) cin >> A[i];
	vector<P> vec(M);
	for(int i = 0; i < M; i++){
		int B, C;
		cin >> B >> C;
		vec[i] = P(C, B);
	}

	sort(A.begin(), A.end());
	sort(vec.begin(), vec.end(), greater<P>());

	int i = 0;
	for(int j = 0; j < M; j++){
		for(int k = 0; k < vec[j].second; k++){
			if(i+k >= N) break;
			if(A[i+k] < vec[j].first) A[i+k] = vec[j].first;
		}
		i += vec[j].second;
		if(i >= N) break;
	}

	ll res = accumulate(A.begin(), A.end(), 0LL);
	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n, a, b;
  cin >> n >> a >> b;

  n %= 12;
  rep(i, n) {
    if ((i+1)&1) {
      a = a-b;
    } else {
      b = a+b;
    }
  }

  cout << a << " " << b << endl;
}



Measured memory_bytes: 3212