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

int main(){
    int n;
    cin>>n;
    vector<int> card(n);
    for(int i=0; i<n; i++){cin>>card.at(i);}
    sort(card.begin(), card.end());
    reverse(card.begin(), card.end());
    int alice=0;
    int bob=0;
    for(int i=0; i<n;i++){
        if(i%2==0){alice+=card.at(i);}
        else{bob+=card.at(i);}
    }
    cout<<alice-bob<<endl;
}


Measured memory_bytes: 256
n=int(input())
c_min=200000
for i in range(1,n):
    a=i
    b=n-i
    a_c=0
    b_c=0
    if(a==0)|(b==0):
        print('Err')
    for j in range(6):
        a_c=a_c+a%10
        a=a//10
    for j in range(6):
        b_c=b_c+b%10
        b=b//10
    if (a_c+b_c<=c_min):
        c_min=a_c+b_c
        #print(i,n-i)
    
print(c_min)

Measured memory_bytes: 3188
#include <iostream>
#include <cmath>
#include <cstring>

using namespace std;

int main () {
	int n,k;
	cin >> n >> k;
	int h [n], h2 [n];
	memset (h2,63,sizeof h2);
	for (int i = 0; i < n; i++) {
		cin >> h [i];
	}
	h2 [0] = 0;
	h2 [1] = 100005;
	for (int i = 0; i < n-1; i++) {
		for (int j = 1; j <= k && i+j < n; j++) {
			//cout<<h2 [i+j]<<" ";
			h2 [i+j] = min (h2 [i+j],h2 [i] + abs (h [i] - h [i+j]));
		}
	}
	cout << h2 [n-1];
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

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

  ll num = 0;
  map<string, ll> S;
  for (ll i = 0; i < N; i++)
  {
    string s;
    cin >> s;
    S[s]++;
    chmax(num, S[s]);
  }

  for (auto sn : S)
  {
    if (sn.second == num)
      cout << sn.first << endl;
  }
}

Measured memory_bytes: 25216
#include<bits/stdc++.h>
using namespace std;
struct RMQ{
  static const int MAX_N = 1 << 17;
  int n,dat[2*MAX_N-1];
  RMQ(){}
  RMQ(int n_){init(n_);}
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    for(int i=0;i<2*n-1;i++) dat[i]=INT_MAX;
  }
  void update(int k,int a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
  }
  int query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return INT_MAX;
    if(a<=l&&r<=b) return dat[k];
    else{
      int vl=query(a,b,k*2+1,l,(l+r)/2);
      int vr=query(a,b,k*2+2,(l+r)/2,r);
      return min(vl,vr);
    }
  }
  int query(int a,int b){
    return query(a,b,0,0,n);
  }
};
int main(){
  int n,q;
  cin>>n>>q;
  RMQ rmq(n);
  for(int i=0;i<q;i++){
    int c,x,y;
    cin>>c>>x>>y;
    if(c) cout<<rmq.query(x,y+1)<<endl;
    else rmq.update(x,y);
  }
  return 0;
}
/*
verified on 2017/02/18
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A
*/



Measured memory_bytes: 4116
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var (
	N, A, B, C int
	l          []int
)

func main() {
	N = nextInt()
	A = nextInt()
	B = nextInt()
	C = nextInt()
	l = make([]int, N)
	for i := 0; i < N; i++ {
		l[i] = nextInt()
	}

	fmt.Println(dfs(0, 0, 0, 0))
}

func dfs(cur, a, b, c int) int {
	if cur == N {
		if min(a, min(b, c)) > 0 {
			return abs(a-A) + abs(b-B) + abs(c-C) - 30
		}

		return int(math.MaxInt32)
	}

	ret0 := dfs(cur+1, a, b, c)
	ret1 := dfs(cur+1, a+l[cur], b, c) + 10
	ret2 := dfs(cur+1, a, b+l[cur], c) + 10
	ret3 := dfs(cur+1, a, b, c+l[cur]) + 10

	return min(min(ret0, ret1), min(ret2, ret3))
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

// ---------- Util.


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

namespace ABC075B
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int h = input[0];
            int w = input[1];

            char[][] s = new char[h][];
            int[] dx = { 1, 0, -1, 0, 1, -1, -1, 1 };
            int[] dy = { 0, -1, 0, 1, 1, 1, -1, -1 };

            for(int i = 0; i < h; i++)
            {
                s[i] = Console.ReadLine().ToCharArray();
            }

            for(int i = 0; i < h; i++)
            {
                for(int j = 0; j < w; j++)
                {
                    if (s[i][j] == '#')
                    {
                        continue;
                    }

                    int count = 0;
                    for(int k = 0; k < 8; k++)
                    {
                        int ni = i + dy[k];
                        int nj = j + dx[k];
                        if (ni < 0 || h <= ni)
                        {
                            continue;
                        }
                        if (nj < 0 || w <= nj)
                        {
                            continue;
                        }
                        if (s[ni][nj] == '#')
                        {
                            count++;
                        }
                    }
                    s[i][j] = (char)(count + '0');
                }
            }
            foreach (char[] item in s)
            {
                Console.WriteLine(new string(item));
            }
        }
    }
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e17

