akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n)   for (int i = 0; i < (n); i++)
#define sz(x)       (int)(x).size()
#define eb          emplace_back
#define pb          push_back
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

const int y = 2019;
const int ivy = 202;
int f[2019];

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

    string s;
    cin >> s;

    ll cnt = 0;
    int mult = 1, off = 0;
    for (char c : s) {
        int i = c - '0';
        off = (off - mult * i % y + y) % y;
        f[(off + mult * i) % y]++;
        cnt += f[off];
        mult = mult * ivy % y;
    }
    cout << cnt;

    return 0;
}


Measured memory_bytes: 3656
import java.util.HashSet;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int n;
        Scanner scanner=new Scanner(System.in);
        int[][] A=new int[3][3];
        for(int j=0;j<3;j++){
            for(int i=0;i<3;i++){
                A[j][i]=scanner.nextInt();
            }
        }
        n=scanner.nextInt();
        HashSet<Integer> hashSet=new HashSet<>();
        for(int j=0;j<n;j++){
            int ss=scanner.nextInt();
            hashSet.add(ss);
        }
        int ff=0;
        for(int j=0;j<3;j++){
            int is=0;
            for(int i=0;i<3;i++){
                if(hashSet.contains(A[j][i])){
                    is++;
                }

            }
            if(is==3){
                ff=1;
                break;
            }
        }
        if(ff==1){
            System.out.println("Yes");
        }
        else{
            for(int j=0;j<3;j++){
                int is=0;
                for(int i=0;i<3;i++){
                    if(hashSet.contains(A[i][j])){
                        is++;
                    }
                }
                if(is==3){
                    ff=1;
                    break;
                }
            }
            if(ff==1){
                System.out.println("Yes");
            }
            else{
                int aa=A[0][0];
                int bb=A[1][1];
                int cc=A[2][2];
                if(hashSet.contains(aa) && hashSet.contains(bb) && hashSet.contains(cc)){
                    System.out.println("Yes");
                }
                else{
                    aa=A[0][2];
                    bb=A[1][1];
                    cc=A[2][0];
                    if(hashSet.contains(aa) && hashSet.contains(bb) && hashSet.contains(cc)){
                        System.out.println("Yes");
                    }
                    else{
                        System.out.println("No");
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 25044
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem0576 : Homework **/
int main()
{
	int L, A, B, C, D;
	cin>>L>>A>>B>>C>>D;
	int t = max(ceil((double)A/C), ceil((double)B/D));
	cout << L-t << endl;
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  // int n;
  // std::cin >> n;
  // std::vector<long long> l(n);
  // for(int i = 0; i < n; i++)
  // {
  //   std::cin >> l[i];
  // }
  // std::sort(l.begin(), l.end());
  
  int n; cin >> n;
  vector<long long> l(n);
  for (int i = 0; i < n; ++i) cin >> l[i];
  sort(l.begin(), l.end()); // L をソートしておく (二分探索に必要)

  // long long res = 0;
  
  // long long ans = 0;
  // for(int i = 0; i < n; ++i)
  // {
  //   for(int j = i+1; j < n; ++j)
  //   {
  //     // int k = std::distance(l.begin(),std::lower_bound(l.begin(), l.end(), l[i]+l[j]));
  //     int k = std::lower_bound(l.begin(), l.end(), l[i] + l[j]) - l.begin();

  //     ans += std::max(k-(j+1),0);
  //   }
  // }
  // std::cerr << ans << std::endl;
  long long ans = 0;
    
  // a と b を固定
  for (int i = 0; i < n; ++i) {
      for (int j = i+1; j < n; ++j) {
          // c の動ける範囲の右端を求める
          int k = std::lower_bound(l.begin(), l.end(), l[i] + l[j]) - l.begin();

          // c の動ける範囲は、[j+1, k)
          ans += std::max(k - (j+1), 0);
      }
  }
  cout << ans << endl;
}




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

int main(void) {
  int A, B;
  cin >> A >> B;

  int answer = 0;
  for (int a = 1; a <= 9; a++) {
    for (int b = 0; b <= 9; b++) {
      for (int c = 0; c <= 9; c++) {
        int x = 10001*a + 1010*b + 100*c;

        if (x >= A && x <= B) {
          answer++;
        }
      }
    }
  }

  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
 
using ull = unsigned long long int;
using ll = long long int;
using du = double;
using ld = long du;
using vi = vector<int>;
using vll = vector<ll>;
using vld = vector<ld>;
using vdu = vector<du>;
using vs = vector<string>;
using vc = vector<char>;
using si = set<int>;
using sll = set<ll>;
using sdu = set<du>;
using sld = set<ld>;
using pii = pair<int, int>;
using pll = pair<ll,ll>;
using pdu = pair<du,du>;
using pld = pair<ld,ld>;
using pis = pair<int,string>;
 
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define sp(x) setprecision(x)<<fixed
#define loop(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pi acos(-1)
#define meme(a,x) memset(a,x,sizeof(a))
#define all(a) a.begin(),a.end()
 
//debugger
 
#ifdef KAIZER
#include "debug.h"
#else
#define debug(x...)
#endif
//debugger
 
//functions
bool check_pow(ll a)
{
    if((a&(a-1))==0) return true;
    else return false;
}
ld my_pow(ld a,int b)
{
    ld ans=1;
    for(int i=0;i<b;i++) ans*=a;
    return ans;
}
ll digits(ll a)
{
    string line=to_string(a);
    return line.size();
}
bool prime_check(ll a)
{
    bool flag=true;
    for(ll i=2;i<=sqrt(a);i++)
    {
        if(a%i==0) {flag=false; break;}
    }
    return flag;
}
bool comp(const pair<int,int> &a , const pair<int,int> &b)
{
    if(a.ff!=b.ff) return a.ff>b.ff;
    else return a.ss<b.ss;
}
bool comp2(const ll &a, const ll &b)
{
     return a>b;
}
 
//functions

int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    FASTIO;
    ll a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c)
    {
        if(a%2) cout<<"0\n";
        else cout<<"-1\n";
    }
    else
    {
        ll cnt=0;
        ll x,y,z;
        while(a%2==0&&b%2==0&&c%2==0)
        {
            x=a;y=b;z=c;
            a=(y/2)+(z/2);
            b=(x/2)+(z/2);
            c=(x/2)+(y/2);
            cnt++;
        }
        cout<<cnt<<endl;
    }
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << '\n'

typedef long long int ll;
typedef pair<int, int> P;

const long long INF = 3e18 + 12;
const int inf = 1e9;

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

  ll n;
  cin >> n;

  ll a = sqrt(n);

  cout << a * a << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    int a[n];
    int ans = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        while (a[i] > 0) {
            if (a[i] % 2 == 0) {
                a[i] /= 2;
                ans++;
            } else {
                break;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, A;
	cin >> N >> A;

	if (N % 500 <= A)cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

Measured memory_bytes: 256
# !/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/C-DiceandCoin.py
#
import math
n, k = map(int, input().split())

# p = (1/n) * (1 - (1/2)**(math.ceil(k/n)))
# if n < k:
#     p -= (1/n) * (1 - (1/2)**(math.ceil(k/n)-n))
# if k <= n:
#     p += (1/n) * (n-k+1)
#
# print(p)
ans = 0
p = 0

for i in range(1, n+1):
    score = i
    p = 1/n
    while score < k:
        p *= (1/2)
        score *= 2
        # print(score)
    ans += p

print(ans)






Measured memory_bytes: 2940
/**
* Think twice, code once.
* 1.integer overflow(maybe even long long overflow : (a+b >= c) -> (a >= c-b)
* 2.runtime error
* 3.boundary condition
* ---------------------------------------------------------------------------------------
* Author : zzy
* Date : 2020-03-20-04.16.23 Thursday
*/
#include <bits/stdc++.h>

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 4000;
int dp[maxn][maxn];
char s[maxn], t[maxn];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    ms(dp, 0);
    cin >> (s+1);
    cin >> (t+1);
    int sl = strlen(s+1);
    int tl = strlen(t+1);
    int goal = 1;
    string ans = "";
    for (int i = 1; i <= sl; ++i) {
        for (int j = 1; j <= tl; ++j) {
            dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
            if (s[i] == t[j]) dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1);
        }
    }
    //cout << dp[sl][tl] << endl;
    int x = sl, y = tl;
    while (x > 0 && y > 0) {
        if (dp[x][y] == dp[x-1][y]) --x;
        else if (dp[x][y] == dp[x][y-1]) --y;
        else {
            ans += s[x];
            --x;
            --y;
        }
    }
    reverse(all(ans));
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 62848
package main
import (
	"fmt"
	"math"
	"bufio"
	"os"
	"strconv"
)

func main(){
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for scanner.Scan(){
		n, _ := strconv.Atoi(scanner.Text())
		if n==0{
			break
		}
		ns := make([]int, n)
		for i:=0; i<n; i++{
			scanner.Scan()
			a, _ := strconv.Atoi(scanner.Text())
			ns[i] = a
		}
		stddev := math.Sqrt(disperse(ns, average(ns)))
		fmt.Println(stddev)
	}
}

func disperse(ns []int, m float64)(ret float64){
	for _, v := range ns{
		ret += math.Pow(float64(v)-m, 2.0)
	}
	return ret/float64(len(ns))
}

func average(ns []int)(ret float64){
	for _, v := range ns{
		ret+=float64(v)
	}
	return ret/float64(len(ns))
}


Measured memory_bytes: 1120
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
  int n,b,c,cou;
  cou=10000;
  b=c=0;
  cin >> n ;
  vector <int>a(n+1);
  for (int i=1;i<=n;i++){
    cin >> a.at(i);
    b+=a.at(i);
  }
  for (int i=1;i<=n;i++){
   b=b-a.at(i);
    c+=a.at(i);
      if(abs(c-b)<cou)
        cou=abs(c-b);
  }
  cout << cou << endl;
}

Measured memory_bytes: 256
from collections import deque



H,W = map(int, input().split())
S = [input() for _ in range(H)]

ans = 0
dyx = [(1,0), (0,1),(-1,0), (0,-1)]
for i in range(H):
    for j in range(W):
        if S[i][j] == "#": continue
        dist = [[0 for _ in range(W)] for _ in range(H)] 
        visited = [[False for _ in range(W)] for _ in range(H)]
        visited[i][j] = True
        q = deque()
        q.append((i,j))
        while q:
            y,x = q.popleft()
            for dy,dx in dyx:
                ny, nx = y+dy, x+dx
                if not 0 <= ny <= H-1 or not 0 <= nx <= W-1 or visited[ny][nx] == True or S[ny][nx] == "#":
                    continue
                q.append((ny, nx))
                dist[ny][nx] = dist[y][x] + 1
                visited[ny][nx] = True


        ans = max(ans, max(max(row) for row in dist))

            

print(ans)

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

using namespace std;

const int N=1e6+3;

const double eps=0.000000001;

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

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

const int inf=1e9,mod=1e9+7;

int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans;

char s[N];

void IO(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("test.txt","r",stdin);
	#endif
}

int main(){
	//IO();
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&x);
		if (x&1)
			continue;
		if ((x%3) !=0 && (x%5) !=0)
			return !printf("DENIED\n");
	}
	printf("APPROVED\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++) 

int main() {
    int N, A[30], B[30], C[30];
    cin >> N;
    rep1(i,N) cin >> A[i];
    rep1(j,N) cin >> B[j];
    rep1(k,N-1) cin >> C[k];

    int ans = B[A[1]];
    for (int i = 2; i <= N; i++) {
        if (A[i] == A[i-1]+1) {
            ans += (B[A[i]] + C[A[i]-1]);
        } else {
            ans += B[A[i]];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import collections
 
# A = input()
# A = int(input())
# A = map(int, input().split())
# A = list(map(int, input().split()))
# A = [int(input()) for i in range(N)]
#
# c = collections.Counter()
 
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [tuple(map(int, input().split())) for i in range(M)]
 
cl = collections.Counter(A)
BC += [(cl[key], key) for key in cl]
BC = sorted(BC, key=lambda x: -x[1])
 
c = 0
total = 0
for (n, key) in BC:
  if (c + n) < N:
    c += n
    total += key * n
  else:
    total += key * (N - c)
    break

print(total)

Measured memory_bytes: 99736
use proconio::input;

const MOD: usize = 1000_000_007;

fn main() {
    input! {
        n: usize,
        arr: [usize; n],
    }

    let mut sum: usize = (&arr).iter().fold(0, |acc, val| (acc+val)%MOD );
    let mut ans: usize = 0;
    for a in arr {
        sum = (sum+MOD-a)%MOD;
        ans = (ans + (sum*a)) % MOD;
    }
    println!("{}", ans);
}


Measured memory_bytes: 5536
#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 pb emplace_back
typedef long long ll;
typedef pair<ll,ll> pint;

int main(){
    int n;
    cin>>n;
    int mn=1000100010;
    FOR(i,1,n){
        int a=i,b=n-i;
        int sum=0;

        while(a){
            sum+=a%10;
            a/=10;
        }
        while(b){
            sum+=b%10;
            b/=10;
        }
        mn=min(sum,mn);
    }
    cout<<mn<<endl;
    return 0;
}

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

int main() {
  ll n; cin >> n;
  ll ans;
  for(ll i = n; i<(n+111); i++){
    if(i%111==0) ans+=i;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
/**
 *  author: MOOONI
 *  hackers are welcome!
**/
#include <bits/stdc++.h>

#define int long long

using namespace std;

template<typename T>
void debug_out(T x) {
  cerr << x;
}

template<typename A>
void debug_out(vector<A> v) {
  cerr << '{';
  for (int i = 0; i < (int) v.size(); i++) {
    if (i) {
      cerr << ", ";
    }
    debug_out(v[i]);
  }
  cerr << '}';
}

template <typename A, typename B>
void debug_out(pair<A, B> p) {
  cerr << '(';
  debug_out(p.first);
  cerr << ", ";
  debug_out(p.second);
  cerr << ')';
}

template <typename A, typename B, typename C>
void debug_out(tuple<A, B, C> p) {
  cerr << '(';
  debug_out(get<0>(p));
  cerr << ", ";
  debug_out(get<1>(p));
  cerr << ", ";
  debug_out(get<2>(p));
  cerr << ')';
}

template <typename A, typename B, typename C, typename D>
void debug_out(tuple<A, B, C, D> p) {
  cerr << '(';
  debug_out(get<0>(p));
  cerr << ", ";
  debug_out(get<1>(p));
  cerr << ", ";
  debug_out(get<2>(p));
  cerr << ", ";
  debug_out(get<3>(p));
  cerr << ')';
}

template <size_t N>
void debug_out(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  cerr << res;
}

template <typename T>
void debug_with_endl(T v) {
  debug_out(v);
  cerr << endl;
}

template <typename Head, typename... Tail> 
void debug_with_endl(Head H, Tail... T) {
  debug_with_endl(H);
  debug_with_endl(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" << endl, debug_with_endl(__VA_ARGS__)
#else
#define debug(...) 2003
#endif

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int sum = 0;
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    sum += x;
  }
  cout << (n - sum >= 0 ? n - sum : -1) << '\n';
  return 0;
}

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

#define llint long long int

using namespace std;

int main(){
    string T;

    cin >> T;

    for(int i = 0; i < T.length(); i ++){
        if(T[i] == '?'){
            T[i] = 'D';
        }
    }
    cout << T << endl;
}

Measured memory_bytes: 3712
#include <stdio.h>

#define max(a,b)	(a>b?a:b)

int main(){
	int N;
	int i;
	int msize;
	int ans;
	
	scanf("%d",&N);
	
	int H[N];
	
	for(i=0;i<N;i++){
		scanf("%d",&H[i]);
	}
	
	ans=0;
	msize=0;
	for(i=0;i<N;i++){
		msize=max(msize,H[i]);
		if(H[i]>=msize)	ans++;
	}
	
	printf("%d",ans);
	
	return 0;
}

Measured memory_bytes: 128
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	final int INF = Integer.MAX_VALUE;

	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();

		boolean[][] g = new boolean[n][n];
		for (int i = 0; i < n; i++) {
			int u = scan.nextInt();
			int k = scan.nextInt();
			for (int j = 0; j < k; j++) {
				int v = scan.nextInt();
				g[u - 1][v - 1] = true;
			}
		}

		int time = 0;
		int[] d = new int[n];
		boolean[] isSearched = new boolean[n];
		Queue<Integer> que = new LinkedList<Integer>();

		for (int i = 0; i < n; i++)
			d[i] = INF;
		que.add(0);
		while (!que.isEmpty()) {
			int length = que.size();
			for (int i = 0; i < length; i++) {
				int id = que.poll();
				if (isSearched[id])
					continue;
				d[id] = Math.min(d[id], time);
				for (int j = 0; j < n; j++)
					if (g[id][j])
						que.add(j);
				isSearched[id] = true;
			}
			time++;
		}
		for (int i = 0; i < n; i++)
			System.out.println((i + 1) + " " + (isSearched[i] ? d[i] : -1));
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 28176
n=int(input())
wl=list(map(int,input().split()))
totalw=sum(wl)
#ans=abs((totalw-wl[0])-wl[0])
ans=totalw
total=0
for i in range(n-1):
  total+=wl[i]
  v=abs((totalw-total)-total)
  if ans > v:
    ans=v
print(ans)


Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    if (n <= 2) {
        if (s[0] == s[1]) {
            cout << "1 2" << endl;
        } else {
            cout << "-1 -1" << endl;
        }
        return 0;
    }
    for (int i = 0; i+3 <= n; i++) {
        if (s[i] == s[i+1] || s[i] == s[i+2] || s[i+1] == s[i+2]) {
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int a,b,k;
  scanf("%d%d%d",&a,&b,&k);
  int i;
  if(a+k-1<b+1-k){
    for(i=1;i<=k;i++) printf("%d\n",a+i-1);
    for(i=k;i>=1;i--) printf("%d\n",b+1-i);
  } else {
    for(i=a;i<=b;i++) printf("%d\n",i);
  }
}

int main(void){
  run();
  return 0;
}


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

using namespace std;

int main()
{	
   long long n,m;
   cin>>n>>m;
   long long cnt=0;
   if(n<=m){
	   if(m>=2LL*n){
	   		cnt=n;
	   		m-=2LL*n;
	   		cnt += (m/4LL);
	   }
	   else{
	   	cnt = m/2LL;
	   }
	}
	else{
		cnt = m/2LL;
	}
   cout<<cnt<<endl;
   return 0;
}

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


int FtoI(char ch){
  if(isdigit(ch)) return ch - '0';
  return 10+ch - 'a';
}

string FtoB(int num){
  string res;
  for(int i=0;i<4;i++)res =  char((num>>i&1)+'0')+res;
  return res;
}


signed main(){
  int q;
  cin>>q;
  while(q--){
    string s,str;
    cin>>s;
    for(int i=0;i<s.size();i++) str += FtoB(FtoI(s[i]));
    
    string f = str[0]=='0'? "":"-";
    
    int k = str.size() - 7 - 1;
    double a = 0.5,ans=0;
    int idx = 1;
    for(int i=k+1;i<str.size();i++) {
      if(str[i]=='1') idx=i-k;
      ans += (str[i]-'0')* a, a*=0.5;
    }
    
    int  b = 1;
    int Ans=0;
    for(int i=k;i>0;i--) Ans+=(str[i]-'0')*b, b*=2;

    char ss[1000];
    sprintf(ss, "%.10Lf", Ans+ans);
    string A = string(ss);
    while(A.back()=='0') A.pop_back();
    
    if(ans == 0) cout<<f<< A<<"0"<<endl;
    else cout<<f<<A<<endl;
  }
  return 0;
}

Measured memory_bytes: 3192
#include <cstdio>
    int c[2000][2000];
    int main() {
      int n, m, k;
      int x = 0, y = 0;
      scanf("%d%d%d", &n, &m, &k);
      for (int i = 0; i < k; ++i) {
        int a;
        scanf("%d", &a);
        while (a--) {
          c[x][y] = i + 1;
          if (~x & 1) y < m - 1 ? ++y : ++x;
          else y > 0 ? --y : ++x;
        }
      }
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j)
          printf("%d ", c[i][j]);
        printf("\n");
      }
      return 0;
    }

Measured memory_bytes: 640
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
vector<int> v,v2;
string s;
int main(void){
    cin>>n;
    cin>>s;
    for(int i=0;i<n;i++){
        v.push_back(s[i]-'0');
    }
    if(n>=3){
        for(int i=1;i<v.size();i++){
            v2.push_back(abs(v[i]-v[i-1]));
        }
        v=v2;
        v2={};
        //for(auto x:v)cout<<x<<endl;
        for(int i=1;i<v.size();i++){
            v2.push_back(abs(v[i]-v[i-1]));
        }
        v=v2;
        v2={};
    }
    while(v.size()>1){
        for(int i=20;i>=0;i--){
            if((v.size()-1)%(1<<i)==0){
                i=max(0,i-1);
                for(int j=(1<<i);j<v.size();j+=(1<<i)){
                    v2.push_back(abs(v[j-(1<<i)]-v[j]));
                }
                v=v2;
                v2={};
                break;
            }
        }
    }
    cout<<v[0]<<endl;
}


Measured memory_bytes: 12792
#include <iostream>
#include <stack>
#include <string>
#include <cstdlib>

using namespace std;

class State{
    stack<int> stk;
public:
    void push(int);
    int result(){
        int r=stk.top();
        stk.pop();
        return r;
    }
};

void State::push(int c){
    //??°?????????????????????????????????????¨??????????
    int n1,n2;
    switch (c){
        case -1:
            n2=stk.top();
            stk.pop();
            n1=stk.top();
            stk.pop();
            stk.push(n1+n2);
            break;
        case -2:
            n2=stk.top();
            stk.pop();
            n1=stk.top();
            stk.pop();
            stk.push(n1-n2);
            break;
        case -3:
            n2=stk.top();
            stk.pop();
            n1=stk.top();
            stk.pop();
            stk.push(n1*n2);
            break;
        default:
            //??°???
            stk.push(c);
            break;
    }
}

int main(){
    string s;
    getline(cin,s);
    State state;
    for (int i=0,l=s.length();i<l;){
        char temp[16];
        int j=0;
        do{
            temp[j++]=s[i++];
            if (i>=l){
                break;
            }
        }while(s[i]!=' ');
        i++;
        temp[j]='\0';
        switch (temp[0]){
            case '+':
                state.push(-1);
                break;
            case '-':
                state.push(-2);
                break;
            case '*':
                state.push(-3);
                break;
            default:
                state.push(atoi(temp));
                break;
        }
    }
    cout<<state.result()<<endl;
    return 0;
}

Measured memory_bytes: 1196
import java.util.Scanner;

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

		while(true) {
			int a = scan.nextInt();
			String op = scan.next();
			int b = scan.nextInt();

			if(("+").equals(op)) {
				System.out.println(a + b);
			} else if (("-").equals(op)) {
				System.out.println(a - b);
			} else if (("*").equals(op)) {
				System.out.println(a * b);
			} else if (("/").equals(op)) {
				System.out.println(a / b);
			} else if (("?").equals(op)) {
				break;
			}
		}
	}

}

Measured memory_bytes: 26040
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    string s;
    ll k;
    cin >> s >> k;
    int n = s.length();
    REP(i,n) {
        if (i == n-1) {
            int char_code = (int)(s[i]-'a');
            k %= 26;
            int change = k+char_code;
            if (change >= 26) change -= 26;
            s[i] = (char)(change+'a');
        }
        else {
            int toA = 26-(int)(s[i]-'a');
            if (s[i] == 'a') continue;
            if (k >= toA) {
                k-=toA;
                s[i] = 'a';
            }
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <list>
#include <string.h>
using namespace std;
typedef long long int ll; typedef pair <int, int> P;
const double INF = 1000000000; const double EPS = 10e-9;
int x1[100], y[100], x2[100], z[100];
double width(int *X, int *Y, int n, double x) {
	double lb = -INF, ub = INF;
	for (int i = 0; i < n; i++)
	{
		double x1 = X[i], x2 = X[(i + 1) % n], y1 = Y[i], y2 = Y[(i + 1) % n];
		if ((x1 - x) * (x2 - x) > 0 || x1 == x2) continue;
		double y = y1 + (y2 - y1) * (x - x1) / (x2 - x1);
		lb = max(lb, y);
		ub = min(ub, y);
	}
	return max(0.0, lb - ub);
}
int main()
{
	while (true)
	{
		vector <int> x;
		int m, n; cin >> m >> n;
		if (m == 0 && n == 0) break;
		for (int i = 0; i < m; i++) {
			cin >> x1[i] >> y[i];
			x.push_back(x1[i]);
		}
		for (int i = 0; i < n; i++) {
			cin >> x2[i] >> z[i];
			x.push_back(x2[i]);
		}
		int minx1 = *min_element(x1, x1 + m), maxx1 = *max_element(x1, x1 + m);
		int minx2 = *min_element(x2, x2 + n), maxx2 = *max_element(x2, x2 + n);
		sort(x.begin(), x.end());
		double res = 0.0;
		for (int i = 0; i + 1 < m + n; i++)
		{
			double a = x[i], b = x[i + 1], c = (a + b) / 2;
			if (minx1 < c && c < maxx1 && minx2 < c && c < maxx2)
			{
				double sa = width(x1, y, m, a) * width(x2, z, n, a);
				double sb = width(x1, y, m, b) * width(x2, z, n, b);
				double sc = width(x1, y, m, c) * width(x2, z, n, c);
				res += (b - a) / 6 * (sa + sb + 4 * sc);
			}
		}
		printf("%.10f\n", res);
	}
	return 0;
}

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

int main(){
	string S;
	cin >> S;
	vector<char> digits;
	string ok = "yes";
	for(int i = 0; i < S.size(); i++){
		for(int j = 0; j < digits.size(); j++){
			if(S[i] == digits[j]){
				ok = "no";
				break;
			}
		}
		if(ok == "no"){
			break;
		}
		digits.push_back(S[i]);
	}
	cout << ok << endl;
}

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
#define        optimize    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define        sqr(a)       ((a)*(a))


int main()
{
    ll tst,n,i,j,m,k;

    cin  >> n;

    ll ar[n+10];

    ll ans = 0;

    for(i=0;i<n;i++)cin>>ar[i];

    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            for(k=j+1;k<n;k++)
            {
                int pr[3];
                pr[0] = ar[i];
                pr[1] = ar[j];
                pr[2] = ar[k];

                sort(pr,pr+3);
                if(pr[2]<(pr[0]+pr[1]) && ar[i]!=ar[j] && ar[i]!=ar[k] && ar[j]!=ar[k])
                {
                    //cout << i+1 << " " << j+1 << " " << k+1<<endl;
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3636
//in the name of <Allah>
#include <bits/stdc++.h>
using namespace std;

const int N = 1 * 100 * 1000 + 1;
int n, a[N];
string ans[] = {"Second", "First"};

bool chek() {
    int cnt[] = {0, 0}, x = 0;
    for (int i = 0; i < n; i++)
        cnt[a[i] & 1]++, x += (a[i] == 1); 
    if (cnt[0] & 1)
        return true;
    if (cnt[1] > 1)
        return false;
    if (x) 
        return false;
    int g = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] & 1)
            a[i]--;
        g = __gcd(g, a[i]);
    }   
    for (int i = 0; i < n; i++)
        a[i] /= g;
    return (!chek());
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    cout << ans[(n - 1 && chek())] << endl;
}


Measured memory_bytes: 4044
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	ll ans = 0;
	ll tmp = 0;
	ll n;
	cin >> n;
	string s = "";
	if(n==0) cout << 0 << endl;
	else {
		while(tmp != n){
			//cout << s.size() << " " << tmp << " " << s << endl;
			if(abs(n-tmp)%((ll)1<<(s.size()+1))==0) s = "0" + s;
			else {
				tmp += (ll)pow(-1, s.size()) * ((ll)1<<s.size());
				s = "1" + s;
			}
		}
		cout << s << endl;
	}
}

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

bool check(int a)
{
    return a != 0 && a%3 == 0;
}

int main()
{
    int a, b;
    cin >> a >> b;

    if(check(a) || check(b) || check(a+b) )
    {
        cout << "Possible" << endl;
    }
    else
    {
        cout << "Impossible" << endl;
    }
}

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

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


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    long int x,n,m,a[10010],i,sum=0;
    scanf("%ld%ld",&n,&m);
    for(i=0;i<m;i++)
    {
        scanf("%ld",&a[i]);
        sum+=a[i];
    }
    x=n-sum;
    if(x<0)
        printf("-1\n");
    else
        printf("%d\n",x);
    return 0;
}


Measured memory_bytes: 1752
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int n, r;
	cin >> n >> r;

	if (10 <= n)cout << r << endl;
	else cout << r + 100 * (10 - n) << endl;




	return 0;
}

Measured memory_bytes: 256
program main
	implicit none
    character(100)::s
    integer::k
    read(*,*)k
    read(*,*)s
    if(len_trim(s)>k)then
    	write(*,*)s(1:k)//'...'
    else
    	write(*,*) s(1:len_trim(s))
    end if
    stop
end program main

Measured memory_bytes: 2852
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public  static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n = sc.nextInt();
        int k = sc.nextInt();
        char c[]=sc.nextString().toCharArray();
        int d[]=new int[n+1];
        char pre='1';
        for (int i = 0; i < c.length; i++) {
			d[i+1]=d[i]+( (c[i]=='0' && pre=='1') ?1:0);
			pre=c[i];
		}
        
        int up=100005,dw=0,md;
        int ans=0;
//        db(d);
        for (int i = 0; i < 60; i++) {
			md=(up+dw)/2;
			int f=0;
			for (int t = 0; t+md < d.length; t++) {
				if(d[t+md]-d[t] <= k) {
					if(t>=1 && c[t-1]=='0' && c[t]=='0')continue;
					f++;break;}
			}
//			db(md,f);
			if(f>0) {
				dw=md;
				ans=md;
			} else {
				up=md;
			}
		}
        
       
        out.println(ans);
        out.flush();
    }

    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

//class P implements Comparable<P>{
//    int id,T;
//    P(int id, int T) {
//        this.id=id;
//        this.T=T;
//    }
//    public int compareTo(P p){
//        return id-p.id; //des
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
    	int r[] = new int[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextInt(); 
		}
    	return r;
    }
    public long[] nextLongArray(int size) throws IOException{
    	long r[] = new long[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextLong(); 
		}
    	return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 25172
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n;
cin>>n;
long long a,b;
cin>>a>>b;
long long ans=0;
if(b==0){
  ans=n;
}
if(a==0){
  ans=0;
}
else{
  ans=(n/(a+b))*a;
  long long temp;
  if(a>=n%(a+b)){
    temp=n%(a+b);
  }
  else{
    temp=a;
  }
  ans+=temp;
}
cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    V< V<int> > a(n, V<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }

    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (a[i][j] > a[i][k] + a[k][j]) {
                    cout << -1 << '\n';
                    return 0;
                }
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            bool is_add = true;
            for (int k = 0; k < n; k++) {
                if (i == k || j == k) continue;
                if (a[i][j] == a[i][k] + a[k][j]) {
                    is_add = false;
                    break;
                }
            }
            if (is_add) ans += (ll)a[i][j];
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;

int solve(int K) {
    deque<ii> dq;
    vector<int> vis(K, 0);

    dq.push_front(ii(1, 1)); // num(%K), cost
    while (!dq.empty()) {
        ii p = dq.front(); dq.pop_front();
        int curr = p.first, cnt = p.second;
        if (curr == 0) return cnt;

        vis[curr] = 1;
        int next = (curr + 1)% K;
        if (vis[next] == 0)
            dq.push_back(ii(next, cnt+1));

        next = (curr * 10) % K;
        if (vis[next] == 0)
            dq.push_front(ii(next, cnt));
    }
}

int main() {
    int K; cin >> K;
    cout << solve(K) << endl;
    return 0;
}


Measured memory_bytes: 1152
# Aizu Problem 0051: Differential II
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


N = int(input())
for n in range(N):
    k = sorted([_ for _ in input().strip()])
    print(int(''.join(k[::-1])) - int(''.join(k)))

Measured memory_bytes: 7828
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<ll>dp(1<<19,-2e18);
vector<ll>buf(1<<19);
ll n,m,ans;
void up(ll v, ll l, ll r) {
    dp[v]+=buf[v];
    if (l<r-1)
	{
        buf[2*v+1]+=buf[v];
        buf[2*v+2]+=buf[v];
    }
    buf[v]=0;
}
void add(ll v,ll l,ll r,ll L,ll R,ll x)
{
    up(v,l,r);
    if(r<=L||R<=l)return;
    if(L<=l&&r<=R)
	{
        buf[v]+=x;
        up(v,l,r);
        return;
    }
    ll m=(l+r)/2;
    add(2*v+1,l,m,L,R,x);
    add(2*v+2,m,r,L,R,x);
    dp[v]=max(dp[2*v+1],dp[2*v+2]);
}
void se(ll v,ll l,ll r,ll i,ll x)
{
    up(v,l,r);
    if(l==r-1)
	{
        dp[v]=x;
        return;
    }
    ll m=(l+r)/2;
    if(i<m)
	{
        se(2*v+1,l,m,i,x);
        up(2*v+2,m,r);
    }
	else
	{
        up(2*v+1,l,m);
        se(2*v+2,m,r,i,x);
    }
    dp[v]=max(dp[2*v+1],dp[2*v+2]);
}
int main()
{
    cin>>n>>m;
    vector<ll>l(n,0);
    vector<vector<pair<ll,ll> > >vec(n + 1);
    for(ll i=0;i<m;i++)
	{
        ll L,R,a;
        cin>>L>>R>>a;
        L--;
        l[L]+=a;
		vec[R].push_back(make_pair(L,a));
    }
    se(0,-1,n,-1,0);
    for(ll i=0;i<n;i++)
	{
        add(0,-1,n,-1,i,l[i]);
        for(ll j=0;j<vec[i].size();j++)
		{
			pair<ll,ll>x=vec[i][j];
            add(0,-1,n,-1,x.first,-x.second);
        }
        ans=max(ans,dp[0]);
        se(0,-1,n,i,dp[0]);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 23808
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 100005
 
#define PI 3.14159265358979323846264338327950
 
#define F first
#define S second
 
#define ll 	 long long int
 
#define mod  1000000007



int main()
{
	FAST;
	ll n;
	cin >> n;
	if(n >= 30){
		cout << "Yes";
		return 0;
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main(){
    int n;
    cin>>n;
    vector<int> height(n);
    rep(i,n)cin>>height.at(i);
    ll cost[n];
    cost[0]=0;
    cost[1]=abs(height.at(1)-height.at(0));
    for(int now=2;now<n;now++){
        cost[now]=min(abs(height[now]-height[now-1])+cost[now-1],abs(height[now]-height[now-2])+cost[now-2]);
    }
    cout<<cost[n-1]<<endl;
    return 0;
}




Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
double eps=1e-12;
long long a,b,c;
int main()
{
	scanf("%lld%lld%lld",&a,&b,&c);
	long double l=1,r=1e9,ans=0;
	for (int i=1;i<=100;i++)
	{
		long double mid=(l+r)/2.0;
		if (-eps<=a*b-mid*mid) {ans=max(ans,mid); l=mid;}else r=mid;
	}
	if (eps<(long double)c-a-b-ans*2.0) printf("Yes\n");else printf("No\n");
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <utility>

using namespace std;

string replace(string s, string a, string b){
  string t = "";
  for(int i = 0; i < s.size(); ++i){
    bool g = true;
    for(int j = 0; j < a.size(); ++j){
      if(s[i+j] != a[j]){
        g = false;
        break;
      }
    }
    if(g){
      t += b;
      i += a.size() - 1;
    }else{
      t += s[i];
    }
  }
  return t;
}

int solve(string c, string d, vector<string> &a, vector<string> &b){
  queue< pair<string,int> > que;
  int ret = -1;
  que.push(make_pair(c,0));
  while(!que.empty()){
    string s = que.front().first;
    int k = que.front().second;
    que.pop();
    if(s == d){
      ret = k;
      break;
    }
    for(int i = 0; i < b.size(); ++i){
      string t = replace(s,a[i],b[i]);
      if(t != s && t.length() <= d.length()){
        que.push(make_pair(t,k+1));
      }
    }
  }
  return ret;
}

int main(){
  int n;
  while(cin >> n, n){
    vector<string> a(n), b(n);
    for(int i = 0; i < n; ++i){
      cin >> a[i] >> b[i];
    }
    string c, d;
    cin >> c >> d;
    cout << solve(c,d,a,b) << endl;
  }
  return 0;
}



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

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define FORW(a, b, c) for(int a = b; a >= c; --a)
#define fi first
#define se second
#define pb push_back
#define int long long

typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int N = 2e5 + 100;
const int oo = 1e8;
const int mod = 1e9 + 7;

int x, y, red, green, white;
int cr[N], cg[N], cw[N];

signed main()  {
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);
    ios_base::sync_with_stdio(false); cout.tie(0);
    cin >> x >> y >> red >> green >> white;

    priority_queue<ii> pq;
    stack<int> sr, sg;

    FOR(i, 1, red) cin >> cr[i], pq.push({cr[i], 0});
    FOR(i, 1, green) cin >> cg[i], pq.push({cg[i], 1});
    FOR(i, 1, white) cin >> cw[i], pq.push({cw[i], 2});

    int cnt = 0, sum = 0, nr = 0, ng = 0;
    while(cnt < x + y) {
        cnt ++;
        sum += pq.top().fi;
        if(pq.top().se == 0) nr ++, sr.push(pq.top().fi);
        else if(pq.top().se == 1) ng ++, sg.push(pq.top().fi);
        pq.pop();
    }
    while(nr > x)   {
        auto cur = pq.top(); pq.pop();
        if(cur.se == 0 || (cur.se == 1 && ng >= y)) continue;
        sum -= sr.top(); sr.pop(); nr --;
        sum += cur.fi;
        if(cur.se == 1) ng ++;
    }
    while(ng > y)   {
        auto cur = pq.top(); pq.pop();
        if(cur.se == 1 || (cur.se == 0 && nr >= x)) continue;
        sum -= sg.top(); sg.pop(); ng --;
        sum += cur.fi;
        if(cur.se == 0) nr ++;
    }
    cout << sum;
}


Measured memory_bytes: 13036
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const long long Maxn=2020;
const long long mod=1e9+7;
long long f[Maxn],n;
inline long long read()
{
	long long s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int main()
{
	n=read();
	f[0]=1ll;
	for(long long i=3;i<=n;++i)
	for(long long j=i-3;j>=0;--j)
	f[i]=(f[i]+f[j])%mod;
	printf("%lld\n",f[n]);
	return 0;
}

Measured memory_bytes: 3776