akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <array>
#include <map>
#include <algorithm>

class Dice {
    const std::array<char,4> dirs{ {'N', 'E', 'S', 'W'} };
    const std::map<char,int> index{ {dirs[0],1}, {dirs[1],2}, {dirs[2],3}, {dirs[3],4} };
    /* order: bottom, north, east, south, west, top */
    std::array<int,6> faces{{6, 5, 3, 2, 4, 1}};
    std::array<int,6> nums{{1, 2, 3, 4, 5, 6}};
    int& bottom{faces[0]}; int& north{faces[1]}; int& east{faces[2]};
    int& south {faces[3]}; int& west {faces[4]}; int& top {faces[5]};
public:
    Dice(){};
    Dice(std::array<int,6> d) { Dice(); nums = d; }
    void rotate(char c);
    void roll_tb_axis_clockward(void);
    int get_top(void);
    void set_top(int n);
    int get_east(void);
    int get_south(void);
    ~Dice(){}
};
void Dice::rotate(char c) {
    if(std::find(dirs.begin(), dirs.end(), c) == dirs.end()) return;
    const int i{index.at(c)}, j{(i+5)%4+1};
    const int prev{bottom};
    bottom = faces[i]; faces[i] = top;
    top = faces[j];    faces[j] = prev;
}
void Dice::roll_tb_axis_clockward(void) {
    const int prev{north};
    north = west; west = south;
    south = east; east = prev;
}
int Dice::get_top(void) {
    return nums[top-1];
}
void Dice::set_top(int n) {
    int face_index{};
    for(face_index=0; face_index<6; face_index++) {
        if(nums[faces[face_index]-1] == n) break;
    }
    if(face_index>=6) return;
    const std::array<std::string,6> rotates{ {"NN", "S", "W", "N", "E", ""} };
    for(auto c : rotates[face_index]) {
        rotate(c);
    }
}
int Dice::get_east(void) {
    return nums[east-1];
}
int Dice::get_south(void) {
    return nums[south-1];
}

int main() {
    std::array<int,6> faces;
    for(auto& x : faces) { std::cin >> x; }
    Dice dice{faces};
    int q{};
    std::cin >> q;
    for(auto i=0; i<q; i++) {
        int top_num{}, south_num{};
        std::cin >> top_num >> south_num;
        dice.set_top(top_num);
        for(auto j=0; j<4; j++) {
            if(dice.get_south() == south_num) break;
            dice.roll_tb_axis_clockward();
        }
        std::cout << dice.get_east() << std::endl;
    }
}



Measured memory_bytes: 3232
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int x, y;
  x = max(a-c, c-a);
  y = max(b-d, d-b);
  if (x == 0 || y == 0) {
    printf("0\n");
    return 0;
  }
  int g = gcd(x, y);

  ll ans = x/g + y/g - 1;
  ans *= g;
  printf("%lld\n", ans);

  return 0;
}


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

using namespace std;

int N,a[100001],b[100001],c[100001],hari[100001][4];
bool acho,bcho,ccho;
int main()
{
    cin>>N;

    for(int i = 1; i<=N; i++){
        cin>>a[i]>>b[i]>>c[i];
    }

    for(int i = 1; i<=N; i++){
        for(int j = 1; j<=3; j++){
            //kalo i nya 1, pilih maksimal dari ai,bi,ci

            if(i == 1){
                if(j == 1){
                    hari[i][j] = a[i];
                }else if(j == 2){
                    hari[i][j] = b[i];
                } else {
                    hari[i][j] = c[i];
                }
            } else {
                for(int k = 1; k<=3; k++){
                    if(j == k){
                        continue;
                    }
                    if(j == 1){
                        hari[i][j] = max(hari[i][j],hari[i-1][k]+a[i]);
                    } else if(j == 2){
                        hari[i][j] = max(hari[i][j],hari[i-1][k]+b[i]);
                    } else if(j == 3){
                        hari[i][j] = max(hari[i][j],hari[i-1][k]+c[i]);
                    }
                }
            }
        }
    }


    int ret;
    ret = max(ret,hari[N][1]);
    ret = max(ret,hari[N][2]);
    ret = max(ret,hari[N][3]);

    cout<<ret<<endl;
    return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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

ll N;
vector<ll> Av;
ll B;

ll i, j, k, ans;


int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        ll a;
        scanf("%lld", &a);
        Av.push_back(a);
        B ^= a;
    }
    
    fornum(i,0,N){
        Av[i] &= ~B;
    }

    j = 0;
    for (i = 59; i >= 0;i--)
    {
        
        fornum(k,j,N){
            if(Av[k]&(1ll<<i))
                break;
        }
        if(k==N)
            continue;
        if(j<k){
            Av[j] ^= Av[k];
        }
        fornum(k, j+1, N){
            ll a = Av[j] ^ Av[k];
            Av[k] = min(Av[k], a);
        }
        j++;
    }
    fornum(i,0,N){
        ll a = ans ^ Av[i];
        ans = max(a, ans);
    }
    printf("%lld", ans*2 + B);

    return 0;
}

