akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			List<Boolean[]> list = new ArrayList<Boolean[]>();
			for (int i = 0; i < n; i++) {
				int a = scanner.nextInt();
				int b = scanner.nextInt();
				int c = scanner.nextInt();
				if (a == 1) {
					int aa = -1;
					loop: for (int j = list.size() - 1; j >= 0; j--) {
						Boolean[] tmp = list.get(j);
						for (int k = c; k < c + b; k++) {
							if (tmp[k]) {
								break loop;
							}
						}
						aa = j;

					}
					if (aa == -1) {
						Boolean[] newMap = new Boolean[6];
						for (int k = 0; k < 6; k++) {
							if (c <= k && k < c + b) {
								newMap[k] = true;
							} else {
								newMap[k] = false;
							}
						}
						list.add(newMap);
					} else {
						Boolean[] tmp = list.get(aa);
						for (int k = c; k < c + b; k++) {
							tmp[k] = true;
						}
					}
				} else {
					int bb = b;
					int count = 0;
					for (int j = list.size() - 1; j >= 0; j--) {
						if (list.get(j)[c]) {
							break;
						} else {
							count++;
						}
					}
					int cn = Math.max(list.size() - count, 0);
					for (int j = cn; j < list.size() && j < cn + b; j++) {
						list.get(j)[c] = true;
						bb--;
					}
					if (bb > 0) {
						for (int j = 0; j < bb; j++) {
							Boolean[] boo = new Boolean[6];
							Arrays.fill(boo, false);
							boo[c] = true;
							list.add(boo);
						}
					}

				}
				for (Iterator<Boolean[]> iterator = list.iterator(); iterator
						.hasNext();) {
					Boolean[] bools = iterator.next();
					int sum = 0;
					for (Boolean bo : bools) {
						if (bo)
							sum++;
					}
					if (sum == 5)
						iterator.remove();
				}
			}
			int ret = 0;
			for (Boolean[] ans : list) {
				for (Boolean b : ans) {
					if (b) {
						ret++;
					}
				}
			}
			System.out.println(ret);
		}
	}
}

