akhauriyash/Code-Regression huggingface dataset:
//https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_1_B
//重み付きUnion Find木
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//重み付きUnion Find木
template<class T>
struct wuf_tree {
    std::vector<int> parent;
    std::vector<T> diff_weight;
    int __size;
    wuf_tree(int size_, T sum_unity=T()) : parent(size_, -1), diff_weight(size_,sum_unity), __size(size_) {}
    void unite(int x, int y, T w) {
        w += weight(x);
        w -= weight(y);
        if ((x = find(x)) != (y = find(y))) {
            if (parent[y] < parent[x]) { std::swap(x, y); w=-w; }
            parent[x] += parent[y];
            parent[y] = x;
            diff_weight[y] = w;
            __size--;
        }
    }
    bool is_same(int x, int y) { return find(x) == find(y); }
    int find(int x) {
        if (parent[x]<0) return x;
        int r = find(parent[x]);
        diff_weight[x] += diff_weight[parent[x]];
        return parent[x] = r;
    }
    int size(int x) { return -parent[find(x)]; }
    int size() const { return __size; }
    T weight(int x) { find(x); return diff_weight[x]; }
    T diff(int x, int y) { return weight(y) - weight(x); }
};

int main() {
#if LOCAL&01
    std::ifstream in("./input.txt"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll n,q; cin>>n>>q;
    wuf_tree<ll> wuft(n);
    REP(i,q){
        ll a; cin>>a;
        if(a==0){
            ll x,y,z; cin>>x>>y>>z;
            wuft.unite(x,y,z);
        }else{
            ll x,y; cin>>x>>y;
            if(wuft.is_same(x,y)){
                cout<<wuft.diff(x,y)<<endl;
            }else{
                cout<<"?"<<endl;
            }

        }
    }
    return 0;
}


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


Measured memory_bytes: 2104
#include <stdio.h>

int main(){
	int n,a,b;
	int na = 0;
	int nb = 0;
	scanf("%d %d %d",&n,&a,&b);
	na = n * a;
	nb = b;
	if(na >= nb)
		printf("%d",nb);
	else
		printf("%d",na);

	return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		String s = sc.next();
		
		boolean isYYMM = isYYMM(s);
		boolean isMMYY = isMMYY(s);
		
		if (isYYMM && isMMYY) {
			System.out.println("AMBIGUOUS");
		} else if (isYYMM) {
			System.out.println("YYMM");
		} else if (isMMYY) {
			System.out.println("MMYY");
		} else {
			System.out.println("NA");
		}
	}
	
	private static boolean isYYMM(String date) {
		int year = (date.charAt(0) - '0') * 10 + (date.charAt(1) - '0');
		int month = (date.charAt(2) - '0') * 10 + (date.charAt(3) - '0');
		
		return ((0 <= year) && (year <= 99) && (1 <= month) && (month <=12));
	}
	
	private static boolean isMMYY(String date) {
		int month = (date.charAt(0) - '0') * 10 + (date.charAt(1) - '0');
		int year = (date.charAt(2) - '0') * 10 + (date.charAt(3) - '0');
		
		return ((0 <= year) && (year <= 99) && (1 <= month) && (month <=12));
	}
	static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine()); 
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}


Measured memory_bytes: 22996
import sys
def input(): return sys.stdin.readline().strip()
n=int(input())
ss=[]
for _ in range(n):
    ss.append(''.join(sorted(input())))
import itertools
import math
c = 0
for _, g in itertools.groupby(sorted(ss)):
    lg = len(list(g))
    if lg > 1:
        c += lg * (lg-1) // 2
print(c)

Measured memory_bytes: 11880
# 初期入力
import sys
input = sys.stdin.readline
N,L = (int(x) for x in input().split())
taste =[i for i in range(L,L+N ) ]
decide =taste[0] *taste[-1]
ans =0
if 0 <= decide: #味が、全て正or全て負
    if taste[0] <0:
        ans =sum(taste[:-1])
    else:
        ans =sum(taste[1:])
