akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;
const int V = 100005;

int main(){
    ll n,k; cin >> n >> k;
    priority_queue<P> pq;
    rep(i,n){
        ll t,d; cin >> t >> d;
        t--;
        pq.emplace(P(d,t));
    }
    vl sushi(n,0);
    ll sum = 0;
    ll x = 0;
    multiset<ll> mse;
    rep(i,k){
        auto p = pq.top(); pq.pop();
        sum += p.first;
        ll u = p.second;
        if(sushi[u]==0){
            sushi[u]++;
            x++;
        }
        else mse.insert(p.first);
    }
    ll ans = sum + x*x;
    while(x<k && !mse.empty() && !pq.empty()){
        auto p = pq.top(); pq.pop();
        ll u = p.second;
        if(sushi[u]>0) continue;
        sushi[u]++;
        sum -= *mse.begin();
        mse.erase(mse.begin());
        sum += p.first;
        x++;
        ans = max(ans, sum + x*x);
    }
    cout << ans << endl;
}

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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>;
using ld = long double;  using vld = vector<ld>; 

int main(void) {
	ll n,a,b; cin >>n>>a>>b;
	
	if(n*a<b) cout <<n*a <<endl;
	else cout <<b <<endl;
	
   return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
	int n,r;
	while(1){
		r=0;
		scanf("%d",&n);
		if(n==0){
			break;
		}
		do{
			n/=5;
			r+=n;
		}while(n!=0);
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 2616
#[allow(dead_code)]
fn main() {
    let mut nn = i::u();
    let mut bb=i::iv(nn-1);
    let mut veca= Vec::new();


    let mut max1=0;

    for x1 in 0..nn {
        if (x1==0){
            veca.push(bb[0]);
        }else if (x1==(nn-1)){
            veca.push(bb[nn-2]);
        }else{
            veca.push(min(bb[x1-1],bb[x1]));
        }
    }
    let mut sum1=0;
    for xx1 in veca {
        sum1+=xx1;
    }
    println!("{}",sum1 );

}


#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }
    pub fn strv(n: usize) -> Vec<String> {
        (0..n).map(|_| str()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
long long x[100010],y[100010],z[100010];
int main(){

  cin.tie(0);
  ios::sync_with_stdio(false);

  long long a,b,c,cnt=0,ans=0,n;
  string s,v;
  char ad[5];

  cin>>a>>b;

  if(a%b==0) cout<<0<<'\n';
  else cout<<1<<'\n';
}
    


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int n;
	cin >> n;
	if (n == 1)
	{
		cout << "Hello World" << endl;
		return 0;
	}

	int a, b;
	cin >> a >> b;
	cout << a + b << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
for (int i = 0; i < N; i++) {
  cin >> vec.at(i);
}
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += vec.at(i);
  }

sort(vec.begin(), vec.end());
if(vec.at(N-1)*2 < sum){
      cout << "Yes" << endl;
  }
  else {
      cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
#define MAX 1000000

int array[MAX];

int bubble_sort(int n, int array[]){
    int tmp,cnt = 0;
    
    for(int i = n - 1 ; i > 0 ; i--){
        for(int j = 0 ; j < i ; j++){
            if(array[j+1] < array[j]){
                tmp = array[j];
                array[j] = array[j+1];
                array[j+1] = tmp;
                cnt++;
            }
        }
            
    }

    return cnt;
}


int main(){
    int n,array[MAX];
    
    while(1){
        cin >> n;
        if(n == 0) break;
        
        for(int i = 0 ; i < n ; i++) cin >> array[i];
        
        int ans = 0;
        ans = bubble_sort(n,array);
       
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1164
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();

        String[] str = line.split(" ");
        String[] num = sc.nextLine().split(" ");
        String strU = sc.nextLine();

        String strS = str[0];
        String strT = str[1];

        int numA = Integer.parseInt(num[0]);
        int numB = Integer.parseInt(num[1]);

        if(strU.equals(strS)) {
        	numA -= 1;
        }else {
        	numB -= 1;
        }

        System.out.println(numA+" "+numB);

	}

}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
inline int readInt() {int x; cin >> x; return x;}
inline char readChar() {char c; cin >> c; return c;}
inline string readString() {string s; cin >> s; return s;}

int32_t main()
{
	//freopen("input.txt", "r", stdin);
	IOS;
	
	int k = readInt();

	if(k == 1 or k == 7) {
		cout << 1;
	}
	else if(k%2 == 0 or k%5 == 0) {
		cout << -1;
	}
	else {
		if(k%7 == 0) k /= 7;
		int mod = 9LL*k, ans = 10;
		int count = 0;
		while(ans != 1) {
			ans = (ans*10LL)%mod;
			++count;
		}
		cout << count + 1 << '\n';
	}
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b-1);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  vector<ll>a;
  function<void(ll,bitset<8>)>dfs=[&](ll num,bitset<8>bit){
    //cout<<num<<endl;
    if(bit==(1ll<<n)-1){
      a.push_back(num);
      return;
    }
    repi(i,1,n+1){
      if(bit[i-1])continue;
      bit[i-1]=1;
      dfs(num*10+i,bit);
      bit[i-1]=0;
    }
    return ;
  };
  ll p=0,q=0;
  rep(i,n){
    ll a;cin>>a;
    p=p*10+a;
  }
  rep(i,n){
    ll a;cin>>a;
    q=q*10+a;
  }
  dfs(0,0);
  sort(all(a));
  ll res=0;
  res=(lower_bound(all(a),p)-a.begin())-(lower_bound(all(a),q)-a.begin());

  cout<<abs(res)<<endl;
  return 0;

}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
vector<long long>v;
long long pp[100005];
main()
{
	int t;
	long long p;
	scanf("%d",&t);
	for(int i = 0;i < t;i++)
	{
		scanf("%lld",&p);
		v.push_back(p);
	}
	sort(v.begin(),v.end());
	for(int i = 0;i < v.size()-1;i++)
	{
		v[i+1]+=v[i];
	}
	int co=1;
	for(int i = t-2;i >= 0;i--)
	{
		//printf("%lld\n",v[i]);
		if(2*v[i]>=v[i+1]-v[i])
		{
			//printf(" ss %d\n",i);
		co++;
		}
		else
		break;
	}
	printf("%d",co);
}
/*
1
2
7
8
15
*/

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <set>
#include <queue>
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int flag = 1;
    while(1) {
        if(flag == 1) {
            c -= b;
            flag = 0;
        }
        else if(flag == 0) {
            a -= d;
            flag = 1;
        }
        if(a <= 0 || c <= 0) break;
    }
    if(a <= 0) cout << "No" << endl;
    else if(c <= 0) cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int n;
cin>>n;
vector<ll>a(n);
for(int i=1;i<n;i++)cin>>a[i];
a[0]=a[1];
ll sum=0;
for(int i=0;i<n-1;i++){
    sum+=min(a[i],a[i+1]);
}
sum+=a[n-1];
cout<<fixed<<setprecision(0)<<sum;
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	
	if(d>a+b) printf("%d",a-(d-a-b));
	else if(d>a) printf("%d",a);
	else printf("%d",d);
}

Measured memory_bytes: 1724
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

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

    size_t N; cin >> N;
    string s, t; cin >> s >> t;

    size_t res = 2 * N;
    for (size_t i = 0; i < N; ++i) {
        if (s.substr(i, N - i) == t.substr(0, N - i)) {
            return cout << res - (N - i) << "\n", 0;
        }
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n, i, j, t;
    int data[4][13];
    char ch;
    char moyou[4] = { 'S','H','C','D' };

    scanf("%d", &n);

    for (i = 0; i < 4; i++)
    {
        for (j = 0; j < 13; j++)
        {
            data[i][j] = 0;
        }
    }

    scanf("%d", &n);

    for (i = 0; i < n; i++)
    {
        scanf(" %c", &ch);
        scanf("%d", &t);

        if (ch == 'S')
        {
            data[0][t - 1] = 1;
        }
        if (ch == 'H')
        {
            data[1][t - 1] = 1;
        }
        if (ch == 'C')
        {
            data[2][t - 1] = 1;
        }
        if (ch == 'D')
        {
            data[3][t - 1] = 1;
        }
    }

    for (i = 0; i < 4; i++)
    {
        for (j = 0; j < 13; j++)
        {
            if (data[i][j] == 0)
            {
                printf("%c %d\n", moyou[i], j + 1);
            }
        }
    }

    return 0;
}



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


int main(){
	vector<vector<int>> c(3);
	rep(i,3){
	    int c1, c2, c3;
	    cin >> c1 >> c2 >> c3;
	    c[i] = {c1, c2, c3};
	}
	vector<int> a(3,0), b(3);
	b[0] = c[0][0] - a[0];
	b[1] = c[0][1] - a[0];
	b[2] = c[0][2] - a[0];

	a[1] = c[1][0] - b[0];
	a[2] = c[2][0] - b[0];

	rep(i,3){
	    rep(j,3){
	        if(c[i][j] != a[i] + b[j]){
                cout << "No\n";
                return 0;
	        }
	    }
	}
	cout << "Yes\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() { 
  int N, M;
  cin >> N >> M;
  vector<int> p(M);
  vector<string> S(M);
  int AC = 0;
  int WA = 0;
  vector<bool> clear(N);
  vector<bool> notclear(N, 1);
  

  for(int i = 0; i < M; i++) {
    cin >> p.at(i) >> S.at(i);
    if(S.at(i) == "AC") notclear.at(p.at(i) - 1) = 0;
  }
  
  for(int i = 0; i < M; i++) {  
    if(notclear.at(p.at(i) - 1) == 1);
    else {
      if(clear.at(p.at(i) - 1) == 1);
      else if((clear.at(p.at(i) - 1) == 0) && (S.at(i) == "WA")) WA++;
      else if((clear.at(p.at(i) - 1) == 0) && (S.at(i) == "AC")) {
        AC++;
        clear.at(p.at(i) - 1) = 1;
      }
    }
  }
  
  cout << AC << " " << WA << endl;

}

Measured memory_bytes: 6144
N = int(input())
A = list(map(int, input().split()))
memo = [0]*(10**6+1)

for a in A:
    memo[a] += 1
    if memo[a] < 2:
        for i in range(2*a, 10**6+1, a):
            memo[i] += 1

ans = 0
for a in A:
    if memo[a] == 1:
        ans += 1

print(ans)


Measured memory_bytes: 32244
n = int(input())
word = []
ab = 0
a = 0
b = 0
mid = 0

for i in range(n):
    s = str(input())
    if s[0] == "B" and s[-1] == "A":
        ab += 1
    elif s[0] == "B":
        a += 1
    elif s[-1] == "A":
        b += 1
    for k in range(len(s) - 1):
        if s[k] == "A" and s[k + 1] == "B":
            mid += 1

# print(a, b, ab, mid)
if ab > 0:
    mid += ab - 1
    if a == 0 and b == 0:
        mid += 0
    elif a == 0 or b == 0:
        mid += 1
    else:
        mid += 2 + min(a - 1, b - 1)

else:
    mid += min(a, b)
print(mid)


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

int main() {
  int n;
  cin>>n;
  vector<vector<int>> vec(9,vector<int>(9));
  for(int i=0;i<9;i++){
    for(int j=0;j<9;j++){
      vec.at(i).at(j)=(i+1)*(j+1);
    }
  }
  bool ans=false;
  for(int i=0;i<9;i++){
    for(int j=0;j<9;j++){
      if(vec.at(i).at(j)==n)ans=true;
    }
  }
  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
def main():
    from math import gcd
    from functools import reduce
    n, *a, = map(int, open(0).read().split())
    m = max(a)

    d = [0] * (m + 1)
    d[1] = 1
    for i in range(2, m + 1):
        for j in range(i, m + 1, i):
            if d[j] == 0:
                d[j] = i

    def primes(x):
        ps = set()
        while x != 1:
            p = d[x]
            ps.add(p)
            x = x // d[x]
        return ps

    b = set()
    f = 0
    for i in a:
        ps = primes(i)
        if b & ps:
            f = 1
            break
        b |= ps
    if f > 0 and reduce(gcd, a) != 1:
        f = 2

    ans = ["pairwise coprime", "setwise coprime", "not coprime"][f]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 228136
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		FastScanner fs = new FastScanner();

		int K = fs.nextInt();
		int sum = 0;
		for(int a = 1; a <= K; a++) {
			for(int b = 1; b <= K; b++) {
				for(int c = 1; c <= K; c++) {
					sum += gcd(a,b,c);
				}
			}
		}
		System.out.println(sum);


	}
	public static int gcd(int a, int b) {
		if(b == 0) return a;
		return gcd(b,a%b);
	}

	public static int gcd(int a, int b, int c) {
		return gcd(gcd(a,b),c);
	}

}


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

using namespace std;

typedef long long ll;

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
	int a,b,c;
	cin >> a >> b >> c;
	if(b-a==c-b) cout << "YES" << "\n";
	else cout << "NO" << "\n";
    
	return 0;
}

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


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>

