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

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

int main() {
  string s;
  cin >> s;
  int cnta = -1, cntz = 0;
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] == 'A' && cnta == -1) cnta = i;
    if (s[i] == 'Z') cntz = i;
  }

  cout << cntz - cnta + 1 << endl;
  return 0;
}


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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

const int N = 3e6 + 7, M = 1000000007, inf = 1e9;
const long long INF = LLONG_MAX;

int n, Q;
int arr[N + 2];
int dx[8] = {1, -1, 0, 0, 1, 1, -1, -1};  	// d, u, l, r
int dy[8] = {0, 0, -1, 1, 1, -1, 1, -1};

int h, w, k;

bool safe(int x, int y)
{
	if ( x < 0 or y < 0 or x >= h or y >= w ) return 0;
	return 1;
}

#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{	rtn
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

#define vec vector
#define ppii pair<  pair<int,int>, int >
void solve()
{
	pii p1, p2;
	cin >> h >> w >> k;
	cin >> p1.ff >> p1.ss;
	cin >> p2.ff >> p2.ss;

	p1.ff--; p1.ss--;
	p2.ff--; p2.ss--;

	vec< vec<char> > mat(h, vec<char> (w));
	lop(i, 0, h)lop(j, 0, w) cin >> mat[i][j];

	vec< vec<bool> > vis(h, vec<bool>(w, false));
	vec< vec<int> > dis(h, vec<int>(w, inf));

	vis[p1.ff][p1.ss] = 1;
	dis[p1.ff][p1.ss] = 0;
	queue< pii > q;
	q.push(p1);

	int cnt = 1;
	while ((q.size()))
	{
		int x = q.front().ff, y = q.front().ss;
		q.pop();
		lop(d, 0, 4)
		{
			lop(j, 1, k + 1)
			{
				int nx = x + j * dx[d], ny = y + j * dy[d];
				if ( !safe(nx, ny) or mat[nx][ny] == '@') break;
				if ( dis[nx][ny] < dis[x][y] + 1 ) break;
				if ( vis[nx][ny] ) continue;


				vis[nx][ny] = 1;
				dis[nx][ny] = dis[x][y] + 1;
				q.push({nx, ny});
			}
		}
	}


	int ans = dis[p2.ff][p2.ss];
	if ( ans >= h * w ) ans = -1;
	cout << ans << endl;


}

int32_t main()
{
	ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);

	int test = 1;
	// cin >> test;
	while (test--)solve();


}





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

#define ll long long int
#define ull unsigned long long int
#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


using namespace std;

const int INF = 1e9 + 7;
const int N = 1e5+5;

int main() {

	IO;
	
	int n, k;
	cin >> n >> k;
	vector<int> ar(n);
	for (int i = 0; i < n; ++i) {
		cin >> ar[i];
	}
	int ans = 0;
	sort(ar.begin(), ar.end());
	for (int i = 0; k--; ++i) {
		ans+= ar[i];
	}
	
	cout << ans;
}


Measured memory_bytes: 3648
#include <cstdio>
using namespace std;

typedef long long LL;

int main(){
	LL s = 0;
	int n, x;
	char p;

	bool ok = true;
	scanf("%d", &n);
	for(int i = 0; i < n; ++i){
		scanf(" %c%d", &p, &x);
		if(p == '('){
			s += x;
		}
		else{
			s -= x;
			if(s < 0){
				ok = false;
			}
		}
	}

	if(s != 0){
		ok = false;
	}

	puts(ok ? "YES" : "NO");
}

Measured memory_bytes: 1012
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, Q, S, T, A[212345], L[212345], R[212345], X[212345];
LL dif[212345], ans;

int main()
{
	in >> N >> Q >> S >> T;
	rep(i, N + 1) { in >> A[i]; }
	rep(i, Q) { in >> L[i] >> R[i] >> X[i]; }

	rep(i, N)
	{
		if (A[i] < A[i + 1]) { ans -= S*(A[i + 1] - A[i]); }
		else { ans += T*(A[i] - A[i + 1]); }
		dif[i] = A[i + 1] - A[i];
	}
	rep(i, Q)
	{
		LL prev = -(dif[L[i] - 1] > 0 ? dif[L[i] - 1] * S : dif[L[i] - 1] * T);
		dif[L[i] - 1] += X[i];
		LL now = -(dif[L[i] - 1] > 0 ? dif[L[i] - 1] * S : dif[L[i] - 1] * T);
		ans += (now - prev);
		if (R[i] < N)
		{
			prev = -(dif[R[i]] > 0 ? dif[R[i]] * S : dif[R[i]] * T);
			dif[R[i]] -= X[i];
			now = -(dif[R[i]] > 0 ? dif[R[i]] * S : dif[R[i]] * T);
			ans += (now - prev);
		}
		out << ans << std::endl;
	}
	return 0;
}

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

/*
    +---+
    |   | 
    | 1 |
    |   |
+---+---+---+
|   |   |   |
| 4 | 2 | 3 |
|   |   |   |
+---+---+---+
    |   |
    | 6 |
    |   |
    +---+
    |   |
    | 5 |
    |   |
    +---+
*/