struct StarrySkyTree {
  vector<ll> seg, lazy;
  int size;
  StarrySkyTree() {}
  StarrySkyTree(int n) {
    init(n);
  }
  void init(int n) {
    size = 1;
    while (size < n) size *= 2;
    seg.resize(size * 2);
    lazy.resize(size * 2);
    for(ll i=0;i<size*2;i++)seg[i]=INF;
  }
  void update(int k,ll v){
    k += size-1;
    seg[k] = v;
    while(k > 0){
      k = (k - 1)/2;
      seg[k] = min(seg[k * 2 + 1], seg[k * 2 + 2]);
    }
  }
  void push(int k, int l, int r) {
    seg[k] += lazy[k];
    if (r - l > 1) {
      lazy[k * 2 + 1] += lazy[k];
      lazy[k * 2 + 2] += lazy[k];
    }
    lazy[k] = 0;
  }
  void add(int a, int b, ll v, int k, int l, int r) {
    push(k, l, r);
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) {
      lazy[k] += v;
      push(k, l, r);
    } else {
      add(a, b, v, k * 2 + 1, l, (l + r) / 2);
      add(a, b, v, k * 2 + 2, (l + r) / 2, r);
      seg[k] = min(seg[k * 2 + 1], seg[k * 2 + 2]);
    }
  }
  void add(int a, int b, ll v) {
    add(a, b, v, 0, 0, size);
  }
  ll query(int a, int b, int k, int l, int r) {
    push(k, l, r);
    if (r <= a || b <= l) return INF*10; // caution
    if (a <= l && r <= b) return seg[k];
    ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl,vr);
  }
  ll query(int a, int b) {
    return query(a, b, 0, 0, size);
  }
};

ll n,T,E;
ll x[101010];
set<P> st;
StarrySkyTree dp,dp1,dp2;

int main(){
	cin>>n>>E>>T;
  rep(i,n)cin>>x[i];
  rep(i,n)st.insert(P(-2*x[i],i));
  x[n]=E;
  dp.init(n+1); dp1.init(n+1); dp2.init(n+1);
  rep(i,n+1){
    dp.update(i,0); dp1.update(i,0); dp2.update(i,0);
  }
  dp.update(0,x[0]); dp1.update(0,x[0]-x[0]); dp2.update(0,x[0]-2*x[0]);
  rep(i,n){
    ll k;
    if(st.lower_bound(P(-2*x[i]+T,-INF))==st.end())k=-1;
    else k=st.lower_bound(P(-2*x[i]+T,-INF))->se;
    k++;
    ll crt=INF;
    // [0,k)
    minch(crt,dp2.query(0,k)+2*x[i]);
    // [k,i+1)
    minch(crt,dp.query(k,i+1)+T);
    crt+=x[i+1]-x[i];
    dp.add(i+1,i+2,crt); dp1.add(i+1,i+2,crt-x[i+1]); dp2.add(i+1,i+2,crt-2*x[i+1]);
    dp.add(0,i+1,x[i+1]-x[i]); dp1.add(0,i+1,x[i+1]-x[i]); dp2.add(0,i+1,x[i+1]-x[i]);
  }
  cout<<dp.query(n,n+1)<<endl;
	return 0;
}


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

using namespace std;

int main(){
  std::vector<int> vec;
  
  //input
  int input_num;
  int buf;
  cin >> input_num;
  
  for(int i=0;i<input_num;i++){
    cin >> buf;
    vec.push_back(buf);
  }
  
  //calc
  int total = 0;
  int fin_flag = 0;
  while(1){
    vector<int>::iterator iter;
    for(iter = vec.begin();iter != vec.end();++iter){
      if(*iter%2 == 0){
        *iter = *iter/2;
      }else{
        fin_flag = 1;
      }
    }
    if (fin_flag != 0)break;
    total++;
  }
  
  cout << total << endl;
  
  
}


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

using namespace std;
#define ll long long


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    for (auto &x:a) cin >> x, sum += x;
    int cnt = 0;
    for (auto &x:a) {
        if (x * 4 * m >= sum) cnt++;
    }
    if (cnt >= m) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn =1e5+1;
