akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.util.Scanner;

public class Main {

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

		String s = sc.next();

		if (Character.isUpperCase(s.charAt(0))) {
			System.out.println("A");
		} else {
			System.out.println("a");

		}
	}
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int x;
  cin >> x;

  int t = 0;
  while ((t * (t + 1)) / 2 < x) {
    t++;
  }

  cout << t << endl;
  return 0;
}


Measured memory_bytes: 256
def cal(lst,op):
	if op == '+':
		return sum(lst)
	else:
		ret = 1
		for num in lst:
			ret *= num
		return ret


def rec ():
	global n,S,idx
	op = S[idx][-1]
	nst = len(S[idx])
	idx += 1
	lst = []
	while idx < n:
		if len(S[idx]) <= nst:
			break
		if not S[idx][-1].isdigit():
			lst.append(rec())
		else:
			lst.append(int(S[idx][-1]))
			idx += 1
	return cal(lst,op)

while True:
	n = int(input())
	if n == 0:
		break
	if n == 1:
		print(input())
		continue
	S = []
	idx = 0
	for i in range(n):
		S.append(input())
	print(rec())



Measured memory_bytes: 5604
#include <iostream>
#include <algorithm>
#include <numeric>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl


int main() {
    ll n,m;
    cin >> n >> m;
    float a[n];
    float cnt = 0;
    bool flg = true;
    for(ll i=0;i < n;i++){
        cin >> a[i];
        cnt += a[i];
    }
    sort(a, a+n, greater<int>());

    for(ll i=0;i < m;i++){
        if(!(cnt <= 4 * m * a[i])){
            flg = false;
        }
    }
    Yes(flg);


    return 0;
}

Measured memory_bytes: 256
X,Y,A,B,C=map(int,input().split())
# 超単純な貪欲法？？
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
R=list(map(int,input().split()))
# DPなんじゃない？
# DP[i,j]:=i,jまでの中からりんごを選んだときに
# DPにしては，なんかおかしい気がする

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

p_top = P[0:X]
q_top = Q[0:Y]
pq_top = p_top+q_top


pqr_top=pq_top+R
pqr_top.sort(reverse=True)

print(sum(pqr_top[0:X+Y]))




Measured memory_bytes: 23412
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define add(x) accumulate(x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end() 
#define rep(i, a, b) for (int i=a; i<(b); i++)
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
                void solve(){
                        ll n;
                        cin>>n;
                        ll ans=0;
                        vll vec(n,0);
                        for(int i = 0; i<=n; i++){
                                if(i%3==0)
                                        vec[i]++;
                                if(i%5==0)
                                        vec[i]++;
                                if(vec[i]==0)
                                        ans+=i;
                        }
                        cout<<ans;

                }
                int main(){ 
                        hs;
                        ll t;
                        t=1;
                        // cin>>t;
                        for (int i=1; i<=t; i++){
                                //cout<<"Case #"<<i<<": ";
                                solve();
                         }
        return 0; 
}         
 

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

#define INF 2000000000
#define MAX 100000

struct Card{
    char suit;
    int value;
};

//MergeSortの実装
Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(Card A[], int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    //L[n1],R[n2]を生成
    for(int i = 0; i < n1; i++){
        L[i] = A[left + i];
    }
    for(int i = 0; i < n2; i++){
        R[i] = A[mid + i];
    }
    L[n1].value = INF;
    R[n2].value = INF;

    int i = 0;
    int j = 0;
    for(int k = left; k < right; k++){
        if(L[i].value <= R[j].value){
            A[k] = L[i];
            i++;
        }else{
            A[k] = R[j];
            j++;
        }
    }
}

void mergeSort(Card A[], int left, int right){
    if(left + 1 < right){
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}


//QuickSortの実装
int pertition(Card A[], int p, int r){
    Card x = A[r];
    int i = p - 1;
    for(int j = p; j < r; j++){
        if(A[j].value <= x.value){
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i+1], A[r]);

    return i + 1;
}

void quickSort(Card A[], int p, int r){
    if(p < r){
        int q = pertition(A, p, r);
        quickSort(A, p, q - 1);
        quickSort(A, q + 1, r);
    }
}


int main(){
    int n, v;
    Card A[MAX], B[MAX];
    char S[10];

    scanf("%d", &n);

    rep(i,n){
        scanf("%s %d", S, &v);
        A[i].suit = S[0];
        A[i].value = v;
        B[i].suit = S[0];
        B[i].value = v;
    }

    quickSort(A, 0, n-1);
    mergeSort(B, 0, n);

    bool isStable = true;
    rep(i,n){
        if(A[i].suit != B[i].suit){
            isStable = false;
            break;
        }
    }

    if(isStable) printf("Stable\n");
    else printf("Not stable\n");

    rep(i,n){
        printf("%c %d\n", A[i].suit, A[i].value);
    }

    return 0;

}


Measured memory_bytes: 5572
#include<iostream>
#define MAX_NODE 10000

using namespace std;

typedef struct{
	int parent,rank;
} Node;

Node node[MAX_NODE];

void init(int n){
	for(int i=0;i<n;i++){
		node[i].parent=i;
		node[i].rank=0;
	}
}

int find(int n){
	return node[n].parent==n?n:node[n].parent=find(node[n].parent);
}

void unite(int x,int y){
	int xr=find(x);
	int yr=find(y);
	if(node[xr].rank>node[yr].rank){
		node[yr].parent=node[xr].parent;
	}else if(xr!=yr){
		node[xr].parent=node[yr].parent;
		if(node[xr].rank==node[yr].rank){
			node[yr].rank++;
		}
	}
}

void same(int x,int y){
	cout<<(find(x)==find(y)?1:0)<<endl;
}	

int main(){
	int n,q,com,x,y;
	cin>>n>>q;
	init(n);
	for(int i=0;i<q;i++){
		cin>>com>>x>>y;
		if(com==0){
			unite(x,y);
		}else{
			same(x,y);
		}
	}
	return 0;
}

Measured memory_bytes: 1240
#include <iostream>

using namespace std;

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

    int n; cin >> n;
    int A[n]; for(auto &i : A) cin >> i;
    int k = 1;
    for(int i = 0; i < n; ++i)
        if(A[i] == k) ++k;
    if(k == 1) cout << -1;
    else cout << n - k + 1;
}


Measured memory_bytes: 1024
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(string, s);
    REP(i, s.size())
    {
        REP(j, s.size())
        {
            if (s[i] == 'C' and s[j] == 'F' and i < j)
            {
                OUT("Yes");
                return 0;
            }
        }
    }
    OUT("No");
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define forinc(i,a,b) for(int i=a;i<=b;++i)
using namespace std;

const int maxn=5e5+10;
int q,n;
string s;
set<int> st[30];

main()
{
    ios_base::sync_with_stdio(false);
    cin>>n>>s;
    s=' '+s;
    forinc(i,1,n) st[s[i]-'a'].insert(i);
    cin>>q;
    while(q--)
    {
        int ty;cin>>ty;
        if(ty==1)
        {
            int pos;char z;
            cin>>pos>>z;
            st[s[pos]-'a'].erase(pos);
            st[z-'a'].insert(pos);
            s[pos]=z;
        }
        else{
            int L,R;
            cin>>L>>R;
            int kq=0;
            forinc(i,0,25){
                    auto it=st[i].lower_bound(L);
                    if(it==st[i].end()) continue;
                    int z=*it;
                    if(z<=R) kq++;
            }
            cout<<kq<<"\n";
        }
    }
}


Measured memory_bytes: 26288
import std.algorithm;
import std.array;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int [] solve (int n, int [] a)
{
	int [] res;
main_loop:
	while (a.length > 0)
	{
		foreach_reverse (i, c; a)
		{
			if (c == i + 1)
			{
				res ~= c;
				a = a[0..i] ~ a[i + 1..$];
				continue main_loop;
			}
		}
		return [-1];
	}
	reverse (res);
	return res;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		writefln ("%(%s\n%)", solve (n, a));
	}
}


