akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int N, M, Q; 
std::vector<ll> a, b, c, d;

ll dfs(int k, std::vector<int> A) {
  if ( k == N ) {
    ll rtn = 0;
    rep(i,Q) if ( A[b[i]] - A[a[i]] == c[i] ) rtn += d[i];
    return rtn;
  }
  
  ll rtn = -1e18;
  for(int x=A[k-1]; x<=M; x++) {
    auto B = A;
    B.push_back(x);
    rtn = std::max(rtn, dfs(k+1, B));
  }
  return rtn;
}

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  std::cin >> N >> M >> Q;
  a.resize(Q);  b.resize(Q);  c.resize(Q);  d.resize(Q);
  rep(i,Q) {
    std::cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--, b[i]--;
  }

  std::vector<int> A; A.push_back(1);
  std::cout << dfs(1,A) << std::endl;
  return 0;
}



Measured memory_bytes: 3660
#include <iostream>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>
#include <vector>
#define ll long long
using namespace std;
const int N=1e6+10;
int n,w;
double sum=0;
double a[N],b[N];

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
   cin>>a[i]>>b[i];
   for(int j=0;j<i;j++)
      sum+=sqrt((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]));
   }
   sum=sum*2/n;
   printf("%.6lf",sum);




return 0;
}




Measured memory_bytes: 2304
import java.util.Scanner;

public class Main {
	private static Scanner sc;
	public static void main(String[] args){
		sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		for(int i=0;i<n;i++){
			a[i]=sc.nextInt();
		}
		int ans=bubbleSort(a,n);
		write(a,n);
		System.out.println(ans);
	}
	static void write(int[] a,int n){
		for(int i=0;i<n-1;i++){
			System.out.print(a[i]+" ");
		}
		System.out.println(a[n-1]);
	}
	static int bubbleSort(int[] a, int n){
		boolean flag=true;
		int i=0;
		int count=0;
		while(flag){
			flag=false;
			for(int j=n-1;j>i;j--){
				if(a[j]<a[j-1]){
					int temp=a[j];
					a[j]=a[j-1];
					a[j-1]=temp;
					flag=true;
					count++;
				}
			}
			i++;
		}
		return count;
	}

}

Measured memory_bytes: 26556
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctype.h>
using namespace std;
#define dump(a) cout << (a) << '\n';
typedef long long Int;
Int mod = 1e9+7;
Int MOD = 998244353;

int main() {
    ios::sync_with_stdio(false);
    Int n, a, b;
    cin >> n >> a >> b;
    Int f, s, t;
    f = s = t = 0;
    for (Int i = 0; i < n; i++) {
        Int p;
        cin >> p;
        if (p <= a) f++;
        else if (a < p && p <= b) s++;
        else t++;
    }
    dump(min(f, min(s, t)));
    return 0;  
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] ab = new int[n][2];

		for (int i = 0; i < n; i++) {
			ab[i][0] = sc.nextInt();
			ab[i][1] = sc.nextInt();
		}
		//a(金額）の少ない順でソート
		Arrays.sort(ab, (a, b) -> Integer.compare(a[0], b[0]));

		long price = 0;
		long amount = 0;
		for (int i = 0; i < n; i++) {
			if (amount + ab[i][1] <= m) {
				price += (long)ab[i][0] * ab[i][1];
				amount += ab[i][1];
			} else {
				price += ab[i][0] * (m - amount);
				break;
			}
			//			System.out.println(price);
		}

		System.out.println(price);

		//		for (int i = 0; i < n; i++) {
		//			System.out.print(ab[i][0] + ", ");
		//			System.out.println(ab[i][1]);
		//		}

		sc.close();
	}
}

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

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

  sort(a, a + n);

  ll s[n] = {a[0]};
  rep (i, n - 1) s[i + 1] = s[i] + a[i + 1];

  int ans = 1;
  for (int i = n - 2; i >= 0; i--) {
    if (s[i] * 2 >= a[i + 1]) {
      ans++;
      continue;
    }
    break;
  }

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

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, sum, mins = 1e15;
	cin >> nn;
	vector<int64> vv(nn);
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> vv[ii];
	}
	for(int64 pp = 0;pp < 100;pp++)
	{
		sum = 0;
		for(int64 ii = 0;ii < nn;ii++)
		{
			sum += (vv[ii] - pp) * (vv[ii] - pp);
		}
		mins = min(sum, mins);
	}
	cout << mins;
	return 0;
}


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

