akhauriyash/Code-Regression huggingface dataset:
//created by Whiplash99
import java.io.*;
import java.util.*;
public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        String s[]=br.readLine().trim().split(" ");
        int X=Integer.parseInt(s[0]);
        int Y=Integer.parseInt(s[1]);
        int A=Integer.parseInt(s[2]);
        int B=Integer.parseInt(s[3]);
        int C=Integer.parseInt(s[4]);

        Long red[]=new Long[A];
        Long green[]=new Long[B];
        Long either[]=new Long[C];

        s=br.readLine().trim().split(" ");
        for(i=0;i<A;i++)
            red[i]=Long.parseLong(s[i]);
        s=br.readLine().trim().split(" ");
        for(i=0;i<B;i++)
            green[i]=Long.parseLong(s[i]);
        s=br.readLine().trim().split(" ");
        for(i=0;i<C;i++)
            either[i]=Long.parseLong(s[i]);

        Arrays.sort(red,Collections.reverseOrder());
        Arrays.sort(green,Collections.reverseOrder());
        Arrays.sort(either,Collections.reverseOrder());

        long sumA=0,sumB=0;
        for(i=0;i<X;i++) sumA+=red[i];
        for(i=0;i<Y;i++) sumB+=green[i];

        int x=X-1,y=Y-1;
        for(i=0;i<C&&x>=0&&y>=0;i++)
        {
            if(either[i]<=Math.min(red[x],green[y])) break;
            if(red[x]<green[y])
            {
                sumA+=either[i];
                sumA-=red[x--];
            }
            else
            {
                sumB+=either[i];
                sumB-=green[y--];
            }
        }
        while (i<C&&x>=0&&either[i]>red[x])
        {
            sumA+=either[i++];
            sumA-=red[x--];
        }
        while (i<C&&y>=0&&either[i]>green[y])
        {
            sumB+=either[i++];
            sumB-=green[y--];
        }

        System.out.println(sumA+sumB);
    }
}

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

static const int MAX_ELEM = 500000;

int MergeElem(int elem[], int start, int mid, int end)
{
#if 1
    int i, j, k, l;
    int num = 0;
    vector<int> left, right;

    i = mid - start;
    j = end - mid;
    l = (i > j) ? i : j;

    /* ???????????¢??????????????? */
    for (k = 0; k < l; k++) {
        left.push_back(elem[start + k]);
        right.push_back(elem[mid + k]);
    }
    /* ??????????????§????????\?????? */
    left[i]  = 0x7FFFFFFF;
    right[j] = 0x7FFFFFFF;

    i = 0;
    j = 0;
    for (k = start; k < end; k++) {
        ++num; /* ?????? */

        if (left[i] <= right[j]) {
            elem[k] = left[i];
            ++i;
        }
        else {
            elem[k] = right[j];
            ++j;
        }
    }

    return num;
#else
    int i, j, k, l;
    int num = 0;
    int left[MAX_ELEM/2 + 1], right[MAX_ELEM/2 + 1];

    i = mid - start;
    j = end - mid;
    l = (i > j) ? i : j;

    /* ???????????¢??????????????? */
    for (k = 0; k < l; k++) {
        left[k]  = elem[start + k];
        right[k] = elem[mid + k];
    }
    /* ??????????????§????????\?????? */
    left[i]  = 0x7FFFFFFF;
    right[j] = 0x7FFFFFFF;

    i = 0;
    j = 0;
    for (k = start; k < end; k++) {
        ++num; /* ?????? */

        if (left[i] <= right[j]) {
            elem[k] = left[i];
            ++i;
        }
        else {
            elem[k] = right[j];
            ++j;
        }
    }

    return num;
#endif
}

/* end ???????±??????????????????????????????§???????´???°???????????? */
int MergeSort(int elem[], int start, int end)
{
    int mid;
    int cnt = 0;

    /* end ???????±????????????????????±????1????????´????????????????????? */
    if ((start + 1) >= end) {
        return 0;
    }

    mid = (start + end) / 2;
    cnt += MergeSort(elem, start, mid);
    cnt += MergeSort(elem, mid,   end);
    cnt += MergeElem(elem, start, mid, end);

    return cnt;
}

int main(void)
{
    int i;
    int num;
    int cnt;
    int elem[500002];

    scanf("%d", &num);
    for (i = 0; i < num; i++) {
        scanf("%d", &elem[i]);
    }

    cnt = MergeSort(elem, 0, num);

    printf("%d", elem[0]);
    for (i = 1; i < num; i++) {
        printf(" %d", elem[i]);
    }
    printf("\n%d\n", cnt);

    return 0;
}

