akhauriyash/Code-Regression huggingface dataset:
#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);
        a.at(i)--;
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        if(a.at(a.at(i))==i) ans++;
    }
    cout << ans / 2 << endl;

}

Measured memory_bytes: 3768
N, Y = map(int, input().split() )
for i in range(N + 1):#価値が最大の10000円札の数を軸に条件判定
  for j in range(N - i + 1):#1週目のループでは1万円さつを用いない組み合わせを判定
    if 10000 * i + 5000 * j + 1000 * (N - i - j) == Y:
    	print(i, j, N - i - j) 
    	exit()
print(-1, -1, -1) 

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  ll N;
  cin >> N;
  cout << (N*(N-1))/2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {

    int N; cin >> N;

    if (N % 10 == 9 || N /10 == 9) {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

count4 = 0
count2 = 0
count0 = 0
for i in a:
    if i % 2 == 0:
        if i % 4 == 0:
            count4 += 1
        else:
            count2 += 1
    else:
        count0 += 1

if count0 <= count4:
    print ('Yes')
elif count0 == count4 + 1 and count2 == 0:
    print ('Yes')
else:
    print ('No')

Measured memory_bytes: 15020
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define i_inf int(1e9)
#define i_half_inf int(1e5)
#define ll_inf ll(1e9)*ll(1e9)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main() {
    string S;
    cin >> S;
    int ans = i_inf;
    rep(i, S.size() - 2) {
        string temp = "";
        temp += S[i];
        temp += S[i + 1];
        temp += S[i + 2];
        ans = min(ans, abs(753 - stoi(temp)));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeSet;

import static java.util.Arrays.binarySearch;
import static java.util.Arrays.copyOfRange;

public class Main {

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;

        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }
}

class Task {

    private static int mod = 1000000007;


    public void solve(int testNumber, InputReader in, PrintWriter out) {
        double n = in.nextDouble();
        out.println(n * n * n / 27);

    }



}

class InputReader {

    private final BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(nextLine());
        }
        return tokenizer.nextToken();
    }

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

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

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

}


Measured memory_bytes: 21460
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.replace(/\n$/,"")).split("\n");
while(true){
   var n=Arr.shift()-0;
   if(n==0)break;
   var str="";
   for(var i=0;i<n;i++)str+=Arr.shift()+" ";
   var arr=(str.trim()).split(" ");
   var s=Arr.shift();
   var f=arr.filter(function(v){return v[0]==s;});
   f.sort();
   var F=[];
   var memo="";
   for(var i=0;i<f.length;i++){
      if(memo==f[i]){
         F[F.length-1]=[f[i],F[F.length-1][1]+1];
      }
      else {
         F.push([f[i],1]);
         memo=f[i];
      }
   }
   F.sort(function(a,b){
      if(a[1]==b[1])return a[0]>b[0];
      else return b[1]-a[1];
   });
   var ans=[];
   for(var i=0;i<5;i++){
      if(F.length>i)ans.push(F[i][0]);
   }
   console.log((ans.length>0)?ans.join(" "):"NA");
}

Measured memory_bytes: 12000
from itertools import product

N = int(input())

S = str(N)
n = len(S)

ans = 0
for i in range(3, n + 1):
    for p in product(['3', '5', '7'], repeat=i):
        x = int(''.join(p))
        if x <= N and len(set(p) & {'3', '5', '7'}) == 3:
            ans += 1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#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 all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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;}
int const INF = 1001001001;


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

int N,M;
cin >> N >> M;

