akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define X first
#define Y second
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
//ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
int a[maxn][5];
int n;
int h;
int now[maxn];
int judge(int x,int y)
{
    int ss = 0;
    for(int i = 0; i < n; ++i)
    {
        now[i] = abs(x - a[i][1]) + abs(y - a[i][2]) + a[i][3];
        if(a[i][3] != 0)
        ss = max(now[i],ss);
    }
    for(int i = 0; i < n; ++i)
    {
        if(max(ss - abs(x - a[i][1]) - abs(y - a[i][2]),0) != a[i][3])
          return 0;
    }
    h = ss;
    return 1;
}
int main()
{
      while(cin>>n)
      {
          int x,y,z;
          for(int i = 0; i < n; ++i)
           cin>>a[i][1]>>a[i][2]>>a[i][3];

           int ansx,ansy,ansh;
           int have = 0;

          for(int i = 0; i <= 100; ++i)
            {
                for(int j = 0; j <= 100; ++j)
          {
              if(judge(i,j))
              {
                  have = 1;
                  ansx = i;
                  ansy = j;
                  ansh = h;
                  break;
              }
          }
          if(have)break;
          }
          printf("%d %d %d\n",ansx,ansy,ansh);
      }
}












Measured memory_bytes: 2304
#include<stdio.h>
#include<string.h>

int main(){
  char s[1001];
  char word[1001][33];
  int cnt[1001],l[1001];
  char tmp[33];
  int len,pos,d,num,i,j;
  int mod,max;

  fgets(s,1001,stdin);
    num = 0;
    len = strlen(s);
    pos = 0;
    while(pos<len){
      //printf("%d\n",pos);
      d = 0;
      while(pos+d<len && (s[pos+d]!=' ' && s[pos+d]!='\n')){
	tmp[d] = s[pos+d];
	d++;
      }
      tmp[d] = '\0';
      for(i=0;i<num;i++){
	if(d!=l[i])continue;
	for(j=0;j<l[i];j++)
	  if(tmp[j]!=word[i][j])break;
	if(j==l[i]){
	  cnt[i]++;
	  break;
	}
      }
      if(i==num){
	for(j=0;j<=d;j++)word[num][j] = tmp[j];
	l[num] = d;
	cnt[num] = 1;
	num++;
      }
      pos+=d+1;
    }
    mod = 0;
    max = 0;
    for(i=1;i<num;i++){
      if(cnt[mod]<cnt[i])mod = i;
      if(l[max]<l[i])max = i;
    }
    printf("%s %s\n",word[mod],word[max]);
  
  return 0;
}

Measured memory_bytes: 0
import java.util.*;

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

		int S = in.nextInt();
		int h = S / 60 / 60;
		int m = (S / 60) % 60;
		int s = S % 60;

		System.out.println(String.format("%d:%d:%d", h, m, s));
	}
}

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

using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define debug(a) cout << #a << ": " << a << endl;

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

  int cnt0 = count(S.begin(), S.end(), '0');
  int cnt1 = count(S.begin(), S.end(), '1');
  cout << min(cnt0, cnt1) * 2 << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  while(true) {
    int n, x;
    cin >> n >> x;
    if(n == 0 && x == 0) break;

    ll dp[n + 1][x + 1][4] = {};
    dp[0][0][0] = 1;
    rep(i, n) rep(j, x + 1) rep(k, 4) {
      dp[i + 1][j][k] += dp[i][j][k];
      int nj = j + i + 1;
      if(k < 3 && nj <= x) dp[i + 1][nj][k + 1] += dp[i][j][k];
    }
    cout << dp[n][x][3] << endl;
  }
}


Measured memory_bytes: 4004
n=int(input())
l=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(l[1]-l[0])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(l[i-1]-l[i]),dp[i-2]+abs(l[i-2]-l[i]))
print(dp[n-1])
#print(dp)
               

Measured memory_bytes: 13980
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

// エイリアス
using ll = long long;
using P = pair<int, int>;

// 素集合データ構造
struct UnionFind {
  vector<int> par, sizes; // par:あるデータの親, sizes:あるデータが属する木のサイズ

  // コンストラクタ
  // データ一つ一つを木とし、親は自分自身に初期化する
  UnionFind(int n) : par(n), sizes(n, 1) {
    for (int i = 0; i < n; i++) par[i] = i;
  }

  // データxが属する木の根ノードを取得
  // 再帰的に根を調べる際に、調べた辺を根に直接繋ぎ直すことで効率化している（経路圧縮）
  int find(int x) {
    return (x == par[x] ? x : par[x] = find(par[x]));
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // それぞれのデータの根ノードを取得
    x = find(x);
    y = find(y);

    // x, yが同じ木に属するならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるようにマージする
    par[y] = x;
    sizes[x] += sizes[y];
  }