else: #味が0をまたぐ時は０を引く⇒合計は変わらない
    ans =sum(taste) 
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
/*メモ 
*/
int main(){
    int n;
    std::cin >> n;
    string s;
    rep(i,n)s.pb(i+'1');
    string a,b;
    rep(i,n){
        char d;
        std::cin >> d;
        a.pb(d);
    }
    rep(i,n){
        char d;
        std::cin >> d;
        b.pb(d);
    }   
    int p1,p2;
    int c=0;
    do{
        c++;
        if(s==a)p1=c;
        if(s==b)p2=c;
        //std::cout << s << std::endl;
    }while(next_permutation(all(s)));
    std::cout << abs(p1-p2) << std::endl;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

ll sumofketa(ll a,ll b){
    string s=to_string(a),t=to_string(b);
    return max(s.size(),t.size());
}

int main(void)
{
    ll a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;

    ll ans1=100*a,ans2=0;
    double tmp=0;

    rep(i,31)rep(j,31){
        rep(k,101)rep(l,101){
            double w = 100 * (a * i + b * j);
            double s = c * k + d * l;
            if(w == 0) continue;
            if(w + s > f) break;
            if(s > e * (a * i + b * j) ) break;
            if( (double)s / (w + s)  > tmp ){
                tmp = max(tmp, s/(w+s));
                ans1 = w + s;
                ans2 = s;
            }
        }
    }
    cout << ans1 << " " << ans2 <<endl;
    return 0;
}

Measured memory_bytes: 3632
def get_event(event, ranner, o_cnt):
    s_cnt = 0
    if event == 'HIT':
        s_cnt = ranner.pop(0) # [1 1 0 ] to [1 0 1]
        ranner.append(1)

    elif event == 'HOMERUN':
        s_cnt = sum(ranner) + 1
        ranner = [0, 0, 0]

    elif event == 'OUT':
        o_cnt += 1

    return (s_cnt, o_cnt, ranner) 

while True:
    try:
        Inning = int(input())
          
        for i in range(Inning):
            score = 0
            o_cnt = 0 
            ranner = [0, 0, 0]
        
            while (o_cnt != 3):
                s_cnt, o_cnt, ranner = get_event(raw_input(), ranner, o_cnt)
                score += s_cnt
            print score
    except:
        break


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

using namespace std;
typedef long long ll;

int main() {
	int s;
	cin >> s;
	
	map<int, int> seen;
	int i = 1;
	seen[s] = i;
	i++;
	
	while(true) {
		if(s%2 == 0) {
			s /= 2;
		}
		else {
			s = 3*s + 1;
		}
		
		if(seen.count(s) > 0) {
			cout << i;
			return 0;
		}
		
		seen[s] = i;
		i++;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;


int main()
{
	int n, q, S[100000], T[50000];
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> S[i];
	cin >> q;
	for (int i = 0; i < q; i++)
		cin >> T[i];
	int c = 0, k;
	for (int i = 0; i < q; i++)
	{
		k = T[i];
		int left = 0, right = n, mid = (left + right) / 2;
		while (left < right)
		{
			if (S[mid] == k)
			{
				c++;
				break;
			}
			else if (k > S[mid])
				left = mid + 1;
			else 
				right = mid;
			mid = (left + right) / 2;
		}
	}
	cout << c << endl;
	return 0;
}



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

const int N = 2010;

int mat[N][N];
char s[N];
bool dpl[N][N], dpr[N][N];
/*
 * set1: dpl[i]
 * set2: dpl[j]
 * set3: dpr[i]
 * set4: dpr[j]
 */
std::bitset <N> set1[N], set2[N], set3[N], set4[N];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i < n; ++i) {
        scanf("%s", s);
        for (int j = 0; j < i; ++j) {
            mat[i][j] = s[j] - '0';
            mat[j][i] = 1 - mat[i][j];
        }
    }
    for (int len = 1; len <= n; ++ len){
        for (int i = 0; i < n; ++ i){
            int j = i + len - 1;
            if (j >= n){
                continue;
            }
            if (len == 1){
                dpl[i][j] = dpr[i][j] = true;
            } else{
                if ((set1[i] & set2[j]).any() || ((set1[i] << 1 & set4[j]).any() && mat[i][j])){
                    dpl[i][j] = true;
                }
                if ((set4[j] & set3[i]).any() || ((set4[j] >> 1 & set1[i]).any() && mat[j][i])){
                    dpr[i][j] = true;
                }
            }
            set1[i][j] = set2[j][i] = dpl[i][j];
            set3[i][j] = set4[j][i] = dpr[i][j];
        }
    }
    int cnt = 0;
    for (int i = 0; i < n; ++ i){
        cnt += dpl[i][n - 1] && dpr[0][i];
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 25856
import java.util.Scanner;

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

            int count = 0;
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == '1') {
                    count++;
                }
            }

            System.out.println(count);
        }
    }
}


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

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 1e5 + 100;

int R, C, N;
pi Ps[MAX_N][2];
bool isOn(pi k) {
	if(k.one == 0 || k.one == R) return true;
	if(k.two == 0 || k.two == C) return true;
	return false;
}
int toInt(pi k) {
	if(k.one == 0) return k.two;
	if(k.two == C) return C + k.one;
	if(k.one == R) return C + R + (C - k.two);
	return C + R + C + (R - k.one);
}
int main() {
	cin >> R >> C >> N;
	REP(i, N) REP(j, 2) scanf("%d%d", &Ps[i][j].one, &Ps[i][j].two);
	vector<pi> Ls;
	REP(i, N) {
		if(isOn(Ps[i][0]) & isOn(Ps[i][1])) {
			int x = toInt(Ps[i][0]);
			int y = toInt(Ps[i][1]);
			if(x > y) swap(x, y);
			Ls.push_back(pi(x, y));
		}
	}
	sort(ALL(Ls));
	stack<int> S;
	for(pi &e : Ls) {
		while(!S.empty() && S.top() < e.one) S.pop();
		if(S.empty()) S.push(e.two);
		else {
			if(S.top() < e.two) {
				puts("NO");
				return 0;
			}
			S.push(e.two);
		}
	}
	puts("YES");
	return 0;
}

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

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)