Measured memory_bytes: 30676
#include <iostream>
#include <cstdio>
using namespace std;
int n, m;
bool graph[110][110];
bool unshowed[110][110];
int main(){
	scanf("%d%d", &n, &m);
	for( int i = 1; i <= n; ++i )
		for( int j = 1; j <= m; ++j ){
			char c;
			scanf("%c", &c);
			while( c != '#' && c != '.' )
				scanf("%c", &c);
			if( c == '#' )
				graph[i][j] = true;
		}
	for( int i = 1; i <= n; ++i ){
		bool con = true;
		for( int j = 1; j <= m; ++j )
			if( graph[i][j] )
				con = false;
		if( con )
			for( int j = 1; j <= m; ++j )
				unshowed[i][j] = true;
	}
	for( int j = 1; j <= m; ++j ){
		bool con = true;
		for( int i = 1; i <= n; ++i )
			if( graph[i][j] )
				con = false;
		if( con )
			for( int i = 1; i <= n; ++i )
				unshowed[i][j] = true;
	}
	for( int i = 1; i <= n; ++i ){
		bool con = true;
		for( int j = 1; j <= m; ++j ){
			if( unshowed[i][j] )
				continue;
			con = false;
			if( graph[i][j] )
				putchar('#');
			else
				putchar('.');
		}
		if( !con )
			puts("");
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int ans = 9999;
    for (int i = 0; i < N; ++i) {
        int ci, ti;
        cin >> ci >> ti;
        if (ti > T) continue;
        if (ci < ans) {
            ans = ci;
        }
    }
    if (ans == 9999) {
        cout << "TLE" << endl;
    } else {
        cout << ans << endl;
    }
}


Measured memory_bytes: 888
import java.util.Scanner;
import java.util.ArrayList;
 
public class Main {
 
	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        String hoge = sc.next();
        int count = 0;
        for(int i = 0; i < hoge.length(); i++){
            if((i + 1) % 2 != 0){
                if(hoge.charAt(i) != 'R' && hoge.charAt(i) != 'U' && hoge.charAt(i) != 'D'){
                    count++;
                }
            }else{
                if(hoge.charAt(i) != 'L' && hoge.charAt(i) != 'U' && hoge.charAt(i) != 'D'){
                    count++;
                }
            }
        }
        if(count == 0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }     
}

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

using namespace std;

using ll = long long;


bool is_prime(ll x){
  for(int i=2; i*i<x; i++){
    if(x%i==0){
      return false;
    }
  }
  
  return true;
}


int main(){
  ll X;
  cin >> X;
    
  while(true){
    if(is_prime(X)){
      cout << X << endl;
      break;
    }
    X += 1; 
  }
  
  return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    
    for (ll i = 1; i <= n; i++)
    {
        ll ans = 0;

        for (ll x = 1; x * x < i; x++)
        {
            for (ll y = 1;  y * y + x * y + x * x < i; y++)
            {
                for (ll z = 1; x * x + y * y + z * z + x * y + y * z + z * x <= i; z++)
                {
                    if (x * x + y * y + z * z + x * y + y * z + z * x == i)
                    {
                        ans++;
                    }
                }
            }
        }
        
        cout << ans << endl;
    }
}

Measured memory_bytes: 3504
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    ll n,a,b;
    in>>n>>a>>b;
    if((a+b)&1){
        cout<<min(a+(b-a)/2,n-b+1+(n-(a+n-b+1))/2)<<endl;
    }
    else cout<<(b-a)/2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define vii vector<pair<int,int> >
#define vi vector<ll>
#define ll long long
#define rep(i,a,b) for(i=a;i<=b;i++)
#define inf 100000000000000000
 
using namespace std;
 
ll n,W;
ll w[101],v[101];
ll dp[101][100001];
 
int main()
{
    cin>>n>>W;
    int mx=0;
    for(int i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
        mx+=v[i];
    }
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=mx;j++)
        {
            dp[i][j]=W+1;
        }
    }
    for(int i=0;i<=n;i++)
    {
        dp[i][0]=0;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=mx;j++)
        {
            if(j>=v[i-1])
            {
                dp[i][j]=min(dp[i][j],min(dp[i-1][j],dp[i-1][j-v[i-1]]+w[i-1]));
            }
            else dp[i][j]=min(dp[i][j],dp[i-1][j]);
        }
    }
    // for(int i=0;i<=n;i++)
    // {
    //     for(int j=0;j<=mx;j++)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    int ans=0;
    for(int i=0;i<=mx;i++)
    {
        if(dp[n][i]<=W)
        {
            ans=max(ans,i);
            //cout<<i<<" "<<dp[n][i]<<"\n";
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 79104
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define rep(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define irep(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define rrep(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

const int MOD = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n) {
        cin >> a[i];
        a[i]--;
    }


    vector<bool> pressed(n, false);

    int now = 0;
    bool flag = false;
    int i = 0;
    while (!pressed[now]) {
        if (now == 1) {
            flag = true;
            break;
        }
        pressed[now] = true;
        now = a[now];
        i++;
        
    }
    cout << (flag ? i : -1) << endl;

    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define vi vector<int>
#define pb push_back
#define F first
#define S second
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1e9+7;

int main(){
    string s;
    cin >> s;
    string t = s;
    reverse(s.begin(), s.end());
    if(s != t){
        cout << "No";
        return 0;
    }
    string l = s.substr(0, (s.size()-1)/2);
    string r = l;
    reverse(r.begin(), r.end());
    if(r == l) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

ll l[35];
ll dis[120010];

ll power(ll m, ll n){

    l[0]=m;
    for(ll i=1; i<30; i++){
        l[i] = (l[i-1]*l[i-1]) % MOD;
    }

    ll tmp = n;
    ll ans = 1;
    rep(i,35){
        if(tmp%2==1){
            ans = (ans*l[i]) % MOD;
        }
        tmp /= 2;
    }
    return ans;

}

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

ll s[100010];

void solve(){

    ll n,k;
    cin >> n >> k;

    for(ll i=k; i>=1; i--){
      s[i]=(power((k/i),n))%MOD;
      for(ll c=2; c*i<=k; c++){
        s[i] = (s[i] - s[i*c] + MOD)%MOD;
      }
    }

    ll ans = 0;
    rep(i,k+1){
      //cout << s[i] << endl;
      ans = (ans + s[i]*i)%MOD;
    }

    cout << ans << endl;

    

}

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


Measured memory_bytes: 4388
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n; string s;
    cin>>n>>s;
    int ans=0;
    rep(i,n-2){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        n : u64
    }

    println!(
        "{}",
        (1..=n).filter(|&x| x % 3 != 0 && x % 5 != 0).sum::<u64>()
    );
}


Measured memory_bytes: 2140
#include <stdio.h>

int main(void)
{
	int a,b,c[7],d;
	for (d=0;d<7;d++){
	scanf("%d %d",&a,&b); 
	c[d]=a-b;
	}
	for (d=0;d<7;d++){
	printf("%d\n",c[d]);
	}
	return 0;
}



Measured memory_bytes: 2112
dic = {1:0,0:1}

from collections import deque 
#スタック
q = deque([])#append pop

N = int(input())
#木
tree = [[]for i in range(0,N+1,1)]
for i in range(1,N,1):
    u,v,w = map(int,input().split())
    tree[u].append([v,w])
    tree[v].append([u,w])
ans = [0]*(N+1)

q.append([1,0,0])#今回のノード、距離、前回のノード

while len(q)>0:
    now,dist,pre = q.pop()
    ans[now] = (ans[pre] + dist%2)%2
    for i in tree[now]:
        if i[0]!=pre:
            q.append([i[0],i[1],now])

for i in range(1,N+1,1):
    print(ans[i])

Measured memory_bytes: 82464
#include <bits/stdc++.h>
#define MAXN 200005
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(c) (c).begin(), (c).end()
using namespace std;

ll n, k, x;
vector <ll> v;
ll sol;

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> x; v.pb(x);
	}
	sort(all(v));
	for (int i = 0; i < n - k; ++i) {
		sol += v[i];
	}
	cout << sol;
	return 0;
}


Measured memory_bytes: 2420
import sys
N,M = map(int,input().split())
s = []
c = []
for i in range(M):
    S,C = map(int,input().split())
    s.append(S)
    c.append(C)
    

for i in range(10**(N+1)):
    st = str(i)

    if  len(st) == N and all([st[s[j]-1] == str(c[j]) for j in range(M)]):
        print(st)
        sys.exit()
        
print(-1)

Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    map<int, int> mp;
    mp[a]++;
    mp[b]++;
    mp[c]++;
    for (auto p : mp)
    {
        if (p.second == 1)
        {
            cout << p.first << endl;
        }
    }
}

Measured memory_bytes: 256
S =input()
l=len(S)

    
apopcount=0
bpopcount=0
for i in range(0,l):
  if i%2==0:
    if int(S[i])==1:
   		apopcount+=1
    else:
      	bpopcount+=1
  else:
    if int(S[i])==1:
    	bpopcount+=1
    else:
      	apopcount+=1
if apopcount<bpopcount:print(apopcount)
else:print(bpopcount) 

Measured memory_bytes: 3188
n=input()
a=[int(i) for i in input().split()]
def chk(a,t):
    ans=0
    x=0
    for i in a:
        x+=i
        if t==True and x<1:
            ans+=1-x
            x=1
        elif t==False and x>-1:
            ans+=x+1
            x=-1
        t=not t
    return ans
print(min(chk(a,True),chk(a,False)))

Measured memory_bytes: 14212
import java.util.*;
	public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);

            String s = sc.next();
            int k = Integer.parseInt(sc.next());
            int[][] dic = new int[s.length()][4];
            int temp = 0;
            int temp2 = 0;
            int j = 1;
            
            for(int i=0; i<s.length(); i++){
            	dic[i][0] = i;
            	dic[i][1] = s.charAt(i);
            	dic[i][2] = 0;
            	dic[i][3] = i;
            }
            
            Arrays.sort(dic, (a, b) -> Integer.compare(a[2], b[2]) * 2 + Integer.compare(a[1], b[1]));
            
            while(k > 1){
//            	if(dic[0][2] < dic[1][2] && dic[0][1] < dic[1][1]){
//            		k -= s.length() - dic[0][0] + 1;
//            		dic[0][2] = 0;
//            		dic[0][1] = 200;
//            		Arrays.sort(dic, (a, b) -> Integer.compare(a[2], b[2]) * 2 + Integer.compare(a[1], b[1]));
//            	}
            	
            	temp = dic[0][1];
            	temp2 = dic[0][2];
            	j = 1;
            	if(dic[0][0] == s.length()-1){
            		dic[0][2] = 1;
            	}else{
            		dic[0][1] = s.charAt(++dic[0][0]);
            		dic[0][2]--;
            	}
            	
            	while(j < s.length() && dic[j][2] == temp2 && dic[j][1] == temp){
            		if(dic[j][0] == s.length()-1){
            			dic[j][2] = 1;
            		}else{
            			dic[j][1] = s.charAt(++dic[j][0]);
            			dic[j][2]--;
            		}
            		j++;
            	}
            	k--;
            	Arrays.sort(dic, (a, b) -> Integer.compare(a[2], b[2]) * 2 + Integer.compare(a[1], b[1]));
            }

            System.out.println(s.substring(dic[0][3], dic[0][0] + 1));
            sc.close();
        }
    }
	