Measured memory_bytes: 5336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int main()
{
    int n, y, m, d;
    cin >> n;
    const int k = 196471;
    while (cin >> y >> m >> d)
    {
        int sum = 0;
        for (int i = 1; i < y; i++)
        {
            if (i % 3 == 0)
            {
                sum += 200;
            }
            else
            {
                sum += 195;
            }
        }
        if (y % 3 == 0)
        {
            sum += (m - 1) * 20 + d;
        }
        else
        {
            if (m % 2 == 0)
            {
                if((m/2)>=0){
                sum += ((m / 2)-1) * 19;
                sum += ((m / 2)) * 20;
                }
                sum += d;
            }
            else
            {
                sum += (m / 2) * 19;
                sum += (m / 2) * 20;
                sum += d;
            }
        }
        cout << k - sum << endl;
    }
}


Measured memory_bytes: 3096
#include<iostream>
#include<cmath>
#include<vector>
#include<map>

using namespace std;

int main()
{
    int N;
    cin >> N;
    map<string, int> s;
    for (int i = 0; i < N; i++) {
        string a;
        cin >> a;
        if (s.find(a) == s.end()) {
            s[a] = 1;
        }
    }
    cout << s.size() << '\n';
    return 0;
}

Measured memory_bytes: 19232
#include <iostream>

using namespace std;

int main(){
  int A, B, C, ans;
  cin >> A >> B >> C;
  if(A+B >= C){
    ans = B+C;
  }else{
    ans = B + C-(C-(A+B+1));
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {

			String inputData = sc.nextLine();
			

				int count = 1;

				for (int i = 0; i < 27; i++) {
					StringBuilder sb = new StringBuilder();
					
					for (int j = 0; j < inputData.length(); j++) {
						char c = inputData.charAt(j);
						
						if((int)c <= 127 && (int)c >= 92) {
						c = (char) ((int) c + count);

						if (c > 122) {
							c = (char) ((c - 122) + 96);
						} else if (c < 97) {
							c = (char) (123 - (97 - c));
						}
						
						}

						sb.append(c);
					}
					
					String aaa = sb.toString();
					String a = "this";
					String b = "that";
					String c = "the";
					
					if (aaa.matches(".*" + a  + ".*") || aaa.matches(".*" + b  + ".*") ||aaa.matches(".*" + c  + ".*")) {
						System.out.println(sb);
						break;
					}
					
					count++;
					
				}
				
				
			
		}
	}

}

Measured memory_bytes: 29004
s = gets.chomp
t = "AKIHABARA"
i = 0
j = 0
while i < s.size() && j < t.size()
  if s[i] == t[j]
    t[j] = "A"
    i += 1
    j += 1
  else
    j += 1
  end
end

if i < s.size()
  puts "NO"
else
  for k in 0...t.size()
    if t[k] != "A"
      puts "NO"
      exit
    end
  end
  puts "YES"
end


Measured memory_bytes: 1788
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    aa = list(map(int, input().split()))
    aa = list(Counter(aa).values())
    aa.sort()
    cs = [0]
    s = 0
    for a in aa:
        s += a
        cs += [s]
    # print(aa)
    # print(cs)
    ans = n + 1
    i = len(aa)
    for k in range(1, n + 1):
        while 1:
            while i > 0 and aa[i - 1] >= ans:
                i -= 1
            s = cs[i] + ans * (len(aa) - i)
            if s >= ans * k:
                break
            else:
                ans -= 1
        print(ans)

main()


Measured memory_bytes: 38448
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using P = pair<int, int>;
#define debug(var) cout << "[" << #var << "] " << var << endl
const ll mod = 1000000007;


