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

typedef long long ll;
const int N = 1 << 18, mod = 998244353;
int n, x[N], p[N];
int qpow(int b, int p) {int r = 1; for (; p; p >>= 1, b = (ll) b * b % mod) if (p & 1) r = (ll) r * b % mod; return r;}
void FWT(int *a, int fl) {
  for (int k = 1; k < 1 << n; k <<= 1) {
    for (int i = 0; i < 1 << n; i += k << 1) {
      for (int j = 0; j < k; j++) {
        int x = a[i + j], y = a[i + j + k];
        a[i + j] = (x + y) % mod;
        a[i + j + k] = (x - y + mod) % mod;
        if (fl) {
          a[i + j] = (ll) a[i + j] * (mod + 1) / 2 % mod;
          a[i + j + k] = (ll) a[i + j + k] * (mod + 1) / 2 % mod;
        }
      }
    }
  }
}
int main() {
  scanf("%d", &n);
  int s = 0;
  for (int i = 0; i < 1 << n; i++) {
    scanf("%d", &p[i]);
    s += p[i];
  }
  for (int i = 0; i < 1 << n; i++) {
    p[i] = (ll) p[i] * qpow(s, mod - 2) % mod;
    x[i] = i == 0 ? (1 << n) - 1 : mod - 1;
  }
  p[0] = (p[0] - 1 + mod) % mod;
  FWT(x, 0);
  FWT(p, 0);
  for (int i = 0; i < 1 << n; i++) {
    x[i] = (ll) x[i] * qpow(p[i], mod - 2) % mod;
  }
  FWT(x, 1);
  for (int i = 0; i < 1 << n; i++) {
    printf("%d\n", (x[i] - x[0] + mod) % mod);
  }
}


Measured memory_bytes: 4864
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;

#define endl "\n"
#define PRIME 1000000007

#define ll long long

#define f(i,a,n) for(int i = a; i < n; i++)
#define fs(i,a,n,k) for(int i = a; i < n; i+=k)

#define fr(i,a,n) for(int i = n; i > a; i--)
#define frs(i,a,n,k) for(int i=n; i>a; i-=k)

#define out1(a) cout << a << endl
#define out2(a,b) cout << a << " " << b << endl
#define out3(a,b,c) cout << a << " " << b << " " << c << endl


int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    //enable fast I/O
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int a;
    cin >> a;

    cout << a + (a*a) + (a*a*a) << endl;

    return 0;
}