int P = M/N;
int ans = 1;
for(int i = 1; i*i <= M; ++i) {
    if(M % i == 0) {
        if(i <= P) chmax(ans,i);
        if(M/i <= P) chmax(ans, M/i);
    }
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
using ll = long long;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
using namespace std;

int main(){
  ll n, m;
  cin >> n >> m;
  ll mx = m / n;
  ll ans;
  repr(i, mx+1){
    if (m % i == 0){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  
  return 0;
}

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

int main(){
   int n[6];
   for(int i=0;i<6;i++)cin >> n[i];
   int bu[5] = {0};
   for(int i=0;i<6;i++){
      bu[n[i]]++;
   }
   sort(bu,bu+5);
   if(bu[1] == 1 && bu[2] == 1 && bu[3] == 2 && bu[4] == 2){
      cout << "YES";
   }else{
      cout << "NO";
   }
   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MIN(x,y) ((x)<(y)?(x):(y))

int main(){
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  if((a&b&c&1)==0) puts("0");
  else {
    printf("%lld\n", MIN((long long) a*b, MIN((long long) b*c, (long long) a*c)));
  }
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] ABC = sc.nextLine().split(" ");

        int A = Integer.parseInt(ABC[0]);
        int B = Integer.parseInt(ABC[1]);
        int C = Integer.parseInt(ABC[2]);

        boolean isPossible = false;
        for (int i = 0; i < 100; i++) {
            if (i * A % B == C) {
                isPossible = true;
            }
        }

        System.out.println(isPossible ? "YES" : "NO");
    }
}


Measured memory_bytes: 21844
($N,$A,$B)=glob<>;
for(<>=~/./g){
	if(/a/){
		print$a+$b<$A+$B?(!++$a,'Yes'):'No',$/
	}elsif(/b/){
		print$a+$b<$A+$B&&$b<$B?(!++$b,'Yes'):'No',$/
	}else{
		print'No',$/
	}
}

Measured memory_bytes: 9856
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
	int A,B;

	cin >> A >> B;

	cout << 6 - A - B;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    char c; cin >> c;
    cout << (char)(c + 1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
	int n,k,x,y;
	cin>>n>>k>>x>>y;
	if(n<=k)cout<<n*x<<endl;
	else cout<<k*x+(n-k)*y<<endl;
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, u, v int
	fmt.Scan(&n, &u, &v)
	u--
	v--

	g := make([][]int, n)
	var a, b int
	for i := 0; i < n-1; i++ {
		fmt.Scan(&a, &b)
		a--
		b--
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}

	us := calc(g, u)
	vs := calc(g, v)

	ans := 0
	for i := 0; i < n; i++ {
		if us[i] < vs[i] {
			ans = max(ans, vs[i]-1)
		}
	}
	fmt.Println(ans)
}

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

func calc(g [][]int, v int) []int {
	n := len(g)
	ds := make([]int, n)
	for i := 0; i < n; i++ {
		ds[i] = -1
	}
	ds[v] = 0

	var dfs func(v, p int)
	dfs = func(v, p int) {
		for _, u := range g[v] {
			if ds[u] == -1 {
				ds[u] = ds[v] + 1
				dfs(u, v)
			}
		}
	}
	dfs(v, -1)

	return ds
}


Measured memory_bytes: 24444
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s=="Sunny")
    cout<<"Cloudy"<<endl;
  else if(s=="Cloudy")
    cout<<"Rainy"<<endl;
  else if(s=="Rainy")
    cout<<"Sunny"<<endl;
}