int main(){
    int A, B;
    cin >> A >> B;

    int res=0;
    string S="", R="";
    for(int i=A; i<=B; i++){
        S = to_string(i);
        R = S;
        reverse(R.begin(), R.end());
        if(S == R)
            res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
int main(void){
    int W, H, x, y, r;
    scanf("%d", &W);
    scanf("%d", &H);
    scanf("%d", &x);
    scanf("%d", &y);
    scanf("%d", &r);
    if(x-r>=0&&x+r<=W&&y-r>=0&&y+r<=H)
    puts("Yes");
    else
    puts("No");
    return 0;
}


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

using lint = long long;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define repu(i, a, b, s) for(int i = int(a); i < int(b); i += int(s))
#define repd(i, a, b, s) for(int i = int(a); i > int(b); i += int(s))
#define endl "\n"
constexpr lint INF = 2e18;
constexpr lint MOD = 1e9 + 7;

lint test[128 * 1000000];
lint grid[10000][10000];
lint dp[3001][3001][4];

void solve() {
    lint R, C, K;
    cin >> R >> C >> K;

    rep(i, R) {
        rep(j, C) { grid[i][j] = -1; }
    }

    rep(i, K) {
        lint r, c, v;
        cin >> r >> c >> v;
        r--;
        c--;
        grid[r][c] = v;
    }

    rep(y, R) {
        rep(x, C) {
            rep(i, 4) { dp[y][x][i] = 0; }
        }
    }

    if(grid[0][0] != -1)
        dp[0][0][1] = grid[0][0];

    rep(y, R) {
        rep(x, C) {

            // 選ばない
            if(0 <= y - 1) {
                rep(i, 4) { dp[y][x][0] = max(dp[y][x][0], dp[y - 1][x][i]); }
            }
            if(0 <= x - 1) {
                rep(i, 4) { dp[y][x][i] = max(dp[y][x][i], dp[y][x - 1][i]); }
            }

            // 選ぶ
            if(grid[y][x] != -1) {
                if(0 <= y - 1) {
                    rep(i, 4) {
                        dp[y][x][1] =
                            max(dp[y][x][1], dp[y - 1][x][i] + grid[y][x]);
                    }
                }
            }
            if(0 <= x - 1) {
                repu(i, 1, 4, 1) {
                    dp[y][x][i] =
                        max(dp[y][x][i], dp[y][x - 1][i - 1] + grid[y][x]);
                }
            }
        }
    }

    lint ans = -INF;
    rep(i, 4) { ans = max(ans, dp[R - 1][C - 1][i]); }
    cout << ans << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
    return 0;
}


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

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

int main() {
    int n;cin>>n;
    string s;cin>>s;
    int m = s.size();
    rep(i,m){
        s[i]+=n;
        if(s[i]<'A' || s[i]>'Z')s[i]-=26;
    }
    cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 3584
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static Node[] ns;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		ns = new Node[N];
		for(int i = 0;i < N;i++){
			ns[i] = new Node(i);
		}
		for(int i = 0;i < N-1;i++) {
			int a = sc.nextInt()-1;
			int b = sc.nextInt()-1;
			ns[a].add(ns[b]);
			ns[b].add(ns[a]);
		}
		DFS(ns[0],null);
		for(int i = 0;i < Q;i++) {
			int p = sc.nextInt();
			int x = sc.nextInt();
			ns[p-1].cnt += x;
		}
		sc.close();
		sum(ns[0]);
		StringBuilder sb = new StringBuilder();
		for(Node n : ns) {
			sb.append(" ").append(n.cnt);
		}
		System.out.println(sb.substring(1));
	}

	private static void sum(Node n) {
		if(n.p != null) {
			n.cnt += n.p.cnt;
		}
		for(Node c : n) {
			if(c != n.p) {
				sum(c);
			}
		}
	}


	private static void DFS(Node n, Node p) {
		n.p = p;
		for(Node cc : n) {
			if(cc != p) {
				DFS(cc, n);
			}
		}
	}

	static class Node extends ArrayList<Node>{
		Node p;
		int id;
		int cnt = 0;
		Node(int id){
			this.id = id;
		}
	}
}

Measured memory_bytes: 211208
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;
struct T{
	ll st;
	ll en;
	bool b;
	bool operator<(const T& another)const{
		if(st==another.st) return en<another.en;
		return st<another.st;
	}
};
vector<T> cards[2];
ll n,m,p,q,r;
ll x,y;

const ll INF=0xffffffffff;
ll B=1;
void printv(){
	for(ll i=0;i<cards[!B].size();i++){
		cout<<"cards["<<i+1<<"]={";
		printf("%lld,%lld,",cards[!B][i].st+1,cards[!B][i].en+1);
		cout<<cards[!B][i].b<<"}"<<endl;
	}
	cout<<endl;
}
ll ans;
ll kosu,px,py;
int main()
{
	while(1){
	B=1;
	scanf("%lld",&n);
	if(!n) return 0;
	scanf("%lld%lld%lld%lld",&m,&p,&q,&r);
	p--;
	q--;
	cards[0].clear();
	cards[0].push_back((T){0,r-1,1});
	cards[0].push_back((T){r,n-1,0});
	for(ll i=0;i<m;i++){
		//printv();
		cards[B].clear();
		scanf("%lld%lld",&x,&y);
		x--;
		y--;
		kosu=0;
		px=upper_bound(cards[!B].begin(),cards[!B].end(),(T){x,INF,INF})-cards[!B].begin()-1;
		py=upper_bound(cards[!B].begin(),cards[!B].end(),(T){y,INF,INF})-cards[!B].begin()-1;
		if(cards[!B][py].en>y){
			cards[B].push_back((T){0,cards[!B][py].en-y-1,cards[!B][py].b});
			kosu+=cards[!B][py].en-y;
		}
		for(ll i=py+1;i<cards[!B].size();i++){
			cards[B].push_back((T){kosu,kosu+cards[!B][i].en-cards[!B][i].st,cards[!B][i].b});
			kosu+=cards[!B][i].en-cards[!B][i].st+1;
		}
		if(px!=py){
			if(cards[!B][px].en>x){
				cards[B].push_back((T){kosu,kosu+cards[!B][px].en-x-1,cards[!B][px].b});
				kosu+=cards[!B][px].en-x;
			}
			for(ll i=px+1;i<py;i++){
				cards[B].push_back((T){kosu,kosu+cards[!B][i].en-cards[!B][i].st,cards[!B][i].b});
				kosu+=cards[!B][i].en-cards[!B][i].st+1;
			}
			cards[B].push_back((T){kosu,kosu+y-cards[!B][py].st,cards[!B][py].b});
			kosu+=y-cards[!B][py].st+1;
		}
		else{
			cards[B].push_back((T){kosu,kosu+y-x-1,cards[!B][py].b});
			kosu+=y-x;
		}
		for(ll i=0;i<px;i++){
			cards[B].push_back((T){kosu,kosu+cards[!B][i].en-cards[!B][i].st,cards[!B][i].b});
			kosu+=cards[!B][i].en-cards[!B][i].st+1;
		}
		cards[B].push_back((T){kosu,kosu+x-cards[!B][px].st,cards[!B][px].b});
		kosu+=x-cards[!B][px].st+1;
		B=!B;
	}
	//printv();
	ans=0;
	for(ll i=0;i<cards[!B].size();i++){
		if(!cards[!B][i].b) continue;
		if(q<cards[!B][i].st||cards[!B][i].en<p) continue;
		ans+=min(q,cards[!B][i].en)-max(p,cards[!B][i].st)+1;
	}
	printf("%lld\n",ans);
}}

Measured memory_bytes: 3360
#include<stdio.h>
int main()
{ 
	int n,m,p,j;
	char s[103][103];
	while(scanf("%d%d",&n,&m)!=EOF)
		{
			for(p=1;p<=n;p++)
			scanf("%s",&s[p]);
			for(j=0;j<m+2;j++) 
			printf("#");
			printf("\n");
			for(p=1;p<=n;p++)
			{   
				printf("#%s#\n",s[p]);
			}
			for(j=0;j<m+2;j++) 
			printf("#");
			printf("\n");
		}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[0].size()){ cout << m[i][j] << ","; } cout << endl; }}



