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

/********************************************************************/
#define M1 1000000007
#define M3 1000000009
#define M2 998244353
#define ll long long
#define pll pair<ll,ll>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPR(i,a,b) for(ll i=b-1;i>=a;i--)
#define forr(i,n) for(ll i=0;i<n;i++)
#define F first
#define S second
#define pb push_back
#define DB pop_back
#define mp make_pair
#define MT make_tuple
#define V(a) vector<a>
#define vi vector<ll>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())

/********************************************************************/
const double pi = 3.1415926535;
ll n, m;
const int mx = 69;
char grid[mx][mx];
ll blocked[mx][mx];
ll vis[mx][mx];
/********************************************************************/
//FAST IO//
void FAST() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

/********************************************************************/

ll power(ll a, ll b)
{
	ll res = 1;
	for (int i = 1; i <= b; ++i)
		res *= a;

	return res;
}
ll sum(ll x) {
	ll ans = 0;
	while (x > 0) {
		ans += (x % 10);
		x /= 10;
	}
	return ans;
}

bool opp(int x, int y)
{
    return ((x ^ y) < 0);
}

int main()
{
  FAST();
  
  	ll n,W;
  	cin>>n>>W;
  	vi val(n),wt(n);
  	forr(i,n)
  	{
  		cin>>wt[i]>>val[i];
  	}
    
   ll i, w; 
   ll K[n + 1][W + 1]; 
  
    
    for (i = 0; i <= n; i++) 
    { 
        for (w = 0; w <= W; w++) 
        { 
            if (i == 0 || w == 0) 
             K[i][w] = 0; 
            else if (wt[i - 1] <= w) 
             K[i][w] = max( val[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w]); 
            else
             K[i][w] = K[i - 1][w]; 
        } 
    } 
  
    cout<< K[n][W]; 

  
}


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



int main(){
    int i,n;
    cin >> n;
    int fib[n+1];
    fib[0] = 1;
    fib[1] = 1;
    for(i = 0; i < n+1;i++){
        if(i == 0) fib[i] = 1;
        else if(i == 1) fib[i] = 1;
        else fib[i] = fib[i-1] + fib[i-2];
    }
    cout << fib[n] << endl;
}


Measured memory_bytes: 3104
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>//pair
#include<cmath>//abs,sqrt
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int INF=1e+9;
const ll INFLL=1e+17;
int a,b;
int main(){
  cin>>a>>b;
  int res;
  if(a>b){
    if(a-1>b){
      res=a+a-1;
    }
    else res=a+b;
  }
  else{
    if(b-1>a) res=b+b-1;
    else res=a+b;
  }
  prin(res);

  
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)

	l := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&l[i])
	}
	sort.Ints(l)

	var cnt int
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if l[i] == l[j] {
				continue
			}
			for k := j + 1; k < n; k++ {
				if l[j] == l[k] {
					continue
				}
				if l[i]+l[j] > l[k] {
					cnt++
				}
			}
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 1844
import java.io.*;

public class Main {
    public static void main(String[] srgs) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            int x = Integer.parseInt(reader.readLine());
            System.out.println(x*x*x);
        } catch(IOException e) {
            System.out.println(e);
        } catch(NumberFormatException e) {
            System.out.println("wrong number is entered.");
        }
    }
}


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int count5 = 0;
	int count7 = 0;

	if (a == 5) count5++;
	if (a == 7) count7++;
	if (b == 5) count5++;
	if (b == 7) count7++;
	if (c == 5) count5++;
	if (c == 7) count7++;
	
	if ((count5 == 2) && (count7 == 1)) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
}

Measured memory_bytes: 3608
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  ll n, m;
  cin >> n >> m;
  ll ans;
  if (n * 2 <= m) ans += n + (m - 2 * n) / 4;
  else ans = m / 2;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