enum{
  TOP    = 0,
  FRONT  = 1,
  RIGHT  = 2,
  LEFT   = 3,
  BACK   = 4,
  BOTTOM = 5,
};

//rotation {TOPtoFRONT, TOPtoRIGHT, FRONTtoRIGHT}
int r[4][6] = {
  {4,0,2,3,5,1},
  {3,1,0,5,4,2},
  {0,3,1,4,2,5} };

void rot(vector<int> &dice, int dir){
  vector<int> tmp = dice;
  rep(i,6)dice[i] = tmp[r[dir][i]];
}

int t[3][3], f[3][3];

vector<int> ans;
vector<int> cube[27];
const int dx[]={0,0,-1,1,0,0}, dy[]={0,-1,0,0,1,0}, dz[]={-1,0,0,0,0,1};

bool check(int pos, const vector<int> &dice){
  int x = pos%3, y = pos/3%3, z = pos/9%3;

  if(y==0){
    if(f[z][x]>0 && f[z][x] != dice[FRONT])return false;
  }
  if(z==0){
    if(t[2-y][x]>0 && t[2-y][x] != dice[TOP])return false;
  }
  rep(d,6){
    int nx = x+dx[d], ny = y+dy[d], nz = z+dz[d];
    if(nx<0 || ny<0 || nz<0)continue;
    if(nx>2 || ny>2 || nz>2)continue;
    int nxt = nz*9+ny*3+nx;
    if(cube[nxt][5-d]>0 && dice[d] + cube[nxt][5-d] != 7)return false;
  }
  return true;
}

void rec(int pos){
  if(pos==27){
    int sum = 0;
    rep(y,3)rep(z,3)sum += cube[z*9+y*3+2][RIGHT];
    ans.push_back(sum);
    return;
  }

  vector<int> dice(6), init(6,-1);
  rep(i,6)dice[i] = i+1;

  rep(azu,6){
    if(azu&1)rot(dice,0);
    else rot(dice,1);

    rep(nyan,4){
      rot(dice,2);

      if(check(pos,dice)){
	cube[pos] = dice;
	rec(pos+1);
	cube[pos] = init;
      }
    }
  }
  return;
}

int main(){
  int n;
  cin >> n;
  while(n--){
    rep(i,3)rep(j,3)cin >> t[i][j];
    rep(i,3)rep(j,3)cin >> f[i][j];

    ans.clear();
    rep(i,27)cube[i] = vector<int>(6,-1);
    rec(0);

    if(ans.size()==0){
      cout << 0 << endl;
    }else{
      sort(ans.begin(),ans.end());
      ans.erase(unique(ans.begin(),ans.end()),ans.end());
      rep(i,ans.size()){
	cout << ans[i] << (i+1==(int)ans.size()?"\n":" ");
      }
    }
  }
}

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

int main(){
    int s;
    cin>>s;
    set<int> ss;
    for(int i=1;;i++){
        if(ss.count(s)){
            cout<<i<<endl;
            return 0;
        }
        else{
            ss.insert(s);
            if(s%2==0) s=s/2;
            else s=3*s+1;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>     // std::cout
#include <algorithm>    // std::sort
#include <vector>       // std::vector


using namespace std;

long long solve(vector<int>& players)
{
	sort(players.rbegin(), players.rend());
	long long confort = players[0];
	int len = players.size() - 2;
	int i = 1;
	int limit;
	if (len % 2)
		limit = 1;
	else
		limit = 0;
	while (len != limit) {
		confort += 2 * players[i];
		i++;
		len -= 2;
	}
	if(len == 1)
		confort += players[i];
	return confort;
}


int main()
{
	int N;
	cin >> N;
	vector<int> players(N);
	for(int i = 0; i < N; i++)
		cin >> players[i];
	
	cout << solve(players) << endl;
	return 0;
}


Measured memory_bytes: 4056
using System;
using System.Collections.Generic;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();
            var strs = str.Split(' ');
            var N = int.Parse(strs[0]);
            var M = long.Parse(strs[1]);

            var ABs = new List<List<long>>();
            for (int i = 0; i < N; i++)
            {
                str = Console.ReadLine();
                strs = str.Split(' ');
                var AB = new List<long>();
                AB.Add(long.Parse(strs[0]));
                AB.Add(long.Parse(strs[1]));
                ABs.Add(AB);
            }
            ABs.Sort((a, b) => (int)(a[0] - b[0]));

            long sum = 0;
            for (int i = 0; i < N; i++)
            {
                if (ABs[i][1] > M)
                {
                    sum += ABs[i][0] * M;
                    break;
                }

                sum += ABs[i][0] * ABs[i][1];
                M -= ABs[i][1];
            }

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 29432
H,W=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]


lst=[]
flag=0
for h in range(H):
    for w in range(W) if h%2==0 else range(W-1,-1,-1):
        if A[h][w]%2:
            if not flag:
                flag=1
            else:
                flag=0
        if flag:
            if h%2==0:
                if w<W-1:
                    lst.append([h,w,h,w+1])
                elif h<H-1:
                    lst.append([h,w,h+1,w])
            else:
                if w>0:
                    lst.append([h,w,h,w-1])
                elif h<H-1:
                    lst.append([h,w,h+1,w])
lst=[[str(i+1) for i in M] for M in lst]
#print(H*W-sum([sum([i%2==1 for i in M]) for M in A])%2)
print(len(lst))
for i in lst:
    print(" ".join(i))


Measured memory_bytes: 102764
#include <bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i = 0; i < n; i++)
#define pb push_back
#define all(c) c.begin(),c.end()
 
 
int main()
{
 
    int r;
    cin >> r;
    cout << 3.14159 * 2 *r << endl;
 
 
 
 
    return 0;
}

Measured memory_bytes: 3788
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	int A, B, C;
	
	cin >> A >> B >> C;
	
	cout << ((A^B)^C) << endl;
}

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

#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
#define FOR_ITER(x, a) for(auto x = a.begin(); x != a.end(); ++x)

using namespace std;

typedef unsigned char byte;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
typedef pair<ll, ll> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }



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