Measured memory_bytes: 1400
S = input()

d = set(['A', 'T', 'C', 'G'])
len_ = 0
ans = 0
for s in S:
    if s in d:
        len_ += 1
    else:
        # この部分書き換える
        # if len_ > ans:
        #     ans = len_
        ans = max(len_, ans)
        len_ = 0
ans = max(len_, ans)
print(ans)


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] =  Integer.parseInt(sc.next());
            }
        }

        double diff = 0;
        double sqrtDist = 0;
        double dist = 0;
        boolean flg = false;
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                dist = 0;
                for (int k = 0; k < d; k++){
                    diff = x[i][k] - x[j][k];
                    dist += diff * diff;
                }

                sqrtDist = (int)Math.sqrt(dist) + 1;
                for (int k = 0; k < sqrtDist; k++) {
                    if (k * k == dist) {
                        count++;
                        break;
                    }
                }
            }
        }

        System.out.println(count);
    }
}

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

#include <algorithm>

int main() {
	while (1) {
		int n;
		cin >> n;
		if (n==0) break;
		char conv[65535];
		for (int i=0; i<65535; i++) {
			conv[i] = -1;
		}
		for (int i=0; i<n; i++) {
			char c1, c2;
			cin >> c1 >> c2;
			conv[c1] = c2;
		}
		int m;
		cin >> m;
		for (int i=0; i<m; i++) {
			char c1;
			cin >> c1;
			if (conv[c1] >= 0) {
				cout << conv[c1];
			} else {
				cout << c1;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1000000007;
main(){
    int cmin[26],N;
    for(int i = 0;i < 26;i++){
        cmin[i] = INF;
    }
    cin >> N;
    for(int i = 0;i < N;i++){
        string s;
        cin >> s;
        int cnt[26] = {};
        for(char c:s){
            cnt[c-'a']++;
        }
        for(int j = 0;j < 26;j++){
            cmin[j] = min(cmin[j],cnt[j]);
        }
    }
    string ans;
    for(int i = 0;i < 26;i++){
        ans += string(cmin[i],i+'a');
    }
    cout << ans << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<int>v(N);
  for(int i = 0; i < N; i++)cin >> v.at(i);
  int k = 0;
  int count = 0;
  for(int i = 0; i < N; i++){
    if(i == N-1){
      count = -1;
    }
    else{
    k = v.at(k) - 1;
    count++;
    if(k == 1)break;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 768
k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

A = sorted(a, reverse=True)[:k[3]]
B = sorted(b, reverse=True)[:k[3]]
C = sorted(c, reverse=True)[:k[3]]

ab = sorted(list(ax+bx for ax in A for bx in B), reverse=True)[:k[3]]
abc = sorted(list(aby+cy for aby in ab for cy in C), reverse=True)[:k[3]]
for i in abc: print(i)


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

int n,k,m;
string s;

int main() {
  cin >> s;
  int cnt=0;
  for(auto c:s)if(c=='1') cnt++;
  cout << min(cnt,(int)s.size()-cnt)*2 << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define REP(i,x,y) for(ll i=x; i<=y; i++)
#define BIT(t) ((long long 1) << t)
#define PER(i,y,x) for(ll i=y; i>=x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define SIZE(v) ll(v.size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
typedef long long ll;

// int main(){
//         ll n;
//         cin >> n;
//         vll r(n), c(n);
//         REP(i,0,n-1){
//                 cin >> r[i] >> c[i];
//         }
//         vvll dp(110, vll(110, 1e9));
//         REP(i,0,n-1){
//                 dp[i][i] = 0;
//         }
//         REP(i,1,n-1){
//                 for(ll j = 0;j+i < n;j++){
//                         ll k = i+j;
//                         ll tmp = 1e9;
//                         REP(l,j,k-1){
//                                 tmp = min(tmp, dp[j][l] + dp[l+1][k] + r[j]*c[l]*c[k]);
//                         }
//                         dp[j][k] = tmp;
//                 }
//         }
//         cout << dp[0][n-1] << endl;
// }

bool f(vll& v){
        ll ttl = 0;
        for(auto x:v){
                ttl += x;
        }
        if(ttl % 2){
                return false;
        }
        ttl /= 2;
        bitset<8000> b = 1;
        REP(i,0,v.size() - 1){
                b = b | (b << v[i]);
        }
        if(b[ttl]){
                return true;
        }else{
                return false;
        }
}

int main(){
        string s;
        cin >> s;
        s+='T';
        ll x,y;
        cin >> x >> y;
        vll numf[2];
        bool flag = 0;
        ll cur = 0;
        ll cnt = 0;
        REP(i,0,s.size()-1){
                
                if(s[i] == 'T'){
                        if(!flag){
                                x -= cnt;
                        }else{
                                numf[cur].push_back(cnt);
                        }
                        cnt = 0;
                        cur = (cur + 1) % 2;
                        flag = 1;
                }else{
                        cnt++;
                }
        }
        numf[0].push_back(abs(x));
        numf[1].push_back(abs(y));
        if(f(numf[0]) && f(numf[1])){
                cout << "Yes" << endl;
        }else{
                cout << "No" << endl;
        }
        for(auto x:numf[0]){
                //cout << x << " ";
        }
        for(auto x:numf[1]){
                //cout << x << " ";
        }
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

const int MAX_N = 100000;

int prime[MAX_N];
bool is_prime[MAX_N + 1];

void eratos(int n) {
    int p = 0;
    for (int i = 0; i <= n; ++i) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; ++i) {
        if (is_prime[i]) {
            prime[p++] = i;
            for (int j = 2*i; j <= n; j += i) is_prime[j] = false;
        }
    }
}

ll dp[100001]; // i 以下の似た数の個数

int main() {
    eratos(1e5+1);
    int q;
    cin >> q;

    for (int i = 1; i <= 100000; ++i) {
        if (is_prime[i] and is_prime[(i+1)/2]) dp[i] = dp[i-1] + 1;
        else dp[i] = dp[i-1];
    }

    rep(i, q) {
        int l, r;
        cin >> l >> r;
        cout << dp[r] - dp[l-1] << endl;
    }
}


Measured memory_bytes: 1536
while True:
  try:
    a = map(int, raw_input().split())
    b = map(int, raw_input().split())
  except:
    break
  ab = zip(a, b)
  hit = 0
  blow = 0
  for xa, xb in ab:
    if xa == xb:
      hit  += 1
    elif xa in b:
      blow += 1
  print('%d %d' % (hit, blow))

Measured memory_bytes: 4216
#include<bits/stdc++.h>
#define ll long long
#define int long long int
#define MOD 1000000007
#define mkp make_pair
#define maxn 100005
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define  vi vector<int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in cin>>
#define out cout<<
using namespace std;
const int infi=1e15+7;
void printVector(vector<int> v){
    for(int i=0;i<(int)v.size();i++)
        cout<<v[i]<<" ";
    out endl;
}

void printArray(int arr[],int n)
{
   for(int i=0;i<n;i++)cout<<arr[i]<<' ';
cout<<endl;
}
 set<pair<int,int>> primeset;
 vi prime_number;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
        for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
           primeset.insert(mkp(p,1));
}
ll modExp(ll base, ll power) {
    if (power == 0) {
        return 1;
    } else {
        ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
        if (power % 2 == 1) cur = cur * base;
        cur = cur % MOD;
        return cur;
    }
}
//for making unordered_map with pair
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
int32_t main()
{
fastio;
    int a,b,c;
    cin>>a>>b>>c;
    int k;in k;
    while(a>=b){
        b*=2;
        k--;
    }
    while(b>=c){
        c*=2;
        k--;
    }
    if(k>=0) out "Yes";
    else out "No";
return 0;
}

/*
google kick start
  cout << "Case #" << tt << ": "<<ans<<endl;
*/


Measured memory_bytes: 3612
public class Main {

  private static void solve() {
    int n = ni();
    char[] s = ns();

    for (int i = 0; i < s.length; i++) {
      int d = s[i] - 'A';

      d = (d + n) % 26;

      s[i] = (char) (d + 'A');
    }

    System.out.println(s);

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 22612
#[allow(unused_macros)]
macro_rules! invec {
    ( $t:ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s.trim().split_whitespace().map(|s| s.parse::<$t>().unwrap()).collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }}
}

#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($(
            {
                 splits.next().unwrap().parse::<$t>().unwrap()
            },
        )*)
    }}
}

struct UnionFindTree {
    v: Vec<usize>,
    sizes: Vec<u64>
}

impl UnionFindTree {
    fn new(n: usize) -> UnionFindTree {
        UnionFindTree {
            v: (0..n).collect(),
            sizes: vec![1; n]
        }
    }

    fn find(&mut self, i: usize) -> usize {
        if self.v[i] == i {
            i
        } else {
            let j = self.v[i];
            self.v[i] = self.find(j);
            self.v[i]
        }
    }

    fn unite(mut self, n: usize, m: usize) -> UnionFindTree {
        let n_root = self.find(n);
        let m_root = self.find(m);
        if n_root != m_root {
            self.v[n_root] = self.v[m_root];
            self.sizes[n_root] += self.sizes[m_root];
            self.sizes[m_root] = self.sizes[n_root];
        }
        self
    }

    fn size(&mut self, i: usize) -> u64 {
        let i_root = self.find(i);
        self.sizes[i_root] 
    }
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (n,m) = input!(usize, usize);

    let mut inputs = Vec::<(usize, usize)>::with_capacity(m);
    let mut outputs = Vec::<u64>::with_capacity(m);
    let mut uft = UnionFindTree::new(n);

    for i in 0..m {
        let bribge = input!(usize, usize);
        inputs.push(bribge);
    }

    inputs.reverse();

    let mut ans = (n * (n - 1) / 2) as u64;
    for tpl in inputs {
        outputs.push(ans);
        if uft.find(tpl.0 - 1) != uft.find(tpl.1 - 1) {
            ans -= uft.size(tpl.0 - 1) * uft.size(tpl.1 - 1);
            uft = uft.unite(tpl.0 - 1, tpl.1 - 1);
        }
    }

    outputs.reverse();

    for out in outputs {
        println!("{}", out);
    }

}

fn main() {
    solve();
}


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

int main() {
  int N; cin >> N;
  vector<int> C(N+1, 0);
  for (int i = 0; i < N-1; i++) {
    int a; cin >> a;
    C.at(a)++;
  }
  for (int i = 1; i <= N; i++) cout << C.at(i) << endl;
}

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

struct UnionFind {
	// 親の番号を格納する。親だった場合はその集合のサイズ
	vector<int> Parent;

	// 作るときはParentの値を全て-1にする
	//　こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	// Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	// 自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)]; //親を取ってきたい
	}

	// AとBを結合する
	bool connect(int A, int B) {
		// AとBを直接つなぐのではなく、root(A)にroot(B)を結合する
		A = root(A);
		B = root(B);
		if (A == B) {
			// 既に結合しているなら結合しない。
			return false;
		}

		// 大きい方(A)に小さいほう(B)を結合したい。
		// 大小が逆ならひっくり返す。
		if (size(A) < size(B)) swap(A, B);

		// Aのサイズを更新する
		Parent[A] += Parent[B];
		// Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

int main() {
	long long N, M;
	cin >> N >> M;
	vector<int> A(M), B(M);
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i];
		A[i]--; B[i]--;
	}

	vector<long long> ans(M);
	ans[M - 1] = N * (N - 1) / 2;

	UnionFind Uni(N);

	for (int i = M - 1; i >= 1; i--) {
		if (Uni.root(A[i]) != Uni.root(B[i])) {
			ans[i - 1] = ans[i] -(long long) Uni.size(A[i])*Uni.size(B[i]);
			Uni.connect(A[i], B[i]);
		}
		else ans[i - 1] = ans[i];
	}

	for (int i = 0; i < M; i++) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 3328
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,x,y,z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;
public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
//typedef modint<MOD> m;
#pragma endregion

map<int, int> m;
int main() {
  int num;
  bool flag = true;
  cin >> N;
  rep(i, N){
    cin >> num;
    if(m.count(num) == 1){
      flag = false;
    }
    m[num] = 1;
  }
  if(flag) cout << "YES";
  else cout << "NO";
}



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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int res = 0;
    if (k < a) res = k;
    else{
        k -= a;
        if (k < b) res = a;
        else{
            k -= b;
            res = a - k;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>

int Partition(int p, int r);
void QuickSort(int p, int r);

int Anum[1000000];
char Amark[1000000];
int Anum0id[1000000];
char Amark0id[1000000];
void aaaaa(int);

int n, a=10;

int main(){
  int isStable = -1;
  int i, p, j;
  char tmp[10];

  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%s %d", tmp, &Anum[i]);
    Amark[i]=tmp[0];
    Anum0id[i]=Anum[i];
    Amark0id[i]=tmp[0];
  }
  QuickSort(0, n-1);
  for(i=1; i<n; i++){
    if(Anum[i-1]==Anum[i]){
      for(j=0; j<n; j++){
	if(Amark0id[j]==Amark[i] && Anum0id[j]==Anum[i]){
	  isStable=0;
	  break;
	}
	else if(Amark0id[j]==Amark[i-1] && Anum0id[j]==Anum[i-1]){
	  break;
	}
      }
    }
    if(isStable==0)break;
  }
  if(isStable==-1)isStable=1;
  if(isStable)printf("Stable\n");
  else printf("Not stable\n");

  for(i=0; i<n; i++){
    printf("%c %d\n", Amark[i], Anum[i]);
  }
  aaaaa(a);
  return 0;
}

void aaaaa(int a){
  int i, count=0;
  for(i=0; i<a; i++){
    count++;
  }
}
int Partition(int p, int r){
  int x, i, j, tmp;
  x=Anum[r];
  i=p-1;
  for(j=p; j<=r-1; j++){
    if(Anum[j]<=x){
      i++;
      tmp=Anum[i];
      Anum[i]=Anum[j];
      Anum[j]=tmp;
      tmp=Amark[i];
      Amark[i]=Amark[j];
      Amark[j]=tmp;
    }
  }
  tmp=Anum[i+1];
  Anum[i+1]=Anum[r];
  Anum[r]=tmp;
  tmp=Amark[i+1];
  Amark[i+1]=Amark[r];
  Amark[r]=tmp;
  return i+1;
}

void QuickSort(int p, int r){
  int q;
  if(p<r){
    q=Partition(p, r);
    QuickSort(p, q-1);
    QuickSort(q+1, r);
  }
}



Measured memory_bytes: 2720
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const ll inf=1e18;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a,b;
    cin>>a>>b;
    ll c=(a*b)/__gcd(a,b);
    cout<<c<<endl;
}


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

int main(){
    std::string S;
    std::cin >> S;
    int Apos = -1, Zpos = -1;
    for(int i = 0; i < S.size(); i++){
        if(Apos == -1 && S[i] == 'A') Apos = i;
        if(S[i] == 'Z') Zpos = i;
    }

    std::cout << Zpos - Apos + 1 << std::endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
const int MX=100005;

int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(false);
   int n;
   cin >> n;
   vector<ll> cnt(MX);
   for (int i=0;i<n;++i){
       int a;
       cin >> a;
       cnt[a]++;
   }
   ll tot=0;
   for (int i=0;i<MX;++i){
       tot+=i*cnt[i];
   }
   int q;
   cin >> q;
   for (int i=0;i<q;++i){
       int b,c;
       cin >> b >> c;
       tot-=b*cnt[b];
       tot-=c*cnt[c];
       cnt[c]+=cnt[b];
       cnt[b]=0;
       tot+=b*cnt[b];
       tot+=c*cnt[c];
       cout << tot << endl;
   }
   return 0;
}


Measured memory_bytes: 3996
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

ll n,m,a,b,c,x,y,aa[100010],ba[100010];
bool r,br,ar;
string s;
char ca,cb;


int main(){
    cin>>n;
    a=0;b=0;
    for(int i=0;i<n;i++)cin>>aa[i];
    sort(aa,aa+n,greater<int>());
    for(int i=0;i<n;i++){
        if(i%2)b+=aa[i];
        else a+=aa[i];
    }
    printf("%d\n",a-b);
}

Measured memory_bytes: 256
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = InputNum();
            var a = InputNumList();
            var b = InputNumList();
            var c = InputNumList();

            int ans = 0;
            int tmp = -1;
            for (int i = 0; i < n; i++)
            {
                ans += b[a[i] - 1];
                if (a[i] - tmp == 1)
                {
                    ans += c[tmp - 1];
                }
                tmp = a[i];
            }
            WriteLine(ans);
        }

        static int InputNum()
        {
            return int.Parse(ReadLine());
        }
        static List<int> InputNumList()
        {
            return ReadLine().Split(' ').Select(int.Parse).ToList();
        }
    }
}

