akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,l;
char s[100005];
int ch[100006][2];
int cnt,root;
void add()
{
	int len=strlen(s);int now=root;
	for(int j=0;j<len;j++)
	{
		int c=s[j]-'0';
		if(!ch[now][c])ch[now][c]=++cnt;
		now=ch[now][c];
	}
}
int ans;
void dfs(int x,int nw)
{
	if(ch[x][0])dfs(ch[x][0],nw+1);
	if(ch[x][1])dfs(ch[x][1],nw+1);
	if(!ch[x][0]&&!ch[x][1])return ;
	if(ch[x][0]&&ch[x][1])return ;
	int tmp=1,g=l-nw;
	while(g%2==0)
	{
		tmp<<=1;g>>=1;
	}
	ans^=tmp;
}
signed main()
{
	cin>>n>>l;root=++cnt;
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s);
		add();
	}
	dfs(root,0);
	if(ans==0)puts("Bob");
	else puts("Alice");
	return 0;
}

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

using namespace std;

typedef long long ll;

#define _abs(x)((x) < 0 ? (x) * -1 : (x))

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //freopen("debug.txt", "w", stderr);

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

    int a, b, c;

    cin >> a >> b >> c;

    if (b - a == c - b) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;

const ll MAXN = 3009;

pair<ll, ll> dp[MAXN][MAXN];

int main() {
  int n; cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j + i - 1 < n; j++) {
      int l = j, r = j + i - 1, turn = (n - i) % 2;
      if (turn == 0) { 
        if (i == 1) {
          dp[l][r].first = a[l];
        } else if (a[l] + dp[l + 1][r].first - dp[l + 1][r].second > a[r] + dp[l][r - 1].first - dp[l][r - 1].second) {
          dp[l][r].first = a[l] + dp[l + 1][r].first;
          dp[l][r].second = dp[l + 1][r].second;
        } else {
          dp[l][r].first = a[r] + dp[l][r - 1].first;
          dp[l][r].second = dp[l][r - 1].second;
        }
      } else {
        if (i == 1) {
          dp[l][r].second = a[l];
        } else if (dp[l + 1][r].first - dp[l + 1][r].second - a[l] < dp[l][r - 1].first - dp[l][r - 1].second - a[r]) {
          dp[l][r].first = dp[l + 1][r].first;
          dp[l][r].second = a[l] + dp[l + 1][r].second;
        } else {
          dp[l][r].first = dp[l][r - 1].first;
          dp[l][r].second = a[r] + dp[l][r - 1].second;
        }
      }
    }
  }
  cout << dp[0][n-1].first - dp[0][n-1].second << endl;
  return 0;
}


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

int main(){
    long long N, K, ans=0, tmp=0, tmp2=0, mod = 1e9+7;
    cin >> N >> K;
    vector<int> a(N);
    for(int i=0; i<N; i++){
	cin >> a[i];
    }

    for(int i=0; i<N; i++){
	for(int j=i; j<N; j++){
	    if(a[i]>a[j])
		tmp++;
	}
	for(int j=0; j<N; j++){
	    if(a[i]>a[j])
		tmp2++;		
	}
    }
    ans = (tmp*K%mod + ((((K-1)*K)/2)%mod*tmp2)%mod)%mod;
    cout << ans << endl;
}



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

int main() {
  int N, frag = 0;
  string cache;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    cin >> cache;
    if (cache == "Y") {
      frag = 1;
      break;
    } 
  }
  
  if (frag == 1) {
    cout << "Four" << endl;
  } else {
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<pair<int, int>> graph[100001];
int ans[100001];
signed main() {
    //Ввод графа и вершины start.
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		--a, --b;
		graph[a].push_back({b, c});
		graph[b].push_back({a, c});
	}
	int Q, K;
	cin >> Q >> K;
    for (int i = 0; i < n; i++) {
        ans[i] = LONG_MAX;
    }
    int start = K - 1;
    ans[start] = 0;

    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;

    q.push({0, start});

    while (!q.empty()) {
        pair<int, int> c = q.top();
        q.pop();

        int dst = c.first, v = c.second;

        if (ans[v] < dst) {
            continue;
        }

        for (pair<int, int> e: graph[v]) {
            int u = e.first, len_vu = e.second;

            int n_dst = dst + len_vu;
            if (n_dst < ans[u]) {
                ans[u] = n_dst;
                q.push({n_dst, u});
            }
        }
    }
    for (int i = 1; i <= Q; i++) {
    	int u, v;
    	cin >> u >> v;
    	u--; v--;
    	cout << ans[u] + ans[v] << '\n';
    }
}

Measured memory_bytes: 13996
let readIntArray () =
    stdin.ReadLine().Split(" ") |> Array.map int

let readInt () = stdin.ReadLine() |> int