Measured memory_bytes: 256
using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 50010
int gcd(int a,int b){
	while (b){
		int k=a%b;
		a=b,b=k;
	}
	return a;
}
int n,m,p;
struct EDGE{
	int to,c;
	EDGE *las;
} e[N*2];
int ne;
EDGE *last[N];
void link(int u,int v,int c){
	e[ne]=(EDGE){v,c,last[u]};
	last[u]=e+ne++;
}
int g,d,z;
int pz[2][1000010];
struct Dsu{
	Dsu *p;
	Dsu *getfa(){return p==this?p:p=p->getfa();}
} *f[N][2][3];
bool check(int S,int T,int R){
	for (int j=0;j<2;++j)
		for (int k=0;k<3;++k){
			int t=((z+R-k*g)%d+d)%d;
			if (pz[j][t] && f[T][0][0]->getfa()==f[S][j][k]->getfa())
				return 1;			
		}
	return 0;
}
int main(){
	int Q;
	scanf("%d%d%d%d",&n,&m,&Q,&p);
	for (int i=1;i<=m;++i){
		int u,v,c;
		scanf("%d%d%d",&u,&v,&c);
		link(u,v,c),link(v,u,c);
	}
	g=p;
	for (int i=1;i<=n;++i){
		int c1=last[i]->c;
		for (EDGE *ei=last[i]->las;ei;ei=ei->las)
			g=gcd(g,gcd((c1-ei->c+p)%p,(ei->c-c1+p)%p));
	}
	d=gcd(3*g,p);
	z=last[1]->c%g;
	for (int i=1;i<=n;++i)
		for (EDGE *ei=last[i]->las;ei;ei=ei->las)
			ei->c-=z;
	for (int i=1;i<=n;++i)
		for (int j=0;j<2;++j)
			for (int k=0;k<3;++k){
				f[i][j][k]=new Dsu;
				f[i][j][k]->p=f[i][j][k];
			}
	pz[0][z]=1;
	pz[1][z*2%d]=1;
	if (z){
		for (int x=z*4%d;x!=z;x=x*4%d)
			pz[0][x]=1;
		for (int x=z*8%d;x!=z*2%d;x=x*4%d)
			pz[1][x]=1;
	}
	for (int i=1;i<=n;++i)
		for (int j=0;j<2;++j)
			for (int k=0;k<3;++k)
				for (EDGE *ei=last[i];ei;ei=ei->las){
					int j_=(j+1)%2,k_=(k*2+ei->c/g)%(d/g);
					f[ei->to][j_][k_]->getfa()->p=f[i][j][k]->getfa();
				}
	while (Q--){
		int S,T,R;
		scanf("%d%d%d",&S,&T,&R);
		if (check(S,T,R))
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}


















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

int main(){
  int a,b;
  cin>>a>>b;

  if(b<0){
    if((b-a)%2==0)cout<<"Negative"<<endl;
    else cout<<"Positive"<<endl;
  }else if(a>0)cout<<"Positive"<<endl;
  else cout<<"Zero"<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int x;
	for (int i = 1;; i++) {
		cin >> x;
		if (x == 0) {
			break;
		}
		else
		{
			cout << "Case" <<" "<< i << ":" <<" "<< x << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3052
import java.util.Scanner;
public class Main {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        if( C <= (A+B)){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
    
}


Measured memory_bytes: 22868
import java.util.Scanner;

public class Main {

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

        int N  = sc.nextInt();

        int seqCount = 0;
        int maxSeq = 0;
        for (int i = 0; i < N; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();

            if(a==b){
                seqCount++;
            }else{
                seqCount=0;
            }

            maxSeq = Math.max(seqCount,maxSeq);


        }

        if(maxSeq >=3){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }

}


Measured memory_bytes: 35952
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

long long int func(string s, string t, int to) {
	long long int ret = 0;
	vector<vector<long long int>>sum(s.size() + 1, vector<long long int>(3));
	vector<vector<long long int>>num(s.size() + 1, vector<long long int>(3));
	num[0][2] = 1;
	for (int i = 0; i < s.size(); i++) {
		for (int j = 0; j < 3; j++) {
			if (i + t.size() <= s.size()) {
				if (j == 0) {
					sum[i + t.size()][0] += num[i][j];
					sum[i + t.size()][0] %= MOD;
				}
				else if (j == 1) {
					if (s.substr(i, t.size()) > t) {
						sum[i + t.size()][0] += num[i][j];
						sum[i + t.size()][0] %= MOD;
					}
					else if (s.substr(i, t.size()) == t) {
						sum[i + t.size()][1] += num[i][j];
						sum[i + t.size()][1] %= MOD;
					}
				}
				else {
					if (t != "0") {
						if (i == 0) {
							if (s.substr(i, t.size()) > t) {
								sum[i + t.size()][0] += num[i][j];
								sum[i + t.size()][0] %= MOD;
							}
							else if (s.substr(i, t.size()) == t) {
								sum[i + t.size()][1] += num[i][j];
								sum[i + t.size()][1] %= MOD;
							}
						}
						else {
							sum[i + t.size()][0] += num[i][j];
							sum[i + t.size()][0] %= MOD;
						}
					}
				}
			}
			for (int k = '0'; k <= '9'; k++) {
				if (j == 1 && s[i] < k)continue;
				if (i == 0 && j == 2 && s[i] < k)continue;
				if (j <= 1) {
					num[i + 1][j && (s[i] == k)] += num[i][j];
					num[i + 1][j && (s[i] == k)] %= MOD;
					sum[i + 1][j && (s[i] == k)] += sum[i][j];
					sum[i + 1][j && (s[i] == k)] %= MOD;
				}
				else {
					if (k == '0') {
						num[i + 1][2] += num[i][j];
						num[i + 1][2] %= MOD;
						sum[i + 1][2] += sum[i][j];
						sum[i + 1][2] %= MOD;
					}
					else {
						if (i == 0) {
							num[i + 1][(s[i] == k)] += num[i][j];
							num[i + 1][(s[i] == k)] %= MOD;
							sum[i + 1][(s[i] == k)] += sum[i][j];
							sum[i + 1][(s[i] == k)] %= MOD;
						}
						else {
							num[i + 1][0] += num[i][j];
							num[i + 1][0] %= MOD;
							sum[i + 1][0] += sum[i][j];
							sum[i + 1][0] %= MOD;
						}
					}
				}
			}
		}
	}
	for (int i = 0; i <= to; i++) {
		ret += sum.back()[i];
	}
	ret %= MOD;
	return ret;
}

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

	string a, b, c;
	cin >> a >> b >> c;
	long long int ans = func(b, c, 1) + MOD - func(a, c, 0);
	if (a == "0"&&c == "0")ans++;
	cout << ans % MOD << endl;
}


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

using namespace std;

#define MOD 998244353

int N;
int occurences[100005];
int maxDist, nPrev;
long long ans;

long long fastExp(long long base, int power)
{
    if (power == 0) return 1;
    long long cur = fastExp(base, power / 2);
    cur = cur * cur % MOD;
    if (power % 2 == 1) cur *= base;
    return cur % MOD;
}

int main()
{
    scanf("%d", &N);
    maxDist = 0;
    for (int i = 0; i < N; i++)
    {
        int D; scanf("%d", &D);
        if (i == 0 && D != 0)
        {
            printf("0\n");
            return 0;
        }
        maxDist = max(maxDist, D);
        occurences[D]++;
    }
    if (occurences[0] != 1)
    {
        printf("0\n");
        return 0;
    }

    nPrev = occurences[1];
    ans = 1;
    for (int i = 2; i <= maxDist; i++)
    {
        ans *= fastExp(nPrev, occurences[i]);
        ans %= MOD;
        nPrev = occurences[i];
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
  
int gcd(int x,int y){
  if(x<y){
    int tmp = x; x = y; y = tmp;
  }
  while(y>0){
    int r=x%y;
    x=y;
    y=r;
  }
  return x;
}
  
int main(){
  int x,y,z;
  scanf("%d%d",&x,&y);
  printf("%d\n",gcd(x,y));
  
  return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

void solve() {

}

int n, k;
ll r, p, s;
string t;
bool won[MAX_N];

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

    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;

    ll ans = 0LL;

    for (int i = 0; i < n; i++) {
        if (i+1 < k) {
            won[i] = true;
            if (t[i] == 'r') {
                ans += p;
            } else if (t[i] == 's') {
                ans += r;
            } else {
                ans += s;
            }
            continue;
        }
        if (t[i-k] == t[i] && won[i-k]) {
            continue;
        }
        won[i] = true;
        if (t[i] == 'r') {
            ans += p;
        } else if (t[i] == 's') {
            ans += r;
        } else {
            ans += s;
        }
    }

    cout << ans;





    return 0;
}


Measured memory_bytes: 592
N = int(input())

r = []
for i in range(N):
    S, P = input().split()
    P = int(P)
    r.append((i+1,S,P))

r.sort(key=lambda x:x[2], reverse=True)
r.sort(key=lambda x:x[1])
for x in r:
    print(x[0])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
template<class T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
 /* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)*/
template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹) */
///////////////////////////////////////////////
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 



int main() {
	ll N,K; cin >> N >> K;
ll MOD = 1000000007; 
	vector<ll> A;
	for (int i = 0; i < N; i++)
	{
		ll a; cin >> a;
		A.PB(a);
	}
	
	ll c = 0;//Aの中での転倒数
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			if(j>i and A[i]>A[j]){c++; c = c % MOD;
			}
		}
	}
	ll d = 0;//Aの外での転倒数
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			if(A[i]>A[j] and i != j){d++; d = d % MOD;
			}
		}
	}
	K = K % MOD;
ll ans = (K * c) % MOD + ((d % MOD) * (((K * (K-1)) / 2) % MOD) % MOD);	ans = ans % MOD;
	cout << ans << endl;
	}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll         long long int 
#define pb         push_back
#define umap       unordered_map
#define mod        1000000007
#define all(x)     (x).begin(), (x).end()
#define MN(a,b,c)  min(a,min(b,c))
#define pr         pair<ll,ll>
#define F          first
#define S          second
#define mP         make_pair
#define f(i,n)     for(int i=0;i<n;i++)
#define f1(i,x,y)  for(int i=x;i<=y;i++)
#define f2(i,x,y)  for(int i=x;i>=y;i--)
//__builtin_popcount(x)
//__builtin_parity(x)   =(number of set bits)%2
//__builtin_clz(x)      to count the number of leading  zeroes 
//__builtin_ctz(x)      to count the number of trailing zeroes 
//__gcd(a,b)
using namespace std;
int main()
{
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
 int n,k;cin>>n>>k;
 vector <int> dp(k+1,-1);
 vector <int> a(n);
 f(i,n){cin>>a[i];dp[a[i]]=1;}
 // dp[x]=1 means Taro would win when k==x
 for(int i=1;i<=k;i++)
 {
    if(dp[i]==-1)
    {dp[i]=0;
    f(j,n)
    {
      if(a[j]>i)break;
      else
      {
        if(dp[i-a[j]]==0)
          {dp[i]=1;break;}
      }
    }
    }
 }
 if(dp[k]==1)
   cout<<"First"<<"\n";
 else 
   cout<<"Second"<<"\n";
}

Measured memory_bytes: 3732
N = int(input())
food = list(map(int,input().split()))
val = list(map(int,input().split()))
bonas = list(map(int,input().split()))

ans = 0

for i in range(N):
  ans += val[food[i]-1]
  
for i in range(N-1):
  if food[i]+1==food[i+1]:
    ans += bonas[food[i]-1]
    
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FL          freopen("in", "r", stdin),freopen("out", "w", stdout);
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 2 * 1e5 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
//int dx[] = {1, 0}, dy[] = {0, 1};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
ll v[12];
int main(){
    //FL;
    FIN;
    ll n;
    cin >> n;
    string ans = "";
    while(n > 0){
        n--;
        ans = char('a' + n % 26) + ans;
        n /= 26;
    }
    cout << ans << '\n';
    EjecuteTime;
    return 0;
}       


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

int main() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans = b-a+1;
    ll e = c/gcd(c,d)*d;
    ans -= b/c-(a-1)/c+b/d-(a-1)/d-(b/e-(a-1)/e);
    cout << ans << endl;
}