Measured memory_bytes: 28884
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N,K=get_i
k=0
ab=array(N)
N.times do|i|
  ab[i]=get_i
end
ab.sort!{|x,y| x[0]<=>y[0]}
ab.each do|a,b|
    k+=b
    if k>=K
        puts a
        break
    end
end

Measured memory_bytes: 21884
from collections import defaultdict
import sys
input = lambda: sys.stdin.readline().rstrip()

M = 998244353
B = pow(10, 18, M)
N = int(input())

def geometric_mod(a, r, m, n):
  x = a
  for i in range(n):
    yield x
    x = (x*r)%m

BB = list(geometric_mod(1, B, M, N+2))

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in e[i]})
    if m:
      g[i] = m
      sum_g[g[i]] = (sum_g[g[i]] + BB[i]) % M
      sum_g[0] = (sum_g[0] + BB[i]) % M
  sum_g[0] = (inv_mod(B-1, pow(B, N+1, M)-B, M) - sum_g[0]) % M
  return sum_g

def read_edge():
  M = int(input())
  e = defaultdict(set)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].add(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in sum_g[0].items():
    for gy, sy in sum_g[1].items():
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret = (ret + sx*sy*sz) % M
  return ret


edge = [read_edge() for i in range(3)]

print(solve(N, edge))

Measured memory_bytes: 77532
/*
  B - Training Camp
  Contest 055
  Rakesh Kumar --> 16/08/2020
 */

#include <bits/stdc++.h>

using ull = unsigned long long int;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0); std::cout.tie(0);

    ull n = 0;
    std::cin >> n;
    ull power = 1;
    for (int i = 1; i <= n; ++i)
        power = (power *= i) % static_cast<int>(((1e+9) + 7));
    std::cout << power << std::endl;

    return 0;
}


