akhauriyash/Code-Regression huggingface dataset:
#![allow(dead_code)]

fn main() {
    let n:u32 = read();
    let mut nums:Vec<u32> = read_vec();

    nums.sort();
    let mut sums:u32 = 0;

    for i in 0..n*2 {
        if i % 2==0 {
            let i = i as usize;
            let a = nums[i];
            let b = nums[i+1];

            if a > b {
                sums += b;
            } else {
                sums += a;
            }
        }

    }

    println!("{}", sums);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}


fn read_n<T: std::str::FromStr>(n: u32) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}


Measured memory_bytes: 4352
n = int(input())
l = list(map(int,input().split()))
l = sorted(l)
count = 0

for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if l[i]+l[j]>l[k] and l[i]+l[k]>l[j] and l[j]+l[k]>l[i]:
        if l[i] != l[j] and l[j] != l[k] and l[k] != l[i]:
   	      count += 1
print(count)

Measured memory_bytes: 9136
package main

import (
	"bufio"
	"fmt"
	"math"
	"math/rand"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int
var t float64

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	d := intScanner()
	c := intSliceScanner(26)
	s := make([][]int, d)
	for i := 0; i < d; i++ {
		s[i] = intSliceScanner(26)
	}
	best := -mod
	bestSchedule := make([]int, d)
	for x := 0; x < 5; x++ {
		schedule := make([]int, d)
		for i := 0; i < d; i++ {
			schedule[i] = rand.Intn(26)
		}
		score := calcScore(schedule, c, s, d)
		for y := 0; y < 10000; y++ {
			z := make([]int, d)
			copy(z, schedule)
			change := rand.Intn(d)
			val := rand.Intn(26)
			z[change] = val
			nextScore := calcScore(z, c, s, d)
			t = float64(score) * 0.1
			if prob(score, nextScore) >= math.Abs(rand.Float64()) {
				copy(schedule, z)
				score = nextScore
			}
			if nextScore >= best {
				best = nextScore
				copy(bestSchedule, schedule)
			}
			t *= 0.999
		}
	}
	for i := 0; i < d; i++ {
		fmt.Println(bestSchedule[i] + 1)
	}
}
func calcScore(schedule []int, c []int, s [][]int, d int) int {
	score := 0
	last := make([]int, 26)
	for i, v := range schedule {
		score += s[i][v]
		for j, _ := range last {
			last[j]++
		}
		last[v] = 0
		for j, v := range last {
			score -= c[j] * v
		}
	}
	return score
}
func prob(before int, after int) float64 {
	if before <= after {
		return 1.0
	}
	return math.Exp((float64(after) - float64(before)) / float64(t))
}


Measured memory_bytes: 6336
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>
#include <stack>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

signed main() {
	int a,b,c,k;
	std::cin >> a >> b >> c >> k;
	int ans = 0;
	if(k>=a) {
		ans+=a;
		k-=a;
	} else {
		print(k);
		return 0;
	}
	if(k>=b) {
		k-=b;
	} else {
		print(ans);
		return 0;
	}
	print(ans-k);
	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int G[500+5][500+5];
void dfs(int l,int r,int s){
	if(l==r){
		return ;
	}
	int m=l+r>>1;
	for(int i=l;i<=m;++i){
		for(int j=m+1;j<=r;++j){
			G[i][j]=s;
		}
	}
	dfs(l,m,s+1);
	dfs(m+1,r,s+1);
}
int main(){
	int n;
	cin>>n;
	dfs(1,n,1);
	for(int i=1;i<=n;++i){
		for(int j=i+1;j<=n;++j){
			cout<<G[i][j]<<" ";
		}
		cout<<"\n";
	}
}

Measured memory_bytes: 1536
import fractions
 
k = int(input())
ans = 0

li = [[0]*(k+1) for i in range(k+1)]
for i in range(k+1):
    for j in range(k+1):
        li[i][j] = fractions.gcd(i,j)

for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            x = li[i][j]
            y = li[x][l]
            ans += y
print(ans)

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

using namespace std;

const int N = 105;

struct Data {
  string name;
  int score, id;

  Data(string n, int s, int i) {
    name = n;
    score = s;
    id = i;
  }
};

bool cmp(Data x, Data y) {
  return x.name == y.name ? x.score > y.score : x.name < y.name;
}

vector<Data> a;

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    string s; int x;
    cin >> s >> x;
    a.push_back(Data(s, x, i + 1));
  }
  sort(a.begin(), a.end(), cmp);
  for (int i = 0; i < a.size(); i++) {
    //cerr << a[i].name << " " << a[i].score << endl;
    printf("%d\n", a[i].id);
  }
  return 0;
}


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

int main()
{
  int h,w;
  while(1){
    cin>>h>>w;
    if(h==0&&w==0)break;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if((i+j)%2==0)cout<<'#';
	else cout<<'.';
      }
      cout<<endl;
    }
    cout<<endl;
  }
  return 0;
}

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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);

void header() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