main() {
    int64_t n;
    cin >> n;

    vector<vector<int64_t>> links(n);
    for (auto i : irange(0L, n)) {
        string s;
        cin >> s;
        for (auto j : irange(0L, n)) {
            if (s[j] == '1') {
                links[i].push_back(j);
            }
        }
    }

    int64_t ans = -1;
    for (auto i : irange(0L, n)) {
        vector<int64_t> idx(n, -1);
        idx[i] = 1;
        unordered_set<int64_t> picked;
        picked.insert(i);

        vector<int64_t> current;
        current.push_back(i);
        bool success = true;
        while (!current.empty()) {
            vector<int64_t> next;
            for (auto j : current) {
                for (auto v : links[j]) {
                    if (idx[v] == -1) {
                        idx[v] = idx[j] + 1;
                        next.push_back(v);
                        picked.insert(v);
                    } else if (idx[v] == idx[j] + 1) {
                        continue;
                    } else if (idx[v] == idx[j] - 1) {
                        continue;
                    } else {
                        success = false;
                        break;
                    }
                }

                if (!success) {
                    break;
                }
            }

            if (!success) {
                break;
            }

            current = std::move(next);
        }

        if (picked.size() < n || !success) {
            continue;
        }

        ans = max(ans, *max_element(idx.begin(), idx.end()));
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


int main() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << b-(b / c + b / d - b / (c*d/euclidean_gcd(c, d))) - ((a-1)-((a - 1) / c + (a - 1) / d - (a - 1) / (c * d / euclidean_gcd(c, d)))) << endl;
}

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

using vi = vector<int>;
using vvi = vector<vi>;

int main()
{
    ios_base::sync_with_stdio(0);

    int n, h; cin >> n >> h;

    vvi v(n, vi(2));

    int mx = 0;

    for(auto& e : v) cin >> e[1] >> e[0], mx = max(mx, e[1]);

    sort(begin(v), end(v));

    int ans = 0;

    for(int i = n - 1; i >= 0 && v[i][0] >= mx && h > 0; i--)
        ans++, h -= v[i][0];

    h = max(0, h);

    ans += h / mx + !!(h % mx);

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
def calc():
    mp = {}
    n, m = map(int, input().split())
    for i in range(0, m):
        s, c = map(int, input().split())
        if s in mp and mp[s] != c:
            return -1
        else:
            mp[s] = c
    if n == 3:
        x = mp[1] if 1 in mp else 1
        y = mp[2] if 2 in mp else 0
        z = mp[3] if 3 in mp else 0
        res = x * 100 + y * 10 + z
    elif n == 2:
        x = mp[1] if 1 in mp else 1
        y = mp[2] if 2 in mp else 0
        res = x * 10 + y
    else:
        res = mp[1] if 1 in mp else 0
    if len(str(res)) != n:
        return -1
    return res


print(calc())


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef long double ld;
using namespace std;

int gcd(int a, int b) 
{ 
  if (a == 0) 
    return b; 
  return gcd(b % a, a); 
} 

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  for(int i = 1; i < n; i++)
  {
    a[0] = gcd(a[0], a[i]);
  }
  cout << a[0];

  return 0;
}


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

int countOdd(int L, int R){  
  
    int N = (R - L) / 2; 
  
    // if either R or L is odd  
    if (R % 2 != 0 || L % 2 != 0)  
        N += 1; 
  
    return N; 
} 

int main(){
   float n;
   cin >> n;
   cout << (float)countOdd(1,n)/n ;
   
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int a[100005];

void solve() {
    int n;
    cin >> n;
    for (int i=0; i<n; ++i) {
        int ai;
        cin >> ai;
        ++a[ai];
    }
    int maxp = 0;
    for (int i=1; i<100000-1; ++i) {
        int t;
        t = a[i-1] + a[i] + a[i+1];
        if (t > maxp)
            maxp = t;
    }
    cout << maxp;

}

int main() {

	solve();
    return 0;
}


Measured memory_bytes: 3524
#include<cstdio>
#include<iostream>
using namespace std;
int n,a[110];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<n;i++)
		for(int j=i+1;j<=n;j++)
			if(a[i]>a[j]) swap(a[i],a[j]);
	printf("%d\n",a[n]-a[1]);
	return 0;
}

Measured memory_bytes: 256
import java.io.*;  

public class Main {
    public static void main(String[] args) throws IOException {

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	int i=0;
    int y = 1;
    String buf = br.readLine();
    //String[] x = buf.split("",0);
    int z = Integer.parseInt(buf);
    while(z!=0){
    	
       	System.out.println("Case "+ y + ": "  + z);
    	buf = br.readLine();
    	z = Integer.parseInt(buf);
    	y++;
    }
  }
    
}

Measured memory_bytes: 32156
N = int(input())
a = []
for i in range(N):
    S = list(input())
    S.sort()
    a.append("".join(map(str,S)))
a.sort()
a.append("z")

c = []
r = 1
for i in range(1,N+1):
    if a[i] == a[i-1]:
        r += 1
    else:
        if r > 1:
            c.append(r)
        r = 1

ans = 0
if len(c) > 0:
    for i in range(len(c)):
        ans += c[i] * (c[i] - 1) // 2
print(ans)

Measured memory_bytes: 10612
fun main(args: Array<String>) {
    val (h, w, k) = readLine()!!.split(" ").map { it.toInt() }
    if(w==1){
        println(1)
        return
    }

    val patterns = (0 until 1.shl(w-1)).filter{ bit -> (0..8).all{ (bit shr it) and 3 != 3 } }
    val rowPatterns=IntArray(w-1)
    patterns.forEach {
        for (i in 0 until w-1){
            rowPatterns[i]+= it shr i and 1
        }
    }

    val dp=LongArray(w)
    dp[0]=1

    repeat(h){
        val nextDp=LongArray(w)
        nextDp[0] = dp[0]*(patterns.size-rowPatterns[0]) + dp[1]*rowPatterns[0]
        nextDp[w-1] = dp[w-1]*(patterns.size-rowPatterns[w-2]) + dp[w-2]*rowPatterns[w-2]
        for(i in 1..w-2){
            nextDp[i] = dp[i]*(patterns.size-rowPatterns[i-1]-rowPatterns[i]) +
                        dp[i-1]*rowPatterns[i-1] +
                        dp[i+1]*rowPatterns[i]
        }
        for(i in 0..w-1){
            dp[i] = nextDp[i] % 1000000007L
        }
    }

    println(dp[k-1])
 }

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

