akhauriyash/Code-Regression huggingface dataset:
package main

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

func main() {
	log.SetFlags(log.Lshortfile)
	scn := newScanner()
	H := scn.nextInt()
	W := scn.nextInt()
	a := make([]string, 0)
	red := make([][]byte, 0)
	blue := make([][]byte, 0)
	for i := 0; i < H; i++ {
		s := scn.nextLine()
		a = append(a, s)
		red = append(red, []byte(s))
		blue = append(blue, []byte(s))
	}
	for i := 0; i < 2; i++ {
		for j := 0; j < H; j++ {
			switch i {
			case 0:
				// red
				if j%2 == 0 {
					for k := 0; k < W; k++ {
						red[j][k] = '#'
					}
				}
				red[j][0] = '#'
				red[j][W-1] = '.'
			case 1:
				// blue
				if j%2 != 0 {
					for k := 0; k < W; k++ {
						blue[j][k] = '#'
					}
				}
				blue[j][0] = '.'
				blue[j][W-1] = '#'
			}
		}
	}
	for i := 0; i < H; i++ {
		fmt.Println(string(red[i]))
	}
	fmt.Println("")
	for i := 0; i < H; i++ {
		fmt.Println(string(blue[i]))
	}
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) nextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) nextInt() int {
	v, _ := strconv.Atoi(s.next())
	return v
}

func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 2816
#include <stdio.h>
int main(void){

	int N;
	scanf("%d",&N);
	int v[N],i,j,tmp;
	
	for(i=0;i<N;i++){
	    scanf("%d",&v[i]);
	}
    for (i=0; i<N; ++i) {
     for (j=i+1; j<N; ++j) {
       if (v[i] > v[j]) {
         tmp =  v[i];
         v[i] = v[j];
         v[j] = tmp;
       }
     }
    }
	double ans,temp2;
	temp2=1.0*v[0];
	for(i=1;i<N;i++){
		ans=1.0*(v[i]+temp2)/2;
		temp2=ans;
	}
	printf("%f\n",ans);
 
 
	return 0;

}


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

int main() {
  int n; cin>>n; n<<=1;
  vector<int> v(n);
  for (int i=0; i<n; i++) cin>>v[i];
  sort(v.begin(),v.end());
  int ret=0;
  for (int i=0; i<n; i+=2) ret+=v[i];
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <set>

using namespace std;

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

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

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

int main() {
    int n, i, j, k;
    vector <long long> v;
    set <long long> s;
    
    for (i = 2; v.size() < 1000; i++) {
        for (j = 2; j * j <= i; j++) {
            if (i % j == 0) break;
        }
        
        if (j * j > i) v.push_back(i);
    }
    
    for (i = 0; i < 500; i++) {
        for (j = 0; j < 500; j++) {
            if ((i + j) % 2 == 1) continue;
            
            a[i][j] = v[(i + j) / 2] * v[(i - j) / 2 + 750];
        }
    }
    
    for (i = 0; i < 500; i++) {
        for (j = 0; j < 500; j++) {
            long long l = 1;
            
            if ((i + j) % 2 == 0) continue;
            
            for (k = 0; k < 4; k++) {
                int x = i + dx[k];
                int y = j + dy[k];
                
                if (x < 0 || x >= 500 || y < 0 || y >= 500) continue;
                
                l = lcm(l, a[x][y]);
            }
            
            for (k = 1; ; k++) {
                if (!s.count(l * k + 1)) break;
            }
            
            s.insert(l * k + 1);
            a[i][j] = l * k + 1;
        }
    }
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            printf("%lld ", a[i][j]);
        }
        puts("");
    }
    
    return 0;
}


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

