akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{
    static long[] last = new long[26];
    static long[] c = new long[26];
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        long[][] s = new long[d+1][26];

        for(int i=0; i<26; i++) {
            c[i] = sc.nextLong();
        }

        for(int i=1; i<=d; i++) {
            for(int j=0; j<26; j++) {
                s[i][j] = sc.nextLong();
            }
        }

        for(int i=1; i<=d; i++) {
            int index = select(s[i], i);
            System.out.print(1);
            System.out.print("\n");
        }
    }

    public static int select(long[] s, int day) {
        long[] score = new long[26];
        int index = 0;
        long max = -1000000000;
        for(int i=0; i<26; i++) {
            score[i] = s[i];
            for(int j=0; j<26; j++) {
                if(i!=j) {
                    score[i] -= c[j]*(day-last[i]);
                }
            }

            if(score[i]>max) {
                index = i;
                max = score[i];
            }
        }
        return index+1;
    }
}

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

#define For(i, j, k) for (int i = j; i <= k; i++)
#define Forr(i, j, k) for (int i = j; i >= k; i--)

using namespace std;

const int N = 3.6e5 + 10;
const int dx[4] = {1, 1, -1, -1}, dy[4] = {-1, 1, -1, 1};

int col[N];
int n;
vector<int> G[N];

int id(int x, int y) {
	return x * n + y + 1;
}

int sqr[N];
bool vis[N];

void DFS(int o, int s, int w) {
	vis[o] = true;
	col[o] |= s * w;
	for (int x : G[o]) if (!vis[x]) DFS(x, s ^ 1, w);
}

void getcol(int d, int w) {
	For(i, 1, n * n) G[i].clear(), vis[i] = false;
	For(i, 0, n - 1) For(j, 0, n - 1)
		for (int k = 0; k * k <= d; ++k) if (k * k == d || sqr[d - k * k]) {
			int s = sqr[d - k * k];
			For(u, 0, 3) {
				int x = i + dx[u] * k, y = j + dy[u] * s;
				if (x >= n || y >= n || x < 0 || y < 0) continue;
				G[id(i, j)].push_back(id(x, y));
			}
		}
	For(i, 1, n * n) if (!vis[i]) DFS(i, 0, w);
}

int p, q;
vector<int> ans[4];

int main() {

	For(i, 1, 600) sqr[i * i] = i;
	scanf("%d%d%d", &n, &p, &q);

	n *= 2;
	getcol(p, 1);
	getcol(q, 2);
	For(i, 1, n * n) ans[col[i]].push_back(i);
	For(i, 0, 3) if (int(ans[i].size()) >= (n / 2) * (n / 2)) {
		For(j, 0, (n / 2) * (n / 2) - 1) printf("%d %d\n", (ans[i][j] - 1) / n, (ans[i][j] - 1) % n);
		return 0;
	}

	return 0;
}

Measured memory_bytes: 78644
def solve():
    n = int(input())
    res = 0
    for i in range(n - 1):
        u, v = map(int, input().split())
        if u > v:
            u, v = v, u
        res += u * (n-v+1)

    return n * (n+1) * (n+2) // 6 - res


print(solve())


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

bool pd(char A) {
    if(A=='A' || A=='T' || A=='C' || A=='G') return true;
    return false;
}
int p[15];
int main() {
    string s;
    memset(p,0,sizeof(p));
    cin>>s;
    int ans=0,in=0;
    if(pd(s[0])) p[0]=1;
    if(p[0] > ans) ans=p[0];
    for(int i=1;i<s.size();i++) {
        if(pd(s[i])) {
            p[i]=p[i-1]+1;
            if(p[i] > ans) ans = p[i];
        }
    }
    cout<<ans<<endl;
}


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

int main() {
	string s1,s2,s3;
    cin >> s1 >> s2 >> s3;
    char a = s1.at(0) - 0x20;
    char b = s2.at(0) - 0x20;
    char c = s3.at(0) - 0x20;
    cout << a << b << c << endl;
}