Measured memory_bytes: 256
N, M = [int(x) for x in input().split()]
A = sorted([int(x) for x in input().split()])

data = []
for i in range(M):
    B, C = [int(x) for x in input().split()]
    data.append([C, B])
data = sorted(data, reverse=True)

D = []
i, tot = 0, 0
while tot < N and i < M:
    C, B = data[i][0], data[i][1]
    for _ in range(B):
        D.append(C)
        tot += 1
        if tot >= N:
            break
    i += 1

i = 0
while i < min(N, len(D)) and A[i] < D[i]:
    i += 1

ans = sum(D[:i] + A[i:])
print(ans)

Measured memory_bytes: 104396
#include <stdio.h>


int main(void)
{
	int n;
	int sum = 0;

	scanf("%d", &n);

	for(int i = 0; i < n; i++)
	{
		int l, r;

		scanf("%d %d", &l, &r);
		sum += (r - l) + 1;
	}
	printf("%d\n", sum);
	return 0;
}


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

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

    vector<int> A(200010, 0);
    int a;
    for (int i = 0; i < N-1; ++i) {
        cin >> a;
        A[a]++;
    }

    for (int i = 1; i <= N; ++i) {
        cout << A[i] << endl;
    }


    return 0;
}


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

typedef complex<double> P; //Point
typedef pair<P,P> L; //Line, Segment

const double EPS = 1e-9;

double dot(P a, P b){ return a.real() * b.real() + a.imag() * b.imag(); }
double cross(P a, P b){ return   a.real() * b.imag() - a.imag() * b.real(); }

int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1; //???????¨???????
  if(cross(b,c) < -EPS) return -1; // ????¨???????
  if(dot(b,c) < -EPS) return 2; // c -- a -- b ????????´???
  if(norm(b) < norm(c)) return -2; // a -- b -- c ????????´???
  return 0; // a -- c -- b ????????´????
}

P crossPoint(L l, L m){
  double A = cross(l.second - l.first, m.second - m.first);
  double B = cross(l.second - l.first, l.second - m.first);
  if(fabs(A) < EPS && fabs(B) < EPS) return m.first;
  else if(fabs(A) >= EPS) return m.first + B / A * (m.second - m.first);
}