void solve() {
    ll n;
    cin >> n;
    string s = "";
    char ch;
    while (n) {
        n--;
        s += (n % 26 + 'a');
        n /=  26;
    }
    for (int i = s.size() - 1; i >= 0; i--) cout << s[i];
    cout << endl;
}

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


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;

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

const int inf = 1e9 + 1;
const double eps = 1e-9;
const int MAXN = 1e5 + 1;

int n;
int h[MAXN];
int dp[MAXN];

int main(){

    cin >> n;
    for (int i = 0; i < n; i++) cin >> h[i];
    for (int i = 0; i < n; i++) dp[i] = inf;
    dp[0] = 0;
    for (int i = 0; i < n-1; i++){
        dp[i+1] = min(dp[i+1], dp[i]+abs(h[i]-h[i+1]));
        if (i < n-2) dp[i+2] = min(dp[i+2], dp[i]+abs(h[i]-h[i+2]));
    }

    cout << dp[n-1];

    return 0;

}


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

int main(){
  int n;
  cin >> n;
  int p=0,max=0,pi;
  for(int i=0;i<n;i++){
    cin >> pi;
    p+=pi;
    if(max<pi) max=pi;
  }
  cout << p-max/2;
}

Measured memory_bytes: 256
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];
		int flg = 1;
		int count = 0;
		int now = 0;

		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();

			if(now == a[i] & flg == 1) {
				flg = 0;
				count += 1;
			}else {
				flg = 1;
			}

			now = a[i];
		}

		System.out.println(count);


	}
}