using namespace std;

typedef long long ll;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt", "r", stdin)
#define write freopen("out.txt", "w", stdout)
#define mem(x, n) memset(x, n, sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\n"

int main() {
	faster;

	ll n;
	cin >> n;

	vector<ll> h(n),dp(n+1,0);

	for (auto &x : h)
		cin >> x;
	
	dp[1] = 0;
	dp[2] = abs(h[1]-h[0]);
	
	if(n >= 3){
		dp[3] = min(abs(h[2]-h[0]),dp[2] + abs(h[2]-h[1]));
	}

	for(ll i = 4; i <= n; i++){
		dp[i] = min(dp[i-1] + abs(h[i-1]-h[i-2]),dp[i-2] + abs(h[i-1]-h[i-3]));
	}

	cout << dp[n] << endl;

	return 0;
}

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

int main() {
	int x,i;
	cin >> x;
	cout << "ai1333";
	for (i = 0; i < x / 100; i++) {
		cout << "3";
	}
	cout << endl;
	int o;
	cin >> o;
	return 0;
}


Measured memory_bytes: 3080
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

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

int main(){

	int N;
	string s;
	cin >> N >> s;

	int c=0;
	rep(i,N){
		string x;
		cin >> x;

		if(x.size()<s.size()) cout << 0 << endl;
		else{

		vector<int>s0,s1;
		rep(j,x.size()){
			if(x[j]==s[0]) s0.push_back(j);
			if(x[j]==s[1]) s1.push_back(j);
		}
		
		bool f=false;
		rep(j,s0.size()){
			if(f) break;
			rep(k,s1.size()){
				if(f) break;
				if(s1[k]-s0[j]>0){
					int d=s1[k]-s0[j];

					REP(e,1,s.size()-2){
						if(x[s1[k]+d*e]==s[e+1] && s1[k]+d*e<=x.size()-1) f=true;
						else{ f=false; break;}
					}
                        if(f){ c++; break;}
				}
			}
		}

	   }
	}

	cout << c << endl;

	return 0;
}

Measured memory_bytes: 1232
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var s = next();
  var output = 0;
  for(var i = 0; i < s.length; i++){
    if(i % 2 == 0 && i != s.length - 1){
      if(s[i] == "g"){
        output++;
      }
    }else{
      if(s[i] == "p"){
        output--;
      }
    }
  }
  myout(output);
}


Measured memory_bytes: 7372
#include<queue>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
using namespace std;

typedef long long ll;
int a[10005][10005];
int whiteying[1005];
bool vis[1005];

int main()
{
    ll n;
    cin>>n;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n-1;j++)
            cin>>a[i][j];
    for(int i=1;i<=n;i++)
        whiteying[i]=1;
    int ans=0;
    while(true)
    {
        for(int i=1;i<=n;i++)
            vis[i]=false;
        for(int i=1;i<=n;i++)
        {
            if(whiteying[i]!=n&&whiteying[a[i][whiteying[i]]]!=n&&vis[i]==false&&vis[a[i][whiteying[i]]]==false&&a[a[i][whiteying[i]]][whiteying[a[i][whiteying[i]]]]==i)
            {
                vis[i]=true;
                vis[a[i][whiteying[i]]]=true;
                whiteying[a[i][whiteying[i]]]++,whiteying[i]++;
            }

        }
        bool flag=true;
        for(int j=1;j<=n;j++)
            if(vis[j]==true)
        {
            flag=false;
            break;
        }
        if(flag)
            break;
        ans++;
    }
    bool flag=true;
    for(int i=1;i<=n;i++)
        if(whiteying[i]!=n)
    {
        flag=false;
        break;
    }
    if(flag)
        cout<<ans<<endl;
    else
        cout<<"-1"<<endl;

    return 0;
}
///*
//
//4 6 0
//0 1 2
//1 2 2
//1 3 1
//0 2 5
//1 3 3
//0 3 4
//
//
//
//*/


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

int count(int n,int x){
    int cnt=0;
    for (int i=1;i<=n-2;i++){
        for (int j=i+1;j<=n-1;j++){
            for (int k=j+1;k<=n;k++){
                if (i+j+k==x) cnt++;
            }
        }
    }
    
    return cnt;
    
}

int main(){
    int n,x;
    
    while(1){
        cin>>n>>x;
        if (n==0&&x==0) break;
        cout<<count(n,x)<<endl;
        
    }
    
    return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	auto H=vecin(10);
	sort(ALL(H),greater<int>());
	REP(i,3){
		out(H[i]);
	}
	return 0;
}


Measured memory_bytes: 3120
#include<stdio.h>