Measured memory_bytes: 13268
#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(ll, N);
    IN(ll, T);
    AIN(ll, A, N);
    vi acc(N + 1);
    for (ll i = N - 1; i >= 0; --i)
    {
        acc[i] = max(acc[i + 1], A[i]);
    }
    ll d = 0;
    REP(i, N - 1)
    {
        CH(max, d, acc[i + 1] - A[i]);
    }
    ll ans = 0;
    REP(i, N - 1)
    {
        if (acc[i + 1] - A[i] == d)
        {
            ++ans;
        }
    }
    OUT(ans);
}

Measured memory_bytes: 4824
#include <bits/stdc++.h>
using namespace std;
#pragma region Macros
typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};
#define LOCAL

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

const int MAX_A=1e5+10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> A(N); cin >> A;
    ll sum=0;
    vector<int> cnt(MAX_A,0);
    for (int i=0;i<N;++i){
        sum+=A[i];
        ++cnt[A[i]];
    }
    int Q; cin >> Q;
    for (;Q--;){
        int B,C; cin >> B >> C;
        int n=cnt[B];
        sum+=(C-B)*n; cnt[B]=0; cnt[C]+=n;
        cout << sum << '\n';
    }
}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string st,str;
    while(cin>>st>>str){
        int cnt=0;
        for(int i=0;i<st.length();i++){
            if(st[i]==str[i])cnt++;
        }
        cout<<cnt<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) throws java.io.IOException{
        Scanner scan = new Scanner(System.in);
       //Queue<Pair> fifo = new LinkedList<Pair>();
        int rank [] ={0,0,0,0,0,0};
      //  ArrayList <Double> mou =new ArrayList <Double>();
        int c =scan.nextInt();
        while (c!=0){
        	double n=scan.nextDouble();
        if(n>=185.0)rank[5]++;
        else if(n>=180.0)rank[4]++;
        else if(n>=175.0)rank[3]++;
        else if(n>=170.0)rank[2]++;
        else if(n>=165.0)rank[1]++;
        else rank[0]++;
        
        
  c--;
        		}
        for(int i=0;i<6;i++){
        	if(rank[i]==0)System.out.println(i+1+":");
        	else {
        		String str="";
        		for(int j=0;j<rank[i];j++)
        			str+="*";
        			
        		System.out.println(i+1+":"+str);
        	}
        	}
        	}
        	
     
        }
      