Measured memory_bytes: 3584
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50

def run():
    n = int(sysread())
    A = list(map(int, sysread().split()))
    #print(A)
    A = sorted(A)
    #print(n, A)
    idx = bisect.bisect_left(A, A[-1] / 2)
    if idx == 0:
        print(f'{A[-1]} {A[0]}')
    elif idx == n-1:
        print(f'{A[-1]} {A[-2]}')
    else:
        val1 = A[idx]
        val2 = A[idx-1]
        if abs(val1 - A[-1] / 2) > abs(val2 - A[-1] / 2):
            print(f'{A[-1]} {val2}')
        else:
            print(f'{A[-1]} {val1}')


if __name__ == "__main__":
    run()

Measured memory_bytes: 18856
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    ll n = s.size();
    ll m = n/2;

    ll ans = 0;
    rep(i, m) {
        if(s[i] != s[n-1-i]) {
            ans++;
        }
    }
    
    out(ans);
    re0;
}

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

using namespace std;

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

  int n, m, q;
  scanf("%d %d %d", &n, &m, &q);
  vector<vector<int>> trains(n, vector<int>(n + 1, 0));

  int l, r;
  for (int i = 0; i < m; ++i) {
    scanf("%d %d", &l, &r);
    trains[--l][--r]++;
  }

  for (int i = 0; i < n; ++i) {
    for (int j = n - 1; 0 < j; --j) {
      trains[j - 1][i] += trains[j][i];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j <= n; ++j) {
      trains[i][j] += trains[i][j - 1];
    }
  }

  int p, t;
  for (int i = 0; i < q; ++i) {
    scanf("%d %d", &p, &t);
    printf("%d\n", trains[--p][--t]);
  }
}