  // 2つのデータx, yが同じ木に属するかどうか
  bool same(int x, int y) {
    return (find(x) == find(y));
  }

  // データxの属する木のサイズを返す
  int size(int x) {
    return sizes[find(x)];
  }
};

int main() {
  // 入力
  int N, M;
  cin >> N >> M;
  int a[M], b[M];
  for (int i = 0; i < M; i++) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }

  int ans = 0;
  for (int i = 0; i < M; i++) {
    UnionFind uf(N);
    for (int j = 0; j < M; j++) {
      if (i == j) continue;
      uf.unite(a[j], b[j]);
    }
    if (uf.size(0) < N) ans++;
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>

int main(){
	int N, A, B, C, D;
	scanf("%d %d %d %d %d\n", &N, &A, &B, &C, &D);
	char s[N + 1];
	scanf("%s", s);
	if(C > D){
		bool flag = false;
		for (int i = B; i <= D; ++i){
			if(s[i - 2] == '.' && s[i - 1] == '.' && s[i] == '.') flag = true;
		}
		if(!flag){
			printf("No\n");
			return 0;
		}
	}
	for (int i = A; i < C - 1; ++i){
		if(s[i] == '#' && s[i + 1] == '#'){
			printf("No\n");
			return 0;
		}
	}
	for (int i = B; i < D - 1; ++i){
		if(s[i] == '#' && s[i + 1] == '#'){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

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

void solve() {
    ll p,q,s,t,y,M;
    cin >> s >> t >> p >> q >> M >> y;
    cout << (s ^ t ^ y) << endl;
}

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



Measured memory_bytes: 3196
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

#define MAX_N 100010

using namespace std;

typedef pair<int, bool> P;

int main() {
    int n;
    cin >> n;
    bool color[n], visited[MAX_N] = {0};
    vector<P> G[MAX_N];
    for (int i=0; i<n-1; i++) {
        int u, v;
        long w;
        cin >> u >> v >> w;
        u--; v--;
        G[u].push_back({v, (bool)(w % 2)});
        G[v].push_back({u, (bool)(w % 2)});
    }
    queue<int> q;
    q.push(0); color[0] = false;
    while (!q.empty()) {
        int i = q.front(); q.pop();
        visited[i] = true;
        for (auto p:G[i]) {
            if (visited[p.first]) continue;
            q.push(p.first);
            color[p.first] = (p.second ? !color[i] : color[i]);
            //cerr << i << ' ' << p.first << ' ' << color[p.first] << '\n';
        }
    }
    for (auto c:color)
        cout << (int)c << '\n';
    return 0;
}


Measured memory_bytes: 6656
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<iostream>
#include<map>
#include<cstring>
#define INF 0x3f3f3f3f
#define eps 1e-10
using namespace std;
set<int> a;
map<int,int>tim;
long long x,k,d,ans,req;
int ne=0;
int main(){
    scanf("%lld%lld%lld",&x,&k,&d);
    x=abs(x);
    ans=x%d;
    req=x/d;
    if(k>req){
        if(abs(ans)>abs(ans-d)){
            ne=1;
            ans=abs(ans-d);
            req++;
        }
        if((k-req)%2!=0){
            if(!ne)
                ans=abs(ans-d);
            else
                ans=d-ans;
        }
    }
    else
        ans=ans+(req-k)*d;
    
    printf("%lld",ans);
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    int k;
    cin >> k;
    int a = 0;
    int b = 0;
    if(k%2==0){
        a = k/2;
        b = k/2;
    } 
    else{
        a = k/2;
        b = k/2+1;
    }
    cout << a*b << endl;
    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

  string s;
  cin >> s;

  int n = s.length();
  string t;
  for(int i = 0; i < n; i++){
    if(i % 2 == 0) t.push_back(s[i]);
  }

  cout << t << endl;

  return 0;
}


Measured memory_bytes: 576
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N,M; cin>>N>>M;
  vi A(N),B(M);
  rep(i,0,N) cin>>A[i];
  rep(i,0,M) cin>>B[i];
  int X=0,Y=0;
  rep(i,1,N){
    int Z=A[i]-A[i-1];
    Z%=MOD;
    Z*=i*(N-i)%MOD;
    Z%=MOD;
    X+=Z;
    X%=MOD;
  }
  rep(i,1,M){
    int Z=B[i]-B[i-1];
    Z%=MOD;
    Z*=i*(M-i)%MOD;
    Z%=MOD;
    Y+=Z;
    Y%=MOD;
  }
  int ans=X*Y%MOD;
  cout<<ans<<endl;
  }



Measured memory_bytes: 1792
import java.util.*;
class Main {

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    String s = sc.next();
    
    int lenS = s.length();
    
    if( lenS > k ) {
        System.out.println( s.substring(0, k) + "...");    
    }else{
        System.out.println( s );    
    }
  }
}


Measured memory_bytes: 38648
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include<iomanip>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>
i64 inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

//メモリ置き場
int n;
vector<int> a;

//inputします
void input() {
	cin >> n;
	a.resize(n);
	ff(i, 0, n) {
		cin >> a[i];
	}
	srt(a);
}

//ライブラリ置き場



//最大公約数
i64 gcd(i64 aa28, i64 bb28) {//aa28>bb28とすること
	i64 rr28 = aa28 % bb28;
	if (rr28 == 0)return bb28;
	return gcd(bb28, rr28);
}

//最小公倍数
i64 lcm(i64 aa29, i64 bb29) {
	return aa29 * bb29 / gcd(aa29, bb29);
}



//main
int main() {
    input();
	vector<int> l(n);
	vector<int> r(n);
	l[0] = a[0];
	ff(i, 1, n-1) {
		l[i] = gcd(l[i - 1], a[i]);
	}
	r[n - 1] = a[n - 1];
	ffrvs(i, n - 2, 1) {
		r[i] = gcd(r[i + 1], a[i]);
	}
	int ans = r[1];
	ff(i, 1, n-1) {
		int pre = gcd(r[i + 1], l[i - 1]);
		if (pre > ans)ans = pre;
	}
	if (l[n - 2] > ans)ans = l[n - 2];
	cout << ans << endl;
	return 0;
}

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

int main(){
    int A=-1,B=-1,C=-1,N,Y,z,w;
    cin>>N>>Y;
    int y=Y/1000;
    for(int a=0;a<=N;a++){
        z=y-10*a;
        if(z>=0){
            for(int b=0;b<=N-a;b++){
                w=z-5*b;
                if(w==N-a-b){
                    A=a,B=b,C=N-a-b;
                    goto lol;
                }
            }
        }    
    }

lol:
cout<<A<<" "<<B<<" "<<C<<endl;
return 0;
}

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

ll mod = 1000000007;
ll MAX = 100005;
int main(){
  string s;
  cin >> s;
  ll n = s.size();
  vector<vector<ll>> dp(MAX,vector<ll>(13,0));
  dp[0][0] = 1;
  ll digit = 1;
  ll count = 1;
  rep(i,n){
    digit %= 13;
    if(s[n-1-i]!='?'){
      int x = ctoi(s[n-1-i]);
      // cout << count << " " << x << endl;
      // count ++;
      x = (x*digit)%13;
      rep(j,13){
        ll id = (j+x)%13;
        dp[i+1][id] += dp[i][j];
      }
    }else{
      rep(t,10){
        int x = (t*digit)%13;
        // cout << count << " " << t << endl;
        // count ++;
        rep(j,13){
          ll id = (j+x)%13;
          dp[i+1][id] += dp[i][j];
        }
      }
    }
    rep(j,13){
      dp[i+1][j] %= mod;
    }
    digit *= 10;
  }
  cout << dp[n][5] << endl;
  
  return 0;
}

Measured memory_bytes: 15616
import sys
def input(): return sys.stdin.readline().rstrip()
# 単位元とseg_funcを設定する
from fractions import gcd
class seg():
    def __init__(self,init_val):
        self.n=len(init_val)
        self.ide_ele=0 #単位元
        self.num=2**(self.n-1).bit_length() #n以上の最小の2のべき乗
        self.seg=[self.ide_ele]*2*self.num
        for i in range(self.n):
            self.seg[i+self.num-1]=init_val[i]
        for i in range(self.num-2,-1,-1):
            self.seg[i]=self.seg_func(self.seg[2*i+1],self.seg[2*i+2])
    def seg_func(self,a,b):
        #return a+b #0
        #return a*b #1
        return gcd(a,b) #0
        #return max(a,b) #-1か-10**10 (十分小さいもの)
        #return min(a,b) #10**10 (十分大きいもの)
    def update(self,k,x):
        k+=self.num-1
        self.seg[k]=x
        while k:
            k=(k-1)//2
            self.seg[k]=self.seg_func(self.seg[k*2+1],self.seg[k*2+2])
    def query(self,p,q): #O(logN)
        if q<=p:return self.ide_ele
        p+=self.num-1
        q+=self.num-2
        self.res=self.ide_ele
        while q-p>1:
            if p&1==0:
                self.res=self.seg_func(self.res,self.seg[p])
            if q&1==1:
                self.res=self.seg_func(self.res,self.seg[q])
                q-=1
            p=p//2
            q=(q-1)//2
        if p==q:self.res=self.seg_func(self.res,self.seg[p])
        else:self.res=self.seg_func(self.seg_func(self.res,self.seg[p]),self.seg[q])
        return self.res

def main():
    n=int(input())
    A=[int(_) for _ in input().split()]
    ans=0
    seg_a=seg(A)
    for i in range(n):
        ans=max(ans,gcd(seg_a.query(0,i),seg_a.query(i+1,n)))
    print(ans)
if __name__=='__main__':
    main()

Measured memory_bytes: 89580
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
F=[int(i) for i in input().split()]
A.sort()
F.sort()

def chk(x):
  ct=0
  for i in range(n):
    a,f=A[i],F[-i-1]
    ct+=max(0,a-x//f)
    if ct>k:
      return False
  if ct<=k:
    return True
  else:
    return False
l=0
r=0
for i in range(n):
  r=max(r,A[i]*F[-i-1])

while r-l>1:
  m=(l+r)//2
  if chk(m):
    r=m
  else:
    l=m

if chk(l):
  print(l)
else:
  print(r)

Measured memory_bytes: 120268
package main

import "fmt"

func main() {
	var X, A, B int
	fmt.Scan(&X, &A, &B)
	if B-A <= 0 {
		fmt.Println("delicious")
	} else if B-A <= X {
		fmt.Println("safe")
	} else {
		fmt.Println("dangerous")
	}
}


Measured memory_bytes: 512
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ll long long
#define int ll
#define ld long double
#define ii pair<int,int>
#define heap priority_queue
#define all(k) k.begin(),k.end()
#define rall(k) k.rbegin(),k.rend()
#define fa(a,c) for(auto &a:c)
#define yes "YES"
#define no "NO"




int32_t main(){
  ios::sync_with_stdio(0); cin.tie(0);
  int a,b,k;
  cin>>a>>b;
  //a2-2ak=b2-2kb
  //(a+b)(a-b)=2k(-b+a)
  //a+b=2k
  int s=a+b;
  if(s&1){
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
  }

  k=s/2;
  if(abs(a-k)==abs(b-k)){
    cout<<k<<endl;
    return 0;
  }
  else{
    k=-k;

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

      cout<<"IMPOSSIBLE"<<endl;
      return 0;
    }
  }


  return 0;
}


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


int main()
{
    ll t;
    cin>>t;
    map<string , int> m1;
    m1["AC"]=0;
    m1["WA"]=0;
    m1["TLE"]=0;
    m1["RE"]=0;
    while(t--){
        string x;
        cin>>x;
        m1[x]=m1[x]+1;
    }
    cout<<"AC x "<<m1["AC"]<<endl;
    cout<<"WA x "<<m1["WA"]<<endl;
    cout<<"TLE x "<<m1["TLE"]<<endl;
    cout<<"RE x "<<m1["RE"]<<endl;
}


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

int main()
{
    ll N, K;
    cin >> N >> K;

    while (N > abs(N - K))
    {
        if (N > K)
        {
            N = N % K;
        }
        else
        {
            N = abs(N - K);
        }
    }

    cout << N << endl;
}


Measured memory_bytes: 256
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split(' ');
            var n = long.Parse(nk[0]);
            var k = long.Parse(nk[1]);

            var a = n / k;
            n -= a * k;

            while (Math.Abs(n - k) < n)
            {
                n = Math.Abs(n - k);
            }
            Console.WriteLine(n);
        }
    }
}

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  int64_t product = 1LL;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    if (A.at(i) == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    if (A.at(i) <= 1000000000000000000/product) {
      product *= A.at(i);
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << product << endl;
}

Measured memory_bytes: 4000
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,st,en;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>a>>b>>x;
    tmp=a/x;
    if(a%x!=0)tmp++;
    st=tmp*x;
    en=(b/x)*x;
    if(st==en)Cout(1);
    else{
        if(st>en)Cout(0);
        else{
            ans=2;
            ans+=max((en-st)/x-1,0LL);
            Cout(ans);
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a; i<ll(b); i++) 
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int gcd(int a, int b){ //a>=0,b>=0,￢(a=b=0)
  while(min(a,b)>0){if(a<b)swap(a,b);a=a%b;}return max(a,b);
}
//int:~2e9   小数:double
int main(){
  int a,b;
  cin >>a>>b;

  if(a>b) swap(a,b);//a<=b
  rep(i,b) cout<<a;
  cout<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <vector>
#include <algorithm>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;

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



int main() {
  LL N; scanf("%lld", &N);
  string str1;
  cin >> str1;
  int num_R = 0;
  int num_W = 0;
  rep(i,N){
    if(str1.at(i)=='R'){
      num_R++;
    }
  } 
  int count = 0;
  rep(i,num_R){
    if(str1.at(i)=='W'){
      count++;
    }
  } 
  printf("%d\n", count);
  // //  printf("%s\n", BUFSIZ.c_str());
  return 0;
}



Measured memory_bytes: 3908
s = input()

if s[0]==s[1]:
    if s[2]==s[3] and s[1]!=s[2]:
        print('Yes')
        exit()

elif s[0]==s[2]:
    if s[1]==s[3] and s[1]!=s[2]:
        print('Yes')
        exit()

elif s[0]==s[3]:
    if s[1]==s[2] and s[0]!=s[2]:
        print('Yes')
        exit()

print('No')

Measured memory_bytes: 38384
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Long> t = new ArrayList<>();
        for(int i = 0;i < n;i++){
            t.add(sc.nextLong());
        }
        long answer = 1L;
        for(Long it : t){
            answer = lcm(answer,it);
        }
        System.out.println(answer);

    }
    public static long lcm(long a,long b){
        return a/gcd(a,b)*b;
    }
    public static long gcd(long a,long b){
        if(b == 0){
            return a;
        }
        return gcd(b,a%b);
    }
}


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

int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  ll money = 1000;
  rep(i,n-1){
    if(a[i] < a[i+1]){
      ll kabu = money/a[i];
      money %= a[i];
      money += kabu*a[i+1];
    }    
  }
  cout << money << endl;
}