typedef long long ll;
#define fi first
#define se second


using namespace std;

int main(){
  
  char X[212345];
  
  int cnt = 0;
  int ans = 0;
  int i;
  int n = 0;
  
  cin>>X;
  
  for( i = 0; i < 212345; i++ ){
    if( X[i] == 'S' || X[i] == 'T' ) n++;
    else{ break; }
  }
  
  for( i = 0; i < n; i++ ){
    if( X[i] == 'S' ) cnt++;
    if( X[i] == 'T' ){
      if( cnt ) cnt--;
      else{     ans++;}
    }
  }
  
  ans += cnt;
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
//#include <ext/hash_map>
#include <tr1/unordered_map>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using namespace tr1;
//using namespace __gnu_cxx;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define DEB 0

//ツ催妥・ツ湘ウツ妥板青板づ個個按づ淞妥つソ
#define SZ 885777

const int dx[] = {1,0,-1,0}; //r,d,l,u
const int dy[] = {0,1,0,-1};

int w,h,sx,sy,home,last;
int field[16][16];
int num[16][16];
int hS[25],hx[25],hy[25],edge[25][4][25]; //[src][dir][dest]
//hash_map<int,int> hii(SZ);
unordered_map<int,int> hii(SZ);


inline bool isnotgoal(int s){
  return (((last&s)) == last);
}
inline bool isnot(int s){
  rep(i,home)if( !(s&(1<<i)) ){
    if( (hS[i]&s)==hS[i] ) return true;
  }
  return false;
}
inline bool inside(int x, int y){
  return (x<0 || y<0 || x>=w || y>=h);
}

int dfs(int S){
  int src = S&((1<<5)-1);
  int s = S>>5;

  if( (1<<home)-1 == s ){ //ツ静「ツ妥篠づ可姪淞づェツづゥ
    return 1;
  }
  if( isnotgoal(s) ){ //ツ仰ウツ嘉ッツづ可姪淞づゥツつスツづ淞づ個嘉づーツ湘氾ッツつオツつスツつゥツづつ、ツつゥ
    return 0;
  }
  //hash_map<int,int>::iterator it = hii.find(S);
  unordered_map<int,int>::iterator it = hii.find(S);
  if( it!=hii.end() ){ //ツ探ツ催オツ催渉づ敖づ個湘ウツ妥板つゥツづつ、ツつゥ
    return it->second;
  }

  // ツプツδ個ゼツδ督トツつェツ置ツつッツづ按つ「ツ嘉づ個有ツ鳴ウ
  if( s>0 && ((s&(s-1))!=0) && isnot(s&~(1<<src)) ){
    return 0;
  }
  
  int ret = 0;
  rep(k,4){
    for(int j=0; edge[src][k][j]!=-1; j++){
      int dest = edge[src][k][j];
      int nx = hx[dest];
      int ny = hy[dest];
      if( field[ny][nx]==1 ){
	field[ny][nx] = 0;
	ret += dfs(((s|(1<<dest))<<5)|dest);
	field[ny][nx] = 1;
	break;
      }
    }
  }
  hii.insert(make_pair(S,ret));
  return ret;
}

int main(){

  while(scanf("%d%d",&w,&h),w|h){
    hii.clear();
    memset(num,-1,sizeof(num));
    memset(edge,-1,sizeof(edge));
    memset(hS,0,sizeof(hS));
    home = last = 0;
    rep(i,h){
      rep(j,w){
	scanf("%d",&field[i][j]);
	if( field[i][j]==2 ){
	  sx=j; sy=i;
	}
	if( field[i][j]==1 ){
	  hx[home]=j; hy[home]=i;
	  num[i][j] = home;
	  home++;
	}
      }
    }
    hx[home] = sx;
    hy[home] = sy;

    // other homes
    rep(i,home){
      rep(k,4){
	int sz = 0;
	for(int j=1; j<20; j++){
	  int tx = hx[i] + dx[k]*j;
	  int ty = hy[i] + dy[k]*j;
	  if( inside(tx,ty) ) break;
	  if( field[ty][tx]==1 ){
	    hS[i] |= (1<<num[ty][tx]);
	    edge[i][k][sz++] = num[ty][tx];
	  }
	}
      }
    }

    //last homes
    rep(k,4){
      int sz = 0;
      for(int i=1; i<20; i++){
	int tx = sx + dx[k]*i;
	int ty = sy + dy[k]*i;
	if( inside(tx,ty) )break;
	if( field[ty][tx]==1 ){
	  last |= (1<<num[ty][tx]);
	  edge[home][k][sz++] = num[ty][tx];
	}
      }
    }
    printf("%d\n",dfs(home));
  }
  

  return 0;
}

Measured memory_bytes: 17000
#include <iostream>

using namespace std;

int main()
{
    int n;
    int a[100];

    cin >> n;

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

    for (int x = n - 1; x >= 0; x--)
    {
        if (x == n - 1)
        {
            cout << a[x];
        }
        else
        {
            cout << " " << a[x];
        }        
    }

    cout << endl;

    return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep_ll(i,n) for(ll i = 0; i < (ll)(n); i++)

using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;

const long double PI = (acos(-1));
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

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

  string s, t;

  cin >> s >> t;
  int ans = 0;

  rep(i,3){
    if(s[i]==t[i]) ans++;
    else continue;
  }

  cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<double,int> pp;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i) cin >> a[i];
    sort(a.begin(), a.end());

    int p = a[n-1];
    vector<pp> b(n-1);
    for(int i=0; i<n-1; ++i) b[i] = pp(fabs(a[i] - (double)p / (double)2), i);
    sort(b.begin(), b.end());
    int q = a[b[0].second];

    cout << p << ' ' << q << endl;
}

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

