akhauriyash/Code-Regression huggingface dataset:
# abc120_d.py
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

N, M = map(int,input().split())
glaph = []
for i in range(M):
    A, B = map(int,input().split())
    glaph.append((A,B))
glaph.reverse()

ans = []
ans.append(N*(N-1)//2)
uf = UnionFind(N)
for i,v in enumerate(glaph):
    a,b = v
    if uf.isSameGroup(a,b):
        ans.append(ans[i])
    else:
        ans.append(ans[i] - uf.Count(a)*uf.Count(b))
    uf.Unite(a,b)
ans.reverse()
for i in range(1,M+1):
    print(ans[i])

Measured memory_bytes: 27984
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    
	int n, v;
	cin >> n >> v;
	
	//隣接テーブルをつくる
	int tab[n][n] = {};
	REP(i,v){
		int sta, goa;
		cin >> sta >> goa;
		sta--; goa--; //1オリジン→0オリジンにする行
		tab[sta][goa]++;
		tab[goa][sta]++;
	}
	//
	bool ch[n];
	queue<int> q;
	int nowtab[n][n];
	REP(i, n){
		for(int j = i+1; j < n; j++){
			if(tab[i][j] == 0) continue;
			else{
				REP(x, n) REP(y, n) nowtab[x][y] = tab[x][y];
				nowtab[i][j] = 0;
				nowtab[j][i] = 0;
				q.push(0);
				REP(x, n) ch[x] = false;
				while (q.size()>0)
				{
					tmp = q.front();
					ch[tmp] = true;
					REP(x, n) {
						if(!ch[x] && nowtab[tmp][x] > 0) q.push(x);
					}
					q.pop();
				}
				bool fi = false;
				REP(x, n) if(!ch[x]){
					//cout << i << " " << j << endl;
					fi = true;
				}
				if(fi) ans ++;
			}
			
		}
	}
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		InputReader in = new InputReader(System.in);
        int n = in.readInt();
        if(n < 105) System.out.println(0);
        else if( n < 135) System.out.println(1);
        else if(n < 165) System.out.println(2);
        else if(n < 189) System.out.println(3);
        else if(n < 195) System.out.println(4);
        else System.out.println(5);
	}
}
class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	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 readInt() {
		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;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    int n,m;
    ll a[100001];
    cin >> n >> m;
    a[0] = 0;
    FOR(i,1,n) cin >> a[i];
    REP(i,n-1) a[i+1] += a[i];
    int p = 0;
    ll ans = 0;
    REP(i,m){
	int t;
	cin >> t;
	ans += abs(a[t+p] - a[p]);
	p += t;
    }
    ans %= 100000;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1944
#include <string>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <math.h>
 
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
 
	int A,B,C,K;
	cin >> A >> B >> C >> K;
    vector<int> vec(114514);
    if(A>=K){
      cout << K << "\n";
      return 0;
    }
    if(A<K){
      if(A+B>=K){
        cout << A << "\n";
        return 0;
      }else{
        cout << A-(K-A-B) << "\n";
      }
    }
  
}

Measured memory_bytes: 3724
N, K = gets.chomp.split
Ds = gets.chomp.split
Es = [*'0'..'9'] - Ds

l = N.size
l += 1 if Es.last * l < N
n = N.to_i
ans = 0

Es.repeated_permutation(l) do |ms|
  ans = ms.join.to_i
  break if ans >= n
end

puts ans


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

signed main(){
  int a=0 , b=0;
  string s;
  char c='W' , d='B';
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i] != c){
      a++;
      c=s[i];
    }
    if(s[i] != d){
      b++;
      d=s[i];
    }
  }
    cout<<min(a,b)<<endl;
  return(0);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int w, a, b;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> w >> a >> b;
  if(a > b) swap(a, b);
  cout << max(0, b-a-w) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,k,arr[100];
long long dp[100][100][5000];

int main()
{
    ios_base::sync_with_stdio(false);
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    dp[0][0][0]=1;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            for(int k=0;k <5000; k++)
            {
                if(dp[i][j][k]==0)continue;
                dp[i+1][j+1][k+ arr[i] ] += dp[i][j][k];
                dp[i+1][j][k] += dp[i][j][k];

            }
        }
    }
    long long sum=0;
    for(int i=1;i<=n;i++)
    {
        sum += dp[n][i][k*i];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 151808
#include<bits/stdc++.h>
#include<atcoder/dsu>
using namespace std;
using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); i++)
int main() {
  int n, m;
  cin >> n >> m;
  dsu uf(n);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    uf.merge(a-1,b-1);
  }
  map<int,int> mp;
  int ans = 0;
  rep(i,n) {
    if (mp[uf.leader(i)]) continue;
    mp[uf.leader(i)]++;
    ans++;
  }
  ans--;
  cout << ans << endl;
}


Measured memory_bytes: 7668
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>