int main(){
	int N, A, B, num=0,count=0,i,j;
	scanf("%d %d %d",&N,&A,&B);
	for(i=1;i<=N;i++){
		j=i;
		
		num=0;
		while(1){
			num+=j%10;
			if(j<10){
				break;
			}
			j/=10;
		}
		if(A<=num&&num<=B){
			count+=i;
		}
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  int seq=1;
  int answer=0;
  for(int i=0;i<n;i++)
  {
    if(a[i]!=seq)
      answer++;
    else
    	seq++;
  }
  if(answer==n)
    cout<<-1;
  else
    cout<<answer;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n, k) for(int i=k; i<n; ++i)
using namespace std;

int main(){
  int n, sum = 0, rsum = 0, ans;
  cin >> n; 
  vector<int> w(n);
  rep(i, n, 0){
    cin >> w.at(i);
    sum += w.at(i);
  }
  ans = sum;
  rep(i, n, 0){
    rsum += w.at(i);
    if(abs(2*rsum - sum) < ans) ans = abs(2*rsum - sum);
  }
  cout << ans << endl;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

bool dp[110][11000];

int main(void){
	int n;
	cin >> n;
	dp[0][0] = true;

	const int limit=100*100;

	rep(i,n){
		int s;
		cin >> s;
		rep(j,limit+1){
			if(dp[i][j]==false) continue;
			dp[i+1][j]=true;
			dp[i+1][j+s]=true;
		}
	}

	int ans = 0;
	rep(j,limit+1) if(dp[n][j] and j%10 !=0) chmax(ans,j);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

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();
		}

		for (int i = 1; i < N; i++) {
			StringBuilder sb = new StringBuilder();
			for (int k : A) {
				sb.append(k);
				sb.append(" ");
			}

			System.out.println(sb.toString().trim());
			int v = A[i];
			int j = i - 1;

			while (j >= 0 && A[j] > v) {
				A[j + 1] = A[j];
				j--;
			}
			A[j + 1] = v;
		}
		StringBuilder sb = new StringBuilder();
		for (int k : A) {
			sb.append(k);
			sb.append(" ");
		}

		System.out.println(sb.toString().trim());
	}
}

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

int main() {
  int K; cin >> K;
  int odd,even;
  even = K/2;
  odd = K - even;
  cout << even * odd << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5;
const int INF = 1e9 + 7;

int a, b, c, d;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a >> b >> c >> d;
	int prod1 = a * c;
	int prod2 = a * d;
	int prod3 = b * c;
	int prod4 = b * d;
	cout << max(prod1, max(prod2, max(prod3, prod4)));
	return 0;
}
//13-09-2020 17:37:53

Measured memory_bytes: 3652
import math
N = int(input())

g = 1000003

fr = [1] * g
for x in range(2, g):
    fr[x] = x * fr[x-1] % g

def div(a, b):
    return a * pow(b, g-2, g) % g

for x, d, n in (map(int, input().split()) for _ in range(N)):
    ans = 1

    if d == 0:
        print(pow(x, n, g))

    else:
        s = div(x, d)
        x, y = s+n-1, s-1
        if s+n-1 < g :
            print(div(fr[x], fr[y]) * pow(d, n, g) % g)
        else:
            print(0)

Measured memory_bytes: 44916
import numpy as np
x, y = map(int, input().split())

def comb(n, r, mod):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return g1[n]*g2[r]*g2[n-r]%mod

if (x+y)%3 != 0:
    print(0)