signed main(){

    int X; cin >> X;
    if(X == 3 || X == 5 || X == 7) cout << "YES";
    else cout << "NO";
    
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      Dice[] aDices = new Dice[n];

      for ( int i=0; i<n; i++ )
        aDices[i] = new Dice(br.readLine().split(" "));

      String result = "Yes";
      for ( int i=0; i<n-1; i++ ) {
        for ( int j=i+1; j<n; j++ )
        if(!aDices[i].isSame(aDices[j])) continue;
        else { result = "No"; break; }
      }

      System.out.println(result);
    }
  }
}

class Dice {
  private int[] side;

  public Dice( int[] ia ) {
    side = Arrays.copyOf(ia, ia.length);
  }
  public Dice( String[] s ) {
    side = new int[s.length];
    for ( int i=0; i < 6; i++)
      side[i] = Integer.parseInt(s[i]);
  }

  @Override
  public boolean equals(Object o) {
    if(o == this) return true;
    if(o == null) return false;
    if(!(o instanceof Dice)) return false;
    Dice r = (Dice) o;

    if(
      (side[0] == r.side[0]) &&
      (side[1] == r.side[1]) &&
      (side[2] == r.side[2]) &&
      (side[3] == r.side[3]) &&
      (side[4] == r.side[4]) &&
      (side[5] == r.side[5])
      ) return true;
    else return false;
  }

  public int getUpperSide() {
    return side[0];
  }
  public int getLowerSide() {
    return side[5];
  }
  public int getFrontSide() {
    return side[1];
  }
  public int getBackSide() {
    return side[4];
  }
  public int getRightSide() {
    return side[2];
  }
  public int getLeftSide() {
    return side[3];
  }

  public boolean isSame(Dice d) {

    d.setFrontPosition(this.getFrontSide());

    for(int i=0; i<4; i++)  {
      for(int j=0; j<4; j++) {
        if( this.equals(d) ) return true;
        else d.rotate("W");
      }
      d.rotate("N");
    }

    return false;
  }

  public void setFrontPosition(int n) {
    for(int i=0; i < 3; i++){
      if(getUpperSide() != n) rotate("N");
    }
    for(int i=0; i < 3; i++){
      if(getUpperSide() != n) rotate("W");
    }
    rotate("S");
  }

  public int doRotate(String s) {
    for ( int i=0; i < s.length(); i++ ) {
      rotate(s.substring(i, i+1));
    }
    return side[0];
  }

  public void rotate(String o) {
    switch(o) {
      case "N" :
        rotateN();
        break;
      case "S" :
        rotateS();
        break;
      case "W" :
        rotateW();
        break;
      case "E":
        rotateE();
        break;
      default :
    }
  }

  private void rotateN() {
    int tmp = side[0];
    side[0] = side[1]; side[1] = side[5]; side[5] = side[4];
    side[4] = tmp;
  }
  private void rotateS() {
    int tmp = side[0];
    side[0] = side[4]; side[4] = side[5]; side[5] = side[1];
    side[1] = tmp;
  }
  private void rotateW() {
    int tmp = side[0];
    side[0] = side[2]; side[2] = side[5]; side[5] = side[3];
    side[3] = tmp;
  }
  private void rotateE() {
    int tmp = side[0];
    side[0] = side[3]; side[3] = side[5]; side[5] = side[2];
    side[2] = tmp;
  }
}


Measured memory_bytes: 28436
n, m, q = map(int, input().split())
a = [[0 for i in range(n)] for j in range(n)]
for i in range(m):
    l, r = map(int, input().split())
    a[l-1][r-1] += 1

for i in range(n):
    for j in range(1, n):
        a[i][j] += a[i][j-1]

for j in range(n):
    for i in range(1, n):
        a[i][j] += a[i-1][j]

for i in range(q):
    l, r = map(int, input().split())
    ans = a[r-1][r-1]
    if l > 1:
        ans += a[l-2][l-2]-a[r-1][l-2]-a[l-2][r-1]
    print(ans)