int main(){
//    int n, l;
//    cin >> n >> k;
//    vector<bool> dislike(10, false);
//
//    FOR(i, 0, k) {
//        int t;
//        cin >> t;
//        dislike[t] = true;
//    }


    int a, b, c;

    cin >> a >> b >> c;

    int d = gcd(a, b);

    if (c % d == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;

int main() {
    int N;
    cin >> N;
    map<ll, int> MP;
    rep(i, 0, N){
        ll tmp;
        cin >> tmp;
        MP[tmp]++;
    }
    ll ans = 0;
    vector<ll>A(N);
    ll index = 0;
    for(auto & s : MP){
        if(s.second>=2){
            A[index] = s.first;
            index++;
        }
    }
    sort(A.begin(), A.end(), greater<ll>());
    
    if (MP[A[0]]>=4){
        ans = A[0] * A[0];
    } else {
       ans = A[0] * A[1];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >>n;
    int h;
    int s,ans=0;
    for(int i=0;i<n;i++){
        cin>>h;
        
        if(s<=h)  ans++;
        s = max(s,h);
    }
    cout<<ans<<endl;
    
}



Measured memory_bytes: 256
N = int(input())
List = [0]*N
for a in range(1, int(N**.5)+1):
  for b in range(1, int(N**.5)+1):
    M = a+b
    T = a**2+b**2+a*b+M+1
    c = 3
    while T<=N:
      List[T-1] += 1
      T = T+M+c
      c += 2
for l in List:
  print(l)

Measured memory_bytes: 9368
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  cout << setprecision(10) << fixed;

  ll n, m;
  cin >> n >> m;
  vector<vector<ll>> g(n);
  rep(i, m) {
    int s, t;
    cin >> s >> t;
    --s; --t; // 0-indexed
    g[s].push_back(t);
  }

  vector<double> dp(n); // dp[i] .. expected valud from i.
  // dp[n-1] = 0;
  for (int v = n-2; v >= 0; --v) {
    double now = 0;
    for (int u : g[v]) {
      now += dp[u];
    }
    now /= g[v].size();
    now += 1; // one-hop
    dp[v] = now;
  }

  double ans = dp[0];
  for (int nv = 0; nv < n-1; ++nv) {
    if (g[nv].size() == 1) { continue; } // skip 1-degree
    int nu = g[nv][0];
    for (int u : g[nv]) {
      if (dp[u] > dp[nu]) { nu = u; }
    }
    // Here, nu is the maximum dp[nu]

    double nowAns;
    {
      for (int v = n-2; v >= 0; --v) {
        double now = 0;
        for (int u : g[v]) {
          if (v == nv && u == nu) { continue; } // skip removed edge
          now += dp[u];
        }
        int deg = g[v].size();
        if (v == nv) { --deg; }
        now /= deg;
        now += 1; // one-hop
        dp[v] = now;
      }
      nowAns = dp[0];
    }
    ans = min(ans, nowAns);
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>
#define MAXN 20000

// ノードを表す構造体
struct Node {
  int data ;
  int hight;
  struct Node * next ;
} ;

typedef struct Node Node ;

// 新しいノードのメモリを確保する
Node *create_node(int new_data, int new_hight) {
  Node *new_node = (Node *) malloc(sizeof(Node));
  if (!new_node) {
    fprintf(stderr, "could not allocate a node.\n");
    exit(1);
  }
  new_node->data = new_data;
  new_node->hight = new_hight;
  new_node->next = NULL;
  return new_node;
}

// リストのメモリを解放する
void clear_list(Node * head) {
  while (head) {
    Node * target = head ;
    head = head->next ;
    free(target) ;
  }
}

//リストが空か否か判定する
int is_empty(Node *head){
  if(head == NULL){
    return 1;
  }
  return 0;
}


// リストの先頭へ新しいノードを追加する
// リストの先頭のポインタを差し替えるため、リストの先頭へのポインタへのポインタを渡す
void push_front(Node **head, int new_data, int new_hight) {
  Node *new_node = create_node(new_data, new_hight) ;
  new_node->next = *head;
  *head = new_node;
}

//リストの先頭からノードを削除する
int pop_front(Node **head){
  Node *tmp = *head;
  int c = (*head)->data;
  *head = (*head)->next;
  free(tmp);
  return c;
}

// リストの要素を先頭から順に出力する
void print_list(const Node * head) {
  while(head) {
    printf("| %d |-> ", head->data);
    head = head->next;
  }
  printf("NULL\n");
}

int main(void) {

  Node * top = NULL ;
  Node *sq = NULL;
  int data ;

  char s[MAXN];
  fgets(s, MAXN, stdin);
  //printf("%s\n", s);

  int i = 0, res = 0, h = 0,  c;

  while((c = s[i++]) != '\n' && c != '\0'){
    switch(c){
    case '\\':
      push_front(&top, i, 0);
      push_front(&sq, 0, h);
      h--;
      break;
    case '_':
      break;
    case '/':
      h++;
      if(!is_empty(top)){
        int tmp = pop_front(&top);
        res += i - tmp;
        int h2;
        tmp = i - tmp;
        while(!is_empty(sq) && (h2 = sq->hight) < h){
          tmp += pop_front(&sq);
          if(h2 == h){
            break;
          }
        }
        push_front(&sq, tmp, h);
      }
      break;
    default:
      break;
    }
  }

  printf("%d\n", res);
  //print_list(sq);
  int ans[MAXN] = {0}, j = 0;
  while(!is_empty(sq)){
    if(sq->data != 0){
      ans[j++] = sq->data;
    }
     pop_front(&sq);
  }
  printf("%d", j);
  for(i = j-1; i >= 0; --i){
    printf(" %d", ans[i]);
  }
  
  printf("\n");
    
  clear_list(top) ;

  return 0 ;
}



Measured memory_bytes: 3004
N,C = [ int(it) for it in input().split() ]
li = [ [ int(it) for it in input().split() ] for i in range(N) ]

li.sort( key = lambda x:x[0] )

vi_li = [ [-1,-1] for i in range(C) ] # end_time, channel


for s,t,c in li:
  vi_li.sort( key= lambda x:x[0] + (1000000000 if x[0]==-1 else 0) )
  for vi in vi_li:
    if ( vi[1] == c ):
      if (vi[0]<=s):
        vi[0] = t
        vi[1] = c
        break
    else:
      if (vi[0]<s):
        vi[0] = t
        vi[1] = c
        break
        
print ( len( [1 for it in vi_li if it[0]!=-1 ] ) )

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


class Program
{
    static void Main(string[] args)
    {
        string[] NK = Console.ReadLine().Split(' ');
        int N = int.Parse(NK[0]);
        int K = int.Parse(NK[1]);
        string[] p_str = Console.ReadLine().Split(' ');
        int[] p = new int[N];
        for(int i=0; i<N; i++){
            p[i] = int.Parse(p_str[i]);
        }

        int sum = 0;
        int max_sum;

        for(int i=0; i<K; i++){
            sum += p[i];
        }
        max_sum = sum;

        for(int i=0; i<N-K; i++){
            sum = sum - p[i] + p[i+K];
            if(sum>max_sum){
                max_sum = sum;
            }
        }

        Console.WriteLine((max_sum + K) / 2.0f);
    }
}

Measured memory_bytes: 28252
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int K = scan.nextInt();
		scan.close();
		if(K % 2 == 0) {
			int t = K / 2;
			int ans = t * t;
			System.out.println(ans);
		}else {
			int t1 = K / 2;
			int t2 = K / 2 + 1;
			int ans = t1 * t2;
			System.out.println(ans);
		}

	}
}

Measured memory_bytes: 21460
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main()
{
    string a;
    cin>>a;
    if(int(a.find('C'))!=-1&&int(a.rfind('F'))!=-1 and a.find('C')<a.rfind('F'))//个人码风问题，习惯用and而不是&&
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
        return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
                x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def nums(self,x):
        return abs(self.parents[self.find(x)])

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
A = [0]*M
B = [0]*M
for i in range(M):
    A[i],B[i] = map(int, input().split())
ans = 0
for i in range(M):
    uf = UnionFind(N)
    for j in range(M):
        if j!=i:
            uf.union(A[j]-1,B[j]-1)
    if len(uf.roots())>1:
        ans += 1
print(ans)

Measured memory_bytes: 3192
#include<stdio.h>

int main(void){
	
	int i,j,hei[10],tmp;
	for(i=0;i<10;i++){
		scanf("%d",&hei[i]);
		
	}

	for(i=0;i<9;i++){
		for(j=9;j>i;j--){
			if(hei[j]>hei[j-1]){
				tmp=hei[j];
				hei[j]=hei[j-1];
				hei[j-1]=tmp;
			}
		}
	}
	printf("%d\n%d\n%d\n",hei[0],hei[1],hei[2]);
	scanf("%d",&i);
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
using namespace std;

double calc_coefficient(double a,double b,double c) {
  return a*a * (b*b + c*c - a*a);
}
double calc_edge(double x1,double y1,double x2,double y2) {
  return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
double calc_surface(double a,double b,double c) {
  double s = (a + b + c) / 2.0;
  return s * (s-a) * (s-b) * (s-c);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(3);
  cout.setf(ios::fixed);

  int n;
  cin >> n;
  while(n--) {
    double x1,y1,x2,y2,x3,y3;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    double a = calc_edge(x2,y2,x3,y3);
    double b = calc_edge(x3,y3,x1,y1);
    double c = calc_edge(x1,y1,x2,y2);

    double px = calc_coefficient(a,b,c)*x1 + calc_coefficient(b,c,a)*x2 + calc_coefficient(c,a,b)*x3;
    px = px / (16 * calc_surface(a,b,c));
    double py = calc_coefficient(a,b,c)*y1 + calc_coefficient(b,c,a)*y2 + calc_coefficient(c,a,b)*y3;
    py = py / (16 * calc_surface(a,b,c));
    cout << px << " " << py << " " <<  calc_edge(px,py,x1,y1) << endl;
  }


}

Measured memory_bytes: 1296
=begin
－－－－－－－－－－－－－－
  N = 入力値
  cnt = 桁数
  ans = 答え
－－－－－－－－－－－－－－
  digitsメソッドを作成(num)
    1: cnt += 1
    2: num /10
    3. num < 0 になったら cnt を返す
  メソッド－－－－－－－－－－

  1: 1 ~ N まで繰り返す(i)
  2: digits(i) % 2 が 0 以外なら ans += 1
  3: ans を出力
=end

def digits(num)
  cnt = 0;
  while num > 0
    cnt += 1;
    num /= 10;
  end
  return cnt;
end

n = gets.to_i;
ans = 0;

(1..n).each{|i|
  ans += 1 unless digits(i) % 2 == 0
}

puts ans

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

int main() {
  int N, K, d, A = 0;
  int count = 0;
  cin >> N >> K;
  vector<int> sunuke(N);
  for (int i = 0; i < K; i++){
    cin >> d;
    for (int j = 0; j < d; j++){
      cin >> A;
      sunuke.at(A - 1)++;
    }
  }
  for (int i = 0; i < N; i++){
    if (sunuke.at(i) == 0)
      count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)

string op = "+-*";
int a[4];

int calc(int a, char op, int b) {
	if (op == '+') return a + b;
	if (op == '-') return a - b;
	return a * b;
}

void solve() {
	sort(a, a+4);
	string ret = "";
	do {
		rep(i,3) rep(j,3) rep(k,3) {
			if (calc(calc(calc(a[0], op[i], a[1]), op[j], a[2]), op[k], a[3]) == 10) {
				printf("((%d %c %d) %c %d) %c %d\n", a[0], op[i], a[1], op[j], a[2], op[k], a[3]);
				return ;
			}
			if (calc(calc(a[0], op[i], a[1]), op[j], calc(a[2], op[k], a[3])) == 10) {
				printf("(%d %c %d) %c (%d %c %d)\n", a[0], op[i], a[1], op[j], a[2], op[k], a[3]);
				return ;
			}
		}
	} while (next_permutation(a, a+4));
	printf("0\n");
}

int main() {
	while (cin >> a[0] >> a[1] >> a[2] >> a[3], a[0]) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 1224
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		
		List<String> list = new ArrayList<>();
		
		for (int i = 0; i < 5; i++) {
			
			list.add(scanner.next());
		}
		
		scanner.close();
		
		int result = list.indexOf("0");
		
			
		System.out.println(result + 1);
	}

}


Measured memory_bytes: 26832
#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++)
typedef long long ll;

int main() {
   int a[5];
   int k;
   rep(i, 5) {
       cin >> a[i];
   }
   cin >> k;

   for (int i=0; i<4; i++) {
       for (int j=i+1; j<5; j++) {
           if (a[j] - a[i] > k) {
               cout << ":(" << endl;
               return 0;
           }
       }
   }

   cout << "Yay!" << endl;
}

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

int main(){

  int n;
  string s[10000];
  int w[1001][1001];

  while(cin >> n, n){
    memset(w,0,sizeof(0));
    int ans = 0;

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

    for(int i=0;i<n;i++){
      if(s[0][i] == '.') w[0][i] = 1;
      if(s[i][0] == '.') w[i][0] = 1;
    }


    for(int i=1;i<n;i++){
      for(int j=1;j<n;j++){

	if(s[i][j] == '*') w[i][j] = 0;

	else{
	  w[i][j] = min(w[i-1][j-1],min(w[i][j-1],w[i-1][j])) + 1;
	  ans = max(ans,w[i][j]);
	}

      }
    }

    cout << ans << endl;
 
  }
}

Measured memory_bytes: 6240
#include <iostream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    string s,t="CODEFESTIVAL2016";
    cin >> s;
    int ans=0;
    rep(i,(int)s.size()) if (s.at(i) != t.at(i)) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> PP;

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

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll N = s.size();
    ll C[26];
    memset(C, 0, sizeof(C));
    for (int i = 0;i < N;i++) C[s[i] - 'a']++;
    ll all = N * (N - 1) / 2 + 1;
    for (int i = 0;i < 26;i++) all -= C[i] * (C[i] - 1) / 2;
    cout << all << endl;
    return 0;
}

Measured memory_bytes: 720
N,K = map(int,input().split())
A = list(map(int,input().split()))
dic = {}

for a in A:
  if a in dic.keys():
    dic[a] += 1
  else:
    dic[a] = 1
    
dic = sorted(dic.items(), key = lambda x:x[1], reverse=True)

ans = 0
for (i,j) in dic[K:]:
  ans += j
  
print(ans)

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

int c[1000], s[1000], f[1000];
int main() {
	int n; cin >> n;
	for (int i = 0; i < n-1; i ++)
		cin >> c[i] >> s[i] >> f[i];
	for (int i = 0; i < n-1; i ++) {
		int j = i, cur = 0; 
		while (j < n-1) {
			if (cur < s[j]) cur = s[j];
			int tmp = (cur - s[j]) % f[j];
			cur += c[j];
			if (tmp) cur += f[j] - tmp;
			j ++;
		}
		cout << cur << endl;
	}
	cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>

using namespace std;


typedef pair<int, int> P;
bool b[1000][1000] = { false };
int H, W;

/* 範囲内かつ白の場合にTRUE */
bool testPoint(int i, int j)
{
	if ((i < 0) || (H <= i)) return false;
	if ((j < 0) || (W <= j)) return false;
	if (b[i][j]) return false;
	b[i][j] = true;
	return true;
}

int main()
{
	queue<P> que[2];
	string s;

	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> s;
		for (int j = 0; j < W; j++) {
			if ('#' == s[j]) {
				b[i][j] = true;
				que[0].push(P(i, j));
			}
		}
	}
	int idx = 0;
	int nxtidx = 1;
	int cnt = 0;
	while ((0 < que[0].size()) || (0 < que[1].size())) {
		while (0 < que[idx].size()) {
			P p = que[idx].front();
			que[idx].pop();
			if (testPoint(p.first - 1, p.second)) que[nxtidx].push(P(p.first - 1, p.second));
			if (testPoint(p.first + 1, p.second)) que[nxtidx].push(P(p.first + 1, p.second));
			if (testPoint(p.first, p.second - 1)) que[nxtidx].push(P(p.first, p.second - 1));
			if (testPoint(p.first, p.second + 1)) que[nxtidx].push(P(p.first, p.second + 1));
		}
		cnt++;
		idx = nxtidx;
		nxtidx = (0 == idx) ? 1 : 0;
	}
	cnt--;

    cout << cnt;
}


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

int main(){
    constexpr long MOD = 1000000007;
    int N, M;
    cin >> N >> M;
    long d{1}, n{1};
    for(int i = 2, k = 0; i * i <= M; ++i, k = 0){
        while(M % i == 0){
            ++k;
            M /= i;
        }
        for(long j = N; k; ++j, --k){
            (d *= j) %= MOD;
            (n *= k) %= MOD;
        }
    }
    if(M ^ 1)(d *= N) %= MOD;
    long p = MOD - 2;
    while(p){
        if(p & 1)(d *= n) %= MOD;
        (n *= n) %= MOD;
        p >>= 1;
    }
    cout << d << endl;
    return 0;
}

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

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

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

int main() {

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

	int N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	string S;
	cin >> S;



	if (C < D) {

		bool flag = true;
		for (int i = A; i < C - 1; i++) {
			if (S[i] == '#' && S[i + 1] == '#') flag = false;
		}		
		for (int i = B; i < D - 1; i++) {
			if (S[i] == '#' && S[i + 1] == '#') flag = false;
		}

		if (flag) cout << "Yes" << "\n";
		else cout << "No" << "\n";

	}
	else {

		bool flag = false;
		for (int i = B - 2; i < D - 1; i++) {

			if (S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.') flag = true;

		}
		if (flag) cout << "Yes" << "\n";
		else cout << "No" << "\n";

	}

	return 0;
}

Measured memory_bytes: 592
N, M = map(int, input().split())
A = list(map(int, input().split()))

w = (2,5,5,4,5,6,3,7,6)
dp = [-1] * (N+100)
dp[0] = 0
for i in range(N+1):
    if dp[i] < 0: continue
    for a in A:
        dp[i + w[a-1]] = max(dp[i + w[a-1]], dp[i]*10+a)

print(dp[N])


Measured memory_bytes: 50908
//四則演算 #pragma GCC target("avx")
//並列計算 #pragma GCC optimize("O3")
//条件分岐を減らす #pragma GCC optimize("unroll-loops")
//浮動小数点演算 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(i) sort(i.begin(),i.end())
#define rSORT(i) sort(i.rbegin(),i.rend())
#define fSORT(i,a) sort(i.begin(),i.end(),a)
#define all(i) i.begin(),i.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int n; cin >> n;
    ll ans = 1;
    int a = 1, cnt = 0;
    FOR(i, 0, n) {
        ++cnt;
        int x; cin >> x;
        if (x < a) {
            (ans *= cnt) %= mod;
            --cnt;
        }
        else a += 2;
    }
    eFOR(i, 1, cnt)(ans *= i) %= mod;
    print(ans);

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func sort(s string) string {
	var table [256]int
	for _, c := range s {
		table[c]++
	}
	ret := make([]byte, len(s))
	for c, i := 0, 0; c < 256; c++ {
		for j := 0; j < table[c]; j++ {
			ret[i] = byte(c)
			i++
		}
	}
	return string(ret)
}

func reverse(s string) string {
	ret := make([]byte, len(s))
	for i, c := range s {
		ret[len(s)-i-1] = byte(c)
	}
	return string(ret)
}

func main() {
	var s, t string
	fmt.Scanln(&s)
	fmt.Scanln(&t)
	if sort(s) < reverse(sort(t)) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N;
string s;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> s;
  string ans = s;
  int tmp = 0;
  for (int i = 0; i < N; i++) {
    if (s[i] == '(') tmp++;
    else if (tmp != 0) tmp--;
  }  
  ans += string(tmp, ')');
  tmp = 0;
  for (int i = N - 1; i >= 0; i--) {
    if (s[i] == ')') tmp++;
    else if (tmp != 0) tmp--;
  }
  ans = string(tmp, '(') + ans;
  cout << ans << endl;

  return 0;
}

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

int N;
long long A, B;

int main() {
    cin >> N >> A >> B;
    long long ans = 0;
    int tmp, next;
    cin >> tmp;
    for (int i = 1; i < N; i++) {
        cin >> next;
        ans += min(A * (next - tmp), B);
        tmp = next;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val map = LinkedHashMap<String, Long>()
    for (i in 0 until n) {
        val s = readLine()!!.toCharArray().sorted().joinToString("")
        map[s] = (map[s] ?: 0) + 1
    }
    println(map.values.map { it * (it - 1) / 2L }.sum())
}

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

int main(){
    int count=0;
    int N;
    cin>>N;
    vector<int>d(N);
    for(int i=0;i<N;i++){
        cin>>d[i];
    }

    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i!=j){
                if(d[i]==d[j]){
                    d[j]=0;
                }
            }
        }
    }
    for(int i=0;i<N;i++){
        if(d[i]!=0){
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
len_s = len(s)
l = []
for i in range(len_s):
  l.append(s[i])
  l.append('')
del l[-1]
i = 0
ans = 0
while i< 2**(len_s-1):
  for j in range(len_s-1):
    l[2*j+1] = ''  if (i//2**j)%2==0 else '+'
  ans += eval(''.join(l))
  i+=1
print(ans)

Measured memory_bytes: 3064
/******************************************c++
using System; //Console, IComparable
using System.IO; //StreamWrtier
using System.Linq; //Select(), Where(), OrderBy(), Count()
using System.Collections.Generic; //List<T>
using System.Reflection; //PropertyInfo[], GetProperties[]
*********************************************/

namespace TempName{
    using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.Reflection;
    using static System.Console;
    using static IOmacro.CInput;
    
    public class CRun{
        private static class gv{
            public static int N;
            public static int[] A;
            public static int[] H;
        }
    
        public void build() {            
            gv.N = _int;
            gv.A = _inta;
            gv.H = new int[gv.N+2]; Array.Clear(gv.H, 0, gv.H.Length);
            foreach (var x in gv.A) gv.H[x]++;
        }
    
        public void solve() {
            var algo = new libcsharp.Math.combination();
            
            long ans = 0;
            
            foreach (long x in gv.H) {
                ans += (x >= 2 ? x*(x-1)/2 : 0);
            }
            
            foreach (var x in gv.A) {
                long ans_buf = ans;
                int H_now = gv.H[x];
                
                ans_buf -= (H_now >= 2 ? (long)(H_now -1) : 0L);
                Console.WriteLine(ans_buf);
            }

            
        }
    }
    class Program { 
        static void Main() { 
            var run = new CRun();
            run.build();
            run.solve();
        } 
    }
}

namespace IOmacro {
    using System; 
    using System.Linq; 
    using System.IO;
    public static class CInput {
        public static StreamWriter _writer = new StreamWriter(Console.OpenStandardOutput());
        public const char separator = ' ';
        public static string _string{get{return Console.ReadLine();}}
        public static string[] _stringa{get{return (Console.ReadLine().Split(separator));}}
        public static int _int{get{return int.Parse(Console.ReadLine());}}
        public static int[] _inta{get{return Console.ReadLine().Split(separator).Select(int.Parse).ToArray();}}
        public static long _long{get{return long.Parse(Console.ReadLine());}}
        public static long[] _longa{get{return Console.ReadLine().Split(separator).Select(long.Parse).ToArray();}}    
    }
}

namespace libcsharp.Math {
    
    using System;
    public class combination {
        public long combs(int n, int r) {
            if (n < 2) throw new OverflowException("n must be n>=2");
            if (n == r || r == 0) return 1L;
            else return combs(n-1, r-1) + combs(n-1, r);
        }
    }
}

Measured memory_bytes: 33628
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        long[] p = new long[a];
        long[] q = new long[b];
        long[] r = new long[c];
        long[] P = new long[x];
        long[] Q = new long[y];
        for (int i = 0; i < a; i++) {
            p[i] = sc.nextLong();
        }
        for (int i = 0; i < b; i++) {
            q[i] = sc.nextLong();
        }
        for (int i = 0; i < c; i++) {
            r[i] = sc.nextLong();
        }

        Arrays.sort(p);
        Arrays.sort(q);
        Arrays.sort(r);

        long sumP = 0;
        long sumQ = 0;
        int point1 = 0;
        for (int i = a - 1; i >= a - x; i--) {
            sumP += p[i];
            P[point1++] = p[i];
        }
        point1 = 0;
        for (int i = b - 1; i >= b - y; i--) {
            sumQ += q[i];
            Q[point1++] = q[i];
        }

        long res = sumP + sumQ;
        int pointP = x - 1;
        int pointQ = y - 1;
        for (int i = c - 1; i >= 0; i--) {
            long large = r[i];
                //System.out.println(large);
            if (pointP >= 0 && pointQ >=0) {
                long pp = P[pointP];
                long qq = Q[pointQ];
      //System.out.println(pp);
              //System.out.println(qq);

                if (pp > qq) {
                    long diff = large - qq;
                    if (diff > 0) {
                        pointQ--;
                        res += diff;
                    } else {
                        break;
                    }
                } else {
                    long diff = large - pp;
                    if (diff > 0) {
                        pointP--;
                        res += diff;
                    } else {
                        break;
                    }
                }
            } else if (pointP >= 0) {
                long pp = P[pointP];
                long diff = large - pp;
                if (diff > 0) {
                    pointP--;
                    res += diff;
                } else {
                    break;
                }
            } else if (pointQ >= 0) {
                long pp = Q[pointQ];
                long diff = large - pp;
                if (diff > 0) {
                    pointQ--;
                    res += diff;
                } else {
                    break;
                }
            } else {
                break;
            }
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 101704
n = gets ; n = n.to_i
arr = []
ab = []
n.times do
  ab = gets.split(" ").map(&:to_i)
  arr << {ab: (ab[0] + ab[1]), a: ab[0], b: ab[1]}
end
arr = arr.sort {|a,b| a[:ab] <=> b[:ab]}.reverse

result = 0
arr.each.with_index do |hash, index|
  result = result + hash[:a] if index.even?
  result = result - hash[:b] if index.odd?
end

puts result


Measured memory_bytes: 34952
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    tmp = 0
    ans = [0] * n
    f = 1
    for i in a:
        tmp += f * i
        f = f * -1
    ans[0] = tmp
    ans[n - 1] = 2 * a[n - 1] - ans[0]
    for i in range(n - 2, 0, -1):
        ans[i] = 2 * a[i] - ans[i + 1]

    print(" ".join([str(i) for i in ans]))


if __name__ == "__main__":
    main()


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

int main() {
  long long N, A, B, C, D, E, F;
  cin >> N >> A >> B >> C >> D >> E;
  F = min({A, B, C, D, E});
  cout << ((N % F == 0) ? N / F + 4 : N / F + 5) << endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    vector<vector<ll>> c(3,vector<ll>(N+1));
    c[0][0] = 0;
    c[1][0] = 0;
    c[2][0] = 0;
    ll ans = 1;

    rep(i,N){
        int id = -1;
        int count = 0;
        if(c[2][i] == A[i]){
            count++;id=2;
        }
        if(c[1][i] == A[i]){
            count++;id=1;
        }
        if(c[0][i] == A[i]){
            count++;id=0;
        }
        if(id==-1){
            cout << 0 << endl;
            return 0;
        }
        c[2][i+1] = c[2][i];
        c[1][i+1] = c[1][i];
        c[0][i+1] = c[0][i];
        c[id][i+1]=A[i]+1;
        ans = (ans * count) % ((ll)1e9+7);
    }
    cout << ans << endl;
}


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

int main()
{
  int k, a, b;
  cin >> k >> a >> b;
  bool can = false;
  
  for (int i=a; i<=b; i++) {
    if (i%k==0) {
      can = true;
      break;
    }
  }
  if(can) cout << "OK" << endl;
  else cout << "NG" << endl;
}

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

//ライブラリ始まり

//定数
//円周率
const double pi = 3.1415926535897932384;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//データ構造
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す
    return SIZE.at(root(x));
  }
};

//関数 (計算量)
//ctoi (O(1))
int ctoi(char c){
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5; 
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;  
}
//to_char (O(1))
char to_char(int i){
  if (i == 0) return '0';
  if (i == 1) return '1';
  if (i == 2) return '2';
  if (i == 3) return '3';
  if (i == 4) return '4';
  if (i == 5) return '5';
  if (i == 6) return '6';
  if (i == 7) return '7';
  if (i == 8) return '8'; 
  if (i == 9) return '9';
  return ' ';  
}
//素数判定 
//一つ一つの判定ではこっちの方が速い(一つ当たりO(√N))
//一方100までに何個あるかなどはEratosthenesの篩の方が良い（O(NlogN))
bool PN(int x) {
  if (x <= 1) return false; // 1や0,-1は素数ではない
  if (x == 2) return true; // √2 + 1 > 2 なので下でやると 2 ％ 2 = 0 となり判定できない
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) return false; // 割れたら素数じゃない
  }
  return true;
}
// A^N mod M を計算する。modしたくなかったらM = LINFとかにすればよい。(O(√N))
ll modpow(ll A, ll N, ll M) {
  long long ans = 1;
  while (N > 0) {
    if (N & 1) ans = ans * A % M;
      A = A * A % M;
      N >>= 1;
   }
  return ans;
}

//ライブラリ終わり
  
//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  int A, B, K;
  cin >> A >> B >> K;
  for (int i = A; i < min(B + 1, A + K); i++) {
    cout << i << endl;
  }
  for (int i = max(B - K + 1, A + K); i <= B; i++) {
    cout << i << endl;
  }
}

Measured memory_bytes: 3624