int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    vector<int> pos(n);
    rep(i, n) {
        cin >> p[i];
        pos[p[i]-1] = i;
    }
    
    set<int> s;
    ll ans = 0;

    for (int i=n-1; i>=0; i--) {
        int x = pos[i];
        if (s.size()==0) {
            s.insert(x);
            continue;
        }
        auto it = s.upper_bound(x);
        ll l1, l2, r1, r2;
        if (it!=s.end()) {
            r1 = *it;
            it++;
            if (it!=s.end()) {
                r2 = *it;
            }
            else {
                r2 = n;
            }
            it--;
        }
        else {
            r1 = n;
            r2 = n;
        }
        if (it!=s.begin()) {
            it--;
            l2 = *it;
            if (it!=s.begin()) {
                it--;
                l1 = *it;
            }
            else {
                l1 = -1;
            }
        }
        else {
            l1 = -1;
            l2 = -1;
        }
        ans += (l2-l1) * (r1-x) * (i+1);
        ans += (r2-r1) * (x-l2) * (i+1);
        s.insert(x);
        //debug(ans);
    }
     
    
    
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end()) 
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

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 = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int bfs(const vector<string>& m, int sh, int sw, int gh, int gw) {
  queue<pair<int, int>> q;

  q.push(make_pair(sh, sw));
  const int H = m.size();
  const int W = m[0].size();
  vector<vector<int>> d(H, vector<int>(W, INF));
  d[sh][sw] = 0;

  while (q.size()) {
    pair<int, int> p = q.front(); q.pop();
    if (p.first == gh && p.second == gw) break;

    // for 4 directions
    for (int i = 0; i < 4; i++) {
      int nh = p.first + dx[i], nw = p.second + dy[i];
      if (nw < 0 || nw >= W || nh < 0 || nh >= H ||
          m[nh][nw] == '#' || d[nh][nw] != INF) continue;

      q.push(make_pair(nh, nw));
      d[nh][nw] = d[p.first][p.second] + 1;
    }
  }

  return d[gh][gw];
}

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

  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  int ans = 0;
  rep(sw, w) {
    rep(sh, h) {
      rep(gw, w) {
        rep(gh, h) {
          if (s[sh][sw] == '#' || s[gh][gw] == '#') continue;
          int tmp = bfs(s, sh, sw, gh, gw);
          if (tmp != INF) chmax(ans, tmp);
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define pr(x) prev(x.end())
# define mset multiset
# define umap unordered_map
# define gcd __gcd
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

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

const int mod = 1e9+7;//998244353
const int N = 1e5+5;



void solve(){
	int n;
	cin>>n;
	int v[n];
	ll s = 0;
    for(int i = 0; i < n; i++){
        cin>>v[i];
        s+=v[i];
        //s%=mod;
    }   
    ll ans = 0;
    for(int i = 0; i < n; i++){
        s-=v[i];
		ans+=((s%mod)*v[i])%mod;  
    }
    ans%=mod;
    cout<<ans;
}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


Measured memory_bytes: 4436
#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const int N = 808;

char c[N][N];
pair<int,int> dp[N][N];
int ans = 1e9;
int h, w, K;

queue<tuple<int,int,int>> q;

set<pair<int,int>> s;

int main() {
    cin >> h >> w >> K;
    int starti, startj;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cin >> c[i][j];
            if(c[i][j] == 'S') {
                starti = i; startj = j;
            }
        }
    }
    q.push(make_tuple(starti,startj,K+1));
    while(!q.empty()) {
        
        tuple<int,int,int> t = q.front(); q.pop();
        int i = get<0>(t); int j = get<1>(t);
        s.insert(make_pair(i, j));
        int k = get<2>(t);
        k--;
        if(k == 0) continue;
        if(i-1 >= 0 && c[i-1][j] == '.' && s.find(mp(i-1,j)) == s.end()) {
            q.push(make_tuple(i-1,j,k)); s.insert(mp(i-1,j)); }
        if(i+1 < h && c[i+1][j] == '.' && s.find(mp(i+1,j)) == s.end()) {q.push(make_tuple(i+1,j,k));s.insert(mp(i+1,j)); }
        if(j-1 >= 0 && c[i][j-1] == '.' && s.find(mp(i,j-1)) == s.end()) {q.push(make_tuple(i,j-1,k));s.insert(mp(i,j-1)); }
        if(j+1 < w && c[i][j+1] == '.' && s.find(mp(i,j+1)) == s.end()) {q.push(make_tuple(i,j+1,k));s.insert(mp(i,j+1)); }
    }
    for(auto it = s.begin(); it != s.end(); ++it) {
        ans = min(ans, (int)ceil(1.0*it->fi/K) + 1);
        ans = min(ans, (int)ceil(1.0*it->se/K) + 1);
        ans = min(ans, (int)ceil(1.0*(h-1 - it->fi)/K) + 1);
        ans = min(ans, (int)ceil(1.0*(w-1 - it->se)/K) + 1);
    }
    
    cout << ans;
    
	return 0;
}


Measured memory_bytes: 30720
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	string S;
	cin >> S;
	cout << ((S == "AAA" || S == "BBB")? "No": "Yes") << endl;

	return 0;
}


Measured memory_bytes: 3564
package main

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

// input scanner
var sc = bufio.NewScanner(os.Stdin)

const (
	initialBufSize = 10e4
	maxBufSize     = 10e6
)

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// util
func max(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n > ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

func min(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n < ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

// main
func main() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	s := next()
	l := len(s)
	dp := make([][]int, l)
	for i := 0; i < l; i++ {
		dp[i] = make([]int, 11)
	}
	for j := 0; j < 11; j++ {
		if j <= 5 {
			dp[0][j] = j
		} else if j == 10 {
			dp[0][j] = 1
		} else {
			dp[0][j] = 10 - (j - 1)
		}
	}
	var a int
	for i := 0; i < l; i++ {
		n, _ := strconv.Atoi(s[i : i+1])
		if i == 0 {
			a = n
			continue
		}
		for j := 0; j < 11; j++ {
			_, dp[i][j] = min([]int{dp[i-1][a] + j, dp[i-1][a+1] + (10 - j)})
		}
		a = n
	}
	last, _ := strconv.Atoi(s[l-1 : l])
	fmt.Println(dp[l-1][last])
}


Measured memory_bytes: 128224
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

typedef long long lli;

lli n;
int m, p[20];

lli calc(lli n){
  return n * (n+1) / 2LL;
}

lli gcd(lli x, lli y){
  if(y == 0) return x;
  return gcd(y, x%y);
}

lli lcm(lli x, lli y){
  return (x*y) / gcd(x, y);
}

double solve(){
  lli a = calc(n), b = n;
  for(lli i=1;i<(1LL<<m);i++){
    int cnt = 0;
    lli r = 1;
    for(int j=0;j<m;j++){
      if(i>>j & 1){
        cnt++;
        r = lcm(r, p[j]);
      }
    }
    if(cnt % 2){
      a -= r * calc(n / r);
      b -= n / r;
    }else{
      a += r * calc(n / r);
      b += n / r;
    }
  }
  return b ? (double)a/b : 0;
}

main(){
  while(cin >> n >> m && (n|m)){
    for(int i=0;i<m;i++){
      cin >> p[i];
    }
    printf("%.10f\n", solve());
  }
}

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

struct Imos2D {
    vector<vector<int>> s;
    Imos2D() {}
    Imos2D(const vector<vector<int>> &a) {
    #define rep(i, n) for (int i = 0; i < n; i++)
        int h = a.size(), w = a[0].size();
        s = vector<vector<int>>(h + 1, vector<int>(w + 1, 0));
        rep(i, h) rep(j, w) s[i + 1][j + 1] = a[i][j];
        rep(i, h + 1) rep(j, w) s[i][j + 1] += s[i][j];
        rep(i, h) rep(j, w + 1) s[i + 1][j] += s[i][j];
    #undef rep
    }
    int sum(int i, int j, int h, int w) {
        return s[i + h][j + w] - s[i][j + w] - s[i + h][j] + s[i][j];
    }
};

using Pi = pair<int, int>;
Pi operator + (Pi a, Pi b) {
    return Pi(a.first + b.first, min(a.second, b.second));
}
Pi   dp[32][32][32 + 1][32 + 1];
bool ok[32][32][32 + 1][32 + 1];

int main() {
    int H, W, S;
    while (cin >> H >> W >> S, H) {
        vector<vector<int>> a(H, vector<int>(W));
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cin >> a[i][j];
            }
        }
        Imos2D imos(a);
        int all = imos.sum(0, 0, H, W);
        memset(ok, false, sizeof(ok));
        for (int h = 1; h <= H; h++) for (int w = 1; w <= W; w++) {
            for (int i = 0; i + (h - 1) < H; i++) {
                for (int j = 0; j + (w - 1) < W; j++) {
                    int extra = S - (all - imos.sum(i, j, h, w));
                    if (extra < 0) continue;
                    ok[i][j][h][w] = true;
                    Pi& res = dp[i][j][h][w];
                    dp[i][j][h][w] = Pi(1, extra);
                    for (int dh = 1; dh < h; dh++) {
                        if (ok[i][j][dh][w] && ok[i + dh][j][h - dh][w]) {
                            Pi tmp = dp[i][j][dh][w] + dp[i + dh][j][h - dh][w];
                            res = max(res, tmp);
                        }
                    }
                    for (int dw = 1; dw < w; dw++) {
                        if (ok[i][j][h][dw] && ok[i][j + dw][h][w - dw]) {
                            Pi tmp = dp[i][j][h][dw] + dp[i][j + dw][h][w - dw];
                            res = max(res, tmp);
                        }
                    }
                }
            }
        }
        Pi ans = dp[0][0][H][W];
        cout << ans.first << " " << ans.second << endl;
    }
    return 0;
}


