akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	map<ll,int> ma;
	for(int i=0;i<n;i++)
	{
		int x; cin>>x;
		ma[x]++;
	}
	ll ans=0;
	ll b1=0; ll b2=0;
	for(auto it=ma.begin();it!=ma.end();it++)
	{
		int occ=it->se;
		if(occ>=4) ans=max(ans,it->fi*it->fi);
		if(occ>=2)
		{
			b2=b1;
			b1=it->fi;
		}
	}
	ans=max(ans,b1*b2);
	cout<<ans<<'\n';
}


Measured memory_bytes: 6528
# -*- coding: utf-8 -*-
import math


def main():
    a = int(input())
    b = int(input())
    c = int(input())
    x = int(input())

    cnt = 0

    for ia in range(a + 1):
        for ib in range(b + 1):
            for ic in range(c + 1):
                total = 500 * ia + 100 * ib + 50 * ic
                if total == x:
                    cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()




Measured memory_bytes: 3060
import java.util.Scanner;
public class Main {

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

		String r = null;
		String a = null;

		r = scan.next();
		a = scan.next();
		while(!r.equals("0") || !a.equals("0")) {
			char rChar[] = r.toCharArray();
			char aChar[] = a.toCharArray();
			
			int hit = 0;
			int blow = 0;
			for(int i = 0 ; i < 4 ; i++) {
				if(rChar[i] == aChar[i]) {

					++hit;
					rChar[i] = ' ';
					aChar[i] = ' ';

				}else{
					
					for(int j = 0 ; j < 4 ;j++) {
						if(rChar[i] == aChar[j]) {
							++blow;
						}
					}
					
				}
			}
			System.out.println(hit +  " " + blow);
			r = scan.next();
			a = scan.next();
		}
	}
}



Measured memory_bytes: 44004
#include<iostream>
#include<memory>
#include<vector>
#include<algorithm>

using namespace std;

void populate_depth(vector<class node *>&, int, int);

class node {
 public:
  vector<int> child_idxs;
  int id;
  int depth;
  explicit node(int id) :id{id} {}
};

int main() {
  int n; cin >> n;
  vector<node*> nodes(n);
  int id, k, cidx;
  for (int i = 0; i < n; ++i) nodes[i] = new node(i);

  for (int i = 0; i < n; ++i) {
    cin >> id >> k;
    nodes[id]->child_idxs = vector<int>();
    for (int ci = 0; ci < k; ++ci) {
      cin >> cidx;
      nodes[id]->child_idxs.push_back(cidx);
    }
  }

  vector<int> parents(n, -1);

  for (auto &v : nodes) {
    for (auto c : v->child_idxs) {
      parents[c] = v->id;
    }
  }

  int root_id = static_cast<int>(
      distance(parents.begin(), find(parents.begin(), parents.end(), -1))
      );

  populate_depth(nodes, root_id, 0);

  for (int i = 0; i < n; ++i) {
    cout << "node " << i << ": parent = " << parents[i]
      << ", depth = " << nodes[i]->depth << ", "
      << (parents[i] == -1 ? "root" :
          (nodes[i]->child_idxs.empty() ? "leaf" : "internal node"))
      << ", [";
    if (!(nodes[i]->child_idxs.empty())) {
      cout << nodes[i]->child_idxs.at(0);
      for (int ci = 1; ci < static_cast<int>(nodes[i]->child_idxs.size()); ++ci)
        cout << ", " << nodes[i]->child_idxs.at(ci);
    }
    cout << "]" << endl;
  }
}

void populate_depth(vector<node*> &nodes, int curr, int depth) {
  nodes[curr]->depth = depth;
  for (int cid : nodes[curr]->child_idxs)
    populate_depth(nodes, cid, depth + 1);
}


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