int f[maxn][2];
typedef long long ll;
int main(){
	int N;
	cin>>N;
	ll sum=0,mx=0,a;
	for(int i=1;i<=N;i++){
		cin>>a;
		mx=max(mx,a);
		sum+=a;
	}
	sum-=mx/2;
	cout<<sum;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn = 507;
int c[maxn],s[maxn],f[maxn];
int n;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n-1;i++)
    {
        scanf("%d%d%d",&c[i],&s[i],&f[i]);
    }
    int t=0;
    for(int i=1;i<=n;i++)
    {
        t=0;
        for(int j=i;j<=n-1;j++)
        {
            if(t<s[j])t=s[j];
            else if(t%f[j]==0);
            else t=t-t%f[j]+f[j];
            t+=c[j];
        }
        cout<<t<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>

using namespace std;

//repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a);i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)

//clear memory
//--------------------------------------------
#define CLR(a) memset((a), 0 , sizeof(a))


#define INF 1<<21
int n, m, x[2], y[2];
int amat[20][20];
int res = 0;
char cht;

int main()
{
	cin >> n >> m;
	
	FOR(i, 0, n)
		FOR(j, 0, n)
			amat[i][j] = INF;

	FOR(i,0,m)
	{
		int a, b, c, d;
		
		cin >> a >>cht>> b >>cht>> c >>cht>> d;
		
		a--; b--;
		amat[a][b] = c;
		amat[b][a] = d;
	}
	
	cin >> x[0] >>cht>> x[1] >>cht>> y[0] >>cht>> y[1];
	x[0]--; x[1]--;
	
	FOR(k,0,n)
	FOR(i,0,n)
	FOR(j,0,n)
	{
		amat[i][j] = min( amat[i][j], amat[i][k] + amat[k][j]);
	}
	
	res = y[0] -y[1] -amat[x[0]][x[1]] -amat[x[1]][x[0]];
	
	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 0
import java.io.*;
import java.util.*;

class Main {
    static Scanner scanner = new Scanner();

    public static void main(String[]$) throws IOException {
        char[] s = scanner.next().toCharArray();
        int n = s.length;
        int count = 0;
        for (int i = 0; i < n; i++) {
            count++;
            if (i + 1 >= n) {
                break;
            }
            if (s[i] == s[i + 1]) {
                if (i + 2 >= n) {
                    break;
                }
                i += 2;
                count++;
            }
        }
        System.out.println(count);
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() throws IOException {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
            return tokenizer.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 26196
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

const int max_nm = 200000+10;

Int N,M,K;

Int fact[max_nm];
Int invfact[max_nm];
Int inv[max_nm];

void init(Int x) {
    fact[0] = fact[1] = 1;
    inv[0] = inv[1] = 1;
    invfact[0] = invfact[1] = 1;
    
    for(int i = 2;i <= x;i++) {
        fact[i] = (i*fact[i-1] % MOD);
        inv[i] = (MOD - (MOD / i)*inv[MOD % i]%MOD) % MOD;
        invfact[i] = (inv[i]*invfact[i-1]) % MOD;
    }

    return;
}

Int comb(Int n, Int r) {
    if(n < r)
        return 0;

    return (fact[n]*invfact[n-r]%MOD)*invfact[r]%MOD;
}

int main(void) {
    cin>>N>>M>>K;
    init(N*M);

    Int sum = 0;
    for(Int d = 1;d < M;d++) {
        sum += ((((comb(N*M-2,K-2)*d)% MOD)*(M-d)%MOD)*N%MOD)*N%MOD;
    }
    sum %= MOD;

    for(Int d = 1;d < N;d++) {
        sum += ((((comb(N*M-2,K-2)*d)%MOD)*(N-d)%MOD)*M%MOD)*M%MOD;
    }
    sum %= MOD;

    cout<<sum<<endl;

    return 0;
}




Measured memory_bytes: 4992
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

int main(){
  int N; cin >> N;
  cout << "ABC";
  cout << N << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a[5][5];
	for (int i=1;i<=3;i++)
        for (int j=1;j<=3;j++)
          cin>>a[i][j];
    cout<<a[1][1]<<a[2][2]<<a[3][3];
	return 0;
}

Measured memory_bytes: 256
// // If you want something you've never had, you must be willing to do
// // something you've never done

// //  When the going gets tough,  the tough get going

// #pragma GCC optimize ("O3")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<pair<int,int>, null_type,less<pair<int, int> >,rb_tree_tag,tree_order_statistics_node_update > pbds;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define pb push_back
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// #define int ll
ll power(ll a, ll b, ll mod) {
    ll res = 1;
    a %= mod;
    while(b) {
        if(b % 2) {
            res *= a;
            res %= mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return res % mod;
}
const int INF = 2e9;

// ----------------------------------------------------------

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



signed main() {
    int s, w;
    cin >> s >> w;
    if(w >= s) {
        cout << "unsafe\n";

    }
    else cout << "safe\n";
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=1;i<=n;i++)
int main(){
int z[9],sum=0;
for(int i=0;i<9;i++)cin>>z[i];
r(a,9)if(z[0]==-1||z[0]==a)
r(b,9)if((z[1]==-1||z[1]==b)&&a!=b)
r(c,9)if((z[2]==-1||z[2]==c)&&c!=b&&c!=a)
r(d,9)if((z[3]==-1||z[3]==d)&&d!=a&&d!=b&&d!=c)
r(e,9)if((z[4]==-1||z[4]==e)&&e!=a&&e!=b&&e!=c&&e!=d)
r(f,9)if((z[5]==-1||z[5]==f)&&f!=a&&f!=b&&f!=c&&f!=d&&f!=e)
r(g,9)if((z[6]==-1||z[6]==g)&&g!=a&&g!=b&&g!=c&&g!=d&&g!=e&&g!=f)
r(h,9)if((z[7]==-1||z[7]==h)&&h!=a&&h!=b&&h!=c&&h!=d&&h!=e&&h!=f&&h!=g)
r(i,9)if(z[8]==-1||z[8]==i){
  int p[9];
  p[0]=a;p[1]=b;p[2]=c;
  p[3]=d;p[4]=e;p[5]=f;
  p[6]=g;p[7]=h;p[8]=i;
  sort(p,p+9);
  if(p[0]!=p[1]&&p[1]!=p[2]&&p[2]!=p[3]&&p[3]!=p[4]&&p[4]!=p[5]&&p[5]!=p[6]&&p[6]!=p[7]&&p[7]!=p[8]){
    if((a+c+f+b*10+e*10+d*100)==(g*100+h*10+i))sum++;
  }
}
cout<<sum<<endl;
}

Measured memory_bytes: 3160
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int a, int b) {
    if (b == 1) return 0;

    int ans = 1;
    int x = a;
    while (x < b) {
        x += a - 1;
        ans++;
    }
    return ans;
}

void main() {
    int a, b; scan(a, b);
    writeln(calc(a, b));
}


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

template<class T>
struct LinearSystemIncidence{
private:
    struct Edge{
        int id, to;
        bool fwd;
        Edge() = default;
        
        Edge(int id_, int to_, bool fwd_)
        : id(id_), to(to_), fwd(fwd_) {}
    };
    int n, m;   
    bool F2;
    std::vector<T> x;
    std::vector<bool> seen;
    std::vector<std::vector<Edge>> G;

public:
    LinearSystemIncidence() = default;

    LinearSystemIncidence(int n_, std::vector<std::pair<int, int>> &E, bool F2_ = false)
    : n(n_), m(E.size()), G(n_), F2(F2_){
        for(int i = 0; i < m; i++){
            G[E[i].first].emplace_back(i, E[i].second, true);
            G[E[i].second].emplace_back(i, E[i].first, false);
        }
    }

    T dfs(std::vector<T> &c, int u){
        seen[u] = true;
        T res = c[u];
        for(Edge e : G[u]){
            if(seen[e.to]) continue;
            T tmp = dfs(c, e.to);
            if(e.fwd) x[e.id] = tmp;
            else x[e.id] = -tmp;
            res += tmp;
            if(F2){
                x[e.id] %= 2;
                if(x[e.id] < 0) x[e.id] += 2;
            }
        }
        if(F2) res %= 2;
        return res;
    }

    std::pair<bool, std::vector<T>> solve(std::vector<T> &c){
        x.assign(m, 0);
        seen.assign(n, false);
        for(int i = 0; i < n; i++){
            if(seen[i]) continue;
            if(dfs(c, i)) return {false, std::vector<T>()};
        }
        return {true, std::move(x)};
    }
};

int main(){
    int n, m;
    std::cin >> n >> m;
    std::vector<std::pair<int, int>> E;
    std::vector<int> c(n);
    for(int i = 0; i < m; i++){
        int u, v;
        std::cin >> u >> v;
        u--; v--;
        E.emplace_back(u, v);
        c[u] ^= 1;
    }

    LinearSystemIncidence<int> LSI(n, E, true);
    auto res = LSI.solve(c);

    if(res.first){
        for(int i = 0; i < m; i++){
            if(res.second[i]) std::swap(E[i].first, E[i].second);
            std::cout << E[i].first + 1 << " " << E[i].second + 1 << '\n';
        }
    }
    else std::cout << -1 << '\n';
}


Measured memory_bytes: 18084
#include<stdio.h>
int main()
{
	int n,i,j,k=0,leap=0;
	int a[100]={};
	for(i=1;i<=9;i++){
		for(j=1;j<=9;j++){
			a[k]=i*j;
			k++;
		}
	}
	while(~scanf("%d",&n)){
		for(i=0;i<81;i++){
			if(a[i]==n){
				leap=1;
				break;
			}
		}if(leap==1){
			printf("Yes\n");
		}else{
			printf("No\n");
		}leap=0;
	}
}

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

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

int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    ll n = a * x + b * y;
    ll m = 2 * c * max(x, y);
    int p = x < y ? b : a;
    ll l = 2 * c * min(x, y) + p * abs(x - y);

    ll min_ans = min(n, min(m, l));
    cout << min_ans << endl;
    return 0;
}

Measured memory_bytes: 3444
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (char& c : s) {
    int x = c - 'A';
    x = (x + n) % 26;
    c = x + 'A';
  }
  cout << s << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s,t;
  cin >> s >> t;
  string ans = "No";
  int n = s.size();
  for(int i = 0;i < n;i++){
    int tmp = i;
    int count = 0;
	for(int j = 0;j < n;j++){
      if(tmp == n) tmp=0;
      if(s[tmp] == t[j]) count++;
      tmp++;
    }
    if(count == n){
      ans = "Yes";
      break;
    }
  }
  cout << ans << endl;
}


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

using namespace std;

int main() {

	int n;
	cin >> n;

	vector<int> a(n + 2, 0);
	for (int i = 1; i <= n + 1; i++) {
		cin >> a[i];
	}
	vector<int>b(n + 1, 0);
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
	}

	long long counter = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] >= b[i]) {
			counter += b[i];
		}
		else {
			counter += a[i];
			b[i] = b[i] - a[i];
			if (a[i + 1] >= b[i]) {
				counter += b[i];
				a[i + 1] -= b[i];
			}
			else {
				counter += a[i + 1];
				a[i + 1] = 0;
			}
		}

	}
	cout << counter << endl;
}

Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