void view(vector<P> G){
  cout << "view : ";
  for(int i=0;i<(int)G.size();i++) cout << G[i] << " ";
  cout << endl;
}

vector<P> convex_cut(vector<P> G, L l){
  vector<P> ans;
  for(int i=0;i<G.size();i++){
    P A = G[i];
    P B = G[(i+1)%G.size()];
    if(ccw(l.first, l.second, A) != -1) ans.push_back(A);
    if(ccw(l.first, l.second, A) * ccw(l.first, l.second, B) < 0)
      ans.push_back(crossPoint(L(A,B), l));
  }
  //view(ans);
  return ans;
}

double area(vector<P> v){
  double sum = 0.0;
  int n = v.size();
  for(int i=0;i<n;i++) sum += (real(v[i]) - real(v[(i+1)%n])) * (imag(v[i]) + imag(v[(i+1)%n]));
  return fabs(sum) / 2;
};

int N,D,V;
double dV;
L p_move( L s, double h ){
  P v = s.second - s.first;
  v = P( -v.imag(), v.real() );
  v /= abs(v);
  s.first += v*h;
  s.second += v*h;
  return s;
}

double solve( vector<P> v, L s ){
  double st = 0.0, ed = 100000.0;
  double A=area(v);
  for(int l=0;l<50;l++){
    double h = (st+ed)/2.0;
    L ns = p_move( s, h );
    double a = A-area(convex_cut( v, ns ));
    if( a < dV )
      st = h;
    else
      ed = h;
  }
  return ed;
}

int main(){
  while( ~scanf("%d%d%d",&N,&D,&V) && (N|D|V) ){
    dV = (double)V/(double)D;
    vector<P> v;
    for(int i=0;i<N;i++){
      int x,y; cin >> x >> y;
      v.push_back( P( x, y ) );
    }
    double res = 0.0;
    for(int i=0;i<N;i++){
      int nd = (i+1)%N;
      L sp = L( v[i], v[nd] );
      res = max( res, solve( v, sp ) );
    }
    printf("%.9lf\n",res);
  }
}

Measured memory_bytes: 1280
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
  int k;
  string s;
  cin>>k>>s;
  int sSize=s.size();
  if (k>=sSize) cout<<s<<endl;
  else {
    cout<<s.substr(0,k)<<"..."<<endl;
  }
  return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<math.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < n; i++)


signed main() {
	int n;

	cin >> n;

	vector<int>a(n);

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

	ll min = -1;

	ll sum = 0;


	for (int i = -100; i <= 100; i++) {
		rep(j, n) {
			sum += (a[j] - i) * (a[j] - i);
		}
		
		if (min == -1) {
			min = sum;
		}
		else if (sum <= min) {
			min = sum;
		}
		sum = 0;
	}
	cout << min << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define NIL -1
using namespace std;

void DFS(int id, const vector<vector<int> >& a,
          vector<int>& find, vector<int>& finish){
    static int t = 1;
    if (find[id] != NIL) return;
    find[id] = t++;
    for (int i = 0; i < a[id].size(); i++) {
        DFS(a[id][i], a, find, finish);
    }
    finish[id] = t++;
}

int main(){
    int n;
    cin >> n;
    vector<vector<int> > a(n + 1);
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            a[u].push_back(v);
        }
    }
    vector<int> find(n + 1, NIL);
    vector<int> finish(n + 1, NIL);
    for (int i = 1; i <= n; i++) {
        DFS(i, a, find, finish);
    }
    for (int i = 1; i <= n; i++) {
        cout << i << " " << find[i] << " " << finish[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main(void){
    long long h,count=0,num=1,ans=1;
    cin >> h;
    while(h>1){
        h /= 2;
        count++;
    }
    rep(i,count){
        num *= 2;
        ans += num;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

public class Main {
	
	public static void main(String[] args) {
		Task task = new Task();
		task.solve();
	}

	public static class Task {
		static final long MOD = (long) 1e9 + 7;

		public void solve() {
			Scan sc = new Scan();
			int n = (int) sc.scanLong();
			int[] arr1 = new int[n];
			int[] arr2 = new int[n];
			for(int i = 0; i < n; ++i){
				arr1[i] = (int) sc.scanLong();
			}
			for(int i = 0; i < n; ++i){
				arr2[i] = (int) sc.scanLong();
			}
			long a_b_count = 0;
			long b_a_count = 0;
			for(int i = 0; i < n; ++i){
				int diff = arr2[i] - arr1[i];
				if(diff >= 0){
					b_a_count += (diff/2);
				}
				else
					a_b_count -= diff;
			}
			if(b_a_count >= a_b_count){
				System.out.println("Yes");
			}
			else
				System.out.println("No");
		}
	}

	public static class Scan {
		private byte[] buf = new byte[1024];
		private int index;
		private InputStream in;
		private int total;

		public Scan() {
			in = System.in;
		}

		public int scan() {
			if (total < 0)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				try {
					total = in.read(buf);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public long scanLong() {
			long integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scanDouble() throws IOException {
			double doub = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doub *= 10;
					doub += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doub += (n - '0') * temp;
						n = scan();
					} else
						throw new InputMismatchException();
				}
			}
			return doub * neg;
		}

		public String scanString() {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n)) {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		public char scanChar() {
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			return (char) n;
		}

		private boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}
	}
}


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

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}




int main()
{
    ll N,K;

    cin >> N >> K ;

    ll h[N],dp[N];

    rep(i,N) cin >> h[i];

    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);

    if(N==2){
        cout << dp[1] << endl;
        return 0;
    }

    for(int i=2;i<N;i++){
        dp[i] =10000000000;
        for(int j=1;j<=K;j++){
            if(i-j>=0){
            dp[i]=min(dp[i-j]+abs(h[i-j]-h[i]),dp[i]);
            }
        }
        
    }

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



 
    return 0;

}

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

int main()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int max;
    max=a>b?a:b;
    max=max>c?max:c;
    int temp=a+b+c-max;
    for(int i=0;i<k;i++){
        max*=2;
    }
    temp+=max;
    printf("%d",temp);

}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void){
    int n, d;
    int i,j,k;
    int p[10][10];
    int c = 0;
    
    scanf("%d %d\n", &n, &d);
    for (i=0; i<n; i++) {
        for (j=0; j<d; j++) {
            if (j!=d-1) scanf("%d ", p[i]+j);
            else scanf("%d\n", p[i]+j);
        }
    }
    
    for (i=0; i<n; i++) {
        int sum = 0;
        double result;
        for (j=i+1; j<n; j++) {
            for (k=0; k<d; k++) {
                // printf("i:%d j;%d ", p[i][k], p[j][k]);
                sum += pow(abs(p[i][k] - p[j][k]), 2);
            }
            result = sqrt(sum);
            // printf("%d %d, ", i, j);
            // printf("sum %d\n", sum);
            // printf("result %lf\n", result);
            if (result - floor(result) <= 0) c++;
            sum = 0;
        }
        
    }
    
    printf("%d", c);
    /*
    printf("%d %d\n", n, d);
    for (i=0; i<n; i++) {
        for (j=0; j<d; j++) {
            printf("%d ", p[i][j]);
        }
        printf("\n");
    }
    */
    
    
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int a[11][11];
	int n, i, j;

	scanf("%d", &n);
	while (n != 0)
	{
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				scanf("%d", &a[i][j]);

		a[n][n] = 0;
		for (i = 0; i < n; i++)
		{
			a[i][n] = 0;
			for (j = 0; j < n; j++)
				a[i][n] += a[i][j];
			a[n][n] += a[i][n];
		}

		for (j = 0; j < n; j++)
		{
			a[n][j] = 0;
			for (i = 0; i < n; i++)
				a[n][j] += a[i][j];
		}

		for (i = 0; i <= n; i++)
		{
			for (j = 0; j <= n; j++)
				printf("%5d", a[i][j]);
			printf("\n");
		}
		
		scanf("%d", &n);
	}

	return 0;
}