()
|> readIntArray
|> fun x ->
    let y = readInt ()
    let max = x |> Array.max
    max
    |> ((*) (pown 2 y))
    |> ((+) (Array.sum x))
    |> (-)
    <| max
    |> printfn "%d"


Measured memory_bytes: 29780
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

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

    int a, b, c;
    int count = 0;
    cin >> a >> b >> c;

    if (a == b) count++;
    if (b == c) count++;
    if (a == c) count++;

    cout << ((3 - count) > 0 ? (3 - count) : 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#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;

#define ll long long
#define ld long double
#define pb push_back
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define umap unordered_map
#define uset unordered_set
#define forz(i, n) for (ll i = 0; i < n; i++)
#define fore(i, m, n) for (ll i = m; i <= n; i++)
#define forr(i, n, m) for (ll i = n; i >= m; i--)
#define itor(it,x) for(auto it=x.begin();it!=x.end();it++)
#define itor2(it,x) for(auto it=x->begin();it!=x->end();it++)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define deci(n) fixed << setprecision(n)
#define setbits(n) __builtin_popcountll(n)
#define zrobits(n) __builtin_ctzll(n)
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define gcd __gcd
#define raunak ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define pv(v) forz(qaz,v.size()) cout<<v[qaz]<<" "; cout<<endl;
#define pa(arr,n) forz(qaz,n) cout<<arr[qaz]<<" "; cout<<endl;

#define oset tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

ll po(ll a,ll b,ll m){
    ll res=1;
    while(b>0){
        if(b&1) res=((res%m)*(a%m))%m;
        a=((a%m)*(a%m))%m;
        b>>=1;
    }
    return res;
}
ll modi(ll a,ll m){
    return po(a,m-2,m);
}
ll lcm(ll a, ll b){ 
    return (a*b)/(gcd(a, b));
}

/////////////////////(^_^)/////////////////////(^_^)/////////////////////(^_^)/////////////////////

int main(){
    raunak;
    string s,t;
    cin>>s>>t;
    ll ans=0;
    forz(i,t.size()){
        if(s[i]!=t[i]) ans++;
        
    }
    p1(ans);
    return 0;
}

Measured memory_bytes: 3828
#include "bits/stdc++.h"
#define rep(i,N) for (int (i) = 0; (i) < (N); (i)++)

int main() {

	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);
	
	int N, K; std::cin >> N >> K;
	unsigned long long ans = K;
	rep(i, N - 1)ans *= (K - 1);

	std::cout << ans;

	return 0;
}

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

int arr[101010];
int main()
{
    int N, M;
    int ac = 0, pe = 0;
    scanf("%d%d", &N, &M);
    for(int i=0; i<M; ++i)
    {
        char a[101];
        int t; scanf("%d%s", &t, a);
        if(arr[t] == -1) continue;
        if(a[0] == 'A')
        {
            pe += arr[t];
            ac++;
            arr[t] = -1;
        }
        else
        {
            arr[t]++;
        }
    }
    printf("%d %d\n",ac, pe);
}

Measured memory_bytes: 640
// Vicfred
// https://atcoder.jp/contests/abc162/tasks/abc162_b
// simulation
import std.conv;
import std.stdio;
import std.string;

void main() {
    int n = readln.chomp.to!int;

    long sum = 0;
    foreach(i; 1..n+1) {
        if(i%3 != 0 && i%5 != 0)
            sum += i;
    }
    sum.writeln;
}



Measured memory_bytes: 2732
#include <iostream>
using namespace std;
 
int main() {
	int xend, yend, N;
	cin>>xend>>yend>>N;
	int xstart=0;
	int ystart=0;
	while (N--){
		int x, y, n;
		cin>> x>>y>>n;
		if (n==1){
			xstart=max(xstart,x);
		}
		else if (n==2){
			xend=min(xend,x);
		}
		else if (n==3){
		 	ystart=max(ystart,y);
		}
		else if (n==4){
			yend=min(yend, y);
		}
	}
		int area=(xend-xstart)*(yend-ystart);
		if ((xend<=xstart)or(yend<=ystart)) cout << 0 << endl;
		else cout<<area<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
    int n;
    cin>>n;
    vector<ll> a(n+1),b(n);
    REP(i,n+1) cin>>a[i];
    REP(i,n) cin>>b[i];

    ll v=0;
    REP(i,n-i){
        if(a[i]>=b[i]){
            v+=b[i];
            b[i]=0;
        }else{
            v+=a[i];
            b[i]-=a[i];
            if(a[i+1]>=b[i]){
                v+=b[i];
                a[i+1]-=b[i];
            }else{
                v+=a[i+1];
                a[i+1]=0;
            }
        }
        if(i!=n-1-i){
            if(a[n-i]>=b[n-1-i]){
                v+=b[n-1-i];
                b[n-1-i]=0;
            }else{
                v+=a[n-i];
                b[n-1-i]-=a[n-i];
                if(a[n-i-1]>=b[n-1-i]){
                    v+=b[n-1-i];
                    a[n-i-1]-=b[n-1-i];
                }else{
                    v+=a[n-i-1];
                    a[n-i-1]=0;
                }
            }
        }
    }

    cout<<v<<endl;

	return 0; 
}


Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int main()
{
	char a[105],b[105],c[105];
	int len1,len2,len3;
	scanf("%s%s%s",a,b,c);
	len1=strlen(a);
	len2=strlen(b);
	len3=strlen(c);
    if(a[len1-1]==b[0]&&b[len2-1]==c[0])
    printf("YES\n");
    else
	printf("NO\n");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define mod 1000000007
using namespace std;
#define LL long double
int main() 
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    LL d,t,s;
    cin >> d >> t >> s;
    if(d>t*s)
        cout<<"No";
    else
        cout<<"Yes";
  }
 
 