int main(){
    int n,k;cin>>n>>k;
    vector<int> x(n);
    ll ans=10000000000;
    for(int i=0;i<n;i++) cin>>x[i];
    for(int l=0;l<n-k+1;l++){
        int r=l+k-1;
        ll time;
        if(x[l]<0&&x[r]<=0) time=abs(x[l]);
        else if(x[l]>=0&&x[r]>0) time=x[r];
        else time=x[r]+abs(x[l])+min(x[r],abs(x[l]));
        ans=min(ans,time);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 768
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    string s;
    cin>>s;
    vector<char> v(70);
    FOR(i,0,70){
        v[i] = (i%26+'A');
    }

    FOR(i,0,s.size()){
        cout<<v[s[i]-'A'+n];
    }
    cout<<endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static Scanner scan  = new Scanner(System.in);
    public static void main(String[]args){
        String s = next();
        if(s.contains("RRR")){
            print(3);
        }
        else if(s.contains("RR")){
            print(2);
        }
        else if(s.contains("R")){
            print(1);
        }
        else print(0);
    }


    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }

    //print
    public static void print(Object a){
        System.out.println(a);
    }


    //gcd
    public static int gcd (int a, int b){
        int tmp;
        while((tmp = a%b) != 0){
            a = b;
            b = tmp;
        }
        return b;
    }


    //lcm
    public static int lcm(int a,int b){
        int tmp;
        long c = a;
        c *= b;
        while((tmp = a%b) != 0){
            a = b;
            b = tmp;
        }
        return (int)(c/b);
    }
}

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

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    vector<int> cnt(7, 0);
    while (n--) {
      int age;
      cin >> age;

      if (age >= 60)
	++cnt[6];
      else
	++cnt[age/10];
    }

    for (int i = 0; i < 7; ++i)
      cout << cnt[i] << endl;
  }
  return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    vector<ll> A(N), B(N), C(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N) cin >> C[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    ll ans = 0;
    rep(i, N) {
        ll b = B[i];
        ll cnt = upper_bound(A.begin(), A.end(), b - 1) - A.begin();
        ll cnt2 = N - (lower_bound(C.begin(), C.end(), b + 1) - C.begin());
        ans += cnt * cnt2;
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


Measured memory_bytes: 2688
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    ll a = inp1, b = inp1;
    ll k = (a + b) / 2;
    if (abs(a-k) == abs(b-k))
        say(k);
    else
        say("IMPOSSIBLE");
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    string S;cin>>S;
    cout<<((S[0]=='9' || S[1]=='9')?"Yes":"No")<<endl;
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int a[] = new int[n];
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt() - 1;
		}
		for (int i = 0; i < n; i++) {
			if (a[a[i]] == i) {
				cnt++;
			}
		}
		System.out.println(cnt / 2);
	}
}

Measured memory_bytes: 50064
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main(){
   int sum=0;
   for(int i=0;i<3;i++){
      int a;
      cin >> a;
      sum +=a;
   }
   if(sum >=22) cout << "bust" << endl;
   else cout << "win" << endl;
   return 0;
}

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

template <class T>
class SegTree {
    int n;
    vector<T> data;
    T def;
    function<T(T,T)> operation;
    function<T(T,T)> update;