Measured memory_bytes: 1044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(void)
{
    int n;
    cin >> n;
    vector<int> p(n);
    REP(i, n)
    {
        cin >> p[i];
    }

    int min = p[0];
    int cnt = 0;
    REP(i, n)
    {
        if(p[i] <= min){
            min = p[i];
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

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

const char nl = '\n';

void solve()
{
    char c; cin >> c;
    cout << (c < 97 ? 'A' : 'a');
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll A, B ;
    cin >> A >> B ;
    cout << A-B+1 << endl;
    
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll N;
ll A[100000], B[100000];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    rep(i,0,N){
        cin>>A[i]>>B[i];
    }
    ll ans=0;
    ll res=0;
    rer(i,N,0){
        if(A[i]>0){
            ans+=((A[i]-1)/B[i]+1)*B[i]-A[i];
            res+=((A[i]-1)/B[i]+1)*B[i]-A[i];
        }
        if(i>0) A[i-1]+=res;
    }
    cout <<ans<<"\n";
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define per(i,n) for(int i=n-1;i>=0;++i)
#define rep1(i,n) for(int i=1; i<=n; ++i)
#define per1(i,n) for(int i=n; i>=1; ++i)
#define debug cout << "line : " << __LINE__ << " debug" << endl
#define Dcout(N) cout << setprecision(20) << N << endl
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF 1e8
#define MOD 1000000007
typedef long long ll;

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

      ll n,m; cin >> n >> m;
      vector<ll> a(m);
      ll sum = 0;
      rep(i,m){
          cin >> a[i];
          sum+=a[i];
      }
      sort(rall(a));
      if(sum>n){
          cout << -1 << endl;
      }else{
          cout << n-sum << endl;

      }
      return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define long long long
#define ull unsigned long long
#define up(i,a,b) for (int i=a; i<=b; i++)
#define down(i,a,b) for (int i=a; i>=b; i--)
#define endl '\n'
#define pb push_back
#define X first
#define Y second
#define II pair<int, int>
#define III pair<int, pair<int, int> >
#define V vector
#define debug(X) cerr<< #X << " = " <<X << endl
#define debug2(X,Y) cerr<< #X << " = " <<X << ","<<#Y<<" = "<<Y<<endl
#define show(X,a,b) {cerr << #X << " = "; up(__,a,b) cerr << X[__] << ' '; cerr << endl;}
#define gc getchar
#define pc putchar

using namespace std;

inline void read(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}
inline void writeln(int x){

         char buffor[21];
         register int i=0;
         int neg=0; if (x<0) {neg=1; x= -x;}
         do{
               buffor[i++]=(x%10)+'0';
               x/=10;
            } while(x);
           i--;
           if (neg) pc('-');
           while(i>=0) pc(buffor[i--]);
           pc('\n');
       }

void input()
{
    int a,b,c;
    cin>>a>>b>>c;
    if (a==b and b==c)
	{
		if (a%2==1) cout<<0; else cout<<-1;
		 return;
	}
	int res=0;
    while (1)
	{
		if (a%2==1 or b%2==1 or c%2==1)
		{
			cout<<res; return;
		}
		int aa,bb,cc;
		res++;
		aa= b/2+c/2; bb= a/2+ c/2; cc= a/2+ b/2;

		a= aa; b= bb; c= cc;
	}
}

void solve()
{

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);// don't use when interactive
    #define TASK "tmp"
 //   freopen(TASK".inp","r",stdin);
  //  freopen(TASK".out","w",stdout);

    input();
    solve();

    return 0;
}


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

#define fi first
#define se second

#define INF (1LL << 31)

typedef pair<long long, long long> pll;

int main() {
	int n;
	vector<pll> in;
	cin >> n;
	for(int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		in.push_back(pll(a,b));
	}

	long long dptab[128][128];
	for(int i = 0; i < 128; i++) for(int j = 0; j < 128; j++) dptab[i][j] = INF;

	for(int i = 0; i < n; i++) {
		dptab[0][i] = dptab[1][i] = 0;
		dptab[2][i] = in[i].fi * in[i].se * in[i + 1].fi * in[i + 1].se;
	}
	for(int width = 0; width <= n; width++) {
		for(int start = 0; start < n; start++) {
			for(int div = 1; div < width; div++) {
				dptab[width][start] = min(dptab[width][start],
						dptab[div][start] + dptab[width - div][start + div] + in[start].fi * in[start + div - 1].se * in[start + div].fi * in[start + width - 1].se);
			}
		}
	}

	cout << dptab[n][0] << endl;

	return 0;
}

Measured memory_bytes: 1324
#b

N,T = map(int,input().split())
CT=[None]*N
for i in range(N):
    CT[i] = list( map(int,input().split()) )

intime = [ct[0] for ct in CT if ct[1]<=T]
if len(intime)==0:
    print("TLE")
else:
    print(min(intime))

Measured memory_bytes: 62460
import sys

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    X = list(map(int, input().split()))

    X.sort()
    Y = [0] * (M - 1)
    for i in range(M - 1):
        Y[i] = X[i + 1] - X[i]
    Y.sort(reverse=True)

    ans = sum(Y[N - 1:])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 13316
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin>>s;
  int start,end;
  for(int i=0;i<s.size();i++){if(s.at(i)=='A'){start=i;break;}}
  for(int i=s.size()-1;i>=0;i--){if(s.at(i)=='Z'){end=i;break;}}
  cout<<s.substr(start, end-start+1).size()<<endl;
}

Measured memory_bytes: 772
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
#define INF 1 << 28
typedef pair<int,int> Pi;
#define F first
#define S second
#define pb push_back

inline void chmax(int &a, int b) { a = max(a,b); }
inline void chmin(int &a, int b) { a = min(a,b); }

int main()
{
  int H, W, N;
  char c;
  int sum[1005][1005][3];
  fill(sum[0][0],sum[1004][1005],0);
  cin >> H >> W >> N;
  for(int i = 1; i <= H; i++) {
    for(int j = 1; j <= W; j++) {
      cin >> c;
      if(c == 'J') sum[i][j][0]++;
      else if(c == 'O') sum[i][j][1]++;
      else sum[i][j][2]++;
      Rep(k,3) {
	sum[i][j][k] += sum[i - 1][j][k] + sum[i][j - 1][k] - sum[i - 1][j - 1][k];
      }
    }
  }

  int A, B, C, D;
  while(N--) {
    cin >> A >> B >> C >> D;
    Rep(i,3) {
      cout << sum[C][D][i] - sum[A - 1][D][i] - sum[C][B - 1][i] + sum[A - 1][B - 1][i];
      if(i == 2)cout << endl;
      else cout << " ";
    }
  }
  return 0;
}

Measured memory_bytes: 14904
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  }
}