int main() {
    long long n,k;
	cin >> n>>k;
    cout<<((n%k<k-n%k)?n%k:k-n%k);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int l = a+b;
  int r = c+d;
  string ans;
  if(l < r) ans="Right";
  else if(l==r) ans="Balanced";
  else ans="Left";

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll=long long;  
using pLL = std::pair<ll, ll>;

#define SORT(v) std::sort(v.begin(), v.end())
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a,b,ans=0,c,d;
    
    cin >> n >> a >> b;
    for(int i=0;i<n;++i){
        cin >> c >> d;
        if(c>=a&&d>=b) ans++;
    }
    cout << ans << "\n";
    return 0;
}

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

#define int long long int 

int32_t main()
{
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                ans+=__gcd(i,__gcd(j,k));
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3640
import sys
N, K = map(int, input().split())
candi = []
p = 0
for i in range(30, -1, -1):
    if 2**i & K == 0:
        p += 2**i
        continue
    else:
        candi.append(p + 2**i)
candi.append(p)
AB = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0

for c in candi:
    cans = 0
    for a, b in AB:
        if a & c:
            continue
        cans += b
    ans = max(ans, cans)
print(ans)

Measured memory_bytes: 59224
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;

  ll ans = n + 1 - 2;
  for(ll i = 1;i * i <= n;i++){
    if(n % i == 0){
      ans = min(ans,i+n/i-2);
    }
  }


  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

void swap(int *nx, int *ny) {
	int temp = *nx;
	*nx = *ny;
	*ny = temp;
}

void sort3(int *n1, int *n2, int *n3) {
	if (*n1 > *n2) swap(n1, n2);
	if (*n2 > *n3) swap(n2, n3);
	if (*n1 > *n2) swap(n1, n2);
}

int main(void) {
	int A, B, C;

	//int count_A = 0, count_B = 0;


		scanf("%d %d %d", &A, &B, &C);
		//int count_A = 0, count_B = 0;
		
		sort3(&A, &B, &C);



		if (A==5 && B==5 && C==7) {
			printf("YES");
		}
		else {
			printf("NO");
		}
		/*
		if (A == 5 || A == 7)
		{
			if (A == 5) count_A++;
			else  count_B++;

			if (B == 5 || B == 7)
			{
				if (B == 5) count_A++;
				else  count_B++;

				if (C == 5 || C == 7)
				{
					if (C == 5) count_A++;
					else  count_B++;

					if (count_A == 2 && count_B == 1)  printf("Yes");
					else printf("No");
				}
				else printf("No");
			}
			else printf("No");
		}
		else printf("No");
		*/

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main(){

    int n;
    cin >> n;
    vector<int> p(n);

    int m = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> p[i];
        if(m<p[i])
            m = p[i];
    }
    int sum = 0;
    for (auto a : p)
    {
        sum += a;
    }
    sum -= m / 2;

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int t[2][220000];

int main(){
	int n,m;
	int i,j,k;
	int a,b,c,d;
	int s=0;
	vector<int> v1;
	cin>>n;
	for(j=0;j<2;j++){
		for(i=0;i<n;i++){
			cin>>a;
			t[j][i]=a;
		}
	}
	for(i=0;i<=28;i++){
		a=(1<<i+1)-1,d=0;
		v1.clear();
		for(j=0;j<n;j++){
			b=a&t[0][j];
			v1.push_back(b);
			v1.push_back(b+(1<<i+1));
		}
		sort(v1.begin(),v1.end());
		for(j=0;j<n;j++){
			if(t[1][j]&(1<<i)){
				b=(3<<i)-(t[1][j]&a);
				c=(1<<i+2)-(t[1][j]&a);
			}else{
				b=(1<<i)-(t[1][j]&a);
				c=(1<<i+1)-(t[1][j]&a);
			}
			auto itr1=lower_bound(v1.begin(),v1.end(),b),itr2=lower_bound(v1.begin(),v1.end(),c);
			d+=distance(itr1,itr2);
			d%=2;
		}
		if(d%2==1)s+=1<<i;
	}
	cout<<s<<endl;
}

Measured memory_bytes: 3956
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#define N 100009
using namespace std;
const int INF = 0x3f3f3f3f;
char s[N];
int ans[N];
int nx[4] = {1, 1, 0, 0};
int ny[4] = {1, 0, 0, 1};
 
bool check(int a, int b, int n)
{
    ans[0] = a; ans[1] = b;
    for(int i = 1; i < n - 1; i++)
    {
        if(s[i] == 'o')
        {
            if(ans[i]) ans[i + 1] = ans[i - 1];
            else ans[i + 1] = !ans[i - 1];
        }
        else
        {
            if(ans[i]) ans[i + 1] = !ans[i - 1];
            else ans[i + 1] = ans[i - 1];
        }
    }
    if(s[0] == 'o')
    {
        if(ans[0])
        {
            if(ans[1] != ans[n - 1]) return false;
        }
        else if(ans[1] == ans[n - 1]) return false;
    }
    else
    {
        if(ans[0])
        {
            if(ans[1] == ans[n - 1]) return false;
        }
        else if(ans[1] != ans[n - 1]) return false;
    }
    if(s[n - 1] == 'o')
    {
        if(ans[n - 1])
        {
            if(ans[0] != ans[n - 2]) return false;
        }
        else if(ans[0] == ans[n - 2]) return false;
    }
    else
    {
        if(ans[n - 1])
        {
            if(ans[0] == ans[n - 2]) return false;
        }
        else if(ans[0] != ans[n - 2]) return false;
    }
    return true;
}
 
 
int main()
{
    int n;
    scanf("%d %s", &n, s);
    for(int i = 0; i < 4; i++)
    {
        if(check(nx[i], ny[i], n))
        {
            for(int i = 0; i < n; i++)
            {
                if(ans[i]) printf("S");
                else printf("W");
            }
            printf("\n");
            exit(0);
        }
    }
    puts("-1");
    return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int min = Integer.MAX_VALUE;
    for (int i = 0; i < n; i++) {
      int num = s.nextInt();
      int cnt = count(num);
      if (cnt < min) min = cnt;
    }
    System.out.println(min);
  }

  private static int count(int num) {
    int cnt = 0;
    while (num > 0 && num % 2 == 0) {
      num /= 2;
      cnt++;
    }
    return cnt;
  }
}


Measured memory_bytes: 21716
a, b, c = gets.chomp.split.map(&:to_i)
f_c = a % b
i = 2
loop do
  if a * i % b == f_c
    puts 'NO'
    break
  end
  if a * i % b == c
    puts 'YES'
    break
  end
  i += 1
end


Measured memory_bytes: 1788
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const ld PI = acos((ld)-1);

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ld a, b, h, m;
	cin >> a >> b >> h >> m;
	ld ang = (ld)((abs(11 * m - 60 * h)) / 2);
	ld c = sqrtl(sq(b) + sq(a) - 2 * b * a * cos((ld)(ang * (ld)(PI / 180))));
	cout << fixed << setprecision(20) << c << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/



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

using namespace std;

const int N = 200010;

char a[N], b[N];

int main() {
  #ifdef LOCAL
  freopen("sol.in", "r", stdin);
  freopen("sol.out", "w+", stdout);
  #endif
  scanf("%s %s", a, b);
  int n = strlen(a);
  vector<int> char_map(26, -1);
  for (int i = 0; i < n; i++) {
    if (char_map[a[i] - 'a'] == -1) {
      char_map[a[i] - 'a'] = b[i] - 'a';
    } else if (char_map[a[i] - 'a'] != b[i] - 'a') {
      puts("No");
      exit(0);
    }
  }
  fill(char_map.begin(), char_map.end(), -1);
  for (int i = 0; i < n; i++) {
    if (char_map[b[i] - 'a'] == -1) {
      char_map[b[i] - 'a'] = a[i] - 'a';
    } else if (char_map[b[i] - 'a'] != a[i] - 'a') {
      puts("No");
      exit(0);
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 640
N,K = list(map(int,input().split()))
H = list(map(int,input().split()))
inf = float('inf')
dp = [inf]*N
dp[0] = 0
dp[1] = abs(H[1]-H[0])
for i in range(2,N):
    L = min(K,i)
    M = []
    for j in range(1,L+1):
        M.append(dp[i-j]+abs(H[i]-H[i-j]))
    dp[i]=min(M)
print(dp[-1])


Measured memory_bytes: 54752
use std::collections::HashMap;
fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
  (0..n).map(|_| read_vec()).collect()
}

fn main() {
  let n: u32 = read();
  let mut hash = HashMap::new();

  for i in 1..n+1 {
    let pair = pair(i);
    let count = hash.entry(pair).or_insert(0);
    *count += 1;
  }

  let mut ans: u64 = 0;

  for i in 1..n+1 {
    let pair = pair(i);
    let pair_pair = (pair.1, pair.0);
    match hash.get(&pair_pair) {
      Some(count) => ans += *count,
      None => ans += 0
    }
  }

  println!("{}", ans);
}

fn pair(i: u32) -> (u32, u32) {
  let last = i%10;
  let start: u32 = i.to_string().chars().nth(0).unwrap().to_digit(10).unwrap();
  return (start, last);
}

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

int main(){
    ios::sync_with_stdio(false);    cin.tie(NULL);  cout.tie(NULL);
    double l;   cin >> l;
    cout << fixed << setprecision(7) << (l/3.0)*(l/3.0)*(l/3.0);

}


Measured memory_bytes: 256
count = 0


def mizu(h):
    global count
    if len(h) is 0:
        return
    if len(h) is 1:
        count = count + h[0]
        return
    m = min(h)
    count = count + m
    h = [i - m for i in h]
    while 0 in h:
        mizu(h[:h.index(0)])
        h = h[h.index(0)+1:]
    mizu(h)
    return count

if __name__ == "__main__":
    N = int(input())
    h = list(map(int, input().split()))
    mizu(h)
    print(count)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
int x[105];
int n,i;
int min=1000000000,max=-1;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&x[i]);
if(x[i]<min)
min=x[i];
if(x[i]>max)
max=x[i];
}
printf("%d",max-min);
return 0;
}