    T _query(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l) return def;
        if(a <= l && r <= b) return data[k];
        else {
            T c1 = _query(a, b, 2*k+1, l, (l+r)/2);
            T c2 = _query(a, b, 2*k+2, (l+r)/2, r);
            return operation(c1, c2);
        }
    }
  public:
    SegTree(size_t _n, T _def, function<T(T,T)> _operation, function<T(T,T)> _update)
    : def(_def), operation(_operation), update(_update) {
            n = 1;
            while(n < _n) {
                n *= 2;
            }
            data = vector<T>(2*n-1, def);
    }

    void change(int i, T x) {
        i += n-1;
        data[i] = update(data[i], x);
        while(i > 0) {
            i = (i-1)/2;
            data[i] = operation(data[2*i+1], data[2*i+2]);
        }
    }

    T query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

    T operator[](int i) {
        return data[i+n-1];
    }
};

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

    SegTree<int> st(N, 0,
                            [](int a, int b) {return a+b; },
                            [](int a, int b) {return a+b; });
    for(int q = 0; q < Q; ++q) {
        int c, x, y;
        cin >> c >> x >> y;
        --x;
        if(c == 0) {
            st.change(x, y);
        } else {
            cout << st.query(x, y) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3860
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

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

const int N = 2e2 + 10;

int x[N], y[N];

// Adjacency list implementation of Dinic's blocking flow algorithm.
// This is very fast in practice, and only loses to push-relabel flow.
//
// Running time:
//     O(|V|^2 |E|)
//
// INPUT:
//     - graph, constructed using AddEdge()
//     - source and sink
//
// OUTPUT:
//     - maximum flow value
//     - To obtain actual flow values, look at edges with capacity > 0
//       (zero capacity edges are residual edges).

typedef long long LL;

//From Brian Bi's codebook
struct Edge {
  int u, v;
  LL cap, flow;
  Edge() {}
  Edge(int u, int v, LL cap): u(u), v(v), cap(cap), flow(0) {}
};

struct Dinic {
  int N;
  vector<Edge> E;
  vector<vector<int>> g;
  vector<int> d, pt;
  
  Dinic(int N): N(N), E(0), g(N), d(N), pt(N) {}

  void AddEdge(int u, int v, LL cap) {
    if (u != v) {
      E.emplace_back(Edge(u, v, cap));
      g[u].emplace_back(E.size() - 1);
      E.emplace_back(Edge(v, u, 0));
      g[v].emplace_back(E.size() - 1);
    }
  }

  bool BFS(int S, int T) {
    queue<int> q({S});
    fill(d.begin(), d.end(), N + 1);
    d[S] = 0;
    while(!q.empty()) {
      int u = q.front(); q.pop();
      if (u == T) break;
      for (int k: g[u]) {
        Edge &e = E[k];
        if (e.flow < e.cap && d[e.v] > d[e.u] + 1) {
          d[e.v] = d[e.u] + 1;
          q.emplace(e.v);
        }
      }
    }
    return d[T] != N + 1;
  }

  LL DFS(int u, int T, LL flow = -1) {
    if (u == T || flow == 0) return flow;
    for (int &i = pt[u]; i < g[u].size(); ++i) {
      Edge &e = E[g[u][i]];
      Edge &oe = E[g[u][i]^1];
      if (d[e.v] == d[e.u] + 1) {
        LL amt = e.cap - e.flow;
        if (flow != -1 && amt > flow) amt = flow;
        if (LL pushed = DFS(e.v, T, amt)) {
          e.flow += pushed;
          oe.flow -= pushed;
          return pushed;
        }
      }
    }
    return 0;
  }

  LL MaxFlow(int S, int T) {
    LL total = 0;
    while (BFS(S, T)) {
      fill(pt.begin(), pt.end(), 0);
      while (LL flow = DFS(S, T))
        total += flow;
    }
    return total;
  }
};

int main()
{
  int n; cin >> n;
  Dinic dinic(2 * N + 2);
  for (int i = 1; i <= 2 * n; ++i) {
  	cin >> x[i] >> y[i];
  }
  for (int i = 1; i <= n; ++i) {
  	dinic.AddEdge(0, i, 1);
  	for (int j = n + 1; j <= 2 * n; ++j) {
  		if (x[i] < x[j] and y[i] < y[j]) {
  			dinic.AddEdge(i, j, 1);
  		}
  		if (i == 1) {
  			dinic.AddEdge(j, 2 * n + 1, 1);
  		}
  	}
  }
  cout << dinic.MaxFlow(0, 2 * n + 1) << endl;
}


Measured memory_bytes: 604
import collections
def main():


    N = int(input())
    V = list(map(int,input().split()))
    V1 = V[0::2]
    V2 = V[1::2]
    count = 0

    fre1 = collections.Counter(V1).most_common(2)
    fre2 = collections.Counter(V2).most_common(2)
    

    if len(list(set(V)))==1:
        print(int(N/2))
        exit()


    if fre1[0][0] != fre2[0][0]:

        count += len(V1)-fre1[0][1]
        count += len(V2)-fre2[0][1]
        print(count)
    elif len(V1)-fre1[0][1] == len(V2)-fre2[0][1]:
        bigger = max(fre1[1][1],fre2[1][1])
        count += len(V1)-bigger
        count += len(V1)-fre1[0][1]
        print(count)
    else:
        if len(V1)-fre1[0][1] < len(V2)-fre2[0][1]:
            count += len(V1)-fre1[0][1]
            count += len(V2)-fre2[1][1]
            print(count)
        else:
            count += len(V1)-fre1[1][1]
            count += len(V2)-fre2[0][1]
            print(count)

        






if __name__== "__main__":
    main() 


Measured memory_bytes: 16572
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const int Maxn=100000+5;
int n,h[Maxn],f[Maxn];
int main()
{	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&h[i]);
	f[1]=0;f[2]=abs(h[1]-h[2]);
	for(int i=3;i<=n;i++)
		f[i]=min(f[i-1]+abs(h[i]-h[i-1]),f[i-2]+abs(h[i]-h[i-2]));
	printf("%d\n",f[n]);
	return 0;
}

Measured memory_bytes: 1024
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    l,r,d = map(int,ipt().split())
    ans = 0
    for i in range(l,r+1):
        if i%d == 0:
            ans += 1
    print(ans)

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 74716
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define pp pair<ll,ll>
#define pq_min priority_queue<ll,vector<ll>,greater<ll>>
#define pq_max priority_queue<ll>
#define forx(i,a,b) for(ll i=0;i<a;i++)
#define ld long double
const ll mod=1e9 + 7;
const ll N=15; 
ll power(ll a,ll b)
{
	a=a%mod;
	ll ans=1;
	while(b>0)
	{
		if(b%2==1)
		{
			ans=(ans*a)%mod;
		}
		b=b/2;
		a=(a*a)%mod;
	}
	return ans;
}

 
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	srand(time(NULL));
    ll n,m;
    cin>>n>>m;
    ll a[n][m];
    ll b[n][m];
    for(ll i=0;i<n;i++)
    {
    	for(ll j=0;j<m;j++)
    	{
    		cin>>a[i][j];
		}
	}
    for(ll i=0;i<n;i++)
    {
    	for(ll j=0;j<m;j++)
    	{
    		cin>>b[i][j];
		}
	}
	
	bool ans[n][m][13000];
	memset(ans,0,sizeof(ans));
	ll z=abs(a[0][0]-b[0][0]);
	ans[0][0][z]=1;
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<m;j++)
		{
				ll f=abs(a[i][j]-b[i][j]);
				if(i>0)
				{
					for(ll k=0;k<13000;k++)
					{
						if(ans[i-1][j][k]==1)
						{
							ans[i][j][k+f]=1;
							ans[i][j][abs(k-f)]=1;
						}
					}
				}
				if(j>0)
				{
					for(ll k=0;k<13000;k++)
					{
						if(ans[i][j-1][k]==1)
						{
						    ans[i][j][k+f]=1;
							ans[i][j][abs(k-f)]=1;
						}
					}
				}
		}
	}
	for(ll i=0;i<13000;i++)
	{
		if(ans[n-1][m-1][i]==1)
		{
			cout<<i<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 81664
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String[] nyu=sc.nextLine().split(" ");
   //  String nyu=sc.nextLine();

int A=Integer.parseInt(nyu[0]);
int B=Integer.parseInt(nyu[1]);
int T=Integer.parseInt(nyu[2]);


int count=0;
int num=0;
int ryo=0;
while(true){
if(count>T)break;

if(count%A==0 && count!=0)ryo+=B;
//System.out.println(ryo+"--"+count);
count++;
}

System.out.println(ryo);



	}
}