struct Scanner<R: BufRead> {
  reader: R,
  iter: std::vec::IntoIter<String>
}

#[allow(dead_code)]
impl<R: BufRead> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader: reader, iter: vec![String::new()].into_iter() }
  }
  fn new_line(&mut self) {
    let mut line = String::new();
    self.reader.read_line(&mut line).ok();
    self.iter = line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>().into_iter();
  }
  fn get<T: FromStr>(&mut self) -> T {
    self.iter.next().unwrap().parse().ok().unwrap()
  }
  fn get_as_vec<T: FromStr>(&mut self) -> Vec<T> {
    self.iter.clone().map(|v| v.parse().ok().unwrap()).collect()
  }
  fn get_line(&mut self) -> String {
    let mut line = String::new();
    self.reader.read_line(&mut line).ok();
    line.trim().to_string()
  }
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut sc = Scanner::new(cin);
  sc.new_line();
  let a = scan!(sc; i32);
  for _ in 0..3 {
    sc.new_line();
  }
  sc.new_line();
  let e = scan!(sc; i32);
  sc.new_line();
  let k = scan!(sc; i32);
  println!("{}", if e - a > k { ":(" } else { "Yay!" });
}


Measured memory_bytes: 4352
import           Control.Monad
import           Control.Monad.ST
import           Data.Array.Unboxed
import           Data.Array.ST
import qualified Data.ByteString.Char8 as B
import           Data.Char
import           Data.List