Measured memory_bytes: 3596
s = str(input())
l = 'qwertyuiopasdfghjklzxcvbnmAC'
if s[0]=="A":
    s_ = s[2:-1]
    c=0
    for w in s_:
        if w=='C':
            c+=1
    if c==1:
        for i in range(len(s)):
            if not s[i] in l:
                break
            if i==len(s)-1:
                print('AC')
                import sys
                sys.exit()
print('WA')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main()
{
    int h, w, d;
    string s[4] = {"GYYG", "RBBR", "YGGY", "BRRB"};
    string a[2] = {"RB", "GY"};


    cin >> h >> w >> d;
    int cnt = 0;
    if (d & 1)
        rep(i, h) rep(j, w)
        {
            int nx = i, ny = j;
            if (nx % 2 == 0 and ny % 2 == 0) {
                cout << "R";
            } else if (nx % 2 == 1 and ny % 2 == 0) {
                cout << "G";
            } else if (nx % 2 == 0 and ny % 2 == 1) {
                cout << "B";
            } else if (nx % 2 == 1 and ny % 2 == 1) {
                cout << "Y";
            }
            if (j == w - 1)
                cout << endl;
        }
    else {
        //        d /= 2;
        rep(i, h) rep(j, w)
        {
            int c = ((i + j) / d + 100000000) % 2;
            int b = ((i - j + 10000 * d) / d + 100000000) % 2;
            cout << a[c][b];
            if (j == w - 1)
                cout << endl;
        }
    }
}


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

int main() {
    ll n;
    cin >> n;
    map<ll, ll> mp;
    for (ll i = 0; i < n; ++i) {
        ll x;
        cin >> x;
        mp[x]++;
    }
    vector<ll> a;
    for (auto p : mp) {
        if (p.second >= 4) for (int i = 0; i < 2; ++i) a.emplace_back(p.first);
        else if (p.second >= 2) a.emplace_back(p.first);
    }
    sort(a.rbegin(), a.rend());
    if (a.size() < 2) cout << 0 << endl;
    else cout << a[0] * a[1] << endl;
}


Measured memory_bytes: 6528
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <queue>
#include <tuple>
#include <regex>
#include <cmath>
#include <map>
#include <set>
#include <cstring>
#include <climits>

#define RREP(i,a,b) for(int i=a;i<b;++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define INVREP(i,a,b) for(int i=a;i>=b;--i)
#define MOD 1000000007ll
#define BIT(i) (1ll<<i)
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }//aに更新したいものを
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

//繰り返し2乗
ll modpow(ll N, ll P, ll M=MOD) {if (P == 0) return 1;if (P % 2 == 0) {ll t = modpow(N, P / 2, M);return t * t % M;}return (N * modpow(N, P - 1, M))%M;}
//階乗
pair<vector<ll>, vector<ll>> fact(ll n) {vector<ll>f(n, 1);RREP(i, 2, n) f[i] = (f[i - 1]*i) % MOD;vector<ll>invf(n, 1);invf[n - 1] = modpow(f[n - 1],MOD-2,MOD);INVREP(i, n - 1, 2) invf[i - 1] = (invf[i]*i) % MOD;return pair<vector<ll>, vector<ll> >(f,invf);}
ll modmult(ll a, ll b, ll M = MOD) { return (a*b) % M; }
ll modadd(ll a, ll b, ll M = MOD) { return (a + b) % M; }
ll comb(pair<vector<ll>, vector<ll>>p, int n, int r) {return modmult(modmult(p.first[n], p.second[r]), p.second[n - r]); }
/*
    auto a = fact(200009);
    cout << comb(a,15,5) << endl;
*/

void solve()
{
    /* collection
    ll n;
    cin >> n;
    vector<ll> A;
    REP(i, n) cin >> A[i];
    vector<pair<ll, ll>> AB;
    REP(i, n) {cin >> AB[i].first;cin >> AB[i].second;}
    
    sort(ALL(vec),greater<int>());

    map<ll, ll> mp;
    map<ll, ll, greater<ll>> mp;
    REP(i, 100) mp[i] = i * 10;
    cout << mp.lower_bound(50)->second<<endl;
    cout << mp.upper_bound(50)->second << endl;
    cout << next(mp.upper_bound(50))->second << endl;
    cout << prev(mp.upper_bound(50))->second << endl;
    */
    int n,q;
    string s;
    cin >> n >> s >> q;
    int a = (int)'a';
    set<int> chars[26];
    REP(i, 26){
        chars[i].insert(10000000);
    }
    REP(i,n){
        chars[(int)s[i]-a].insert(i+1);
    }
    
    REP(time,q){
        int type;
        cin>>type;
        if(type==1){
            int i;char c;
            cin >> i >> c;
            chars[int(s[i-1])-a].erase(i);
            s[i-1]=c;
            chars[(int)c-a].insert(i);
        }else{
            int l,r,ans=0;
            cin >> l >> r;
            REP(i,26){
                if (*(chars[i].lower_bound(l))<=r) ans++;
            }
            cout << ans << '\n';
        }
    }
}