Measured memory_bytes: 13428
#coding:utf-8
n=[int(i) for i in input().split()]
d=n[1]
for i in range(2,-1,-1):
  if(d/pow(10,i)>=1):
    count=i
    break
n[0]=n[0]*int(pow(10,count+1))+n[1]
if(pow(n[0],1/2)==int(pow(n[0],1/2))):
  print("Yes")
else:
  print("No")

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

long long dp[100010];
int x,n,k;
vector <int> V;

int main()
{
    cin >> n >> k;
    for (int i=0;i<n;i++){
        cin >> x;
        V.push_back(x);
    }

    for (int i=1;i<n;i++){
        dp[i]=LLONG_MAX;
        for (int j=1;j<=k;j++){
            if (i-j<0) continue;
            dp[i]=min(dp[i], dp[i-j]+abs(V[i]-V[i-j]));
        }
    }
    cout << dp[n-1];
}


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

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<Integer> ret = new ArrayList<Integer>();
		while (sc.hasNext()) {
			int i, j, k, l;
			int cnt = 0;
			int input = sc.nextInt();
			for (i = 0; i <= 9; i++) {
				for (j = 0; j <= 9; j++) {
					for (k = 0; k <= 9; k++) {
						for (l = 0; l <= 9; l++) {
							if (i + j + k + l == input) {
								cnt++;
							}
						}
					}
				}
			}
			ret.add(cnt);
		}
		for (int cnt : ret) {
			System.out.println(cnt);
		}
	}
}

Measured memory_bytes: 26844
// Crt. 2020-01-07  0946
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define PII pair<int, int>
#define mk make_pair
#define N 204
using namespace std;
const int Mod = 998244353;

inline int fsp(int x, int p = Mod - 2) {
    int res = 1;
    while (p) {
        if (p & 1) res = 1ll * res * x % Mod;
        x = 1ll * x * x % Mod, p >>= 1;
    } return res;
}

inline int getp(int x) {
    return x < 0 ? -1 : 1;
}

inline int Abs(int x) {
    return x < 0 ? -x : x;
}

inline int gcd(int x, int y) {
    while (y ^= x ^= y ^= x %= y);
    return x;
}

int n, x[N], y[N], m, z[N];

inline PII getk(int i, int j) {
    int a = y[j] - y[i], b = x[j] - x[i];
    //cout << i << " " << j << " " << a << " " << b << endl;
    if (!a) { return mk(-100000, y[i]); }
    if (!b) { return mk(x[i], -100000); } 
    int pa = getp(a), pb = getp(b);
    if (pa < 0) pa = -pa, pb = -pb;
    a = Abs(a), b = Abs(b);
    int g = gcd(a, b);
    a /= g, b /= g;
    a *= pa, b *= pb;
    return mk(a, b);
}

int main(){
#ifdef LOCAL_JUDGE
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n;

    for (int i = 1; i <= n; ++i)
        scanf("%d%d", x + i, y + i);

    long long ans = fsp(2, n) - 1 - n;

    for (int i = 1; i <= n; ++i)
        for (int j = i + 1; j <= n; ++j) {
            int cnt = 0;
            for (int k = j + 1; k <= n; ++k) {
                if (getk(i, j) != getk(i, k)) continue; 
                ++cnt;
            }
            (ans -= fsp(2, cnt)) %= Mod;
        }

    if (ans < 0) ans += Mod;
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, M = sc.nextInt()
  val abs = List.fill(N)(sc.nextInt() -> sc.nextInt())
  val cds = List.fill(M)(sc.nextInt() -> sc.nextInt()).zipWithIndex
  abs.map { case (a, b) =>
    cds.minBy { case ((c, d), _) =>
      math.abs(a - c) + math.abs(b - d)
    }._2 + 1
  }.foreach(println)
}


Measured memory_bytes: 55596
#include <stdio.h>

int main(void){
  int x,y,z,d,i,j;
  
  scanf("%d %d",&x,&y);

  if(x>y){
    z=x%y;
    j=y;
  }
  else {
    z=y%x;
    j=x;
  }
  if(z!=0){
    for(i=z;i>0;--i){
      if(z%i==0 && j%i==0){
	break;
      }
    }
    printf("%d\n",i);
  }
  else{
    printf("%d\n",x);
  }

  return 0;
}



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

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

    int r;
    if (n % 1000 == 0) {
        r = 0;
    } else if (n < 1000) {
        r = 1000 - n;
    } else {
        r = (1000 * ((n/1000)+1)) - n;
    }

    cout << r << endl;

    return 0;
}


Measured memory_bytes: 3632
n,m,x = map(int,input().split())
ca = [[int(i) for i in input().split()] for j in range(n)]

num = 2**n
mon = 10**18

for i in range(num):
    tmp = format(i, '0'+str(n)+'b')
    #print(tmp)
    tmp_mon = 0
    alg = [0]*(m)
    for j in range(n):
        if int(tmp[j]) == 1:
            for k in range(m):
                alg[k] += ca[j][1+k]
            tmp_mon += ca[j][0]
    
    flag = True
    #print(alg,tmp_mon)
    for j in range(m):
        if alg[j] < x:
            flag = False
            break
    
    if flag == False:
        continue
    
    mon = min(tmp_mon,mon)

if mon == 10**18:
    print(-1)
else:
    print(mon)

