akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <cstring>

int main(void)
{
  int a, b, t;
  std::cin >> a >> b >> t;
  int q = (t + 0.5) / std::max(1, a);
  std::cout << b * q << std::endl;
  return 0;
}


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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
#define INF             1000000000

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

void init(){
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

const int N = 55;

char nxtABC(char cmp){
	return 'A'+ ((cmp - 'A' + 1) % 3);
}

int main()
{
	init();
	int n, ans = 0;
	char cmp = 'A';
	string str;
	cin >> n >> str;
	for(int i = 0; i < (int)str.size(); ++i){
		if(str[i] == cmp){
			ans += (cmp == 'C');
			cmp = nxtABC(cmp);
		}
		else if(str[i] == 'A'){
			cmp = 'B';
		}
		else{
			cmp = 'A';
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int,int> P;

int cs[11451],rs[11451],mo[6000];
vector<vector<int>> edge;
bool go[6000];
void bfs(int s,int r){
    memset(go,0,sizeof(go));
    queue<int> q;
    go[s]=true;
    q.push(s);
    for(int i=0;i<r;i++){
        int qsize=q.size();
        for(int j=0;j<qsize;j++){
            int n=q.front();q.pop();
            for(int k=0;k<edge[n].size();k++){
                int ne=edge[n][k];
                if(!go[ne]){
                    go[ne]=true;
                    q.push(ne);
                }
            }
        }
    }
}
int main(){
    int N,K;
    scanf("%d%d",&N,&K);
    for(int i=0;i<N;i++){
        scanf("%d%d",&cs[i],&rs[i]);
    }
    edge=decltype(edge)(N);
    int a,b;
    for(int i=0;i<K;i++){
        scanf("%d%d",&a,&b);
        a--;b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    memset(mo,127,sizeof(mo));
    mo[0]=0;
    priority_queue<P,vector<P>,greater<P>> pq;
    pq.push(make_pair(0,0));
    while(!pq.empty()){
        auto p=pq.top();pq.pop();
        int at=p.second;
        if(mo[at]<p.first) continue;
        bfs(at,rs[at]);
        for(int i=0;i<N;i++){
            if(go[i] && mo[at]+cs[at]<mo[i]){
                mo[i]=mo[at]+cs[at];
                pq.push(make_pair(mo[i],i));
            }
        }
    }
    printf("%d\n",mo[N-1]);
}

Measured memory_bytes: 1652
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl '\n'
#define TIME 1.0*clock()/CLOCKS_PER_SEC
#define pii pair < int , int >
#define Endl '\n'

#pragma GCC optimize("Ofast")

using namespace std;
using namespace __gnu_pbds;

template <typename T> using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 gen(chrono::system_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
const int FFTM = 998244353;

const int SX[4] = {0 , 1 , -1 , 0};
const int SY[4] = {1 , 0 , 0 , -1};
const int rx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
const int ry[8] = {0, 0, 1, -1, 1, -1, 1, -1};
const int kx[8] = {1, 1, -1, -1, 2, 2, -2, -2};
const int ky[8] = {2, -2, 2, -2, 1, -1, 1, -1};

typedef cc_hash_table< int, int, hash<int>, equal_to<int>, direct_mask_range_hashing<int>, hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("gotham.in", "r", stdin);
//    freopen("gotham.out", "w", stdout);
#endif
    int n;
    cin >> n;
    int kol = 0;
    for (int i = 0;i < n; ++i){
        int x;
        cin >> x;
        if (i % 2 == 0 && x % 2)kol++;
    }
    cout << kol << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

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

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

  long max = 0;
  for (int i = 0; i < k; i++) {
    max += p[i];
  }

  long temp = max;
  for (int i = 0; i < n - k; i++) {
    temp += (p[i + k] - p[i]);
    if (temp > max) {
      max = temp;
    }
  }

  if ((max + k) % 2 == 0) {
    cout << (max + k) / 2 << endl;
    return 0;
  } else {
    string ans = to_string((max + k) / 2);
    ans += ".5";
    cout << ans << endl;
    return 0;
  }
}


Measured memory_bytes: 1024
//This code was made by Chinese_zjc_
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#define int long long
#define INF 0x3fffffffffffffff
#define Mod 1000000007
using namespace std;
inline int rd(int &ddd)
{
	char tmp=getchar();
	int xxx=1;
	ddd=0;
	while(('0'>tmp||tmp>'9')&&tmp!='-'&&tmp!=EOF)
	{
		tmp=getchar();
	}
	if(tmp==EOF)
	{
		return EOF;
	}
	if(tmp=='-')
	{
		xxx=-1;
		tmp=getchar();
	}
	while('0'<=tmp&&tmp<='9')
	{
		ddd=(ddd<<3)+(ddd<<1)+(tmp^48);
		tmp=getchar();
	}
	return ddd*=xxx;
}
inline char rd(char &ddd)
{
	char tmp=getchar();
	while(tmp==' '||tmp=='\n')
	{
		tmp=getchar();
	}
	if(tmp==EOF)
	{
		return EOF;
	}
	return ddd=tmp;
}
inline int max(const int &A,const int &B)
{
	return A<B?B:A;
}
inline int min(const int &A,const int &B)
{
	return A<B?A:B;
}
int dp[100005][13],len,f[10][13];
char n[100005];
int Find(int j,int k)
{
	if(f[j][k])
	{
		return f[j][k];
	}
	for(int x=0;x<13;++x)
	{
		if((x*10+j)%13==k)
		{
			return f[j][k]=x;
		}
	}
}
signed main()
{
	scanf("%s",n);
	len=strlen(n);
	if(n[0]=='?')
	{
		for(int i=0;i<=9;++i)
		{
			dp[0][i]=1;
		}
	}
	else
	{
		dp[0][n[0]-'0']=1;
	}
	for(int i=1;i<len;++i)
	{
		if(n[i]=='?')
		{
			for(int j=0;j<=9;++j)
			{
				for(int k=13;k<26;++k)
				{
					dp[i][k%13]=(dp[i][k%13]+dp[i-1][Find(j,k%13)])%Mod;
				}
			}
		}
		else
		{
			int j=n[i]-'0';
			for(int k=13;k<26;++k)
			{
				dp[i][k%13]=(dp[i][k%13]+dp[i-1][Find(j,k%13)])%Mod;
			}
		}
	}
	printf("%lld",dp[len-1][5]);
	return 0;
}


Measured memory_bytes: 10496
#include <iostream>
using namespace std;
int a[111];
int main () {
  int n;
  cin >> n;
  for (int i = 0 ; i < n ; ++ i) a[i] = (int)(1e6);
  for (int i = 1 ; i < n ; ++ i) {
	int b;
    cin >> b;
    a[i] = min (a[i], b);
    a[i - 1] = min (a[i - 1], b);
  }
  long long sum = 0;
  for (int i = 0 ; i < n ; ++ i)
    sum += a[i];
  cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1LL<<50)
#define s second
#define f first
using namespace std;
typedef long long ll;
typedef pair<ll,ll>P;
typedef pair<ll,P> PP;
ll G[200][200][2];
int n,m,r,z[1000];

void WF(){
  for(int k=0;k<n;k++)
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++){
	G[i][j][0]=min(G[i][j][0],G[i][k][0]+G[k][j][0]);
	G[i][j][1]=min(G[i][j][1],G[i][k][1]+G[k][j][1]);
      }
}


ll dijkstra(){
  vector<vector<ll> > D(n,vector<ll>(r,INF));
  priority_queue<PP,vector<PP>,greater<PP> > Q;
  Q.push(PP(0,P(z[0],0)));
  D[z[0]][0] = 0;

  while(!Q.empty()){
    PP t=Q.top();Q.pop();
    ll cost=t.f,ship=t.s.f,idx=t.s.s,pos=z[idx];
    if(idx==r-1)return cost;
    if(D[ship][idx]<cost) continue;
    
    int npos=z[idx+1];
    ll ncost=cost+G[pos][npos][0];
    if(D[ship][idx+1]>ncost)Q.push(PP(ncost,P(ship,idx+1))),D[ship][idx+1]=ncost;

    for(int i=0;i<n;i++){
	ncost=cost+G[pos][ship][0]+G[ship][i][1]+G[i][npos][0];
	if(D[i][idx+1]>ncost)Q.push(PP(ncost,P(i,idx+1))),D[i][idx+1]=ncost;
      }
  }
  assert(0);
} 

int main(){
  while(1){
    cin>>n>>m;
    if(!n&&!m)break;
    for(int i=0;i<n;i++) 
      for(int j=0;j<n;j++) G[i][j][0]=G[i][j][1]=INF*(i!=j);
    
    for(int i=0,x,y,c,idx;i<m;i++){
      char ch;
      cin>>x>>y>>c>>ch;x--,y--;
      idx=(ch=='S');
      G[x][y][idx]=G[y][x][idx]=min(G[x][y][idx],(ll)c);
    }
    cin>>r;
    for(int i=0;i<r;i++)cin>>z[i],z[i]--;
    WF();
    cout <<dijkstra()<<endl;
  }
  return 0;
}

Measured memory_bytes: 5244
#最大公約数を求める
def gcd(a,b):
    #a>bとなるように入れ替え
    if a < b:
        tmp = a
        a = b
        b = tmp
    
    #ユークリッドの互除法
    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b
    
    return b

#最小公倍数を求める
def lcm(a,b):
    return int((a*b)//gcd(a,b))

#入力
N = int(input())
T = []
for i in range(N):
    T.append(int(input()))

#Tのリストの2数のlcmを求めて範囲を広げていく
tmp_lcm = 1 #現在の範囲までのlcm
for i in range(N):
    tmp_lcm = lcm(tmp_lcm,T[i])

print(tmp_lcm)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
#include<string>
#include<stdio.h>
#include<cmath>
#include<map>
#include<bitset>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define repr(i, n) for(int i = n-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define lint long long


int main(){
    int a, b; cin>>a>>b;
    repn(i, 3){
        if(a != i && b != i){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
using System;

namespace _094C
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] v = new int[n];
            int[] x = new int[n];

            string[] str = Console.ReadLine().Split(' ');
            for (int i = 0; i < str.Length; i++)
            {
                x[i] = int.Parse(str[i]);
                v[i] = x[i];
            }
            Array.Sort(v);
            int n1 = (n / 2) - 1;
            int n2 = n1 + 1;

            int med1 = v[n1];
            int med2 = v[n2];

            for (int i = 0; i < n; i++)
            {
                int t = x[i];
                if (t <= med1)
                {
                    System.Console.WriteLine(med2);
                } else if (med2 <= t)
                {
                    System.Console.WriteLine(med1);
                }
            }
        }
    }
}

Measured memory_bytes: 36668
package main

import (
    "fmt"
    "sort"
)

type Store struct {
    Name string
    Point int
    Id int
}

type Stores []Store

func (s Stores) Len() int { return len(s) }
func (s Stores) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s Stores) Less(i, j int) bool {
    if (s[i].Name < s[j].Name) {
        return true
    } else if (s[i].Name > s[j].Name) {
        return false
    } else {
        return s[i].Point > s[j].Point
    }
}

func main() {
    var n int
    fmt.Scan(&n)
    stores := make(Stores, n)
    for i := 0; i < n; i++ {
        var s string
        var p int
        fmt.Scan(&s)
        fmt.Scan(&p)
        stores[i] = Store{s, p, i+1}
    }
    sort.Sort(stores)

    for i := 0; i < n; i++ {
        fmt.Println(stores[i].Id)
    }
}


Measured memory_bytes: 512
/// @file
/// @version Accepted.
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  string S;
  cin >>  S;
  int height = 0, left = 0;;
  for (int i = 0; i < N; ++i) {
    const int difference = S[i] == '(' ? 1 : -1;
    height += difference;
    if (height < 0) {
      assert(height == -1);
      ++left;
      height = 0;
    }
  }
  for (int i = 0; i < left; ++i) cout << "(";
  cout << S;
  for (int i = 0; i < height; ++i) cout << ")";
  cout << endl;
}


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

constexpr int inf = 1e9;

int main() {
    int n, T; cin >> n >> T;
    int ans = inf;
    for(int i = 0; i < n; ++i) {
        int c, t; cin >> c >> t;
        if(t <= T) ans = min(ans, c);
    }
    if(ans == inf) {
        cout << "TLE" << endl;
    } else {
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
N, C = map(int, input().split())
prog = [list(map(int, input().split())) for _ in range(N)]

#tv[i] = [t, c]
tv = [[-1, 0] for i in range(C)]

prog.sort()

for p in prog:
    s, t, c = p
    for i in range(C):
        if tv[i][0] < s - 0.5 or tv[i][1] == c or tv[i][1] == 0:
            tv[i][0] = t
            tv[i][1] = c
            break


ans = 0
for i in range(C):
    if tv[i][0] > 0:
        ans += 1
    else:
        break

print(ans)

Measured memory_bytes: 27528
#%%
n = int(input())
s = list(map(int, input().split()))
inf =  1000000007

a, b, c = 0, 0, 0
ans = 1

for i in range(n):
	tmp = [a, b, c].count(s[i])
	ans *= tmp
	ans %= 1000000007
	if s[i] == a:
		a += 1
	elif s[i] == b:
		b += 1
	else:
		c += 1
	

print(ans)

Measured memory_bytes: 13964
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  int h[10000]={},a[10000],b;
  cin >> n >> m;
  for(int i=0; i<m; i++) cin >> a[i];
  for(int i=0; i<m; i++){
    for(int j=0; j<n; j++){
      cin >> b;
      if(b == a[i]) h[j]++;
      else h[a[i]-1]++;
    }
  }
  for(int i=0; i<n; i++) cout << h[i] << endl;
  return 0;
}



Measured memory_bytes: 3124
import java.io.IOException;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			w = scanner.nextInt();
			h = scanner.nextInt();
			n = scanner.nextInt();
			if ((w | h | n) == 0)
				break;
			size = new int[n + 1];
			for (int i = 0; i < n; i++) {
				int b = scanner.nextInt();
				int k = scanner.nextInt();
				size[b] = k;
			}
			map = new int[h][w];
			pos = new int[n + 1][2];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					int s = scanner.nextInt();
					map[i][j] = s;
					if (s > 0) {
						pos[s][0] = i;
						pos[s][1] = j;
					}
				}
			}
			count = 0;
			ans = new int[h][w];
			f(1);
			if (count == 1) {
				for (int i = 0; i < h; i++) {
					for (int j = 0; j < w; j++) {
						System.out.print(ans[i][j]);
						System.out.print(j == w - 1 ? '\n' : ' ');
					}
				}
			} else {
				System.out.println("NA");
			}
		}
	}

	private void f(int k) {
		PriorityQueue<Point> pq = new PriorityQueue<Point>();
		pq.add(new Point(map, 1));
		while (!pq.isEmpty()) {
			Point point = pq.poll();
			int[][] map = point.map;
			k = point.k;
			if (k == n + 1) {
				count++;
				if (count == 2)
					return;
				for (int i = 0; i < h; i++) {
					for (int j = 0; j < w; j++) {
						int a = map[i][j];
						ans[i][j] = a >= 100 ? a / 100 : a;
					}
				}
				continue;
			}
			int s = size[k];
			for (int r = 1; r <= s; r++) {
				if (s % r != 0)
					continue;
				int y = pos[k][0];
				int x = pos[k][1];
				for (int ui = y + 1 - s / r; ui <= y; ui++) {
					if (ui < 0)
						continue;
					loop: for (int lj = x + 1 - r; lj <= x; lj++) {
						if (lj < 0)
							continue;
						int di = ui + s / r;
						int rj = lj + r;
						if (di > h || rj > w)
							continue;
						for (int i = ui; i < di; i++) {
							for (int j = lj; j < rj; j++) {
								if (map[i][j] != 0 && map[i][j] != k)
									continue loop;
							}
						}
						int[][] tmp = new int[h][w];
						for (int i = 0; i < h; i++)
							tmp[i] = Arrays.copyOf(map[i], w);
						for (int i = ui; i < di; i++) {
							for (int j = lj; j < rj; j++) {
								if (tmp[i][j] != k)
									tmp[i][j] = k;
							}
						}
						pq.add(new Point(tmp, k + 1));

					}
				}
			}
		}
	}

	class Point implements Comparable<Point> {
		int[][] map;
		int k;

		public Point(int[][] map, int k) {
			super();
			this.map = map;
			this.k = k;
		}

		@Override
		public int compareTo(Point o) {
			return o.k - this.k;
		}

	}

	int count;
	int h, w, n;
	int[] size;
	int[][] map;
	int[][] pos;
	int[][] ans;

}