Measured memory_bytes: 22996
a,b = map(int,input().split())
c,d = map(int,input().split())
e,f = map(int,input().split())
l = [a,b,c,d,e,f]
if l.count(1)>=3:
  print("NO")
  exit()
if l.count(2)>=3:
  print("NO")
  exit()
if l.count(3)>=3:
  print("NO")
  exit()
if l.count(4)>=3:
  print("NO")
  exit()
print("YES")

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};

const int N=2e5+5;
int a[N];
int b[N];

int32_t main(){

    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;++i){
        cin>>a[i];
    }
    forn(z,k){
        for(int i=1;i<=n;++i){
            b[i]=0;
        }
        for(int i=1;i<=n;++i){
            int l=max(1ll,i-a[i]);
            int r=min(n+1,i+a[i]+1);
            b[l]++;
            b[r]--;
        }
        int c=0,f=1;
        for(int i=1;i<=n;++i){
            c+=b[i];
            a[i]=c;
            if(a[i]!=n)f=0;
        }
        if(f)break;
    }
    for(int i=1;i<=n;++i){
        cout<<a[i]<<' ';
    }
    cout<<'\n';

    return 0;
}


Measured memory_bytes: 6776
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
	
	void run() {
		int n = sc.nextInt();
		String[] s = new String[n];
		
		int count = 0;
		int startFromB =0;
		int endWithA =0;
		int B_A = 0;
		
		for(int i = 0 ; i < n ; i++) {
			s[i] = sc.next();
			
			count += countAB(s[i]);
			
			if(s[i].charAt(0) == 'B') {
				startFromB ++;
			}
			if(s[i].charAt(s[i].length()-1) == 'A') {
				endWithA ++;
			}

			if(s[i].charAt(0) == 'B') {
				if(s[i].charAt(s[i].length()-1) == 'A') {
					B_A++;
				}
			}				
		}
		
		
		int byConcat = Math.min(Math.min(startFromB, endWithA), n-1) ;

		if(Math.max(startFromB, endWithA) == B_A) {
			byConcat = Math.max(0, B_A - 1);
		}
		
		System.out.println(count +byConcat);
		
	}
	
	int countAB(String str) {
		int res = 0;
		int flg = 0;
		for(char ch : str.toCharArray()) {
			if(flg == 0) {
				if(ch == 'A') {
					flg = 1;
				}else {
					flg = 0;
				}
			}else {
				if(ch == 'B') {
					res++;
				}
				if(ch != 'A') {
					flg = 0;
				}
				
			}
		}
		return res;
	}
}


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

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

void solve() {
  int n,m; cin >> n >> m;
  vector<string> a(n),b(m);
  for(int i=0; i<n; ++i) cin >> a.at(i);
  for(int i=0; i<m; ++i) cin >> b.at(i);

  for(int i=0; i<n-m+1; ++i) {
    for(int j=0; j<n-m+1; ++j) {
    //  if(a[i][j]==b[0][0]) {
      if(i+m-1>=n || j+m-1>=n) continue;
        int ok=1;
        bool match = true;
        for(int k=0; k<m; ++k) {
          for(int l=0; l<m; ++l) {
            if(a[i+k][j+l]!=b[k][l]) {
              --ok; match=false;
            }
          }
        }
        if(match) drop("Yes");
    }
  }
  cout << "No" << endl;

  return;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


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

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

    int ans = N;
    int A;
    for (int i = 0; i < M; i++)
    {
        cin >> A;
        ans -= A;
    }
    cout << max(-1, ans) << endl;
}


Measured memory_bytes: 3632
unittest
{
	assert( [ "1 2 10 20 15 200" ].parse.expand.solve == "110 10" );
	assert( [ "1 2 1 2 100 1000" ].parse.expand.solve == "200 100" );
	assert( [ "17 19 22 26 55 2802" ].parse.expand.solve == "2634 934" );
}



import std.algorithm;
import std.conv;
import std.functional;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abcdef = input.front.split.to!( long[] );
	return tuple( abcdef[ 0 ], abcdef[ 1 ], abcdef[ 2 ], abcdef[ 3 ], abcdef[ 4 ], abcdef[ 5 ] );
}

auto solve( long a, long b, long c, long d, long e, long f )
{
	a *= 100;
	b *= 100;
	
	auto ws = memoize!combisum( a, b, f );
	ws.popFront;		// 0は削る
	
	auto pm = -1.0f;
	auto wm = 0L;
	auto sm = 0L;
	foreach( w; ws )
	{
		auto st = min( w / 100 * e, f - w );
		auto s = memoize!combisum( c, d, st ).reduce!max;
		auto p = 100.0f * s / ( w + s );
		
		if( pm < p )
		{
			pm = p;
			wm = w;
			sm = s;
		}
	}
	
	return format( "%d %d", wm + sm, sm );
}