using namespace std;
typedef long long int ll;
void sayYes() { cout << "Yes" << endl; };
void sayNo() { cout << "No" << endl; };
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define rep(i, n) for (ll i = 0; i < n; i++)

void Main()
{
    // int n;
    // cin >> n;
    // vector<int> a(n);
    // rep(i, n)
    // {
    //     cin >> a[i];
    // }
    int k, a, b;
    cin >> k >> a >> b;

    for (int i = a; i <= b; i++)
    {
        if (i % k == 0)
        {
            cout << "OK" << endl;
            return;
        }
    }

    cout << "NG" << endl;

    return;
}

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


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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    const char* d[] = { "SUN","MON","TUE","WED","THU","FRI","SAT"};
    string S;
    cin >> S;

    for( int i = 0 ;   i < 7; i++ ){
        if( S == d[i] ){
            cout << 7-i << endl;
            break;
        }
    }
}


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

class P
{
    static void Main()
    {
        int[] HW = Console.ReadLine().Split().Select(int.Parse).ToArray();
        string[] s = new string[HW[0]].Select(_ => Console.ReadLine()).ToArray();

        for (int i = 0; i < HW[0]; i++)
        {
            Console.WriteLine(s[i]);
            Console.WriteLine(s[i]);
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <utility>
#include <stdint.h>
#include <unordered_map>
#include <string>
#include <set>

using namespace std;

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

  unordered_map<string,int> X;
  
  for (int n=0; n<N; ++n) {
    string S;
    cin >> S;

    auto itr = X.find(S);
    if (itr == X.end())
      X.emplace(S,1);
    else
      itr->second += 1;
  }

  int maxCount = 0;
  for (auto x : X)
    maxCount = max(x.second, maxCount);

  set<string> ans;
  for (auto x : X) {
    if (x.second == maxCount)
      ans.insert(x.first);
  }

  for (auto s : ans)
    cout << s << endl;

  return 0;
}


Measured memory_bytes: 33480
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int a[3],i,b,c;
    c=999;
    b=0;
    for (i=0;i<3;i++){
        cin>>a[i];
        if (a[i]>b){
            b=a[i];
        }
        if (a[i]<c){
            c=a[i];
        }
    }
    cout<<b-c;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

typedef long long ll;
#define mfor(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  mfor(i,0,n)
#define all(x) (x).begin(),(x).end()

bool comp(const vector<int> &x, const vector<int> &y){
    return x[2] > y[2];
}

int main(void){

    string s; cin >> s;
    int k; cin >> k;

    vector<string> ss;
    rep(i, s.length()){
        mfor(j, 1, 6){
            ss.push_back(s.substr(i, j));
        }
    }

    sort(all(ss));
    ss.erase(unique(all(ss)), ss.end());

//    rep(i, ss.size()){
//        cout << ss[i] << endl;
//    }

    cout << ss[k-1] << endl;

    return 0;
}

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

int main(void){

  char s[200];
  char p[100];

  scanf("%s",&s);
  scanf("%s",&p);
  strncat(s,s,strlen(p));
  if(strstr(s,p)){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 532
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstdlib>
#define INF 100000000
#define _INF -100000000
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;

static const int N = (int)1e5;
int n, m;
vi x(N), y(N), num(N, 1);
vector<bool> ps(N, false); //possibility

void solve() {
	Loop(i, m) {
		num[x[i] - 1]--;
		num[y[i] - 1]++;
		if (ps[x[i] - 1]){
			ps[y[i] - 1] = true;
			if (num[x[i] - 1] == 0) {
				ps[x[i] - 1] = false;
			}
		}
	}
	int ret = 0;
	Loop(i, n) {
		if (ps[i]) ret++;
	}
	cout << ret << endl;
}

int main() {
	cin >> n >> m;
	Loop(i, m){
		cin >> x[i] >> y[i];
	}
	ps[0] = true;
	solve();
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>

using namespace std;

int dfs(int ar, int al, int br, int bl, int turn) {
	int na,nb,nc,nd;
	if (ar > 4 && al > 4) return -1;
	if (br > 4 && bl > 4)return 1;

	if (turn == 1) {
		if (br < 5) {
			if (ar < 5) {
				na = dfs(ar, al, br + ar, bl, -1);
			}else{
				na = -1;
			}
			if (al < 5) {
				nb = dfs(ar, al, br + al, bl, -1);
			}else{
				nb = -1;
			}
		}
		else {
			na = nb = -1;
		}
		if (bl < 5) {
			if (ar < 5) {
				nc = dfs(ar, al, br, bl + ar, -1);
			}else{
				nc = -1;
			}
			if (al < 5) {
				nd = dfs(ar, al, br, bl + al, -1);
			}else{
				nd = -1;
			}
		}else{
			nc = nd = -1;
		}
		if (na == -1&&nb == -1&&nc == -1&&nd == -1) {
			return -1;
		}
		else {
			return 1;
		}
	}
	if (turn == -1) {
		if (ar < 5) {
			if (br < 5) {
				na = dfs(ar + br, al, br, bl, 1);
			}else{
				na = 1;
			}
			if (bl < 5) {
				nb = dfs(ar + bl, al, br, bl, 1);
			}else{
				nb = 1;
			}
		}
		else {
			na = nb = 1;
		}
		if (al < 5) {
			if (br < 5) {
				nc = dfs(ar, al + br, br, bl, 1);
			}else{
				nc = 1;
			}
			if (bl < 5) {
				nd = dfs(ar, al + bl, br, bl, 1);
			}else{
				nd = 1;
			}
		}
		else {
			nc = nd = 1;
		}
		if (na == 1&&nb == 1&&nc == 1&&nd == 1) {
			return 1;
		}
		else {
			return -1;
		}
	}
}
//1...ISONO
//-1...NAKAJIMA

int main(void) {
	int ar, al, br, bl, ans;
	cin >> ar >> al >> br >> bl;
	ans = dfs(ar, al, br, bl, 1);

	if(ans==1)cout << "ISONO" << endl;
	else cout << "NAKAJIMA" << endl;
}

Measured memory_bytes: 1160
import sys
#input = sys.stdin.buffer.readline

def main():
    s = list(input())
    l = len(s)
    if s[0] != "1" or s[-1] != "0":
        print(-1)
    else:
        for i in range(l//2):
            if s[i] != s[l-i-2]:
                print(-1)
                exit()
        s = s[::-1]
        s[0] = "1"
        now = 0
        ans = []
        while now<l-1:
            c = 1
            ans.append((l-now,l-(now+c)))
            while s[now+c] == "0":
                c += 1
                ans.append((l-now,l-(now+c)))
            now += c
        for x,y in ans:
            print(x,y)

if __name__ == "__main__":
    main()


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

int main() {
  int H, W;
  int N=0;
  vector<int> V={};
  cin >> H >> W;
  int A[H][W];
  
  for(int h=0; h<H; h++) {
    for(int w=0; w<W; w++) {
      cin >> A[h][w];
    }
  }
  
  for(int h=0; h<H; h++) {
    if(h%2==0) {
      for(int w=0; w<W; w++) {
        if(h==H-1&&w==W-1) {break;}
        if(A[h][w]%2==1 && w!=W-1) {
          V.push_back(h+1);
          V.push_back(w+1);
          V.push_back(h+1);
          V.push_back(w+2);
          A[h][w+1] += 1;
          N++;
        } else if(A[h][w]%2==1 && w==W-1) {
          V.push_back(h+1);
          V.push_back(W);
          V.push_back(h+2);
          V.push_back(W);
          A[h+1][W-1] += 1;
          N++;
        }
      }
    } else {
      for(int w=W-1; w>=0; w--) {
        if(h==H-1&&w==0) {break;}
        if(A[h][w]%2==1 && w!=0) {
          V.push_back(h+1);
          V.push_back(w+1);
          V.push_back(h+1);
          V.push_back(w);
          A[h][w-1] += 1;
          N++;
        } else if(A[h][w]%2==1 && w==0) {
          V.push_back(h+1);
          V.push_back(1);
          V.push_back(h+2);
          V.push_back(1);
          A[h+1][0] += 1;
          N++;
        }
      }
    } 
  }
  
  cout << N << endl;
  for(int i=0; i<V.size(); i++) {
    cout << V[i];
    if(i%4==3) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
  
  return 0;
}

Measured memory_bytes: 5104
import java.util.Scanner;

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

        int max = -1;
        int min = 100000;
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();

            max = Math.max(max, a);
            min = Math.min(min, a);
        }
        
        System.out.println(max - min);
    }
}


Measured memory_bytes: 21712
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define pb push_back
#define mp make_pair
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;



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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n;
	cin >> n;
	
	vector<P> d(n);
	REP(i, n) {
		ll x, l;
		cin >> x >> l;
		d[i].first = x + l;
		d[i].second = x - l;
	}

	sort(all(d));

	ll con = 0;
	ll pre = -INF;
	REP(i, n) {
		if (pre <= d[i].second) {
			con++;
			pre = d[i].first;
		}
	}

	cout << con << endl;

	return 0;
}


Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	nk, _ := reader.ReadString('\n')
	tmp := strings.Split(strings.Replace(nk, "\n", "", -1), " ")
	n, _ := strconv.ParseInt(tmp[0], 0, 64)
	k, _ := strconv.ParseInt(tmp[1], 0, 64)

	m := map[string]bool{}

	for i := 0; i < int(k); i++ {
		_, _ = reader.ReadString('\n')
		s, _ := reader.ReadString('\n')
		tmp := strings.Split(strings.Replace(s, "\n", "", -1), " ")
		for _, j := range tmp {
			m[j] = true
		}
	}

	for range m {
		n = n - 1
	}
	fmt.Println(n)
}


Measured memory_bytes: 2072
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

const int MAX_N = 30001;

int L[MAX_N], R[MAX_N], sum[MAX_N];
int n, m, w, h, s;

int bin_search_line(double x, double y) {
	int l = 0, r = m, line = 0;
	while (l <= r) {
		int mid = (l + r) >> 1;
		if ((y - L[mid]) * w > x * (R[mid] - L[mid])) {
			l = mid + 1;
		} else r = mid - 1, line = mid;
    }
    return line;
}

int bin_search_level(int end) {
	int l = 0, r = end, level = -1;
	while (l <= r) {
		int mid = (l + r) >> 1;
		if ((L[end] - L[mid] + R[end] - R[mid]) * w > 2 * (w * h - s)) {
			l = mid + 1;
		} else r = mid - 1, level = mid;
	}
	return level;
}

void solve() {
	L[0] = R[0] = 0.;
	fill(sum, sum + m + 1, 0);
	for (int i = 1; i <= m; ++i) {
		scanf("%d%d", &L[i], &R[i]);
	}
	double x, y;
	for (int i = 0; i < n; ++i) {
		scanf("%lf%lf", &x, &y);
		++sum[bin_search_line(x, y)];
	}
	for (int i = 1; i <= m; ++i) {
		sum[i] += sum[i - 1];
	}
	int res = n;
	for (int i = 0; i <= m; i++) {
		int index = bin_search_level(i);
		if (-1 == index) continue;
		res = min(res, n - (sum[i] - sum[index]));
	}
	printf("%d\n", res);
}

int main() {
	while (5 == scanf("%d%d%d%d%d", &n, &m, &w, &h, &s)) {
		if (0 == n) break;
		solve();
	}
	return 0;
}

Measured memory_bytes: 1576
//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <map>

using namespace std;
typedef pair<int,int> Paint;

bool Pairsecond(const Paint& pf,Paint&ps){//sortCompare
  return pf.second < ps.second;
}

int main(){
  int h,w;cin>>h>>w;
  char mp[h][w];
  int point[h][w];
  vector<int> auth[w];//w列の意思の場所
  vector<int> autw[h];
  for(int i = 0; h > i; i++){
    for(int j = 0; w > j; j++){
     
      cin>>mp[i][j];
      point[i][j] = 0;
      
      if(mp[i][j] == '#'){
        auth[j].push_back(i);

        autw[i].push_back(j);

      }
    }
  }
  int h_nw = 0;
  int w_nw = 0;
  //横側
  for(int i = 0; h > i; i++){
    h_nw = 0;
    for(int j = 0; w > j; j++){
      
      if(mp[i][j] == '#'){
        h_nw++;
        continue;
      }
      if(h_nw == autw[i].size()){
        if(h_nw == 0){
          point[i][j]+=w;
        }else{
          point[i][j]+=w+1-autw[i][h_nw-1]-2;
        }
      }else{
        if(h_nw == 0){
          point[i][j]+=autw[i][h_nw]-0;
        }else{
          point[i][j]+=autw[i][h_nw]-autw[i][h_nw-1]-1;
        }
      }
    }
  }






  for(int i = 0; w > i; i++){
    w_nw = 0;
    for(int j = 0; h > j; j++){
      if(mp[j][i] == '#'){
        w_nw++;
        continue;
      }
      if(w_nw == auth[i].size()){
        if(w_nw == 0){
          point[j][i]+=h;
        }else{
          point[j][i]+=h+1-auth[i][w_nw-1]-2;
        }
      }else{
        if(w_nw == 0){
          point[j][i]+=auth[i][w_nw]-0;
        }else{
          point[j][i]+=auth[i][w_nw]-auth[i][w_nw-1]-1;
        }
      }
    }
  }

  int mx = 0;
  for(int i = 0; h > i; i++){
    for(int j = 0; w > j; j++){
      mx = max(mx,point[i][j]-1);
    }
  }
  cout << mx << endl;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using db = double;
#define pb push_back

const int mxn = 100006;

int n;
int l;
int a[mxn];

int main() {
	cin >> n >> l;
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	for (int i = 1; i + 1 <= n; ++i)
		if (a[i] + a[i + 1] >= l) {
			puts("Possible");
			for (int j = 1; j < i; ++j)
				printf("%d\n", j);
			for (int j = n - 1; j > i; --j)
				printf("%d\n", j);
			printf("%d \n", i);
			return 0;
		}
	puts("Impossible");
	
	return 0;
}


Measured memory_bytes: 1152
use std::io::Read;
use std::cmp::min;
use std::collections::VecDeque;
use std::iter::FromIterator;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let _n: usize = iterator.next().unwrap().parse().unwrap();
    let mut s: VecDeque<char> = VecDeque::from_iter(iterator.next().unwrap().chars());
    while !s.is_empty() && *s.front().unwrap() == '.' {
        s.pop_front().unwrap();
    }
    while !s.is_empty() && *s.back().unwrap() == '#' {
        s.pop_back().unwrap();
    }
    let s: Vec<char> = Vec::from(s);

    let n: usize = s.len();
    if n == 0 {
        return "0".to_string();
    }

    let mut s1 = s.clone();
    let mut c1: usize = 0;
    for i in 0..(n - 1) {
        if s1[i] == '#' && s1[i + 1] == '.' {
            s1[i + 1] = '#';
            c1 += 1;
        }
    }

    let mut s2 = s.clone();
    let mut c2: usize = 0;
    for i in (1..n).rev() {
        if s2[i - 1] == '#' && s2[i] == '.' {
            s2[i - 1] = '.';
            c2 += 1;
        }
    }

    let mut ans = min(c1, c2);

    let mut b: Vec<usize> = vec![0; n];
    b[0] = 1;
    for i in 1..n {
        if s[i] == '#' {
            b[i] = b[i - 1] + 1;
        } else {
            b[i] = b[i - 1];
        }
    }
    let mut w: Vec<usize> = vec![0; n];
    w[n - 1] = 1;
    for i in (0..(n - 1)).rev() {
        if s[i] == '.' {
            w[i] = w[i + 1] + 1;
        } else {
            w[i] = w[i + 1];
        }
    }

    for i in 0..(n - 1) {
        if s[i] == '.' && s[i + 1] == '#' {
            ans = min(ans, b[i] + w[i + 1]);
        }
    }

    return ans.to_string();
}


Measured memory_bytes: 10492
/*
 * Problem
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_B&lang=jp
 *
 * Author
 * Leonardone @ NEETSDKASU
 */
#include <stdio.h>

void exchange(int A[], int i, int j) {
	int tmp = A[i];
	A[i] = A[j];
	A[j] = tmp;
}

int Partition(int A[], int p, int r) {
	int x = A[r];
	int i = p - 1;
	int j;
	
	for (j = p; j < r; ++j) {
		if (A[j] <= x) {
			++i;
			exchange(A, i, j);
		}
	}
	exchange(A, i + 1, r);
	return i + 1;
}

int main(void) {
	int A[100001];
	int n, i, q;
	
	scanf("%d", &n);
	for (i = 1; i <= n; ++i) {
		scanf("%d", &A[i]);
	}
	
	q = Partition(A, 1, n);
	
	for (i = 1; i <=n ; ++i) {
		if (i > 1) {
			putchar(' ');
		}
		if (i == q) {
			printf("[%d]", A[i]);
		} else {
			printf("%d", A[i]);
		}
	}
	putchar('\n');
	
	return 0;
}

Measured memory_bytes: 996
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const double pi = acos(-1);

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

    vector<P> p(n);
    rep(i, n) {
        ll x, y;
        cin >> x >> y;
        p[i] = make_pair(x, y);
    }
    sort(all(p));

    map<P, ll> mp;
    exrep(i, 0, n-2) {
        exrep(j, i+1, n-1) {
            ll dx = p[j].first - p[i].first;
            ll dy = p[j].second - p[i].second;
            mp[make_pair(dx, dy)]++;
        }
    }

    ll ma = 0;
    for(auto x : mp) {
        chmax(ma, x.second);
    }
    
    out(n - ma);
    re0;
}

Measured memory_bytes: 384
#include <algorithm>

template <typename FI>
void parted_rotate(FI first1, FI last1, FI first2, FI last2) {
  if (first1 == last1 || first2 == last2) return;
  auto next = first2;
  while (first1 != next) {
    std::iter_swap(first1++, next++);
    if (first1 == last1) first1 = first2;
    if (next == last2) {
      next = first2;
    } else if (first1 == first2) {
      first2 = next;
    }
  }
}

template <typename BI>
bool next_combination_imp(BI first1, BI last1, BI first2, BI last2) {
  if (first1 == last1 || first2 == last2) return false;
  auto target = last1;
  --target;
  auto last_elem = last2;
  --last_elem;
  while (target != first1 && !(*target < *last_elem)) --target;
  if (target == first1 && !(*target < *last_elem)) {
    parted_rotate(first1, last1, first2, last2);
    return false;
  }
  auto next = first2;
  while (!(*target < *next)) ++next;
  std::iter_swap(target++, next++);
  parted_rotate(target, last1, next, last2);
  return true;
}

template <typename BI>
inline bool next_combination(BI first, BI mid, BI last) {
  return next_combination_imp(first, mid, mid, last);
}

#include <iostream>
#include <iterator>
#include <vector>

using namespace std;

int main() {
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<int> a(Q), b(Q), c(Q), d(Q);
  for (auto i = 0; i < Q; ++i) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    --a[i];
    --b[i];
  }