int main(){
  int A, H;
  cin >> H >> A;
  int count;
  if (H % A == 0){
    count = H / A;
    cout << count << endl;
  }
  else{
    count  = H / A + 1;
    cout << count << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
  int N,i,a,b,c,d;
  char S[5];
  a=0;
  b=0;
  c=0;
  d=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%s",S);
    if(strcmp(S,"AC")==0) a++;
    if(strcmp(S,"WA")==0) b++;
    if(strcmp(S,"TLE")==0) c++;
    if(strcmp(S,"RE")==0) d++;
  }
  printf("AC x %d\n",a);
  printf("WA x %d\n",b);
  printf("TLE x %d\n",c);
  printf("RE x %d\n",d);
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    int a , b;
    cin >> a >> b;
    cout << a * b << endl;

    return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

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

   int n = s.size();
   for (int i = 0; i < n; ) {
      string dreamErase = s.substr(i, 10);
      string dreamEraser = s.substr(i, 11);
      string char5 = s.substr(i, 5);
      string char6 = s.substr(i, 6);
      string char7 = s.substr(i, 7);

      if (dreamEraser == "dreameraser") {
         i += 11;
      } else if (dreamErase == "dreamerase") {
         i += 10;
      } else if (char7 == "dreamer") {
         i += 7;
      } else if (char6 == "eraser") {
         i += 6;
      } else if (char5 == "erase" || char5 == "dream") {
         i += 5;
      } else {
         puts("NO");
         return 0;
      }
   }

   puts("YES");

   return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    cout << a[0] << b[1] << c[2] << endl;
}


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