auto combisum( long x, long y, long t )
{
	long[] cs;
	
	for( auto xi = 0; true; xi++ )
	{
		auto xc = x * xi;
		if( t < xc ) break;
		
		for( auto yi = 0; true; yi++ )
		{
			auto yc = y * yi;
			auto c = xc + yc;
			if( t < xc + yc ) break;
			
			cs ~= xc + yc;
		}
	}
	
	return cs.sort().uniq;
}


Measured memory_bytes: 3324
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();

		int[][] treat = new int[k][n];
		for(int i = 0; i < k; i++){
			int d = sc.nextInt();

			for(int j = 0; j < d; j++){
				treat[i][sc.nextInt() - 1]++;
			}
		}

		int trick = 0;
		for(int i = 0; i < n; i++){
			boolean nothing = true;

			for(int j = 0; j < k; j++){
				if(treat[j][i] > 0){
					nothing = false;
					break;
				}
			}

			if(nothing){
				trick++;
			}
		}

		System.out.println(trick);


	}

}


Measured memory_bytes: 37288
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

signed main(){
    
    int x, a; cin >> x >> a;
    if(x < a) cout << 0 << endl;
    else cout << 10 << endl;   
    return 0;
}


Measured memory_bytes: 256
a[101],b[101];j;k;y;z;main(x){for(;~scanf("%d%d",a+k++,b+k););for(;j++-*a;printf("%d ",z))for(k=0;k++-*b;k==1|x<y?y=x,z=k:0)x=abs(a[j]-a[*a+k])+abs(b[j]-b[*a+k]);}

Measured memory_bytes: 128
import { readFileSync } from 'fs'

const canFinish = (works: number[][]) => {
  let totalTime = 0

  for (const [time, limit] of works) {
    totalTime += time
    if (totalTime > limit) {
      return false
    }
  }

  return true
}

function main(input: string) {
  const [[N], ...works] = input.split('\n').map(v => v.split(' ').map(Number))

  works.sort(([, a], [, b]) => a - b)

  console.log(canFinish(works) ? 'Yes' : 'No')
}

main(readFileSync('/dev/stdin', 'utf8').trim())


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    string s; cin >> s;
    ll n = s.length();

    vector<ll> val(2019, 0);
    ll fac = 1;
    ll cur = 0;
    //なぜ行う？
    //右からn文字目をs[n]として
    //s[a] と s[b] を 2019 で割った余りが等しい場合に答えの組み合わせが増えていく
    //s[b]がb=0の場合も含まれる（文字列の一番右まで見た場合）ため、s[0]の時の余りも組み合わせの一つとして入れておく
    val[cur]++;

    for (ll i = 0; i < n; ++i) {
        ll add = s[n - 1 - i] - '0'; //後ろから見ていく
        cur = (cur + fac * add) % 2019;
        fac = (fac * 10) % 2019; //10倍していく方も事前に2019で割っておいて良い
        val[cur]++;
    }

    ll ans = 0;
    for (ll i = 0; i < (ll)val.size(); ++i) {
        ans += val[i] * (val[i] - 1) / 2; //nC2を計算
    }

    cout << ans << endl;
}

Measured memory_bytes: 3728
x = int(input())

if x <= 111:
    print(111)
elif x <= 222:
    print(222)
elif x <= 333:
    print(333)
elif x <= 444:
    print(444)
elif x <= 555:
    print(555)
elif x <= 666:
    print(666)
elif x <= 777:
    print(777)
elif x <= 888:
    print(888)
else:
    print(999)


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) { cin >> a[i]; }

    ll ans = 0;
    rep(i, n) {
        ans += a[i] / 2;
        a[i] %= 2;
        if (i != n - 1) {
            if (a[i] && a[i + 1]) {
                a[i]--;
                a[i + 1]--;
                ans++;
            }
        }
    }

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



Measured memory_bytes: 4392
import java.util.Scanner;

public class Main
{
    private final static Main main = new Main();

    public static void main(String[] args)
    {
        long l = System.currentTimeMillis();
        main.contest();
        //System.out.println("処理時間：" + (System.currentTimeMillis() - l));
    }

    private void contest()
    {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        System.out.println(s.matches(".*C.*F.*") ? "Yes" : "No");
    }
}


Measured memory_bytes: 10192
import sys
n,k,q = map(int,input().split())
if k > q:
    for _ in range(n):
        print("Yes")
    sys.exit()
p = [0 for i in range(n)]

for __ in range(q):
    number = int(input())
    p[number - 1] += 1

for x in range(n):
    if k - q + p[x] >= 1:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