readInts :: IO [Int]
readInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine

main :: IO ()
main = do
  [n, m, k] <- readInts
  lrs <- replicateM m readInts
  pqs <- replicateM k readInts
  let ary = runSTUArray $ mkArray n lrs

  forM_ pqs $ \[p, q] ->
    print $ ary!(q, q) - ary!(p-1, q) - ary!(q, p-1) + ary!(p-1, p-1)


mkArray :: Int -> [[Int]] -> ST s (STUArray s (Int, Int) Int)
mkArray n lrs = do
  a_ary <- newArray ((0, 0), (n, n)) 0 :: ST s (STUArray s (Int, Int) Int)
  b_ary <- newArray ((0, 0), (n, n)) 0 :: ST s (STUArray s (Int, Int) Int)

  forM_ lrs $ \[l, r] ->
    writeArray a_ary (l, r) =<< (+1) <$> readArray a_ary (l, r)

  forM_ [1..n] $ \i ->
    forM_ [1..n] $ \j ->
      writeArray b_ary (i, j) =<< (\x y z w -> x + y - z + w)
        <$> readArray b_ary (i-1, j)
        <*> readArray b_ary (i, j-1)
        <*> readArray b_ary (i-1, j-1)
        <*> readArray a_ary (i, j)

  return b_ary


Measured memory_bytes: 84988
#!/usr/bin/env python3
def inp():
        n, m = map(int, input().split())
        return n - 1, m - 1

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 size(self, x):
        return -self.parents[self.find(x)]

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

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

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

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

def rem(cand, p, q):
    cand[p] += 1
    cand[q] += 1

n, m, k = map(int, input().split())
UF = UnionFind(n)
non_cand = [1] * n
for _ in range(m):
    a, b = inp()
    UF.union(a, b)
    rem(non_cand, a, b)
for _ in range(k):
    c, d = inp()
    if UF.same(c, d):
        rem(non_cand, c, d)

ans = [UF.size(i) - non_cand[i] for i in range(n)]

print(*ans)

Measured memory_bytes: 14192
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt(),count4=0,count2=0;
    long[] a=new long[n];
    for(int i=0;i<n;i++) {
    	a[i]=sc.nextLong();
    	if(a[i]%4==0)count4++;
    	else if(a[i]%2==0)count2++;
    }
    if(count4+count2/2>=n/2) {
    	System.out.println("Yes");
    }else {
    	System.out.println("No");
    }
  }
}


Measured memory_bytes: 50432
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[25],b[25],c[25];
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
		cin >> a[i];
	for(int i=1;i<=n;i++)
		cin >> b[i];
	for(int i=1;i<n;i++)
		cin >> c[i];
	int sum=0;
	for(int i=1;i<=n;i++){
		sum+=b[a[i]];
//		cout << b[a[i]] << endl;
		if(i<n&&a[i+1]-a[i]==1){
//			cout << c[a[i]] << endl;
			sum+=c[a[i]];
		}
	}
	cout << sum << endl;
	return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int INF = (int)1e9;
int e_num = 1, S, T;
int hed[maxn], dep[maxn];

struct Edge {
  int from, to, nxt, c;
} edge[maxn * 4];

void addedge(int from, int to, int c) {
  edge[++e_num] = (Edge){from, to, hed[from], c};
  hed[from] = e_num;
}

void adde(int from, int to, int c) {
  addedge(from, to, c);
  addedge(to, from, 0);
}

int que[maxn + 5], head = 0, tail = 0;
bool bfs() {
  head = tail = 0;
  que[tail++] = S;
  for (int i = 0; i <= T; i++) dep[i] = 0;
  dep[S] = 1;
  while (head != tail) {
    int cur = que[head++]; head %= maxn;
    for (int i = hed[cur]; i; i = edge[i].nxt) {
      int to = edge[i].to;
      if (!dep[to] && edge[i].c) {
        dep[to] = dep[cur] + 1;
        que[tail++] = to; tail %= maxn;
      }
    }
  }
  return dep[T];
}

int dfs(int x, int flow) {
  if (x == T) return flow;
  int ret = 0;
  for (int i = hed[x]; i; i = edge[i].nxt) {
    int to = edge[i].to;
    if (dep[to] == dep[x] + 1 && edge[i].c) {
      int tmp = dfs(to, std::min(flow, edge[i].c));
      edge[i].c -= tmp;
      edge[i ^ 1].c += tmp;
      flow -= tmp;
      ret += tmp;
      if (!flow) {
        break;
      }
    }
  }
  if (!ret) dep[x] = 0;
  return ret;
}