Measured memory_bytes: 128
import bisect

N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0
for mid in B:
    n_bottom = N - bisect.bisect_right(C,mid)
    n_top = bisect.bisect_left(A,mid)
    ans += n_bottom * n_top

print(ans)

Measured memory_bytes: 23092
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define mk make_pair
#define vec vector<int> 
#define finput ifstream cin;cin.open("in.txt")
#define foutput ofstream cout;cout.open("out.txt") 

int main(){
//	finput;foutput;
	ios_base::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    int x[3];
    x[0]=a;x[1]=b;x[2]=c;
    sort(x,x+3);
    cout<<10*x[2]+x[0]+x[1];
}

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

int main()
{
    int n, q;
    string s;
    cin >> n >> q;
    cin >> s;
    vector<int> acSum(n, 0);
    vector<int> ans;
    int ruiseki = 0;

    for (auto i = 1; i < n; i++)
    {
        if (s[i - 1] == 'A' && s[i] == 'C')
        {
            ruiseki += 1;
        }
        acSum[i] = ruiseki;
    }

    for (auto i = 0; i < q; i++)
    {
        int l, r, sum = 0;
        cin >> l >> r;
        l -= 1;
        r -= 1;

        ans.push_back(acSum[r] - acSum[l]);
    }

    for (auto i = 0; i < q; i++)
    {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 1912
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		TreeSet<Integer> A = new TreeSet<>();
		TreeSet<Integer> Z = new TreeSet<>();

		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'A') {
				A.add(i);
			} else if (s.charAt(i) == 'Z') {
				Z.add(i);
			}
		}
		System.out.println(Z.last() - A.first() + 1);

	}
}