int main(){
    solve();
}


Measured memory_bytes: 26232
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define ll  long long
#define ull unsigned long long 
#define ff first 
#define ss second
#define eb(x) emplace_back(x)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define testcase(t) int t;cin>>t;while(t--)
#define mp(x,y) make_pair(x,y)
#define in(x) insert(x)
#define rep(i,a,b)  for (__typeof((b)) i=(a);i<=(b);i++)
#define nrep(i,a,b)  for (__typeof((b)) i=(b);i>=(a);i--)
#define PI 3.14159265358979323846
#define SP(x) setprecision(x)
#define reflex ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define M 998244353
#define sz(a) (int)a.size()
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(x) x.resize(distance(x.begin(), unique(all(x))))
#define mem(arr,val) memset(arr,val,sizeof(arr)) //For "0" and "-1"                  
#define inp0(a,n) rep(i,0,n-1) cin>>a[i];
#define inp1(a,n) rep(i,1,n) cin>>a[i]; 
#define prll(x) printf("%lld",x)
#define nth_ele(v,n) nth_element(v.begin(), v.begin()+n ,v.end())//O(N)
#define DEBUG(x) cerr << (#x) << ": " << (x) << endl
#define DEBUGV(x) for(auto IT:x) cout<<IT.ff<<" "<<IT.ss<<endl; cout<<endl;
#define minheap priority_queue <int, vector<int>, greater<int>>
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll gcd(ll n1, ll n2){if(n2!=0) return gcd(n2, n1%n2);else return n1;}
ll powerM(ll a,ll b){if(b==0) return 1LL;  if(b==1) return a%M; ll x=powerM(a,b/2)%M; if(b&1){return ((((a%M)*(x%M))%M)*(x%M))%M;}return ((x%M)*(x%M))%M;}
ll power(ll a,ll b){if(b==0) return 1;  if(b==1) return a; ll x=power(a,b/2); if(b&1){return ((((a)*(x)))*(x));}return ((x)*(x));}
 
const ll INF = (ll)2e18+77; 
const int SIZE = 100005;

signed main(){
    int n,k;
    cin>>k;
    string s;
    cin>>s;
    n=sz(s);
    if(n>k){
        rep(i,0,k-1) cout<<s[i];
        cout<<"...\n";
    }
    else{
        cout<<s<<endl;
    }
} 

Measured memory_bytes: 3628
N = int(input())
A = list(map(int, input().split()))
while len(A)>1:
  A.sort()
  tmp = [A[0]]
  for i in range(1,len(A)):
    if A[i]-A[0]>0 and A[i]%A[0]!=0:
      tmp.append(A[i]%A[0])
  A = tmp
print(A[0])

Measured memory_bytes: 14252
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	LL N,L;
	LL pre;
	cin >> N >> L;
	cin >> pre;
	for(int i=1;i<N;i++){
		LL cur;
		cin >> cur;
		if(pre+cur>=L){
			cout << "Possible" << endl;
			for(int j=1;j<i;j++){
				cout << j << endl;
			}
			for(int k=N-1;k>=i;k--){
				cout << k << endl;
			}
			return 0;
		}
		pre=cur;
	}
	cout << "Impossible" << endl;
}


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

	int *x = new int[n]();
	
	rep(i, q){
		int a;
		cin >> a;
		x[a-1]++;
	}

	rep(i, n){
		if(k - q + x[i] > 0) cout << "Yes\n";
		else cout << "No\n";
	}

	delete x;
	return 0;
}

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

class Program
{
	static void Main() => new Program().Solve();

	void Solve()
	{
		var n = ReadLong();

		Console.WriteLine(Math.Ceiling(n / 1000d) * 1000 - n);
	}

	#region Console.Read 関係
	long[] ReadLongArray() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
	long ReadLong() => long.Parse(Console.ReadLine());
	#endregion
}


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

int main(){
  char c;
  cin >> c;
  
  if(c == 'A'){
    cout << 'T' << endl;
  }else if(c == 'T'){
    cout << 'A' << endl;
  }else if(c == 'G'){
    cout << 'C' << endl;
  }else{
    cout << 'G' << endl;
  }
}

Measured memory_bytes: 256
H,W,K=map(int,input().split())
x1,y1,x2,y2=map(lambda x:int(x)-1,input().split())

pond=[]
for _ in range(H):
    pond.append(list(input()))

inf=10**7
cost=[[inf]*W for _ in range(H)]
cost[x1][y1]=0
from heapq import heapify,heappop,heappush
hq=[(0,x1,y1)]