int dinic() {
  int ret = 0;
  while (bfs()) {
    ret += dfs(S, INF);
  }
  return ret;
}

const int N = 103;
int n, m, a[N][N], x[N][N], y[N][N], row1[N * N], row2[N * N], ban[N * N], id[N * N];

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
      row1[a[i][j]] = i;
      row2[m * (i - 1) + j] = i;
    }
  }
  S = 0, T = n * 2 + 1;
  for (int c = 1; c <= m; c++) {
    for (int i = 0; i <= T; i++) hed[i] = 0;
    e_num = 1;
    for (int i = 1; i <= n; i++) {
      adde(S, i, 1);
      adde(i + n, T, 1);
    }
    for (int i = 1; i <= n * m; i++) {
      if (!ban[i]) {
        adde(row1[i], row2[i] + n, 1);
        id[i] = e_num - 1;
      }
    }
    dinic();
    for (int i = 1; i <= n * m; i++) {
      if (!ban[i] && !edge[id[i]].c) {
        ban[i] = 1;
        x[row1[i]][c] = i;
        y[row2[i]][c] = i;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      printf("%d ", x[i][j]);
    }
    puts("");
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      printf("%d ", y[i][j]);
    }
    puts("");
  }
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int N; cin >> N;
	vector<P> pos(N);
	rep (i, N){
		cin >> pos[i].first >> pos[i].second;
	} // end rep

	bool ok = true;
	ll par = (abs(pos[0].first) + abs(pos[0].second)) % 2;
	for (int i = 0; i < N; ++i){
		ll par2 = (abs(pos[i].first) + abs(pos[i].second)) % 2;
		pos[i] = P(pos[i].first + pos[i].second, pos[i].first - pos[i].second);
		if (par != par2){
			ok = false;
			break;
		} // end if
	} // end for

	if (!ok){
		cout << "-1" << endl;
	}else{
		vector<ll> d; d.clear();
		for (int i = 30; i >= 0; --i){
			d.push_back(1<<i);
		} // end for
		if (par % 2 == 0) d.push_back(1);

		cout << (int)d.size() << endl;
		for (int j = 0; j < (int)d.size(); ++j){
			cout << d[j] << (j != (int)d.size() - 1 ? ' ' : '\n');
		} // end for
		rep (i, N){
			int xdir, ydir;
			int xsum = 0, ysum = 0;
			for (int j = 0; j < (int)d.size(); ++j){
				if (xsum <= pos[i].first){
					xdir = 1, xsum += d[j];
				}else{
					xdir = -1, xsum -= d[j];
				} // end if
				if (ysum <= pos[i].second){
					ydir = 1, ysum += d[j];
				}else{
					ydir = -1, ysum -= d[j];
				} // end if

				if (xdir == 1 && ydir == 1){
					cout << "R";
				}else
				if (xdir == 1 && ydir == -1){
					cout << "U";
				}else
				if (xdir == -1 && ydir == -1){
					cout << "L";
				}else{ // if (xdir == -1 && ydir == 1)
					cout << "D";
				} // end if
			} // end for
			cout << endl;
		} // end rep
	} // end if

	return 0;
}

Measured memory_bytes: 256
from itertools import accumulate

n = int(input())
A = list(map(int, input().split()))
rem = 10**9+7

acum = list(accumulate(A))

ans = 0
for i in range(n-1):
    ans += (A[i] * (acum[-1] - acum[i]))%rem
    ans  %=  rem
print(ans)

Measured memory_bytes: 31260
#%%timeit
N = int(input())
X_str = input()

X = int(X_str, 2)