Measured memory_bytes: 21588
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#define INF 1000000007
using namespace std;
using P = pair<int, int>;
using ll = long long;
int main(){
	int n,m;
	cin>>n>>m;
	int t=(n-m)*100+m*1900;
	cout<<t*pow(2,m)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
#define Uniq(v) v.erase(unique(All(v)),v.end())
typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
typedef pair<string, int> Psi;
const int INF = (1<<30);
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

int main()
{
  int H, W;
  char A[9][9];
  bool arrive = false;
  int visited_cells = 0;

  cin >> H >> W;
  Rep(i, H) Rep(j, W) {
    cin >> A[i][j];
    if( A[i][j] == '#' ) visited_cells++;
  }
  
  queue<Pip> q;
  bool used[9][9] = {{0}};
  q.push( Pip(1, Pii(0, 0)) );
  while( !q.empty() ) {
    Pip p = q.front(); q.pop();
    int now_cells = p.fr, y = p.sc.fr, x = p.sc.sc;
    if( y == H-1 && x == W-1 && now_cells == visited_cells ) {
      arrive = true;
      break;
    }
    if( used[y][x] ) continue;
    used[y][x] = true;
    if( y+1 < H && A[y+1][x] == '#' ) {
      q.push( Pip(now_cells+1, Pii(y+1, x)) );
    }
    if( x+1 < W && A[y][x+1] == '#' ) {
      q.push( Pip(now_cells+1, Pii(y, x+1)) );
    }
  }

  if( arrive ) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}


Measured memory_bytes: 256
k = "keyence"
S = input()
num = len(k)
rem = len(S) - num

flag = False
if S == k:
    flag = True

for i in range(len(S)-rem):
    if S[0:i] + S[i+rem:] == k:
        flag = True
if flag:
    print("YES")
else:
    print("NO")


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


int main(){
    int n;
    cin >> n;
    vector<ll> v(5);
    rep(i,n){
        string s;
        cin >> s;
        if(s.front()=='M') v[0]++;
        if(s.front()=='A') v[1]++;
        if(s.front()=='R') v[2]++;
        if(s.front()=='C') v[3]++;
        if(s.front()=='H') v[4]++;
    }
    ll ans = 0;
    for(int i=0; i<5; i++){
        for(int j=i+1; j<5; j++){
            for(int k=j+1; k<5; k++){
                ans += v[i]*v[j]*v[k];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define LL long long
#define FOR(i,c) for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define F first
#define S second
using namespace std;

const LL mod = 1e9 + 7;

template<typename T> T gcd(T a, T b) { return b == 0?a: gcd(b, a % b); }
template<typename T> T LCM(T a, T b) { return a*(b/gcd(a, b)); }
template<typename T, typename S> T expo(T b, S e, const T &m){if(e <= 1)return e == 0?1: b;\
	return (e&1) == 0?expo((b*b)%m, e>>1, m): (b*expo((b*b)%m, e>>1, m))%m;}
template<typename T, typename S> T expo(T b, S e){if(e <= 1)return e == 0?1: b;\
	return (e&1) == 0?expo((b*b), e>>1): (b*expo((b*b), e>>1));}
template<typename T, typename S> T modinv(T a, S mod) { return expo(a, mod-2, mod); }
template<class T, class S> std::ostream& operator<<(std::ostream &os, const std::pair<T, S> &t) {
	os<<"("<<t.first<<", "<<t.second<<")";
	return os;
}
template<class T> std::ostream& operator<<(std::ostream &os, const std::vector<T> &t) {
	os<<"["; FOR(it,t) { if(it != t.begin()) os<<", "; os<<*it; } os<<"]";
	return os;
}
int main() {
  ios_base::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  if(a == b) {
    cout << "Draw" << endl;
  } else if(a == 1 || b == 1) {
    if(a == 1) cout << "Alice" << endl;
    else cout << "Bob" << endl;
  } else if(a > b) {
    cout << "Alice" << endl;
  } else {
    cout << "Bob" << endl;
  }
  return 0;
}


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

using ll = long long;
const ll INF = ll(1e18)+1;

int main(){
    int n; ll k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    ll l = -INF, r = INF;

    while(l+1<r){
        ll m = (l+r)/2;
        ll tot = 0;
        rep(i,n){
            if (a[i]>=0){
                int right=n; int left=-1;
                int mid = (right+left)/2;
                while(left+1<right){
                    mid = (right+left)/2;
                    if (a[i]*a[mid]<m) left=mid;
                    else right=mid;
                }
                tot +=right;
            }
            else{
                int right=n; int left=-1;
                int mid = (right+left)/2;
                while(left+1<right){
                    mid = (right+left)/2;
                    if (a[i]*a[mid]<m) right=mid;
                    else left=mid;
                }
                 tot +=n-right;
            }
            if (a[i]*a[i]<m) tot--;
        }
        tot/=2;

        if (tot<k) l = m;
        else r = m;
    }

    cout << l << endl;
}

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

    using namespace std;
    using namespace std::chrono; 

    typedef long long int ll;

    #define MOD (ll)(1e9+7)
    #define endl "\n"
    #define pb push_back
    #define TEST_CASES  ll t;cin>>t;while(t--)
    #define forn(i,a,n) for (int i = a; i < n; ++i)
    #define f first
    #define s second
    #define all(x) x.begin(), x.end()

    void __print(int x) {cerr << x;}
    void __print(long x) {cerr << x;}
    void __print(long long x) {cerr << x;}
    void __print(unsigned x) {cerr << x;}
    void __print(unsigned long x) {cerr << x;}
    void __print(unsigned long long x) {cerr << x;}
    void __print(float x) {cerr << x;}
    void __print(double x) {cerr << x;}
    void __print(long double x) {cerr << x;}
    void __print(char x) {cerr << '\'' << x << '\'';}
    void __print(const char *x) {cerr << '\"' << x << '\"';}
    void __print(const string &x) {cerr << '\"' << x << '\"';}
    void __print(bool x) {cerr << (x ? "true" : "false");}

    template<typename T, typename V>
    void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
    template<typename T>
    void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
    void _print() {cerr << "]\n";}
    template <typename T, typename... V>
    void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
    #ifndef ONLINE_JUDGE
    #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
    #else
    #define debug(x...)
    #endif

    ll powD(ll x,ll y){
      ll res = 1;
      while(y > 0){
        if(y & 1)
          res = (res*x)%MOD;
        x = (x*x)%MOD;
        y = y>>1;
      }
      return res;
    }
    /*CHECK FOR CORNER CASES FOR GOD'S SAKE*/
    int main()
    {
      //freopen("dislodging_logs_validation_input.txt", "r", stdin);
      //freopen("output.txt", "w", stdout);
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int h,w,m;
      cin>>h>>w>>m;
      vector<int> x(h,0),y(w,0);
      map<pair<int,int>,bool> targets;
      vector<pair<int,int>> t;
      forn(i,0,m){
          int u,v;
          cin>>u>>v;
          u--;v--;
          targets[{u,v}] = 1;
          x[u]++;
          y[v]++;
          t.push_back({u,v});
      }
      int maxx = *max_element(all(x));
      int maxy = *max_element(all(y));
      vector<int> xcandi,ycandi;
      forn(i,0,h){
        if(maxx == x[i])
          xcandi.push_back(i);
      }
      forn(j,0,w){
        if(maxy == y[j])
          ycandi.push_back(j);
      }
      ll a = xcandi.size();
      ll b = ycandi.size();
      if(a*b > m){
        cout<<maxy+maxx<<endl;
      }
      else{
        bool flag = 0;
        for(auto i : xcandi){
          for(auto j : ycandi){
            if(!targets[{i,j}])
              flag = 1;
          }
        }
        if(flag)
          cout<<maxx+maxy<<endl;
        else
          cout<<maxx+maxy-1<<endl;
      }
  } 



     
    


Measured memory_bytes: 30932
#include <iostream>
using namespace std;
int main(void){
    int E,Y;
    cin >> E >> Y;
    if(E==0){
        if(Y>=1868&&Y<=1911){
            Y=Y-1867;
            cout << "M"<<Y<<endl;
        }
        else if(Y>=1912&&Y<=1925){
            Y=Y-1911;
            cout << "T"<<Y<<endl;
        }
        else if(Y>=1926&&Y<=1988){
            Y=Y-1925;
            cout << "S"<<Y<<endl;
        }
        else if(Y>=1989&&Y<=2016){
            Y=Y-1988;
            cout << "H"<<Y<<endl;
        }
    }
    if(E==1){
        Y=Y+1867;
        cout << Y << endl;
    }
    if(E==2){
        Y=Y+1911;
        cout << Y << endl;
    }
    if(E==3){
        Y=Y+1925;
        cout << Y << endl;
    }
    if(E==4){
        Y=Y+1988;
        cout << Y << endl;
    } 
     
}


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

int main(){
  int n;
  cin >> n;
  std::vector<int>v(n);
  
  for(int i=0;i<n;++i)
    cin >> v[i];
    
  std::sort(v.begin(),v.end());
  int a=0;
  int b=0;
  
  for(int i=0;i<n;++i){
    if(i%2!=0)
      a += v[n-1-i];
    else
      b += v[n-1-i];
  }
  
  cout << b-a << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define IN freopen("in.txt", "r", stdin);
#define OUT freopen("out.txt","w",stdout);
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
const int inf = 0x3f3f3f3f;


int main(){
    IOS;
    string s;cin>>s;
    cout<<s.substr(0,3)<<endl;



    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template <typename T,typename E>
struct SegmentTree{
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H = function<E(E,E)>;
  using P = function<E(E,size_t)>;
  int n;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  P p;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(int n_,F f,G g,H h,T ti,E ei,
	      P p=[](E a,size_t b){b++;return a;}):
    f(f),g(g),h(h),ti(ti),ei(ei),p(p){
    init(n_);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,ti);
    laz.clear();
    laz.resize(2*n-1,ei);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  inline void eval(int len,int k){
    if(laz[k]==ei) return;
    if(k*2+1<n*2-1){
      laz[k*2+1]=h(laz[k*2+1],laz[k]);
      laz[k*2+2]=h(laz[k*2+2],laz[k]);
    }
    dat[k]=g(dat[k],p(laz[k],len));
    laz[k]=ei;
  }
  T update(int a,int b,E x,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return dat[k];
    if(a<=l&&r<=b){
      laz[k]=h(laz[k],x);
      return g(dat[k],p(laz[k],r-l));
    }
    return dat[k]=f(update(a,b,x,k*2+1,l,(l+r)/2),
		    update(a,b,x,k*2+2,(l+r)/2,r));
  }
  T update(int a,int b,E x){
    return update(a,b,x,0,0,n);
  }
  T query(int a,int b,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return ti;
    if(a<=l&&r<=b) return dat[k];
    T vl=query(a,b,k*2+1,l,(l+r)/2);
    T vr=query(a,b,k*2+2,(l+r)/2,r);
    return f(vl,vr);
  }
  T query(int a,int b){
    return query(a,b,0,0,n);
  }
  void update(int k,T x){
    query(k,k+1);//evaluate
    k+=n-1;
    dat[k]=x;
    while(k){
      k=(k-1)/2;
      dat[k]=f(dat[k*2+1],dat[k*2+2]);
    }
  }
};
//END CUT HERE
signed main(){
  int n,q;
  cin>>n>>q;
  SegmentTree<Int,Int> ch(n,
			  [](Int a,Int b){return a+b;},
			  [](Int a,Int b){return a+b;},
			  [](Int a,Int b){return a+b;},
			  0,0,
			  [](Int a,Int b){return a*b;});
  ch.build(n,vector<Int>(n,0));
  for(int i=0;i<q;i++){
    int c,s,t,x;
    cin>>c;
    if(c){
      cin>>s>>t;
      cout<<ch.query(s-1,t)<<endl;
    }else{
      cin>>s>>t>>x;
      ch.update(s-1,t,x);
    }
  }
}

/*
  verified on 2018/03/04
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_G
*/



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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;




void one_case() {
    string line;
    cin >> line;
    cout << (line != "ABC" ? "ABC\n" : "ARC\n");
}

int main() {
//    std::ios::sync_with_stdio(false);
//    std::cin.tie(nullptr);

    int t = 1;
//    cin >> t;
    while (t--) {
       one_case();
    }

    return 0;
}


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

int main(){
    int num_query;
    cin >> num_query;
    list<int> int_list;
    list<int>::iterator itr = int_list.end();
    for(int i = 0;i < num_query;i++){
        int command, val;
        scanf("%d",&command);
        if(command == 0){ // insert
            scanf("%d",&val);
            itr = int_list.insert(itr--,val);
            
        }else if(command == 1){ // mov iterator
            scanf("%d",&val);
            if(val > 0){
                for(int i = 0; i < val;i++) itr++;
            }else if(val < 0){
                for(int i = val; i < 0;i++) itr--;
            }
        }else if(command == 2){ // erase element
            itr = int_list.erase(itr);
        } 
    }
    
    for(list<int>::iterator i = int_list.begin(); i!= int_list.end();i++){
        printf("%d\n",*i);
    }
    return 0;   
}


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

int main() {
    int A, B, C, K,sum;
    sum = 0;
    cin >> A >> B >> C >> K;
    for (int i = 0; i < K; i++){
        if(A == K){
            sum =A;
            break;
        }
        if(A > 0){
            sum ++;
            A--;
        }else if(B > 0){
            B--;
        }else{
            C--;
            sum --;
        }
    }
    cout << sum << endl;
}


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

int main () {
    int n,a,b;
    cin >> n>> a >> b;
    int bus = n*a;
    int taxi = b;
    if (bus < taxi){
        cout << bus;
    } else if (taxi < bus){
        cout << taxi;
    } else if (taxi == bus){
        cout << taxi;
    }
    return 0;
}

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

public class Main {

	private class DisjointSet {
		
		int[] p, rank;
		
		public DisjointSet(int size) {
			p = new int[size];
			rank = new int[size];
			for (int i = 0; i < size; i++) {
				makeSet(i);
			}
		}

		private void makeSet(int x) {
			p[x] = x;
			rank[x] = 0;
		}
		
		public boolean same(int x, int y) {
			return findSet(x) == findSet(y);
		}

		private int findSet(int x) {
			if (p[x] != x) {
				p[x] = findSet(p[x]);
			}
			return p[x];
		}
		
		public void unite(int x, int y) {
			link(findSet(x), findSet(y));
		}

		private void link(int x, int y) {
			if (rank[x] > rank[y]) {
				p[y] = x;
			} else {
				p[x] = y;
				if (rank[x] == rank[y]) {
					rank[y]++;
				}
			}
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(reader.readLine());
		int n = Integer.parseInt(st.nextToken());
		DisjointSet ds = new DisjointSet(n);
		int q = Integer.parseInt(st.nextToken());
		for (int i = 0; i < q; i++) {
			st = new StringTokenizer(reader.readLine());
			int c = Integer.parseInt(st.nextToken());
			int x= Integer.parseInt(st.nextToken());
			int y = Integer.parseInt(st.nextToken());
			if (c == 0) {
				ds.unite(x, y);
			} else {
				System.out.println(ds.same(x, y)?"1":"0");
			}
		}
		reader.close();
	}
}



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

int main(){
    int H,W;
    while(1){
        cin>>H>>W;
        if(H == 0 && W == 0)break;
        for(int a = 1;a <= H;a++){
            for(int b = 1;b <= W;b++){
                if((a + b) % 2 == 0){
					cout<<"#";
				}else{
					cout<<".";
                }
            }
            cout<<endl;
        }
        cout<<endl;
    }

    return 0;
}



Measured memory_bytes: 3104
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    println(problem070a(n))
}

fun problem070a(n: Int): String {
    return n.toString().let { if (it[0] == it[2]) "Yes" else "No" }
}

Measured memory_bytes: 29348
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++) cin>>h[i];
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]) ,dp[i-2]+abs(h[i]-h[i-2]));
    cout<<dp[n-1];
}

Measured memory_bytes: 4392
#include<stdio.h>

char map[50][50];
int w,h;

void areaw(int x,int y)
{
  if(x+1<h){
    if(map[x+1][y] == '.'){
			map[x+1][y] = 'w';
			areaw(x+1,y);
    }else if(map[x+1][y]=='b'){
			map[x+1][y] = 'o';
			areaw(x+1,y);
    }
  }
  if(y+1<w){
    if(map[x][y+1] == '.'){
			map[x][y+1] = 'w';
			areaw(x,y+1);
    }else if(map[x][y+1]=='b'){
			map[x][y+1] = 'o';
			areaw(x,y+1);
    }
  }
  if(x-1>=0){
    if(map[x-1][y] == '.'){
			map[x-1][y] = 'w';
			areaw(x-1,y);
    }else if(map[x-1][y]=='b'){
			map[x-1][y] = 'o';
			areaw(x-1,y);
    }
  }
  if(y-1>=0){
    if(map[x][y-1] == '.'){
			map[x][y-1] = 'w';
			areaw(x,y-1);
    }else if(map[x][y-1]=='b'){
			map[x][y-1] = 'o';
			areaw(x,y-1);
    }
  }
}

void areab(int x,int y)
{
  if(x+1<h){
    if(map[x+1][y] == '.'){
			map[x+1][y] = 'b';
			areab(x+1,y);
   	}else if(map[x+1][y]=='w'){
			map[x+1][y] = 'o';
			areab(x+1,y);
    }
  }
  if(y+1<w){
    if(map[x][y+1] == '.'){
			map[x][y+1] = 'b';
			areab(x,y+1);
    }else if(map[x][y+1]=='w'){
			map[x][y+1] = 'o';
			areab(x,y+1);
    }
  }
  if(x-1>=0){
    if(map[x-1][y] == '.'){
			map[x-1][y] = 'b';
			areab(x-1,y);
    }else if(map[x-1][y]=='w'){
			map[x-1][y] = 'o';
			areab(x-1,y);
    }
  }
  if(y-1>=0){
    if(map[x][y-1] == '.'){
			map[x][y-1] = 'b';
			areab(x,y-1);
    }else if(map[x][y-1]=='w'){
			map[x][y-1] = 'o';
			areab(x,y-1);
    }
  }
} 

int main(void)
{
  int i,j;
  int black,white;

  while(1){
    scanf("%d %d ",&w,&h);
    if(w==0 && h==0)break;

    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
				scanf("%c ",&map[i][j]);
      }
    }

    for(i=0;i<h;i++){
    	for(j=0;j<w;j++){
    		if(map[i][j]=='W')areaw(i,j);
    		if(map[i][j]=='B')areab(i,j);
    	}
    }
    
    white = 0;
    black = 0;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
				if(map[i][j]=='w')white++;
				if(map[i][j]=='b')black++;
      }
    }
    printf("%d %d\n",black,white);

  }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<iostream>