Measured memory_bytes: 11700
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>

using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> a;
    a = vector<vector<int>>(n,vector<int>(m,0));

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

    vector<int> b(m);
    for(int i=0; i<m; i++){
        cin >> b[i];
    }

    for(int i=0; i<n; i++){
        int sum=0;
        for(int j=0; j<m; j++){
            sum += a[i][j] * b[j];
        }
        cout << sum << endl;
    }

    return 0;
}



Measured memory_bytes: 3184
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;

long pp[100005];
long a[100005];
long s[100005];

int main(int argc, char* argv[])
{
    long qq;
    scanf("%ld", &qq);

    vector<long> ll(qq),rr(qq);
    long i;
    for(i=0; i<qq; i++) {
        scanf("%ld%ld", &ll[i], &rr[i]);
    }

    pp[0]=pp[1]=1;
    for(i=2; i<100000; i++) {
        if(pp[i]) continue;
        long k=i+i;
        while(k<100000) {
            pp[k]=1;
            k+=i;
        }
    }

    for(i=1; i<100000; i+=2) {
        if(pp[i]==0 && pp[(i+1)/2]==0) {
            a[i]=1;
        }
    }
    for(i=0; i<100000; i++) {
        s[i+1]=s[i]+a[i];
    }

    for(i=0; i<qq; i++) {
        printf("%ld\n", s[rr[i]+1]-s[ll[i]]);
    }

    return 0;
}