popcount_cache = [0, 1] + [-1] * 3 * 10 ** 5
for x in range(2, 200000+2):
  popcount_cache[x] =  popcount_cache[x // 2] + x % 2

# def popcount(x):
#   global popcount_cache
#   if popcount_cache[x] < 0:
#     # tmp = x
#     # p = 0
#     # while tmp not in popcount_cache:
#     #   p += tmp % 2
#     #   tmp //= 2
#     popcount_cache[x] = popcount(x // 2) + x % 2
#   return popcount_cache[x]

count_cache = [0, 1] + [-1] * 3 * 10 ** 5
for x in range(2, 200000+2):
  count_cache[x] = 1 + count_cache[x % popcount_cache[x]]


# def count(x):
#   #print('count', x)
#   global count_cache
#   if count_cache[x] < 0:
#     #print('count', x, popcount(x), x % popcount(x))
#     count_cache[x] = 1 + count(x % popcount[x])
#   return count_cache[x]
  
popcount_N = 0
for s in X_str:
  if s == '1':
    popcount_N += 1

def safemod(x, n):
  if n <= 0:
    return 0
  return x % n

Xmodpp = safemod(X, (popcount_N + 1))
Xmodpn = safemod(X, (popcount_N - 1))

ans = []
for i in range(N):
  if i == 0:
    modpp = 1
    modpn = 1
  else:
    modpp = safemod((modpp * 2) , (popcount_N+1))
    modpn = safemod((modpn * 2) , (popcount_N-1))
  if X_str[N - 1 - i] == '0':
    ans.append(count_cache[  safemod((Xmodpp + modpp), (popcount_N + 1))] + 1)
  else:
    if popcount_N == 1:
      ans.append(0)
    else:
      ans.append(count_cache[  safemod((Xmodpn - modpn), (popcount_N - 1))] + 1)

ans.reverse()
for a in ans:
  print(a)


Measured memory_bytes: 92504
#include <stdio.h>
#include <string.h>
int main(void) {
    int m,h,i,j;
    char string[202],temp[202];
    while (1) {
        scanf("%s\n",string);
        if (strcmp(string,"-")==0) break;
        scanf("%d\n",&m);
        for (i=0; i<m; i++) {
            scanf("%d\n",&h);
            for (j=0; j<h; j++) temp[j]=string[j];
            for (j=0; j<strlen(string)-h; j++) string[j]=string[j+h];
            for (j=0; j<h; j++) string[strlen(string)-h+j]=temp[j];
        }
        printf("%s\n",string);
    }
    return 0;
}

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

int main(){
    int n; cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++){
        if (i % 2 == 0) continue;
        int cnt = 0;
        for (int j = 1; j <= i; ){
            if (i%j == 0) cnt ++;
            j += 2;
        }
        if (cnt == 8) ans ++; 
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
a = gets.chomp.to_i #split(" ").map(&:to_i)

def saiki(k, padding)
  #return 0 if k==0
  return k+padding if k <10
  ans = 0#padding
  [*0..k.to_s.size-1].each do |i|
    ans += saiki(k.to_s[i+1..-1].to_i, k.to_s[0..i].to_i+padding)#+padding
  end
  return ans
end

p saiki(a,0)


Measured memory_bytes: 1788
a = input()
b = input()
c = input()
Sa = [a[i] for i in range(len(a))]
Sb = [b[i] for i in range(len(b))]
Sc = [c[i] for i in range(len(c))]
turn = "a"
while True:
  if turn == "a":
    if len(Sa) == 0:
      print("A")
      break
    else:
      turn = Sa.pop(0)
  elif turn == "b":
    if len(Sb) == 0:
      print("B")
      break
    else:
      turn = Sb.pop(0)
  elif turn == "c":
    if len(Sc) == 0:
      print("C")
      break
    else:
      turn = Sc.pop(0)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
#define int long long
char s[114][114];
char ans[114][114];
signed main(){
	ic(n)
	c((n-1)/2)
}						


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

using namespace std;

#define ones(x) __builtin_popcount(x)
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
#define lbit(x) ((x)&(-(x)))
#define hbit(x) 1<<(31-__builtin_clz(x))
#define isp2(x) ((x) && !((x)&((x)-1)))
#define set(x, p) ((x) |= (1<<(p)))
#define unset(x, p) ((x) &= (~(1<<(p))))
#define flip(x, p) ((x) ^= (1<<(p)))
#define ck(x, p) ((x) & (1<<(p)))

const int L = 17; 
int seg[1<<L];

void build(int l, int r, int flag) {
    if (l+2 == r) return;
    int A = seg[l], B = seg[r-1];
    int p = -1;
    for (int i = 0; i < L; i++) {
        if (ck(A, i) ^ ck(B, i))
            p = i;
    }
    assert(p >= 0);
    unset(flag, p);
    int k = -1;
    for (int i = 0; i < L; i++) {
        if (ck(flag, i))
            k = i;
    }
    assert(k >= 0);
    int m = (l+r)>>1;
    int C = A; flip(C, k); seg[m-1] = C;
    flip(C, p);     seg[m] = C;
    if (ck(A, p)) {
        for (int i = l+1; i < m-1; i++) {
            set(seg[i], p);
        }
        for (int i = m+1; i < r-1; i++) {
            unset(seg[i], p);
        }
    } else {
        for (int i = l+1; i < m-1; i++) {
            unset(seg[i], p);
        }
        for (int i = m+1; i < r-1; i++) {
            set(seg[i], p);
        }
    }
    build(l, m, flag);
    build(m, r, flag);
}

void solve() {
    int n, A, B;
    cin >> n >> A >> B;
    int p = 60 + ones(A) - ones(B);
    if (!(p&1)) {
        cout << "NO";
        return;
    }
    seg[0] = A;
    seg[(1<<n)-1] = B;
    build(0, 1<<n, (1<<n)-1);
    cout << "YES" << "\n";
    for (int i = 0; i < (1<<n); i++) {
        cout << seg[i] << ' ';
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 1536
#include<stdio.h>
int main()
{
	int h, w;
	int i, j;
	for (;;)
	{
		scanf("%d %d", &h, &w);
		if (h == 0 && w == 0)
			break;
		for (i = 0; i < w; i++)
			printf("#");
		printf("\n");
		for (i = 1; i < h - 1; i++)
		{
			printf("#");
			for (j = 1; j < w - 1; j++)
				printf(".");
			printf("#\n");
		}
		for (i = 0; i < w; i++)
			printf("#");
		printf("\n\n");
	}
	return 0;
}


Measured memory_bytes: 2048