int main(){
  int W,H,N,p,q,r,s;
  cin>>W>>H>>N;
  vector<vector<int>>A(N,vector<int>(3));
  for(int i=0;i<N;i++){
    for(int j=0;j<3;j++){
      cin>>A.at(i).at(j);
    }
  }
  p=0,q=W,r=0,s=H;
  for(int i=0;i<N;i++){
    if(A.at(i).at(2)==1)p=max(p,A.at(i).at(0));
    if(A.at(i).at(2)==2)q=min(q,A.at(i).at(0));                          
    if(A.at(i).at(2)==3)r=max(r,A.at(i).at(1));                          
    if(A.at(i).at(2)==4)s=min(s,A.at(i).at(1));
  }
  if(q>=p&&s>=r)cout<<(q-p)*(s-r)<<endl;
  else cout<<0<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a[10000];
	int j=0;
	scanf("%d",&a[j]);
	while(a[j]!=0)
	{
		j++;
		scanf("%d",&a[j]);
	}
	for(int i=0;i<j;i++)
	{
		printf("Case %d: %d",i+1,a[i]);
		printf("\n");
	}
	return 0;
} 


Measured memory_bytes: 2728
// atcoder/abc140/E/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<lli> v(n);
    cin >> v;

    vector<pair<int, lli>> u;
    for (int i = 0; i < v.size(); ++i) {
      u.push_back({i, v[i]});
    }
    sort(u.begin(), u.end(), [] (auto i, auto j) { return i.second > j.second; });

    set<pair<int, lli>> s;
    s.insert({-1, -1});
    s.insert({-1, -2});
    s.insert({n, n+1});
    s.insert({n, n+2});

    lli sum = 0;
    each (i, u) {
      s.insert(i);
      if (i.second == n) continue;
      auto x = s.find(i);
      auto b = --x;
      auto a = --x;
      ++x;
      ++x;
      auto c = ++x;
      auto d = ++x;
      --x;
      --x;

      sum += x->second * (b->first - a->first) * (c->first - x->first);
      sum += x->second * (d->first - c->first) * (x->first - b->first);
    }
    cout << sum << endl;
  }

  return 0;
}


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

int main(){ 
	int n,k;
	cin >> n >> k;
	long long arr[n+1];
	for(int i = 1;i <= n;i++)
		cin >> arr[i];

	sort(arr + 1, arr + 1 + n);

	long long sum = 0;
	for(int i = 1;i <= k;i++)
		sum += arr[i];

	cout << sum;
}

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1LL << 60;

//Write From this Line