while hq:
    t,x,y=heappop(hq)
    if x==x2 and y==y2:
      print(t)
      exit()
    #北へ
    for i in range(1,K+1):
        if x-i<0 or pond[x-i][y]=="@" or cost[x-i][y]<t+1:
            break
        if cost[x-i][y]>t+1:
            cost[x-i][y]=t+1
            heappush(hq,(t+1,x-i,y))
    #東へ
    for i in range(1,K+1):
        if y+i>W-1 or pond[x][y+i]=="@" or cost[x][y+i]<t+1:
            break
        if cost[x][y+i]>t+1:
            cost[x][y+i]=t+1
            heappush(hq,(t+1,x,y+i))
    #南へ
    for i in range(1,K+1):
        if x+i>H-1 or pond[x+i][y]=="@" or cost[x+i][y]<t+1:
            break
        if cost[x+i][y]>t+1:
            cost[x+i][y]=t+1
            heappush(hq,(t+1,x+i,y))
    #西へ
    for i in range(1,K+1):
        if y-i<0 or pond[x][y-i]=="@" or cost[x][y-i]<t+1:
            break
        if cost[x][y-i]>t+1:
            cost[x][y-i]=t+1
            heappush(hq,(t+1,x,y-i))

print(-1)



Measured memory_bytes: 43272
#include<iostream>
using namespace std;
int N;
string s;
long mod=1e9+7;
main()
{
	cin>>N>>s;
	long ans=1,cnt=0;
	for(int i=0;i<2*N;i++)
	{
		if(cnt%2==0)
		{
			if(s[i]=='B')
			{
				cnt++;
			}
			else
			{
				ans=ans*cnt--%mod;
			}
		}
		else
		{
			if(s[i]=='B')
			{
				ans=ans*cnt--%mod;
			}
			else
			{
				cnt++;
			}
		}
	}
	for(int i=1;i<=N;i++)ans=ans*i%mod;
	cout<<(cnt==0?ans:0)<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=a;i<=n;++i)
#define lpd(i,a,n) for(int i=a;i>=n;--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-9
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 100002;
int n;

bool prime(int x){
    if(x < 2) return false;
    for(int i = 2; 1ll*i*i <= x; ++i)
        if(x % i == 0) return false;
    return true;
}

int main(){
    readi(n);
    while(!prime(n)) ++n;
    cout <<n;
}

/*
uniform_int_distribution<type>(l, r)(rng)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
*/


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>

int N, K;

using namespace std;

vector<int> v;
int ans = 2000000000;