Measured memory_bytes: 60160
using namespace std;
#include <iostream>
#include <algorithm>
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
ll mod = 1e9+7;
#include <vector>

int n;
vector<int> h;

bool dfs(int i, int prev_h){
    if(i == n) return true;

    if(prev_h == h[i]) return dfs(i+1,h[i]);
    //else if(prev_h < h[i])  return dfs(i+1,h[i]) || dfs(i+1,h[i]-1);
    else if(prev_h < h[i])  return dfs(i+1,h[i]-1);
    else return false;
}

int main(){

    cin >> n;

    for(int i=0; i<n; i++){
        int tmp;
        cin >> tmp;
        h.push_back(tmp); 
    }

    if(n == 1){
        cout << "Yes" << endl;
        return 0;
    }

    if(dfs(0,h[0]) || dfs(0,h[0]-1)) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

using ll = long long;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}

int main() {
  int N; cin >> N;
  ll H, W; cin >> H >> W;
  vector<ll> A(N), B(N); REP(i, N) cin >> A[i] >> B[i];
  int cnt = 0;

  REP(i, N) {
    if(H <= A[i] && W <= B[i]) cnt++;
  }

  cout << cnt << endl;
}

Measured memory_bytes: 256
# 素因数分解
def prime_factorize(n):
    a = set()
    while n % 2 == 0:
        a.add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.add(n)
    return a