Measured memory_bytes: 1920
#include <iostream>
using namespace std;
int main(void){
    int n, a, b, total_a, total_b;
    while(1){
        cin >> n;
        if(n == 0){
            break;
        }
        total_a = 0;
        total_b = 0;
        for(int i=1; i<=n; i++){
            cin >> a >> b;
            if(a > b){
                total_a += a + b;
            }
            else if(b > a){
                total_b += a + b;
            }
            else{
                total_a += a;
                total_b += b;
            }
        }
        cout << total_a << " " << total_b << endl;
    }
    return 0;
    
}



Measured memory_bytes: 3084
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
using namespace std;

int n,pos;
double t,a,A[2020],tmp;

int main()
{
  scanf("%d%lf%lf",&n,&t,&a);
  for(int i=1; i<=n; ++i)
  {
    scanf("%lf",&A[i]);
    A[i]=t-A[i]*0.006;
  }
  tmp=fabs(A[1]-a);
  pos=1;
  for(int i=2; i<=n; ++i)
    if(fabs(A[i]-a) <tmp)
      tmp = fabs(A[i]-a),pos=i;
  printf("%d\n",pos);
  return 0;
}

Measured memory_bytes: 256
from collections import deque

h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]

q = deque()

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            q.append((i, j, 0)) 

while q:
    y, x, d = q.popleft()
    if a[y][x] == '#':
        for xdx, ydy in zip((x, x, x+1, x-1), (y+1, y-1, y, y)):
            if (0 <= xdx < w) and (0 <= ydy < h):
                if a[ydy][xdx] == '.':
                    a[ydy][xdx] = '#'
                    q.append((ydy, xdx, d+1))
print(d)

Measured memory_bytes: 216552
from math import factorial

n, m = [int(i) for i in input().split()]
mod = 10 ** 9 + 7

ans = 0
diff = abs(n - m)
if diff == 0:
    ans = (factorial(n) * factorial(m) * 2) % mod
elif diff == 1:
    ans = factorial(n) * factorial(m) % mod
print(ans)