int main (){
  int k,tmp;
  cin >> k;
  for (int i = 1; i <= k; i++) {
    if (i % 3 == 0) cout << " " << i;
    else {
      for (int j = 0; j < 6; j++) {
	tmp = i / (std::pow(10,j));
	if (tmp % 10 == 3) {
	  cout  << " " << i;
	  break;
	}
      }
    }
  }

  cout << endl;
  return 0;
}



Measured memory_bytes: 3276
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int main()
{
    int n; cin>>n;
    ll sq=0;
    while((sq+1)*(sq+1)<=n) sq++;
    ll ans=0;
    auto sum=[](ll x){
        return ((x*(x+1))>>1);
    };
    for(ll i=1; i<=sq; i++){
        ans+=sum(i)*(sum(n/i)-sum(n/(i+1)));
    }
    for(ll i=1; i<=sq && n/i>sq; i++){
        ans+=i*sum(n/i);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3600
n=int(input())
d=[]
ans=0
for i in range(n):
    tmp=[int(j) for j in input().split()]
    d.append(tmp)
for i in range(n):
    for j in range(i+1,n):
        ans+=d[i][j]

for i in range(n):
    for j in range(i+1,n):
        for k in range(n):
            if i==k or j==k:
                continue
            if d[i][j]>d[i][k]+d[k][j]:
                print(-1)
                exit()
            elif d[i][j]==d[i][k]+d[k][j]:
                ans-=d[i][j]
                break
print(ans)


Measured memory_bytes: 43228
use proconio::input;

fn main() {
  let mut _d : i128 ;
  

   input! {
    d : i128 ,
  
 }
 if d == 22 {
  println!("Christmas Eve Eve Eve");
 }else if d == 23 {
   println!("Christmas Eve Eve");
 }else if d == 24 {
  println!("Christmas Eve");
 }else if d == 25 {
  println!("Christmas ");
 }else {
   println!("normal day");
 }



}


Measured memory_bytes: 2084
#include <stdio.h>

int main() {
  int a,b,c,t;
  scanf("%d %d %d\n",&a,&b,&c);

 if (b>c) 
 {
   t=b;
   b=c;
   c=t;
 }

 if (a>b) 
 {
   t=a;
   a=b;
   b=t;
 }
 
 if (b>c) 
 {
   t=b;
   b=c;
   c=t;
 }
 
 printf("%d %d %d\n",a,b,c );
  
  return 0;
}


Measured memory_bytes: 2060
a=int(input())
c=list(map(int,input().split(" ")))
b=[]
for i in range(1,a+1):
    b.append(i)
b.sort()
co=0
for j in range(0,a):
    if b[j]!=c[j]:
        co+=1
if co==0 or co==2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            // 文字列の入力
            string s = Console.ReadLine();

            for(int i = 0; i<s.Length; ++i) {
                var left = i >= 2 ? s.Substring(0, i - 1) : "";
                var temp = left + s.Substring(i + 1, s.Length - i - 1);
                
                if (temp.Contains(s[i])) {
                    Console.WriteLine("no");
                    return;
                }
            }

            Console.WriteLine("yes");

         }
    }
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    
    ll Zmin = MIN(X,Y), Zmax = MAX(X,Y);
    ll D1 = A*X + B*Y;
    ll D2 = A*MAX(X-Zmin,0) + B*MAX(Y-Zmin,0) + 2*C*Zmin;
    ll D3 = 2*C*Zmax;
    PR(MIN(MIN(D1,D2),D3));
    

    return 0;
}