Measured memory_bytes: 68676
// by adiforluls
#pragma GCC optimize ("-O2")
#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 FAST            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define mii             map<int,int>
#define vi              vector<int>
#define vll             vector<long long>
#define all(a)          (a).begin(),(a).end()
#define clz(a)          __builtin_clz(a) // count leading zeroes
#define ctz(a)          __builtin_ctz(a) // count trailing zeroes
#define popc(a)         __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul             1000000007
#define rep(i,a,b)      for(int i=a;i<b;i++)
#define rfor(i,a,b)     for(int i=a; i>=b; i--)
#define debug(x)        cerr << #x << " = " << x << endl;
#define F               first
#define S               second
#define mod             998244353 
#define pll             pair<ll,ll>
#define endl            '\n'
#define deci(n)         cout<<fixed<<setprecision(n)
#define ordered_set     tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
#define N    100005

void solve()
{
    int a[] = {100,101,102,103,104,105};
    int n; cin>>n;
    vi dp(n+1,0);
    dp[0] = 1;
    rep(i,1,n+1)
    {
        rep(j,0,6)
        {
            if(i>=a[j]) dp[i]|=dp[i-a[j]];
        }
    }
    cout<<dp[n];    
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;  //cin>>t;
    while(t--){
       solve();
    }
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	int org, i;
	int temp = 0;
	char temp_c;
	char dig[16];
	cin >> dig;

	org = atoi(dig);
	for (i = 0; i < strlen(dig); i++) {
		temp_c = dig[i];
		temp += temp_c - '0';
	}

	if (org % temp == 0)
		cout << "Yes";
	else
		cout << "No";

	cout << endl;

	return 0;
}


Measured memory_bytes: 256
def cumsum(l):
    c = [0] * len(l)
    for i in range(len(l)):
        c[i] = c[i-1] + l[i]
    return c

N, K = map(int, input().split())
a = [int(i) for i in input().split()]
c = [0] + cumsum(a)
s = {bin(c[j+i] - c[j]).replace('0b','').zfill(40) for i in range(1, N+1) for j in range(N-i+1)}
ans = 0

for i in range(40):
    t = {j for j in s if j[i] == '1'}
    if len(t) >= K:
        ans += 2**(39-i)
        s = t

print(ans)

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

int main(){
    int q,h,s,d;
    long long n;
    cin >> q >> h >> s >> d >> n;
    n=n*4;
    map<int,int> price;
    price[q*8]=1;
    price[h*4]=2;
    price[s*2]=4;
    price[d]=8;
    long long ans = 0;
    for(auto p:price){
        int cost = p.first;
        int volume = p.second;
        ans += cost*volume/8*(n/volume);
        n -= (n/volume)*volume;
        if(n==0) break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    S = []
    M = []
    sumsum = 0
    for _ in range(N):
        t = int(input())
        if t != 0:
            sumsum = sumsum + t
            S.append(t)
            if t % 10 != 0:
                M.append(t)

    if sumsum % 10 != 0:
        print(sumsum)
        return
    
    if len(M) == 0:
        print("0")
        return

    M.sort()
    print(sumsum - M[0])


if __name__ == "__main__":
    main()

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

const int INF = 1e9;

main() {
  string s; cin >> s;
  int cur{};
  vector<int> dp(1 << 26, INF);
  dp[0] = 0;
  for (auto c : s) {
    cur ^= 1 << (c - 'a');
    for (int i = 0; i < 26; i++) dp[cur] = min(dp[cur], dp[cur ^ (1 << i)] + 1);
  }
  cout << max(1, dp[cur]) << endl;
}


Measured memory_bytes: 262788
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int A=sc.nextInt();
        int B=sc.nextInt();

        int sum=0;
        for(int i=1;i<=N;i++){
            int n=i;
            int digSum=0;
            while(n>0){
                digSum+=n%10;
                n/=10;
            }
            if(digSum>=A&&digSum<=B)sum+=i;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  a *= 100; b *= 100;
  set<int> water, sugar;
  rep(i, f+1){
    rep(j, f+1){
      if(i == j && i == 0) continue;
      int add = a*i + b*j;
      if(add > f) continue;
      water.insert(add);
    }
  }
  rep(i, f+1){
    rep(j, f+1){
      int add = c*i + d*j;
      if(add > f) continue;
      sugar.insert(add);
    }
  }

  pair<int, int> ans(-1, -1);
  double p = -1;
  for(auto wa : water){
    for(auto su : sugar){
      if(wa+su > f) break;
      double ap = (double)su/(wa+su);
      if(ap > (double)e/(100+e)) break;
      if(ap > p){
        ans = make_pair(wa, su);
        p = ap;
      }
    }
  }
  cout << ans.first+ans.second << " " << ans.second << endl;
  return 0;
}

Measured memory_bytes: 384
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    h,w=parseMap(split(readline()))
    for i in 1:h
        s=split(readline())
        for j in 1:w
            if s[j]=="snuke"
                println(join(['A'+j-1,string(i)]))
                break
            end
        end
    end
end
main()

Measured memory_bytes: 123252
import fractions
from functools import reduce
 
def lcm_base(x, y):
  return (x*y)//fractions.gcd(x, y)
 
def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)
 
n = int(input())
ts = [0]*n
for i in range(n):
  ts[i] = int(input())

print(lcm_list(ts))

Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N,K,ans=0;
  cin>>N>>K;
  if(K==0){
    cout<<N*N<<endl;
    return 0;
  }
  for(int b=K+1;b<=N;b++)
    ans+=N/b*(b-K)+max(0LL,N%b-K+1);
  cout<<ans<<endl;
}

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