using namespace std;
int main(void)
{
  	int a;
  	cin >> a;
  	int cnt=0;
  	for(int i=1;i<=a;i++)
      	if(i%2) cnt++;
  	double d;
  	d=1.0*cnt/a;
  	printf("%.10lf" ,d);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

ll csf[500][3] = {};

int main(){
    ll n, c, s, f, rm, i, j;
    cin >> n;
    for(i=1; i<n; i++){
        cin >> csf[i][0] >> csf[i][1] >> csf[i][2];
    }
    for(j = 0; j<n; j++){
        ll tm_arr[500] = {};
        for(i=j+1; i<n; i++){
            c = csf[i][0]; s = csf[i][1]; f = csf[i][2];
            if(tm_arr[i-1] < s){
                tm_arr[i] = s+c;
            }else{
                rm = (tm_arr[i-1]-s) % f;
                tm_arr[i] = tm_arr[i-1]+c;
                if(rm != 0){
                    tm_arr[i] += f - rm;
                }
            }
        }
        cout << tm_arr[n-1]-tm_arr[j] << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int64_t dp[101][100001];
 
int64_t recurse(auto& v, auto& w, int64_t i, int64_t m) {
    if(i < 0 or m <= 0) return 0;
	int64_t& state = dp[i][m];
  	if(state != -1) return state;
  	state = numeric_limits<int64_t>::min();
  	if(m >= w[i]) {
    	state = max(state, recurse(v, w, i - 1, m - w[i]) + v[i]);
    }
  	state = max(state, recurse(v, w, i - 1, m));
    return state;
}
 
signed main() {
  	int64_t n, m; cin >> n >> m;
  	vector<int64_t> v(n), w(n);
  	for(int i = 0; i < n; ++i) {
  	    cin >> w[i] >> v[i];
  	}
  	memset(dp, -1, sizeof dp);
 	cout << recurse(v, w, n - 1, m);
	return 0;
}


Measured memory_bytes: 79104
import sys,collections,math,random,fractions,bisect;sys.setrecursionlimit(10**7)
sr = sys.stdin.readline; P = print; P2 = lambda x: print(*x, sep="\n")
def I(i=0): t = [int(x)-i for x in sr().split()];return t
def S(): t = sr().split(); return t if len(t) > 1 else t[0]
L1,L2,L3,L4, = [],[],[],[]
 
N, = I()
d = collections.defaultdict(int)
for _ in range(N):
    d[S()] += 1
maxvalue = max(d.values())
d = sorted(d.items(),key=lambda x: x[1])
d = sorted(d)
for e in d:
    if e[1] == maxvalue:
        print(e[0])

Measured memory_bytes: 45604
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var n,m int
    fmt.Scan(&n,&m)
    a := scanString(n)
    b := scanString(m)
    ans := "No"
    for i:=0;i<n-m+1;i++{
        for j:=0;j<n-m+1;j++{
            flg := true
            for y:=0;y<m;y++{
                for x:=0;x<m;x++{
                    if a[i+y][j+x]!=b[y][x]{
                        flg = false
                    }
                }
            }
            if flg{
                ans = "Yes"
            }
        }
    }
    fmt.Println(ans)
}





// Pairsort
type Pair struct {
    first,second int64
}

type By func(p1, p2 *Pair) bool

func (by By) Sort(pairs []Pair) {
    ps := &pairSorter{
            pairs : pairs,
            by: by,
    }
    sort.Sort(ps)
}

type pairSorter struct {
    pairs []Pair
    by func(p1, p2 *Pair) bool
}

func (s *pairSorter) Len() int {
    return len(s.pairs)
}

func (s *pairSorter) Swap(i, j int) {
    s.pairs[i], s.pairs[j] = s.pairs[j], s.pairs[i]
}

func (s *pairSorter) Less(i, j int) bool {
    return s.by(&s.pairs[i], &s.pairs[j])
}

func first (p1, p2 *Pair) bool {
        return p1.first < p2.first
}

func second (p1, p2 *Pair) bool {
        return p1.second < p2.second
}
// end



func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func makeTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func sortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}

func reverseString(s string) string{
    t := []rune(s)
    for i,j := 0, len(s)-1 ; i < j ; i, j = i+1, j-1 {
        t[i], t[j] = t[j], t[i]
    }
    return string(t)
}

func inside(h,w,H,W int) bool{
    if h>=0 && h<H && w>=0 && w<W{
        return true
    }
    return false
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N;
    string s, t;
    cin >> N >> s >> t;
    string s1, t1;
    for (int i = N; i >= 0; i--)
    {
        s1 = s.substr(N - i, i);
        t1 = t.substr(0, i);
        if (s1 == t1)
        {
            cout << 2 * N - i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using lint = long long;
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define Rep(i, n) for (int i = int(n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { int to; double cost; };
using P = pair<lint, lint>;
using D = pair<double, double>;
using DI = pair<double, int>;
//const lint mod = 998244353LL;
const lint mod = 1000000007LL;
const lint inf = 3LL * mod * mod;

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

lint modpow(lint x, lint n, lint m) {
	lint ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (m <= ans) ans %= m;
		}
		x *= x;
		if (m <= x) x %= m;
		n >>= 1;
	}
	return ans;
}

lint fact[1000000];
void f_init(lint n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint inver[1000000]; bool inve[100000];
lint inv(lint x) {
	if (x == 0) return 0;
	else if (inve[x]) return inver[x];
	else {
		inve[x] = true;
		return inver[x] = modpow(x, mod - 2, mod);
	}
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * inv(fact[n - r]) % mod * inv(fact[r]) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

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

lint lcm(lint a, lint b) { return a / gcd(a, b) * b; }

bool pri(lint p) {
	for (lint i = 2; i * i <= p; i == 2 ? ++i : i += 2) if (p % i == 0) return false;
	return p > 1;
}

map<lint, lint> factring(lint n) {
	map<lint, lint>ans;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

double dis(D a, D b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); }

lint n, cnt;
int main() {
	cin >> n;
	if (n & 1) cout << 0 << endl;
	else {
		for (lint i = 10; i <= n; i *= 5) {
			cnt += n / i;
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 305
#define inf (long long)1e16
int n;
long long dp[maxn][maxn];
vector<pair<int,pair<int,int> > > a;
main() {
    int i,j,x,y,u,v;
    long long len,ans;
    scanf("%d",&n);
    for(i=1;i<=n;i++) {
        for(j=1;j<=n;j++) {
            scanf("%d",&x);
            a.push_back({x,{i,j}});
            if(i!=j) dp[i][j] = inf;
        }
    }
    sort(&a[0],&a[n*n]);
    ans = 0;
    for(i=0;i<n*n;i++) {
        x = a[i].second.first; y = a[i].second.second;
        len = dp[x][y];
        if(len<a[i].first) {
            printf("-1");
            return 0;
        }
        if(len>a[i].first) {
            for(u=1;u<=n;u++) {
                for(v=1;v<=n;v++) {
                    dp[u][v] = min(dp[u][v], dp[x][u] + dp[v][y] + a[i].first);
                    dp[u][v] = min(dp[u][v], dp[x][v] + dp[u][y] + a[i].first);
                }
            }
            ans += a[i].first;
        }
    }
    printf("%lld",ans);
}


Measured memory_bytes: 2424
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
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 main()
{
  string s ;
  cin >> s ;
  if(s=="Sunny"){
    cout <<"Cloudy"<<endl ;
  }
  else if(s=="Cloudy"){
    cout <<"Rainy"<<endl ;
  }
  else{
    cout <<"Sunny"<<endl ;
  }


  return 0 ;
}



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

int main() {
	int n,day[1000]={};
	cin>>n;
	for(int i=0; i<n; i++){
		cin>>day[i];
	}
	for(int i=n-1; i>=0; i--){
		if (i!=n-1){
			cout<<" ";
		}
		cout<<day[i];
	}
	cout<<endl;
}


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

using namespace std;

// 入力
int N, M, Q;
vector<long long> a, b, c, d;

// A[b[i]] - A[a[i] == d[i]ならスコアを加算する。
// スコアの最大値を求める
// 再帰を用いた全探索を行う
// 単調増加なら選択肢が減る O(M^N)
long long dfs(vector<long long> & A) {
	if (A.size() == N) {
		// スコア計算
		long long sum = 0;
		for (int i = 0; i < Q; i++) {
			if (A[b[i]] - A[a[i]] == c[i]) {
				sum += d[i];
			}
		}
		return sum;
	}

	// 単調増加数列を生成
	long long res = 0;
	int prev_last = (A.empty() ? 0 : A.back());
	for (int i = prev_last; i < M; i++) {
		A.push_back(i);
		res = max(res, dfs(A)); // 再帰呼び出ししながらスコア最大値を更新
		A.pop_back();
	}
	return res;
}

int main(void) {
	cin >> N >> M >> Q; // 数列の長さN, 数列の取りうる値M, 数列の組数Q
	a.resize(Q); b.resize(Q); c.resize(Q); d.resize(Q);
	for (int q = 0; q < Q; q++) {
		cin >> a[q] >> b[q] >> c[q] >> d[q];
		--a[q]; --b[q]; // 0-indexに変換
	}

	// スコア最大値を計算する
	vector<long long> A;
	cout << dfs(A) << endl;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

ll modpow(ll x, ll n, const ll mo) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) (res *= x) %= mo;
		(x *= x) %= mo;
		n >>= 1;
	}
	return res;
}

ll inverse(ll x, const ll mo) {
	return modpow(x, mo - 2, mo);
}

vector<ll> lagrange_interpolation(vector<ll> xs, vector<ll> ys, const int mo) {
	const int n = xs.size();
	for (int i = 0; i < n; ++i) {
		xs[i] %= mo;
		ys[i] %= mo;
	}
	vector<ll> all_c(n + 1);
	all_c[0] = 1;
	for (int i = 0; i < n; ++i) {
		vector<ll> nxt(n + 1);
		for (int j = 0; j < n; ++j) {
			nxt[j + 1] = all_c[j];
		}
		for (int j = 0; j < n; ++j) {
			nxt[j] = (mo + nxt[j] - xs[i] * all_c[j] % mo) % mo;
		}
		all_c = move(nxt);
	}

	vector<ll> c(n);
	for (int i = 0; i < n; ++i) {
		ll qi = 1;
		for (int j = 0; j < n; ++j) {
			if (i == j) continue;
			qi = qi * (mo + xs[i] - xs[j]) % mo;
		}
		qi = inverse(qi, mo) * ys[i] % mo;

		auto tmp_c = all_c;
		for (int j = n - 1; j >= 0; --j) {
			c[j] = (c[j] + qi * tmp_c[j + 1]) % mo;
			tmp_c[j] = (tmp_c[j] + tmp_c[j + 1] * xs[i]) % mo;
		}
	}
	return c;
}

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

	int P;
	cin >> P;
	vector<int> xs(P), ys(P);
	rep(i, 0, P)
	{
		cin >> ys[i];
		xs[i] = i;
	}

	auto ans = lagrange_interpolation(xs, ys, P);

	for (auto& v : ans)
	{
		cout << v << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <unordered_set>

using namespace std;

int main(){
  unordered_set<int> trick;
  int N, K, a, d;
  cin >> N >> K;
  for (int i=0; i<N; i++){
    trick.insert(i);
  }
  for (int i=0; i<K; i++){
    cin >> d;
    for (int j=0; j<d; j++){
      cin >> a; a--;
      if (trick.find(a) != trick.end()){
        trick.erase(a);
      }
    }
  }
  cout << trick.size() << "\n";
  return 0;
}

Measured memory_bytes: 3604
def _comb(n, count = 3)
  return [n] if count == 1

  (1..(n-1)).to_a.reverse.flat_map{|e|
    _comb(e, count - 1).map{|z|
      [n, *z]
    }
  }
end

def comb(n)
  (1..n).to_a.reverse.flat_map{|e|
    _comb(e)
  }
end

loop {
  n, x = gets.split.map(&:to_i)
  break if n == 0 && x == 0

  puts comb(n).map(&:sum).count(x)
}


Measured memory_bytes: 25020
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair




int main(){
    ll n,d,x;
    cin>>n>>d>>x;
    ll count=0;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        count+=d/a;
        if(d%a){count++;}
    }
    cout<<count+x<<endl;
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lint long long
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
using namespace std;

// cout << fixed << setprecision(12)

int main(){
  int N;
  cin >> N;
  vector<lint> A(N,0);
  lint ans = 1;
  //bool plus = true;
  for(int i=0; i<N; i++){
    cin >> A[i];
    if(A[i]==0){
      ans = 0;
      //plus = false;
      break;
    }
  }
  if(ans!=0){
    for(int i=0; i<N; i++){
      if(A[i] > 1000000000000000000/ans){
        ans = -1;
        break;
      }
      ans *= A[i];
    }
  }

  
  cout << ans << endl;
}
    


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

int a[3][3];
int b[3][3];

void mark(int x) {
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            if(a[i][j] == x) b[i][j] = 1;
        }
    }
}

bool check() {
    if(b[0][0] == 1 && b[0][1] == 1 && b[0][2] == 1) return true;
    else if(b[1][0] == 1 && b[1][1] == 1 && b[1][2] == 1) return true;
    else if(b[2][0] == 1 && b[2][1] == 1 && b[2][2] == 1) return true;
    else if(b[0][0] == 1 && b[1][0] == 1 && b[2][0] == 1) return true;
    else if(b[0][1] == 1 && b[1][1] == 1 && b[2][1] == 1) return true;
    else if(b[0][2] == 1 && b[1][2] == 1 && b[2][2] == 1) return true;
    else if(b[0][0] == 1 && b[1][1] == 1 && b[2][2] == 1) return true;
    else if(b[2][0] == 1 && b[1][1] == 1 && b[0][2] == 1) return true;
    else return false;
}

int main() {
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> a[i][j];
            b[i][j] = 0;
        }
    }
    int n; cin >> n;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        mark(x);
    }

    if(check()) {
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    bool res = false;
    while (n) {
        if (n % 10 == 7) {
            res = true;
            break;
        }
        n /= 10;
    }
    cout << (res ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 3612