Measured memory_bytes: 36820
///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair <int, int> pii;
#define pb push_back
#define f first
#define s second
#define sz(x) (int)x.size()
char a[305][305], b[305][305];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	cout.tie(0);
	int n, ans = 0;
	bool bu;
	cin >> n;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			cin >> a[i][j];
	for(int k = 0; k < n; k++){
		bu = 0;
		for(int i = 0; i < n; i++)
			for(int j = 0; j < n; j++)
				b[i][j] = a[i][(j + k) % n];
		for(int i = 0; i < n; i++)
			for(int j = 0; j < n; j++)
				if(b[i][j] != b[j][i])
					bu = 1;
		if(!bu){
//			cout << k << endl;
			ans++;
		}
	}
	cout << n * ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main() {
    string s;
    cin >> s;
    
    for (int i=0; i<s.size(); i++) {
        if (i%2) {
            if (s[i] == 'R') {
                cout << "No" << endl;
                return 0;
            }
        }
        else {
            if (s[i] == 'L') {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
}


Measured memory_bytes: 760
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 1e5 + 5;

int n, m;
int color[N];
bool visited[N];
vector<int> g[N];

bool dfs(int v) {
    for (int u : g[v]) {
        if (!visited[u]) {
            visited[u] = true;
            color[u] = !color[v];
            if (!dfs(u)) {
                return false;
            }
        } else if (color[u] == color[v]) {
            return false;
        }
    }
    return true;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    for (int i = 0, x, y; i < m; i++) {
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    visited[1] = true;
    color[1] = 0;
    if (dfs(1)) {
        int b = 0, w = 0;
        for (int i = 1; i <= n; i++) {
            if (!color[i]) {
                b++;
            } else {
                w++;
            }
        }
        cout << b * w - m << '\n';
    } else {
        cout << n * 1LL * (n - 1) / 2 - m << '\n';
    }
    return 0;
}



Measured memory_bytes: 7424
import java.util.Scanner;

public class Main {

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

		int N = sc.nextInt();

		String[] S = new String[N];
		int[] P = new int[N];
		int[] num = new int[N];
		for (int i = 0; i < N; i++) {
			S[i] = sc.next();
			P[i] = sc.nextInt();

			num[i]++;

			for (int j = 0; j < i; j++) {
				if (S[i].compareTo(S[j]) < 0) {
					num[j]++;
				} else if (S[i].compareTo(S[j]) > 0) {
					num[i]++;
				} else if(S[i].equals(S[j])) {
					if (P[i] > P[j]) {
						num[j]++;
					} else {
						num[i]++;
					}
				}
			}
		}

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (num[j] == i + 1) {
					System.out.println(j + 1);
				}
			}
		}
	}
}

Measured memory_bytes: 21716
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define MODNUM (static_cast<int>(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

template <typename T>
int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T>
void chmax(T& m, T x) {
	m = std::max(m, x);
}

template <typename T>
void chmin(T& m, T x) {
	m = std::min(m, x);
}

template <typename T>
T square(T x) {
	return x * x;
}

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int n, k, s;
	scanf("%d %d %d", &n, &k, &s);

	if(k == n) {
		REP(i, n) { printf("%d ", s); }
		putchar('\n');
		return 0;
	}

	REP(i, k) { printf("%d ", s); }
	int x = s == static_cast<int>(1e9) ? (static_cast<int>(1e9) - 1)
									   : static_cast<int>(1e9);
	REP(i, n - k) { printf("%d ", x); }
	putchar('\n');
	return 0;
}

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


int main(){
    long long n;
    cin>>n;
    long long a[n];
    long long c[n]={};
    for(int i=0;i<n;i++){
        cin>>a[i];
        c[a[i]]++;
        if(n%2==0 && a[i]%2==0){
            cout<<0<<endl;
            return 0;
        }
        else if(n%2==1 && a[i]%2==1){
            cout<<0<<endl;
            return 0;
        }
        else if(c[a[i]]>2){
            cout<<0<<endl;
            return 0;
        }
    }

    bool ok=true;

    if(n%2 && c[0]!=1) ok=false;
    if(n%2==0 && c[1]!=2) ok=false;

    if(ok)
    for(int i=2;i<n;i+=2){
        if(n%2 && c[i]!=2){
            ok=false;
            break;
        }
        else if(n%2==0 && c[i+1]!=2){
            ok=false;
            break;
        }
    }

    long long MOD=1000000007;

    long long ans=1;
    for(int i=1;i<=n/2;i++){
        ans=ans*2%MOD;
    }
    if(ok)
    cout<<ans<<endl;

    else cout<<0<<endl;

}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-

# 入力を各変数に格納
N = int(input())

ans = 0
# 10の〇乗は10になるパターン
for i in range(1, 6):
	if N == 10 ** i:
		ans = 10
# 他は各桁を足した合計
if ans == 0:
	# 数値を文字列にして1文字ずつのリストにする
	strN_list = list(str(N))
	# ループして各桁を足した合計を計算
	for strN in strN_list:
		ans += int(strN)
print(ans)

Measured memory_bytes: 2940
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

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

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 998244353;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9; 
const int N = 6e5+5;                                         
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}
int l[N], r[N];

ll dp[N], f[N];

int main () {
	SpeedForce;
	int n, k;
	cin >> n >> k;
	
	dp[1] = 1;
	
	for (int i = 1; i <= k; ++i)
		cin >> l[i] >> r[i];
	for (int i = 1; i <= n; ++i) {
		(f[i] += f[i-1]) %= mod;
		(dp[i] += f[i]) %= mod;
		//cout << i << ' ' << dp[i] << ' ' << f[i] << '\n';;
		for (int it = 1; it <= k; ++it) {
			if(i + l[it] > n) continue;
			
			int st = i + l[it];
			int fn = min(n, i+r[it])+1;
			(f[st] += dp[i]) %= mod;
			(f[fn] += mod-dp[i]) %= mod;		
		}
	}
	
	cout << dp[n] << '\n';
	
	
	return Accepted;
}

// B...a


Measured memory_bytes: 6796
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool stop;
int board[8][8];
int dr[] = {0,1,1,1,0,-1,-1,-1};
int dc[] = {1,1,0,-1,-1,-1,0,1};

struct poc {
	int row;
	int col;
	int count;
	vector<int> dir;
	bool operator<(const poc& right) const {
		if (count == right.count) {
			if (row == right.row) {
				return (col < right.col);
			}
			else {
				return (row < right.row);
			}
		}
		else {
			return (count > right.count);
		}
	}
};

void update_board(int p, poc c) {
	board[c.row][c.col] = p;
	for (int i = 0; i < (c.dir).size(); ++i) {
		int nr = c.row + dr[c.dir[i]];
		int nc = c.col + dc[c.dir[i]];
		bool find = false;
		while (!find) {
			board[nr][nc] = p;
			nr += dr[c.dir[i]];
			nc += dc[c.dir[i]];
			if (board[nr][nc] == p) {
				find = true;
			}
		}
	}
	return;
}

void play_turn(int p) {
	vector<poc> cand;
	for (int i = 0; i < 8; ++i) {
		for (int j = 0; j < 8; ++j) {
			if (board[i][j] == 0) {
				int count = 0;
				vector<int> ds;
				for (int d = 0; d < 8; ++d) {
					int nr = i + dr[d];
					int nc = j + dc[d];
					int rcmin = min(nr,nc);
					int rcmax = max(nr,nc);
					if (rcmax < 8 && rcmin >= 0 && board[nr][nc] == -p) {
						bool find = false; 
						int tc = 0;
						while (!find) {
							if (board[nr][nc] == p) {
								find = true;
								stop = false;
								ds.push_back(d);
								count += tc;
							}
							else if (board[nr][nc] == -p) {
								++tc;
								nr += dr[d];
								nc += dc[d];
								rcmin = min(nr,nc);
								rcmax = max(nr,nc);
								if (rcmax >= 8 || rcmin < 0) {
									find = true;
								}
							}
							else {
								find = true;
							}
						}
					}
				}
				if (ds.size() > 0) {
					cand.push_back({i,j,count,ds});
				}
			}
		}
	}
	if (cand.size() > 0) {
		sort(cand.begin(),cand.end());
		poc prop = cand[0];
		if (p == -1) {
			int max_c = cand[0].count;
			for (int i = 0; i < cand.size() && cand[i].count == max_c; ++i) {
				prop = cand[i];
			}
		}
		update_board(p,prop);
	}
	return;
}

int main(void) {
	for (int i = 0; i < 8; ++i) {
		for (int j = 0; j < 8; ++j) {
			char c; 
			cin >> c;
			if (c == 'x') {
				board[i][j] = -1;
			}
			else if (c == '.') {
				board[i][j] = 0;
			}
			else {
				board[i][j] = 1;
			}
		}
	}

	stop = false;
	while (!stop) {
		stop = true;
		play_turn(1);
		play_turn(-1);
	}

	for (int i = 0; i < 8; ++i) {
		for (int j = 0; j < 8; ++j) {
			if (board[i][j] == -1) {
				cout << "x";
			}
			else if (board[i][j] == 0) {
				cout << ".";
			}
			else {
				cout << "o";
			}
		}
		cout << endl;
	}
	return 0;
}



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

int main(void){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0;i < n;i++)cin >> a[i];
    sort(a,a+n);
    bool check = true;
    for(int i = 1;i < n;i++){
        if(a[i-1] == a[i])check = false;
    }
    if(check == true)cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 1024
MOD = 10**9+7
N = int(input())
S1 = input()
S2 = input()
pre_flag = S1[0] == S2[0]
if pre_flag:
    ans = 3
    i = 1
else:
    ans = 6
    i = 2

while i < N:
    flag = S1[i] == S2[i]
    if flag:
        if pre_flag:
            ans =  (ans * 2) % MOD
        i += 1
        pre_flag = flag
        continue
    if pre_flag:
        ans =  (ans * 2) % MOD
    else:
        ans =  (ans * 3) % MOD
    i += 2
    pre_flag = flag
print(ans)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    int h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    int num = 0;
    vector<vector<int>> graph(h, vector<int>(w, 0));
    REP(i, h) REP(j, w){
        if(i % 2 == 0){
            graph[i][j] = num+1;
        }else{
            graph[i][w-j-1] = num+1;
        }

        a[num]--;
        if(a[num] == 0) num++;
    }

    REP(i, h) REP(j, w) cout << graph[i][j] << " \n"[j == w-1];
}


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