  vector<int> A;
  for (auto i = 0; i != M; ++i) {
    fill_n(back_inserter(A), N, i);
  }

  int ma{0};
  do {
    int score = 0;
    for (auto q = 0; q != Q; ++q) {
      if (A[b[q]] - A[a[q]] == c[q]) score += d[q];
    }
    ma = max(ma, score);
  } while (next_combination(A.begin(), A.begin() + N, A.end()));

  cout << ma << endl;

  return 0;
}


Measured memory_bytes: 3640
import static java.lang.Integer.MAX_VALUE;
import static java.lang.Integer.MIN_VALUE;
import static java.lang.Integer.parseInt;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * Sport Meet
 */
public class Main {

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

		StringBuilder sb = new StringBuilder();
		while (!(line = br.readLine()).equals("0")) {

			int[][] min = { { 0, MAX_VALUE }, { 0, MAX_VALUE } };
			int[][] max = { { 0, MIN_VALUE }, { 0, MIN_VALUE } };
			int n = Integer.parseInt(line);
			for (int i = 0; i < n; ++i) {
				line = br.readLine();
				int team = parseInt(line.substring(0, line.indexOf(' ')));
				int sec = seconds(line.substring(line.indexOf(' ') + 1));

				//
				if (sec < min[0][1]) {
					min[1][0] = min[0][0];
					min[1][1] = min[0][1];
					min[0][0] = team;
					min[0][1] = sec;
				} else if (sec > min[0][1] && sec < min[1][1]) {
					min[1][0] = team;
					min[1][1] = sec;
				}
				//
				if (sec > max[0][1]) {
					max[1][0] = max[0][0];
					max[1][1] = max[0][1];
					max[0][0] = team;
					max[0][1] = sec;
				} else if (sec < max[0][1] && sec > max[1][1]) {
					max[1][0] = team;
					max[1][1] = sec;
				}
			}
			sb.append(String.format("%d\n%d\n%d\n", min[0][0], min[1][0],
					max[1][0]));
		}
		System.out.print(sb.toString());
	}

	static int seconds(String info) {
		StringTokenizer st = new StringTokenizer(info);
		int min = 0, sec = 0;
		for (int i = 0; i < 8; ++i) {
			if (i % 2 == 0) {
				min += parseInt(st.nextToken());
			} else {
				sec += parseInt(st.nextToken());
			}
		}
		return min * 60 + sec;
	}

}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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(){

    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    int l[q], r[q];
    int cnt[n+1] = {0};
    for(int i = 0; i < n; i++){
        if(s.substr(i, 2) == "AC"){
            cnt[i+1] = cnt[i] + 1;
        }
        else{
            cnt[i+1] = cnt[i];
        }
    }

    for(int i = 0; i < q; i++){
        cin >> l[i] >> r[i];
        l[i]--, r[i]--;
    }
    for(int i = 0; i < q; i++){
        cout << cnt[r[i]] - cnt[l[i]] << endl;
    }
    return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>

using namespace std;

int main(){
  int i = 0,d[20];
  while(cin >> d[i++]);
  sort(d,d+10);
  sort(d+11,d+20);
  cout << d[7] + d[8] + d[9] << " " <<  d[17] + d[18] + d[19] << endl;
}

Measured memory_bytes: 1180
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstring>
#include<complex>
#include<stack>
#include<queue>
#include<unordered_map>
#include<map>

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

using namespace std;

int main(void) {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int num = 0;
  int tmp = 0;
 

  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      tmp = (x - 500*i - 100*j) / 50;
      if (tmp >= 0 && tmp <= c) {
        num++;
      }
    }
  }
  cout << num << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define PER(i, a, b) for (int i = a; i >= b; --i)