Measured memory_bytes: 3628
import java.util.*;

public class Main {
        public static void main(String [] args){
            Scanner sc =new Scanner(System.in);
            double ans = 0;
            double n = sc.nextLong();
            double m = sc.nextLong();
            double d = sc.nextLong();

            if(d==0) {
                System.out.println((1.0/n)*(m-1));
            }else {
                ans =2.0*(n-d)/n/n;
                System.out.println(ans *(m-1.0));
            }

        }
}


Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<double,int>;
const ll M = 1e9+7;
void add(ll& x, ll y) {x+=y; x%=M;}
void chmax(ll& x, ll y) {if (x<y) x=y;}
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}

int main() {
  ll n; cin>>n;
  ll k; cin>>k;
  ll a[n],b[n];
  for(int i=0;i<n;i++) cin>>a[i]>>b[i];

  ll an=0,sm=0;
  for(int i=0;i<n;i++) {
    if ((k | a[i]) == k) {
      sm+=b[i];
    }
  }
  an=max(an,sm);

  for(ll i=2;i<=k;i<<=1) {
    if ((k & i) == 0) continue;
    ll k2 = k;
    k2 ^= i; k2 |= i-1;
    sm = 0;
    for(int j=0;j<n;j++) {
      if ((k2 | a[j]) == k2) {
        sm += b[j];
      }
    }
    an = max(an,sm);
  }
  cout<<an<<endl;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
int main(){
	int A, B, C, D; cin >> A >> B >> C >> D;
	cout << max(A*B, C*D) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int x,y;
int main(){
    cin>>x>>y;
    if(x==1 && y==1){
        cout<<1000000<<endl;
        return 0;
    }
    int ans=0;
    if(x==1)
        ans+=300000;
    else if(x==2)
        ans+=200000;
    else if(x==3)
        ans+=100000;

    if(y==1)
        ans+=300000;
    else if(y==2)
        ans+=200000;
    else if(y==3)
        ans+=100000;
    
    cout<<ans<<endl;
    return 0;
        
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<climits>
#include<algorithm>
#include<vector>
#include<string>
#include<string.h>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<cmath>
using namespace std;
#define inf 0x3f3f3f3f
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define sz(a) int((a).size())
#define pb push_back
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
const int N = 1e5+7;
ll n,m,k,x,y,b;
int main(){
    fast;
    cin>>n;
    forn(i,n){
        cin>>y;
        if(!y) k+=x/2,x=0;
        x+=y;
    } k+=x/2;
    cout<<k<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#define rep(i,n) for (int i=0;i<n;i++)
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;


int main(){
	string S,S2,S3;
  cin >> S;
  

  
  string tmp4=S;
  reverse(tmp4.begin(),tmp4.end());

  rep(i,((int)S.size()-1)/2){
    S2.push_back(S.at(i));
  }
  
  string tmp=S2;
    reverse(S2.begin(),S2.end());

  
  for(int i=((int)S.size()+3)/2-1;i<(int)S.size();i++){
    S3.push_back(S.at(i));
  }
    string tmp2=S3;
  reverse(S3.begin(),S3.end());
  
  if(tmp==S2 && tmp2==S3 && tmp4==S)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}





Measured memory_bytes: 256
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let a: usize = itr.next().unwrap().parse().unwrap();
    let b: usize = itr.next().unwrap().parse().unwrap();
    let c: usize = itr.next().unwrap().parse().unwrap();
    for i in 1..200 {
        if a * i % b == c {
            println!("YES");
            return;
        }
    }
    println!("NO");
}


Measured memory_bytes: 4352
//FA専用
#include <bits/stdc++.h>
using namespace std;
#define int long long
const long long LINF=1e18;
int a,b,c,d,e,f,n,m,ans;
string s,t,u;
template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}
template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}
template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
template<typename T,typename U>
void fin(T a,U b){
  cout<<a<<" "<<b<<endl;
  exit(0);
}
template<typename T,typename U,typename S>
void fin(T a,U b,S c){
  cout<<a<<" "<<b<<" "<<c<<endl;
  exit(0);
}

signed main(){
cin>>a>>b>>c;
  d=min(a,c);
  a-=d;c-=d;
  e=min(b,c);
  b-=e;
  fin(a,b);
}

Measured memory_bytes: 256
<?php

while (True) {
  $count = 0;
  fscanf(STDIN, "%d %d", $n, $x);
  if ($n === 0 and $x === 0) {
    break;
  }
  for ($i = 1; $i <= ($x / 3); $i++) {
    for ($j = $i + 1; $j <= ($x * 2 / 3); $j++) {
      if (($j + 1) <= ($x - ($i + $j)) && ($x - ($i + $j)) <= $n) {
        $count++;
      }
    }
  }
  echo $count."\n";
}


Measured memory_bytes: 9228
program main
  implicit none
  integer :: N
  character(len=100) :: s
  integer :: i
  integer :: n_r,n_s
  read(*,*) N
  read(*,*) s(1:N)
  n_r = 0
  n_s = 0
  do i = 1,N
     if (s(i:i) == 'R') then
        n_r = n_r + 1
     else
        n_s = n_s + 1
     end if
  end do
  if (n_r > n_s) then
     write(*,'(a)') 'Yes'
  else
     write(*,'(a)') 'No'
  end if
end program main


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		String seven = "No";
		try (Scanner scn = new Scanner(System.in)) {
			final char[] N = scn.next().toCharArray();
			for (int i = 0; i < N.length; i++) {
				if (N[i] == '7') {
					seven = "Yes";
					break;
				}
			}
		}
		System.out.println(seven);
	}
}