Measured memory_bytes: 3736
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>

int main(int argc, char const *argv[])
{
    std::stack<int> S1;
    std::stack< std::pair<int, int> > S2;
    char ch;
    int sum = 0;

    for(int i = 0;std::cin >> ch;i++){
        if(ch == '\\') S1.push(i);
        else if(ch == '/' && S1.size() > 0){
            int j = S1.top();
            S1.pop();
            sum += i-j;
            int a = i-j;
            while(S2.size() > 0 && S2.top().first > j){
                a += S2.top().second;
                S2.pop();
            }
            S2.push(std::make_pair(j,a));
        }
    }

    std::vector<int> ans;
    
    while(S2.size() > 0){
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(),ans.end());
    std::cout << sum << std::endl;
    std::cout << ans.size();
    for(int i = 0;i < ans.size();i++){
        std::cout << " ";
        std::cout << ans[i];
    }
    std::cout << std::endl;

    return 0;
}



Measured memory_bytes: 3268
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        string[] str = Console.ReadLine().Split(' ');
        int a = int.Parse(str[0]);
        int b = int.Parse(str[1]);
        int c = int.Parse(str[2]);

        if(c >= a && c <= b){
            Console.WriteLine("Yes");
        }else{
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>

int main(void)
{
	int a, b, c;

	std::cin >> a >> b >> c;


	if ((a == b + c) ||
		(b == a + c) ||
		(c == a + b)) {
		std::cout << "Yes";
	}
	else {
		std::cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
S = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(S[K-1])

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

int main() {
  int n, m;
  cin >> n >> m;
  
  int a[m], b[m], c[n] = {};
  for (int i = 0; i < m; i++) 
    cin >> a[i] >> b[i];
  
  for (int i = 0; i < m; i++) {
    c[a[i] - 1]++;
    c[b[i] - 1]++;
  }
  
  for (int i = 0; i < n; i++) 
    cout << c[i] << endl;
}


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

using namespace std;

typedef pair<int, int> P;

int main() {
  int n;
  cin >> n;
  vector<vector<P>> v(n, vector<P>());
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    for (int j = 0; j < a; j++) {
      int x, y;
      cin >> x >> y;
      x--;
      v[i].emplace_back(x, y);
    }
  }

  int ans = 0;
  for (int bit = 0; bit < 1 << n; bit++) {
    vector<bool> t(n, false);
    for (int i = 0; i < n; i++) {
      if (bit >> i & 1) {
        t[i] = true;
      }
    }
    bool ok = true;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (t[i]) {
        cnt++;
        for (auto &w : v[i]) {
          if (t[w.first] != w.second) {
            ok = false;
          }
        }
      }
    }
    if (ok) {
      ans = max(ans, cnt);
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  vector<string> s,t;
  string a,b,c,d;
  bool ans=true;

  std::cin >> a >> b;

  s.push_back(a);
  t.push_back(b);

  sort(s[0].begin(),s[0].end());
  sort(t[0].begin(),t[0].end(),greater<int>());

  c=s[0];
  d=t[0];

  if(c>=d) ans=false;


  if(ans)printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a,num;
  scanf("%d",&a);
  num= a%10;
  if(num==2||num==4||num==5||num==7||num==9){
    printf("hon");
  }else if(num==3){
    printf("bon");
  }else{
    printf("pon");
  }
  return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
#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 rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.20f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;


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

	long double ans = a * b;

	cout << (ll)floor(ans) << endl;
	return 0;
}


Measured memory_bytes: 3732
import java.util.*;

public class Main{

    public static void main(String[] args){
        int n;
        int max, min, sum = 0, cur;
        Scanner scanner = new Scanner(System.in);

        int i;

        n = scanner.nextInt();
        while(n != 0){

            cur = scanner.nextInt();
            max = cur;
            min = cur;
            
            cur = scanner.nextInt();
            if(cur > max) max = cur;
            else min = cur;

            sum = 0;
            
            for(i = 0; i < n - 2; i++){
                cur = scanner.nextInt();
                if(cur > max){
                    sum = sum + max;
                    max = cur;
                }
                else if(cur < min){
                    sum = sum + min;
                    min = cur;
                }
                else sum = sum + cur;
            }
            sum = sum / (n - 2);
            System.out.println(sum);
            n = scanner.nextInt();
        }

        scanner.close();
    }
}


Measured memory_bytes: 28600
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	vector<pair<ll, ll>> v;
	vector<pair<ll, ll>> w;
	for( int i = 0; i < n; ++i ){
		ll x, y;
		cin >> x >> y;
		v.emplace_back(x, y);
		w.emplace_back(x, y);
	}
	ll ans = -1;
	sort( v.begin(), v.end() );
	sort( w.begin(), w.end(), []( auto &x, auto &y ){ return x.second < y.second; } );
	for( int rangex = 1; rangex < n; ++rangex ){
		for( int ix = 0; ix + rangex < n; ++ix ){
			ll yoko = v.at(rangex+ix).first - v.at(ix).first;
			for( int rangey = 1; rangey < n; ++rangey ){
				for( int iy = 0; iy + rangey < n; ++iy ){
					ll a = v.at(ix).first;
					ll b = v.at(rangex+ix).first;
					ll c = w.at(iy).second;
					ll d = w.at(rangey+iy).second;
					int cnt = 0;
					for( int i = 0; i < n; ++i ){
						ll x = v.at(i).first;
						ll y = v.at(i).second;
						if( a <= x && x <= b && c <= y && y <= d ) ++cnt;
					}
					if(
						a <= w.at(iy).first && w.at(iy).first <= b
						&&
						a <= w.at(rangey+iy).first && w.at(rangey+iy).first <= b
						&&
						c <= v.at(ix).second && v.at(ix).second <= d
						&&
						c <= v.at(rangex+ix).second && v.at(rangex+ix).second <= d
						&&
						cnt >= k
					){
						ll tate = w.at(rangey+iy).second - w.at(iy).second;
						if( ans == -1 ){
							ans = yoko * tate;
						} else{
							ans = min( ans, yoko * tate );
						}
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// B - Shift only
#include <stdio.h>

int main(void){
    int n, cnt=0, a[210];
    scanf("%d", &n);
    for(int i=0; i<n; i++){scanf("%d", &a[i]);}
    int judge=0;
    while(1){
        for(int i=0; i<n; i++){
            if(a[i]%2!=0){judge=1;}
        }
        if(judge){break;}
        for(int i=0; i<n; i++){a[i]/=2;}
        cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}

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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main(){
  fastIO;
  string t;
  cin >> t;
  int n = t.size();
  if(n % 2 == 1)
    cout << "No\n";
  else{
    for(int i = 1; i < n; i += 2){
      if(t[i - 1] != 'h' || t[i] != 'i'){
        cout << "No\n";
        return 0;
      }
    }
    cout << "Yes\n";
  }
  return 0;
}

Measured memory_bytes: 256
def sgn(a, b):
    return int(a*b/abs(a*b))

numbers = list(map(int, input().split()))
numbers_dict = {1:numbers[0], 2:numbers[1], 3:numbers[2], -3:numbers[3], -2:numbers[4], -1:numbers[5]}
numbers_ver_dict = {numbers[0]:1, numbers[1]:2,numbers[2]:3,numbers[3]:-3, numbers[4]:-2,numbers[5]:-1}
n = int(input())
for _ in range(n):
    a, b = map(int, input().split())
    var_a = numbers_ver_dict[a]
    var_b = numbers_ver_dict[b]
    if abs(var_a) == 1:
        if abs(var_b) == 2:
            print(numbers_dict[sgn(var_a,var_b)*3])
        else:
            print(numbers_dict[-sgn(var_a,var_b)*2])
    elif abs(var_a) == 2:
        if abs(var_b) == 1:
            print(numbers_dict[-sgn(var_a, var_b)*3])
        else:
            print(numbers_dict[sgn(var_a,var_b)])
    else:
        if abs(var_b) == 1:
            print(numbers_dict[sgn(var_a, var_b)*2])
        else:
            print(numbers_dict[-sgn(var_a,var_b)])




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

using namespace std;

const int N = 610;
const int Mod = 1e9 + 7;

int add(int a, int b) {
  return (a += b) >= Mod ? a - Mod : a;
}

int sub(int a, int b) {
  return (a -= b) < 0 ? a + Mod : a;
}

int mul(int a, int b) {
  return 1ll * a * b % Mod;
}

int n, k, a[N], b[N], f[N][N], g[N][N], h[N];

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d %d", &a[i], &b[i]);
  }
  h[0] = 1;
  for (int i = 1; i <= n; i++) {
    h[i] = mul(h[i - 1], i * 2 - 1);
  }
  int ans = 0;
  for (int len = 2; len <= 2 * n; len += 2) {
    for (int l = 1; l + len - 1 <= 2 * n; l++) {
      int r = l + len - 1, cnt = 0;
      bool flag = 1;
      for (int i = 1; i <= k; i++) {
        bool ina = l <= a[i] && a[i] <= r;
        bool inb = l <= b[i] && b[i] <= r;
        if (ina && inb) cnt++;
        else if (ina || inb) flag = 0;
      }
      if (!flag) continue;
      cnt = len / 2 - cnt;
      f[l][r] = g[l][r] = h[cnt];
      for (int i = l + 1; i < r - 1; i += 2) {
        f[l][r] = sub(f[l][r], mul(f[l][i], g[i + 1][r]));
      }
      ans = add(ans, mul(f[l][r], h[n - k - cnt]));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#include <cstring>
#include <limits>
using namespace std;
#define ll long long int
#define lli long long int
#define fw(i, s, e) for (ll i = s; i < e; ++i)
#define fe(i, s, e) for (ll i = s; i <= e; ++i)
#define fb(i, e, s) for (ll i = e; i >= s; --i)
#define L(T)  \
    ll T;     \
    cin >> T; \
    while (T--)
#define FASTIO                   \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr);            \
    cout.tie(nullptr);
#define mem(a, i) memset(a, i, sizeof(a))
#define ld long double
#define endl "\n"
#define in(P) \
    ll P;     \
    cin >> P;
int main()
{
    FASTIO
    // L(T)
    {
        in(n);
        ll a[n + 90];
        ll b[n + 90];

        ll an = 0;
        ll orr = 0;
        fw(i, 0, n)
        {
            cin >> a[i];
            orr = orr ^ a[i];
        }
        fw(i, 0, n)
        {
            b[i] = orr ^ a[i];
            cout << b[i] << " ";
        }
        cout << endl;
    }
    return 0;
}

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

int n, a[2000005], ans = 2e7, k;

int main() {
	cin>>k>>n;
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for(int i = 2; i <= n; i++) 
	    ans = min(ans, k - a[i] + a[i - 1]);
	ans = min(ans, a[n] - a[1]);
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
import sys
from itertools import permutations

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, M, R = map(int, input().split())
    r = list(map(int, input().split()))
    P = permutations(r)

    dp = [[INF] * N for _ in range(N)]
    for i in range(N):
        dp[i][i] = 0

    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        dp[a][b] = c
        dp[b][a] = c

    # ワーシャルフロイド
    for k in range(N):
        for i in range(N):
            for j in range(N):
                tmp = dp[i][k] + dp[k][j]
                if tmp < dp[i][j]:
                    dp[i][j] = tmp

    ans = INF
    for p in P:
        tmp = 0
        for i in range(R - 1):
            tmp += dp[p[i] - 1][p[i + 1] - 1]

        if tmp < ans:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 4636
#![allow(unused_imports)]

//input
use proconio::input;
use proconio::marker::{Bytes, Chars};
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

//use std::cmp::*;

fn main() {
    input! {
        v: [usize;5],
    }
    for i in 0..5 {
        if v[i] != i + 1 {
            println!("{}", i + 1);
        }
    }
}


Measured memory_bytes: 1996
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            final String line = br.readLine();
            if (line == null) break;
            double weight = Double.parseDouble(line);
            if (weight<=48.00){
                System.out.println("light fly");
            }else if (48.00<weight && weight<=51.00){
                System.out.println("fly");
            }else if (51.00<weight && weight<=54.00){
                System.out.println("bantam");
            }else if (54.00<weight && weight<=57.00){
                System.out.println("feather");
            }else if (57.00<weight && weight<=60.00){
                System.out.println("light");
            }else if (60.00<weight && weight<=64.00){
                System.out.println("light welter");
            }else if (64.00<weight && weight<=69.00){
                System.out.println("welter");
            }else if (69.00<weight && weight<=75.00){
                System.out.println("light middle");
            }else if (75.00<weight && weight<=81.00){
                System.out.println("middle");
            }else if (81.00<weight && weight<=91.00){
                System.out.println("light heavy");
            }else if (weight>91.00){
                System.out.println("heavy");
            }
        }
    }
}

Measured memory_bytes: 16904
def cc083():
    import sys
    x,y = list(map(int, input().split()))

    if x == y:
        print(1)
        sys.exit()

    m = x
    d = 1
    while True:
        m *= 2
        if m > y:
            print(d)
            sys.exit()
        d += 1

cc083()

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
 
int main(){
    int a, b;
    while(cin >> a >> b && !(a == 0 && b == 0)){
        for(int i = 0; i < a; i++){
            for(int j = 0; j < b; j++){
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
import java.io.PrintWriter
import java.math.BigDecimal

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val (a, b) = readStringList()
    val ans = BigDecimal(a).multiply(BigDecimal(b)).toLong()
    println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 36032
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

mint factorial(ll n) {
  mint answer = 1;
  while (n > 1) {
    answer *= n;
    n--;
  }
  return answer;
}

mint combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

mint permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

// setprecision(8) 桁数指定
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

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

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

vector<ll> Eratosthenes(const ll N) {
  bool is_prime[1000000 + 1];
  vector<ll> P;
  for (ll i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  for (ll i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (ll j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

int main() {
  char x, y;
  cin >> x >> y;
  char ans = (x > y ? '>' : '<');
  ans = (x == y ? '=' : ans);
  cout << ans << endl;
  return 0;
}

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

ll dp[101][101][2];

int main()
{
	string n;
	cin >> n;
	int k;
	cin >> k;

	dp[0][0][0] = 1;

	for(int i = 0;i<n.size();i++)
	{
		for(char c = '0';c<n[i];c++)
		{
			for(int j = 0;j<101;j++)
			{
				if(c=='0')dp[i+1][j][1] += dp[i][j][0];
				else dp[i+1][j+1][1] += dp[i][j][0];
			}
		}
		if(n[i]=='0')for(int j = 0;j<101;j++)dp[i+1][j][0] += dp[i][j][0];
		else for(int j = 0 ;j<101;j++)dp[i+1][j+1][0] += dp[i][j][0];

		for(char c = '0';c<='9';c++)
		{
			for(int j = 0;j<101;j++)
			{
				if(c=='0')dp[i+1][j][1] += dp[i][j][1];
				else dp[i+1][j+1][1] += dp[i][j][1];
			}
		}
	}
	//for(int i = 0;i<100;i++)
	//{for(int j=0;j<4;++j)cout<<dp[j][i][1]<<' ';cout<<endl;}
	cout<<dp[n.size()][k][0]+dp[n.size()][k][1]<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
struct zifu
{
	char z[15];
};
int vis[200005];
zifu arr[200005];
bool compare( zifu a,zifu b)
{
	if(strcmp(a.z, b.z)<0)
		return true;
	else
		return false;
}
int main()
{
	int n;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		scanf("%s", arr[i].z);
	}
	sort(arr, arr+n, compare);
	int max1=-1;
	int count=1;
	if(n==1)
	{
		printf("%s\n", arr[0]);
		return 0;
	}
	for(int i=0;i<n-1;i++)
	{
		if(strcmp(arr[i].z, arr[i+1].z)==0)
		{
			count++;
			vis[i+1]=count;
		}
		else
		{
			vis[i]=count;
			max1=max(max1, count);
			count=1;
		}
	}
	max1=max(max1, count);
	if(strcmp(arr[n-1].z, arr[n-2].z)!=0)
	{
		vis[n-1]=1;
	}
	for(int i=0;i<n;i++)
	{
		if(vis[i]==max1)
		{
			printf("%s\n", arr[i].z);
		}
	}

	return 0;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

const long long MOD = 1000000007LL;
const long long INF = 1e18;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

struct chash {
    static uint64_t splitmix64(uint64_t x) {x += 0x8e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf54876d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
    size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM);}
    size_t operator()(pair<uint64_t,uint64_t> x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1);}
};

long long a[22],b[22],c[22];
int n;

long long helper(int pos, int ate=-1){
    if(pos == n) return 0;
    if(ate+1==a[pos]) return max(helper(pos+1),helper(pos+1,a[pos])+c[ate]+b[a[pos]]);
    return max(helper(pos+1),helper(pos+1,a[pos])+b[a[pos]]);
}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n;

    for(int i = 0; i < n; ++i) cin >> a[i];
    for(int i = 1; i <= n; ++i)cin >> b[i];
    for(int i = 1; i < n; ++i) cin >> c[i];

    cout << helper(0,false);

    return 0;

}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int n, tmp, max, min;
    long sum = 0;
    max = -1000000;
    min = 1000000;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%d", &tmp);
        if(max < tmp)
            max = tmp;
        if(min > tmp)
            min = tmp;
        sum = sum + tmp;
    }
    printf("%d %d %ld\n", min, max, sum);
}


Measured memory_bytes: 2080
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N = input()
    long=len(N)
    M= int(N)

    seq=(3,5,7)
    cnt=0
    for j in range(3,long+1):
        for i in product(seq,repeat=j):
            if i.count(3)>=1 and i.count(5)>=1 and i.count(7)>=1\
                    and int(''.join(str(j) for j in i))<=M:
                cnt+=1
    print(cnt)




resolve()

Measured memory_bytes: 65264
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x*(-1), a))
queue = heapq.heapify(a)

for i in range(m):
    x = heapq.heappop(a)*(-1)
    x //= 2
    heapq.heappush(a, x*(-1))

print(sum(a)*(-1))

Measured memory_bytes: 92096
"""
1 2 3 4 5 6 7

1

1 2
2 1

2 1 3
3 1 2

3 1 2 4
4 2 1 3

4 2 1 3 5
5 3 1 2 4

5 3 1 2 4 6
6 4 2 1 3 5

6 4 2 1 3 5 7
7 5 3 1 2 4 6
"""

n = int(input())
a = list(map(int, input().split()))
ans = ""
if(n % 2 == 0):
    for i in range(n-1, 0, -2):
        ans += str(a[i]) + " "
    for i in range(0, n-1, 2):
        ans += str(a[i]) + " "
    print(ans)
else:
    for i in range(n-1, -1, -2):
        ans += str(a[i]) + " "
    for i in range(1, n-1, 2):
        ans += str(a[i]) + " "
    print(ans)

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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  while (a <= b) {
    if (a % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
    a++;
  }
  cout << "NG" << endl;
  return 0;
}

Measured memory_bytes: 3584
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) printf("Case #%d: ",i);
using namespace std;
typedef long long int ll;
typedef complex<double> com;
typedef pair<int, int> P;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;



int main(){
	int n; cin >> n;
	vector<vector<int>> a(n), dis(n);
	rep(i, 0, n) {
		a[i].resize(n); dis[i].resize(n);
	}
	rep(i, 0, n)rep(j, 0, n) {
		cin >> a[i][j]; dis[i][j] = a[i][j];
	}
	rep(k, 0, n)rep(i, 0, n)rep(j, 0, n) {
		if (i == j) continue;
		if (k != i && k != j && a[i][j] == a[i][k] + a[k][j]) dis[i][j] = 0;
		if (a[i][j] > a[i][k] + a[k][j]) {
			cout << -1 << endl;
			return 0;
		}
	}
	ll ans = 0;
	rep(i, 0, n)rep(j, 0, i) ans += dis[i][j];
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define eps 1e-6
#define rep(i,n) for(int i=0;i<n;++i)
#define snc(a,b,c) ((a)?(b):(c))
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define ins insert
#define pb push_back
using namespace std; 

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << min(a,b)+min(c,d) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;
using ull = unsigned long long;

int main() {
    ull N;
    cin >> N;
    string S = to_string(N);
    ull Fx = 0;
    for (char c : S) {
        Fx += c - '0';
    }
    if (N % Fx == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
b = [0 for _ in range(n)]
for i in reversed(range(n)):
    if i * 2 >= n:
        b[i] = a[i]
        continue
    s = 0
    for j in range(i, n, i + 1):
        s += b[j]
    if s % 2 != a[i]:
        b[i] = 1
print(sum(b))
for i in range(n):
    if b[i] == 1:
        print(i + 1, end=' ')
print('')


Measured memory_bytes: 90720
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  string s1 = "AAA";
  string s2 = "BBB";
  if (s1<S && S<s2) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
B = []
C = []
for i in range(1, N+2):
  B.append(abs(A[i] - A[i-1]))
  if i >= 2:
    C.append(abs(A[i] - A[i-2]))
S = sum(B)
for i in range(1, N+1):
  print(S - B[i-1] - B[i] + C[i-1])

Measured memory_bytes: 98620
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(elem, _list) for(auto& (elem) : (_list))
#define debug(_list) foreach(e, _list){ cout << e << sp; } cout << next
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define ALL(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e);
#define INF 1e+8
#define PI acos(-1)
#define TAU PI * 2
using ll = long long;
using ull = unsigned long long;
const ll MOD = 1000000007;

int main(){
    ll n, k;
    cin >> n >> k;

    ll ans = 0;
    for(ll i = k; i <= n + 1; ++i){
        ll left = i * (i - 1) / 2;
        ll right = (2 * n - i + 1) * i / 2;
        ll add = right - left + 1;
        ans = (ans + add) % MOD;
    }

    println(ans);
}

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

class Cmondai
{
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray();
        var sunuke = a[0];
        var araiguma = 0L;
        for (int i = 1; i < N; ++i) araiguma += a[i];
        var ans = Math.Abs(sunuke - araiguma);
        for (int i = 1; i < N-1; ++i)
        {
            sunuke += a[i];
            araiguma -= a[i];
            var sa = Math.Abs(sunuke - araiguma);
            if (sa < ans) ans = sa;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 35844
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<string> vs;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

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

	int Sx, Sy, Tx, Ty;
	cin >> Sx >> Sy >> Tx >> Ty;
	
	int dx = Tx - Sx;
	int dy = Ty - Sy;

	string ans;
	ans += string(dy, 'U') + string(dx, 'R');
	ans += string(dy, 'D') + string(dx, 'L');
	ans += 'L' + string(dy + 1, 'U') + string(dx + 1, 'R') + 'D';
	ans += 'R' + string(dy + 1, 'D') + string(dx + 1, 'L') + 'U';

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
    cout << fixed << setprecision(10);

    LLI n;
    cin >> n;

    vector<LLI> a(n);

    REP(i, n)cin >> a[i];


    LLI h = a[0];
    LLI cnt = 0;
    REP(i, n)
    {
        cnt += _max(h - a[i], 0);
        chmax(h,a[i]);
    }
    cout << cnt;

    return 0;
}

Measured memory_bytes: 4836
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T> vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    bool ok = 0;
    int len = 0;
    rep(i, N) {
        int a, b;
        cin >> a >> b;
        if(a == b)
            len++;
        else
            len = 0;
        if(len >= 3)
            ok = 1;
    }
    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3632
N = int(input())
F = [[int(f) for f in input().split()] for _ in range(N)]
P = [[int(p) for p in input().split()] for _ in range(N)]

ans = -10**18
for i in range(2**10+1, 2**11):
    num = 0
    b = bin(i)
    for j in range(N):
        cnt = 0
        for k in range(10):
            if F[j][k] == 1 and b[k+3] == "1":
                cnt += 1
        num += P[j][cnt]
    ans = max(ans, num)
    
print(ans)

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

int N, M;
vector<pair<pair<int, int>, int>> pyn;

int main(){
  cin >> N >> M;
  vector<pair<int, int>> npyn(M);

  for(int i = 0; i < M; i++){
    int p, y;
    cin >> p >> y;
    pyn.push_back(make_pair(make_pair(p, y), i));     //pが所属県、yが誕生年、iが出力順
  }

  sort(pyn.begin(), pyn.end());    //県番号でソート
  
  int ii = pyn[0].first.first;               //走査開始県番号(県番号の最小値)
  
  for(int i = 0; i < M;){
    int ser = 1;                                        //同県内に存在する都市の数　各県について求める
    while(pyn[i].first.first == ii){
      npyn[pyn[i].second] = make_pair(pyn[i].first.first, ser);     //その都市が県内で作られた順
      i++;
      ser++;
    }
    ii = pyn[i].first.first;     //次の県番号を取得
  }

  for(int i = 0; i < M; i++)
    printf("%06d%06d\n", npyn[i].first, npyn[i].second);       //0埋めを採用

  return 0;
  
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long int a, b;
    cin >> a >> b;

    if ((a+b)%2 == 0)
    {
    	cout << (a+b)/2;
    }
    else
    {
    	cout << "IMPOSSIBLE";
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <cstdio>

#define MAX 17

using  namespace std;

struct matatabi
{
	int x1;
	int y1;
	int x2;
	int y2;
};

int dp[MAX][MAX];

int main(void)
{
	int n;
	int gx,gy;
	int p;
	int check1,check2;
	int i1,i2,i3,i4;
	int a,b,c,d;
	matatabi m;

	cin>>n;
	for(i1=0;i1<n;i1++){
		cin>>gx>>gy;
		cin>>p;

		vector<matatabi> v;
		for(i2=0;i2<p;i2++){
			cin>>a>>b>>c>>d;
			if((a+b)<(c+d)) {
				m.x1=a;
				m.y1=b;
				m.x2=c;
				m.y2=d;	
			}
			else {
				m.x1=c;
				m.y1=d;
				m.x2=a;
				m.y2=b;
			}
			v.push_back(m);
		}
		//cout<<endl;
		memset(dp,0,sizeof(dp));
		dp[1][1]=1;

		for(i2=1;i2<=gy+1;i2++){
			for(i3=1;i3<=gx+1;i3++){
				if(i2==1 && i3==1) continue;

				check1=0;
				check2=0;
				for(i4=0;i4<p;i4++){
					if(i2==v[i4].y2+1 && i3==v[i4].x2+1) {
						if(i2-1==v[i4].y1+1 && i3==v[i4].x1+1) check1=1;
						if(i2==v[i4].y1+1 && i3-1==v[i4].x1+1) check2=1;
					}
				}

				if(check1!=1) dp[i2][i3]+=dp[i2-1][i3];
				if(check2!=1) dp[i2][i3]+=dp[i2][i3-1];

			}
		}

		/*for(i2=1;i2<=gy+1;i2++){
			for(i3=1;i3<=gx+1;i3++){
				printf("%4d ",dp[i2][i3]);
			}
			printf("\n");
		}*/

		if(dp[gy+1][gx+1]==0) cout<<"Miserable Hokusai!"<<endl;
		else cout<<dp[gy+1][gx+1]<<endl;

	}
	return 0;
}

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



int main(){
    ll N;
    double aaa,total=0;
    cin >> N;
    vector<double> x(N);
    vector<double> y(N);
    vector<double> z;
    rep(i,N) cin >> x[i] >> y[i];
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            aaa=sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
            z.push_back(aaa);
        }
    }
    
    for(int i=0;i<z.size();i++){
        total+=z[i];
    }

    total/=z.size();
    total=total*(N-1);
    printf("%.8lf",total);

    return 0;
}


Measured memory_bytes: 256