/*



*/

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'


void solve(int rad, int n, vi l, vi r, vi h) {
  double ok = 0, ng = 20 + rad;
  rep (_, 10000) {
    bool flag = true;
    double t = (ok + ng) / 2.0;
    for (int x = -rad; x <= rad; x++) {
      int left_ma = 0, right_ma = 0;
      rep (i, n) {
        if (l[i] < x && x < r[i]) {
          chmax(left_ma, h[i]);
          chmax(right_ma, h[i]);
        }
        else if (l[i] == x) {
          chmax(right_ma, h[i]);
        }
        else if (r[i] == x) {
          chmax(left_ma, h[i]);
        }
      }
      int ma;
      if (x == -rad) ma = right_ma;
      else if (x == rad) ma = left_ma;
      else ma = min(left_ma, right_ma);
      double y = sqrt(rad*rad - x*x) - rad + t;
      if (y > ma) {
        flag = false;
        break;
      }
    }
    if (flag) ok = t;
    else ng = t;
  
  }
  Sp(ok);
}

int main() {
  while (true) {
    int rad, n;
    cin >> rad >> n;
    if (rad == 0) return 0;
    vi l(n), r(n), h(n);
    rep (i, n) {
      cin >> l[i] >> r[i] >> h[i];
    }
    solve(rad, n, l, r, h);
  }
}