#define RVC(i, S) for (int i = 0; i < S.size(); ++i)
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fi first
#define se second
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> VI;

int n;
map<int, int> cnt;
int main(){
	scanf("%d", &n);
	REP(i, 1, n){
		int x; scanf("%d", &x);
		++cnt[x];
		++cnt[x - 1];
		++cnt[x + 1];
	}
	int ans = 0;
	for (map<int, int>::iterator it = cnt.begin(); it != cnt.end(); ++it)
		ans = max(ans, it -> se);
	printf("%d\n", ans);
	return 0;
}

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

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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; }

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

vector<int> graph[2005];
vector<vector<int>> len(2005, vector<int>(2005, -1));
vector<vector<int>> sorted(2005, vector<int>());

void dfs(int s, int p, int l) {
  len[s][p] = l;
  sorted[s].push_back(p);
  for(auto e: graph[p]) {
    if (len[s][e] == -1) {
      dfs(s, e, l+1);
    }
  }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  string s; cin >> s;
  vector<bool> vec(n+1);
  rep(i, n) {
    if (s[i] == '1') {
      vec[i+1] = true;
      //debugln(i+1);
    }
  }

  rep(i, n-1) {
    int a, b; cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  for(int i=1; i<=n; i++) {
    dfs(i, i, 0);
  }

  int mi = INT_MAX;
  for(int i=1; i<=n; i++) {
    int sum = 0;
    for(int j=1; j<=n; j++) {
      if (vec[j]) {
        sum += len[i][j];
      }
    }
    if (sum%2 == 0) {
      reverse(sorted[i].begin(), sorted[i].end());
      vector<P> dp(2005); // P(dp, lensum);
      vector<int> cnt(2005);
      vector<bool> used(2005);
      for(auto p: sorted[i]) {
        used[p] = true;
        P top = P(0, 0);
        P total = P(0, 0);
        if (vec[p]) cnt[p]++;
        for(auto e: graph[p]) {
          if (used[e]) {
            P pa = dp[e];
            total.first += pa.first;
            total.second += pa.second;
            cnt[p] += cnt[e];
            if (pa.second > top.second) {
              top = pa;
            }
          }
        }
        P rest = {total.first-top.first, total.second-top.second};
        dp[p].second = total.second;
        if (top.second-top.first*2 <= rest.second) {
          dp[p].first = dp[p].second/2;
        } else {
          dp[p].first = top.first + rest.second;
        }
        dp[p].second += cnt[p];
        //debug(i); debug(p); debug(cnt[p]); debug(dp[p].first); debugln(dp[p].second);
      }
      if (dp[i].first == sum/2) {
        chmin(mi, sum/2);
      }
    }
  }

  if (mi == INT_MAX) {
    cout << -1 << endl;
  } else {
    cout << mi << endl;
  }
}

Measured memory_bytes: 32256
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <ctime>


#ifndef _USEFUL_MACROS_
#define _USEFUL_MACROS_
#define INF 99999999
#define N_PRIME 1000000007
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define OUTPUT_DEBUG
#ifdef OUTPUT_DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x) do{}while(false)
#endif
#endif 

using namespace std;


int main(){
    int64_t n,k;
    cin >> n >> k;
    
    vector<int64_t> counter(200005);
    REP(i,n){
        int temp;
        cin >> temp;
        counter[temp]++;
    }
    
    priority_queue<int, vector<int>, std::greater<int> > q;
    
    int n_color = 0;
    REP(i,200005){
        if( counter[i] > 0 ){
            q.push(counter[i]);
            n_color++;
        }
    }
    
    int ans=0;
    
    while(true){
        if( n_color <= k )break;
        
        
        ans += q.top();
        q.pop();
        n_color--;
    }
    
    cout << ans << endl;
    
    
}

Measured memory_bytes: 2936
import java.util.Scanner;
public class Main {

	public static void main(String args []){
		Scanner scan = new Scanner(System.in);
			int a = scan.nextInt();
			int b = scan.nextInt();
			int ans1 = a * b;
			int ans2 = 2 * (a + b);
			System.out.print(""+ ans1);
			System.out.println(" "+ ans2);
	}
}

Measured memory_bytes: 25884
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
	int n;
	cin>>n;
	int color = 0;

	map<string,int> t;
	vector<priority_queue<int,vector<int> ,greater<int> > > tt;
	for(int i=0;i<n;i++){
		string s;
		int d;
		cin>>s>>d;
		if(t.find(s) == t.end() ){
			priority_queue<int,vector<int> ,greater<int> > q;
			t[s] = tt.size();
			q.push(d);
			tt.push_back(q);
		}else{
			int ss = t[s];
			tt[ss].push(d);
		}
	}

	int m;
	cin>>m;
	bool f = false;
	int now = -1;
	for(int i=0;i<m;i++){
		string s;
		cin>>s;
		if(f)continue;
		if(t.find(s) == t.end()){
			//cout<<"color not exsit"<<endl;
			f = true;
			continue;
		}
		int ss = t[s];
		if(tt[ss].empty() ){
			//cout<<"color used "<<endl;
			f = true;
			//cout<<1<<endl;
			continue;
		}
		int next=tt[ss].top();
		tt[ss].pop();
		//cout<<s<<' '<<next<<endl;
		while(now  >= next){
			if(tt[ss].empty() ){
				f = true;
				break;
			}
			next = tt[ss].top();
			tt[ss].pop();
			//cout<<now<<' '<<next<<endl;
			//cout<<2<<endl;
			continue;
		}
		now = next;
	}
	if(f){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
	}

	return 0;
}



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