int main(){
	scanf("%d %d", &N, &K);
	for(int i=0; i<N; i++){
		int x;
		scanf("%d", &x); v.push_back(x);
	}
	for(int i=0; i+K-1<N; i++){
		int j = i+K-1;
		if(v[i] > 0){
			ans = min(ans, v[j]);
			continue;
		}
		if(v[j]<0){
			ans = min(ans, -v[i]);
			continue;
		}
		ans = min(-v[i]*2 + v[j], ans);
		ans = min(-v[i] + 2*v[j], ans);
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 892
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    string s; cin >> s;
    // dream, dreamer, erase, eraser

    ll cur = 0;
    ll solve = false;
    while (true) {
        if (s.substr(cur, 7) == "dreamer") {
            // 末尾のerがerase/eraser由来かを確かめる
            if (s.substr(cur+5, 5) == "erase") {
                cur += 5;
            } else {
                cur += 7;
            }
        } else if (s.substr(cur, 5) == "dream") {
            cur += 5;
        } else if (s.substr(cur, 6) == "eraser") {
            cur += 6;
        } else if (s.substr(cur, 5) == "erase") {
            cur += 5;
        } else if (cur == s.size()) {
            solve = true;
            break;
        } else {
            break;
        }
    }
    if (solve) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 3724
// abc115_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    ll ans = accumulate(ALL(A), 0) - *max_element(ALL(A)) / 2;
    print(ans);


    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# 全探索


def solve(i, m):
    global A, n

    if (m == 0):
        return True
    if (i >= n):
        return False

    res = solve(i + 1, m) or solve(i + 1, m - A[i])

    return res


if __name__ == "__main__":
    n = int(input())
    A = [int(i) for i in input().split()]
    q = int(input())
    m = [int(i) for i in input().split()]
    total = sum(A)
    for m_i in m:
        if m_i > total:
            print('no')
        else:
            print('yes' if solve(0, m_i) else 'no')



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

int main(){
  int n;
  long long x[1010], y[1010];
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> x[i] >> y[i];
  }

  int tmp = (abs(x[0]) + abs(y[0])) % 2;
  for(int i = 1;i < n;i++){
    if((abs(x[i]) + abs(y[i])) % 2 != tmp){
      cout << -1 << endl;
      return 0;
    }
  }

  long long d[40];

  int p = 0;
  if(tmp == 0){
    d[0] = 1;
    p++;
  }
  d[p] = 1;

  int m = 33;

  for(int i = p+1;i < m;i++){
    d[i] = d[i-1]*2;
  }

  cout << m << endl;
  for(int i = 0;i < m;i++){
    cout << d[i];
    if(i != m-1) cout << " ";
  }
  cout << endl;


  for(int i = 0;i < n;i++){
    stack<char> st;

    long long nx, ny;
    nx = x[i];
    ny = y[i];
    if(tmp == 0) nx++;

    for(int i = 32;i >= (1-tmp);i--){
      long long t = nx + d[i];
      if(abs(t) + abs(ny) > d[i]){
        t = nx - d[i];
        if(abs(t)+abs(ny) > d[i]){
          t = ny+d[i];
          if(abs(t) + abs(nx) > d[i]){
            t = ny-d[i];
            ny = t;
            st.push('U');
          }else{
            ny = t;
            st.push('D');
          }
        }else{
          nx = t;
          st.push('R');
        }
      }else{
        nx = t;
        st.push('L');
      }
    }


    if(tmp == 0){
      st.push('L');
    }

    while(!st.empty()){
      cout << st.top();
      st.pop();
    }

    cout << endl;
  }
  return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int num = Integer.parseInt(in.nextLine());
        int[] h = new int[num];
		for (int i = 0; i < num; i++) {
            h[i] = in.nextInt();
        }
		in.close();
      
        int max = h[0];
		int count = 1;
		for(int i = 1; i < num; i++) {
			if (max < h[i]) {
                max = h[i];
                count++;
            } else if (max == h[i]) {
                count++;
            }
		}
        System.out.println(count);
	}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

string b;
int solve(string a, int d){
    if(d==a.size()) return 0;
    if(a[d]==b[d]) return solve(a,d+1);
    int need=10, r=b[d]-a[d];
    range(i,d,a.size()){
        a[i]=(a[i]-'0'+r+10)%10+'0';
        need=min(need,solve(a,d+1));
    }
    return need+1;
}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int n;
	while(cin>>n,n){
		string a;
		cin>>a>>b;
		cout<<solve(a,0)<<endl;
	}
	return 0;
}



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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b && b == c) {
        cout << 1 << endl;
    } else if(a != b && b != c && a != c) {
        cout << 3 << endl;
    } else {
        cout << 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
struct node{
	int a;
	int b;
}a[1000000];
bool cmp(node a,node b)
{
	return a.a<b.a;
}
int main()
{
	int n,m;
	while(cin>>n>>m)
	{
		priority_queue<int> que;
		for(int i=0;i<n;i++) cin>>a[i].a>>a[i].b;
		sort(a,a+n,cmp);
		int cnt=0;
		int ans=0;
		for(int i=1;i<=m;i++)
		{
			while(cnt<n&&a[cnt].a<=i)
			{
				que.push(a[cnt].b);
				cnt++;
			}
			if(!que.empty())
			{
				ans=ans+que.top();
				que.pop();	
			} 
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 1660
#include<stdio.h>
int main(void){
    int n,a,b;
    scanf("%d %d %d",&n,&a,&b);
    
    if((n*a)<=b){
        printf("%d\n",n*a);
    }
    else{
        printf("%d\n",b);
    }
    return 0;
}


Measured memory_bytes: 128
from math import ceil
N = int(input())

Ans = 0
for i in range(1,N+1):
    d = []
    limit = ceil(N**.5)
    for j in range(1,limit):
        if i//j == i/j:
            if j not in d:
                d.append(j)
            if i//j not in d:
                d.append(i//j)
    if len(d)==8 and i%2==1:
        Ans += 1

print(Ans)




Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var mergeQuery = new long[M][];
            for (var i = 0; i < M; ++i)
                mergeQuery[i] = Sarray();
            var uf = new UnionFind((int)N+1);
            var fuben = N * (N - 1) / 2;
            var ans = new long[M];
            for (var i = M - 1; 0 <= i; --i)
            {
                ans[i] = fuben;
                var a = mergeQuery[i][0];
                var b = mergeQuery[i][1];
                if (!uf.issame((int)a, (int)b))
                    fuben -= uf.size((int)a) * uf.size((int)b);
                uf.merge((int)a, (int)b);
            }
            foreach (var a in ans)
                WriteLine(a);
            
            //Out.Flush();
        }
        class UnionFind
        {
            int[] par;
            public UnionFind(int n)
            {
                init(n);
            }
            public void init(int n)
            {
                par = new int[n];
                for (var i = 0; i < n; ++i) { par[i] = -1; }
            }
            public int root(int x)
            {
                if (par[x] < 0) return x;
                else return par[x] = root(par[x]);
            }
            public bool issame(int x, int y)
            {
                return root(x) == root(y);
            }
            public bool merge(int x, int y)
            {
                x = root(x);
                y = root(y);
                if (x == y) return false;
                if (par[x] > par[y])
                {
                    var tmp = y;
                    y = x;
                    x = tmp;
                }
                par[x] += par[y];
                par[y] = x;
                return true;
            }
            public int size(int x)
            {
                return -par[root(x)];
            }
        }
    }
}

Measured memory_bytes: 25140
var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim();
var n = +input;
var output=n;
 
var primes = [];
 
while (n % 2 == 0) {
    primes.push(2);
    n /= 2;
}
while (n % 3 == 0) {
    primes.push(3);
    n /= 3;
}
for (var i = 1; n > 1; i++) {
    var low = i * 6 - 1;
    var high = i * 6 + 1;
    while (n % low == 0) {
        primes.push(low);
        n /= low;
    }
    while (n % high == 0) {
        primes.push(high);
        n /= high;
    }
}


console.log(output + ': '+primes.join(' '));


Measured memory_bytes: 15388
/*
*  Author: windystreet
*  Date  : 2019-04-13 11:07:49
*  Motto : Think twice, code once.
*/
#include<bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define eps  1e-5
#define gcd __gcd
#define pb push_back
#define PI acos(-1.0)
#define lowbit(x) (x)&(-x)
#define bug printf("!!!!!\n");
#define mem(x,y) memset(x,y,sizeof(x))

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef unsigned long long uLL;

const int maxn = 1e5+7;
const int INF  = 1<<30;
const int mod  = 1e9+7;

bool ok(char c){
	if(c=='A' || c == 'C' || c =='G' || c == 'T')return true;
	return false;
}

void solve(){
	string s;
	cin>>s;
	int len = s.length();
	int ans = 0,cur = 0;
	for(int i=0;i<len;i++){
		if(ok(s[i])){
			++cur;
		}else{
			ans = max(ans,cur);
			cur = 0;
		}
	}
	ans = max(ans,cur);
	printf("%d\n",ans );
    return;
}

int main()
{
#ifndef ONLINE_JUDGE
   // freopen("F:/in.txt","r",stdin);
#endif
//    freopen("out.txt","w",stdout);
//    ios::sync_with_stdio(false);
    int t = 1;
    //scanf("%d",&t);
    while(t--){
    //    printf("Case %d: ",cas++);
        solve();
    }
    return 0;
}

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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Mll = M<ll, ll>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin(),ie=(c).rend();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n;
Vi v;

void dfs(int depth) {
    if (depth == n) {
        REP(i, n) cout << (char)('a'+v[i]);
        cout << '\n';
        return;
    }
    int maxi = 0;
    REP(i, depth) {
        maxi = max(maxi, v[i]);
    }
    REP(i, maxi+2) {
        v[depth] = i;
        dfs(depth+1);
    }
}

int main() {
    cin >> n;
    v = Vi(n);
    v[0] = 0;

    dfs(1);

    return 0;
}


Measured memory_bytes: 1536
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;
#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

typedef vector<int> vi;
typedef vector<vi> vvi;

struct Edge {
	int id, src;
	Edge(int id, int src) : id(id), src(src) {}
};

vvi mul(const vvi& a, const vvi& b)
{
	int n = a.size();
	vvi ret(n, vi(n, 0));
	rep(i, n) rep(j, n) rep(k, n)
		ret[i][j] |= a[i][k] * b[k][j];
	return ret;
}

vvi pow(const vvi& a, int n)
{
	int dim = a.size();
	vvi ret(dim, vi(dim));
	rep(i, dim) rep(j, dim)
		ret[i][j] = i == j;

	vvi mat = a;
	while(n){
		if(n&1)
			ret = mul(ret, mat);
		mat = mul(mat, mat);
		n >>= 1;
	}
	return ret;
}

int main()
{
	int n, m, z;

input:
	while(scanf("%d%d%d", &n, &m, &z), n){
		vector<vector<Edge> > edge(n);
		rep(i, m){
			int a, b;
			scanf("%d%d", &a, &b);
			if(a>b)
				swap(a, b);
			--a;
			--b;
			edge[a].push_back(Edge(i*2, b));
			edge[b].push_back(Edge(i*2+1, a));
		}

		vvi mat(m*2, vi(m*2, 0));
		rep(i, n){
			rep(j, edge[i].size()){
				int src = edge[i][j].src;
				rep(k, edge[src].size()){
					Edge e = edge[src][k];
					if(e.src == i)
						continue;
					mat[edge[i][j].id][e.id] = 1;
				}
			}
		}
		vvi ret = pow(mat, z-1);

		bool ok = false;
		rep(i, n) rep(j, edge[i].size()){
			if(edge[i][j].src == 0){
				rep(k, edge[n-1].size()){
					if(ret[edge[n-1][k].id][edge[i][j].id])
						ok = true;
				}
			}
		}
		puts(ok ? "yes" : "no");
	}
	return 0;
}

Measured memory_bytes: 1204
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>

using namespace std;

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  long long ans = 0;
  if (k % 2 == 0) {
    long long v = n / k;
    ans += v*v*v;
    long long w = n / (k / 2);
    ans += (w - v)*(w - v)*(w - v);
  }
  else {
    long long v = n / k;
    ans = v*v*v;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 128