Measured memory_bytes: 3272
#include "bits/stdc++.h"
#include <set>

using namespace std;
#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 rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int x, n;
	cin >> x >> n;
	vector<int>p(n);
	rep(i, n) {
		cin >> p[i];
	}

	auto result = std::find(p.begin(), p.end(), x);
	if (result == p.end()) {// not found
		print(x);
		return 0;
	}
	int abs = 1;
	while (true) {
		auto result = std::find(p.begin(), p.end(), x-abs);
		if (result == p.end()) {
			print(x-abs);
			return 0;
		}
		result = std::find(p.begin(), p.end(), x + abs);
		if (result == p.end()) {
			print(x+abs);
			return 0;
		}
		abs++;
	}
}

Measured memory_bytes: 3632
fun main(args: Array<String>) {
    val (x, y) = readLine()!!.split(" ").map{ it.toInt() }
    var list = (1..x).toList()
    for (i in 0 until y){
        val n = readLine()!!.toInt()
        readLine()!!.split(" ").map { it.toInt() }.forEach {
            list = list.minus(it)
        }
    }
    println(list.size)
}


Measured memory_bytes: 39844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
	public static void main(String[] args){
		FastScanner sc = new FastScanner(System.in);
		String S = sc.next();
		String a = S.substring(0, 2);
		String b = S.substring(2, 4);
		String ans = "NA";
		if (Integer.parseInt(a) <= 12 && Integer.parseInt(a) != 0 && Integer.parseInt(b) <= 12 && Integer.parseInt(b) != 0) {
			ans = "AMBIGUOUS";
		} else if (Integer.parseInt(a) <= 12 && Integer.parseInt(a) != 0) {
			ans = "MMYY";
		} else if (Integer.parseInt(b) <= 12 && Integer.parseInt(b) != 0) {
			ans = "YYMM";
		} else {
			//
		}
		System.out.println(ans);
	}

}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 22740
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using Int = long long;
Int inf = 100000000000000001LL;
int main() {
    int N;
    cin >> N;
    vector<Int> h = vector<Int>(N+1);
    for(int i=1;i<=N;i++){
        cin>>h[i];
    }
    vector<Int> dp = vector<Int>(N+1, inf);
    dp[1] = 0;

    for(int i=1; i<=N+1; i++){
        if(i+1<=N){
            dp[i+1] = min(dp[i+1],abs(h[i+1] - h[i]) + dp[i]);
        }
        if(i+2<=N){
            dp[i+2] = min(dp[i+2],abs(h[i+2] - h[i]) + dp[i]);
        }

    }

    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 1792
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto tx = input.front.split.to!( long[] );
	return tuple( tx[ 0 ], tx[ 1 ] );
}