Measured memory_bytes: 12000
#include <stdio.h>

int main(void)
{

	int n;
	int k;
	int x[1000] = {0};
	int y[1000] = {0};

	int i;
	int a,b;

	scanf("%d",&n);
	scanf("%d",&k);

	for( i = 0 ; i < k ; i++)
	{
		scanf("%d",&x[i]);
		scanf("%d",&y[i]);
	}

	for( i = 0 ; i < k ; i++)
	{
		a = x[i];
		b = y[i];

		if( n - a + 1 < a)
			a = n - a + 1;

		if( n - b + 1 < b)
			b = n - b + 1;

		if( a > b)
			printf("%d\n", ((b+2) % 3) + 1 );
		else
			printf("%d\n", ((a+2) % 3) + 1 );

	}

	return 0;
}

Measured memory_bytes: 0
using System;

namespace ABC155A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] word = Console.ReadLine().Split(' ');
            int a = int.Parse(word[0]);
            int h = int.Parse(word[1]);
            int n = int.Parse(word[2]);

            if (a == h &&( h != n || n != a))
                Console.WriteLine("Yes"); 
           
            else if (a == n && (a != h || h != n))
                Console.WriteLine("Yes");
            else if (n == h && (n != a || a != h))
                Console.WriteLine("Yes");
           
            else Console.WriteLine("No");

        }
    }
}