using namespace std;
int main (){
    int n,m;
    cin >> n >> m;
    vector<int> x(m);
    for (int i = 0; i < m; i++){
        cin >> x[i];
    }
    sort(x.begin(),x.end());
    vector<int> dif(m-1);
    for (int i = 0; i < m-1; i++){
        dif[i]=x[i+1]-x[i];
//        cout << dif[i] << "\n";
    }
    sort(dif.begin(),dif.end());
    int count=0;
    for (int i = 0; i < max(0,(m-n)); i++){
        count+=dif[i];
    }
    cout << count << "\n";

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n, q;
	cin>>n>>q;
	string s;
	cin>>s;
	int dp[n+1];
	dp[0] = 0;
	dp[1] = 0;
	if(s[0]=='A'&&s[1]=='C')
		dp[2] = 1;
	else
		dp[2] = 0;
	for(int i = 3 ; i <=n ; i++)
		{
			dp[i] = ((s[i-2]=='A'&&s[i-1]=='C')?1:0);
			dp[i] += dp[i-1];
		}
	for(int i = 0 ; i < q; i++)
	{
		int l,r; cin>>l>>r;
		cout<<dp[r]-dp[l]<<endl;
	}

	return 0; 
}

Measured memory_bytes: 1408
object Main {
  def main(args:Array[String]) {
    val S = readLine()
    val weeklist = List("SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN")
    var ans = 0
    for(i <- 0 until weeklist.length) {
      if(S == weeklist(i)) ans = (i % 7) + 1
    }
    println(ans)
  }
}