auto solve( long t, long x )
{
	return cast( real )( t ) / x;
}


Measured memory_bytes: 256
// @Author :- Gaurav Bharti
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define empb emplace_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define vii vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define mapii map<int,int> 
#define mapll map<ll,ll>
#define all(a) a.begin(),a.end()
#define test ll t; cin>>t; while(t--)
#define prec(n) fixed<<setprecision(n)
#define ItsFUN ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007

vector<vector<int>> groups;
vector<bool> visited;

void dfs(int x,int &size){

    if(visited[x]) return ;
    visited[x] = true ;
    size++;
    for(int next : groups[x])
        dfs(next,size);
    return ;
}

int main(){ 
	ItsFUN;

    int n,p,i,j,x,y; cin >> n >> p;
    visited.resize(n+1,false),groups.resize(n+1);
    for(i=0;i<p;i++){
        cin>>x>>y;
        groups[x].push_back(y);
        groups[y].push_back(x);
    }

    int ans=0,size;
    for(i=1;i<=n;i++) {
        if(!visited[i]) {
            size = 0;
            dfs(i,size);
            ans=max(ans,size);
        }
    }

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


Measured memory_bytes: 20260
#include <iostream>

using namespace std;


int main(void){
  
 
	int r, c;
	int countC = 0;
	int *countR;
	cin >> r >> c;
	countR = new int[c + 1];
	for (int i = 0; i < c + 1; i++)
		countR[i] = 0;

	for (int i = 0; i<r; i++) {
		int number;
		for (int j = 0; j<c; j++) {
			cin >> number;
			cout << number << " ";
			countC += number;
			countR[j] += number;
		}
		cout << countC << endl;
		countC = 0;
	}

	for (int i = 0; i<c; i++) {
		cout << countR[i] << " ";
		countR[c] += countR[i];
	}
	cout << countR[c] << endl;
	delete[] countR;
return 0;
}

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

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

const int INF = 1e9 + 7;

using namespace std;

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

	int n, m;
	cin >> n >> m;

	vector<vector<int>> node(n);
	rep (i, 0, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		node[a].push_back(b);
	}

	int res = 0;
	int min_g = INT_MAX;
	rep (i, 0, n) {
		if (i == min_g) {
			min_g = INT_MAX;
			res++;
		}
		for (int ele : node[i]) {
			min_g = min(min_g, ele);
		}
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 5760
import java.util.*;

public class Main {
	void doIt() {
		Scanner in = new Scanner(System.in);
		Person[][] personArray = new Person[3][8]; //選手の番号とタイムを格納
		Person[] sub = new Person[18]; //決勝にいけなかった選手を格納
		for (int i=0; i<3; i++) { //各組
			for (int j=0; j<8; j++) { //各組の選手
			int tmpname = in.nextInt();
			String tmptime = in.next();
			personArray[i][j] = new Person(tmpname, tmptime);
			}
			Arrays.sort(personArray[i]); //タイムの速い順に並べ替える
			System.out.println(personArray[i][0]); //１番目の選手
			System.out.println(personArray[i][1]);
			for (int j=i*6, k=2; j<(i+1)*6; j++,k++) { //決勝にいけなかった選手を組関係なく全て格納
				sub[j] = personArray[i][k];
			}
		}
		Arrays.sort(sub);
		System.out.println(sub[0]);
		System.out.println(sub[1]);
	}
	public static void main(String[] args) {
		new Main().doIt();
	}
	class Person implements Comparable<Person> {
		int name;
		String time;
		Person (int name, String time) {
				this.name = name;
				this.time = time;
		}
		@Override
		public String toString() {
			return name + " " + time;
		}
		@Override
		public int compareTo(Person o) {
			return time.compareTo(o.time);
		}
	}
}

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

const long long MOD = 1000000007;
const int INF = 1e9;

int main(){
  long long n;
  const long long max_n = 2 * 1e5;
  long long a[max_n + 1];
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];
  
  long long sum_a[max_n + 1];
  sum_a[0] = a[0] % MOD;
  for(int i = 1; i < n; i++){
    sum_a[i] = sum_a[i-1] + a[i];
    sum_a[i] %= MOD;
  }

  long long ans = 0;
  for(int i = 0; i < n-1; i++){
    long long tmp = sum_a[n-1] - sum_a[i];
    tmp %= MOD;
    if(tmp < 0) tmp += MOD;
    tmp = tmp * a[i];
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int state=0;

		String a = br.readLine();
		String b = br.readLine();
		
		boolean flag=true;
		for(int i=0;i<a.length();i++){
			flag=true;
			if(i+b.length()>a.length()){
				break;
			}
			for(int j=0;j<b.length();j++){
				if(a.charAt(i+j)!=b.charAt(j)){
					flag=false;
					break;
				}
			}
			if(flag){
				System.out.println(i);
			}
		}
	}

}



Measured memory_bytes: 24304
import sys

# sys.stdin = open('d1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    s = read_str()
    res = 'First'
    if (len(s) % 2 == 0) ^ (s[0] == s[-1]):
        res = 'Second'
    print(res)


main()


Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
char str[11]={'\0'};
int main()
{
    int len;
    int i,j=0,ans=0;
    scanf("%s",str);
    len=strlen(str);
    for(i=0;i<len;i++)
    {
        if(str[i]=='A'||str[i]=='G'||str[i]=='C'||str[i]=='T')
        {
            j++;
            ans=max(j,ans);
        } 
        else
        {
            j=0;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256