Measured memory_bytes: 5176
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  int n;
  cin>>n;
  vector<ll> l(n);
  for (int i = 0; i < n; ++i)
  {
    cin>>l[i];
  }
  int cnt=0;
  for (int i = 0; i < n; ++i)
  {
    for (int j = i+1; j < n; ++j)
    {
      for (int k = j+1; k < n; ++k)
      {
        if(l[i]+l[j]>l[k]&&
          l[j]+l[k]>l[i]&&
          l[k]+l[i]>l[j]&&
          l[i]!=l[j]&&
          l[j]!=l[k]&&
          l[k]!=l[i]) 
          {cnt++;
      }
      }
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3628
package main

import "fmt"

func main() {
	var o, e string
	fmt.Scan(&o, &e)

	var ans string
	for i := 0; i < len(o); i++ {
		if i == len(o)-1 && len(e)-1 < i {
			ans += string(o[i])
		} else {
			ans += string(o[i]) + string(e[i])
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << " \n"[i==(int)v.size()-1]
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 500050;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e18 + 1;
constexpr int INF = 1e9 + 1;
//int dx[4] = { 0,0,-1,1 }, dy[4] = { 1,-1,0,0 };

bool hi[100], lo[100];
void solve() {
	int N; cin >> N;
	vector<int>A(N);
	REP(i, N) {
		cin >> A[i];
	}
	REP(i, N) {
		if (i == N - 1) {
			hi[i] = true;
			lo[i] = false;
		}
		else {
			if (A[i + 1] > A[i])lo[i] = true;
			else if (A[i + 1] < A[i])hi[i] = true;
		}
	}
	int now = 1000;
	int k = 0;
	REP(i, N) {
		if (lo[i]) {
			k += now / A[i];
			now -= (now / A[i])*A[i];
		}
		else if (hi[i]) {
			now += A[i] * k;
			k = 0;
		}
	}
	print(now);
}



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;
	//cin >> q;
	//while (q--)
	solve();

}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)

signed main(){
  int A,B,ans=0;
  cin>>A>>B;
  if(A+B>=24)ans=A+B-24;
  else ans=A+B;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3640
#include <iostream>

int main(int argc, const char * argv[]) {
    int a, b, c;
    char op;
    for ( ; std::cin >> a >> op >> b && op != '?'; ) {
        switch (op)
        {
        case '+' : c = a + b; break;
        case '-' : c = a - b; break;
        case '*' : c = a * b; break;
        case '/' : c = a / b; break;
        default: continue;
        }
        std::cout << c << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
ll gcd(ll a,ll b)
{
   return b?gcd(b,a%b):a; 
}
main(){
    ll n,a,b,ans=1,MOD=mod-1;
    cin>>n;
    map<pair<ll,ll>,pair<ll,ll>>m;
    for(ll i=0;i<n;i++){
        cin>>a>>b;
        if(!a&&!b) MOD++;
        else{
            ll g=gcd(a,b);
            a/=g,b/=g;
            if(b<0) a=-a,b=-b;
            if(a<=0) m[{b,-a}].second++;
            else m[{a,b}].first++;
        }
    }
    for(auto u:m) ans=ans*(power(2,u.second.first)+power(2,u.second.second)-1+mod)%mod;
    cout<<(ans+MOD)%mod;
}


Measured memory_bytes: 19236
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<unordered_map>
#include<string.h>
#include<math.h>
using namespace std;
using ll = long long;
const int MAX = 5100000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    ll X, Y, Z;
    cin >> X >> Y;
    if((X + Y) % 3 == 0)Z = (X + Y) / 3;
    else {cout << 0;return 0;}
    ll ii, jj;
    bool aaa = false;
    for(ll i = 0;i <= Z;i++)
    {
        if(i * 1 + (Z-i) * 2 == X && (Z-i) * 1 + i * 2 == Y){ii = i;jj = Z-i;aaa = true;}
    }
    if(aaa == false){cout << 0;return 0;}
    ll r = min({ii, jj});
    COMinit();
    cout << COM(ii + jj, r);
}



Measured memory_bytes: 119808
#!/usr/bin/env python3
from collections import deque
import sys
try:
    from typing import Deque, List
except ImportError:
    pass


def solve(K: int):
    pars = list(range(K))

    def union(a: int, b: int):
        pars[a] = b

    def getpar(a: int):
        if pars[a] == a:
            return a
        pars[a] = getpar(pars[a])
        return pars[a]

    for i in range(K):
        union(getpar(i), getpar(i * 10 % K))

    gs = [getpar(i) for i in range(K)]
    if gs[0] == gs[1]:
        print(1)
        return
    G = [[] for i in range(K)]  # type: List[List[int]]
    for i in range(K):
        G[gs[i]].append(gs[(i + 1) % K])
    d = {gs[1]: 1}
    q = deque()  # type: Deque[int]
    q.append(gs[1])
    while q:
        s = q.popleft()
        for t in G[s]:
            if t in d:
                continue
            d[t] = d[s] + 1
            if t == gs[0]:
                print(d[t])
                return
            q.append(t)
    assert False


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 16244
n, m = map(int, input().split())
ab = []
for i in range(m):
    ai, bi = map(int, input().split())
    ab.append([ai, bi])

def check_1(ab_lists):
    while True:
        if len(ab_lists) == 1:
            if len(ab_lists[0]) == n:
                return True
            else:
                return False
        if len(ab_lists) == 2 and len(ab_lists[0]) + len(ab_lists[1]) == len(set(ab_lists[0] + ab_lists[1])):
            return False
        for i in range(len(ab_lists)):
            flag = 0
            for j in range(i+1, len(ab_lists)):
                if len(ab_lists[i]) + len(ab_lists[j]) != len(set(ab_lists[i] + ab_lists[j])):
                    ab_lists[i] = list(set(ab_lists[i] + ab_lists[j]))
                    flag = 1
                    break
            if flag == 1:
                ab_lists.pop(j)
                break

res = 0
for i in range(m):
    ab_lists = ab[:i] + ab[i+1:]
    ret = check_1(ab_lists)
    if not ret:
        res += 1
print(res)

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

using namespace std;

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

    int n, k;
    cin >> n >> k;
    if (k > (n - 1) * (n - 2) / 2)
        return cout << "-1\n", 0;

    int cnt = n * (n - 1) / 2 - k;
    cout << cnt << '\n';
    for (int i = 1; i <= n && cnt > 0; i++)
        for (int j = i + 1; j <= n && cnt > 0; j++, cnt--)
            cout << i << ' ' << j << '\n';

    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>; 

int main() {
    ll N, M;
    cin >> N >> M;
    vl k(M);
    vll s(M);
    rep(i, M){
        cin >> k[i];
        rep(j, k[i]){
            ll t;
            cin >> t;
            s[i].push_back(t);
        }
    }
    vl p(M);
    rep(i, M) cin >> p[i];

    ll ans = 0;
    rep(bit, 1<<N){
        bool ok = false;
        vl pp = p;
        rep(i, N){
            if(bit & (1<<i)){
                rep(j, M){
                    rep(l, k[j]){
                        if(i+1 == s[j][l]){
                            pp[j] = !pp[j];
                            break;
                        }
                    }                    
                }

            }
        }
        rep(m, M){
            if(pp[m] == 0){
                ok = true;
            }else{
                ok = false;
                break;
            }
        }
        if(ok) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    string S;
    cin >> S;
    ll N = S.size();
    vector<ll> jg;
    for(int i=1;i<N;i++){
        if(S[i]!=S[i-1]) {
            jg.push_back(i);
        }
    }
    int nct=0,ct=0;
    bool right=true;
    vector<ll> ans(N,0);
    for(int i=0;i<N;i++){
        if(i==jg[ct]){
            ct++;
            if(ct%2==0){
                nct=ct;
            }
        }
        if(right){
            if(llabs(i-jg[nct])%2==0){
                ans[jg[nct]]++;
            }
            else ans[jg[nct]-1]++;
        }
    }
    for(int i=0;i<N;i++){
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 2292
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, K] = [long(input_raw[0]), long(input_raw[1])]
    sushi = []
    for i in range(N):
        input_raw = read_func().strip().split()
        [t, d] = [long(input_raw[0]), long(input_raw[1])]
        sushi.append((d, t))

    sushi.sort(reverse=True)

    already_eat = set([])
    max_score = 0L
    count = 0
    not_eat_list = deque([])
    eat_list = deque([])
    for i in range(N):
        if sushi[i][1] not in already_eat:
            already_eat.add(sushi[i][1])
            max_score += sushi[i][0]
            eat_list.append(i)
        else:
            not_eat_list.append(i)

        if len(already_eat) == K:
            break
    count = len(already_eat)

    if count < K:
        while 1:
            if count >= K :
                break
            if len(not_eat_list) <= 0:
                break
            i =not_eat_list.popleft()
            eat_list.appendleft(i)
            max_score += sushi[i][0]
            already_eat.add(sushi[i][1])
            count += 1



    now_kind = len(already_eat)
    max_score += now_kind * now_kind
    now_score = max_score
    if len(not_eat_list) > 0:
        for new_idx in not_eat_list:
            if len(eat_list) == 0 :
                break
            eated_idx = eat_list.pop()
            if sushi[eated_idx][1] in already_eat:
                already_eat.remove(sushi[eated_idx][1])
            already_eat.add(sushi[new_idx][1])

            new_kind = len(already_eat)
            now_score =  now_score - (now_kind * now_kind) + (new_kind *new_kind) - sushi[eated_idx][0] + sushi[new_idx][0]
            now_kind = new_kind
            max_score =max(max_score, now_score)


    print max_score




if __name__ == '__main__':
    main()


Measured memory_bytes: 23160
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vi l(n, -1);
	REP(i, m) {
		int s, c;
		cin >> s >> c;
		if (l[s - 1] != -1) {
			if (l[s - 1] != c) {
				cout << -1 << endl;
				return 0;
			}
		} else {
			l[s - 1] = c;
		}
	}
	if (n == 1) {
		if (l[0] == -1) l[0] = 0;
		printf("%d\n", l[0]);
	} else {
		if (l[0] == -1) l[0] = 1;
		else if (l[0] == 0) {
			cout << -1 << endl;
			return 0;
		}
		FOR(i, 1, n-1)
			if (l[i] == -1) l[i] = 0;
		REP(i, n) printf("%d", l[i]);
		printf("\n");
	}
}

Measured memory_bytes: 256
import java.awt.*;
import java.util.*;
class Main{
	static Scanner s=new Scanner(System.in);
	static int getInt(){return Integer.parseInt(s.next());}
	public static void main(String[]$){
		Point st=new Point(getInt(),getInt()),go=new Point(getInt(),getInt());
		if(st.y>go.y) {
			Point buf=go;
			go=st;
			st=buf;
		}
		Comparator<Point>c=Comparator.comparingDouble(Point::getX);
		TreeSet<Point>p=new TreeSet<>(st.x<go.x?c:c.reversed());
		for(int i=getInt();i>0;--i) {
			int x=getInt(),y=getInt();
			if(st.y<=y&&y<=go.y)
				p.add(new Point(x,y));
		}
		int v=lis(p.subSet(st,true,go,true));
		System.out.println(
				(Math.abs(st.x-go.x)+Math.abs(st.y-go.y))*100L
				+v*-20
				+(v==Math.min(go.y-st.y,Math.abs(go.x-st.x))+1?
						(v+1)
						:v)
				*5*Math.PI
				);
	}
	private static int lis(NavigableSet<Point> p){
		if(p.isEmpty())return 0;
		ArrayList<Integer>l=new ArrayList<>();
		l.add(p.pollFirst().y);
		while(!p.isEmpty()){
			int y=p.pollFirst().y;
			if(l.get(l.size()-1)<y)
				l.add(y);
			else {
				int v=Collections.binarySearch(l,y);
				if(v<0)
					l.set(~v,y);
			}
		}
		return l.size();
	}
}

Measured memory_bytes: 93792
N,S = map(int,input().split())
A = list(map(int,input().split()))
#%%
b = [[0]*(S+1) for _ in range(N+1)]
b[0][0] = int(S==0)
MOD = 998244353

for r in range(N):
    for s in range(S+1):
        b[r+1][s] += b[r][s]
        if s-A[r]>=0:
            b[r+1][s] += b[r][s-A[r]]
        if s==A[r] or s==0:
            b[r+1][s] += 1
        b[r+1][s] %= MOD

ans = 0
for i in range(N):  
    ans += b[i+1][S]
    ans %= MOD
    
print(ans)


Measured memory_bytes: 135360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100003;
const int mod = 1e9 + 7;

int dx[] = { 0, 0, 1, -1 };
int dy[] = { 1, -1, 0, 0 };
int n;
int a;
map<int,int>mp;
int main() {
	//freopen("input.txt", "r", stdin);
scanf("%d",&n);
int mx1=0,mx2=0;
for(int i=0;i<n;i++){
	scanf("%d",&a);
	mp[a]++;
	if(mx1>mx2)
		swap(mx1,mx2);
	if(mp[a]>=2 && a>mx1){
mx1=a;
mp[a]-=2;
	}
}
cout<<(ll) mx2 *mx1;



}



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

ll gcd(ll a,ll b){
  return b ? gcd(b,a%b) : a;
}

int main(){
  int k;
  cin >> k;
  ll ans=0;
  ll cal;
  for(int a=1;a<=k;++a){
    for(int b=1;b<=k;++b){
      cal=gcd(a,b);
      for(int c=1;c<=k;++c){
        ans+=gcd(cal,c);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<int> t[26];
int main(void){
    string s;
    cin>>s;
    int rans=101;
    for(int i=0;i<s.size();i++){
        t[s[i]-'a'].push_back(i);
    }
    //cout<<t[0][0]<<endl;
    for(int i=0;i<26;i++){
        int ans=0;
        int root=-1;
        if(t[i].empty())continue;
        for(auto x:t[i]){
            ans=max(ans,x-root-1);
            root=x;
        }
        //cout<<(int)s.size()-root-1<<endl;
        ans=max(ans,(int)s.size()-root-1);
        //cout<<ans<<i<<endl;
        rans=min(rans,ans);
    }
    cout<<rans<<endl;
    
}


Measured memory_bytes: 256