else:
    mod, N = 10**9+7, 10**6
    g1, g2, inverse = [1, 1], [1, 1], [0, 1]
    for i in range(2, N+1):
        g1.append((g1[-1]*i)%mod)
        inverse.append((-inverse[mod%i]*(mod//i))%mod)
        g2.append((g2[-1]*inverse[-1])%mod)
    a = np.array([[1, 2], [2, 1]])
    b = np.array([x, y])
    x0, y0 = np.linalg.solve(a, b)
    print(comb(int(x0+y0), int(x0), mod))


Measured memory_bytes: 145528
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
const ll maxn = 1e5+3LL;
ll dp[maxn][2];
int main()
{
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	int n,w;
	cin >> n >> w;
	ll nax = 0LL,weight[n+1],value[n+1];
	for(int i = 1;i<=n;i++) cin >> weight[i] >>value[i];
	for(int j = 1;j<=n;j++) {
		int curr = j&1,next = 1 - curr;
		for(int i = 0;i<=w;i++) {
			if((dp[i][curr]!=0||i==0)&&i+weight[j]<=w) {
				dp[i+weight[j]][next] = max(dp[i][curr]+value[j],dp[i+weight[j]][next]);
				nax = max(nax,dp[i+weight[j]][next]);
			}
			dp[i][next] = max(dp[i][curr],dp[i][next]);
		}
	}
	cout <<nax<<"\n";
	return 0;
}

Measured memory_bytes: 5176
#include <bits/stdc++.h>
using namespace std;
int n,k; long long ans;
int main(){
	scanf("%d%d",&n,&k);
	for (int i=k+1,j;i<=n;++i){
		/*(k~i-1)
		(k~i-1)+i
		(k~i-1)+2i   2i+k~3i-1
		a%i>=k*/
		
		for (j=0;;j+=i){
			//j+k~j+i-1
			if (j+k>n) break;
			if (j+i-1>n){
				ans+=n-j-k+1;
				break;
			}else ans+=i-k;
		}
		if (k==0) --ans;
	}
	printf("%lld\n",ans);
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
int main()
{
  char s[10];
  cin >> s;
  sort(s, s + 4);
  printf((s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) ? "Yes\n" : "No\n");

}

Measured memory_bytes: 256
solve :: Int -> (Int, Int, [[Int]])
solve 1 = (1, 0, [])
solve l
  | l `mod` 2 == 0 =
    let (n, m, uvws) = solve (l `div` 2)
    in (n+1, m+2, [1,2,0] : [1,2,1] : map (\[u,v,w] -> [u+1,v+1,2*w]) uvws)
  | otherwise =
    let (n,m,uvws) = solve (l - 1)
    in (n, m+1, [1,n,l-1] : uvws)

main = do
  cont <- getContents
  let [l] = map read $ words cont
      (n, m, uvws) = solve l
  putStr $ unlines $ map (unwords . map show) $ [n, m] : uvws


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

using namespace std;

int n, m;
long long ans;
pair<int, int> p[101010];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
    }
    sort(p, p + n);
    for (int i = 0; i < n; i++) {
        if (!m) {
            return cout << ans << '\n', 0;
        }
        if (m >= p[i].second) {
            ans += (p[i].first * 1LL * p[i].second);
            m -= p[i].second;
        } else {
            ans += (p[i].first * 1LL * m);
            m = 0;
        }
    }
    cout << ans << '\n';
    return 0;
}

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

using namespace std;

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define FOR(i,n) for (int i = 0; i < n; i++)
#define FORR(i,a,b) for (int i = a; i <= b; i++)
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ii> vii;

const int MX = 105, mod = 1e9+7;
int n, h[MX];
ll dp[MX][MX][2];

ll pot (ll b, ll p, int mod) {
	ll res = 1;
	b %= mod;

	while (p) {
		if (p & 1) res = res * b % mod;
		b = b * b % mod;
		p /= 2;
	}

	return res;
}

ll obtRes (int i, int j, int f, int off) {
	ll &res = dp[i][j][f];
	if (res != -1) return res;

	int mn = 2e9, cn;
	for (int k = i; k <= j; k++)
		if (h[k] < mn) {
			mn = h[k];
			cn = 1;
		} else if (h[k] == mn)
			cn++;

	if (f) {
		ll x = pot(2, cn, mod);
		ll y = pot(2, mn - off, mod) - 2;
		int ant = -1;

		for (int k = i; k <= j; k++) {
			if (h[k] > mn) {
				if (ant == -1) ant = k;
			} else {
				if (ant != -1) {
					x = x * (obtRes(ant, k-1, 1, mn) + obtRes(ant, k-1, 0, mn)) % mod;
					y = y * obtRes(ant, k-1, 0, mn) % mod;
				}
				ant = -1;
			}
		}

		if (ant != -1) {
			x = x * (obtRes(ant, j, 1, mn) + obtRes(ant, j, 0, mn)) % mod;
			y = y * obtRes(ant, j, 0, mn) % mod;
		}

		return res = (x + y) % mod;
	}

	res = pot(2, mn - off, mod);

	int ant = -1;
	for (int k = i; k <= j; k++) {
		if (h[k] > mn) {
			if (ant == -1) ant = k;
		} else {
			if (ant != -1)
				res = res * obtRes(ant, k-1, 0, mn) % mod;
			ant = -1; 
		}
	}

	if (ant != -1)
		res = res * obtRes(ant, j, 0, mn) % mod;

	return res;
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	FOR(i,MX) FOR(j,MX) FOR (k,2) dp[i][j][k] = -1;

	cin >> n;
	FOR(i,n) cin >> h[i];

	cout << MOD(obtRes(0, n-1, 1, 0), mod) << endl;

	return 0;
}

Measured memory_bytes: 384
#define TEST_MODE true

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;             \
                               c > 0 ? i < b : i > b; \
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long

#ifdef LOCAL_ENV

#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x) << endl
#else
const bool test = false;
#define dump(x) 
#endif

#else
const bool test = false;
#define dump(x) 
#endif

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while (getline(ss, buffer, sep))
    {
        v.push_back(buffer);
    }
    return v;
}

template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
    return accumulate(begin, end, 0ll);
}

void solve();

class Solver {
public:
    int N;
    void solve() {
        cin >> N;
        cout << "ABC" << N << endl;
    }
};

signed main()
{
    cout << fixed << setprecision(20);
    auto ptr = new Solver();
    ptr->solve();
    delete ptr;
    // while (true) {    
    //     auto ptr = new Solver();
    //     ptr->solve();
    //     delete ptr;
    // }
    return 0;
}

// class Mycin {
// 	bool flag = true;
// public:
// 	Mycin& operator >> (int& a) {flag = scanf("%lld", &a) != EOF; return *this;}
// 	Mycin& operator >> (char& a) {flag = scanf("%c", &a) != EOF; return *this;}
// 	Mycin& operator >> (string& s) {flag = (bool)(cin >> s); return *this;}
// 	operator bool() {return flag;}
// } mycin;
 
// class Mycout {
// public:
// 	Mycout& operator << (const int& a) {printf("%lld", a); return *this;}
// 	Mycout& operator << (const char c) {printf("%c", c); return *this;}
// 	Mycout& operator << (const string& s) {printf("%s", s.c_str()); return *this;}
// } mycout;
 