int main()
{
	ll a, b, c;
	cin >>  a>> b>> c;
	if(4 * a * b < (c - a - b) * (c - a - b) && (c - a - b) > 0){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}


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

int main(){
    int N,i,alice = 0,bob = 0;
    cin >> N;
    vector<int> a(N);
    for(i = 0 ; i < N;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end(),greater<int>());

    for(i = 0 ; i < N;i++){
        if(i%2 == 0){
            alice += a[i];
        }else{
            bob += a[i];
        }
    }
    cout << alice - bob;
}

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

using namespace std;

int main() {
  bool can = false;
  int num = 0;
  int A, B;
  string S;

  cin >> A >> B;

  for (int i = A; i <= B; ++i) {
    S = to_string(i);
    if (S[0] == S[4] && S[1] == S[3]) {
      num += 1;
    }
  }

  cout << num << endl;
  
  // if (can) cout << "Yes" << endl;
  // else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	ll L, R;
	cin >> L >> R;
	if(L%2019==0 || L/2019!=R/2019){
	    cout << 0 << endl;
	    return 0;
	}
	ll ans=2020;
	for(ll p=L; p<R; ++p){
	    for(ll q=p+1; q<=R; ++q){
	        ans=min(ans, (p*q)%2019);
	    }
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main(){
	int n,count=0,ch;
	int p;
	
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&p);
		if(p==2||p==3)
		count++;
		else if(p>3&&p%2!=0){
			ch=0;
			for(int j=3;j<=sqrt(p);j=j+2){
				if(p%j==0){
					ch=1;
					break;
				}
			}
			if(ch==0)
			count++;
		}
	}
	printf("%d\n",count);
}

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

int main(){
  int N,K;
  cin >> N >> K;
  if(K==1){
    cout << N+1 << endl;
  }
  else if(K==2){
    cout << 2*N << endl;
  }
  else if(K==3||K==4){
    if(N!=1){
      cout << 4+K*(N-2) << endl;
    }
    else{
      cout << 2 << endl;
    }
  }
  else if(K==9||K==10){
    if(N==1){
      cout << 2 << endl;
    }
    else if(N==2){
      cout << 4 << endl;
    }
    else if(N==3){
      cout << 8 << endl;
    }
    else if(N==4){
      cout << 16 << endl;
    }
    else{
      cout << 16+(N-4)*K << endl;
    }
  }
  else{
    if(N==1){
      cout << 2 << endl;
    }
    else if(N==2){
      cout << 4 << endl;
    }
    else if(N==3){
      cout << 8 << endl;
    }
    else{
      cout << 8+K*(N-3) << endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
int divr[maxn];
/*ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}*/
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
 
 
 
 
 














int main()
{
     int n,m;
     cin>>n>>m;
     vector<pi> vec(n);
     for(int i=0;i<n;i++)
     {
          cin>>vec[i].fi>>vec[i].se;
     }
     sort(vec.begin(),vec.end());
     ll cost=0;
     for(int i=0;i<vec.size()&&m>0;i++)
     {
          int t=vec[i].se;
          if(t<m){
               m-=t;
               cost+=t*vec[i].fi;
          }
          else
          {
               cost+=m*vec[i].fi;
               m=0;
          }
     }
     cout<<cost;

}




















 
 
 
 
 

















Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <math.h>

using namespace std;

int N;
double cos60 = 1.0 / 2.0;
double sin60 = sqrt(3) / 2.0;

class Point
{
  public:
    Point(double _x, double _y) : x(_x), y(_y) {}

    double x;
    double y; 

    void print()
    { printf("%08f %08f\n", this->x, this->y); }
};

void kock(int n, Point &p1, Point &p2)
{
  if(n == 0)
    return;

  const double dx = p2.x - p1.x, dy = p2.y - p1.y;

  Point s(p1.x + 1.0 / 3.0 * dx, p1.y + 1.0 / 3.0 * dy);
  Point t(p1.x + 2.0 / 3.0 * dx, p1.y + 2.0 / 3.0 * dy);
  Point u(1.0 / 3.0 * (cos60 * dx - sin60 * dy) + s.x, 
          1.0 / 3.0 * (sin60 * dx + cos60 * dy) + s.y);

  kock(n-1, p1, s);
  s.print();
  kock(n-1, s, u);
  u.print();
  kock(n-1, u, t);
  t.print();
  kock(n-1, t, p2);

}

int main()
{
  cin >> N;
 
  Point p1(0.0, 0.0), p2(100.0, 0.0);

  p1.print();
  kock(N, p1, p2);
  p2.print();

  return 0;
}



Measured memory_bytes: 3220
n,m = map(int,input().split())

a = []
b = []
c = []
d = []
e = []
f = []
g = []
h = []

for i in range(n):
    x,y,z = map(int,input().split())
    a.append(x+y+z)
    b.append(x+y-z)
    c.append(x-y+z)
    d.append(x-y-z)
    e.append(-x+y+z)
    f.append(-x+y-z)
    g.append(-x-y+z)
    h.append(-x-y-z)

a.sort()
b.sort()
c.sort()
d.sort()
e.sort()
f.sort()
g.sort()
h.sort()

#print(a)

a1 = 0
b1 = 0
c1 = 0
d1 = 0
e1 = 0
f1 = 0
g1 = 0
h1 = 0
for i in range(m):
    a1 += a[len(a)-1-i]
    b1 += b[len(b)-1-i]
    c1 += (c[len(c)-1-i])
    d1 += (d[len(d)-1-i])
    e1 += (e[len(e)-1-i])
    f1 += (f[len(f)-1-i])
    g1 += (g[len(g)-1-i])
    h1 += (h[len(g)-1-i])
print(max(a1,b1,c1,d1,e1,f1,g1,h1))


Measured memory_bytes: 3444
import sys

n, x, *a = map(int, sys.stdin.read().split())
a = [0] + a

def main():
  tot = 0
  for i in range(1, n + 1):
    if a[i] + a[i-1] > x:
      tot += a[i] + a[i-1] - x
      a[i] = x - a[i-1]
  print(tot)

if __name__ ==  '__main__':
  main()

Measured memory_bytes: 14092
//atcoder.jp abc 120 d
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define fst first
#define scd second
using namespace std;
 
inline ll read() {
     ll f=1,x=0;char ch=getchar();
     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
     while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
     return x*f;
}
 
const int MAXN=1e5+5;
int n,m,fa[MAXN];
 
struct EDGE {
     int u,v;
}e[MAXN];
 
ll ans[MAXN],sz[MAXN];
 
int get_fa(int x) {
     if(x==fa[x]) return x;
     return fa[x]=get_fa(fa[x]);
}
 
int main() {
    //freopen("","r",stdin);
    //freopen("","w",stdout);
     ios::sync_with_stdio(0);cin.tie(0);/*syn加速*/
     n=read();m=read();
     
     for(int i=1;i<=m;++i) {
          e[i].u=read(); e[i].v=read();
     }
     
     for(int i=1;i<=n;++i) 
        fa[i]=i,sz[i]=1;
     
     ans[m]=(ll)n*(n-1)/2;
     
     for(int i=m;i>=1;--i) {
          int u=get_fa(e[i].u),v=get_fa(e[i].v);
          if(u==v) 
              ans[i-1]=ans[i];
          else {
               ans[i-1]=ans[i]-sz[v]*sz[u];
               sz[v]+=sz[u]; fa[u]=v;
          }
     }
     
     for(int i=1;i<=m;++i) 
        cout<<ans[i]<<endl;
     return 0;
}

Measured memory_bytes: 4096
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    String S =sc.next();
    String s[] =S.split("",0);
    String T =sc.next();
    String t[] =T.split("",0);
    int ans=0;
    for(int i=0;i<3;i++){
      if(s[i].equals(t[i])){ans =ans+1;}}
    System.out.println(ans);
  }
}

Measured memory_bytes: 35672
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        ModInt[] res = new ModInt[n + 1];
        res[0] = 1;
        for (int i = 1; i < res.Length; i++)
        {
            for (int j = 0; j <= i - 3; j++)
            {
                res[i] += res[j];
            }
        }
        Console.WriteLine(res.Last());
    }
}