Measured memory_bytes: 256
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<map>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const int mod=1000000007;
const llint big=1e18+10;
const long double pai=3.141592653589793238462643383279;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}//a>b
int main(void){
	int n,i;cin>>n;
	vector<int>a(n);
	for(i=0;i<n;i++){cin>>a[i];}
	sort(a.begin(),a.end());
	llint ans=1;
	if(n%2==0){
		for(i=0;i<n;i++){
			if(a[i]!=(i/2)*2+1){ans=0;}
		}
	}else{
		for(i=0;i<n;i++){
			if(a[i]!=((i+1)/2)*2){ans=0;}
		}
	}
	for(i=0;i<n/2;i++){
		ans*=2;
		ans%=mod;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 640
/*
ID: rchalam1
LANG: C++14
TASK:
*/
// For train.usaco.org, fill the template above.

// Competitive Coding Template

// GCC OPTIMIAZTION FLAGS
#ifdef ONLINE_JUDGE
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#endif

#include <bits/stdc++.h>

/*
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
*/
// All Includes for Competitive Coding Template

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

using vi = std::vector<int>;
using vll = std::vector<long long>;
using vull = std::vector<unsigned long long>;

#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (auto i = (a); i >= (b); --i)
#define R0F(i, a) ROF(i, a, 0)
#define ITR(a, x) for (auto& a: x)

#define FSRT(set) sort((set).begin(),(set).end())
#define RSRT(set) sort((set).rbegin(),(set).rend())
#define CSRT(set, function) sort((set).begin(),(set).end(), (function))
#define TRS(set) sort((set).begin(),(set).end(), greater<>())
#define REV(set) reverse((set).begin(),(set).end());

#define ALL(set) (set).begin(), (set).end()

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// For stdio, call setIO() or setIO("").
void setIO(std::ifstream &readFile, std::ofstream &writeFile, const std::string &name = "", bool stdIO = false)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	if(!name.empty() && !stdIO)
	{
		readFile.open(name + ".in");
		if(readFile.fail()) return;
		writeFile.open(name + ".out");
		std::cin.rdbuf(readFile.rdbuf());
		std::cout.rdbuf(writeFile.rdbuf());
	}
}

// To time program, create object Timer  to start timing, and call Timer.elapsed().
#include <chrono>

class Timer
{
	std::chrono::time_point<std::chrono::high_resolution_clock> m_beg;
public:
	Timer() : m_beg(std::chrono::high_resolution_clock::now())
	{}

	void reset()
	{ m_beg = std::chrono::high_resolution_clock::now(); }

	[[nodiscard]] long double elapsed() const
	{
		return std::chrono::duration_cast<std::chrono::duration<long double, std::ratio<1> >>(
				std::chrono::high_resolution_clock::now() - m_beg).count();
	}
};

// Defines datatype
using dt = int;
// Defines MAXN value
constexpr dt MAXN = 1e5 + 1;
// Defines Modulus
constexpr dt MOD = 1e9 + 7;
// Defines Floating Point Correction
constexpr long double EPS = 1e-9;

//*****
//START CODE BELOW
//*****

int main(int argc, char *argv[])
{
	static std::ifstream readFile;
	static std::ofstream writeFile;
	setIO(readFile, writeFile);
	string a, b;
	cin >> a >> b;
	if(a.size() > b.size()) cout << "GREATER\n";
	else if(a.size() < b.size()) cout << "LESS\n";
	else if(a == b) cout << "EQUAL\n";
	else cout << (a > b ? "GREATER\n" : "LESS\n");
}

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

int main() {
  string A;
  cin >> A;
  if(A[0]!=A[1] && A[0]!=A[2] && A[1]!=A[2]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }    
}


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

const int MOD = 998244353, N = 102000;

int n, a[N];

int main(void) {
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a, a + n);
  long long ans = 1;
  for(int i = 0, x; i < n; i++) {
    x = a[i];
    ans = ans * __gcd(x, i) % MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>

using namespace std;

#define rep1(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, n, m) for (long long i = (long long)(n); i <= (long long)(m); i++)
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
const long long mod = 1e9 + 7;

int main() {
    string s;
    cin >> s;
    string out = (s.at(0) == s.at(1) && s.at(1) == s.at(2)) ? "No" : "Yes";
    cout << out << endl;
}


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

std::string solve(int n, const std::vector<std::pair<int, int>>& pairs)
{
  int count = 0;
  for (const auto& p : pairs) {
    if (p.first == p.second) {
      ++count;
      if (count >= 3) return "Yes";
    } else {
      count = 0;
    }
  }
  return "No";
}

int main()
{
  int n;
  std::cin >> n;
  std::vector<std::pair<int, int>> pairs(n);
  for (auto& p : pairs) {
    std::cin >> p.first >> p.second;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, pairs) << std::endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
//#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const ll INF = 1e16;
const int MOD = 1000000007;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////
///////////////////////___modpow___////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}


////////////////////////////////////////////////////////////////////

int h,w;bool t[25][25];
int ans = 0;
int dist[500][500];
void bfs(int sx, int sy){
  queue<P> que;que.push(P(sx,sy));
  dist[sx][sy] = 0;
  while(!que.empty()){
    P p = que.front();que.pop();
    int x = p.first , y = p.second;
    rep(i,4){
      int nx = x+fd[i].first, ny = y+fd[i].second;
      if(nx < 0 || ny < 0 || nx >= h || ny >= w || dist[nx][ny] >= 0 || !t[nx][ny])continue;
      dist[nx][ny] = dist[x][y] + 1;
      que.push(P(nx, ny));
    }
  }

}

signed main(){
  cin>>h>>w;
  rep(i,h){
    string s;cin>>s;
    rep(j,w){
      t[i][j] = (s[j] == '.');
    }
  }
  rep(i,h)rep(j,w){
    if(!t[i][j])continue;
    rep(k,h)rep(l,w)dist[k][l] = -1;
    bfs(i, j);
    rep(k,h)rep(l,w){
      chmax(ans, dist[k][l]);
    }
  }
  cout << ans << endl;
}




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

int n,k;
long long s,s1,m=1e9+7,b[100001];

int xar(int n, int p){
    long long s;
    if ( p==1 )
        return n;

    long long l=xar(n, p/2);

    if (p%2==1)
      s=(((l*l)%m)*n)%m;
    else
      s=(l*l)%m;

    return s%m;
}

main()
{
	ios::sync_with_stdio(0);
	
	cin >> n >> k;
	
	for (int i=k; i>=1; i--){
		int j=i+i;
		
		while(j<=k){
			s+=b[j];
			s%=m;
			j+=i;
		}
		
		b[i]=((xar(k/i, n) % m)-s)%m;
		b[i]=(b[i]+m)%m;
		s=0;
		s1=0;
	}
	
	for (int i=1; i<=k; i++){
		s+=(b[i]*i)%m;
		//cout << b[i] << " ";
		s%=m;
		s=(s+m)%m;
	}
	cout << s << endl;
}


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    int x;
    cin>>x;
    if(x>=30)
       cout<<"Yes";
       
    else
      cout<<"No";
    

    return 0;
}

Measured memory_bytes: 3620
n=int(input())
a=list(map(int,input().split()))
keta=[0]*61
for i in range(n):
  for j in range(61):
    if (a[i]>>j)&1==1:
      keta[j]+=1
ans=0
for i in range(61):
  ans+=((2**i)*(n-keta[i])*keta[i])%(10**9+7)
print(ans%(10**9+7))  


Measured memory_bytes: 124440
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using ll = unsigned long long;
using namespace std;

int main(void) {
    string s;
    cin >> s;

    int ans = 0;
    for (size_t i = 0; i < s.size(); ++i) {
        if (s[i] == '+') {
            ans++;
        } else {
            ans--;
        }
    }

    cout << ans << endl;

    return 0;
}

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

#define rep(ver,n) rep2(ver,0,n)
#define rep2(ver,m,n) for(int ver=m;ver<(n);ver++)
#define dup(x,y) (((x)+(y)-1)/(y))
#define vecadd emplace_back

typedef long long ll;

int main(){
  int n,k,q;
  cin>>n>>k>>q;
  int p[100010]={};
  rep(i,q){
    int a;
    cin>>a;
    p[a-1]++;
  }
  
  rep(i,n){
    p[i]+=k;
    p[i]-=q;
    if(p[i]>0){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
    
  }
  
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll n;
    cin >> n;
    map<ll, ll> mp;
    ll sum = 0;
    ll res = 0;
    mp[0] = 1;
    rep(i, n){
        ll a;
        cin >> a;
        sum += a;
        if(mp[sum] == 0)mp[sum] = 1;
        else res += mp[sum], mp[sum] += 1;
    }
    // all_map(itr, mp)cout << itr->second << endl;
    cout << res << endl;
}

Measured memory_bytes: 12800
n=int(input())
red=[list(map(int, input().split())) for _ in range(n)]
blue=[list(map(int, input().split())) for _ in range(n)]
blue=sorted(blue, key=lambda x:x[0])
ans=0 
for b in blue:
    for r in sorted([r_ for r_ in red if r_[0]<b[0]], key=lambda x:x[1], reverse = True):
        if r[1]<b[1]:
            ans+=1
            red.pop(red.index(r))
            break
print(ans)

Measured memory_bytes: 3064
n=int(input())
w=[input() for i in range(n)]
count=0
if len(w)==len(set(w)):
    for i in range(n-1):
        if w[i][-1]==w[i+1][0]:
            count+=1
        else:
            count=count*0
            break
else:
    count=count*0
    
print('Yes' if count>0 else 'No')

Measured memory_bytes: 3060
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){
   
    int n;
	string s;
	cin >> n >> s;

	set<int> s1,s2,s3;
	s1.insert(s[0]-'0');
	for(int i = 1;i < n;i++){
		int x = s[i]-'0';
		for(auto a : s2){
			s3.insert(a+100*x);
		}
		for(auto a : s1){
			s2.insert(a+10*x);
		}
		s1.insert(x);
	} 

	cout << s3.size() << endl;



	
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2020-qual.contest.atcoder.jp/tasks/ddcc2020_qual_b
// rm -r -f test;oj dl https://sumitrust2019.contest.atcoder.jp/tasks/sumitb2019_b

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>

using namespace std;
typedef long long ll;

struct node
{
    ll a, b;
}node1[100000+100];

bool cmp( node x, node y)
{
    return x.a < y.a;
}
int main()
{
    ll n, k;
    ll sum = 0;
    ll ans;

    cin >> n >> k;
    for( ll i = 0; i < n; i++)
        scanf("%lld%lld", &node1[i].a, &node1[i].b);
    sort( node1, node1+n, cmp);
    for( ll i = 0; i < n; i++)
    {
        sum += node1[i].b;
        if(sum >= k)
        {
            ans = node1[i].a;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

const int DIM = 1e5 + 7;

bool viz[DIM];

int wa[DIM];

string s;

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

    int n, m;

    cin >> n >> m;

    long long rez1 = 0;
    long long rez2 = 0;
    for(int i = 1; i <= m; i++)
    {
        int x;
        cin >> x;
        cin >> s;

        if(s == "AC")
            {
             if(viz[x] == false)
             {
                viz[x] = true;
                rez1++;
                }
            }
        else
        if(s == "WA")
        if(viz[x] == false)
        wa[x]++;
    }

    cout << rez1 <<" ";

    for(int i = 1; i <= n; i++)
        if(viz[i] == true)
        rez2+= wa[i];

    cout << rez2;
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#define N 1001
using namespace std;
int main(){
  int n,m,c,d,l,r,flag,sum;
  int V[N]={0};
  cin >> n >> m;
  for(int i=0;i<m;i++){
    cin >> c >> d;
    V[c]=max(V[c],d);
  }
  l=r=0;
  flag=sum=0;
  for(int i=0;i<=n;i++){
    if(flag&&V[i]!=0) r=max(r,V[i]);
    else if(flag&&r==i) sum+=3*(r-l),flag=0;
    else if(V[i]!=0&&!flag) l=i,r=V[i],flag=1,sum++;
    else if(!flag) sum++;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1164
<?php
fscanf(STDIN, "%s", $number);

$diff = '';
$is_ok = true;
foreach (str_split((string) $number) as $char) {
    if ($diff == $char) {
        $is_ok = false;
        break;
    }
    $diff = $char;
}

if ($is_ok) {
    echo "Good\n";
} else {
    echo "Bad\n";
}

Measured memory_bytes: 4604
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <iostream>
#include <fstream>

using namespace std;

const int DIV = 1000000007;

int main(int argc, char *argv[]) {
#ifdef VLAD_LOCAL
    ifstream in("in.txt");
#else
    istream &in = cin;
#endif
    int64_t a, b;
    double bb;
    in >> a >> bb;
    b = bb * 100 + 0.5;
    int64_t res = a * b / 100;
    printf("%lld", res);
	return 0;
}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int h, w;
    cin >> h >> w;
    vector<string> ss;
    rep (h) {
        string s;
        cin >> s;
        string blank_row(w, '.');
        if (s == blank_row) {
            continue;
        }
        ss.push_back(s);
    }
    
    h = ss.size();
    vector<bool> v(w, true);
    repeat (i, w) {
        repeat (j, h) {
            if (ss[j][i] != '.') {
                v[i] = false;
                break;
            }
        }
    }
    
    repeat (j, h) {
        repeat (i, w) {
            if (v[i]) continue;
            cout << ss[j][i];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
X, K, D = [int(x) for x in input().split(" ")]

result = 0
if abs(X) > K * D:
    result = abs(X) - K * D
else:
    y = int(round(abs(X) / D))
    resX = abs(abs(X) - D * y)
    resK = K - y
    if resK % 2 == 1:
        result = abs(resX - D)
    else:
        result = resX
print(result)


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

using namespace std;

const int maxl = 3010;

int dp[maxl][maxl];
pair<int , int> parent[maxl][maxl];
string s, t;

int main(){
	cin >> s >> t;
	for (int i = 1; i <= s.length(); i++){
		for (int j = 1; j <= t.length(); j++){
			if (s[i-1] == t[j-1]){
				dp[i][j] = dp[i-1][j-1] + 1;
				parent[i][j] = make_pair(i-1, j-1);
			}
			else {
				if (dp[i-1][j] > dp[i][j-1]){
					dp[i][j] = dp[i-1][j];
					parent[i][j] = make_pair(i-1, j);
				}
				else {
					dp[i][j] = dp[i][j-1];
					parent[i][j] = make_pair(i, j-1);
				}
			}
		}
	}
	string ans = "";

	int i = s.length();
	int j = t.length();

	while (i > 0 && j > 0){
		pair<int , int> par = parent[i][j];
		if (i - par.first == 1 && j - par.second == 1){
			ans += s[i-1];
		}
		i = par.first;
		j = par.second;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	return 0;
}


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

int main() {
  int num[3], i, j, damy;

  cin >> num[0] >> num[1] >> num[2];
  for(i = 0; i < 3; i++) {
    for(j = 2; j > i; j--) {
      if(num[j-1] > num[j]) {
        damy = num[j];
        num[j] = num[j-1];
        num[j-1] = damy;
      }
    }
  }
  cout << num[0] << " " << num[1] << " " << num[2] << endl;

  return 0;
}

Measured memory_bytes: 1164
import java.util.*;
  public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int l[]=new int[n];
    int r[]=new int[n];
    int sheets=0;
    for(int i=0;i<n;i++){
      l[i]=sc.nextInt();
      r[i]=sc.nextInt();
      sheets+=r[i]-l[i]+1;
    }
    sc.close();
    System.out.println(sheets);
  }
}

Measured memory_bytes: 24788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false); 
    ll n;
    cin >> n;
    int f=1;
    REP(i,n){
        ll x;
        cin >> x;
        if(x%2==0){
            if(x%3==0||x%5==0){
                
            }else{
                f=0;
            }
        }
    }
        if(f){
            cout << "APPROVED" << endl;
        }else{
            cout <<"DENIED" << endl;
        }
}


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





int gcd(int a, int b){
  int smaller=min(a,b);
  int bigger=max(a,b);
  
  if (bigger%smaller==0){
    return smaller;
  }
  else {
    return gcd(bigger%smaller,smaller);
  }
}

vector<int> divider(int n){
  int rootn=0;
  
  vector<int> tmp;

  while ((rootn+1)*(rootn+1)<=n){
    rootn++;
  }
  
  for (int i=1;i<=rootn;i++){
    if (n%i==0){
      tmp.push_back(i);
      tmp.push_back(n/i);
    }
  }
  
  return tmp;
}

  
  


int main(){
  
  int n;
  cin>>n;
  
  vector<int> data(n);
  for (int i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    data.at(i)=tmp;
  }
  
  int answer;
  
  if (n==2){
    answer=max(data.at(0),data.at(1));
  }
  else if (n==3){
    int tmp1,tmp2,tmp3;
    tmp1=gcd(data.at(0),data.at(1));
    tmp2=gcd(data.at(1),data.at(2));
    tmp3=gcd(data.at(2),data.at(0));
    
    answer=max(tmp1,max(tmp2,tmp3));
  }
  
  else {
    vector<int> vec1=divider(gcd(data.at(0),data.at(1)));
    vector<int> vec2=divider(gcd(data.at(2),data.at(3)));
    
    vec1.insert(vec1.end(),vec2.begin(),vec2.end());
    
    sort(vec1.begin(),vec1.end());
    reverse(vec1.begin(),vec1.end());
    
    
    for (int i=0;i<int(vec1.size());i++){
      
      int count=0;
      
      for (int j=0;j<n;j++){
        if (data.at(j)%vec1.at(i)==0){
          count++;
        }
      }
      
      if (count>=n-1){
        answer=vec1.at(i);
        break;
      }
    }
  }
  
    
    cout<<answer<<endl;

                             
    
    
  
  
  
  
  
  

        
}

Measured memory_bytes: 640
#include <iostream>
#include<vector>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> vec(n - 1);
	for (int i = 0; i < n - 1; i++) {
		cin >> vec.at(i);
	}
	vector<int> ans(n, 0);
	for (int i = 0; i < n - 1; i++) {
		ans.at(vec.at(i) - 1)++;
	}
	cout << ans.at(0);
	for (int i = 1; i < n; i++) {
		cout << endl << ans.at(i);
	}
}

Measured memory_bytes: 4816
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;++i)

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

vector<set<int>> node;
vector<int> searched;

void solve(int index){
    searched[index]=index;
    queue<int> que; que.push(index);
    while(!que.empty()){
        int order = que.front(); que.pop();
        for(auto itr=node[order].begin();itr!=node[order].end();++itr){
          if(-999==searched[*itr])que.push(*itr);
            searched[*itr]=index;
        }
    }
}

int main(){
   int n,m;cin>>n>>m;
   node.resize(n);
   searched.resize(n,-999); 
   REP(i,m){
    int x,y;cin>>x>>y;
    node[x].insert(y);
    node[y].insert(x);
   }
   REP(i,n)
    if(-999==searched[i])
      solve(i);
   int hm;cin>>hm;
    REP(i,hm){
      int x,y;
      cin>>x>>y;
      if(searched[x]==searched[y]&&searched[y]!=-999&&searched[x]!=-999)
        cout << "yes" << endl;
      else 
        cout << "no" << endl;
    }
}


Measured memory_bytes: 17260
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define rg register
#define usn unsigned
#define llint long long
using namespace std;
const int N=1008611;

struct ios{
	template <typename _tp>
	inline ios operator >> (_tp &x){
		x = 0;int f = 1;char c = getchar();
		for(;c<'0'||c>'9';c=getchar()) if(c=='-') f = -1;
		for(;c<='9'&&c>='0';c=getchar()) x = (x<<1)+(x<<3)+(c^48);
		x *= f;
		return *this;
	}
	template <typename _tp>
	inline ios operator << (_tp x){
		char s[66];int dgt = 0;
		if(x==0) putchar('0');
		if(x<0) putchar('-'),x = -x;
		while(x) ++dgt,s[dgt] = x%10+'0',x/=10;
		while(dgt) putchar(s[dgt]),--dgt;
		return *this;
	}
	inline ios operator << (char x){
		putchar(x);
		return *this;
	}
}io;

llint a,b; 

int main()
{
	io >> a >> b;
	if((a+b)%2==1) puts("IMPOSSIBLE");
	else printf("%lld\n",(a+b)>>1);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
K = str(input())

r = K.count("R")
g = K.count("G")
b = K.count("B")
total = r*g*b
n_remove = 0
for space in range(0, N//2 +1):
    for i in range(N- 2*(space+1)):
        try:
            pattern_remove = [K[i], K[i+space+1], K[i+(space*2)+ 2]]
            if set(pattern_remove) == set(["R", "B", "G"]):
                #print(set(pattern_remove))
                n_remove += 1
        except:
            continue
                
print(total - n_remove)
        

Measured memory_bytes: 68092
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <cstdlib>
using namespace std;
 
int main () {
	int n,i;
	double sum1=0,sum2=0,sum3=0,sum=0;
	cin >> n;
	double x[n],y[n],z[n];
	for(i=0;i<n;i++){
		cin >> x[i];
	}
	for(i=0;i<n;i++){
		cin >> y[i];
	}
	for(i=0;i<n;i++){
		z[i]=abs(x[i]-y[i]);
	}
	for(i=0;i<n;i++){
		sum1+=z[i];
	}
	for(i=0;i<n;i++){
		sum2+=z[i]*z[i];
	}
	sum2=sqrt(sum2);
	for(i=0;i<n;i++){
		sum3+=z[i]*z[i]*z[i];
	}
	sum3=pow(sum3,1/3.0);
	for(i=0;i<n;i++){
		if(z[i]>sum) sum=z[i];
	}
	cout << setprecision(20)<< sum1 << endl << sum2 << endl << sum3 << endl << sum << endl;
	return 0;
}
	

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

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

  int ans = INT_MAX;
  int r = sum;
  int l = 0;
  for (int i = 0; i < N - 1; i++) {
    r -= w[i];
    l += w[i];
    ans = min(ans, abs(r - l));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3564
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int n,q;(n=s.nextInt())+(q=s.nextInt())>0;){C[]d=new C[n];for(;n-->0;)d[n]=new C(s.next(),s.nextInt(),s.nextInt());Arrays.sort(d,new Comparator<C>(){public int compare(C a,C b){return a.a-b.a;}});for(;q-->0;){n=s.nextInt();String r="Unknown";for(C c:d)if(c.a<n&&n<=c.b)r=c.s+" "+(n-c.a);System.out.println(r);}}}static class C{String s;int a,b;C(String t,int n,int y){s=t;a=(b=y)-n;}}}

Measured memory_bytes: 14000
import java.util.*;

class Main{
	public static int n, l;
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	n = sc.nextInt();
      	l = sc.nextInt();
      	
      	if(l > 0) {
      		System.out.println(sum(1));
      	}else if((l + n-1) < 0) {
      		System.out.println(sum(n));
      	}else {
      		System.out.println(sum(1-l));
      	}
    }
	
	public static int sum(int m) {
		int sum = 0;
		for(int i = 1; i <= n; i++) {
			if(i == m) continue;
			//System.out.print(l+i-1);
			//System.out.println();
			sum += (l + i-1);
		}
		return sum;
	}
}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define LB lower_bound
#define UB upper_bound

using namespace std;

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

string ans[5000*6];

int main(){

	ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);

	int k , n , pt(0);
	string s;
	cin >> s >> k;

	n = s.size();

	for(int i = 0 ; i < n ; i++)
	   for(int j = 0 ; j < k ; j++){
		  if(i+j < n)
			 ans[pt++] = s.substr(i , j+1);
			
	   }
	

	sort(ans , ans+pt);
	unique(ans , ans+pt);
	cout << ans[k-1] << endl;

	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

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

  if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
const int INF = 1 << 30;
int main(){
  int N, P[301][301] = {{}};
  cin >> N;
  for(int i = 1; i <= N; i++){
    for(int j = 1; j <= N; j++){
      cin >> P[i][j];
      P[i][j] += P[i - 1][j] + P[i][j - 1] - P[i - 1][j - 1];
    }
  }
#define Sum( y1, x1, y2, x2) (P[y2][x2] - P[y2][x1 - 1] - P[y1 - 1][x2] + P[y1 - 1][x1 - 1])
  int ret = -INF;
  for(int i = 1; i <= N; i++){
    for(int j = i; j <= N; j++){
      int better = 0;
      for(int k = 1; k <= N; k++){
        int st = Sum( i, k, j, k);
        ret = max( ret, st + better);
        better = max( st, better + Sum( i, k, i, k) + (i != j ? Sum( j, k, j, k) : 0));
      }
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 1524
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
string S,T;

int main() {
  INCANT;
  cin >> S >> T;
  bool flag = true;
  rep(i, S.size()) {
    if (S[i]!=T[i]) flag = false; 
  }
  string ans = flag?"Yes":"No";
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3656
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        n: i32, m: i32,
        a: [i32; m]
    }

    let days_to_do_homework: i32 = a.iter().sum();
    let days_to_play: i32 = n - days_to_do_homework;

    if days_to_play < 0 {
        println!("-1");
    }else{
        println!("{}", days_to_play);
    }
}


Measured memory_bytes: 2276
# problem C
A,B = map(int,input().split())
ans = []

for i in range(1,1001):
    x = int(i * 0.08)
    y = int(i * 0.10)
    if x == A and y == B:
        ans.append(i)
    else:
        pass
if len(ans) == 0:
    print(-1)
else:
    print(ans[0])

Measured memory_bytes: 3060
#include<stdio.h>
int main(){
  int d[110]={0},r,i;
  char s[110];
  while(fgets(s,105,stdin),s[0]-'.'){
    for(i=r=0;s[i];i++){
      if(s[i]=='(')d[++r]=1;
      if(s[i]=='[')d[++r]=2;
      if(s[i]==')'){
	if(d[r--]-1)break;
      }
      if(s[i]==']'){
	if(d[r--]-2)break;
      }
    }
    if(s[i]||r)printf("no\n");
    else         printf("yes\n");
  }
  return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e3+9;
ll x,y,a,b,c;
int main()
{
    FASTINOUT;
    cin>>x>>y>>a>>b>>c;
    priority_queue<ll>red,green,no;
    ll op;
    for (int i=0; i<a; i++)
    {
        cin>>op;
        red.push(op);
    }
    for (int i=0; i<b; i++)
    {
        cin>>op;
        green.push(op);
    }
    for (int i=0; i<c; i++)
    {
        cin>>op;
        no.push(op);
    }
    ll ans=0;
    for (int i=0;i<x;i++){
        no.push(red.top());
        red.pop();
    }
    for (int i=0;i<y;i++){
        no.push(green.top());
        green.pop();
    }
    for (int i=0;i<x+y;i++){
        ans+=no.top();
        no.pop();
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 7920
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include <iomanip> 
#include<sstream>
#include <map>
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n,k,*p,i;
    while (cin >> n>>k)
    {
        p = new int[n];
        for (i = 0; i < n; i++)
            cin >> p[i];
        sort(p, p + n);
        long long ans = 0;
        for (i = 0; i < n - k; i++)
            ans = ans + p[i];
        cout << ans << '\n';
    }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  cin >> a[0];
  int l=1,c=0;
  for(int i=1;i<n;i++){
    cin >> a[i];
    if(a[i]==a[i-1]){
      l++;
    }
    else{
      c+=l/2;
      l=1;
    }
  }
  c+=l/2;
  cout << c;
}

Measured memory_bytes: 256
K = int(input())
l = [i for i in range(1,10)]

def func(x):
    y = x%10
    if y == 0:
        return [x*10,x*10+1]
    elif y == 9:
        return [x*10+8,x*10+9]
    else:
        return [x*10+y-1,x*10+y,x*10+y+1]

li1 = l[:]
li2 = []
if K < 10:
    print(K)
else:
    while True:
        for i in li1:
            a = func(i)
            li2.extend(a)
        l.extend(li2)
        if len(l) >=K:
            break
        else:
            li1 = li2[:]
            li2 = []
    print(l[K-1])


Measured memory_bytes: 13684
n,a,b,c = map(int,input().split())
L = []
for i in range(n):
    L.append(int(input()))
import itertools
ans = 10**9
tmp = 0
for use in itertools.product([0,1,2,-1] ,repeat=n):
    tmp = 0
    ls = [0,0,0]
    for idx,u in enumerate(use):
        if u>-1:
            if ls[u] >0:
                tmp+=10
            ls[u]+=L[idx]

    if ls[0] ==0 or ls[1] ==0 or ls[2] ==0:continue
    tmp = tmp + abs(ls[0] -a) +abs(ls[1] -b)+abs(ls[2] -c)
    ans = min(tmp,ans)
print(ans)


Measured memory_bytes: 3064
#include <utility> // pair make_pair
using std::swap; // c++11
using std::pair;
using std::make_pair;
#include <tuple> // tuple(c++11) make_tuple(c++11)
using std::tuple; // get<address>(variable)
using std::make_tuple;
#include <string> // string stoi(c++11) stoll(c++11) to_string(c++11)
using std::string;
using std::stoi;
using std::stoll;
using std::to_string;
#include <queue> // queue priority_queue
using std::queue;
using std::priority_queue;
#include <stack> // stack
using std::stack;
#include <vector> // vector
using std::vector;
#include <map> // map
using std::map;
#include <set> // set
using std::set; // insert erase find count
#include <algorithm> // min max
using std::sort;
using std::lower_bound; // iterator,  >=
using std::upper_bound; // iterator,  >
using std::min;
using std::max;
using std::min_element; // iterator
using std::max_element; // iterator
#include <complex> // complex
using std::complex; // real imag
#include <iostream> // cin cout
using std::cin;
using std::cout;
using std::endl;
#include <iomanip> // setprecision fixed(manipulator)
using std::setprecision;
using std::fixed;
#include <cmath>
#include <cstdio>

#define lli long long int
#define INF (int)1e09
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define EFOR(i, m, n) for (int i = m; i <= n; i++)
#define RFOR(i, m, n) for (int i = m; i > n; i--)
#define REFOR(i, m, n) for (int i = m; i >= n; i--)
#define VSORT(v) sort((v).begin(), (v).end()) // sort vector
typedef pair<int, int> PI;
typedef tuple<int, int, int> TI;
template <typename T> using Vec = vector<T>; // c++11


int main(void) {
    int n;
    cin >> n;
    Vec<int> t(n);
    Vec<int> v(n);
    int time = 0;
    FOR (loop, 0, n) {
        cin >> t[loop];
        time += t[loop];
    }
    FOR (loop, 0, n) {
        cin >> v[loop];
    }

    Vec<int> sped(10 * time + 1, 0);
    Vec<int> max_s(10 * time + 1);
    int rui = 0; // ruiseki_time
    max_s[0] = 0;
    FOR (i, 0, n) {
        FOR (j, 10 * rui, 10 * (rui + t[i])) {
            max_s[j] = v[i] * 10;
        }
        if (i != 0) {
            max_s[10 * rui] = min(v[i], v[i - 1]) * 10;
        }
        rui += t[i];
    }

    while (1) {
        bool change = false;
        // operation
        FOR (i, 1, 10 * time) {
            sped[i] += 1;
            if (abs(sped[i - 1] - sped[i]) > 1 || abs(sped[i + 1] - sped[i]) > 1 || sped[i] > max_s[i]) {
                sped[i] -= 1;
            } else {
                change = true;
            }
        }
        if (change == false) {
            break;
        }
    }
    /*
    FOR (i, 0, 10 * time) {
        cout << (double)(i) / 10 << " " << (double)(sped[i]) / 10 << " " << (double)(max_s[i]) / 10 << endl;
    }
     */

    double total = 0;
    FOR (i, 0, 10 * time) {
        int status = sped[i + 1] - sped[i];
        if (status == 1) {
            total += sped[i + 1] * 2 - 1;
        } else if (status == 0) {
            total += sped[i] * 2;
        } else {
            total += sped[i] * 2 - 1;
        }
    }
    total /= 200;
    cout << std::fixed << setprecision(4) << total << endl;

    return 0;
}



Measured memory_bytes: 1792
N, M = map(int, input().split())
adj_matrix = [[0]* N for _ in range(N)]

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

def dfs(v, used):
    if not False in used:       # chek complete or not
        return 1

    ans = 0
    for i in range(N):           # check all edge
        if not adj_matrix[v][i]: # edge check
            continue
        if used[i]:              # used check
            continue

        used[i] = True           #　使用済みを示す
        ans += dfs(i, used)
        used[i] = False          # ほかのエッジのためにFalseにする

    return ans

used = [False] * N
used[0] = True

print(dfs(0, used))


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

int main() {
  int n;
  int A[300000],B[300000];
  cin>>n;
  for(int i=0;i<n-1;i++){
    cin>>A[i];
    B[i]=0;
  }
  
  for(int i=0;i<n-1;i++){
    B[A[i]-1]++;
  }
  
  for(int i=0;i<n;i++){
  cout<<B[i]<<endl;
  }
}


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

long long c;

void merge(int left, int mid, int right, vector<int>& A) {
	vector<int> L, R;
	int n1=mid-left;
	int n2=right-mid;
	int i,j,k;

	L.resize(n1+1);
	R.resize(n2+1);

	for(i=0; i<n1; ++i) {
		L[i]=A[left+i];
	}
	for(i=0; i<n2; ++i) {
		R[i]=A[mid+i];
	}
	i=j=0;
	L[n1]=1000000001;
	R[n2]=1000000001;
	for(k=left; k<right; ++k) {
		if(L[i]>R[j]) {
			c+=(long long)n1-(long long)i;
			A[k]=R[j];
			++j;
		} else {
			A[k]=L[i];
			++i;
		}
	}
	return;
}

void mergeSort(int left, int right, vector<int>& A) {
	if(left+1<right) {
		int mid=left+(right-left)/2;
		mergeSort(left,mid,A);
		mergeSort(mid,right,A);
		merge(left,mid,right,A);
	}
	return;
}

int main() {
	int n;
	vector<int> A;
	scanf("%d",&n);
	c=0;
	A.resize(n);
	for(int i=0; i<n; ++i) {
		scanf("%d",&A[i]);
	}
	mergeSort(0,n,A);
	printf("%lld\n",c);
	return 0;
}

Measured memory_bytes: 3872
#include <bits/stdc++.h>
#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
  
signed main() {
    fast;
    int n,m;
    cin>>n>>m;
    int sum=0;
    if (n>=2)
    {
        sum+=n*(n-1)/2;
    }
    if (m>=2)
    {
        sum+=m*(m-1)/2;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int A, B;

int check(int val)
{
    int a = val * 8 / 100;
    int b = val * 10 / 100;
    //printf("%d: %d %d\n", val, a, b);
    if (a == A && b == B) return 0;
    else if (a <= A && b <= B) return -1;
    else if (a >= A && b >= B) return 1;
    else return 2;
}

int main()
{
    scanf("%d%d", &A, &B);
    int lo = 0, mid, hi = 2000, ans = -1;
    while (lo <= hi)
    {
        mid = (lo + hi) / 2;
        if (check(mid) == 1)
        {
            hi = mid - 1;
        }
        else if (check(mid) == -1)
        {
            lo = mid + 1;
        }
        else if (check(mid) == 0)
        {
            hi = mid - 1;
            ans = mid;
        }
        else
        {
            break;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
 #include<stdio.h>
 #include<cstdlib>
 #include<cstdio>
 #include<string>
 #include<math.h>
 #include<time.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<fstream> 
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 #include<list>
 #include<memory>
 
 using namespace std;

 int main()
 { 
   int n;
   long long int y;
   while(cin>>n>>y) 
   {
     long long int min,max;
     if(y%10000==0) min=y/10000;
     else min=int(y/10000)+1;
     max=y/1000;
     if(n<min||n>max) cout<<"-1 -1 -1"<<endl;
     else
     {
       bool flag=0;
       for(int i=0;i<=(int)(y/10000);i++)
       {
         if(i>n) break;
         for(int j=0;j<=(int)((y-i*10000)/1000);j++)
         {
           if((i+j)>n) break;
           long long int kkk=(n-i-j);
           long long int yy=y-i*10000-j*1000;
           if(yy>=0&&(yy%5000==0)&&(kkk>=0)&&(kkk==(yy/5000)))
           {
             cout<<i<<" "<<kkk<<" "<<j<<endl;
             flag=1;         
           }        
           else continue;
           if(flag) break;
         }        
         if(flag) break;
       }    
       if(!flag) cout<<"-1 -1 -1"<<endl;
     }
   }
   return 0;
 }
 

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

int main(){
    ll d; cin >> d;
    vector<ll> c(26); rep(i,26) cin >> c[i];
    vector<vector<ll>> g(365, vector<ll> (26));

    rep(i,365){
        rep(j,26){
            cin >> g[i][j];
        }
    }

    rep(i,365){
        ll jud = rand() % 26;
        cout << jud + 1 << endl;
    }
}

Measured memory_bytes: 3748
import heapq
N = int(input())
A = [int(i) for i in input().split()]

sumLeft = [0] * (N+1) #A[:N+i]中のN要素の和の最大値のリスト
sumLeft[0] = sum(A[:N])
Aleft = A[:N]
heapq.heapify(Aleft)

sumRight = [0] * (N+1) #A[N+i:]中のN要素の和の最小値のリスト
sumRight[-1] = sum(A[2*N:]) 
Aright = [-1*i for i in A[2*N:]] #最大値をpopするために要素を-1倍しておく
heapq.heapify(Aright)

for i in range(1, N+1):
    a = A[N+i-1]
    b = -1 * A[2*N-i]
    sumLeft[i] = sumLeft[i-1] + a - heapq.heappushpop(Aleft, a)
    sumRight[-1-i] = sumRight[-i] + heapq.heappushpop(Aright, b) - b

score = sumLeft[0] - sumRight[0]
for i in range(1, N+1):
    score = max(score, sumLeft[i] - sumRight[i])
print(score)

Measured memory_bytes: 40340
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

int main(void) {

	int n[4];

	for (int k = 0; k < 4; k++) cin >> n[k];

	sort(n, n + 4);

	swap(n[1], n[3]);

	if (n[0] == 1 && n[1] == 9 && n[2] == 7 && n[3] == 4)cout << "YES\n";
	else cout << "NO\n";
	

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static void solve() {
		int n = in.nextInt();
		int m = in.nextInt();
		int t = in.nextInt();
		int[] a = new int[n];
		for (int i=0; i<n; i++) {
			a[i] = in.nextInt();
		}
		boolean[] f = new boolean[t*2];
		for (int i=0; i<n; i++) {
			for (int j=a[i]-m; j<a[i]+m; j++) {
				f[j] = true;
			}
		}
		int ans = 0;
		for (int i=0; i<t; i++) {
			if (!f[i]) ans++;
		}
		dump(f);
		out.println(ans);
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 26644
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()

    idx_a = s.index("A")
    idx_z = -1

    for i, char in enumerate(s):
        if char == "Z":
            idx_z = i

    print(idx_z - idx_a + 1)


if __name__ == '__main__':
    main()


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

int main(int argc, const char * argv[]) {
    // insert code here...
    string a, b, c, A, B, C;
    cin >> a >> b >> c;
    
    A = a, B = b, C = c;
    
    cout << A.at(0) << B.at(1) << C.at(2) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
????????????????????????????????? ??§?????§  
??????????????? ??§?????§ ???????´<_??? ?????? Welcome to My Coding Space!
???????????? ??? ?´_???`??????/??? ???i     
?????????????????????????????? ???  |???|     
????????? /?????? /??£??£??£??£/??????|  
??? ???_(__??????/???    ???/ .| .|????????????  
??? ????????????/????????????/??????u??????  
---------------------------------------------------------------------------------------------------*/


#define INF 10101010
int N, E, T, W[303], G[1010];
vector<int> S[1010];
int ans[303];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> E >> T; T--;
    rep(i, 0, N) cin >> W[i];
    rep(i, 0, E) {
        int C; cin  >> G[i] >> C; G[i]--;
        rep(j, 0, C) {
            int s; cin >> s; s--;
            S[i].push_back(s);
        }
    }

    rep(i, 0, N) {
        if(W[i] == 1) ans[i] = 1;
        else ans[i] = INF;
    }

    rep(a, 0, N * 2) rep(b, 0, E){
        vector<int> v;
        for (int i : S[b]) v.push_back(ans[i]);
        sort(v.begin(), v.end(), greater<int>());

        int a = 0;
        rep(i, 0, v.size()) a = max(a, i + v[i]);

        ans[G[b]] = min(ans[G[b]], a);
    }

    if (ans[T] == INF) ans[T] = -1;
    printf("%d\n", ans[T]);
}

Measured memory_bytes: 3292