Measured memory_bytes: 26964
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        mut reds: [(u64, u64); n],
        mut blues: [(u64, u64); n],
    }
    reds.sort_by_key(|&(_, y)| y);
    blues.sort();

    let mut used = vec![false; n];
    let mut cnt = 0;
    for i in 0..n {
        for k in (0..n).rev() {
            if !used[k] && blues[i].0 > reds[k].0 && blues[i].1 > reds[k].1 {
                cnt += 1;
                used[k] = true;
                break;
            }
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 4352
//                                                   ¯\_(ツ)_/¯               
  //#pragma GCC optimize("Ofast")												 
 //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")  
//#pragma GCC optimize("unroll-loops")                                             
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
#define pi pair<int,int>
const int N=1e6+5,MOD=998244353;
 
using namespace std;

int a,b,c;
int main() {


		cin>>a>>b>>c;

		int ans = b/a;

		printf("%d\n",min(ans,c) );
	
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        List<Integer> colorList = new ArrayList<>();

        for (int i = 0; i < s.length(); i++){
            int value = Character.getNumericValue(s.charAt(i));
            colorList.add(value);
        }

        if (colorList.size() == 1){
            System.out.println(0);
        }else {
            int zeroOne = zeroOne(colorList);
            int oneZero = colorList.size() - zeroOne;

            System.out.println(Math.min(zeroOne, oneZero));
        }
    }

    private static int zeroOne(List<Integer> colorList){
        // 010101010101...なら0が返る

        int updateCount = 0;
        for (int i = 0; i < colorList.size(); i++){
            if (i % 2 == 0){
                // 奇数番目、が0かどうかを検証、0ならそのまま、1ならプラス１
                if (colorList.get(i) == 1){
                    updateCount++;
                }
            }else {
                if (colorList.get(i) == 0){
                    updateCount++;
                }
            }
        }

        return updateCount;
    }
}

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

using namespace std;

const int nax=1e5+5;
vector<int>edges[nax];
const int mod=1e9+7;
int mul(int a,int b)
{
    return (long long) a * b % mod;
}

pair<int,int> dfs(int a,int parent)
{
    int all_white=1;
    int smth_black=0;
    for(int b:edges[a])
    {
        if(b!=parent)
        {   //p.first means the child b is black

            pair<int,int>p=dfs(b,a);
            int temp_white=all_white;
            all_white=mul(all_white,p.second);
            smth_black=(mul(temp_white,p.first)+ mul(smth_black,p.first+p.second))%mod;
        }
    }
    return make_pair(all_white,(all_white+smth_black)%mod);
}


int main()
{
    int n;
    scanf("%d",&n);
    int a,b;
    for(int i=0;i<n-1;i++)
    {
        scanf("%d %d",&a,&b);
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    pair<int,int>p=dfs(1,-1);
    cout<<(p.first+p.second)%mod<<endl;

}

Measured memory_bytes: 12672
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
  
  
namespace io{
    const int L = (1 << 20) + 1;
     
    char buf[L], *S , *T, c;
      
    char getchar() {
        if(S == T) {
            T = (S = buf) + fread(buf, 1, L, stdin);
            return (S == T ? EOF : *S++);
        }
        return *S++;
    }
     
    int inp() {
        int x = 0, f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
     
    ll inp_ll() {
        ll x = 0; int f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
     
    char B[25], *outs=B+20, *outr=B+20;
    template<class T>
    inline void print(register T a,register char x=0){
        if(x) *--outs = x, x = 0;
         
        if(!a)*--outs = '0';
        else
            while(a)
                *--outs = (a % 10) + 48, a /= 10;
         
        if(x)
            *--outs = x;
         
        fwrite(outs, outr - outs , 1, stdout);
        outs = outr;
    }
};
  
using io :: print;
using io :: inp;
using io :: inp_ll;
const int maxN = 100010;
const int maxM = 20;
int n,X;
int a[maxN];
int gcd(int u,int v)
{
	if(u < v) swap(u,v);
	if(v == 0) return u;
	else
		return gcd(v,u%v);
}
int main()
{
	scanf("%d %d",&n,&X);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	int ans = abs(a[1] - X);
	for(int i=2;i<=n;i++)
	{
		int p = abs(a[i] - X);
		ans = gcd(p,ans);
	}
	printf("%d\n",ans);
    return 0;
}

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

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

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

  int min = 1000000;
  for(int j=0; j<n-1; j++){
   for(int i=j+1; i<n; i++){
    if(a[j]>=a[i] && a[j]-a[i]<min){
     min = a[j]-a[i];
    }else if(a[j]<a[i] && a[i]-a[j]<min){
     min = a[i]-a[j];
    }
   }
  }

  cout << min <<endl;
 }

 return 0;
}

 

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
template <class T> T input() {T t; cin>>t; return t;}
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define CHMAX(a,b) a = max(a,b)
#define CHMIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define newline putchar('\n')
#define cspace ' '
#define sspace " "
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;
const VI dx = {1, 0, -1, 0};
const VI dy = {0, 1, 0, -1};

int main()
{
    ll n, ans = 0ll;
    cin>>n;

    FOR(i,1,n+1) {
        ans += i * (n + 1 - i);
        //cout<<min(n+i-1, n+(n-i+1)-1)<<endl;
    }

    REP(i,n-1) {
        int u, v;
        cin>>u>>v;
        if (u > v) swap(u, v);
        ans -= u * (n - v + 1);
    }

    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main()
{

    string a;
    cin>>a;
    if((a[0]==a[1]&&a[0]==a[2]) ||
        (a[1]==a[2]&&a[1]==a[3]) || (a[1]==a[2]&&a[2]==a[3]) &&a[0]==a[1])
            cout<<"Yes";
    else cout<<"No";


return 0;
}






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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

const int mod=1000000007;
void Wafrelka(int const(&a)[3][3],int const(&b)[3][3],int(&c)[3][3]){
	REP(i,3)REP(j,3){
		c[i][j]=0;
		REP(k,3)c[i][j]+=a[i][k]*b[k][j];
		c[i][j]%=mod;
	}
}
int s[30][3][3],t[3][3];

signed main(){
	{
		int tmp[3][3]={
			{2,1,1},
			{2,1,0},
			{1,1,1}
			};
		swap(s[0],tmp);
		FOR(i,1,30)
			Wafrelka(s[i-1],s[i-1],s[i]);
	}
	{
		int tmp[3][3]={
			{1,0,0},
			{2,1,0},
			{1,1,1}
			};
		swap(t,tmp);
	}
	int n=read(),m=read(),last=0;
	assert(n<=1000000000);
	assert(m<=100000);
	int buf[3][3]={{1,0,0},{0,1,0},{0,0,1}};
	REP(_,m){
		int x=read();
		assert(last<x);
		int g=x-last-1;
		REP(i,30)if((g>>i)&1){
			int tmp[3][3];
			Wafrelka(s[i],buf,tmp);
			swap(buf,tmp);
		}
		int tmp[3][3];
		Wafrelka(t,buf,tmp);
		swap(buf,tmp);
		last=x;
	}
	assert(last<n);
	int g=n-last-1;
	REP(i,30)if((g>>i)&1){
		int tmp[3][3];
		Wafrelka(s[i],buf,tmp);
		swap(buf,tmp);
	}
	int ans=0;
	REP(i,3)ans+=buf[i][0];
	ans%=mod;
	cout<<ans<<endl;
}


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

#define int long long
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);

int32_t main(){
	fast;
	string s;
	cin >> s;
	
	int n = s.length() - 1;
	int ans = 0;
	for(int mask =0 ; mask <(1LL << n) ; mask++)
	{
		int t = 1;
		for(int i = n ;  i >= 1 ; i--)
		{
			ans += t*(s[i]-'0');
			if(mask & (1LL << (i-1)))   t = 1;
			else                        t *= 10;
		}
		
		ans += t*(s[0] -'0');
	}
	
	cout << ans;
}







Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int,input().split()))
    cnt = 0

    for i in range(N):
        temp = i
        minj = A[i]
        for j in range(i+1,N):
            if A[j] < minj:
                minj = A[j]
                temp = j

        if temp != i:
            temp2 = A[i]
            A[i] = A[temp]
            A[temp] = temp2
            cnt += 1

    print(' '.join(map(str,A)))
    print(cnt)