Measured memory_bytes: 4480
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

int main(){
    long n;
    cin >> n;
    vector<long> l(n);
    for(int i = 0; i < n; i++){
        cin >> l[i];
    }
    sort(l.begin(), l.end());
    long sum = accumulate(l.begin(), l.end(), 0L), summ = sum;
    if(sum % 10 == 0){
        for(int i = 0; i < n; i++){
            if(l[i] % 10 == 0) continue;
            else{
                sum -= l[i];
                break;
            }
        }
        if(sum == summ) sum = 0;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

int v[100010];

int main()
{
    //freopen("file.in","r",stdin);
    //freopen("file.out","w",stdout);
    int n,a=0,b=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&v[i]);
    sort(v+1,v+n+1);
    int poz=n;
    while(poz>=1)
    {
        if(v[poz]==v[poz-1] && a==0) {a=v[poz];poz-=2;}
        else if(v[poz]==v[poz-1]) {b=v[poz];break;}
        else poz--;
    }
    printf("%lld",1LL*a*b);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
     
    using namespace std;
     
    int main(void)
    {
      int N;

      scanf("%d", &N);

      int count =0;
      int num;
      bool YES = true;
      for(int i=1;i<=N;i++){
          cin >> num;
          if(num != i){
              count++;
          }
          if(count>2){
              YES =false;
              break;
          }
      }

      if(count ==1){
          YES =false;
      }
      
      if(YES){
          cout<<"YES"<<endl;
            }
      else{
          cout<<"NO"<<endl;
          }

      return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
//----------------------------------------------------------------

int main(void) {
  string w;
  cin >> w;

  int c[26]={};

  rep(i,w.size()){
    c[w[i]-'a']++;
  }

  bool ok=true;
  rep(i,26){
    if(c[i]%2) ok=false;
  }

  prtok(ok);
}


Measured memory_bytes: 256
buildings = []
for _ in range(4):
    building = []
    for _ in range(3):
        building.append([0 for _ in range(10)])
    buildings.append(building)

n = int(input())
notice_list = []
for i in range(n):
    b, f, r, v = map(int, input().split())
    buildings[b-1][f-1][r-1] += v

for i in range(len(buildings)):
    for floor in buildings[i]:
        print(' ', ' '.join(map(str, floor)), sep='')
    if i != len(buildings)-1:
        print("####################")


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

long long int PowMod_RepeatSquaring(long long int N, long long int P, long long int mod)
{
    if (P == 0)
    {
        return 1;
    }
    if (P % 2 == 0)
    {
        long long int t = PowMod_RepeatSquaring(N, P / 2, mod);
        return t * t % mod;
    }
    return (N * PowMod_RepeatSquaring(N, P - 1, mod)) %mod;
}

//x*(x-1)*(x-2)*...*(x-k+1)
long long int kaijou(long long int x, long long int k, long long int mod)
{
    long long int ans = 1;

    for (long long int i = 0; i < k; i++)
    {
        ans *= x - i;
        ans %= mod;
    }

    return ans;
}

long long int combination(long long int n, long long int k, long long int mod)
{
    long long int X, Y;

    X = kaijou(n, k, mod);
    Y = kaijou(k, k, mod);

    long long int inverse_Y = PowMod_RepeatSquaring(Y, mod - 2, mod);

    return (X * PowMod_RepeatSquaring(Y, mod - 2, mod)) % mod;
}

int main()
{
    /* ------- 宣言と入力 ------- */

    long long int n, a, b;

    cin >> n >> a >> b;

    /* ------- 計算 ------- */

    long long int mod = 1000000007;

    long long int ans;

    ans = PowMod_RepeatSquaring(2, n, mod);

    a = min(a, n - a);
    b = min(b, n - b);

    long long int nCa = combination(n, a, mod);
    long long int nCb = combination(n, b, mod);
    long long int nC0 = combination(n, 0, mod);

    ans -= (nCa + nCb + nC0) % mod;

    if (ans < 0)
    {
        ans += mod;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    map<int, ll> cnt;
    ll ans = 0;
    rep(i, n) {
        ans += cnt[-a[i] + i];
        cnt[a[i] + i]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 26668
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll now = INF, ans, n;
int main() {
	cin >> n;
	REP(i, n) {
		ll a;
		cin >> a;
			if (a < now) {
				now = a;
				ans = i + 1;
		}
	}
	cout << ans << endl;
}




Measured memory_bytes: 3088
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include <algorithm> 
using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

int main()
{

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

    vector<pair<long,long>> v(n);
    for(int i=0;i<n;i++){
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(),v.end());

    long int c=0;
    long long int res=0;
    for(int i=0;i<n;i++){
        if(v[i].second+c<m){
            res+=v[i].first*v[i].second;
            c += v[i].second;
        } else {
            res+=v[i].first*(m-c);
            break;
        }
    }
    p(res)
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int k; std::cin >> k;
  vector<ll> a(k); rep(i, k) std::cin >> a[i];
  bool ok = true;
  if (a[k-1] != 2) ok = false;
  ll mi = 2, ma = 3;
  drep(i, k-1) {
    if (ma < a[i] || (ma / a[i]) * a[i] < mi) ok = false;
    if (mi % a[i]) mi += a[i] - mi % a[i];
    ma = (ma / a[i]) * a[i] + a[i]-1;
  }
  if (ok)
    std::cout << mi << " " << ma << "\n";
  else
    std::cout << -1 << "\n";
}


Measured memory_bytes: 1024
#include<stdio.h>
int A[101][101];
int main(){
    int i,j,r,c,cal1,cal2;
    scanf("%d %d",&r,&c);
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            scanf("%d",&A[i][j]);
        }
    }
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            A[i][c] += A[i][j];
            A[r][j] += A[i][j];
        }
        A[r][c] += A[i][c];        
    }
    for(int i=0;i<r+1;i++){
        for(int j=0;j<c+1;j++){
            if(j==c) printf("%d\n",A[i][j]);
            else printf("%d ",A[i][j]);
            }
    }
}


Measured memory_bytes: 2692
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;
bool check(long long h[50], int n){
    long long all = (1LL << n) - 1;
    rep(i,n){
        if(all == h[i]) return 1;
    }
    return 0;
}

int main(){
    int n;
    while(cin >> n,n){
        int d[50][31] = {0};
        long long have[50] = {0};
        long long b = 0;
        rep(i,n){
            have[i] = (1LL << i);
            b |= have[i];
        }

        rep(i,n){
            int m;
            cin >> m;
            rep(j,m){
                int inp;
                cin >> inp;
                d[i][inp] = 1;
            }
        }

        int ans = -1;
        range(i,1,31){
            long long all = 0;
            rep(j,n){
                assert(j < 50);
                assert(i != 31);
                if(d[j][i] == 1){ //i??\?????\?????????
                    all |= have[j]; //?????£????????°???????????????
                }
            }
            long long a = (1LL << n);
            /*
            if(all > a){
                debug(b)
                    debug(all)
                    debug(a)
            }
            */
            assert(all <= a);
            rep(j,n){
                if(d[j][i] == 1){
                    have[j] |= all; //?????\??\????????????????????£???????????°???????????????
                }
            }
            if(check(have, n)){
                ans = i;
                break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  if(A > B){
    if(A > C && C > B){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else{
    if(B > C && C > A){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}

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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST_CASE int tc;cin>>tc;while(tc--)

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

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


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


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

/******************************************************************************************************************************/

int main()
{
    FASTIO

    #ifndef JD
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif

    ll x,k,d,ans;
    cin>>x>>k>>d;
    x = abs(x);
    ll g = x/d;
    if(k<=g){
        ans = x - k*d;
    }
    else{
        ans = x - g*d;
        if(odd(k-g)) {++g;ans = x - g*d;}
    }

    cout<<abs(ans)<<"\n";

    return 0;
}


Measured memory_bytes: 3604
from itertools import combinations

def skill(m, l, x):
    ans = pow(10, 9)
    rikai = [0 for _ in range(m)]

    for i in range(n):
        cl = combinations(range(n), i+1)
        for c in cl:
            cost = 0
            rikai = [0 for _ in range(m)]
            for j in c:
                cost += l[j][0]
                for k in range(m):
                    rikai[k] += l[j][k+1]
            flag = 0
            for k in range(m):
                if rikai[k] < x:
                    flag = 1
                    break
            if flag == 0 and cost < ans:
                ans = cost
            # print(c, cost, rikai)
    if ans != pow(10, 9):
        print(ans)
    else:
        print(-1)

n, m, x = [int(i) for i in input().split()]
l = []
for _ in range(n):
    l.append([int(i) for i in input().split()])

skill(m, l, x)

Measured memory_bytes: 9160
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;

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

const int mod=1e9+7;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << (a<=c&&c<=b||b<=c&&c<=a?"Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
template<typename T> inline void add(T& a, T b) { a += b; if (a >= MOD) a -= MOD; }

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

  int N; cin >> N;
  string S; cin >> S;

  ll r = 0;
  ll g = 0;
  ll b = 0;

  rep(i, N) {
    if(S[i] == 'R') {
      ++r;
    } else if(S[i] == 'G') {
      ++g;
    } else {
      ++b;
    }
  }

  auto ans = r * g * b;
  if(ans == 0) {
    cout << 0 << endl;
    return 0;
  }

  for(int i = 1; i < N; ++i) { // pivot
    for(int j = 0; j < i; ++j) { // left
      int k = i * 2 - j;
      if(k < N) {
        if(S[i] != S[j] && S[i] != S[k] && S[j] != S[k]) --ans;
      }
    }
  }

  cout << ans << endl;
}


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

int main()
{
    ll a;
    string b;
    cin >> a >> b;
    int int1, dec1, dec2;
    int1 = b[0] - '0';
    dec1 = b[2] - '0';
    dec2 = b[3] - '0';
    //cout << int1 << dec1 << dec2 << endl;

    ll ans = 0;
    ans += (a * int(int1) * 100);
    ans += (a * int(dec1) * 10);
    ans += (a * int(dec2));
    ans /= 100;

    cout << ans << endl; 

    return 0;
}

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

#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define REP3(i,x,n) for(int i=x; i>(n); i--)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int N;cin>>N;
    vector<int>S(N);
    REP(i,N)cin >> S[i];
    sort(S.begin(),S.end());
    int q;
    cin >> q;
    int ans=0,t;
    
    REP(i,q){
        cin>>t;
        int left = 0;int right = N;
        while(left<right){
            int middle = (left+right)/2;
            if(S[middle]<t){
                left = middle+1;
            }else if(S[middle]>t){
                right = middle;
            }else{ans++;break;}
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3272
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int H, W; char c;
int main() {
	ios::sync_with_stdio(false);
	while (cin >> W >> H, H | W) {
		vector<vector<int> > a(H, vector<int>(W));
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cin >> c;
				if (c == 'R') a[i][j] = 0;
				if (c == 'G') a[i][j] = 1;
				if (c == 'B') a[i][j] = 2;
			}
		}
		vector<vector<pair<int, int> > > comp;
		vector<vector<bool> > vis(H, vector<bool>(W, false));
		vector<int> dir({ 0, 1, 0, -1 });
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (vis[i][j]) continue;
				comp.push_back(vector<pair<int, int> >({ make_pair(j, i) }));
				vis[i][j] = true;
				queue<pair<int, int> > que;
				que.push(make_pair(j, i));
				while (!que.empty()) {
					pair<int, int> u = que.front(); que.pop();
					for (int k = 0; k < 4; k++) {
						int tx = u.first + dir[k], ty = u.second + dir[k ^ 1];
						if (0 <= tx && tx < W && 0 <= ty && ty < H && !vis[ty][tx] && a[u.second][u.first] == a[ty][tx]) {
							vis[ty][tx] = true;
							comp.back().push_back(make_pair(tx, ty));
							que.push(make_pair(tx, ty));
						}
					}
				}
			}
		}
		vector<int> col(comp.size());
		for (int i = 0; i < comp.size(); i++) {
			for (pair<int, int> j : comp[i]) {
				col[i] = a[j.second][j.first];
				a[j.second][j.first] = i;
			}
		}
		vector<vector<int> > G(comp.size());
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (j + 1 != W && a[i][j] != a[i][j + 1]) {
					G[a[i][j]].push_back(a[i][j + 1]);
					G[a[i][j + 1]].push_back(a[i][j]);
				}
				if (i + 1 != H && a[i][j] != a[i + 1][j]) {
					G[a[i][j]].push_back(a[i + 1][j]);
					G[a[i + 1][j]].push_back(a[i][j]);
				}
			}
		}
		for (int i = 0; i < G.size(); i++) {
			sort(G[i].begin(), G[i].end());
			int ptr = unique(G[i].begin(), G[i].end()) - G[i].begin();
			G[i].erase(G[i].begin() + ptr, G[i].end());
		}
		for (int i = 0; ; i++) {
			bool ok = false;
			for (int j = 0; j < 1 << i; j++) {
				vector<int> w1(col);
				for (int k = 0; k < i; k++) {
					int r = (w1[a[0][0]] + ((j & (1 << k)) ? 2 : 1)) % 3;
					queue<int> que2; que2.push(a[0][0]);
					vector<bool> vis2(G.size()); vis2[a[0][0]] = true;
					while (!que2.empty()) {
						int u = que2.front(); que2.pop();
						for (int l : G[u]) {
							if (!vis2[l] && w1[u] == w1[l]) {
								vis2[l] = true;
								que2.push(l);
							}
						}
					}
					for (int l = 0; l < G.size(); l++) {
						if (vis2[l]) w1[l] = r;
					}
				}
				bool flag = true;
				for (int k = 1; k < G.size(); k++) {
					if (w1[0] != w1[k]) {
						flag = false;
						break;
					}
				}
				if (flag) {
					ok = true;
					break;
				}
			}
			if (ok) {
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3184
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct CharandNum {
	int	Char;  
	int num; 
};

/* functions */
int compar(const int *val1, const int *val2);
int compar2(const void *p, const void *q);

#define MAX_NUM 100000
int main()
{
	int N, M;
	static int A[MAX_NUM];
	static CharandNum BC[MAX_NUM];
	static int Kakikae[MAX_NUM];
	int beforechara = 0;
	int beforenum = 0;
	int i, j;
	int cnt = 0;
	long long sum = 0;

	scanf("%d %d", &N, &M);

	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}


	for (i = 0; i < M; i++) {
		scanf("%d %d", &BC[i].num, &BC[i].Char);
	}
	qsort(A, N, sizeof(int), (int(*)(const void *, const void *))compar);
	qsort(BC, M, sizeof(CharandNum), compar2);

	for (i = 0; i < M; i++) {
		for (j = 0; j < BC[i].num; j++) {
			Kakikae[cnt++] = BC[i].Char;
			if (cnt >= N) {
				break;
			}
		}
		if (cnt >= N) {
			break;
		}
	}	

	for (i = 0; i < N; i++) {
		if (A[i] < Kakikae[i]) {
			A[i] = Kakikae[i];
		}
		sum += A[i];
	}
	// a b c d e f g h i j k l
	// A B C D E F G H I J K L
	printf("%lld\n", sum);

	return 0;
}

/**
* 比較関数
*/
int compar2(const void *p, const void *q) {
	if (((CharandNum*)p)->Char < ((CharandNum*)q)->Char) {
		return 1;
	}
	else if (((CharandNum*)p)->Char == ((CharandNum*)q)->Char) {
		return 0;
	}
	else {
		return -1;
	}
}

/**
* 比較関数
*/
int compar(const int *val1, const int *val2) {
	if (*val1 < *val2) {
		return -1;
	}
	else if (*val1 == *val2) {
		return 0;
	}
	else {
		return 1;
	}
}

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

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

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

const double PI = acos(-1);
#define MOD 1000000007  ///1e9+7

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '

#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) abs((a)*(b))/gcd((a),(b))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

///******************************** C o d e ********************************///



main()
{
    ll x,i,j,a,b,c;
    while(cin>>x){
        c=0;
        for(i=-118;i<120;i++){
            for(j=-118;j<120;j++){
                a=pow((double)i,5);
                b=pow((double)j,5);
                if(a-b==x){
                    cout<<i sp<<j el;
                    c++;
                    break;
                }
            }
            if(c) break;
        }
    }

}



///Thank you.



///Brainless_Loco Terminates Here!


Measured memory_bytes: 4112
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  string s,t; cin >> s >> t;
  REP(i,s.size()) {
    if (s==t) { COUT("Yes"); return 0; };
    rotate(s.begin(), s.begin()+1, s.end());
  }
  COUT("No");
  return 0;
}

Measured memory_bytes: 256