int main(){

    string n; cin >> n;

    if(n[0] == '7' || n[1] == '7' || n[2] == '7') cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3596
N = int(input())
A = list(map(int, input().split()))
ans = 0
B = []
for i in range(len(A)):
	B.append(A[i] - i + 1)
B.sort()
if len(B) % 2 == 0:
	b = (B[N//2] + B[N//2-1]) // 2
else:
	b = B[N//2]
for i in range(len(B)):
	ans += abs(B[i] - b)
print(ans)

Measured memory_bytes: 25196
#include <iostream>
using namespace std;
int dig(int x)
{
    int dg=0;
    while(x>0)
    {
        dg+=(x%10);
        x/=10;
    }
    return dg;
}
int main() {
  int n,a,b,s=0,ds;
  cin>>n>>a>>b;
  for(int i=0;i<=n;i++)
  {
      ds=dig(i);
      if(ds>=a && ds<=b) s+=i;
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] a = new int[N];
    int[] b = new int[N + 1];
    int[] c = new int[N];
    for(int i = 1; i < N + 1; i++) {
      b[i] = i;
    }
    for(int i = 0; i < N; i++) {
      a[i] = sc.nextInt();
      b[a[i]]--;
      if(b[a[i]] >= 0) c[b[a[i]]]++;
    }
    int L = 0;
    for(int i = 0; i < N; i++) {
      if(c[i] == 0) L++;
    }
    for(int i = 0; i < M; i++) {
      int x = sc.nextInt();
      int y = sc.nextInt();
      if(b[a[x - 1]] >= 0) c[b[a[x - 1]]]--;
      if(b[a[x - 1]] >= 0 && c[b[a[x - 1]]] == 0) L++;
      b[a[x - 1]]++;
      a[x - 1] = y;
      b[y]--;
      if(b[y] >= 0 && c[b[y]] == 0) L--;
      if(b[y] >= 0) c[b[y]]++;
      System.out.println(L);
    }
  }
}


Measured memory_bytes: 169028
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    return 0;
}
using namespace std;

void transpose(vector<vector<char>> &b)
{
    if (b.size() == 0)
        return;

    vector<vector<char>> trans_vec(b[0].size(), vector<char>());

    for (int i = 0; i < b.size(); i++)
    {
        for (int j = 0; j < b[i].size(); j++)
        {
            trans_vec[j].push_back(b[i][j]);
        }
    }

    b = trans_vec; // <--- reassign here
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    string ans;

    for (int i = 1; i < 10; i++)
    {
        for (int j = 1; j < 10; j++)
        {
            if (i * j == n)
            {
                ans = "Yes";
                cout << ans << endl;
                return 0;
            }
            else
            {
                ans = "No";
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  string S;
  cin>>S;
  reverse(S.begin(),S.end());
  bool bo=false;
  for(int i=0;i<S.size();){
    if(S.substr(i,5)=="maerd")
      i+=5;
    else if(S.substr(i,7)=="remaerd")
      i+=7;
    else if(S.substr(i,5)=="esare")
      i+=5;
    else if(S.substr(i,6)=="resare")
      i+=6;
    else{
      bo=true;
      break;
    }
  }
  if(bo)
    cout<<"NO"<<endl;
  else
    cout<<"YES"<<endl;
}

Measured memory_bytes: 3740
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let N = read int64
    let bs = reads int64
    let cs = reads int64
    let (ds, es) =
        List.map2 (-) bs cs
        |> List.partition ((<=) 0L)
        |> fun (xs, ys) -> (List.sortDescending xs, List.sort ys)

    let dsScan = List.scan (+) 0L ds |> List.tail
    let esSum = List.sum es

    let (fs, gs) = List.partition ((<) -esSum) dsScan
    let ans1 = List.length gs + 1
    let ans2 = List.length es

    match es, fs with
    | [], _ -> printfn "0"
    | _, [] -> printfn "-1"
    | _ -> printfn "%i" (ans1 + ans2)

    0

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

const int MOD = 1e9 + 7;
const int MAXN = 1e5;
int k;
vector<vector<int>> to(MAXN);


ll fac[MAXN], finv[MAXN], inv[MAXN];

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

// 順列組み合わせ計算
ll P(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[n - k] % MOD) % MOD;
}

ll dfs(int v, int parent=-1){
	ll res = 1;
	int childn,childk;
	
	if(parent==-1){
		res = k;
		childn = to[v].size();
		childk = k-1;
	}
	else{
		childn = to[v].size()-1;
		childk = max(k-2,0);
	}
	
	res = (res * P(childk,childn)) % MOD;
	
	for(auto child : to[v]){
		if(child == parent) continue;
		res = (res * dfs(child,v)) % MOD;
	}
	
	return res;
}

int main(){
	
	COMinit();
	int n;
	cin >> n >> k;
	
	rep(i,n-1){
		int a,b;
		cin >> a >> b;
		--a; --b;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	
	cout << dfs(0) << endl;
	return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int mod=1e9+7;
int f[3005][3005],sum[3005],n,m,mx[3005];
char s[3005];
int add(int a,int b){return a+b>=mod?a+b-mod:a+b;}
int main(){
	scanf("%d%d",&n,&m);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+(s[i]=='1');
	for(int i=1,l,r;i<=m;i++){
		scanf("%d%d",&l,&r);
		for(int p=l;p<=r;p++) mx[p]=max(mx[p],r);
	}
	f[0][0]=1;
	for(int i=1;i<=n;i++){
		if(!mx[i]){
			for(int p=0;p<=i;p++){
				if(s[i]=='1'&&p) f[i][p]=f[i-1][p-1];
				if(s[i]=='0') f[i][p]=f[i-1][p];
			}
			continue;
		}
		for(int p=0;p<=i;p++){
			if(p) f[i][p]=add(f[i-1][p],f[i-1][p-1]);
			else f[i][p]=f[i-1][p];
			if(sum[mx[i]]<p||(mx[i]-sum[mx[i]])<i-p) f[i][p]=0;
		}
	}
	printf("%d",f[n][sum[n]]);
	return 0;
}

Measured memory_bytes: 34176
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);

    int dx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
    int dy[8] = {0, 0, 1, -1, 1, -1, 1, -1};

    for (int i = 0; i < h; i++)
    {
        cin >> s[i];
    }

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (s[i][j] == '.')
            {
                int ans = 0;
                for (int k = 0; k < 8; k++)
                {
                    int nx = j + dx[k];
                    int ny = i + dy[k];
                    if (0 <= nx && nx < w && 0 <= ny && ny < h && s[ny][nx] == '#')
                        ans++;
                }
                cout << ans;
            }else{
                cout << "#";
            }
        }
        cout << endl;
    }
    return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()

int n;
int h[101000];
ll dp[100100];

void input(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>h[i];
	return;
}

void solve(){
	for(int i=0;i<=n;i++)dp[i]=INF;
	dp[0]=0;
	for(int i=0;i<n-1;i++){
		dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
		dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
	}
	cout<<dp[n-1]<<endl;
	return;
}

int main(){
	input();
	solve();
	return 0;
}

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input = null;
		try {
			input = br.readLine();
			br.close();
		} catch (IOException e) {
		}

		String[] inputs = input.split(" ");

		int w = Integer.parseInt(inputs[0]);
		int h = Integer.parseInt(inputs[1]);
		int x = Integer.parseInt(inputs[2]);
		int y = Integer.parseInt(inputs[3]);
		int r = Integer.parseInt(inputs[4]);

		if((x + r) <= w && (y + r) <= h && (x - r) >= 0 && (y - r) >= 0 ){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 24472
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const long long inf = 200000000001;

int main() {
    int A, B, Q;
    scanf("%d%d%d", &A, &B, &Q);

    vector<long long> s(A+2), t(B+2);
    s[0] = -inf;
    t[0] = -inf;
    s[A+1] = inf;
    t[B+1] = inf;
    for (int i = 1; i <= A; i++) {
        scanf("%lld", &s[i]);
    }
    for (int i = 1; i <= B; i++) {
        scanf("%lld", &t[i]);
    }

    long long q, res;
    for (int i = 0; i < Q; i++) {
        scanf("%lld", &q);
        int si = lower_bound(s.begin(), s.end(), q) - s.begin();
        int ti = lower_bound(t.begin(), t.end(), q) - t.begin();
        res = min({
            abs(q-s[si]) + abs(s[si]-t[ti]),
            abs(q-s[si]) + abs(s[si]-t[ti-1]),
            abs(q-s[si-1]) + abs(s[si-1]-t[ti]),
            abs(q-s[si-1]) + abs(s[si-1]-t[ti-1]),
            abs(q-t[ti]) + abs(t[ti]-s[si]),
            abs(q-t[ti]) + abs(t[ti]-s[si-1]),
            abs(q-t[ti-1]) + abs(t[ti-1]-s[si]),
            abs(q-t[ti-1]) + abs(t[ti-1]-s[si-1])
        });
        printf("%lld\n", res);
    }
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
 int inf = INT_MAX;
 int getadd(int x){
    int kv=0;
    while(x){
      kv+=x%10; x/=10;
    }
    return kv;
 }
 int main() {
   int n, i; int mini=inf ; 
   cin>>n;
   for(i=1;i<n;i++){
     mini=min(mini,getadd(i)+getadd(n-i));
   }
   cout<<mini<<endl;

  return 0;
}


Measured memory_bytes: 256
#import pysnooper

#@pysnooper.snoop()
def main():
    r,c=map(int,input().split())
    a=[list(map(int,input().split())) for _ in range(r)]
    c1=[0 for _ in range(c)]
    s=0

    for i in range(r):
        print(*a[i],sum(a[i]))
        s+=sum(a[i])
        for j in range(c):
            c1[j]+=a[i][j]
    print(*c1,s)

main()


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


int main() {
    string s;
    cin>>s;
    int c1=0,c2=0;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='0')c1++;
        else c2++;
    }
    cout<<min(c1,c2)*2<<endl;

}


Measured memory_bytes: 512
// Contest.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include"iostream"
#include"string"
#include"vector"
#include"algorithm"

using namespace std;

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

	int memo = 0;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (memo <= a[i]) {
			ans++;
			memo = a[i];
		}
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    int count=0;
    string x,y;
    cin>>x;
    for(int i=0;i<x.size();i++){
        if(x[i]>='A' && x[i]<='Z'){
            x[i]+='a'-'A';
        }
    }
    while(cin>>y){
        if(y=="END_OF_TEXT"){
            break;
        }
        for(int j=0;j<y.size();j++){
            if(y[j]>='A' &&y[j]<='Z'){
                y[j]+='a'-'A';
            }
        }
        if(x==y){
            count++;
        }
        
    }
    cout<<count<<endl;
    
    
    return 0;
}


Measured memory_bytes: 3216
# -*- coding: utf-8 -*-
# 整数の入力
a, b, c = map(int, input().split())
# カウンタのクリア
five_count = 0
seven_count = 0
# 5,7,5を判定
def setsu_check(x):
	global five_count, seven_count
	if x == 5:
		five_count+=1
	elif x == 7:
		seven_count+=1
# 判定関数のCALL
setsu_check(a)
setsu_check(b)
setsu_check(c)
if five_count == 2 and seven_count == 1:
	print("YES")
else:
	print("NO")

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

#define pb push_back
#define mod 1000000007
typedef int integer;
#define int long long
using namespace std;

int powmod(int a, int b) {
    int res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1)res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

const integer NN = 200005;
int ar[NN];
int n, m, k;
string s;


integer main() {
    ios_base::sync_with_stdio(false);

    cin >> n >> m;
    int ans = (n * (n-1)) / 2;
    ans += (m * (m-1)) / 2;
    cout << ans << endl;
//    for (int i = 0; i < n; i++){
//        cin >> ar[i];
//    }
}


Measured memory_bytes: 256
#include "iostream"
#include "stdio.h"
using namespace std;

int main()
{
	double r, pi;
	cin >> r;
	pi = 3.141592653589;
	double circleL = r * 2 * pi;
	double circleS = r * r*pi;
	printf("%0.5f %0.5f", circleS, circleL);
}


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

int main(void){
  string s;
  cin>>s;
  int count=0 ,max = 0;

  for(int i = 0;i < s.length();i++){

    if(s[i] == 'A'||s[i] == 'G'||s[i] == 'C'||s[i] == 'T'){
      count++;
    }
    else count=0;
    if(count>max)max=count;
  }
  cout<<max;

}


Measured memory_bytes: 256
import math  # noqa
import bisect  # noqa
import queue  # noqa


if __name__ == '__main__':
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    cnt = {}
    for a in A:
        if a not in cnt:
            cnt[a] = 1
        else:
            cnt[a] += 1

    for _ in range(M):
        B, C = map(int, input().split())
        if C not in cnt:
            cnt[C] = B
        else:
            cnt[C] += B

    cnt = [[k, v] for k, v in cnt.items()]
    cnt.sort(reverse=True)

    ans = 0
    for k, v in cnt:
        if N <= v:
            ans += k * N
            break
        else:
            ans += k * v
            N -= v

    print(ans)


Measured memory_bytes: 107880
#include <atcoder/dsu>
#include <cstdio>

using namespace std;
using namespace atcoder;

int main() {
    int n, q;
    scanf("%d %d", &n, &q);
    dsu d(n);
    for (int i = 0; i < q; i++) {
        int t, u, v;
        scanf("%d %d %d", &t, &u, &v);
        if (t == 0) {
            d.merge(u, v);
        } else {
            if (d.same(u, v)) {
                printf("1\n");
            } else {
                printf("0\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3544
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int k = scan.nextInt();
		int s = scan.nextInt();
		int c = 0;
		for (int i = 0; i <= k; i++) {
			for (int j = 0; j <= k; j++) {
					if (i+j<=s && s-i-j <= k) {
						c++;
				}
			}
		}
		System.out.println(c);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

vector<vector<long>> tree(1e5+1);
void f(long k,vector<long>& d){
    queue<long> q;
    q.push(k);
    while(!q.empty()){
        long t=q.front(); q.pop();
        for(auto x:tree[t]){
            if(x!=k&&d[x]==0){
                d[x]=d[t]+1;
                q.push(x);
            }
        }
    }
}
int main(){
    long n; cin>>n;
    for(int i=0;i<n-1;i++){
        long a,b; cin>>a>>b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    vector<long> df(n+1,0),ds(n+1,0);
    f(1,df);
    f(n,ds);
    long sum=0;
    for(int i=1;i<=n;i++)
        sum+=df[i]<=ds[i]?1:-1;
    if(sum>0)
        cout<<"Fennec";
    else
        cout<<"Snuke";
}

Measured memory_bytes: 8004
#include<iostream>
#include<algorithm>
#include<vector>
int main ()
{
	int n { 0 }; std::cin >> n;
	std::string s; std::cin >> s;
	std::vector<char> vect;
	vect.push_back (s[0]);
	for(int i = 1; i < s.length (); i++)
	{
		if(s[i] != vect.back ())vect.push_back (s[i]);
	}
	std::cout << vect.size ();

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    if(abs(a-c)<=d){
        cout<<"Yes"<<endl;
    }else if(abs(a-b)<=d&&abs(b-c)<=d){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <ctime>
#include <map>
#include <iomanip>
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long long a, long long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long long a, long long b){
	return a / gcd(a,b) * b;
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }
 
typedef long long ll;
 
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int n,idx;
int cnt[112345];
ll ans = 1;

int main(){
	cin >> n;

	REP(i,n){
		int a;
		cin >> a;

		if (!a) idx = i;

		cnt[a]++;
	}

	REP(i,n-1){
		REP(j,cnt[i+1]){
			ans *= cnt[i];
			ans %= 998244353;
		}
	}
	
	if (!idx) cout << ans << endl;
	else cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 640
import sys,math
from collections import deque,defaultdict
import operator as op
from functools import reduce
sys.setrecursionlimit(10**6) 

I=sys.stdin.readline

 #s="abcdefghijklmnopqrstuvwxyz"

#
def ii():
	return int(I().strip())
def li():
	return list(map(int,I().strip().split()))
def mi():
	return map(int,I().strip().split())

def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer // denom

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x





	

def main():
	n=ii()
	arr=sorted(li())
	cnt=0
	for i in range(n-2):
		for j in range(i+1,n-1):
			if arr[i]!=arr[j]:
				for k in range(j+1,n):
					if arr[j]!=arr[k]:
						if arr[i]+arr[j]>arr[k] and arr[k]+arr[j]>arr[i] and arr[i]+arr[k]>arr[j]:
							cnt+=1
	print(cnt)













	
	
	






		







		
		
	
		

	







		









if __name__ == '__main__':
	main()

Measured memory_bytes: 9596