main()



Measured memory_bytes: 5600
#include <stdio.h>
#include <iostream>
using namespace std;
int main(void){
    int J=0,n;
    
    cin >> n;
        int Q[101][6]={{}};
    
    for(int A=0;A<n;A=A+1){\
    
        for(int i=0;i<6;i=i+1){
            cin >> Q[A][i];
        }
    }
    
    
    for(int L=0;L<n-1;L=L+1){
        for(int R=L+1;R<n;R=R+1){
    
    
    
    for(int j=0;j<9;j=j+1){
        if(Q[R][0]==Q[L][0]&&Q[R][5]==Q[L][5]){
            for(int k=0;k<7;k=k+1){
                if(Q[R][1]==Q[L][1]&&Q[R][2]==Q[L][2]&&Q[R][3]==Q[L][3]&&Q[R][4]==Q[L][4]){
                    J=7;
                    if(J==7)break;
                    
                }else{
                    Q[100][1]=Q[R][2];Q[100][2]=Q[R][4];Q[100][4]=Q[R][3];Q[100][3]=Q[R][1];
                    Q[R][1]=Q[100][1];Q[R][2]=Q[100][2];Q[R][3]=Q[100][3];Q[R][4]=Q[100][4];
                }
            }
        }else if(j!=2){
                Q[100][0]=Q[R][1];Q[100][1]=Q[R][5];Q[100][5]=Q[R][4];Q[100][4]=Q[R][0];
                Q[R][0]=Q[100][0];Q[R][1]=Q[100][1];Q[R][4]=Q[100][4];Q[R][5]=Q[100][5];
        }else{
                Q[100][0]=Q[R][3];Q[100][2]=Q[R][0];Q[100][3]=Q[R][5];Q[100][5]=Q[R][2];
                Q[R][0]=Q[100][0];Q[R][3]=Q[100][3];Q[R][2]=Q[100][2];Q[R][5]=Q[100][5];
        }
    }
    
    
    
        }
        
        
    }
    
    if(J==7){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}



Measured memory_bytes: 3116
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}