int main()
{
  long A, B, C, K;
  cin >> A >> B >> C >> K;

  if (K <= A) cout << K << endl;
  else if (K - A <= B) cout << A << endl;
  else cout << A - (K - A - B) << endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<map>
using namespace std;

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

	map<int, int> mp;
	for(int i=0; i<N; i++){
		int a;
		cin >> a;

		mp[a]++;
	}

	int ret = 0;
	for(auto it=mp.begin(); it!=mp.end(); it++){
		if(it->second > it->first)
			ret += it->second - it->first;
		else if(it->second < it->first)
			ret += it->second;
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 4736
#include <iostream>

int main()
{
	using namespace std;
	int x;

	cout << "";
	cin >> x;

	switch (x) {
	case 3:
	case 5:
	case 7:
		cout << "YES" << endl;
		break;
	default:
		cout << "NO" << endl;
		break;
	}
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

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

    string a,b;

    cin >> a >> b;

    for(int i = 0;i < a.length();i++)
    {
        if(a==b){ cout << "Yes"; return 0; }
        string b = a;
        a = b.substr(0,b.size()-1);
        a = b[b.size()-1]+a;
    }

    cout << "No";
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;
char ch ;
int a ,b ,c ;
int main()
{
    //freopen("test.in","r",stdin) ;
    //freopen("test.out","w",stdout) ;
    scanf("%c",&ch) ;
    switch(ch){
        case 'a' :{a ++ ;break ;}
        case 'b' :{b ++ ;break ;}
        case 'c' :{c ++ ;break ;}
    }
    scanf("%c",&ch) ;
    switch(ch){
        case 'a' :{a ++ ;break ;}
        case 'b' :{b ++ ;break ;}
        case 'c' :{c ++ ;break ;}
    }
    scanf("%c",&ch) ;
    switch(ch){
        case 'a' :{a ++ ;break ;}
        case 'b' :{b ++ ;break ;}
        case 'c' :{c ++ ;break ;}
    }
    if (!(a == 1 && b == 1 && c == 1))
        printf("No") ;
    else
        printf("Yes") ;
    return 0;
}


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

int main(){
  int n, k;
  cin >> n >> k;
  
  long long ans = 0;
  for(int i = k+1; i <= n; i++){
    long long plus = max(0, (n/i) * (i-k) + max(0, (n%i) - k + 1));
    ans += plus;
    if(k == 0) ans--;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,1,-1,1,-1,-1,0};
int dy[]={0,1,1,-1,-1,1,0,-1};



int main(){
    int n;cin >> n;
    vector<int> a(n),b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    vector<int> aa(3*n);
    for (int i = 0; i < n; i++) {
        aa[i] = b[i] ^ b[(i+1)%n];
        aa[i + n] = a[i] ^ a[(i+1)%n];
        aa[i + 2 * n]  = aa[i + n];
    }
    vector< int > prefix(aa.size());
    for(int i = 1, j = 0; i < aa.size(); i++) {
        if(i + prefix[i - j] < j + prefix[j]) {
            prefix[i] = prefix[i - j];
        } else {
            int k = max(0, j + prefix[j] - i);
            while(i + k < aa.size() && aa[k] == aa[i + k]) ++k;
            prefix[i] = k;
            j = i;
        }
    }
    for (int i = n; i < 2 * n; i++) {
        if(prefix[i] >= n){
            int k = i - n;
            cout << k << " " << (a[k] ^ b[0]) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 9728
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1e9+7;
const llint big=(llint)(2.19e15)+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
using pli=pair<llint,int>;
using daic=priority_queue<pli,vector<pli>,greater<pli>>;
int main(void){
	int n,i,j;cin>>n;
	vector<lldo>x(n);
	vector<lldo>y(n);
	cout<< setprecision(20);
	for(i=0;i<n;i++){cin>>x[i]>>y[i];}
	for(i=0;i<n;i++){
		vector<lldo>kak;
		for(j=0;j<n;j++){
			if(i==j){continue;}
			kak.pub(atan2(y[i]-y[j],x[i]-x[j]));
		}
		SO(kak);
		//cerr<<"de"<<kak.size()<<endl;
		lldo sa=0;
		for(j=0;j<n-2;j++){maxeq(sa,kak[j+1]-kak[j]);}
		maxeq(sa,2*pai+kak[0]-kak[n-2]);
		if(sa<pai){cout<<"0\n";}
		else{cout<<(sa-pai)/(2*pai)<<endl;}
	}
	RE;
}

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

using ll = long long;
using namespace std;


ll n, s1, s2, ff, bb;
vector<ll> a, b, c;
const ll mod = 998244353;
 

int main(){
    cin >> n;
    rep(i,3*n){
        char s; cin >> s;
        if(s == 'R') a.pb(i);
        if(s == 'G') b.pb(i);
        if(s == 'B') c.pb(i);
    }

    vector<ll> front(n), back(n);
    rep(i,n){
        front[i] = min({a[i],b[i],c[i]});
        back[i] = max({a[i],b[i],c[i]});
    }

    ll ans = 1;
    rep(i,3*n){
        if(ff < n && front[ff] == i) s1++, ff++;
        else if(bb < n && back[bb] == i) ans *= s2--, bb++;
        else ans *= s1--, s2++;
        ans %= mod;
    }
    rep(i,n) ( ans *= i+1 ) %= mod;
    cout << ans << endl;
    return 0;
}

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

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

int main(){
int c[3][3];
rep(i,3){
  rep(j,3)
  cin>>c[i][j];
}
bool flag =false;
for(int i=0;i<=100;i++){
int a[3],b[3];
bool flag1=true;
b[0]=c[0][0]-i;
b[1]=c[1][0]-i;
b[2]=c[2][0]-i;
a[0]=i;
a[1]=c[0][1]-b[0];
a[2]=c[0][2]-b[0];
rep(x,3){
  rep(y,3){
if(a[x]+b[y]!=c[y][x])
flag1=false;
  }
}
if(flag1)
flag=true;
}
if(flag)
cout<<"Yes"<<endl;
else
{
  cout<<"No"<<endl;
}

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int n;

int main(){
	while(scanf("%d", &n),n){
		int t = 0;
		while(true){
			if(n == 1) break;
			if(n%2) n = n*3+1;
			else n /= 2;
			t++;
		}
		printf("%d\n", t); 
	}
}

Measured memory_bytes: 1028
import sys
input = sys.stdin.readline

class Dice:
    def __init__(self, u, d, w, e, n, s):
        self.nums = {
            "u": u,
            "d": d,
            "w": w,
            "e": e,
            "n": n,
            "s": s
        }
    
    def roll_w(self):
        dic = {}
        dic["s"] = self.nums["s"]
        dic["n"] = self.nums["n"]
        dic["w"] = self.nums["u"]
        dic["u"] = self.nums["e"]
        dic["e"] = self.nums["d"]
        dic["d"] = self.nums["w"]
        self.nums = dic
    
    def roll_e(self):
        dic = {}
        dic["s"] = self.nums["s"]
        dic["n"] = self.nums["n"]
        dic["w"] = self.nums["d"]
        dic["d"] = self.nums["e"]
        dic["e"] = self.nums["u"]
        dic["u"] = self.nums["w"]
        self.nums = dic
    
    def roll_s(self):
        dic = {}
        dic["w"] = self.nums["w"]
        dic["e"] = self.nums["e"]
        dic["s"] = self.nums["u"]
        dic["u"] = self.nums["n"]
        dic["n"] = self.nums["d"]
        dic["d"] = self.nums["s"]
        self.nums = dic
    
    def roll_n(self):
        dic = {}
        dic["w"] = self.nums["w"]
        dic["e"] = self.nums["e"]
        dic["n"] = self.nums["u"]
        dic["u"] = self.nums["s"]
        dic["s"] = self.nums["d"]
        dic["d"] = self.nums["n"]
        self.nums = dic
    

def main():
    a = list(map(int, input().split()))
    s = input().strip()

    dice = Dice(a[0], a[5], a[3], a[2], a[4], a[1])

    for c in s:
        if c == "S":
            dice.roll_s()
        elif c == "W":
            dice.roll_w()
        elif c == "N":
            dice.roll_n()
        elif c == "E":
            dice.roll_e()
    
    print(dice.nums["u"])



if __name__ == "__main__":
    main()


Measured memory_bytes: 5620
package main

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

func main() {
	nextReader = NewScanner()
	_ = nextInt()  //モンスターの数
	a := nextInt() // 各モンスターの体力

	sort.Ints(a)

	for i := 0; i < len(a)-1; i++ {
		x := a[i]
		y := a[i+1]
		for x > 0 && y > 0 {
			x, y = attack(x, y)
		}
		a[i+1] = int(math.Max(float64(x), float64(y)))
	}

	fmt.Printf("%d", a[len(a)-1])
}

func attack(x, y int) (int, int) {
	if x < y {
		return x, y % x
	} else {
		return x % y, y
	}
}

// ------ Mathライブラリ ---------------------------------//
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func maxIdx(a ...int) int {
	r := a[0]
	index := 0
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
			index = i
		}
	}
	return index
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func minNonZero(a ...int) int {
	r := math.MaxInt64
	for i := 0; i < len(a); i++ {
		if r > a[i] && a[i] > 0 {
			r = a[i]
		}
	}
	return r
}

func minIdx(a ...int) int {
	r := a[0]
	index := 0
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
			index = i
		}
	}
	return index
}

func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// ------ Mathライブラリ ---------------------------------//

// ----- 標準入力用の関数 ----------------------------------//
var nextReader func() []string

func NewScanner() func() []string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	return func() []string {
		r.Scan()
		return strings.Fields(r.Text())
	}
}

func nextString() []string {
	return nextReader()
}

func nextInt() []int {
	var intArray []int
	strArray := nextReader()
	for _, v := range strArray {
		i, _ := strconv.Atoi(v)
		intArray = append(intArray, i)
	}
	return intArray
}

func nextFloat64() []float64 {
	var floatArray []float64
	strArray := nextReader()
	for _, v := range strArray {
		f, _ := strconv.ParseFloat(v, 64)
		floatArray = append(floatArray, f)
	}
	return floatArray
}

// ------ 標準入力用の関数 ---------------------------------//

// ------ あまり使わない -----------------------------------//
func nextInt64() []int64 {
	var int64Array []int64
	strArray := nextReader()
	for _, v := range strArray {
		i, _ := strconv.ParseInt(v, 10, 64)
		int64Array = append(int64Array, i)
	}
	return int64Array
}

// ------ あまり使わない -----------------------------------//


Measured memory_bytes: 8192
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <unordered_map>
#include <math.h>
using namespace std;
#define _USE_MATH_DEFINES

int main() {
	int H, W;
	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0)
			break;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (i == 0 || i == H - 1 || j == 0 || j == W - 1)
					cout << '#';
				else
					cout << '.';
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,y;
    cin>>n>>y;
    rep(i,n+1){
      rep(j,n-i+1){
	if(10000*i+5000*j+1000*(n-i-j)==y){
	  cout<<i<<' ' <<j<<' '<<n-i-j<<'\n';
	  goto tmp;
	}
      }
    }
  cout<<-1<<' '<<-1<<' '<<-1<<'\n';
 tmp:  
  	
    return(0);
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if (a <= 0 && 0 <= b) {
    cout << "Zero" << endl;
  } else if (0 < a) {
    cout << "Positive" << endl;
  } else {
    if ((abs(b-a)+1) % 2) {
      cout << "Negative" << endl;
    } else {
      cout << "Positive" << endl;
    }
  }
}

Measured memory_bytes: 256
#include                          <bits/stdc++.h>
#define     lli                   unsigned long long int
#define     ll                    long long int
#define     PI                    acos(-1.0)
#define     UNIQUE(V)             (V).erase(unique(ALL(V), (V).end()) //vector/string etc must need to be sorted
#define     timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define     ALL(V)                (V).begin(), (V).end()
#define     MEMSET(a, val)        memset(a, val, sizeof(a))
#define     FILE_INPUT            freopen("input.txt", "r", stdin) , freopen("output.txt", "w", stdout)
#define     DEBUG                 printf("---- ekhane asi ekhon ---- \n");
#define     SQR(x)                ((x)*(x))
using       namespace             std;


template    <class T> T GCD(T a, T b) { return (b != 0 ? GCD <T> (b, a%b) : a); }
template    <class T> T LCM(T a, T b) { return ((a*b)  / GCD <T> (a, b)); }
template    <class T> T POW(T x, T n) { if(n == 0) return 1; if(n&1) return x*POW(x, n-1);  else return SQR(POW(x, n/2));}

long long   Bigmod(long long base, long long power, long long MOD) {long long ret = 1; while(power) {if(power & 1) ret = (ret*base)%MOD; base = (base*base)%MOD; power >>= 1;} return ret;}
bool        isVowel(char ch) {ch = toupper(ch); if(ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E') return true; return false;}
long long   ModInverse(long long number, long long MOD) {return Bigmod(number, MOD-2, MOD);}
bool        isConst(char ch) {if(isalpha(ch) && !isVowel(ch)) return true; return false;}
int         toInt(string s)  {int si; stringstream ss(s); ss >> si; return si;}

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


//------------------- Let`s Start ------------------------ //

bool myfunc(pair<char, char> &x, pair<char, char> &y)
{
    if(x.first == y.first || x.second == y.second) return true;
    else return false;
}


int main()
{
    timesave;

    ll t, a, b, c, d;

    cin >> t;

    for(int i = 0; i < t; i++){
        cin >> a >> b >> c >> d;

        if(b > a || b > d) cout << "No" << endl;

        else if(c >= b) cout << "Yes" << endl;

        else{
            ll gcd = __gcd(b, d);
            ll res = b - gcd + (a%gcd);

            if(res > c) cout << "No" << endl;
            else cout << "Yes" << endl;
        }
    }

	return 0;
}


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

int dp[100001];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    dp[i] = 0x7fffffff;
    int x = 1;
    while (i - x >= 0) {
      dp[i] = min(dp[i], dp[i - x] + 1);
      x *= 6;
    }
    x = 9;
    while(i-x>=0){
      dp[i] = min(dp[i], dp[i - x] + 1);
      x *= 9;
    }
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 640
N = gets.to_i
MOD = (10**9) + 7

STRING = %w(A G C T)
BLACK3 = %w(AGC GAC ACG)
# 後ろ3文字にを見れば次に追加していい文字が一意に定まるので、その判定のためのRegExp
BLACK = {
  /.AG/ => 'C',
  /.AC/ => 'G',
  /.GA/ => 'C',
  /A.G/ => 'C',
  /AG./ => 'C'
}

# AGCTからなる3文字を全列挙、禁止文字を取り除く
STRING_3 = STRING.repeated_permutation(3).map(&:join).reject { |s| BLACK3.include?(s) }

# 3文字をkeyに次につけられる文字をvalue(Array)に入れる
STRING_3_WITH_NEXT = STRING_3.each_with_object({}) { |str3, obj|
  obj[str3] = STRING - BLACK.each_with_object([]) {
    |(reg, str), obj|
    obj << str if reg === str3
  }
}

# DPをします。
# dp[n文字]['ACG'] = dp[n-1]['AAC' or 'CAC' or 'GAC' or 'TAC'] の4つの和
dp = Array.new(N+1) { Hash.new(0) }
STRING_3.each { |str| dp[3][str] = 1 }

4.step(N) do |i|
  STRING_3_WITH_NEXT.each do |str, next_strs|
    ts = str[1..2]
    next_strs.each do |next_str|
      dp[i][ts+ next_str] += dp[i - 1][str]
    end
  end
end

puts (dp[N].values.reduce(:+)%MOD)

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

int main(void){
    int n, m, all = 0;
    vector<int> a;
    cin >> n >> m;
    for(int i = 0; i < n; ++i){
        int num;
        cin >> num;
        all += num;
        a.push_back(num);
    } 
    sort(a.begin(), a.end());
    cout << ((a[n-m] >= ((float)all / (4 * m)))? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <tuple>
#include <queue>
using namespace std;

typedef long long ll;

#define INF 100000000;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define eps 1.0e-14;
#define mod 1e9 + 7;

int main(){
	ll A,V,B,W,T; cin >> A >> V >> B >> W >> T;
	ll oni = V * T;
	ll nige = W * T;
	string ans;
	ll sa = abs(A - B);
	ll hantei = (sa + nige) - oni;
	if (hantei <= 0) ans = "YES";
	else ans = "NO";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int n,a,ans;
vector<int> v;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++)v.push_back(-1);
    for(int i=0;i<n;i++){
        cin>>a;
        int L=lower_bound(v.begin(),v.end(),a)-v.begin();
        L--;
        v[L]=a;
    }
    for(int i=0;i<v.size();i++)if(v[i]!=-1)ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 892
#include <cstdio>
#include <algorithm>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

int N, K;
char S[100010];
std::vector<int> a, b;
int Sa[100010], Sb[100010];
int ans;

int main()
{
  scanf( "%d%d", &N, &K );
  scanf( "%s", S );

  int cnt = 0;

  S[N] = '2';

  rep( i, N+1 )
  {
    if( i && S[i] != S[i-1] )
      (S[i-1]=='1'?b:a).push_back( cnt ), cnt = 0;

    ++cnt;
  }

  rep( i, a.size() )
    Sa[i+1] = Sa[i]+a[i];//, printf( "a[%d] = %d\n", i, a[i] );
  rep( i, b.size() )
    Sb[i+1] = Sb[i]+b[i];//, printf( "b[%d] = %d\n", i, b[i] );

  /*
    i = 1

    111 0 11 [00] 1 00 1
    a: 1,[2],2
    b: 3,2,1,1
  */

  if( K == 1 )
  {
    if( a.empty() )
    {
      printf( "%d\n", N );

      return 0;
    }

    rep( i, a.size() )
    {
      if( S[0] == '0' )
        ans = std::max( ans, a[i]+(i<b.size()?b[i]:0)+(i?b[i-1]:0) );
      else
        ans = std::max( ans, a[i]+(i<b.size()?b[i]:0)+(i+1<b.size()?b[i+1]:0) );
    }

    printf( "%d\n", ans );

    return 0;
  }

  if( a.size() <= K || b.size() <= K-1 )
  {
    printf( "%d\n", N );

    return 0;
  }

  // a: '0', b: '1'
  rep( i, std::max<int>(a.size()-K+1,0) )
  {
    // a0 b0 a1 b1
    if( S[0] == '0' )
      ans = std::max( ans, Sa[i+K]-Sa[i]+Sb[std::min<int>(i+K,b.size())]-Sb[std::max(0,i-1)] );
    // b0 a0 b1 a1
    else
      ans = std::max( ans, Sa[i+K]-Sa[i]+Sb[std::min<int>(i+K+1,b.size())]-Sb[i] );
  }

  rep( i, std::max<int>(b.size()-K,0) )
  {
    // a0 b0 a1 b1
    if( S[0] == '0' )
      ans = std::max( ans, Sa[std::min<int>(i+K,a.size())]-Sa[std::min<int>(i,a.size())]+Sb[std::min<int>(i+K,b.size())]-Sb[std::max(i-1,0)] );
    // b0 a0 b1 a1
    else
      ans = std::max( ans, Sa[std::min<int>(i+K-1,a.size())]-Sa[std::max(0,i-1)]+Sb[std::min<int>(i+K,b.size())]-Sb[std::max(i-1,0)] );

    //printf( "{%d} %d\n", i, Sa[std::min<int>(i+K-1,a.size())]-Sa[std::max(0,i-1)]+Sb[std::min<int>(i+K,b.size())]-Sb[std::max(i-1,0)] );
  }

  /*
    K = 2
    i = 3

    i = 3

    0 111 0 1 0 1 0 [11] 00 11
    a: 1,1,1,1,2
    b: 3,1,1,[2],2
  */

  printf( "%d\n", ans );

  return 0;
}

Measured memory_bytes: 1276
#include <iostream>
using namespace std;
using ll = long long;
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
const ll MOD = 1000000007;
int a[26];
int main() {
	int n;
	string s;
	cin >> n >> s;
	rep(i, n) a[s[i] - 'a']++;
	ll ans = 1;
	rep(i, 26) ans = ans * (a[i] + 1) % MOD;
	cout << (ans + MOD - 1) % MOD << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

typedef int node_id;

std::vector<int> result(300000);
std::vector<bool> checked(300000);
std::vector<std::vector<node_id> > adjacent(300000);
std::vector<int> counter(300000);

void dfs(node_id now_node, int now_val){
  now_val += counter[now_node];
  //std::cout << "dfs(" << now_node <<","<<now_val<<")"<<std::endl;
  result[now_node] = now_val;
  checked[now_node] = true;
  for(const auto& elem: adjacent[now_node]){
    if(!checked[elem]) dfs(elem, now_val);
  }

}


int main(void){

  int n, q;
  std::cin >> n >> q;
  
  for(int i=0; i<n-1; i++){
    node_id a, b;
    std::cin >> a >> b;
    adjacent[a].push_back(b);
    adjacent[b].push_back(a);
  }

  for(int i=0; i<q; i++){
    node_id p;
    int x;
    std::cin >> p >> x;
    counter[p] += x;
  }

  //for(int i=1; i<n; i++){
  //  std::cout << counter[i] << " ";
  //}
  //std::cout << std::endl;
  
  dfs(1, 0);
  for(int i=1; i<=n; i++){
    std::cout << result[i] << " ";
  }
  std::cout << std::endl;

  return 0;
}


Measured memory_bytes: 27392
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n+m){
    vector<int>ve(n);
    ll ans=0;
    for(int i=0;i<n;i++){
      cin>>ve[i];ans+=ve[i];
    }
    sort(ve.begin(),ve.end(),greater<int>());
    for(int i=m-1;i<n;i+=m)
      ans-=ve[i];
    cout<<ans<<endl;
  }
  return 0;
}



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

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
int n, x, t;

int main(){
    cin >> n >> x >> t;
    int ans = 0;
    while(n != 0){
        if(n < x){
            ans+=t;
            n = 0;
        } else {
            ans+=t;
            n -= x;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const ll mod = 1000000007;

int n, m;
vector<int> visited;

void dfs(const Graph &G, int v) {

    visited[v] = 1;

    rep(u, n) {
        if(G[u][v] && !visited[u]) {
            dfs(G, u);
        }
    }

}

int main() {

    cin >> n >> m;    

    Graph G(n, vector<int>(n));
    vector<int> a(m), b(m);
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--;  b[i]--;
        G[a[i]][b[i]] = G[b[i]][a[i]] = 1;
    }

    int ans = 0;
    rep(i, m) {

        G[a[i]][b[i]] = G[b[i]][a[i]] = 0;

        visited.assign(n, 0);

        dfs(G, 0);

        rep(j, n) {
            if(!visited[j]) {
                ans++;
                break;
            } 
        }

        G[a[i]][b[i]] = G[b[i]][a[i]] = 1;

    }

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

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

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

  int *A;
  A = new int[num];

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

  int numSwap = 0;
  for (int i = 0; i < num; i++) {
    int argmin = i;
    for (int j = i; j < num; j++) {
      if (A[j] < A[argmin]) {
        argmin = j;
      }
    }
    if (argmin != i) {
      int tmp = A[i];
      A[i] = A[argmin];
      A[argmin] = tmp;
      numSwap++;
    }
  }

  for (int i = 0; i < num - 1; i++) {
    cout << A[i] << " ";
  }
  cout << A[num - 1] << endl;
  cout << numSwap << endl;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;
int intceil(int a, int b) {
	return (a + (b - 1)) / b;
}
int main() {
	cin >> N;
	vector<int>C(N), S(N), F(N);
	for (int i = 0; i < N - 1; i++) {
		cin >> C[i] >> S[i] >> F[i];
	}
	for (int i = 0; i < N - 1; i++) {
		ans = 0;
		ans += S[i] + C[i];
		for (int j = i+1; j < N - 1; j++) {
			if (ans <= S[j])ans = S[j] + C[j];
			else {
				ans = F[j] * intceil(ans, F[j]) + C[j];
			}
		}
		cout << ans << endl;
	}
	cout << 0 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#define lowbit(x) ((-x)&(x))
#define f(i,x,y) for(int i=(x);i<=(y);i++)
#define r(i,x,y) for(int i=(x);i>=(y);i--)
#define ll long long
using namespace std;//head
const int inf=0x3f3f3f3f;
string s; 
int main(){
cin>>s;
int a=0,b=0;
for(int i=0;i<s.length();i++ ){
	if(s[i]=='A')a++;
	else b++; 
}
if(a&&b)printf("Yes");
else printf("No");
	
	return 0;
}


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

ll x,y,tmp=0;

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

int main(){

	cin >>x>>y;

	ll g = gcd(x,y);

	for(ll i=2; i<= g / i; i++){
		if(g%i==0){
				tmp++;
				while(g%i == 0) g /= i;
		}
    }
	if(g>1)tmp++;
	cout<<tmp+1<<endl;

	return 0;
}


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

#define debug(x) cerr << #x << ": " << x << endl

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  multiset<int> ms;
  int res = numeric_limits<int>::max();
  for (int i = 0; i < n; i++) {
    if (i >= k) 
      ms.erase(ms.lower_bound(a[i - k]));
    ms.insert(a[i]);
    if (i >= k - 1) {
      int mn = 0;
      int mx = 0;
      mn = min(mn, *ms.begin()), mx = max(mx, *ms.rbegin());
      res = min(res, min({2 * abs(mn) + abs(mx), abs(mn) + 2 * abs(mx)}));
    }
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 5376
/*---------------------------------- NEVER GIVE UP --------------------------------------------*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef double ld;
typedef pair<ll,ll> pii;
typedef tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fastt ios_base::sync_with_stdio(false); cin.tie(NULL)
#define debug1(x) cerr<<#x<<" : "<<x<<endl
#define debug2(x,y) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define debug3(x,y,z) cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl

const ll modd=1e9+7;
const ll inf=1e18;

ll poww(ll a,ll b){
  ll ans=1;
  while(b){
    if(b&1LL) ans=(ans*a);
    a=(a*a);
    b=b>>1LL;
  }
  return ans;
}

/*    
         -> mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
         -> cout<<"Case #"<<casee<<": "<<ans<<endl; // for google kickstart

*/

/*-----------------------------------------------------------------------------------------------*/

bool valid(ll month){
  if(month>0 && month<=12) return true;
  else                     return false;
}

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

   ll month1=(s[0]-'0')*10+(s[1]-'0');
   ll  month2=(s[2]-'0')*10+(s[3]-'0');

   if(valid(month1) && valid(month2)){
      cout<<"AMBIGUOUS\n";
   }

   else if(valid(month1)){
      cout<<"MMYY\n";
   }

   else if(valid(month2)){
      cout<<"YYMM\n";
   }

   else{
      cout<<"NA\n";
   }
 
   return 0;
}


Measured memory_bytes: 256
from sys import stdin
from collections import defaultdict
input = stdin.readline
# ~ T = int(input())
T = 1
for t in range(1,T + 1):
	n = int(input())
	count = 0; ans = 0
	for i in range(1,n + 1):
		x,y = map(int,input().split())
		if x == y:
			count += 1
		else:
			ans = max(ans,count)
			count = 0
	ans = max(ans,count)
	print("Yes" if ans >= 3 else "No")
			


Measured memory_bytes: 9468
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
 
using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU 
 
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    while (n != 0) {
        int A = 0, B = 0;
        REP(i, n) {
            int a, b;
            cin >> a >> b;
            if (a > b) {
                A += a + b;
            }
            else if(a < b) {
                B += a + b;
            }
            else {
                A += a;
                B += b;
            }
        }
        cout << A << " " << B << endl;
        cin >> n;
    }
    PAU;
    return 0;
}


Measured memory_bytes: 3072
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int ufp[100100];
ll ufr[100100];

void ufinit(int n){
	int i;
	for(i=0; i<n; ++i){
		ufp[i] = i;
		ufr[i] = 1ll;
	}
}

int ufind(int x){
	if(ufp[x] == x){
		return x;
	}else{
		ufp[x] = ufind(ufp[x]);
		return ufp[x];
	}
}

ll unionf(int x, int y){
	ll ret;
	x = ufind(x);
	y = ufind(y);
	if(x==y){
		return 0ll;
	}
	ret = ufr[x]*ufr[y];
	if(ufr[x] > ufr[y]){
		ufp[y] = x;
		ufr[x] += ufr[y];
	}else{
		ufp[x] = y;
		ufr[y] += ufr[x];
	}
	return ret;
}

int a[100100],b[100100];
ll ans[100100];

int main(void){
	int m,i;
	ll n,s;
	cin >> n >> m;
	s = n*(n-1);
	s /= 2;
	ufinit((int)n);
	for(i=(m-1); i>=0; --i){
		cin >> a[i] >> b[i];
		--a[i]; --b[i];
	}
	ans[0] = 0ll;
	for(i=0; i<m; ++i){
		ans[i+1] = unionf(a[i],b[i]);
		ans[i+1] += ans[i];
	}
	for(i=(m-1); i>=0; --i){
		cout << (s-ans[i]) << endl; 
	}
	return 0;
}


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

int main() {
	int room[4][3][10] = {}, n, i, j, k, l, b, f, r, v;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> b >> f >> r >> v;
		room[b - 1][f - 1][r - 1] += v;
	}
	for (i = 0; i < 4; i++) {
		if (i != 0) {
			for (l = 0; l < 20; l++)cout << "#";
			cout << endl;
		}
		for (j = 0; j < 3; j++) {
			for (k = 0; k < 10; k++) {
				cout << " " << room[i][j][k];
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;

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

		int n = scan.nextInt();
		int[] arr = new int[n];
		int start = (n)/2;
		for(int i = 1; i <= n; i++) {
			if(n%2==0) arr[start + ((i%2!=0)?1:-1) * (i/2)] = scan.nextInt();
			else arr[start + ((i%2==0)?1:-1) * (i/2)] = scan.nextInt();
		}
		System.out.print(arr[0]);
		for(int i = 1; i < n; i++) {
			System.out.print(" "+arr[i]);
		}
		System.out.println();
	}
}


Measured memory_bytes: 94212
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#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 fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const ll MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;

int lcs(string s, string t) {
    vvi dp(s.size() + 1, vi(t.size() + 1));
    
    for(int i = 0; i < s.size(); i++) {//LCS
        for(int j = 0; j < t.size(); j++) {
            if(s[i] == t[j]) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            }
            else{
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            }
        }
    }
    return dp[(int)s.size()][(int)t.size()];
}

int main(void){

   int n;
   string s;
   cin>>n>>s;
   ll ans=0;
   for(char i='0';i<='9';i++){
       for (char j = '0'; j <= '9'; j++)
       {
           for (char k = '0'; k <= '9'; k++)
           {
               string tmp="";tmp+=i;tmp+=j;tmp+=k;
               if(lcs(s,tmp)==3)ans++;
           }
       }
   }
   fin(ans);
}

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


public class Main{

	public static void main(String[] args) throws IOException{
		// TODO ?????????????????????????????????????????????

		BufferedReader insBR = new BufferedReader(new InputStreamReader(System.in));

		String strLine = null;
		while(true){
			//??????????????????
			strLine = insBR.readLine();
			//?????¬???????????¶
			if("-".equals(strLine)){
				break;
			}
			//?????£??????????????°??????
			String strNum =insBR.readLine();
			int m = Integer.parseInt(strNum);

			for(int i = 0; i < m; i++){
				//????????????????????°?????????
				String strH = insBR.readLine();
				int h = Integer.parseInt(strH);

				//?????????????????????
				String strCutLine = strLine.substring(0,h);
				String strTemp = strLine.substring(h,strLine.length());
				//??£???
				strLine = strTemp + strCutLine;
			}
			System.out.println(strLine);

		}


	}
}

Measured memory_bytes: 17040
fun main(arg: Array<String>) {
    val N = nextInt()
    val S = next()
    val A = BooleanArray(N)
    val B = BooleanArray(N)
    val C = BooleanArray(N)
    for (n in A.indices) A[n] = S[n] == 'o'
    for (b in 0 .. 3) {
        B[0] = (b and 1) != 0
        B[1] = (b and 2) != 0
        for (n in C.indices) C[n] = A[n]
        for (n in C.indices) {
            C[n] = C[n] xor B[n]
            if (n in 1 until N - 1) B[n + 1] = B[n - 1] xor C[n]
        }
        if ((B[0] == (B[N - 2] xor C[N - 1])) && (B[N - 1] == (B[1] xor C[0]))) {
            val sb = StringBuilder()
            for (n in B.indices) sb.append(if (B[n]) 'S' else 'W')
            return println(sb.toString())
        }
    }
    println(-1)
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta


Measured memory_bytes: 40704
#include <iostream>
#include <set>

int main() {
    int N;
    std::cin >> N;
    std::set<int> s;
    for (int i = 0; i < N; ++i) {
        int e;
        std::cin >> e;
        s.insert(e);
    }

    int Q;
    std::cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int k;
        std::cin >> k;
        if (!s.count(k)) {
            std::cout << 0 << std::endl;
            return 0;
        }
    }

    std::cout << 1 << std::endl;
}


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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

// left, down, right, up
const int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};

int gx, gy;
int W, H;

void dfs(vvi& field, int x, int y, int dir, int& mi, int depth) {
    if (depth == 10) return;

//    LOG("%d %d %d %d\n", x, y, dir, depth);

    while (1) {
        x += dx[dir], y += dy[dir];
        if (0 <= x && x < W && 0 <= y && y < H) {
            if (field[y][x] == 1) return;
            if (x == gx && y == gy) {
                mi = min(mi, depth+1);
                return;
            }
            int nx = x + dx[dir], ny = y + dy[dir];
            if (0 <= nx && nx < W && 0 <= ny && ny < H) {
                if (field[ny][nx] == 1) {
                    field[ny][nx] = 0;
                    REP(d, 4) {
                        dfs(field, x, y, d, mi, depth+1);
                    }
                    field[ny][nx] = 1;
                    return;
                }
            }
        } else {
            return;
        }
    }
}

int main() {
    while (cin >> W >> H, W|H) {
        vvi field(H, vi(W));
        int x, y;
        REP(i, H) REP(j, W) {
            cin >> field[i][j];
            if (field[i][j] == 2) {
                x = j;
                y = i;
            } else if (field[i][j] == 3) {
                gx = j;
                gy = i;
            }
        }

        int mi = 1e9;
        REP(dir, 4) {
            dfs(field, x, y, dir, mi, 0);
        }
        if (mi == 1e9) {
            cout << "-1" << endl;
        } else {
            cout << mi << endl;
        }
    }
}

Measured memory_bytes: 3144
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>	
using namespace std;
typedef long long ll;
#define bay_bay return 0;
#define fori(n) for(int i=0;i<n;++i)
#define for1(n) for(int i=1;i<=n;i+=3)
#define all(v) ((v).begin()), ((v).end())	
#define sz(v) v.size()
#define endl "\n"
constexpr auto EPS = 1e-9;
#define ff fflush(stdout);
const ll Mod = 1e9 + 7;
clock_t T;
#define ctime cerr << "Time : " << double(clock() - T) / CLOCKS_PER_SEC << endl
void GOAT()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
#endif
}

int main()
{
	//GOAT();
	int a, b, c;
	cin >> a >> b >> c;
	cout << c<<" " << a<<" " << b << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(S == T) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inp_ll;

const int MAXN = 300010;

int n, m;
int a[MAXN];
int f1[MAXN], f2[MAXN];

int main()
{
	
	scanf("%d", &n);
	m = 1<<n;
	for (int i = 0; i < m; ++ i)
	{
		scanf("%d", &a[i]);
		f1[i] = max(a[0], a[i]);
		f2[i] = min(a[0], a[i]);
	}
	int ans = 0;
	for (int s = 1; s < m; ++ s)
	{
		for (int t = (s-1)&s; t; t=(t-1)&s)
		{
			if (a[t] > f1[s])
			{
				f2[s] = f1[s];
				f1[s] = a[t];
			}
			else if (a[t] > f2[s])
				f2[s] = a[t];
		}
		ans = max(ans, f1[s]+f2[s]);
		printf("%d\n", ans);
	}
	
	return 0;
}


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


int main() {
  int N;
  cin >> N;
  
  vector<int> a(N);
  for (int i=0; i<N;i++){
  	cin >> a.at(i);
  }
  
  vector<long long> b(200000,0);
  
  for (int i=0; i<N; i++){
  	b.at(a.at(i))++;
  }
  
  long long count=0;
  for (int i=0; i<200000; i++){
  	
    if (b.at(i)>1){
    	count += b.at(i)*(b.at(i)-1)/2;    
    }
    
  }
  

  for (int k=0; k<N; k++){
    long long c=count - b.at(a.at(k)) + 1;
    cout << c << endl;
  }
    
}

Measured memory_bytes: 4992