akhauriyash/Code-Regression huggingface dataset:
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[] a = new int[n];
		Arrays.setAll(a, i -> sc.nextInt());
		
		int minSum = Integer.MAX_VALUE;
		for (int num = -100; num <= 100; num++) {
			int sum = 0;
			for (int i = 0; i < n; i++) {
				int abs = Math.abs(num - a[i]);
				sum += abs* abs;
			}
			minSum = Math.min(minSum, sum);
		}
		
		System.out.println(minSum);
		
		sc.close();
	}
}



Measured memory_bytes: 32320
import sys
input = sys.stdin.readline

def main():
    S = input().rstrip('\n')
    cc = 0
    itr = 0
    for i in range(len(S)):
        if S[i] == 'W':
            itr += 1
            cc += i - (itr - 1)
    S = S[::-1]
    itr = 0
    for i in range(len(S)):
        if S[i] == 'B':
            itr += 1
            cc += i - (itr - 1)
    print(cc//2)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 3500
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(N):
    temp = B[i] - A[i]
    if temp >= 0:
        ans += A[i]
        if A[i+1] >= temp:
            A[i+1] -= temp
            ans += temp
        else:
            ans += A[i+1]
            A[i+1] = 0
    else:
        ans += B[i]

print(ans)

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

int main() {
    ios_base :: sync_with_stdio(false);
    int n; cin >> n;
    
    vector<int> l(n, 0), r(n, 0);
    vector<pair<int, int>> v(n);

    int maxx = 0;

    for (int i = 0; i < n; i += 1) {
        cin >> l[i] >> r[i];
        if (r[i] - l[i] + 1 > maxx) {
            maxx = r[i] - l[i] + 1;
        }
        v[i] = make_pair(l[i], r[i]);
    }

    if (n == 1) {
        cout << maxx << "\n";
        return 0;
    }
    
    int min_r = *min_element(r.begin(), r.end());
    int max_l = *max_element(l.begin(), l.end());
    
    auto w = v;

    for (int i = 0; i < n; i += 1)
        if(w[i].second - w[i].first + 1 == maxx) {
            w.erase(w.begin() + i);
            break;
        }

    auto getBest = [] (vector<pair<int, int>> v) {
        if(v.empty())
            return 0;
        int rt = numeric_limits<int> ::max();
        int lf = 0;

        for (const auto& elem : v) {
            rt = min(rt, elem.second);
            lf = max(lf, elem.first);
        }

        return max(0, rt - lf + 1);
    };
       
    int ans = maxx + getBest(w);

    int who = -1;
    vector<int> taken(n, 0);
    int best_l_for_r = numeric_limits<int>::max(), best_r_for_l = -1;

    for (int i = 0; i < n; i += 1) {
        if (r[i] == min_r and l[i] < best_l_for_r) {
            best_l_for_r = l[i];
            who = i;
        }
    }
    

    taken[who] = 1;

    w = v;
    w.erase(w.begin() + who);

    ans = max(ans, (min_r - best_l_for_r + 1) + getBest(w));

    who = -1;

    for (int i = 0; i < n; i += 1) {
        if (not taken[i] and l[i] == max_l and r[i] > best_r_for_l) {
            best_r_for_l = r[i];
            who = i;
        }
    }

    if (who == -1) {
        cout << ans << "\n";
        return 0;
    }
    
    taken[who] = 1;
       
    vector<int> p(n, 0);
    for (int i = 0; i < n; i += 1)
        p[i] = i;

    sort(p.begin(), p.end(), [&] (int a, int b) {
        return v[a] < v[b];
    });

    int smallest = numeric_limits<int>::max();

    for (int ii = n - 1; ii >= 0; ii -= 1) {
        int i = p[ii];

        if (taken[i])
            continue;

        int left = max(v[i].first, best_l_for_r);
        int right = min(best_r_for_l, smallest);

        ans = max(ans, max(0, (min_r - left + 1)) + max(0, (right - max_l + 1)));
        smallest = min(smallest, v[i].second);
    }

    
    cout << ans << "\n";
}

Measured memory_bytes: 3824
n = int(input())
A = []
wrd = []
for i in range(n):
    a = int(input())
    A.append(a)
    xy = []
    for j in range(a):
        x,y = map(int,input().split())
        xy.append((x,y))
    wrd.append(xy)

def mujunsearch(n,n15,wrd):
    cnt = 0
    s = {}
    for i in range(n):
        if(n15>>i&1) == 1:
            cnt += 1
            for j in wrd[i]:
                x = j[0]
                y = j[1]
                if s.get(x,y) != y:
                    return 0
                else:
                    s[x] = y
    for i in range(n):
        if(n15>>i&1) == 0:
            if s.get(i+1,0) == 1:
                return 0
        else:
            if s.get(i+1,1) == 0:
                return 0
    # print(s)
    # print(bin(n15))
    return cnt

st = 0
for i in range(1<<n):
    st = max(st,mujunsearch(n,i,wrd))
print(st)


Measured memory_bytes: 3064
from sys import stdin


def a(s):
    result = 0
    for c in s[::-1]:
        result += int(c)
    return result


def main():
    N = int(stdin.readline().rstrip())
    print(min([a(str(x)) + a(str(N - x)) for x in range(1, N // 2 + 1)]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3480
#include<iostream>

using namespace std;

int f(int n){
    int retval = 0;

    while(n % 100 == 0){
        n /= 100;
        retval++;
    }

    return retval;
}

int main(){

    int d, n;
    int cnt = 0, ans = 0;

    cin >> d >> n;

    while(cnt != n){
        ans++;
        if(f(ans) == d) cnt++;
    }

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

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  vint a(n);
  bool posi = false;
  rep(i, n) {
    cin >> a[i];
    posi |= a[i] > 0;
  }
  if(!posi) {
    int idx = distance(a.begin(), max_element(all(a)));
    cout << a[idx] << endl;
    vint ans;
    while(idx+1 < n) ans.push_back(n--);
    while(idx > 0) ans.push_back(1), --idx;
    cout << ans.size() << endl;
    rep(i, ans.size()) cout << ans[i] << endl;
    return 0;
  }
  int even = 0;
  rep(i, n) if(!(i&1) && a[i] >= 0) even += a[i];
  int odd = 0;
  rep(i, n) if((i&1) && a[i] >= 0) odd += a[i];
  vector<bool> vec(n, false);
  if(even >= odd) {
    cout << even << endl;
    rep(i, n) if(!(i&1) && a[i] >= 0) vec[i] = true;
  } else {
    cout << odd << endl;
    rep(i, n) if((i&1) && a[i] >= 0) vec[i] = true;
  }
  vint ans;
  while(vec.size() > 1) {
    vector<bool> tmp;
    if(!vec[0]) {
      reps(i, 1, vec.size()) tmp.push_back(vec[i]);
      ans.push_back(1);
    } else if(!vec.back()) {
      rep(i, (int)vec.size()-1) tmp.push_back(vec[i]);
      ans.push_back(vec.size());
    } else {
      reps(i, 1, (int)vec.size()-1) {
	if(vec[i-1] && !vec[i] && vec[i+1]) {
	  rep(j, i-1) tmp.push_back(vec[j]);
	  tmp.push_back(true);
	  reps(j, i+2, vec.size()) tmp.push_back(vec[j]);
	  ans.push_back(i+1);
	  break;
	} else if(!vec[i-1] && !vec[i] && !vec[i+1]) {
	  rep(j, i-1) tmp.push_back(vec[j]);
	  tmp.push_back(false);
	  reps(j, i+2, vec.size()) tmp.push_back(vec[j]);
	  ans.push_back(i+1);
	  break;
	}
      }
    }
    vec.swap(tmp);
  }
  cout << ans.size() << endl;
  rep(i, ans.size()) cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define first fi
#define second se
#define MOD 1000000007
#define MAXN 2003
#define endl "\n"
#define readln(x) getline(cin, x);
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
ll fpow(ll x, ll n, ll mod){if (n==0) return 1%mod; ll u = fpow(x, n/2, mod); u = (u*u)%mod; if (n%2==1)u = (u*x)%mod;return u;}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

int N, X, Y, freq[MAXN];

int main(){
    //freopen("data.txt","r",stdin);
    cin >> N >> X >> Y;
    for (int i = 1; i<N; i++){
        for (int j = i+1; j<=N; j++){
            int sp = min(abs(j-i), min(abs(X-i)+1+abs(Y-j), abs(X-j)+1+abs(Y-i)));
            freq[sp]++;
        }
    }
    for (int i = 1; i<N; i++){
        cout << freq[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, const char* argv[])
{
	string S[3];
	int indices[3] = {0};
	cin >> S[0] >> S[1] >> S[2];
	int t = 0;
	while (indices[t] < S[t].size()) {
		t = S[t][indices[t]++] - 'a';
		//		cout << t << ":" << indices[t] << endl;
	}
	cout << (char)('A' + t) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

P knapsack[105];

signed main(){
  int n,w;
  cin>>n>>w;
  for(int i=1; i<=n; i++){
    cin>>knapsack[i].first>>knapsack[i].second;
  }
  
  int dp[10005];
  for(int i=0; i<=w; i++) dp[i]=0;
  dp[0]=0;
  for(int i=1; i<=n; i++){
    P p=knapsack[i];
    for(int j=w; j>=p.second; j--){
      dp[j]=max(dp[j], dp[j-p.second]+p.first);
      //cout<<"dp["<<j<<"]:   "<<dp[j]<<en;
    }
  }
  
  cout<<*max_element(dp, dp+w+1)<<en;
}




Measured memory_bytes: 3196
S = input()
check = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] not in ['R', 'U', 'D']:
            check = 1
    else:
        if S[i] not in ['L', 'U', 'D']:
            check = 1
if check == 1:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int i[114514];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c,d=0,e,f;
	string s[114514],u;
	cin >>a>>u;
	if(a>=3200) cout <<u<<'\n';
	else cout <<"red\n";
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
int main()
{
    int N;
    std::cin >> N;
    std::vector<int> three_cand{};
    std::vector<int> five_cand{};
    std::vector<int> fifteen_cand{};
    std::vector<int> twenty_five_cand{};
    // 100 / 2
    for (int i : {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}){
        if (N >= i * 2) {
            three_cand.emplace_back(i);
        }
    }
    if (N >= 6) {
        five_cand.emplace_back(2);
    }
    if (N >= 9) {
        five_cand.emplace_back(3);
    }
    // 100 / 4
    for (int i : {5, 7, 11, 13, 17, 19, 23}) {
        if (N >= i * 4) {
            five_cand.emplace_back(i);
        }
    }
    if (N >= 16) {
        fifteen_cand.emplace_back(2);
    }
    if (N >= 30) {
        fifteen_cand.emplace_back(3);
    }
    if (N >= 60) {
        fifteen_cand.emplace_back(5);
    }
    if (N >= 91) {
        fifteen_cand.emplace_back(7);
    }
    if (N >= 28) {
        twenty_five_cand.emplace_back(2);
    }
    if (N >= 54) {
        twenty_five_cand.emplace_back(3);
    }
    if (N >= 100) {
        twenty_five_cand.emplace_back(5);
    }

    int ans = 0;
    // 3 5 5
    for (const auto& th : three_cand) {
        for (const auto& fi : five_cand) {
            if (th != fi) {
                for (const auto& fi2 : five_cand) {
                    if (th != fi2 and fi < fi2) {
                        ans++;
                    }
                }
            }
        }
    }
    // 25 3
    for (const auto& tw : twenty_five_cand) {
        for (const auto& th : three_cand) {
            if (tw != th) {
                ans++;
            }
        }
    }
    // 15 5
    for (const auto& fif : fifteen_cand) {
        for (const auto& fi : five_cand) {
            if (fif != fi) {
                ans++;
            }
        }
    }
    // 75
    if (N >= 78) {
        ans++;
    }

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

Measured memory_bytes: 256
n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]

xy.sort()
if n==1:
    print(1)
    exit()
ans = float('inf')

for i in range(n-1):
    for j in range(i+1,n):
        p = xy[j][0]-xy[i][0]
        q = xy[j][1]-xy[i][1]
        a = 0
        for k in range(n):
            if [xy[k][0]-p, xy[k][1]-q] not in xy:
                a+=1
        ans = min(a,ans)

print(ans)

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

#define for(i, a, b) for(ll (i)=a;(i)<(b);++(i))
#define rep(i, n)    for(i, 0, n)
#define sz(x)        ((ll)(x).size())

const ll inf = 1 << 25;
const ll mod = 1e9 + 7;

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

int main() {
    int N;
    cin >> N;
    
    int max = 0;
    int ans = 1;
    rep(i, N) {
        int cnt = 0;
        int x = i + 1;
        while (x % 2 == 0) x /= 2, cnt++;
        if (max < cnt) {
            max = cnt;
            ans = i + 1;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

vector<ll> a(200001);


int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	if (n == 1){
		cout << 0 << endl;
		return 0;
	}
	sort(a.begin(), a.begin() + n, greater<ll>());
	ll ans = a[0];
	if (n == 2){
		cout << ans << endl;
		return 0;
	}
	int coun = 1;
	for (int i = 1; ; i++){
		ans += a[i];
		coun++;
		if (coun == n-1) break;
		ans += a[i];
		coun++;
		if (coun == n-1) break;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) (v).begin(),(v).end()
#define debug(x) cout << #x << '=' << x << '\n'
const long long MOD=1e9+7;
//const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?'\n':' ');
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;} return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;} return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<pair<ll,int>> A;
    for (int i=0;i<N;++i){
        ll a; cin >> a;
        A.emplace_back(a,i);
    }
    sort(A.begin(),A.end()); reverse(A.begin(),A.end());
    vector<vector<ll>> dp(N+1,vector<ll>(N+1,-IINF));
    dp[0][0]=0;
    for (int i=0;i<N;++i){
        for (int j=0;j<=N;++j){
            chmax(dp[i+1][j+1],dp[i][j]+A[i].first*abs(A[i].second-j));
            chmax(dp[i+1][j],dp[i][j]+A[i].first*abs(A[i].second-N+1+i-j));
        }
    }
    ll ans=0;
    for (int j=0;j<=N;++j) chmax(ans,dp[N][j]);
    cout << ans << '\n';
}

Measured memory_bytes: 34588
main :: IO()
main = getContents >>= putStrLn.solve.formatIn

type Dice  = [String]
formatIn :: String -> [Dice]
formatIn = map words.lines

solve :: [Dice] -> String
solve [[x1,x2,x3,x4,x5,x6],y]
    | y == [x1,x2,x3,x4,x5,x6] = "Yes"
    | y == [x1,x3,x5,x2,x4,x6] = "Yes"
    | y == [x1,x5,x4,x3,x2,x6] = "Yes"
    | y == [x1,x4,x2,x5,x3,x6] = "Yes"
      
    | y == [x2,x6,x3,x4,x1,x5] = "Yes"
    | y == [x2,x3,x1,x6,x4,x5] = "Yes"
    | y == [x2,x1,x4,x3,x6,x5] = "Yes"
    | y == [x2,x4,x6,x1,x3,x5] = "Yes"
      
    | y == [x3,x1,x2,x5,x6,x4] = "Yes"
    | y == [x3,x2,x6,x1,x5,x4] = "Yes"
    | y == [x3,x6,x5,x2,x1,x4] = "Yes"
    | y == [x3,x5,x1,x6,x2,x4] = "Yes"
      
    | y == [x4,x1,x5,x2,x6,x3] = "Yes"
    | y == [x4,x2,x1,x6,x5,x3] = "Yes"
    | y == [x4,x6,x2,x5,x1,x3] = "Yes"
    | y == [x4,x5,x6,x1,x2,x3] = "Yes"
      
    | y == [x5,x1,x3,x4,x6,x2] = "Yes"
    | y == [x5,x3,x6,x1,x4,x2] = "Yes"
    | y == [x5,x6,x4,x3,x1,x2] = "Yes"
    | y == [x5,x4,x1,x6,x3,x2] = "Yes"
      
    | y == [x6,x2,x4,x3,x5,x1] = "Yes"
    | y == [x6,x3,x2,x5,x4,x1] = "Yes"
    | y == [x6,x5,x3,x4,x2,x1] = "Yes"
    | y == [x6,x4,x5,x2,x3,x1] = "Yes"
      
    | otherwise                = "No"

Measured memory_bytes: 3580
#include <stdio.h>
#include <stdlib.h>

int primenumber[1000000];

void SetPrime()
{
	long number, i, j;
	long count = 0, num = 0;

	for ( i = 2 ; i <= 999999 ; i++ )
	{
		if ( primenumber[i] == 0 ){
			for ( j = 2 * i ; j <= 999999 ; j = j + i )
			{
				primenumber[j] = 1;
			}
			primenumber[i] = ++num;
		}
		else 
		{
			primenumber[i] = num;
		}
	}
}

int main()
{
	//int prime[999999];
	int i = 0;
	int n;
	SetPrime();


	while ( scanf( "%d", &n ) != EOF )
	{
		fprintf( stdout, "%d\n", primenumber[n] );
	}

	return 0;
}

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

vector<bool> count(ll n){
    ll x;
    ll i=1;
    if(n==1){
        return vector<bool>(1,true);
    }
    while(true){
        x=i*(i+1)/2;
        if(n<=x) break;
        i++;
    }
    vector<bool> ans(n,false);
    if(x==n){
        rep(j,i){
            ans.at(j)=1;
        }
        return ans;
    }
    vector<bool> ans2(x-n);
    ans2=count(x-n);
    rep(i,x-n){
        ans.at(i)=ans2.at(i);
    }
    rep(j,i){
        if(ans.at(j)==true) ans.at(j)=false;
        else ans.at(j)=true;
    }
    return ans;
}

int main() {
    ll n;
    cin>>n;
    vector<bool> ans(n);
    ans=count(n);
    rep(i,n){
        if(ans.at(i)==true) cout<<i+1<<endl;
    }
}

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<int,int>> a(n);
    vector<pair<int,int>> b(n);

    rep(i,0,n){ cin >> a[i].first; a[i].second = i; }
    rep(i,0,n){ cin >> b[i].first; b[i].second = i; }
    sort(all(a));
    sort(all(b));
    rep(i,0,n){
        if(a[i].first > b[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    rep(i,0,n-1){
        if(a[i+1].first <= b[i].first){
            cout << "Yes" << endl;
            return 0;
        }
    }
    vector<int> perm(n);
    rep(i,0,n) perm[a[i].second] = b[i].second;
    int cur = 0;
    int next;
    rep(i,0,n){
        if(perm[cur] == -1){
            cout << "Yes" << endl;
            return 0;
        }
        next = perm[cur];
        perm[cur] = -1;
        cur = next;
    }
    cout << "No" << endl;

}

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

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


bool cal(pair<string, ll>a, pair<string, ll> b){
    if(a.first == b.first) return a.second > b.second;
    else return a.first < b.first;
}

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

    ll N;
    cin >> N;

    map<pair<string,  ll>, ll> idx;
    vector<pair<string, ll> > dic;

    rep(i, N){
        string s;
        ll score;
        cin >> s >> score;
        dic.pb(mp(s, score));
        idx[mp(s,score)] = i;
    }

    sort(all(dic), cal);

    rep(i, dic.size()){
        cout << idx[mp(dic[i].first, dic[i].second)] + 1 << endl;
    }



    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// Author by Md. Jashim Uddin_RMSTU

#include<bits/stdc++.h>
using namespace std;
#define     sf(a)           scanf("%d",&a)
#define     sff(a,b)        scanf("%d %d",&a,&b)
#define     sfff(a,b,c)     scanf("%d %d %d",&a,&b, &c)
#define     pb              push_back
#define     ll              long  long int
#define     fast            ios_base :: sync_with_stdio(false);cin.tie(0)
#define     pi              2*acos(0)
#define     sp              fixed<<setprecision
#define     lcm(a,b)        (a*b)/gcd(a,b)
#define     gcd(a,b)        _gcd(a,b)

#define     forn(i,n)       for(int i=1;i<=n;i++)
#define     min3(a,b,c)     min(a,min(b,c)
#define     M             32000
map< string,int> m;
map< string,int > ::iterator it;

int main()
{

    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        string s;
        cin>>s;
        m[s]+=1;
    }
    int maxi =0;

for(it = m.begin();it!=m.end();it++ )
{
    if(it->second>maxi)
    {
        maxi = it->second;
    }

}
    
    for(it=m.begin();it!=m.end();it++)
        if(maxi==it->second) cout<<it->first<<endl;

}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
using namespace std;

int main(){ 
  int n;
  cin>>n;
  int c=0,d=0,ans=10000,a,b,x,y;
  rep(i,1,n){
    x=i; y=n-i;
    rep(j,1,6){
      c+=x%10; d+=y%10;
      x/=10; y/=10;
    }
    ans=min(ans,c+d);
    c=0; d=0;
  }
  co(ans);
      
  
  return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        EKnapsack2 solver = new EKnapsack2();
        solver.solve(1, in, out);
        out.close();
    }

    static class EKnapsack2 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int W = in.nextInt();
            long[] dp = new long[(int) 1e5 + 10];
            Arrays.fill(dp, Integer.MAX_VALUE);
            dp[0] = 0;
            for (int i = 0; i < N; i++) {
                long wi = in.nextInt();
                int vi = in.nextInt();
                for (int j = dp.length - vi - 1; j >= 0; j--) {
                    dp[j + vi] = Math.min(dp[j] + wi, dp[j + vi]);
                }
            }
            int ans = 0;
            for (int i = dp.length - 1; i >= 0; i--) {
                if (dp[i] <= W) {
                    out.print(i);
                    return;
                }
            }
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 24916
#include<stdio.h>
int main(void)
{
 int N,D,X,i,Y;
Y=0;
 scanf("%d%d%d",&N,&D,&X);
 for(i=1;i<=N;i++){
 int Ai,Bi;
 scanf("%d",&Ai);
 for(Bi=0;Bi*Ai+1<=D;Bi++){
 }
 Y=Y+Bi; 
 }
printf("%d",Y+X);

 return 0;
}


Measured memory_bytes: 128
w=input()
flag=0
if w[0]=='A' and w.count('C')==1 and w.count('A')==1 and w[1].lower()==w[1] and w[-1].lower()==w[-1]:
    flag+=0
else:
    flag=1    
if w.replace('A','').replace('C','').lower()==w.replace('A','').replace('C',''):
    flag+=0
else:flag=1
if flag:print('WA')
else:print('AC')

Measured memory_bytes: 3188
n,k=map(int,input().split())
r,s,p=map(int,input().split())
l=list(input())
ans=0
v=[0]*n
for i in range(n):
    if i>=k and l[i]==l[i-k] and v[i-k]==1:
            continue
    else:
        v[i]=1
        if l[i]=='s':
            ans+=r
        elif l[i]=='r':
            ans+=p
        else:
            ans+=s
print(ans)    

Measured memory_bytes: 50288
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System.IO;

class Program
{
    static void Main()
    {
        var input = ReadLine().Split();
        int n = int.Parse(input[0]);
        int k = int.Parse(input[1]);

        if (n % k == 0) WriteLine(0);
        else WriteLine(1);
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <functional>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>

using namespace std;
using ll = long long;

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

	vector <vector <int> > hap(n, vector <int>(2));

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

	sort(hap.begin(), hap.end(), [](const vector<int> & x, const vector<int> &y){return x[0] + x[1] > y[0] + y[1]; });

	ll cnt = 0;
	for (int i = 0; i < n; i++)
	{
		if (i % 2 == 0)
		{
			cnt += hap[i][0];
		}
		else
			cnt -= hap[i][1];
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 5760
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    S = list(int(_) for _ in input())
    K = int(input())
    for i in range(len(S)):
        if S[i] == 1 and i+1 == K:
            print(1)
            return
        elif S[i] != 1:
            print(S[i])
            return
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <stdio.h>
#define mod (int)(1e9 + 7)

long long int MOD(long long int a){
	if(a < 0){
		return mod + a % mod;
	}
	else{
		return a % mod;
	}
}

int main(){
	int m, n, i;
	long long int x, y, sumn = 0, summ = 0;
	scanf("%d%d", &n, &m);
	for(i = 1; i <= n; i++){
		scanf("%lld", &x);
		sumn = MOD(sumn + ((2 * i - 1 - n) * x)); 
	}
	for(i = 1; i <= m; i++){
		scanf("%lld", &y);
		summ = MOD(summ + ((2 * i - 1 - m) * y));
	}
	printf("%d\n", (sumn * summ) % mod);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <cmath>
using namespace std;

int main(int argc, const char * argv[]) {
  int n, t, a;
  cin >> n >> t >> a;
  double m = 999999;
  int mIndex = -1;
  int h;
  for(int i = 0; i < n; i++){
    cin >> h;
    if(abs(a - (t - h * 0.006)) < m){
      m = abs(a - (t - h * 0.006));
      mIndex = i;
    }
  }
  cout << mIndex + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;

bool check(string s)
{
  bool ok = true;
  rep(i, s.size())
  {
    if (!(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'))
    {
      ok = false;
      break;
    }
  }
  return ok;
}

int main()
{
  string s;
  int l = 0;
  cin >> s;
  rep(i, s.size())
  {
    rep(j, s.size())
    {
      string s2 = s.substr(i, j + 1);
      if (check(s2))
      {
        l = max(l, (int)s2.size());
      }
    }
  }
  cout << l << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
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; }

using Lint=long long;

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

    int N; cin>>N;
    vector<pair<int,int>> p(N);
    for(int i=0;i<N;i++){
        int l,r; cin>>l>>r;
        p[i]={r,l};
    }
    sort(p.begin(),p.end());
    vector<int> l(N),r(N);
    for(int i=0;i<N;i++){
        tie(r[i],l[i])=p[i];
    }

    int ans=0,last=0;
    for(int i=0;i<N;i++){
        if(last<l[i]){
            ans++,last=r[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4336
N = input()
A = list(map(int, input().split()))

# 偶数はいくつあっても最後にひとつ偶数が残せる
# 奇数が偶数個あったら最後に偶数がひとつ生まれる
# 上二つを消して最後に一つ偶数が生まれる

odd = len(list(filter(lambda x: x % 2 == 1, A)))
print("YES" if odd % 2 == 0 else "NO")


Measured memory_bytes: 14112
object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val r = sc.next match {
      case "Sunny" => "Cloudy"
      case "Cloudy" => "Rainy"
      case "Rainy" => "Sunny"
    }
    println(r)
  }
}


Measured memory_bytes: 25792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
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);
}
int main()
{
    string S;
    cin >> S;
    if (S.size() == 1)
    {
        cout << "YES";
        return 0;
    }
    map<char, int> cnt;
    cnt['a'] = 0;
    cnt['b'] = 0;
    cnt['c'] = 0;
    for (int i = 0; i < S.size(); i++)
    {
        cnt[S[i]]++;
    }

    set<char> s;
    for (char i = 'a'; i <= 'c'; i++)
    {
        s.insert(cnt[i]);
    }

    if (s.size() < 3 and (*max_element(all(s)) - *min_element(all(s))) < 2)
        cout << "YES";
    else
    {
        cout << "NO";
    }

    return 0;
}

Measured memory_bytes: 512
def doc_string():
    """
    I can fly.
    """
while True:
    h,m,s = map(int,raw_input().split())
    if h == -1 and m == -1 and s == -1:
        break
    
    h = h * 3600
    m = m * 60
    time = 120 * 60 - (h + m + s)
    h = str(time / 3600)
    m = str(time % 3600 / 60)
    s = str(time % 3600 % 60)
    if len(h) == 1:
        h = "0" + h
    if len(m) == 1:
        m = "0" + m
    if len(s) == 1:
        s = "0" + s
    print h + ":" + m + ":" + s

    h = str(time * 3 / 3600)
    m = str(time * 3 % 3600 / 60)
    s = str(time * 3 % 3600 % 60)
    if len(h) == 1:
        h = "0" + h
    if len(m) == 1:
        m = "0" + m
    if len(s) == 1:
        s = "0" + s
    print h + ":" + m + ":" + s

Measured memory_bytes: 6304
#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

int main() {
    int n, k;
    string s;
    cin >> n >> s >> k;
    const char key = s[k - 1];
    for (string::iterator i = s.begin(); i != s.end(); ++i)
        putchar(*i == key ? *i : '*');
    cout << endl;
    return 0;    
}


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

int main() {
    string s;
    cin >> s;
    int ans = 0;
    rep(i,4) {
        if(s[i] == '+') ans++;
        else ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
program main
  implicit none
  integer :: N,M
  integer,allocatable :: K(:)
  type a
     integer,allocatable :: in(:)
  end type a
  integer,allocatable :: Aall(:,:)
  type(a),allocatable :: Ain(:)
  logical :: flag
  integer :: out
  integer :: i,j
  read(*,*) N,M
  allocate(K(N))
  allocate(Ain(N))
  allocate(Aall(N,M))
  do i = 1,N
     read(*,*) K(i),Aall(i,1:K(i))
  end do
  do i = 1,N
     allocate(Ain(i)%in(K(i)))
     Ain(i)%in(:) = Aall(i,1:K(i))
  end do
!  do i = 1,N
!     write(*,*) Ain(i)%in(:)
!  end do
  out=0
  do j = 1,M
     flag=.true.
     do i = 1,N
        if ( any( Ain(i)%in(:) == j ) ) then
           continue
        else
           flag=.false.
        end if
     end do
     if ( flag ) out=out+1
  end do
  write(*,'(i0)') out
  deallocate(Aall)
  
  stop
end program main


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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 dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n;
ll a[100100],b[100100];

int main(){
	cin>>n;
	REP(i,n)
		cin>>a[i]>>b[i];
	ll ans=0;
	for(int i=n-1;i>=0;i--){
		a[i]+=ans;
		if(a[i]%b[i]!=0){
			ans+=(b[i]-a[i]%b[i]);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define lb push_back
typedef long long ll;
using namespace std;
const int maxn = 1e6+5;
map<int,int> w;
int main()
{
    int n, k, a; cin >> n >> k;
    for(int i = 1; i <= k; i++) {
        cin >> a;
        w[a] = 1;
    }
    for(int i = n; i <= 100000; i++) {
        a = i;
        int flag1 = 0;
        while(a) {
            int b = a%10;
            if(w[b]) {
                flag1 = 1;
                break;
            }
            a /=10;
        }
        if(!flag1) {
            cout << i << endl;
            return 0;
        }
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Apr 12 21:00:00 JST 2020
 **/

signed main() {
    Int n;
    std::cin >> n;
    Int ans = 0;
    REP(i, 1, n + 1) {
        ans += (i % 3 && i % 5) * i;
    }
    std::cout << ans << std::endl;
}


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



int main(){
    int n,m,q;
    cin >> n >> m >> q;
    int query[50][4];
    rep(i,q) cin >> query[i][0] >> query[i][1] >> query[i][2] >> query[i][3];

    auto score = [&](const int *a){
        int ret = 0;
        rep(i,q){
            int b=query[i][0]-1;
            int c = query[i][1]-1;
            if(a[c]-a[b]==query[i][2]) ret += query[i][3];
        }
        return ret;
    };

    int ans = 0;
    for(int a1=1;a1<=m;a1++){
        for(int a2=a1;a2<=m;a2++){
            for(int a3=a2;a3<=m;a3++){
                for(int a4=a3;a4<=m;a4++){
                    for(int a5=a4;a5<=m;a5++){
                        for(int a6=a5;a6<=m;a6++){
                            for(int a7=a6;a7<=m;a7++){
                                for(int a8=a7;a8<=m;a8++){
                                    for(int a9=a8;a9<=m;a9++){
                                        for(int a10=a9;a10<=m;a10++){
                                            int a[10] = {a1,a2,a3,a4,a5,a6,a7,a8,a9,a10};
                                            ans = max(ans,score(a));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3648
#pragma GCC optimize("Ofast,fast-math,unroll-loops")

#include <bits/stdc++.h>

#define int ll
//#define double long double
//#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
#define PI 3.14159265358979

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
using pld = pair <ld, ld>;

/*
const ll MAX_MEM = 3e8;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/

template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}

template <class T>
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}

template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}

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

inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}
const int P = 1e9 + 7;
int add(int a, int b)
{
    return a + b >= P ? a + b - P : a + b;
}
int mul(int a, int b)
{
    return (a * b) % P;
}
int bpow(int a, int n)
{
    int res = 1;
    while (n)
    {
        if (n & 1)
            res = mul(res, a);
        a = mul(a, a);
        n >>= 1;
    }
    return res;
}
int rev(int x)
{
    return bpow(x, P - 2);
}
int sub(int a, int b)
{
    return a - b >= 0 ? a - b : (a - b + P * P) % P;
}
struct comb
{
    vector <int> fact, revf;
    int N;
    comb() {}
    comb(int _n)
    {
        N = _n;
        fact.resize(N + 1, 1);
        revf.resize(N + 1, 1);
        for (int i = 1; i <= N; ++i)
            fact[i] = mul(fact[i - 1], i), revf[i] = mul(revf[i - 1], rev(i));
    }
    int operator () (int n, int k)
    {
        return mul(fact[n], mul(revf[k], revf[n - k]));
    }
};
signed main()
{
    Start();
    const int N = 1e6 + 1;
    comb c(N);
    int x, y;
    cin >> x >> y;
    if ((x + y) % 3 != 0)
        return cout << 0, 0;
    if (min(x, y) - (x + y) / 3 < 0)
        return cout << 0, 0;
    cout << c((x + y) / 3, min(x, y) - (x + y) / 3);


    return 0;
}




Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define db(x) cout<<#x<<"="<<x<<endl
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //y1 j0 j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
#define EPS 1e(-9);
using namespace std;
typedef long long ll;

struct UnionFind{
  vector<int> par; // 親ノード rootで取得すること
  vector<int> rank;
  vector<ll> nodes;

  UnionFind(int n) {
    par.resize(n); rank.resize(n); nodes.resize(n);
    rep(i,n) {par[i] = i, rank[i] = 0; nodes[i]=1;}
  }

  int root(int x) { //ノードの根を返す
    if (par[x] == x) return x; //親が自分なら自分を返す
    else {
      int r = root(par[x]); //根まで遡りながら経路圧縮
      return par[x] = r;
    }
  }
  bool issame(int x, int y) {
    return root(x) == root(y);
  }
  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (rank[x] < rank[y]) swap(x, y);
    if (rank[x] == rank[y]) ++rank[x];
    par[y] = x; //ランクの小さい方に接続
    return true;
  }
  ll query(int x, int y){
      if(issame(x,y)) return 0;
      ll sum=nodes[root(x)]+nodes[root(y)];
      ll res=nodes[root(x)]*nodes[root(y)];
      merge(x,y);
      nodes[root(x)]=sum;
      return res;
  }
};

void Main(){

  int N,M;
  cin>>N>>M;

  int A[M],B[M];

  UnionFind uf(N);

  rep(i,M){
      cin>>A[i]>>B[i];
      --A[i];--B[i];
  }

  ll ans[M+1]; ll sum=0;
  repr(i,M-1,0){
      ans[i]=uf.query(A[i],B[i]);
  }

  rep(i,M){
      cout<< ans[i]<<"\n";
      ans[i+1]+=ans[i];
  }
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 4480
local n=io.read("n")
local a={}
local xor=0
for i=1,n do
    a[i]=io.read("n")
    xor=xor~a[i]
end

local b={}
for i=1,n do
    b[i]=xor~a[i]
end
print(table.concat(b," "))

Measured memory_bytes: 25564
s = int(input())
ans = [s]

for i in range(1,10**6+1):
    if len(set(ans)) != len(ans):
        print(i)
        break
    if s % 2 != 0:
        s = 3 * s + 1
        ans.append(s)
    else:
        s = s // 2
        ans.append(s)

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

template <typename T> struct SegmentTree {
  struct Node {
    T v;
    Node(T v) : v(v) {}
    Node operator*(const Node &r) const {
      return Node(min(v, r.v));
    }
  };

  Node e = Node((1ll << 31) - 1);
  size_t n;
  vector<Node> seg;

  SegmentTree(size_t size) : n(1 << (32 - __builtin_clz(size - 1))), seg(2 * n, e) {}

  void update(int k, const Node &x) {
    for (seg[k + n] = x, k = (k + n) / 2; k; k >>= 1) {
      seg[k] = seg[2 * k] * seg[2 * k + 1];
    }
  }

  Node query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return e;
    if (a <= l && r <= b) return seg[k];
    return query(a, b, 2 * k, l, (l + r) / 2) * query(a, b, 2 * k + 1, (l + r) / 2, r);
  }

  void update(int k, T x) {
    update(k, Node(x));
  }

  T query(int a, int b) {
    return query(a, b, 1, 0, n).v;
  }
};


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

  SegmentTree<int> seg(n);
  while (q--) {
    int c, x, y;
    cin >> c >> x >> y;

    if (c) {
      cout << seg.query(x, y + 1) << endl;
    } else {
      seg.update(x, y);
    }
  }
}

Measured memory_bytes: 3848
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


#隣接リスト 1-order
def make_adjlist_d(n, edges):
    res = [[] for _ in range(n + 1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
        res[edge[1]].append(edge[0])
    return res


def make_adjlist_nond(n, edges):
    res = [[] for _ in range(n + 1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
    return res


#nCr
def cmb(n, r):
    return math.factorial(n) // math.factorial(r) // math.factorial(n - r)


def main():
    N = NI()
    A = NLI()
    A = sorted(A)

    ma = A[-1]
    hurui = [0] * (ma + 10)
    for a in A:
        if hurui[a] == 0:
            hurui[a] = 1
        else:
            hurui[a] = 10

    for a in A:
        if hurui[a] == 0:
            continue

        for i in range(a*2, ma+10, a):
            hurui[i] = 0

    print(hurui.count(1))



if __name__ == "__main__":
    main()

Measured memory_bytes: 34176
# 初期入力
import sys
input = sys.stdin.readline
N,D = (int(x) for x in input().split())
X =[]
for i in range(N):
    xx = list(map(int, input().split()))
    X.append(xx)

#D次元の距離
from itertools import combinations
import math
count =0
for i in combinations(range(N),2):
    dis_2jou =0
    for d in range(D):
       dis_2jou += (X[i[0]][d] -X[i[1]][d])**2 
    if  math.sqrt(dis_2jou).is_integer():
        count +=1
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <bits/stdc++.h>
 
#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;
 
typedef long long ll;
const ll mod=1e9+7;
 
using pear = pair<int,int>;
 
int main(){
    int n; cin >>n;
    vector<int> l(n);
    rep(i,n) cin >>l[i];
    int ans = 0;
    sort(l.begin(), l.end());
    for(int i = n-1; i >1 ; i--){
        for(int j = i-1; j >=1;j--){
            for(int k = j-1; k >= 0;k--){
                if(l[i]+l[j]>l[k]&&l[i]<l[j]+l[k]&&l[i]+l[k]>l[j]) ans++;
                else continue;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384