//vector <long long> v[1000000];

//stack <long long> pus, wyn;

long long int  x[1000000], y[1000000], z[1000000], czy=0, w, n, m;
char s[1000000];

int main()
{
    long long int a, b, c, d, k, i, j, q, t, p;

//    q=1;


//    scanf("%lld", &q);
//    for(t=0; t<q; t++)
    {
        scanf("%lld", &n);

        w=0;
        a=0;
        b=0;
        c=0;
        d=0;

        for(i=0; i<n; i++)
        {
            scanf("%s", s);
            if(s[0]=='A')a++;
            if(s[0]=='W')b++;
            if(s[0]=='T')c++;
            if(s[0]=='R')d++;

        }

        printf("AC x %lld\nWA x %lld\nTLE x %lld\nRE x %lld\n", a, b, c ,d);
    }

    return(0);
}


Measured memory_bytes: 3832
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
using pii=pair<int,int>;

#define REP(i,a) for(int i=0;i<a;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rREP(i,a) for(int i=(a)-1;i>=0;i--)
#define rFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define out(S) cout<<(S)<<endl;
#define beginend(v) (v).begin(),(v).end()
#define IfOut(condition,text) if(condition){out(text);return 0;}
#define IfOutElse(condition,if_text,else_text) if(condition){out(if_text);return 0;}else{out(else_text);return 0;}
#define mod(s) ((s)%(ll)(1e9+7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a*modpow((ll)b,(ll)(1e9+5))))
#define pb(i) push_back(i)
#define fst first
#define snd second
#define Foreach(item,collection) for(auto item:collection)
#define INF 1e10
#define removeAll(vec,deleg) auto itr=remove_if(beginend(vec),deleg);vec.erase(itr,vec.end());
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
ll manhattanDistance(ll x1, ll y1, ll x2, ll y2) { return (abs(x2 - x1) + abs(y2 - y1)); }
vector<ll> sieveOfEratosthenes(int max) {ll prime;double sqrtmax = sqrt(max);vector<ll> primeVec, searchVec;FOR(i, 2, max + 1) searchVec.push_back(i);do{prime = searchVec[0];primeVec.push_back(prime);auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; });searchVec.erase(itr, searchVec.end());} while (prime < sqrtmax);primeVec.reserve(primeVec.size() + searchVec.size());primeVec.insert(primeVec.end(), beginend(searchVec));return primeVec;}
ll sum(vi v) {ll sum=0;Foreach(i,v){sum+=i;}return sum;}
#define ShowAll(v) Foreach(i,v) out(i);