Measured memory_bytes: 3664
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	static int N;
    static int M;
    static int[] A;
    static int[] B;

	static boolean[] used;
	static long max=0;

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

	    N=gi();
	    M=gi();
	    A=new int[M];
	    B=new int[M];
	    Map<Integer,Integer> map=new HashMap<Integer,Integer>();

	    for(int i=0;i<M;i++) {
	        A[i]=gi();
	        B[i]=gi();
	        if(map.containsKey(A[i])) {
	        	if(map.get(A[i])>B[i]) {
	        		map.put(A[i], B[i]);
	        	}
	        } else {
        		map.put(A[i], B[i]);
        	}
	    }

	    Pair<Integer,Integer>[] ps=new Pair[map.size()];
	    int ind=0;
	    for(Map.Entry<Integer, Integer> e :map.entrySet()) {
	    	ps[ind]=new Pair<Integer,Integer>(e.getKey(), e.getValue());
	    	ind++;
	    }
	    Arrays.parallelSort(ps);

	    int ans=0;
	    int nb=Integer.MAX_VALUE;
	    Pair<Integer,Integer> np=ps[0];
	    int npi=0;
	    for (int i=1;i<=N;i++) {
	    	if(nb==i) {
            	ans++;
            	nb=Integer.MAX_VALUE;
            }
	    	if(np.getKey()==i) {
            	nb=Math.min(nb, np.getValue());
            	npi++;
            	if(npi<ps.length) {
            	    np=ps[npi];
            	}
            }
	    }


	    System.out.println(ans);
	}

	public static class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> implements Comparable<Pair<K, V>> {
		/** serialVersionUID. */
	    private static final long serialVersionUID = 6411527075103472113L;

	    public Pair(final K key, final V value) {
	        super(key, value);
	    }

		@Override
		public int compareTo(Pair<K, V> o) {

			Comparable key = (Comparable)this.getKey();
			Comparable key2 = (Comparable)o.getKey();

			return key.compareTo(key2);
		}

	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 67876
main(){
  int i,n,a,b,c;
  scanf("%d",&n);
  for (i=0;i<n;i++){
    scanf("%d %d %d",&a,&b,&c);
    if (a*a+b*b==c*c || a*a+c*c==b*b || b*b+c*c==a*a) printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<vector>
#include<cstring>

using namespace std;


struct Node {
  int key;
  Node *left, *right, *parent;
};


Node *root, *NIL;

void insert(int n) {
  Node *x = root;
  Node *y = NIL;
  Node *z;

  z = new Node;
  z->key = n;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key)
      x = x->left;
    else
      x = x->right;
  }

  z->parent = y;  
  if (y == NIL) {
    root = z;
  }
  else {
    if (z->key < y->key)
      y->left = z;
    else
      y->right = z;
  }
}


Node* _find(Node *u, int k) {
  while (u != NIL && k != u->key) {
    if (k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

void find(int n) {
  Node *t = _find(root, n);
  if (t != NIL) printf("yes\n");
  else printf("no\n");
}


void inorder(Node *u) {
  if (u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node *u) {
  if (u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

void print() {
  inorder(root);
  printf("\n");
  preorder(root);
  printf("\n");
}


void solve(int n) {
  char cmd[20];
  int num;
  
  for (int i = 0; i < n; ++i) {
    scanf("%s %d ", cmd, &num);
    if (strcmp(cmd, "print") == 0)
      print();
    else if (strcmp(cmd, "insert") == 0)
      insert(num);
    else if (strcmp(cmd, "find") == 0)
      find(num);
  }
}

int main() {

  int n;
  scanf("%d ", &n);

  solve(n);
  return 0;
}



Measured memory_bytes: 21364
#include <iostream>
#include <stdio.h>
#include <queue>
#include <vector>
using namespace std;

bool chk[100005];
int n, m, a[100005], ans = 0, cnt = 0, node[100005];
vector <int> adj[100005];

void BFS(int x)
{
    queue <int> q;
    q.push(x);
    chk[x] = true;
    node[a[x]] = ++cnt;
    a[x] = cnt;
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        for (int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i];
            if (chk[v]) continue;
            q.push(v);
            chk[v] = true;
            node[a[v]] = cnt;
            a[v] = cnt;
        }
    }
}

int main()
{
	scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    int x, y;
    for (int i = 1; i <= m; i++)
    {
        scanf("%d%d", &x, &y);
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    fill(chk + 1, chk + 1 + n, false);
    for (int i = 1; i <= n; i++)
        if (!chk[i]) BFS(i);
    for (int i = 1; i <= n; i++)
        if (node[i] == a[i]) ans++;
    printf("%d", ans);
	return 0;
}


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

int main() {
    int a, b, x; cin >> a >> b >> x;
    bool ans = true;
    if (a>x)
        ans = false;
    if (a+b<x)
        ans = false;
    cout << (ans ? "YES": "NO") << endl;
}

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

using namespace std;


int main(){
    string s_d;
    string T;
    cin >> s_d >> T;

    bool isOK = false;
    int T_start;

    //printf("T.length : %d\n", T.length());
    //printf("T[0] : %c\n",T[0]);

    for(int j = s_d.length() - 1; j >= 0; j--){
        if(isOK){
            break;
        }
        for(int i = T.length()-1; i >= 0; i--){
            //printf("i : %d, j : %d\n", i, j);
            //printf("T : %c\n", T[i]);
            //printf("s_d[j-(T.length()-1-i)] : %c\n",s_d[j-(T.length()-1-i)]);
            if(T[i] == s_d[j-(T.length()-1-i)] or '?' == s_d[j-(T.length()-1-i)]){
                if(i==0){
                    isOK = true;
                    T_start = j;
                }
                continue;
            }else{
                break;
            }
        }
    }

    if (not isOK){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    string S;

    //printf("T_start : %d\n",T_start);

    for(int j = s_d.length() - 1; j >= 0; j--){
        if(j == T_start){
            for(int i = T.length()-1; i >= 0; i--){
                S.push_back(T[i]);
            }
            j -= T.length()-1;
        }else{
            S.push_back(s_d[j]);
        }
    }

    reverse(S.begin(),S.end());

    for(int i = 0; i < S.length(); i++){
        if(S[i]=='?'){
            S[i] = 'a';
        }
    }

    cout << S << endl;

    return 0;
}


Measured memory_bytes: 256
import numpy as np 

a,b,h,m=map(int,input().split())

h_deg = 30 * h + 0.5 * m
m_deg = 6 * m
deg = h_deg-m_deg
if deg <= 180:
    ans = np.sqrt(a**2+b**2-2*a*b*np.cos(deg*np.pi/180))
else:
    deg = 360-deg
    ans = np.sqrt(a**2+b**2-2*a*b*np.cos(deg*np.pi/180))
print(ans)

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

using static Input;
using static Util;
class Program
{
    static int K;
    static int N;
    static int[] A;
    static void INPUT()
    {
        K = NextInt();
        N = NextInt();
        A = LineInt();
    }

    static void OUT()
    {
        var a = new int[N];
        for (var i = 1; i < N; i++)
        {
            a[i - 1] = A[i] - A[i - 1];
        }
        a[N - 1] = K - A[N - 1] + A[0];

        Console.WriteLine(a.Sum() - a.Max());
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 34916
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

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

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

ll gcd(ll a, ll b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();
    int n;
    cin>>n;
    int a[n];
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int c=0;
    int ans=0;
    for (int i=1;i<n;i++)
    {
        if (a[i-1]>=a[i])
        {
            c++;
            if (c>ans)
            {
                ans=c;
            }


        }
        else
        {
            c=0;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3996
N = int(input())
info = [0] * N
ans = [0]*3
for i in range(N):
    info[i] = [0] * 3
    info[i][0], info[i][1], info[i][2] = map(int, input().split())

info = sorted(info, key=lambda x: x[2], reverse=True)

height = [0] * 101
for x_kouho in range(101):
    height[x_kouho] = [0]*101
    for y_kouho in range(101):
        height[x_kouho][y_kouho] = info[0][2] + \
            abs(info[0][0] - x_kouho) + abs(info[0][1] - y_kouho)
        for p in range(N):
            if info[p][2] != max(0, (height[x_kouho][y_kouho] - abs(info[p][0] - x_kouho) - abs(info[p][1] - y_kouho))):
                break
            if p == N - 1:
                if 0 <= height[x_kouho][y_kouho]:
                    print("{} {} {}".format(
                        x_kouho, y_kouho, height[x_kouho][y_kouho]))
                    exit()


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    int Q;
    cin >> Q;
    Vl A;
    Vl basis;
    while (Q--) {
        ll N;
        cin >> N;
        A.resize(N);
        for (ll i = 0; i < N; i++) {
            cin >> A[i];
        }
        string S;
        cin >> S;
        reverse(A.begin(), A.end());
        reverse(S.begin(), S.end());

        bool is_zero = true;

        basis.clear();
        for (ll i = 0; i < N; i++) {
            if (S[i] == '0') {
                ll a = A[i];
                for (const auto& w : basis) {
                    if (w & (-w) & a) {
                        a ^= w;
                    }
                }
                if (a) basis.emplace_back(a);
            }
            else {
                ll a = A[i];
                for (const auto& w : basis) {
                    if (w & (-w) & a) {
                        a ^= w;
                    }
                }
                if (a) {
                    is_zero = false;
                    break;
                }
            }
        }

        if (is_zero)
            cout << 0 << "\n";
        else
            cout << 1 << "\n";
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 3576
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <stack>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#define mst(a,b) memset(a,b,sizeof(a))
#define din(a) scanf("%d",&a);
#define lfin(a) scanf("%lf",&a);

using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const double E=exp(1.0);
const double eps=1e-9;
const int mod=1e7;
const int M=1e6;

typedef pair<int,int>P;
vector<P>vec[M];
ll d[M];
void dfs(int x,int y){
	int i,k=vec[x].size();
	for(i=0;i<k;i++){
		P s=vec[x][i];
		if(s.first!=y){
			d[s.first]=d[x]+s.second;
			dfs(s.first,x);
		}
	}
}



int main() {
	int n,i;
	din(n);
	for(i=0;i<n-1;i++) {
		int a,b,c;
		din(a);din(b);din(c);
		vec[a].push_back(P(b,c));
		vec[b].push_back(P(a,c));
	}
	int  m,k;
	din(m);din(k);
	d[k]=0;
	dfs(k,k);
	for(i=0 ;i<m ;i++) {
		int a,b;
		din(a);din(b);
		printf("%lld\n",d[a]+d[b]);
	}
	return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    int32 prev = -INF;
    REP(i,n){
        int32 h;
        cin >> h;
        if(prev > h){
            cout << "No\n";
            return 0;
        }else if(prev == h){
            prev = h;
        }else{
            prev = h - 1;
        }
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
   int n;
   cin>>n;
   vector<vector<int>>data(9,vector<int>(9));
  for(int i=0;i<9;i++){
    for(int j=0;j<9;j++) {
        data[i][j]=(i+1)*(j+1);
        }
  }
  for(int i=0;i<9;i++){
    for(int j=0;j<9;j++) {
        if(data[i][j] == n){
            cout << "Yes"<<endl;
            return 0;
        }

        }
    }   
    cout <<"No"<<endl;   
   

}

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

int main(){
  int n;
  cin >> n;
  int t[n];
  int t_1[n];
  for(int i = 0;i < n;i++){
    cin >> t[i];
    t_1[i] = t[i];
  }
  int m;
  cin >> m;
  int ans[m] = {0};
  for(int i = 0;i < m;i++){
    int p,x;
    cin >> p >> x;
    t[p-1] = x;
    for(int j = 0;j < n;j++){
      ans[i] += t[j];
    }
    t[p-1] = t_1[p-1];
  }
  for(int i = 0;i < m;i++){
    cout << ans[i] << endl;
  }
}


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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int ans = 700;
char s;

main() {
    rep(i,3) {
        cin >> s;
        if (s == 'o') ans += 100;
    }
    ct(ans)
}

Measured memory_bytes: 256
<?php
fscanf(STDIN,'%d',$n);
$h = fgets(STDIN);
$array = explode(' ',$h);
$dp    = array();
$dp[0] = 0;

for ($i=1;$i<$n;$i++){
	if ($i==1){
		$dp[$i] = $dp[$i-1]+abs($array[$i]-$array[$i-1]);
	}else {
		$dp[$i] = min($dp[$i-1]+abs($array[$i]-$array[$i-1]),$dp[$i-2]+abs($array[$i]-$array[$i-2]));
	}
}
echo $dp[$i-1];

Measured memory_bytes: 36212
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int N; cin>>N;
	vector<int> L(N*2);
	rep(i,N*2)cin>>L[i];
	sort(all(L));
	int ans = 0;
	rep(i,N){
		ans += L[i*2];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
  int N,Alice,Bob;
  Alice = 0;
  Bob = 0;
  cin >> N;
  vector<int> v;
  int a;
  for (int i = 0; i<N; i++) {
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(),v.end(),greater<int>());
  for(int i=0; i<v.size(); i++) {
    if(i % 2) {
      Bob+=v[i];
      // cout << v[i] << "\n";
    } else {
      Alice+=v[i];
      // cout << v[i] << "\n";
    }
  }
  cout << Alice - Bob << "\n";
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`
										`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())

	k := nextInt()

	if k%2 == 0 || k%5 == 0 {
		ans := -1
		fmt.Fprintln(out, ans)
		return
	}

	l := 9 * k
	if k%7 == 0 {
		l /= 7
	}

	w := 10
	ans := 1

	for i := 0; i < 1000000; i++ {
		w %= l
		if w == 1 {
			break
		}
		w *= 10
		ans++
	}

	//fmt.Fprintln(out, "[DEBUG]", a)
	fmt.Fprintln(out, ans)

}

// 挿入ソート配列
type slist struct {
	l []int
}

func makeSlist() slist {
	return slist{[]int{}}
}

func (s *slist) add(a int) {
	pos := sort.Search(len(s.l), func(i int) bool { return s.l[i] >= a })
	if pos < len(s.l) {
		s.l = append(s.l[:pos+1], s.l[pos:]...)
		s.l[pos] = a
	} else {
		s.l = append(s.l, a)
	}
}
func (s slist) contains(a int) bool {
	pos := sort.Search(len(s.l), func(i int) bool { return s.l[i] >= a })
	return pos < len(s.l) && s.l[pos] == a
}

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

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func printArray(a []int) {
	for i := 0; i < len(a); i++ {
		if i >= 1 {
			fmt.Fprint(out, " ")
		}
		fmt.Fprint(out, a[i])
	}
	fmt.Fprintln(out)
}

func absInt(x int) int {
	return int(math.Abs(float64(x)))
}
func minInt(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func maxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func log10(x int) float64 {
	return math.Log10(float64(x))
}
func divCeil(shi, bo int) int {
	ans := shi / bo
	if shi%bo != 0 {
		ans++
	}
	return ans
}


Measured memory_bytes: 1828
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//---------------------------------------------------------------
#define fastio std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
//--------------------------------------------------------------

void Main(){
  int n;
  cin>>n;
  vi x(n,0),y(n,0);
  vl h(n,0ll);
  int cx,cy,sx,sy; ll ch,sh;
  rep(i,n){
    cin>>x[i]>>y[i]>>h[i];
    if(h[i]!=0){sx = x[i];sy=y[i];sh = h[i];}
  }
  rep(i,101){
    cx = i;
    rep(j,101){
      cy = j;
      ch = sh+(ll)(abs(cx-sx)+abs(cy-sy));
      bool f = true;
      rep(k,n){
        ll up = h[k]+(ll)(abs(cx-x[k])+abs(cy-y[k]));
        if( h[k]!=0 and  ch != up ){f = false;break;}
        if( h[k]==0 and  ch >  up ){f = false;break;}
      }
      if(f){cout<<cx<<" "<<cy<<" "<<ch; return;}
    }
  }
  exit(1);
}

int main(int argc,char** argv)
{fastio; myio; Main();}


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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    ll N;
    cin >> N;
    vll a(N+1), b(N);
    rep(i, N+1){
        cin >> a[i];
    }
    rep(i, N){
        cin >> b[i];
    }
    ll count = 0;
    rep(i, N){
        ll first = min(b[i], a[i]);
        count += first;
        b[i] -= first;
        ll second = min(b[i], a[i+1]);
        count += second;
        a[i+1] -= second;
    }
    cout << count << endl;
}


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

int N;
string s;
vector<int> w;
vector<int> e;

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

    int sum = 0;
    for(int i = 0; i < N; i++) {
        if(s[i] == 'W') {
            sum++;
        }
        w.push_back(sum);
    }
    sum = 0;
    for(int i = N-1; i >= 0; i--) {
        if(s[i] == 'E') {
            sum++;
        }
        e.push_back(sum);
    }

    int ret = 1e9;
    for(int i = 0; i < N; i++) {
        ret = min(ret, e[N-i-1] + w[i] - 1);
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 4728
s = input()
t = input()
n, m = len(s), len(t)

T = [[0] * (m + 1) for i in range(n + 1)]
k = 0
for j in range(m):
    if s[0] == t[j]:
        k = 1
    T[0][j] = k

k = 0
for i in range(n):
    if s[i] == t[0]:
        k = 1
    T[i][0] = k

for i in range(n - 1):
    for j in range(m - 1):
        if s[i + 1] == t[j + 1]:
            T[i + 1][j + 1] = T[i][j] + 1
        else:
            T[i + 1][j + 1] = max(T[i][j + 1], T[i + 1][j])


i, j = n - 1, m - 1
ans = ''
while i >= 0 and j >= 0:
    if s[i] == t[j]:
        ans += s[i]
        i, j = i - 1, j - 1
    else:
        if T[i - 1][j] > T[i][j - 1]:
            i -= 1
        else:
            j -= 1

print(ans[::-1])


Measured memory_bytes: 112476
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    static bool Calc(int[] xs) {
        int odd = xs.Count(e => e % 2 == 1);
        return odd % 2 == 0;
    }

    static void Main() {
        ReadInt();
        var xs = ReadInts();
        Console.WriteLine("{0}", Calc(xs) ? "YES" : "NO");
    }
}

Measured memory_bytes: 13528
import math
pi=3.14159265358979

def radians(x):
    return 1.0*x/180*pi
    
x = 0
y = 0
theta = radians(90)

while True:
    a, b = map(float, raw_input().split(','))
    if a==0 and b==0: break
    x += a * math.cos(theta)
    y += a * math.sin(theta)
    theta += radians(-b)

print int(x)
print int(y)

Measured memory_bytes: 4444
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

void solve(){
    ll n, k;
    cin >> n >> k;
    ll ans = min(n%k, (k-(n%k))%k);
    cout << ans << '\n';
}

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

Measured memory_bytes: 3636
N, M = map(int, input().split())
S = input()

p = N
prev = N
flag = True
ans = []
for i in range(N, -1, -1):
    if (prev - i) > M:
        ans.append(prev - p)
        prev = p
        if (prev - i) > M:
            flag = False
            break
    if S[i] == "0":
        p = i
ans.append(prev)
if flag:
    print(" ".join(map(str, ans[::-1])))
else:
    print(-1)


Measured memory_bytes: 11124
fun main(args: Array<String>) {
    val (x, y) = readIntList()
    for (i in 0..100) {
        for (j in 0..100) {
            if (2 * i + 4 * j == y && i + j == x) {
                println("Yes")
                return
            }
        }
    }
    println("No")
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 36456
#include <bits/stdc++.h>
using namespace std;
const long long MOD = (1e9)+7;

int n, m;
long long dp[3001][3001][2], ans;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	dp[0][0][1] = 1;
	for(int j = 1; j <= n; j++) dp[0][j][0] = 1;
	for(int i = 1; i <= m; i++) for(int j = 0; j <= n; j++) {
		dp[i][j][0] = (j > 0 ? dp[i-1][j-1][0] : 0)+2*dp[i-1][j][0]+(j < n ? dp[i-1][j+1][0] : 0);
		dp[i][j][1] = (j > 0 ? dp[i-1][j-1][1] : 0)+2*dp[i-1][j][1]+(j < n ? dp[i-1][j+1][1] : 0);
		if(!j or j == n) {
			dp[i][j][0] -= dp[i-1][j][0];
			dp[i][j][1] -= dp[i-1][j][1];
			if(!j) {
				dp[i][j][0] = 0;
				dp[i][j][1] += (j < n ? dp[i-1][j+1][0] : 0);
			}
		}
		if(j == 1) {
			dp[i][j][0] -= dp[i-1][j][0];
			dp[i][j][1] += dp[i-1][j][0];
		}
		dp[i][j][0] = (dp[i][j][0]+MOD)%MOD;
		dp[i][j][1] = (dp[i][j][1]+MOD)%MOD;
	}
	for(int j = 0; j <= n; j++) ans = (ans+dp[m][j][1])%MOD;
	cout << ans;
}


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

int main(){
  int a, b, c, d, ansd, ansb;

  cin>>a>>b>>c>>d;

  if(a > b) ansd = b;
  else ansd = a;

  if(c > d) ansb = d;
  else ansb = c;

  cout<<ansd + ansb<<endl;


  return 0;
}


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

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979323846

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




ll cnt_rep = 0;
ll powmod(ll N, ll P, ll M){
  cnt_rep++;
  if(P == 0) return 1;
  if(P%2 == 0){
    ll t = powmod(N, P/2, M);
    return t*t % M;
  }
  return (N * powmod(N, P-1, M)) % M;
}


ll gcd(ll a, ll b){
  ll resi, g, l;
  if(a > b){
    g = a; l = b;
  }else if(b > a){
    g = b; l = a;
  }else{
    return a;
  }
  resi = g % l;
  if(resi != 0){
    return gcd(l, resi);
  }else{
    return l;
  } 
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

int ans = 0;
int N, M, Q;

template<typename T>
void showall(vector<T> v){
  rep(i, 0, v.size()){
    cout << v[i] << " ";
  }
  cout << endl;
}

template<typename T>
ll com(T n, T m, T mod){
  ll a = 1, b = 1, ans;
  if(n == m || m == 0){
    ans = 1;
  }else{
    for(ll i = 0;i < m; i++){
      a *= n-i;
      a %= mod;
      b *= i+1;
      b %= mod;
    }
    ans = (a * powmod(b, mod-2, mod)) % mod;
  }
  
  return ans;
}

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

  vector<int> ans(N, -1);
  vector<vector<int>> que(N);
  rep(i, 0, M){
    int Ai, Bi;
    cin >> Ai >> Bi;

    que[Ai-1].push_back(Bi-1);
    que[Bi-1].push_back(Ai-1);
  }

  // 幅優先探索
  queue<int> detect;
  detect.push(0);

  while(!detect.empty()){
    int now = detect.front();
    detect.pop();
    
    for(auto& node : que[now]){
      if(ans[node] != -1) continue;

      ans[node] = now;
      detect.push(node);
    }
  }

  cout << "Yes" << endl;
  rep(i, 1, N){
    cout << ans[i]+1 << endl;
  }







  // cout << setprecision(20) << ans << endl;  // For double
}

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

#include <iostream>

int c[15];
int a[15][15];

class CSkillUp {
public:
    void solve(std::istream& in, std::ostream& out) {
        int n, m, x, total_cost = 0;
        in >> n >> m >> x;
        for(int i = 0; i < n; i++){
            in >> c[i];
            total_cost += c[i];
            for(int j = 0; j < m; j++){
                in >> a[i][j];
            }
        }
        int min_cost = total_cost + 1;
        for(int i = 0; i < (1 << n); i++){
            int cost = 0;
            int comprehensions[15] = {0};
            for(int j = 0; j < n; j++){
                if(i>>j & 1){
                    cost += c[j];
                    for(int k = 0; k < m; k++){
                        comprehensions[k] += a[j][k];
                    }
                }
            }
            bool ok = true;
            for(int j = 0; j < m; j++){
                ok &= (x <= comprehensions[j]);
            }
            if(ok){
                min_cost = std::min(min_cost, cost);
            }
        }
        if(min_cost == total_cost + 1){
            out << -1 << std::endl;
        }else{
            out << min_cost << std::endl;
        }
    }
};


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


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef long long ll;
typedef pair<ll,ll> pint;
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;
}
int main(){
    ll n,k;cin>>n>>k;
    vector<ll> ans(k+1);
    ll MOD=pow(10,9)+7;
    for(int i=k;0<i;i--){
        ans[i]=modpow(k/i,n,MOD);
        ll cnt=i*2;
        while(cnt<=k){
            ans[i]=(ans[i]-ans[cnt]%MOD)%MOD;
            cnt=(cnt/i+1)*i;
        }
    }
    rep(i,k+1){
      ans[i]=(ans[i]*i)%MOD;
    }
    ll sum=accumulate(ans.begin(),ans.end(),0LL);
    sum=sum%MOD;
    //rep(i,k+1)cout<<ans[i]<<" ";cout<<endl;
    cout<<sum<<endl;
}

Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int A,B;
    cin >> A >> B;
    if ((B - 1) % (A - 1) == 0){
        cout << (B - 1) / (A - 1) << endl;
    }
    else{
        cout << (B - 1) / (A - 1) + 1 << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define debug(s, param) std::cerr << s << param << std::endl;

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

int main() {
  int x;
  cin >> x;
  if (x == 0) {
    cout << "1" << endl;
  } else {
    cout << "0" << endl;
  }
  return 0;
}

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

#define cc(x) cout << (x) << endl
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<long long> vll;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

const ll inf = 1LL<<58;
const int iinf = 1<<30;

int main(){
    int a, b, t;
    cin >> a >> b >>t;
    cc(t/a*b);
}

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

int main() {
	int N;
	cin >> N;
	for (int i = 1; i <= 9; ++i) {
		int x = 111 * i;
		if(x >= N){
			cout << x << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#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 n, h;
  cin >> n >> h;
  vector<int> a(n);
  vector<int> b(n);
  int ma = 0;
  rep(i, n) {
    int aa, bb;
    cin >> aa >> bb;
    a.at(i) = aa;
    b.at(i) = bb;
    ma = max(ma, aa);
  }
  sort(b.rbegin(), b.rend());
  int bi = 0;
  int cnt = 0;
  while (h > 0) {
    if (bi != n && b.at(bi) > ma) {
      h -= b.at(bi);
      bi++;
      cnt++;
    } else {
      cnt += (h + ma - 1) / ma;
      h = 0;
      break;
    }
  }
  cout << cnt << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  int sum=0;
  for(int i=0;i<N;i++){
    int l,r;
    cin >> l >>r;
    sum += (r-l+1);
  }
cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int N,K;
    cin>>N>>K;
    string S;
    cin>>S;
    vector<P> rev(0);
    int from=-1,to=-1;
    rep(i,N){
        if(S.at(i)=='0'){
            if(to>=0){
                rev.pb({from,to});
                from=-1,to=-1;
            }
        }
        else{
            if(from>=0){
                to=i;
            }
            else{from=i,to=i;}
        }
    }
    if(from>=0){
        rev.pb({from,N-1});
    }
    /*rep(i,rev.size()){
        cout<<rev.at(i).first<<","<<rev.at(i).second<<" ";
    }*/
    int x=rev.size();
    if(K>x){cout<<N<<endl;return 0;}
    int ans=rev.at(K-1).second+1;
    chmax(ans,N-rev.at(x-K).first);
    for(int i=1;K-1+i<x;i++){
        chmax(ans,rev.at(K-1+i).second-rev.at(i-1).first+1);
    }
    cout<<ans<<endl;
}

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

int main(){
	int n;
	cin >> n;
	double p[n+1];
	for (int i = 1; i <= n; ++i) cin >> p[i];
	double dp[n+1][n+1];	//dp[i][j] prob of hving j heads with n coins
	dp[0][0] = 1.00;
	for (int i = 1; i <= n; ++i){
		dp[i][0] = dp[i-1][0] * (1-p[i]);
		for (int j = 1; j <= i; ++j){
			//flipped a tail, flipped a head
			dp[i][j] = dp[i-1][j] * (1-p[i]) + dp[i-1][j-1] * p[i];
		}
	}
	double ans = 0;
	for (int i = n; i > n/2; --i) ans += dp[n][i];
	cout << fixed << setprecision(12) << ans << '\n';
	return 0;
}

Measured memory_bytes: 70400
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn=2e5+5;
const ll p=1000000007;
vector<int>G[maxn];
ll f[maxn];

	
ll qpow(ll a,ll b){
	ll res=1,temp=a%p;
	while (b>0){
		if (b&1) res=res*temp%p;
		temp=temp*temp%p;
		b>>=1;
	}
	return res;
}

ll inv(ll x){
	return qpow(x,p-2);
}

ll solve(ll n,ll m){
	if (n<m) return 0;
	return f[n]*inv(f[n-m]%p)%p;
}


ll ans,k;
void dfs(int u,int fa){
	for (int v:G[u]){
		if (v==fa) continue;
		dfs(v,u);
	}
	if (fa==-1){
		(ans*=solve(k-1,G[u].size()))%=p;
	}else{
		(ans*=solve(k-2,G[u].size()-1))%=p;
	}
}

int main(){
	ios::sync_with_stdio(false);
	f[0]=1;
	for (int i=1;i<maxn;i++) f[i]=f[i-1]*i%p;
//	cout<<inv(f[2])<<endl;
	int n;
	cin>>n>>k;
	
	for (int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		G[u].pb(v);
		G[v].pb(u);
	}	
	ans=k;
	dfs(1,-1);
	cout<<ans<<endl;
}


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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

int N,K,X,Y,Z;
ll dp [41] [1 << 17];
const ll MOD = 1e9 + 7;

long long pow_mod(long long x,long long y,long long i = MOD - 2)
{
	while(i){
		if(i & 1){
			(x *= y) %= MOD;
		}
		(y *= y) %= MOD;
		i >>= 1;
	}
	return x;
}

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

	cin >> N >> X >> Y >> Z;
	K = X + Y + Z;

	dp [0] [0] = 1;
	FOR(i,0,N){
		FOR(mask,0,1 << K){
			if(dp [i] [mask] == 0) continue;
			for(int j = 1;j <= 10;j++){
				int nmask = (mask << j) | (1 << (j - 1));
				nmask &= ((1 << K) - 1);
				bool flag = true;
				flag &= (nmask >> (X + Y + Z - 1) & 1);
				flag &= (nmask >> (Y + Z - 1) & 1);
				flag &= (nmask >> (Z - 1) & 1);
				if(flag == false){
					(dp [i + 1] [nmask] += dp [i] [mask]) %= MOD;
				}
			}
		}
	}

	ll ans = pow_mod(1,10,N);
	FOR(mask,0,1 << K){
		(ans -= dp [N] [mask]) %= MOD;
	}
	(ans += MOD) %= MOD;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 37632
#include <stdio.h>
#include <string.h>
int cnt = 0;
int W, H;

void search(char data[][22], int self_i, int self_j) {
  //  printf("self_i = %d  self_j = %d\n", self_i, self_j);
  data[self_i][self_j] = '#';
  cnt++;
  if (self_i-1 >= 0 && data[self_i-1][self_j] == '.') {
	search(data, self_i-1, self_j);
  }
  if (self_j-1 >= 0 && data[self_i][self_j-1] == '.') {
	search(data, self_i, self_j-1);
  }
  if (self_j+1 <= W && data[self_i][self_j+1] == '.') {
	search(data, self_i, self_j+1);
  }
  if (self_i+1 <= H && data[self_i+1][self_j] == '.') {
	search(data, self_i+1, self_j);
  }
}

int main(void) {
  while(1) {
	cnt = 0;
	scanf("%d%d", &W, &H);
	if (W == H && W == 0) break;
	char data[22][22] = {{0}};
	for (int i = 0; i < H; i++) {
	  scanf("%s", data[i]);
	}
	int self_i, self_j;
	for (int i = 0; i < H; i++) {
	  for (int j = 0; j < W; j++) {
		if (data[i][j] == '@') {
		  self_j = j;
		  self_i = i;
		  goto L1;
		}
	  }
	}
  L1:
	search(data, self_i, self_j);
	printf("%d\n", cnt);


  }
  return 0;
}

Measured memory_bytes: 1060
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long A, B;
	cin >> A >> B;
	vector<long long>N(999);
	N.at(0) = 1;
	for (int i = 1; i < 999; i++) {
		N.at(i) = N.at(i - 1) + i + 1;
	}
	int num = B - A - 1;
	int ans = N.at(num) - B;
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int len = scanner.nextInt();
		int nums[] = new int[len];
		int count = 0;

		for (int i = 0; i < nums.length; i++) {
			nums[i] = scanner.nextInt();
		}

		int minIdx = 0;

		for (int j = 0; j < nums.length; j++) {
			minIdx = j;
			for (int j2 = j; j2 < nums.length; j2++) {
				if (nums[j2] < nums[minIdx]) {
					minIdx = j2;
				}
			}
			if (minIdx != j) {
				int minValue = nums[minIdx];
				nums[minIdx] = nums[j];
				nums[j] = minValue;
				count++;
			}
		}
		new Main().arrayToString(nums);
		System.out.println(count);
	}

	public void arrayToString(int[] arr) {
		for (int i = 0; i < arr.length; i++) {

			if (i == arr.length - 1) {
				System.out.println(arr[i]);
			} else {
				System.out.print(arr[i] + " ");
			}
		}
	}

}


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

int main(){
  int N,M;
  struct drink{
    int price;
    int num;
  };
  vector<drink> _drink;
  cin >> N >> M;
  for(int i = 0;i < N;i++){
    int a,b;
    cin >> a >> b;
    _drink.push_back((drink){a,b});
  }
  sort(_drink.begin(), _drink.end(), 
     [](const drink& x, const drink& y) { return x.price < y.price;});
  long cnt = 0;
  long totalPrice = 0;
  int i = 0;
  while(cnt != M){
    if(_drink[i].num == 0){
      i++;
    }else{
      //cout << i << endl;
      cnt++;
      _drink[i].num--;
      totalPrice += _drink[i].price;
    }
  }
  cout <<  totalPrice;
  return 0;
}

Measured memory_bytes: 1400