// #define cin mycin
// #define cout mycout
// #define endl '\n'




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

#define    ll    long long int

int main( )
{
    int a, b, j, k;
    cin >> a;
    int i, rt = sqrt(a);
    for (i = 1; i <= 9; i++)
    {
        if (a % i == 0)
        {
            j = a / i;
            if (j <= 9)
            {
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
n = int(input())
words = [input() for i in range(n)]
checkWords = set(words)
flag = True
if len(checkWords) != n:
    print("No")
else:
    for i in range(n-1):
        if words[i][-1] != words[i+1][0]:
            flag = False
    print("Yes") if flag else print("No")

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
    int a,c;
    char b;
    cin>>a;
    int card[4][13]={};
    for(int i=0;i<a;i++){
        cin>>b>>c;
        if(b=='S'){
            card[0][c-1]=1;
        }
        else if(b=='H'){
            card[1][c-1]=1;
        }
        else if(b=='C'){
            card[2][c-1]=1;
        }
        else if(b=='D'){
            card[3][c-1]=1;
        }
    }
    for(int z=0;z<13;z++){
        if(card[0][z]==0) cout<<"S"<<" "<<z+1<<endl;
    }
    for(int z=0;z<13;z++){
        if(card[1][z]==0) cout<<"H"<<" "<<z+1<<endl;
    }
    for(int z=0;z<13;z++){
        if(card[2][z]==0) cout<<"C"<<" "<<z+1<<endl;
    }
    for(int z=0;z<13;z++){
        if(card[3][z]==0) cout<<"D"<<" "<<z+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  int cr, cl;
  cin >> a >> b >> c;
  vector<int> vec(b);
  for (int i = 0; i < b; i++) {
    cin >> vec.at(i);
  }
    for (int j = 0; j < b; j++) {
      if (vec.at(j) > c && vec.at(j) < a) {
        cr++;
      }
    }
  for (int i = 0; i < b; i++) {
    if (vec.at(i) < c) {
      cl++;
    }
  }
  if (cr < cl) {
    cout << cr << endl;
  }
  else {
    cout << cl << endl;
  }
}

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

int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  vector<int> p(N + 1);
  for (int i = 1; i < N + 1; i++) {
    cin >> p[i];
  }

  int ans = 0;
  for (int i = 1; i < N; i++) {
    if (p[i] == i && p[i + 1] == i + 1) {
      p[i] = i + 1;
      p[i + 1] = i;
      ans++;
    } else if (p[i] == i) {
      p[i] = i + 1;
      p[i + 1] = i;
      ans++;
    } else if (i == N - 1) {
      if (p[N] == N) {
        ans++;
      }
    }
  }

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


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
long long n,x;
long long ans=0;
long long gcd(long long a,long long b)
{
	return b==0?a:gcd(b,a%b);
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>x;
	for(int i=1;i<=n;i++)
	{
		int temp;
		cin>>temp;
		ans=gcd(ans,abs(temp-x));
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
int n;
cin>>n;
int s[n];
int ans=0;
vector<int>a;
bool flag=false;
rep(i,n){
  cin>>s[i];
  ans+=s[i];
  if(s[i]%10!=0){
    flag=true;
a.push_back(s[i]);
  }
}if(flag){
sort(a.begin(),a.end());
}
if(ans%10==0&&flag){
  cout<<ans-a[0]<<endl;
}else if(ans%10==0){
  cout<<0<<endl;
}else
{
  cout<<ans<<endl;
}


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n, m;
  cin >> n >> m;
  ll ans;
  if(m==1 and n==1) ans=1;
  else if(m==1) ans=n-2;
  else if(n==1) ans=m-2;
  else ans=(n-2)*(m-2);
  cout << ans << newl;
  return 0;
}

Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {

    public static void main(String[] args)  {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int t = scanner.nextInt();
        int ne = -1;
        long to = (long)t * n;
        for (int i = 0;i < n;++i){
            int a = scanner.nextInt();
            if(ne > 0&&ne - a > 0){
                to -= ne - a;
            }
            ne = a + t;
        }
        System.out.println(to);
    }

}



Measured memory_bytes: 61404
N = int(input())
ans = "Yes"
appeared_words = [input()]
for _ in range(N - 1):
    curr_word = input()
    if appeared_words[-1][-1] != curr_word[0] or curr_word in appeared_words:
        ans = "No"
    appeared_words.append(curr_word)
print(ans)


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

int main(void){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  int rate[8]={0};
  int over_3200=0;
  for(int i=0;i<n;i++){
    if(a[i]>=3200) over_3200++;
    else rate[a[i]/400]=1;
  }
  int min_color=0;
  for(int j=0;j<8;j++) min_color+=rate[j];
  cout << max(1,min_color) << " " << min_color+over_3200 << endl;
  return 0;
}


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

int main()
{
	int n;
	scanf("%d",&n);
	int even,odd;
	odd=n/2;
	if(n%2==1) odd+=1;
	even=n-odd;
	printf("%d\n",odd*even);
	return 0;
}

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

ll gcd_ori(ll a, ll b){
    if(b == 0){
        return a;
    }

    return gcd_ori(b, a % b);
}

ll cnt2(ll a){
    ll cnt = 0;
    while(a%2==0){
        a/=2;
        cnt++;
    }

    return cnt;
}

int main() {
    ll n, m; cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) cin >> a.at(i);

    vector<ll> b(n);
    rep(i, n){
        b.at(i) = a.at(i)/2;
    }
    sort(b.rbegin(), b.rend());
    ll gcd_n = 1;
    rep(i, n){
        ll tmp = gcd_ori(b.at(i), gcd_n);
        ll tmp2 = b.at(i)*gcd_n;
        gcd_n = tmp2/tmp;
    }

    ll res = cnt2(a.at(0));
    rep(i, n){
       if(res != cnt2(a.at(i))){
           cout << 0 << endl;
           return 0;
       } 
    }
    //dump(gcd_n);

    ll cnt = 0;
    cnt = m / gcd_n;
    cnt = (cnt+1)/2;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n;
    cin >> n;
    ll x=1,y=1,z=1;
    for(ll i=0;i<n;i++){
        x*=10;x%=MOD;
        y*=9;y%=MOD;
        z*=8;z%=MOD;
    }
    y*=2;y%=MOD;
    ll ans=x-y+z;
    if(ans<0) ans+=MOD;
    ans%=MOD;
    cout << ans << endl;
}

Measured memory_bytes: 3588
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;
typedef pair<int,int> P;
int main(){
	while(true){
		int a,l;
		scanf("%d%d",&a,&l);
		if(l==0) break;
		int tmp[21]={};
		tmp[0]=a;
		for(int i=1;i<=20;i++){
			int dig[6],t=tmp[i-1];
			for(int j=0;j<l;j++){
				dig[j]=t%10;
				t/=10;
			}
			sort(dig,dig+l);
			int mx=0,mn=0;
			for(int j=0;j<l;j++){
				mn*=10;
				mn+=dig[j];
			}
			sort(dig,dig+l,greater<int>());
			for(int j=0;j<l;j++){
				mx*=10;
				mx+=dig[j];
			}
			tmp[i]=mx-mn;
			bool flag=false;
			for(int j=0;j<i;j++){
				if(tmp[j]==tmp[i]){
					printf("%d %d %d\n",j,tmp[j],i-j);
					flag=true;
					break;
				}
			}
			if(flag) break;
		}
	}
	return 0;
}

Measured memory_bytes: 1048
#include<iostream>
#include<vector>
using namespace std;
int main(){
    while(1){
        int n,m,x,sum1=0,sum2=0,ans=100000,num,ax=0,ay=0;
        vector<int> N,M;
        cin >> n >> m;
        if(n==0&&m==0)  break;
        for(int i=n;i--;){
            cin >> x;
            sum1+=x;
            N.push_back(x);
        }
        for(int i=m;i--;){
            cin >> x;
            sum2+=x;
            M.push_back(x);
        }
        num = sum1 - sum2;
        //cout << sum1 << " " <<sum2 << endl;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(num == 2*(N[i]-M[j])&&ans>N[i]+M[j]){
                    ans = N[i]+M[j];
                    ax=N[i];
                    ay=M[j];
                }
            }
        }
        if(ax==0&&ay==0)    cout << "-1\n";
        else cout << ax << " " << ay << "\n";
    }
}

Measured memory_bytes: 3096
import sys
sys.setrecursionlimit(200000)

N=int(input())
ab=[list(map(int, input().split())) for _ in range(N-1)]
ans=[0 for _ in range(N-1)]

def dfs(v, c=-1, p=-1):
  k=1
  for i in range(len(to[v])):
    u, id=to[v][i]
    if u==p:
      continue
    if k==c:
      k+=1
    ans[id]=k
    k+=1
    dfs(u, ans[id], v)

to=[[] for _ in range(N)]
for i in range(N-1):
  a, b=ab[i][0]-1, ab[i][1]-1
  to[a].append([b, i])
  to[b].append([a, i])

dfs(0)
print(max(ans))
for a in ans:
  print(a)
               

Measured memory_bytes: 128984
#include <iostream>
#include <cstdio>

using namespace std;

const int N=8;

int n,m,w,ans;
char g[N][N];

int main()
{
    scanf("%d%d%d",&n,&m,&w);
    for(int i=0;i<n;i++)
        scanf("%s",g[i]);
    for(int i=0,cnt;i<1<<n;i++)
        for(int j=0;j<1<<m;j++)
        {
            cnt=0;
            for(int a=0;a<n;a++)
                for(int b=0;b<m;b++)
                    if(!(i>>a&1)&&!(j>>b&1)&&g[a][b]=='#')
                        cnt++;
            if(cnt==w)ans++;
        }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int dp[111][111];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<string> fi(H);
    REP(i,H) cin >> fi[i];
    int ans = 0;

    queue<tuple<int, int, char>> q;
    q.emplace(0, 0, fi[0][0]);
    memset(dp, 10101010, sizeof(dp));
    if(fi[0][0] == '.') dp[0][0] = 0;
    else dp[0][0] = 1;

    while(!q.empty()){
        int h, w;
        char cur;
        tie(h, w, cur) = q.front(); q.pop();
        if(h == H-1 && w == W-1) break;
        REP(i,2){
            int nh = h + dx[i], nw = w + dy[i];
            if(nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
            if(cur == fi[nh][nw]){
                if(chmin(dp[nh][nw], dp[h][w])){
                    q.emplace(nh, nw, cur);
                }
            }
            else{
                if(cur == '#'){
                    if(chmin(dp[nh][nw], dp[h][w])){
                        q.emplace(nh, nw, fi[nh][nw]);
                    }
                }
                else{
                    if(chmin(dp[nh][nw], dp[h][w] + 1)){
                        q.emplace(nh, nw, fi[nh][nw]);
                    }
                }
            }
        }
    }
    cout << dp[H-1][W-1] + ans << endl;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
n = int(input())
s = []
for i in range(n):
    s.append(str(input()))
m = int(input())
t = []
for i in range(m):
    t.append(str(input()))

ans = 0
tmp = 0
for i in range(n):
    tmp = s.count(s[i]) - t.count(s[i])
    if tmp > ans:
        ans = tmp
print(ans)

"""
ans = s[0]
for h in range(n):
    tmp = s[h]
    money = 0
    money_max = 0
    for i in range(n):
        if s[i] == tmp:
            money += 1
    for j in range(m):
        if t[j] == tmp:
            money -= 1
    if money > money_max:
        money_max = money
        ans = tmp
print(money_max, ans)
"""


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

vector<int> tsort(vector<vector<int>> G){

  int n = G.size();
  vector<int> sorted,indeg(n,0); //入次数
  for(int u = 0; u < n; u++){
    for(int v : G[u]){
      indeg[v]++;
    }
  }

  queue<int> q;
  for(int u = 0; u < n; u++){
    if(indeg[u] == 0) q.push(u);
  }
  while(!q.empty()){
    int u = q.front(); q.pop();
    for(int v : G[u]){
      indeg[v]--;
      if(indeg[v] == 0) q.push(v);
    }
    sorted.push_back(u);
  }
  return sorted;
}

using P = pair<int,int>;

signed main(){

  int n; cin >> n;
  map<pair<int,int>,int> dic;
  int k = 0;
  for(int i = 0; i < n; i++){
    for(int j = i+1; j < n; j++){
      dic[P(i,j)] = k++;
    }
  }

  vector<vector<int>> G(k);
  for(int i = 0; i < n; i++){
    vector<int> v(n-1);
    for(int j = 0; j < n-1; j++){
      cin >> v[j];
      v[j]--;
      if(j == 0) continue;
      int preu = dic[minmax(i,v[j-1])];
      int u = dic[minmax(i,v[j])];
      G[preu].push_back(u);
    }
  }

  auto t = tsort(G);
  if(t.size() != k){
    cout << -1 << endl;
    return 0;
  }
  vector<int> dp(k,0);
  int ans = 0;
  for(int i = 0; i < k; i++){
    for(int j : G[t[i]]){
      dp[j] = max(dp[j],dp[t[i]]+1);
      ans = max(ans,dp[j]);
    }
  }
  cout << ans+1 << endl;

  return 0;
}


Measured memory_bytes: 96116
//Author: A_S_M_M@sud_P@rvez
#include<bits/stdc++.h>
using namespace std;
#define    MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define    for0(i,n) for(int i=0;i<n;i++)
#define    forn(i,n) for(int i=1;i<=n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    Sort(s) sort(s.begin(),s.end())
#define    gcd(a, b) __gcd(a , b)
#define    lcm(a,b) (a*(b/__gcd(a,b)))
#define    nl     "\n"
#define    End    return 0 
#define    gt     greater<int>()
#define    ll     long long int
#define    mp     make_pair
#define    pb     push_back
#define    vi     vector<int>
#define    vl     vector<ll>
#define    mod    1000000007
#define    sp(n)  fixed<<setprecision(n)
#define    pi     acos(-1)

int main()
{
MP;
	
    string s;
    cin>>s;
    if(s=="ABC")cout<<"ARC";
    else cout<<"ABC";
    
End;
}


Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;

const int maxn = 1e5 + 5;

int main () {
    int n, a, b;
    cin >> a >> b >> n;
    cout << min(n, a*b) << endl;
    return 0;
}

Measured memory_bytes: 3600
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int m=in.nextInt();
		int[] a=new int[m+5];
		int[] dp=new int[n+5];
		for(int i=1;i<=m;i++)
			a[i]=in.nextInt();
		Arrays.fill(dp,1<<25);
		dp[0]=0;
		for(int i=1;i<=m;i++)
			for(int j=0;j<=n;j++)
				if(j-a[i]>=0&&dp[j]>dp[j-a[i]]+1)
					dp[j]=dp[j-a[i]]+1;
		in.close();
		System.out.println(dp[n]);
	}
}

Measured memory_bytes: 26764
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String ans = s.replace(',' , ' ');
		System.out.println(ans);
		sc.close();
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 23764