Measured memory_bytes: 27384
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define rep0(i,r) for (int i=0,i##end=r;i<i##end;++i)
#define pr pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pb push_back
using namespace std;
const int N=1e3+3;
const int w[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
int ans[N][N],a[N][N];
int main(){
    int n; cin>>n;
    rep(i,1,n) rep(j,1,n) ans[i][j]=min(min(i,n-i+1),min(j,n-j+1))-1,a[i][j]=1;
    int s=0;
    rep(i,1,n*n){
        int p; scanf("%d",&p); int x=(p+n-1)/n,y=p%n==0?n:p%n;
        s+=ans[x][y]; a[x][y]=0;
        rep0(i,4){
            int x0=x+w[i][0],y0=y+w[i][1];
            ans[x][y]=min(ans[x][y],ans[x0][y0]+a[x0][y0]);
        }
        queue< pair<int,int> > q; q.push(mp(x,y));
        while (!q.empty()){
            int x=q.front().fi,y=q.front().se; q.pop();
            rep0(i,4){
                int x0=x+w[i][0],y0=y+w[i][1];
                if (ans[x][y]+a[x][y]<ans[x0][y0])
                    ans[x0][y0]=ans[x][y]+a[x][y],q.push(mp(x0,y0));
            }
        }
    }
    cout<<s<<endl;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n ;
  int total = 0;
  cin >> n;
  vector<int> v(n);
  
  rep(i,n){
    cin >> v.at(i);
    total += v.at(i) ;
  }
  int m ;
  cin >> m;
  
  int ans = total ;
  rep(i,m){
    int p , c ;
    cin >> p >> c ;
    ans = total - (v.at(p-1) - c) ;
    cout << ans <<endl;
  }
    
  
    

}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
const int N = 1000000;
const int mod = 1000000007;
const int INF = 1 << 30;
#define rep(i,n) for(int i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
char m[100][100];
int a, b;//. #
int main() {
	rep(i, 100)rep(j, 50) { m[i][j] = '#'; m[i][j+50] = '.'; }
	cin >> a >> b;
	rep(i, a-1) {
		m[i/24*2+1][(1 + i * 2) % 48] = '.';
	}
	rep(i, b - 1) {
		m[i / 24*2+1][(1 + i * 2) % 48 + 50] = '#';
	}
	cout << 100 << " " << 100 << endl;
	rep(i, 100) {
		rep(j, 100)cout << m[i][j];
		cout << "" << endl;
	}
	return 0;
}


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

class Student {
	
public:
	//自分を含める
	int classstudent;
	int mynumber;

	Student();

	bool operator<(const Student& another)const {
		return classstudent > another.classstudent;
	}
};

Student::Student() {
	classstudent = 0;
	mynumber = 0;
}

Student InputData(int student, int number) {
	
	Student stu;

	stu.classstudent = student;
	stu.mynumber = number;

	return stu;
}

int main()
{
	int N;
	cin >> N;
	
	vector<Student> stu;

	for (int i = 1; i <= N; i++) {
		int A;
		cin >> A;

		stu.push_back(InputData(A, i));
	}

	sort(stu.begin(), stu.end());

	while (!stu.empty())
	{
		cout << stu[stu.size() - 1].mynumber << " ";
		stu.pop_back();
	}

	cout << endl;

	return 0;
}



Measured memory_bytes: 1780
#include <stdio.h>

int main()
{
    unsigned long int a,b,sum,i,count;

    while(scanf("%lu %lu",&a,&b)!=EOF)
    {
        sum=a+b;
        count=0;
        for(i=0; sum!=0; i++)
        {
            sum=sum/10;
            count++;
        }
        printf("%d\n",count);
    }

    return 0;
}

Measured memory_bytes: 604
from collections import Counter
import sys

sys.setrecursionlimit(20000)


def _ia(): return map(int, sys.stdin.readline().strip().split())


class UnionFind:
    def __init__(self, n):
        self._par = [-1]*(n+1)
        self._rnk = [0]*(n+1)

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

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        elif self._rnk[x] > self._rnk[y]:
            self._par[x] += self._par[y]
            self._par[y] = x
        else:
            self._par[y] += self._par[x]
            self._par[x] = y
            if self._rnk[x] == self._rnk[y]:
                self._rnk[y] += 1

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


def main():
    n, m = _ia()
    uf = UnionFind(n)
    for _ in range(m):
        a, b = map(lambda x: x-1, _ia())
        uf.unite(a, b)
    c = Counter([uf.root(i) for i in range(n)])
    return max(c.values())


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 116708
N,A,B,C=map(int,input().split())
L = []
for i in range(N):
    L.append(int(input()))

def dfs(n,a,b,c):
    if n == N:
        if min(a,b,c)>0:
            return abs(A-a)+abs(B-b)+abs(C-c)-30
        else:
            return 10000
    root1=dfs(n+1,a+L[n],b,c)+10
    root2=dfs(n+1,a,b+L[n],c)+10
    root3=dfs(n+1,a,b,c+L[n])+10
    root4=dfs(n+1,a,b,c)
    return min(root1,root2,root3,root4)
    
print(dfs(0,0,0,0))



Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <algorithm>
#include <time.h>
#include <stdlib.h>

using namespace std;

int main (void)
{
	int a[2000],co,d,e;

	co = 3000;
	for (int i = 0; i < 3; i++)
	{
		cin >> a[i];

		if (a[i] < co)
		{
			co = 0;
			co = a[i];
		}
	}
	cin >> d >> e;

	if (d <= e)
	{
		cout << co + d - 50 << endl;
	}
	else if (d > e)
	{
		cout << co + e - 50 << endl;
	}
}

Measured memory_bytes: 3092
n = int(input())
p = [0]*(n+1)
m = [[None for _ in range(n+1)] for _ in range(n+1)]
for i in range(1,n+1):
    p[i-1],p[i] = map(int,input().split())
    m[i][i] = 0
for l in range(2,n+1):
    for i in range(1,n-l+2):
        j = i+l-1
        m[i][j] = float("inf")
        for k in range(i,j):
            m[i][j] = min(m[i][j],m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j])
print(m[1][n])


Measured memory_bytes: 5712
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;

vector<int> fac(MX);
vector<int> ifac(MX);

long long fpow(long long a,long long n){
  long long ret=1;
  if(n==1) return a;
  if(n%2==0) {
      ret = fpow(a*a%mod, n/2) %mod ;
  }else {
      ret = (a%mod)*fpow(a*a%mod, n/2) %mod;
  }
  return ret %mod;
}

int comb(int a, int b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    int tmp = ifac[a-b]* ifac[b] % mod;
    return tmp * fac[a] % mod;
}

int P(int a, int b) {
    int res = comb(a,b);
    res *= fac[b];
    return res % mod;
}

int ans, k;
vector<int> to[100005];
void dfs(int v, int p=-1) {
    for(int u: to[v]) {
        if(u == p) continue;
        dfs(u, v);
    }
    int nk = (p==-1) ? k : k-2;
    int c = (p==-1) ? to[v].size()+1 : to[v].size()-1;
    ans *= P(nk, c);
    ans %= mod;
}

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

    for (size_t i = 0; i < n-1; i++)
    {
        int a,b;
        cin >> a>>b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    fac[0] = 1;
    ifac[0] = 1;
    for(int i = 0; i<MX-1; i++){
        fac[i+1] = fac[i]*(i+1) % mod; // n!(mod M)
        ifac[i+1] = ifac[i]*fpow(i+1,mod-2) % mod; 
    }
    ans = 1;
    dfs(0);
    cout << ans << endl;
    return 0;
}




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

using namespace std;

typedef long long ll;

int main() {
  int N, K;
  cin >> N >> K;
  ll x = N / K;
  if (K % 2 == 1) cout << x * x * x << endl;
  else {
    ll y = 0;
    if (N - K / 2 >= 0) y = (N - K / 2) / K + 1;
    cout << x * x * x + y * y * y << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	vector<vector<int>>vec(2, vector<int>(N));
	rep(i, 0, 2)rep(j, 0, N)cin >> vec[i][j];
	int ans = 0;
	rep(i, 0, N) {
		int k = 0, cnt = 0;
		rep(j, 0, N) {
			cnt += vec[k][j];
			if (i == j) {
				++k;
				cnt += vec[k][j];
			}
		}
		chmax(ans, cnt);
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    while (1) {
        int H,W; cin >> H >> W;
        if (H+W==0) break;
        vector<vector<int>> S(H, vector<int>(W));
        rep(i,H) rep(j,W) cin >> S[i][j];

        int ans = 0;
        rep(i,H) {
            rep(j,W) {
                for (int k = i+2; k < H; ++k) {
                    for (int l = j+2; l < W; ++l) {
                        int wall = 1e9;
                        for (int m = i; m <= k; ++m) {
                            chmin(wall,S[m][j]);
                            chmin(wall,S[m][l]);
                        }
                        for (int m = j; m <= l; ++m) {
                            chmin(wall,S[i][m]);
                            chmin(wall,S[k][m]);
                        }
                        bool ok = true;
                        int val = 0;
                        for (int m = i+1; m < k; ++m) {
                            for (int n = j+1; n < l; ++n) {
                                if (S[m][n] >= wall) ok = false;
                                val += wall - S[m][n];
                            }
                        }
                        if (ok) chmax(ans,val);
                    }
                }
            }
        }

        cout << ans << ln;
    }
}



Measured memory_bytes: 3140