Measured memory_bytes: 25500
class SegmentTree
  def initialize
    @N=2**17
    @INF=2**31-1
    @seg=Array.new(2*@N-1){@INF}
  end
  
  def update(i, x)
    i+=@N-1 #??°??????i??????????????????????????¨????????????????????????
    @seg[i]=x
    while i.nonzero?
      i=(i-1)/2 #????????????????????????????????¨????????????
      @seg[i]=[@seg[2*i+1], @seg[2*i+2]].min #????????????
    end
  end
  
  def segmin(a, b, i=0, l=0, r=@N) #??????i?????????????????????=>[l, r)
    if b<=l or r<=a #2??????????????????????????????; ??\???????????????????????´
      @INF
    elsif a<=l and r<=b #????????????????????¨?????\??????????????????????????????
      @seg[i]
    else
      m=(l+r)/2
      vl=segmin(a, b, 2*i+1, l, m) #?????????
      vr=segmin(a, b, 2*i+2, m, r) #?????????
      [vl, vr].min
    end
  end
end


n, q=gets.split.map(&:to_i)

st=SegmentTree.new
q.times do |i|
  c, a, b=gets.split.map(&:to_i)
  case c
  when 0 #update a-th element to b
    st.update(a, b)
  when 1 #getmin [a..b]
    puts st.segmin(a, b+1)
  end