n = int(input())
li = list(prime_factorize(n))
m = len(li)

# print(li)
# print(m)

cnt = 0
for i in range(1, 2 ** m):
  popcount = bin(i).count("1")
  mul = 1
  for j in range(m):
    if (i >> j) & 1:
      mul *= li[j]
  # print(popcount, bin(i), j, mul)
  if popcount % 2 == 0:
    cnt -= n // mul
  else:
    cnt += n // mul 
print(n - cnt)   




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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> A(H, vector<char>(W));
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> A[i][j];
    }
  }
  vector<bool> row(H), col(W);
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (A[i][j] == '#') {
        row[i] = col[j] = true;
      }
    }
  }
  for (int i = 0; i < H; ++i) {
    if (!row[i]) continue;
    for (int j = 0; j < W; ++j) {
      if (!col[j]) continue;
      cout << A[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n, m = list(map(int, input().split()))

query = []
for i in range(m):
    query.append(list(map(int, input().split())))

for num in range(1000):
    flag = True
    s_num = str(num)
    if len(s_num) != n:
        continue  # ここがflag=Falseだと、下で配列の範囲外参照になってエラー
    for j in query:
        if s_num[j[0]-1] != str(j[1]):
            flag = False
    if flag:
        print(num)
        exit()

print(-1)


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

int main() {

	vector<int> loc(5, 0);
	for (int i = 0; i < loc.size(); i++) {
		cin >> loc[i];
	}

	int k;
	cin >> k;

	int diff;
	bool jdg = true;
	for (int i = 0; i < loc.size() - 1; i++) {
		for (int j = i + 1; j < loc.size(); j++) {
			diff = loc[j] - loc[i];
			if (diff > k) {
				jdg = false;
				break;
			}
		}
	}

	if (jdg == true) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}

	return 0;
}


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

using namespace std;

typedef long long LL;

const int N = 1010;

int n;
int cnt[N];
string s;

int main()
{

    cin >> n >> s;

    int res = 0;

    for(int i = 1; i < n; i++)
    {
        memset(cnt, 0, sizeof cnt);
        for(int j = 0; j < i; j++)
            cnt[s[j] - 'a'] |= 1;
        for(int j = i; j < n; j++)
            cnt[s[j] - 'a'] |= 2;

        int t = 0;
        for(int j = 0; j < 26; j++)
            if((cnt[j] & 1) && (cnt[j] & 2))
                t++;
        res = max(res, t);
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  vector<ll> V(n); rep(i, n) cin >> V[i];
  ll ans = 0;
  rep(i, k+1) rep(j, k+1) {
    int rem = k-(i+j);
    if(rem < 0) continue;
    if(i+j > n) continue;
    priority_queue<ll, vector<ll>, greater<ll>> q;
    rep(ii, i) q.push(V[ii]);
    rep(jj, j) q.push(V[n-1-jj]);
    rep(kk, rem) {
      if(q.empty()) break;
      if(q.top() >= 0) break;
      q.pop();
    }
    ll sum = 0;
    while(!q.empty()) {
      sum += q.top();
      q.pop();
    }
    chmax(ans, sum);
  }
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using LL = long long;
const LL MOD = 1e9+9;
using namespace std;


int main(){
    int A,B,K;cin >>A >> B >> K;
    vector<int> ans;
    for(int a = 1;a <= min(A,B);a++){
        if(A % a ==  0 && B % a == 0)ans.push_back(a);
    }
    sort(ans.begin(),ans.end());
    cout<<ans.at(ans.size()-K)<<endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>?): Unit {
    val (a, b ,c) = readLine()!!.trim().split(' ').map(String::toInt)
    for (t in 0 until 60){
        if ((60 * t + c) % (a + b) <= a) {
            println(60 * t + c)
            return
        }
    }
    println(-1)
}



Measured memory_bytes: 33892
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>

#define int long long

struct edge {
    int to;
    int cost;
};

using namespace std;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vb = vector<bool>;
using qi = queue<int>;
using P = pair<int, int>;
using graph = vector<vector<edge>>;
// using graph = vector<vector<int>>;


#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define delim(i, n) cout << (i == n-1 ? "\n" : " ");

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

const int inf = 1LL << 60;
// const int inf = 100000000;
const int mod = 1000000007;

const int maxn = 1e5+1;
int n, m, a;
vi rem(maxn);

vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};

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

    cin >> n >> a >> m;
    int cnt = n;
    int loop = n;
    int ret = a;
    rem[0] = a;
    FOR(i, 1, n){
        a = (a*a)%m;
        int flag = false;
        REP(j, i) {
            if (a == rem[j]) {
                flag = true;
                loop = i-j;
            }
        }
        if (flag) {
            cnt = i;
            break;
        } else rem[i] = a;
        ret += a;
    }
    int loopsum = 0;
    for (int i = cnt - loop; i < cnt; i++) {
        loopsum += rem[i];
    }
    
    ret += ((n-cnt)/loop)*loopsum;
    REP(i, (n-cnt)%loop) {
        ret += rem[i+cnt-loop];
    }
    cout << std::fixed << std::setprecision(10) << ret << "\n";
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

unordered_set<ll> usedColor[100010];
vector<ll> edge[100010];


int main()
{
    ll n;
    cin>>n;
    vector<ll> a(n-1),b(n-1),color(n-1);
    for (int i = 0; i < n-1; i++)
    {
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
        edge[a[i]].push_back(i);
        edge[b[i]].push_back(i);
    }
    for (int i = 0; i < n-1; i++)
    {
        color[i]=-1;
    }
    queue<ll> q;
    q.emplace(0);
    while (q.size()>0)
    {
        ll now =q.front();
        q.pop();
        
        //set children color
        ll nuruColor=0;
        for (int i = 0; i < edge[now].size(); i++)
        {
            ll nowEdge=edge[now][i];
            if(color[nowEdge]==-1)
            {
                ll next;
                if(b[nowEdge]==now) next=a[nowEdge];
                else next=b[nowEdge];
                while (usedColor[now].find(nuruColor)!=usedColor[now].end())
                {
                    nuruColor++;
                }
                
                color[nowEdge]=nuruColor;
                usedColor[now].insert(nuruColor);
                usedColor[next].insert(nuruColor);
                nuruColor++;
                q.emplace(next);
            }
        }
    }
    ll colorVari=1;
    for (int i = 0; i < n-1; i++)
    {
        color[i]++;
        colorVari=max(colorVari,color[i]);
    }
    cout<<colorVari<<endl;
    for (int i = 0; i < n-1; i++)
    {
        cout<<color[i]<<endl;
    }
        
    return 0;
}

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

using namespace std;

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

const int INF = 1000000000; //
const ll LINF = (ll) 4000000000000000000; //
const ll MOD = (ll) 1000000007; //
const double PI = 3.1415926535898; //
const int limit = 100010;

#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())

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

int main() {
    int n, ma, mb;
    cin >> n >> ma >> mb;
    int a[n], b[n], c[n];
    rep(i, n) cin >> a[i] >> b[i] >> c[i];

    int dp[41][401][401];

    memset(dp, INF, sizeof (dp));

    rep(i, 41) rep(j, 401) rep(k, 401) dp[i][j][k] = INF;


    dp[0][0][0] = 0;

    rep(num, n) {

        rep(ai, 401) {

            rep(bi, 401) {
                dp[num + 1][ai][bi] = min(dp[num + 1][ai][bi], dp[num][ai][bi]);
                if (ai + a[num] <= 400 && bi + b[num] <= 400) {
                    dp[num + 1][ai + a[num]][bi + b[num]] = min(dp[num + 1][ai + a[num]][bi + b[num]], dp[num][ai][bi] + c[num]);
                }
            }
        }
    }

    int Min_value = INF;

    rep(i, 401) {

        rep(j, 401) {
            if (dp[n][i][j] != INF && ma * j == mb * i && i * j != 0) {
                Min_value = min(Min_value, dp[n][i][j]);
            }
        }
    }

    if (Min_value == INF) cout << -1 << endl;
    else cout << Min_value << endl;

    return 0;
}

Measured memory_bytes: 26112
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int h = scanner.nextInt();
		System.out.println((a+b) * h / 2);
		scanner.close();
	}

}


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

typedef long long ll;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = (n / (a + b));
  ans *= a;
  ans += n % (a + b) > a? a: n % (a + b);
  cout << ans <<'\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
int main()
{
    long long n;
    cin>>n;
    vector<long long> v(n);
    for(int i=0;i<n;i++)
    cin>>v[i];
    long long ans=0;
    long long p=v[0];
    for(int i=1;i<n;i++)
    {
    	if(v[i]>p)
    	p=v[i];
    	else
    	{
    		ans=ans+p-v[i];
    	}
    }
    cout<<ans;
}

Measured memory_bytes: 4828
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

N = i_i()

ans = 0
for i in range(1, N+1):
    if i % 15 == 0:
        ans = ans
    elif i % 5 == 0:
        ans = ans
    elif i % 3 == 0:
        ans = ans
    else:
        ans += i

print(ans) 

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
int main(){
  int ans=0,n,x;
  cin>>n;
  for(int i=1;i<=n;i++){
  	cin>>x;
	  while(x%2==0){
	  	ans++;
	  	x/=2;
	  }
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans = 0;
		sc.close();
		for (int i=1; i<=n; i+=2) {
			if (numYaku8(i)) ans+=1;
		}
		System.out.println(ans);
	}

	private static boolean numYaku8(int n)
	{
		int yaku=0;
		for (int i=1; i<=n; i++) {
			if (n % i == 0) yaku+=1;
		}
		if (yaku == 8) return true;
		return false;
	}
}


Measured memory_bytes: 21844
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    S = input()
    l = len(S)
    if l % 2 != 0:
        print('No')
    elif S.count('hi') == l // 2:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
    int A,B,C;
    scanf("%d %d %d",&A,&B,&C);
    if(-100<=A&&B&&C<=100)
    {
        if(C>=A&&C<=B)
        {
            printf("Yes");
        }
        else
        {
            printf("No");
        }
    }
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() { cin.tie(nullptr); ios_base::sync_with_stdio(false); }
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

signed main()
{
  long a;
  cin >> a;
  if (a&1) {
    a *= 2;
  }
  cout << a << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define rep (i, n) for (int i = 1; i <= n; i++)

using namespace std;

int main() {
	int x;
	cin >> x;
	
	for (int a = -118; a <= 119; a++) {
		for (int b = -118; b <= 119; b++) {
			if (a * a * a * a * a - b * b * b * b * b == x) {
				cout << a << " " << b << endl;
				return 0;
			}
		}
	}
	
	return 0;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (b == 0) cout << 0 << endl;
    else {
        cout << (b - 1) / a + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char *argv[]){
	int i,n,k,t,u,v,l,d[12000]={0},m;
	int now,carrot=0,spup=0;
	double time=0;
	scanf("%d %d %d %d %d %d ",&n,&k,&t,&u,&v,&l);
	for(i=0;i<n;i++){
		scanf("%d ", &m);
		d[m]=1;
	}
	for(now=0;now<l;now++){
		if(d[now]){
			if(carrot < k) carrot ++;
			else spup=t*v;
		}
		if(!spup && carrot){
			carrot --;
			spup = t*v;
		}
		time += (double)1/(spup?v:u);
		if(spup)spup --;
		//printf("now %d, spup %d, time %lf, carrot %d\n", now, spup, time, carrot);
	}
	printf("%lf\n", time);
    return 0;
}

Measured memory_bytes: 0
import math

# 組み合わせ算出
def combinations_count(n, r):
    if n == 1:
        return 0
    if n == 0:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if __name__ == '__main__':
    a,b=map(int,input().split())
    # 偶数を2回引く
    e_2 =  combinations_count(a,2)
    # 奇数を２回引く引
    o_2 = combinations_count(b, 2)
    print(e_2 + o_2)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <cstdlib>
using namespace std;
using ll = long long int;
int INF = 1e9+7;

int main() {
    int N;
    cin >> N;
    int L[N];
    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }
    sort(L,L+N);
    reverse(L,L+N);
    int sum = 0;
    for  (int i = 1; i < N; i++) {
        sum += L[i];
    }
    if (L[0] < sum) {cout << "Yes" << endl;}
    else cout << "No" << endl;
}


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

int main()
{
	int a[5], k, cnt = 0, minpt = -1;
	for(auto&& i : a)
	{
		cin >> i;
		if (i % 10 == 0) cnt++;
		else
		{
			if (minpt == -1) minpt = i % 10;
			else minpt = min(minpt, i % 10);
		}
	}
	int ans = 0;
	for(auto&& i : a)
	{
		if(i % 10 != minpt)
		{
			ans += (i / 10 + !!(i % 10)) * 10;
		}else
		{
			ans += i;
			minpt = -1;
		}
	}
	cout << ans << "\n";
}


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

using namespace std;

typedef vector< vector<int> > Graph;

int n;
Graph g;

bool dfs1(int cur, int par, deque<int>& route) {
	if (cur == n - 1) {
		route.push_front(cur);
		return true;
	}
	for (int nex : g[cur]) {
		if (nex == par) continue;
		if (dfs1(nex, cur, route)) {
			route.push_front(cur);
			return true;
		}
	}
	return false;
}

void dfs2(int cur, int par, vector<int>& color) {
	for (int nex : g[cur]) {
		if (nex == par) continue;
		if (color[nex] != -1 && color[nex] != color[cur]) continue;
		color[nex] = color[cur];
		dfs2(nex, cur, color);
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	g.resize(n);
	for (int i = 0; i + 1 < n; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	deque<int> route;
	dfs1(0, -1, route);

	vector<int> color(n, -1);
	while (true) {
		if (route.empty()) break;
		else {
			color[route.front()] = 1;
			route.pop_front();
		}
		if (route.empty()) break;
		else {
			color[route.back()] = 0;
			route.pop_back();
		}
	}
	dfs2(0, -1, color);
	dfs2(n - 1, -1, color);

	int b = 0, w = 0;
	for (int i = 0; i < n; i++) {
		if (color[i]) b++;
		else w++;
	}
	cout << (b <= w ? "Snuke" : "Fennec") << endl;
	return 0;
}

Measured memory_bytes: 12800
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		int current=0;
		int max=0;
		for (int i = 0; i < str.length(); i++) {
			char c = str.charAt(i);
			if(c=='A' || c=='T' || c=='G' || c=='C') {
				current++;
				if(current>max){
					max=current;
				}
			}else {
				if(current>max) {
					max = current;
				}
				current =0;
			}
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const ll mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination{
    vector<mint> fact,ifact;
    combination(int n):fact(n+1),ifact(n+1){
        assert(n < mod);
        fact[0] = 1;
        for(int i = 1;i <= n; ++i){
            fact[i] = fact[i-1]*i;
        }
        ifact[n] = fact[n].inv();
        for(int i = n; i >= 1; --i){
            ifact[i-1] = ifact[i]*i;
        }
    }
        mint operator()(int n, int k){
            if( k < 0 || k > n) return 0;
            return fact[n]*ifact[k]*ifact[n-k];
        }
    
};

ll modpow(ll p,ll q){
    if(q == 0)return 1;
    if(q%2 == 0){
        ll x = modpow(p,q/2);
        return x*x%mod;
    }else{
        return modpow(p,q-1)*p%mod;
    }
}

ll choose(ll n,ll k){
    ll x=1,y=1;
    rep(i,k){
        x = x*(n-i)%mod;
        y = y*(k-i)%mod;
    }
    y = modpow(y,mod-2);
    return x*y%mod;
}




int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans;
    ans = modpow(2,n)-1;
    cerr << ans << endl;
    ans -= choose(n,a)+choose(n,b);
    ans = (ans%mod+mod)%mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
ll mod=1E9+7;
 
#define REP(a,b,c) for(ll a=(b);a<(c);a++)
#define PER(a,b,c) for(ll a=(b);a>=(c);a--)

ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
double id(){ double x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oe(){ cout << endl; }
void oie(ll x){ oi(x); oe(); }
void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

ll dp[3000][3000];
int main(){
    ll N=ii();
    vector<pii> A;
    REP(i,0,N) A.push_back(make_pair(ii(),i));
    sort(A.rbegin(), A.rend());

    REP(i,0,N){
        REP(j,0,i+1){
            dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+A[i].first*abs(A[i].second-j));
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]+A[i].first*abs(A[i].second-(N-1-i+j)));
        }
    }

    ll ret=0;
    REP(j,0,N+1){
        ret=max(dp[N][j],ret);
    }
    oie(ret);
 
    return 0;
}

Measured memory_bytes: 27312
#include<bits/stdc++.h>
using namespace std;
#define N 1111116
#define next nxt

int n,m,x[N],y[N],next[N],p[N],h[N][2];
long long cnts,cnto,cnte;

int travel(int x,int k){
	h[x][k]=1;
	for (int t=p[x];t;t=next[t])
		if (!h[y[t]][k^1])
		travel(y[t],k^1);
	return h[x][k^1];
}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();m=read();
	for (int i=1;i<=m;i++){
		x[2*i-1]=y[2*i]=read();
		y[2*i-1]=x[2*i]=read();
		next[2*i-1]=p[x[2*i-1]];p[x[2*i-1]]=2*i-1;
		next[2*i]=p[x[2*i]];p[x[2*i]]=2*i;
	}
	for (int i=1;i<=n;i++)
		if (!p[i]) cnts++;
		else if (!h[i][0]&&!h[i][1])
			travel(i,0)?cnto++:cnte++;
	printf("%lld\n",cnts*(2*n-cnts)+(cnto+cnte)*(cnto+cnte)+cnte*cnte);
	return 0;
}

Measured memory_bytes: 20992
#include<iostream>
#include<vector>
#include<numeric>
using namespace std;
int main(){
    int n,s,a=100000;
    cin>>n;
    vector<int>w(n);
    for(int i=0;i<n;i++)cin>>w[i];
    s=accumulate(w.begin(),w.end(),0);
    for(int i=1;i<n;i++)w[i]+=w[i-1];
    for(int i=0;i<n-1;i++)a=min(a,abs(s-2*w[i]));
    cout<<a<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " "<<a.second; }
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }

 
#define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)
#define ALL(v) (v).begin(), (v).end()
#define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());}
#define fr first
#define sc second
 
typedef pair< int , int > Pi;
typedef pair< int , Pi > Pii;
const int INF = 1 << 30;

typedef long long int64;

int main(){
  int N;
  cin >> N;
  vector < int > Value(N);
  cin >> Value;
  vector< vector< int64 > > dp( N - 1, vector< int64 >( 21, 0));
  dp[0][Value[0]] = 1;
  for(int i = 1; i < N - 1; i++){
    for(int j = 20; j >= 0; j--){
      if(dp[i][j] == -1) continue;
      if(j + Value[i] < 21) dp[i][j + Value[i]] += dp[i - 1][j];
      if(j - Value[i] >= 0) dp[i][j - Value[i]] += dp[i - 1][j];
    }
  }
  cout << dp[N - 2][Value[N - 1]] << endl;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(void){
    int n, m;
    string s;
    cin >> n >> m >> s;
    
    vector<int> dp(n+1, 0);
    vector<int> ans;
    dp[0] = -1;
    int idx = n;
    
    while (idx != 0) {
        int idx_c = idx;
        for (int i = 1; i <= m; i++) {
            if (s[idx-i] == '0') {
                dp[idx-i] = dp[idx];
                idx_c = idx-i;
            }
            
            if (idx-i == 0)
                break;
        }
        
        if (idx == idx_c)
            break;
        ans.push_back(idx-idx_c);
        idx = idx_c;
    }
    
    if (dp[0] == -1)
        cout << -1 << endl;
    else {
        for (int i = ans.size()-1; i >= 0; i--)
            cout << ans[i] << " ";
        cout << endl;
    }
}

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

int main()
{
	int n, k;

	cin >> n >> k;

	for (long d = 0; d < (1 << n); d++) {
		int c = 0;

		for (int j = 0; j < n; j++) {
			if (d & (1 << j))
				c++;
		}

		if (c == k) {
			cout << d << ":";

			for (int s = 0; s < n; s++) {
				if (d & (1 << s))
					cout << " " << s;
			}

			cout << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3136
#include<iostream>
using namespace std;
const int N=100001;
int n,a[N],x,ans;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if(x>n) ans++;
        else a[x]++; 
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]==0) continue;
        if(a[i]<i) ans+=a[i];
       		else if(a[i]>i) ans+=a[i]-i;
    }
    cout<<ans<<endl;
    return 0;
}

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

public class Main {
    int n;
    SortedSet<Character> set;
    List<Map<Character, Integer>> maps;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        set = new TreeSet<>();
        maps = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            char[] cs = sc.next().toCharArray();
            maps.add(new HashMap<>());
            for (int j = 0; j < cs.length; j++) {
                set.add(cs[j]);
                if (maps.get(i).containsKey(cs[j])) {
                    maps.get(i).put(cs[j], maps.get(i).get(cs[j]) + 1);
                } else {
                    maps.get(i).put(cs[j], 1);
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        Iterator<Character> it = set.iterator();
        while (it.hasNext()) {
            char c = it.next();
            int minNum = 100;
            for (int i = 0; i < n; i++) {
                int num = 0;
                if (maps.get(i).containsKey(c)) {
                    num = maps.get(i).get(c);
                }
                if (num < minNum) {
                    minNum = num;
                }
            }
            while (minNum > 0) {
                sb.append(c);
                minNum--;
            }
        }
        System.out.println(sb);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

int main(void){
	string A,B;
	cin >> A >> B;
	if(A.size()>B.size())cout <<"GREATER";
	else if(A.size()<B.size())cout <<"LESS";
	else{
		if(A>B)cout<<"GREATER";
		else if(A<B)cout<<"LESS";
		else cout<<"EQUAL";
	}
	return 0;
}

Measured memory_bytes: 384
### constant

TYPE_D = 0
TYPE_F = 1

INDEX_FILE = 'index.html'

### subroutines

def search_path(root, path)
  segs = path.split('/')
  segs.shift
  segs << '' if path[-1] == '/'
  #p segs
  
  cdir = root
  nmpath = [root]

  for seg in segs
    return nil if cdir[1] == TYPE_F

    if seg == '.'
      next
    elsif seg == '..'
      nmpath.pop
      return nil if nmpath.empty?
      cdir = nmpath.last
    elsif seg == ''
      idx = cdir[2].index{|d| d[0] == INDEX_FILE && d[1] == TYPE_F}
      return nil if idx.nil?
      cdir = cdir[2][idx]
      nmpath << cdir
    else
      idx = cdir[2].index{|d| d[0] == seg}
      return nil if idx.nil?
      cdir = cdir[2][idx]
      nmpath << cdir
    end
  end

  if cdir[1] == TYPE_D
    idx = cdir[2].index{|d| d[0] == INDEX_FILE && d[1] == TYPE_F}
    return nil if idx.nil?
    nmpath << cdir[2][idx]
  end

  return nil if nmpath.last[1] == TYPE_D
  
  nmpath.map{|nmseg| nmseg[0]}
end

### main

loop do
  n, m = gets.split.map(&:to_i)
  break if (n | m) == 0

  root = ["", TYPE_D, []]
  n.times do
    psegs = gets.strip.split('/')
    psegs.shift
    #p psegs

    file = psegs.pop
    cdir = root

    for pseg in psegs
      idx = cdir[2].index{|d| d[0] == pseg && d[1] == TYPE_D}
      if idx.nil?
        idx = cdir[2].length
        cdir[2] << [pseg, TYPE_D, []]
      end
      cdir = cdir[2][idx]
    end
    cdir[2] << [file, TYPE_F]
  end
  #p root

  m.times do
    path0 = gets.strip
    path1 = gets.strip
    #p [path0, path1]
    
    nmpath0 = search_path(root, path0)
    nmpath1 = search_path(root, path1)
    #p [nmpath0, nmpath1]
    
    if nmpath0.nil? || nmpath1.nil?
      puts 'not found'
    else
      puts (nmpath0 == nmpath1) ? 'yes' : 'no'
    end
  end
end

Measured memory_bytes: 6120
#include<cstdio>

using namespace std;

bool isprime(int a){
	if((a&1)==0) return a==2;
	for(int i=3;i*i<=a;i+=2) if(a%i==0) return false;
	return a!=1;
}

int main(){
	for(int a,d,n;scanf("%d%d%d",&a,&d,&n),a;){
		for(;n;a+=d) if(isprime(a)) n--;
		printf("%d\n",a-d);
	}
	return 0;
}

Measured memory_bytes: 0