template <typename T>
bool chmax(T &a, const T& b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W;
    cin >> H >> W;
    int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
    bool seen[H][W][25];
    ll d[H][W];
    rep(i,H){
        rep(j,W){
            rep(k,25)
            seen[i][j][k]=false;
            d[i][j]=INF;
        }
    }
    int ch,cw,dh,dw;
    cin >> ch >> cw >> dh >> dw;
    ch--;cw--;dh--;dw--;
    deque<P> que;
    que.push_front({ch,cw});
    vvc s(H,vc(W));
    rep(i,H){
        rep(j,W){
            cin >> s[i][j];
        }
    }
    d[ch][cw]=0;
    while(!que.empty()){
        P p=que.front();
        que.pop_front();
        ll x=p.first,y=p.second;
        rep(i,4){
            int nx=x+DX[i],ny=y+DY[i];
            if(!(0<=nx&&nx<H&&0<=ny&&ny<W&&s[nx][ny]=='.'))continue;
            if(seen[nx][ny][(DX[i]+2)+5*(DY[i]+2)])continue;
            if(chmin(d[nx][ny],d[x][y]))que.push_front({nx,ny});
            seen[nx][ny][(DX[i]+2)+5*(DY[i]+2)]=true;
        }
        FOR(dx,-2,3){
            FOR(dy,-2,3){
                if(abs(dx)+abs(dy)<2)continue;
                int nx=x+dx,ny=y+dy;
                if(!(0<=nx&&nx<H&&0<=ny&&ny<W&&s[nx][ny]=='.'))continue;
                if(seen[nx][ny][(dx+2)+5*(dy+2)])continue;
                if(chmin(d[nx][ny],d[x][y]+1))que.push_back({nx,ny});
                seen[nx][ny][(dx+2)+5*(dy+2)]=true;
            }
        }
    }
    cout << (d[dh][dw]==INF?-1:d[dh][dw]) << endl;
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/


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

int main(){
  int N;
  cin >> N;
  vector<int> s(N);
  int64_t total=0;
  for(int i=0;i<N;i++){
    cin >> s.at(i);
    total+=s.at(i);
  }
  if(total%10!=0){
    cout << total << endl;
    return 0;
  }
  sort(s.begin(),s.end());
  vector<int64_t> sum(N+1);
  sum.at(0)=0;
  for(int i=1;i<=N;i++){
    sum.at(i)=sum.at(i-1)+s.at(i-1);
  }
  int64_t tmp=total;
  priority_queue<int64_t> pq;
  for(int i=1;i<=N;i++){
    for(int j=i;j<=N;j++){
      total-=(sum.at(j)-sum.at(j-i));
      pq.push(total);
      total=tmp;
    }
  }
  while(!pq.empty()){
    if(pq.top()%10!=0){
      cout << pq.top() << endl;
      return 0;
    }
    pq.pop();
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    map<int,int> mp1,mp2;
    rep(i,n/2){
        int x,y;cin>>x>>y;
        mp1[x]++;
        mp2[y]++;
    }
    priority_queue<pair<int,int>> que1,que2;
    for(auto& p:mp1){
        que1.push({p.second,p.first});
    }
    for(auto& p:mp2){
        que2.push({p.second,p.first});
    }
    int x1=que1.top().first,y1=que1.top().second;que1.pop();
    int x2=(que1.size())? que1.top().first:0;que1.pop();
    int x3=que2.top().first,y3=que2.top().second;que2.pop();
    int x4=(que2.size())? que2.top().first:0;que2.pop();
    if(y1!=y3){
        ll res=n-(x1+x3);
        cout<<res<<endl;
        return 0;
    }else{
        ll buf1=n-(x1+x4),buf2=n-(x2+x3);
        ll res=min(buf1,buf2);
        cout<<res<<endl;
        return 0;
    }
}

Measured memory_bytes: 6136
#include <bits/stdc++.h>
#define ll long long
# define fastio ios_base :: sync_with_stdio ( false ) ; cin.tie ( 0 ) ; cout.tie ( 0 ) ;
using namespace std;



int main(){
	fastio
	ll a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	if(a==0) cout<<1<<"\n";
	if(b==0) cout<<2<<"\n";
    if(c==0) cout<<3<<"\n";
    if(d==0) cout<<4<<"\n";
    if(e==0) cout<<5<<"\n";


}


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

using namespace std;

int main(){
	string s;
	cin >> s;
	
	if ((s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) || (s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) || (s[0] == s[3] && s[1] == s[2] && s[0] != s[1])) {
		puts("Yes");
	} else {
		puts("No");
	}
	
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(int i = 0;i < n;++i)
#define LONGINF 1000000000000000000
long long dp[1000] = {};
long long cnt[1000] = {};
string s;
int main() {
	cin >> s;
	cnt[0] = 1;
	for (int i = 0;i < s.length();++i) {
		for (int q = i + 1;q < s.length();++q) {
			cnt[q] += cnt[i];
		}
	}
	for (int i = 0;i < s.length();++i) {
		for (int q = i + 1;q < s.length()+1;++q) {
			dp[q] += dp[i] + cnt[i] * stoll(s.substr(i, q - i));
		}
	}
	cout << dp[s.length()] << endl;
	return 0;
}

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> h(N);
    REP(i, 0, N) {
        cin >> h[i];
    }
    const ll inf = 1LL << 60;
    auto dp = make_v(N, inf);
    dp[0] = 0;
    REP(i, 0, N) {
        REP(j, 1, 3) {
            if (i + j < N) {
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
            }
        }
    }

    cout << dp[N - 1] << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<iostream>

#include<cmath>
#include<string>
#include <algorithm> 

using namespace std;

# define p(s) cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) cout << (j ? "Yes" : "No") << endl;

string lpad(string l,int s,int n){
    string temp = to_string(n);
    string res = "";
    int loop = s - temp.size();
    while(loop--) res+=l;

    return res+temp;
}

int main()
{
    double t,x;
    cin >> t >> x ;

    p(t/x)
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
double EPS=1e-9;
double x[60];
double y[60];
double z[60];
double r[60];
long long d[60];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%lf%lf%lf%lf%lld",x+i,y+i,z+i,r+i,d+i);
	}
	for(int i=0;i<b;i++){
		double ax,ay,az,bx,by,bz;
		scanf("%lf%lf%lf%lf%lf%lf",&ax,&ay,&az,&bx,&by,&bz);
		long long ret=0;
		for(int j=0;j<a;j++){
			double left=0;
			double right=1;
			double val=999999999;
			for(int k=0;k<100;k++){
				double m1=left*2/3+right/3;
				double m2=left/3+right*2/3;
				double dx1=x[j]-(m1*ax+(1.0-m1)*bx);
				double dy1=y[j]-(m1*ay+(1.0-m1)*by);
				double dz1=z[j]-(m1*az+(1.0-m1)*bz);
				double dx2=x[j]-(m2*ax+(1.0-m2)*bx);
				double dy2=y[j]-(m2*ay+(1.0-m2)*by);
				double dz2=z[j]-(m2*az+(1.0-m2)*bz);
				
				double d1=sqrt(dx1*dx1+dy1*dy1+dz1*dz1);
				double d2=sqrt(dx2*dx2+dy2*dy2+dz2*dz2);
				val=min(val,min(d1,d2));
				if(d1<d2){
					right=m2;
				}else left=m1;
			}
			if(val<r[j]+EPS){
				ret+=d[j];
			}
		}
		printf("%lld\n",ret);
	}
}

Measured memory_bytes: 1068
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
 if(abs(a-b)<=d&&abs(b-c)<=d)cout<<"Yes";
  else if(abs(c-a)<=d)cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a=[0]*m
b=[0]*m
c=[[] for i in range(m)]
for i in range(m):
  a[i],b[i] =map(int,input().split())
  c[i] = sum([2**(int(x)-1) for x in input().split()])
# N
dp = [1000000000 for i in range(2**n)]
dp[0]=0
for i in range(2**n):
  for j in range(m):
    dp[i|c[j]] = min(dp[i|c[j]], dp[i]+a[j])
if dp[2**n-1]==1000000000:
  print(-1)
else:
  print(dp[2**n-1])


Measured memory_bytes: 44648
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#define maxn 10005
using namespace std;
int a[maxn],b[maxn];
int x,y,n,m;
int main()
{
	scanf("%d%d%d%d",&n,&m,&x,&y);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=m;i++) scanf("%d",&b[i]);
	a[++n]=x,b[++m]=y;
	sort(a+1,a+n+1),sort(b+1,b+m+1);
	if(a[n]>=b[1]) printf("War");
	else printf("No War");
}

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

int main() {
  string s;
  cin >> s;
  int sum = 0, rui = 0;
  for(int i = 0; i < 3; i++) {
    if(s[i] == 'R') rui++;
    else rui = 0;
    if(sum <= rui) sum = rui;
  }
  cout << sum << "\n";
}

Measured memory_bytes: 3632
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Wed Jan  9 09:29:22 2019
//
package main

import (
	"fmt"
)

const MOD = 1e9 + 7

func main() {
	var N int
	fmt.Scan(&N)
	var s1, s2 string
	fmt.Scan(&s1)
	fmt.Scan(&s2)

	ans := 1
	prevUp := true
	for i := 0; i < len(s1); i++ {
		if i == 0 {
			if s1[i] == s2[i] {
				ans *= 3
				prevUp = true
			} else {
				ans *= 6
				i++
				prevUp = false
			}
		} else {
			if s1[i] == s2[i] {
				if prevUp {
					ans *= 2
				} else {
					ans *= 1
				}
				prevUp = true
			} else {
				if prevUp {
					ans *= 2
				} else {
					ans *= 3
				}
				i++
				prevUp = false
			}
		}
		ans %= MOD
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
H,W,M=gets.split.map(&:to_i)
B=M.times.map{gets.split.map{|i|i.to_i-1}}

cnth=[0]*H
cntw=[0]*W
maxh=maxw=0
B.each do |h,w|
  maxh=[maxh,cnth[h]+=1].max
  maxw=[maxw,cntw[w]+=1].max
end

nh=nw=0
vh=*vw=[]
H.times do |h|
  next unless cnth[h]==maxh
  nh+=1
  vh[h]=true
end
W.times do |w|
  next unless cntw[w]==maxw
  nw+=1
  vw[w]=true
end

ne=B.count{|h,w|vh[h]&&vw[w]}

p nh*nw==ne ? maxh+maxw-1 : maxh+maxw


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

int main() {
  int N,M;
  cin>>N>>M;
  vector<int> p(N);
  int z=0;
  for(int i=0;i<N;i++){
    p.at(i)=-1;
  }
  for(int i=0;i<M;i++){
    int c,a;
    cin>>c>>a;
    if(p.at(c-1)==-1){
      p.at(c-1)=a;
    }
    else if(a!=p.at(c-1)){
    z=-1;
      break;
    }
  }
  if(N==1&&z==0){
    if(p.at(0)==-1){
        cout<<"0"<<endl;
      }
      else{
        cout<<p.at(0)<<endl;
      }
    }
   
  else if(z==0&&p.at(0)!=0&&p.at(0)!=-1){
    for(int i=0;i<N;i++){
      if(p.at(i)==-1){
        cout<<"0";
      }
      else{
        cout<<p.at(i);
      }
    }
    cout<<endl;
  }
  else if(z==0&&p.at(0)==-1){
    cout<<"1";
    for(int i=1;i<N;i++){
      if(p.at(i)==-1){
        cout<<"0";
      }
      else{
        cout<<p.at(i);
      }
    }
    cout<<endl;
  }
  else{
    cout<<"-1"<<endl;
  }
}

Measured memory_bytes: 256
xy[501][501],yz[501][501],zx[501][501];
main(n,h){
	char c[3];
	int m,a,b,i;
	for(;scanf("%d%d",&n,&h)*n;){
		memset(xy,0,sizeof(xy));
		memset(yz,0,sizeof(yz));
		memset(zx,0,sizeof(zx));
		m=n*n*n;
		for(;h--;){
			scanf("%s%d%d",c,&a,&b);
			if(strcmp(c,"xy")==0){
				for(i=1;i<=n;i++)
					m-=!xy[a][b]&&!yz[b][i]&&!zx[i][a];
				xy[a][b]=1;
			}
			if(strcmp(c,"yz")==0){
				for(i=1;i<=n;i++)
					m-=!yz[a][b]&&!zx[b][i]&&!xy[i][a];
				yz[a][b]=1;
			}
			if(strcmp(c,"xz")==0){
				for(i=1;i<=n;i++)
					m-=!zx[b][a]&&!xy[a][i]&&!yz[i][b];
				zx[b][a]=1;
			}
		}
		printf("%d\n",m);
	}
	{int n;for(n=1000000;n--;)getchar();}//delay(0.52s)
	exit(0);
}

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

long long int n;
long long int num=0;
int main()
{
	cin>>n;
	for(long long int i=1;i<=sqrt(n);i++)
	{
		if(n%i==0)
		{
			long long int m=n/i-1;
			if(m>0&&i==n/m)num+=m;
			long long int k=n/i;
			if(k!=i)
			{
			  m=n/k-1;
			if(m>0&&k==n/m)num+=m;	
			}
			
						
		}
	}
	cout<<num;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

int N;
vector<int> A;
vector<vector<vector<int>>> dp;

void DP(int turn, int front, int have) {
	//先手
	if (turn == 0) {
		for (int n = front + 1; n < N + 2; n++) {
			if (dp[1][n][n - 1] == INT_MAX)DP(1, n, n - 1);
			dp[0][front][have] = max(dp[0][front][have], dp[1][n][n - 1]);
		}
		dp[0][front][have] = max(dp[0][front][have], abs(A[N + 1] - A[have]));
	}
	else {
		for (int n = front + 1; n < N + 2; n++) {
			if (dp[0][n][n - 1] == -1)DP(0,n, n - 1);
			dp[1][front][have] = min(dp[1][front][have], dp[0][n][n - 1]);
		}
		dp[1][front][have] = min(dp[1][front][have], abs(A[N + 1] - A[have]));
	}
}

int main() {
	cin >> N;
	A.resize(N + 2);
	cin >> A[0] >> A[1];
	for (int n = 2; n < N + 2; n++)cin >> A[n];
	dp.resize(2);
	dp[0].resize(N + 2, vector<int>(N + 2, -1));
	dp[1].resize(N + 2, vector<int>(N + 2, INT_MAX));
	DP(0, 2, 1);
	cout << dp[0][2][1] << endl;
	return 0;
}


Measured memory_bytes: 31744
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define ASCll 48 

#define PREP(i, m, n) for(int i = m; i < n; i++)
#define MREP(i, m, n) for(int i = m - 1; i >= n; i--)
using namespace std;

int stringToInt(string m, int n){
	int result = 0;
	for(int i = 0, j = n; i < n; i++, j--){
		int tmp = m[i] - ASCll;
		for(int k = j - 1; k > 0; k--){
			tmp *= 10;
		}
		result += tmp;
	}
	return result;
}

string intToString(int m, int n){
	string result;
	for(int i = 0; i < n; i++){
		int tmp = m % 10 + ASCll;
		result.insert(result.begin(), 1, tmp);
		m /= 10; 
	}
	return result;
}

int main(){
	string m;
	int n = 0;
	while(cin >> m >> n && (m != "0" || n != 0)){
		//桁数合わせ
		if(m.size() != n){
			int tmp = m.size();
			for(int i = 0; i < n - tmp; i++){
				m.insert(m.begin(), 1, '0');
			}
		}
		string stResult = m;
		vector<int> result;
		result.push_back(stringToInt(stResult, n));
		int index = 0;
		bool hit = false;
		while(1){
			//降順ソート
			sort(stResult.begin(), stResult.end(), greater<int>());
			int max = stringToInt(stResult, n);
			//昇順ソート
			sort(stResult.begin(), stResult.end());
			int min = stringToInt(stResult, n);
			
			int iResult = max - min;

			result.push_back(iResult);

			stResult = intToString(iResult, n);

			for(int i = 0; i < result.size() - 1; i++){
				if(result[i] == iResult){
					index = i;
					hit = true;
					break;
				}
			}

			if(hit)break;
		}
		cout << index << " " << result[result.size() - 1] << " " << result.size() - 1 - index << endl;
	}
	return 0;
}

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

using namespace std;

int main() {
    int n, a, z;
    cin >> n >> a;
    
    for (int x = 0; x <= n; x++) {
        for (int y = 0; y <= n - x; y++) {
            z = n - (x + y);

            if (a == x*10000 + y*5000 + z*1000 && z >= 0) {
                cout << x << " " << y  << " " << z << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> X(M);
	rep(i, M) {
		cin >> X[i];
	}
	sort(X.begin(), X.end());
	vector<int> D(M-1);
	rep(i, M-1) {
		D[i] = abs(X[i + 1] - X[i]);
	}
	sort(D.begin(), D.end());
	int n = max(M - N, 0);
	int ans = 0;
	rep(i, n) {
		ans += D[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1);
const int maxn = 2e6 + 10;
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ull base = 131;
const ull mod1 = 1e9 + 9;
const ull mod2 = 1610612741;

int n;
ll a[maxn];

int main()
{
    scanf("%d", &n);
    bool flag = false;
    for (int i = 1; i <= n; ++i)
    {
        scanf("%lld", a+i);
        if (!a[i]) flag = true;
    }
    if (flag)
    {
        printf("0\n");
        return 0;
    }
    ll ans = 1;
    for (int i = 1; i <= n; ++i)
    {
        if (ans * a[i] > 1000000000000000000 || ans * a[i] < ans)
        {
            printf("-1\n");
            return 0;
        }
        ans *= a[i];
    }
    printf("%lld\n", ans);
    return 0; 
}

Measured memory_bytes: 4544
import sys
def main():
    input = sys.stdin.readline
    N,T=map(int, input().split())
    ans=10**10
    for _ in range(N):
        c,t=map(int, input().split())
        if t<=T: ans = min(ans, c)
    print(ans if ans < 10**10 else 'TLE')

if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <cmath>
#include <climits>
#include <cstdint>
using namespace std;

inline namespace atcoder {
    template <typename T, size_t Depth>
    struct vector_helper { using type = vector<typename vector_helper<T, Depth - 1>::type>; };
    template <typename T>
    struct vector_helper<T, 0> { using type = T; };
    template <typename T, size_t Depth>
    using vector_t = typename vector_helper<T, Depth>::type;

    template <typename T> using vec = vector_t<T, 1>;
    template <typename T> using vvec = vector_t<T, 2>;
    template <typename T> using vvvec = vector_t<T, 3>;

    constexpr int64_t mpow(int64_t a, int64_t b, int64_t mod = 1000000007) {
        if (b <= 0) return 1; if (b == 1) return a % mod; if (b == 2) return (a * a) % mod;
        return (max(a * (b & 1), (int64_t)1) * mpow(mpow(a, b / 2, mod), 2, mod)) % mod;
    }
    constexpr int64_t mdiv(int64_t a, int64_t b, int64_t mod = 1000000007) {
        return (a * mpow(b, mod - 2, mod)) % mod;
    }
}

int main() {
    int n; cin >> n;
    vec<int> l(n);
    for (auto &e : l) cin >> e;
    sort(l.rbegin(), l.rend());
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            for (int k = j + 1; k < n; ++k) {
                if (l[i] < l[j] + l[k]) {
                    ++ans;
                }
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3576
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
//#include <intrin.h>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 300005
#define inf (ll)2e18
#define EPS 1e-12
#define MOD 998244353ll
#define __builtin_popcount(x) __popcnt(x)

using namespace std;

typedef long long ll;

inline void solve()
{
	int r;
	cin >> r;
	cout << fixed << setprecision(10) << 2 * M_PI * r;
}

int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	fore(t, 0, q)
	{
		solve();
		cout << '\n';
	}
}

Measured memory_bytes: 3776
//test
#include<cstdio>
#define LL long long
#define __debug
using namespace std;
const int maxn = 5e5 + 5, mod = 998244353;
int step[maxn], inv[maxn];
 
LL fpow(LL a, int b) {
	LL ans = 1;
	while(b) {
		if(b & 1) ans = ans * a % mod;
		a = a * a % mod, b >>= 1;
	}
	return ans;
}
 
void pre(int n) {
	step[0] = inv[0] = 1;
	for(register int i = 1; i <= n; ++i) 
		step[i] = 1ll * step[i - 1] * i % mod;
	inv[n] = fpow(step[n], mod - 2);
	for(register int i = n - 1; i >= 1; --i)
		inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
}
 
int C(int n, int m) {
	if(n < 0) return m & 1 ? -C(m - n - 1, m) : C(m - n - 1, m);
	if(n - m < 0) return 0;
	return (1ll * step[n] * inv[n - m] % mod) * inv[m] % mod;
}
 
int n, k, ret;
int main() {
	scanf("%d%d", &n, &k), pre(k);
	if(n > k) return printf("0"), 0;
	for(register int i = n; i <= k; ++i) {
		ret += C(k - 1, i - 1) % mod, ret %= mod;
	}
	printf("%d", ret);
	return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int x;
	cin >> x;
	int ans = 1;
	
	for(int i=2; i<11 ; i++){
		rep2(j, 2, x+1){
			ll s =1;
			rep(k, i) s *=j;
			if( s <=x) ans = max<ll>(ans, s);
		}
	}
	
	cout << ans<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#pragma comment(linker, "/STACK:36777216")

using namespace std;

#define MP make_pair
#define all(v) (v).begin(), (v).end()
#define PROBLEM_ID "A"

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

int main() {
  //freopen(PROBLEM_ID".in", "r", stdin);
  int n;
  cin >> n;
  vi a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int odd = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] % 2) {
      ++odd;
    }
  }
  if (odd % 2) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
  return 0;
}

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


int main(){
    int n; cin >> n;
    string s; cin >> s;
    
    int count = 0;
    rep(i,n-2){
        if(s[i] =='A' && s[i+1] == 'B' && s[i+2] == 'C'){
            count++;
        }
    }
    cout << count << endl;
    
    
}




Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
int a[10][10];
int b[10][10];
long long sum;
int main(void)
{
     int i,j,k,n,m;
     scanf("%d%d",&n,&m);
     memset(b,0,sizeof(b));
     for(i=0;i<10;i++)
     {
          for(j=0;j<10;j++)
          {
               scanf("%d",&a[i][j]);
          }
     }
     sum=0;
     for(k=0;k<10;k++)
     {
          for(i=0;i<10;i++)
          {
               for(j=0;j<10;j++)
               {
                    if(a[i][j]>a[i][k]+a[k][j])
                         a[i][j]=a[i][k]+a[k][j];
               }
          }
     }
     for(i=1;i<=n;i++)
     {
          for(j=1;j<=m;j++)
          {
               scanf("%d",&k);
               if(k==-1||k==1)
                    continue;
               sum+=a[k][1];
          }
     }
     printf("%lld\n",sum);
     return 0;
}


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

int main()
{
	int n;
	cin >> n;
	for (int i = 0; 4 * i <= n; i++)
	{
		if ((n - 4 * i) % 7 == 0)
		{
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256