//↑template↑


int main() {

	int a, b;
	cin >> a >> b;
	cout << abs(a - b) << endl;


}


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

int digitPoor(int n)
{
    if (n < 10)         return 1;
    else if (n < 100)        return 2;
    else if (n < 1000)       return 3;
    else if (n < 10000)      return 4;
    else if (n < 100000)     return 5;
    else if (n < 1000000)    return 6;
    else if (n < 10000000)   return 7;
    else if (n < 100000000)  return 8;
    else if (n < 1000000000) return 9;
    else if (n < 10000000000) return 10;
    else if (n < 100000000000) return 11;
    else if (n < 1000000000000) return 12;
    else if (n < 10000000000000) return 13;
    else if (n < 100000000000000) return 14;
    else if (n < 1000000000000000) return 15;
    else if (n < 10000000000000000) return 16;
    else if (n < 100000000000000000) return 17;
    else if (n < 1000000000000000000) return 18;
}
int check(int a,int b,int i,int x){
    if(a*i+b*digitPoor(i)<=x) {
        if(i>=1000000000) return 1000000000;
        else return i;
        }
    if(i<=0) return 0;
    check(a,b,i-1,x);
}
main()
{
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    rep(i,n) cin>>a[i];
    int ans=1e18;
    rep(i,n-k+1){
        int b=0;
        if(a[i]<0&&a[i+k-1]<0){
            b=abs(a[i]);
        }else if(a[i]<0&&a[i+k-1]>0){
            b=min(-a[i]-a[i]+a[i+k-1],a[i+k-1]*2-a[i]);
        }else if(a[i]>0&&a[i+k-1]>0){
            b=a[i+k-1];
        }
        ans=min(ans,b);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){
   int n;
   cin>>n;
   int ans=0;
   int tmp=n;
   while (tmp!=0){
       ans+=tmp%10;
       tmp=tmp/10;

   }
   if(n%ans==0)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
}

Measured memory_bytes: 256