end

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

void input(long &n, vector<long> &a) {
    cin >> n;
    a.resize(n);
    rep(i,n) {
        cin >> a[i];
    }
}

long div(long n) { // 整数が2で割り切れる回数
    long count = 0;
    while (n % 2 == 0) {
        n /= 2;
        count++;
    }
    return count;
}

int main() {
    long n; vector<long> a;
    input(n, a);

    long sum = 0;
    rep(i,n) { //各要素の2で割り切れる回数の総和
        sum += div(a[i]);
    }
    cout << sum << endl;
}

Measured memory_bytes: 3688
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
#define N 104730
int main() {
	unsigned long long i, j, cnt = 0, p[N] = { 0 }, sum = 0, n;
	for (i = 2; i <= (unsigned long long)sqrt((double)N); ++i) if (!p[i]) for (j = 2; j*i < N; ++j) p[i*j] = 1;
		while (scanf("%lld", &n), n != 0) {
		for (i = 2; i < N&&cnt < n; ++i) if (!p[i]) ++cnt, sum += i;
		printf("%lld\n", sum),cnt = sum = 0;
	}
	return 0;
}

Measured memory_bytes: 1424
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	ll n, m; cin >> n >> m;
	ll ans = 0;
	if( n*2 > m ){
		ans += m/2;
		m = 0;
	} else {
		ans += n;
		m -= n*2;
	}
	ans += m/4;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define all(a)  (a).begin(),(a).end()


signed main(){
  int a,b;
  cin>>a>>b;
  V<V<int>> c(10,V<int>(10));
  fo(i,10){
    fo(j,10){
      cin>>c[i][j];
    }
  }
  V<V<int>> d(a,V<int>(b));
  fo(i,a){
    fo(j,b){
      cin>>d[i][j];
    }
  }
  fo(k,10){
    fo(i,10){
      fo(j,10){
        c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
      }
    }
  }
  int e=0;
  fo(i,a){
    fo(j,b){
      if(d[i][j]==1)
        continue;

      if(d[i][j]!=-1){
        e+=c[d[i][j]][1];
      }
    }

  }
  cout<<e<<endl;
}

Measured memory_bytes: 512