struct ModInt
{
    public const int Mod = 1000000007;
    const long POSITIVIZER = ((long)Mod) << 31;
    long Data;
    public ModInt(long data) { if ((Data = data % Mod) < 0) Data += Mod; }
    public static implicit operator long(ModInt modInt) => modInt.Data;
    public static implicit operator ModInt(long val) => new ModInt(val);
    public static ModInt operator +(ModInt a, int b) => new ModInt() { Data = (a.Data + b + POSITIVIZER) % Mod };
    public static ModInt operator +(ModInt a, long b) => new ModInt(a.Data + b);
    public static ModInt operator +(ModInt a, ModInt b) { long res = a.Data + b.Data; return new ModInt() { Data = res >= Mod ? res - Mod : res }; }
    public static ModInt operator -(ModInt a, int b) => new ModInt() { Data = (a.Data - b + POSITIVIZER) % Mod };
    public static ModInt operator -(ModInt a, long b) => new ModInt(a.Data - b);
    public static ModInt operator -(ModInt a, ModInt b) { long res = a.Data - b.Data; return new ModInt() { Data = res < 0 ? res + Mod : res }; }
    public static ModInt operator *(ModInt a, int b) => new ModInt(a.Data * b);
    public static ModInt operator *(ModInt a, long b) => a * new ModInt(b);
    public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { Data = a.Data * b.Data % Mod };
    public static ModInt operator /(ModInt a, ModInt b) => new ModInt() { Data = a.Data * GetInverse(b) % Mod };
    public static bool operator ==(ModInt a, ModInt b) => a.Data == b.Data;
    public static bool operator !=(ModInt a, ModInt b) => a.Data != b.Data;
    public override string ToString() => Data.ToString();
    public override bool Equals(object obj) => (ModInt)obj == this;
    public override int GetHashCode() => (int)Data;
    static long GetInverse(long a)
    {
        long div, p = Mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
        while (true)
        {
            if (p == 1) return x2 + Mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p;
            if (a == 1) return x1 + Mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a;
        }
    }
}

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

typedef long long ll;
typedef tuple<ll, int, int> tlii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll>> vvl;
#define rep(i, a, b) for (ll i=(a); i<(b); i++)
#define rrep(i, a, b) for (ll i=(a); i>(b); i--)
#define all(obj) (obj).begin(), (obj).end()
#define pb push_back
#define str to_string
#define mkp make_pair
#define mkt make_tuple
#define print(out) cout << (out) << endl
// const ll INF = 1e18;
const ll INF = pow(2, 31)-1;
const ll MOD = 1e9 + 7;
void chmax(ll &a, ll b) { a = max(a, b); }
void chmin(ll &a, ll b) { a = min(a, b); }


template<typename Monoid>
struct SegmentTree {
	using F = function<Monoid(Monoid, Monoid)>;
	
	int sz;
	vector<Monoid> seg;
	
	const F f;
	const Monoid M1;
	
	SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
		sz = 1;
		while(sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}
	
	void set(int k, const Monoid &x) {
		seg[k + sz] = x;
	}
	
	void build() {
		for(int k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}
 
  	void update(int k, const Monoid &x) {
    	k += sz;
    	seg[k] = x;
    	while(k >>= 1) {
      		seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    	}
  	}
 
	Monoid query(int a, int b) {
		Monoid L = M1, R = M1;
		for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if(a & 1) L = f(L, seg[a++]);
			if(b & 1) R = f(seg[--b], R);
		}
	    return f(L, R);
	}

	Monoid operator[](const int &k) const {
    	return seg[k + sz];
	}
};

int main() {
	int N,Q,c,x,y;
	cin >> N >> Q;
	// c++のラムダ [](引数) -> 戻り値型 { 処理内容 }
	SegmentTree<ll> st(N, [](ll a, ll b) { return min(a, b); }, INF);
	while(Q--) {
		cin >> c >> x >> y;
		if (c==0) {
			st.update(x, y);
		} else {
			print(st.query(x, y+1));
		}
	}
	return 0;
}



Measured memory_bytes: 4828
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int N;
	string S;
	cin >> N >> S;

	vector<int> bv( N );
	vector<int> wv( N );
	int w = 0;
	int b = 0;
	for( int i = 0; i < N; i++ ) {
		bv[i] = b;
		if( S[i] == '#' ) b++;
	}
	for( int i = N - 1; i >= 0; i-- ) {
		wv[i] = w;
		if( S[i] == '.' ) w++;
	}
	int ans = N;
	for( int i = 0; i < N; i++ ) {
		ans = min( ans, bv[i] + wv[i] );
	}

	cout << ans << endl;
}


Measured memory_bytes: 5180