void solve(){
    int N;
    vi ans;
    while (cin>>N,N)
    {
        vi a(N);
        REP(i,N){
            cin>>a[i];
        }
        sort(beginend(a));
        ll s=sum(a);
        s-=a.front();
        s-=*--a.end();
        ans.pb(s/(N-2));
    }
    Foreach(i,ans) out(i);
}

int main(){


    solve();
    return 0;
}

Measured memory_bytes: 3044
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=1000000007;
const long double PI=3.14159265358979;

vector<pair<long long,int>> f(long long N){
  vector<pair<long long ,int>> ans(1,{0,0});
  long long n=N;
  for(int i=2;i<sqrt(n);i++){
    if(N%i==0){
      N/=i;
      if(ans.at(ans.size()-1).first==i){
        ans.at(ans.size()-1).second++;
      }
      else{
        ans.push_back({i,1});
      }
      i--;
    }
    if(N==1){
      break;
    }
  }
  if(N!=1){
    ans.push_back({N,1});
  }
  auto itr1=ans.begin();
  ans.erase(itr1);
  return ans;
}


int main() {
  ll N;
  cin>>N;
  while(1){
    if(f(N)[0].first==N){
      cout<<N;
      break;
    }
    N++;
  }
}

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

int main(){

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

    //Need[i][j] := i日目から連続して励まされていて、j日目に必要な励まし力
    vector<vector<int> > Need(n, vector<int> (n, -1));  

    for(int i = 0; i < n; i++){
        int t = 0;
        for(int j = i; j < n; j++){
            int now_x = max(0, X[j] - t);
            t = max(0, Y[j] - now_x);
            Need[i][j] = t;
            //cout << t << " ";
        }
        //cout << endl;
    }

    //dp[i][j][k] := いままでj日学校行くことができている,k日連続で励まされている
    int dp[110][110][110];
    //dp初期化
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            for(int k = 0; k <= n; k++){
                dp[i][j][k] = -1;
            }
        }
    }
    dp[0][0][0] = p;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k <= i; k++){

            //cout << i << " " << j << " " << k << " " << dp[2][0][0] << endl;
            //行かない
            dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]);
            /*if(j==0 && k==0){
                cout << i << " " << j << " " << k << " " << dp[i][j][k] << " " << dp[i + 1][j][k] << endl;
            }*/
            //行く
            int need = Need[i - k][i];
            if(need == 0) dp[i + 1][j + 1][0] = max(dp[i + 1][j + 1][0], dp[i][j][k]);
            else dp[i + 1][j + 1][k + 1] = max(dp[i + 1][j + 1][k + 1], dp[i][j][k] - need);
            }
        }
    }

    int ans = 0;
    for(int j = 0; j <= n; j++){
        for(int k = 0; k <= n; k++){
            if(dp[n][j][k] >= 0) ans = max(ans, j);
        }
    }

    /*for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            for(int k = 0; k <= n; k++){
                cout << dp[i][j][k] << " ";
            }
            cout << endl;
        }
        cout << endl;
    }*/


    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7968
#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long LL;

int main(){
  string t_A;
  cin >> t_A;
  vector<int> A(t_A.size());
  vector<vector<int> >alpha;
  for(int i=0;i<26;i++){
	vector<int> tmp;
	alpha.push_back(tmp);
  }

  const char* cstr = t_A.c_str();
  
  for(int i=0;i<A.size();i++){
	A[i]=(int)cstr[i]-'a';
	alpha[A[i]].push_back(i);
  }
  
  LL ans=(A.size()-1)*(A.size())/2+1;

  for(int i=0;i<alpha.size();i++){
	ans-=alpha[i].size()*(alpha[i].size()-1)/2;
  }
  
  cout << ans <<endl;

  return 0;
}

Measured memory_bytes: 2680