akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;



int n;
vector<int> G,B,R;

void count(string s,int n){
  if(s[n-1]=='R') R[n-1]++;
   if(s[n-1]=='B') B[n-1]++;
   if(s[n-1]=='G') G[n-1]++;
  for(int i=n-2;i>=0;i--){
   if(s[i]=='R') {R[i]=R[i+1]+1;B[i]=B[i+1];G[i]=G[i+1];}
   if(s[i]=='B') {B[i]=B[i+1]+1;G[i]=G[i+1];R[i]=R[i+1];}
   if(s[i]=='G') {G[i]=G[i+1]+1;B[i]=B[i+1];R[i]=R[i+1];}
  }
}

int main() {
  
  cin>>n;
  string s;
  cin>>s;
  ///////////
  ll ans=0;
  G.resize(n);
  B.resize(n);
  R.resize(n);
  count(s,n);
 // cout<<R[3]<<B[3]<<G[3]<<endl;
  rep(i,n-2){
   for(int j=i+1;j<n-1;j++){
      if(s[i]!=s[j]){
        int c=j-i;
        int k=j+c;
           if(s[i]=='R') {
                  
   				  if(s[j]=='B'){ ans+=G[j+1];if(k<n&&s[k]=='G') ans--;}
   				  if(s[j]=='G') {ans+=B[j+1];if(k<n&&s[k]=='B') ans--;}
            }
           if(s[i]=='B') {
                  if(s[j]=='R') {ans+=G[j+1];if(k<n&&s[k]=='G') ans--;}
   				  if(s[j]=='G') {ans+=R[j+1];if(k<n&&s[k]=='R') ans--;}
           }
           if(s[i]=='G'){
                  if(s[j]=='B') {ans+=R[j+1];if(k<n&&s[k]=='R') ans--;}
   				  if(s[j]=='R') {ans+=B[j+1];if(k<n&&s[k]=='B') ans--;}
           }
          
      }
   }
  }
  cout <<ans<<endl;
}




 




Measured memory_bytes: 3664
#include <iostream>

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    if(a % 3 == 0 || b % 3 == 0 || (a+b)%3 == 0)
        cout << "Possible" << endl;
    else 
        cout << "Impossible" << endl;

    return 0;
}

Measured memory_bytes: 256
str_inp = list(input())
str_len = len(str_inp)
flag = "ok"
check1 = ""
check2 = ""
dummy1 = (str_len - 1) // 2
for j in range(dummy1):
  check1 = check1 + str_inp[j]
#print(check1)
for i in range(dummy1//2):
  if check1[i] != check1[-i-1]:
    flag = "ng"
    
dummy2 = (str_len + 3) // 2
for k in range(dummy2-1,str_len):
  check2 = check2 + str_inp[k]
#print(check2)
dummy_len = len(check2)
for l in range(dummy_len//2):
  if check2[l] != check2[-l-1]:
    flag = "ng"

if flag == "ok" and check1 == check2:
  print("Yes")
else:
  print("No")



Measured memory_bytes: 3064
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from itertools import accumulate

class BIT(object):
    def __init__(self, size):
        self.size = size+1
        self.bitree = [0]*self.size
        
    def addval(self, idx:int, val:int):
        while idx < self.size:
            self.bitree[idx] += val
            idx += idx&(-idx)
            
    def getsum(self, idx:int):
        ret = 0
        while idx > 0:
            ret += self.bitree[idx]
            idx -= idx&(-idx)
            
        return ret
    
    def reset(self):
        self.bitree = [0]*self.size


def val2ord(a: list, rev=False):
    dic = {ai: i for i, ai in enumerate(sorted(a, reverse=rev))}
    return [dic[ai] for ai in a]


n,k = li()
a = [ni() for _ in range(n)]

acc = [0] + list(accumulate(a))

b = [acci - i*k for i,acci in enumerate(acc)]
c = val2ord(b)

bitree = BIT(n+1)

ans = 0
for ci in c:
    bitree.addval(ci+1, 1)
    ans += bitree.getsum(ci+1)-1

print(ans)

Measured memory_bytes: 57004
using System;
using System.Linq;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine();
            var total = n.ToCharArray().Select(i => long.Parse(i.ToString())).Sum();

            if(long.Parse(n) % total == 0){
                Console.WriteLine("Yes");
            }else{
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 11220
#include <stdio.h>
#include <random>
int D;
int c[26];
int l[367][26];
int s[366][26];
int t[366];
int m, p, q, d, k;
int md[100001];
int mq[100001];
int ans, bans;
unsigned long long a;
int main() {
	scanf("%d", &D);
	for (int i = 0; i < 26; i++) {
		scanf("%d", c + i);
	}
	for (int i = 1; i <= D; i++) {
		for (int j = 0; j < 26; j++) {
			scanf("%d", s[i] + j);
		}
	}
	std::mt19937_64 rd(468);
	for (int i = 1; i <= D; i++) {
		a = rd();
		t[i] = a % 26;
	}
	m = 1000;
	for (int i = 0; i < 1000; i++) {
		a = rd();
		md[i] = a % D + 1;
		mq[i] = a % 26;
	}
	for (int i = 1; i <= D; i++) {
		ans += s[i][t[i]];
		for (int j = 0; j < 26; j++) {
			l[i][j] = l[i - 1][j] + 1;
		}
		l[i][t[i]] = 0;
		for (int j = 0; j < 26; j++) {
			ans -= c[j] * l[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		q = mq[i];
		d = md[i];
		p = t[d];
		if (p != q) {
			bans = ans;
			t[d] = q;
			ans -= s[d][p];
			ans += s[d][q];
			k = d;
			while (l[k][q] && k <= D) {
				ans -= c[q] * (k - d - l[k][q]);
				l[k][q] = k - d;
				k++;
			}
			k = d;
			do {
				ans -= c[p] * (l[k - 1][p] + 1 - l[k][p]);
				l[k][p] = l[k - 1][p] + 1;
				k++;
			} while (l[k][p] && k <= D);
			if (ans < bans) {
				mq[i + 1] = p;
				md[i + 1] = d;
			}
		}
	}
	for (int i = 1; i <= D; i++) {
		printf("%d\n", t[i] + 1);
	}
}

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

int main(){
  int N; cin >> N;
  priority_queue<long long> A;
  for(int i=0; i<N; i++){
    long long t; cin >> t; A.push(t);
  }
  
  //上から入れたほうがよさそう
  long long result=0;
  priority_queue<long long> kokochi;
  kokochi.push(0);
  while(!A.empty()>0){
    long long nk=kokochi.top();
    kokochi.pop();
    result+=nk;
    if(nk==0){
      kokochi.push(A.top());
    }else{
      kokochi.push(min(A.top(),nk));
      kokochi.push(min(A.top(),nk));
    }
    A.pop();
  }
  cout << result << endl;
}

Measured memory_bytes: 7988
def dist(x, y):
    return sum([0 if x == y else 1 for x, y in zip(x, y)])


S = list(input())

p1 = ["0" if i % 2 == 0 else "1" for i in range(len(S))]
p2 = ["1" if i % 2 == 0 else "0" for i in range(len(S))]

print(min(dist(S, p1), dist(S, p2)))

Measured memory_bytes: 6308
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll dp[200050],dp2[200050];

int main(){
  string s;
  cin >> s;
  int n=s.size();
  dp[0]=1,dp2[0]=2;
  REP(i,1,n){
    if(s[i]=='0'){
      dp[i]=(3*dp[i-1])%mod;
      dp2[i]=dp2[i-1];
    }else{
      dp[i]=((3*dp[i-1])%mod+dp2[i-1])%mod;
      dp2[i]=(2*dp2[i-1])%mod;
    }
  }
  cout << (dp[n-1]+dp2[n-1])%mod << endl;
return 0;}

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

using namespace std;

long long dp[55][55];

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

    long long v[n];
    for (auto& x : v) cin >> x;

    sort(v, v + n);
    reverse(v, v + n);

    double ave = 0;
    for (int i = 0; i < a; i++) ave += v[i];
    ave /= a;

    long long comb[n + 10][n + 10] = {};
    comb[0][0] = 1;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= i; j++) {
            if (j == 0 or j == i) comb[i][j] = 1;
            else comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
            // cerr << " " << comb[i][j];
        }
        cerr << endl;
    }

    int x = 0, y = 0;
    for (int i = 0; i < n; i++) {
        if (v[i] == v[a - 1]) x++;
        if (i >= a) continue;
        if (v[i] == v[a - 1]) y++;
    }
    cerr << x << " " << y << endl;

    long long cnt = 0;
    if (y == a) {
        cerr << "a\n";
        for (int i = a; i <= b; i++) {
            cnt += comb[x][i];
        }
    }
    else cerr << "b\n", cnt += comb[x][y];

    printf("%.6f\n%lld\n", ave, cnt);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>//万能文件头
using namespace std;
string s="CODEFESTIVAL2016";//好像也没什么用
string a;
long long ans;
int main(){
    cin>>a;//输入字符串
    if(a[0] != 'C') ans++;//开始无脑判断
    if(a[1] != 'O') ans++;//要是有一个不一样
    if(a[2] != 'D') ans++;//就马上加上去
    if(a[3] != 'E') ans++;
    if(a[4] != 'F') ans++;
    if(a[5] != 'E') ans++;
    if(a[6] != 'S') ans++;
    if(a[7] != 'T') ans++;
    if(a[8] != 'I') ans++;
    if(a[9] != 'V') ans++;
    if(a[10] != 'A') ans++;
    if(a[11] != 'L') ans++;
    if(a[12] != '2') ans++;
    if(a[13] != '0') ans++;
    if(a[14] != '1') ans++;
    if(a[15] != '6') ans++;
    cout<<ans<<endl;//加完了，输出
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int R = Integer.parseInt(in.nextLine());
		if (R < 1200) {
			System.out.println("ABC");
		} else if (R < 2800) {
			System.out.println("ARC");
		} else {
			System.out.println("AGC");
		}
		in.close();
	}

}

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


//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  int k;
  cin>>k;
  int c=0;
  for(int i=0;i<k;i++){
    int x;
    cin>>x;
    c|=1<<x;
  }
  for(int b=0;b<(1<<n);b++){
    if((b&c)!=c) continue;
    cout<<b<<":";
    for(int i=0;i<n;i++)
      if((b>>i)&1) cout<<" "<<i;
    cout<<"\n";
  }
  cout<<flush;
  return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, x;
  cin >> k >> x;
  for (int i = -1000000; i < 1000001; i++) {
    if (i > x - k && i < x + k) {
      cout << i << ' ';
    }
  }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(400000)
N, Q = map(int, input().split())
paths = [list() for _ in range(N+1)] # paths[i] : 頂点iと繋がってる点を全て表す
for _ in range(N-1):
    a, b = map(int, input().split())
    paths[a].append(b)
    paths[b].append(a)
# ab = [list(map(int, input().split())) for _ in range(N-1)]
px = [list(map(int, input().split())) for _ in range(Q)]

ans = [0]*(N+1) # ans[i] : 頂点iについて答える値を格納

counters = [0]*(N+1) # そのノードの部分木に与える点数の総和を格納
for x in px:
    counters[x[0]] += x[1]

visit = [0]*(N+1) #dfsをする時に一度訪れた点に再訪しないための確認
def dfs(node, score, ans):
    visit[node] = 1 # 訪問したことを記録
    score += counters[node] # 自分の部分木に加点する分を加えて後世に残す
    ans[node] = score # 点数の記録
    for loof in paths[node]: # 自分と繋がってる各ノードについて
        if visit[loof] == 0: # まだ探索していなければ
            dfs(loof, score, ans) # 探索

dfs(1, 0, ans)
    

for i in range(1, N+1):
    print(ans[i])

Measured memory_bytes: 273880
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    ll hp; cin >> hp;
    vector<ll> a(n), b(n);
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
    sort(a.begin(), a.end(), greater<ll>());
    sort(b.begin(), b.end(), greater<ll>());
    ll ans = 0, val = a[0];
    for(int i = 0; i < n; i++)
    {
        if(b[i] <= val || hp <= 0) break;
        hp -= b[i];
        ans++;
    }
    if(hp > 0) ans += (hp + val - 1) / val;
    cout << ans << endl;
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	int a[n][3];
	for (int i = 0; i < n; ++i){
		for(int j = 0; j < 3; ++j){
			cin >> a[i][j];
		}
	}
	int dp[n+1][3];
	for (int i = 0; i < n+1; ++i){
		for (int j = 0; j < 3; ++j){
			dp[i][j] = 0;
		}
	}
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < 3; ++j){
			for(int k = 0; k < 3; ++k){
				if(j==k)continue;
				dp[i+1][j] = max(dp[i][k] + a[i][k], dp[i+1][j]);
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < 3; ++i)
	{
		ans = max(ans, dp[n][i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
/*
            _ _  ___            __ _ _  _       _     
 _   _  ___| | |/ _ \__      __/ _| | || |  ___| |__  
| | | |/ _ \ | | | | \ \ /\ / / |_| | || |_/ __| '_ \ 
| |_| |  __/ | | |_| |\ V  V /|  _| |__   _\__ \ | | |
 \__, |\___|_|_|\___/  \_/\_/ |_| |_|  |_| |___/_| |_|
 |___/                 

 */

#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 300005

vector<int> v;

void solve(int n) 
{ 
    for (int i=1; i<=sqrt(n); i++) 
    { 
        if (n%i == 0) 
        { 
            if (n/i == i){
                v.pb(i);
  			}
            else{
                v.pb(n/i); 
                v.pb(i);
        	}
        } 
    } 
} 
signed main(){
	fast
	int n, k; cin>>n>>k;
	int A[n+1];
	int sum=0;
	For(i, 0, n){
		cin>>A[i];
		sum+=A[i];
	}

	solve(sum);
	// tr(v){
	// 	cout<<*it<<" ";
	// }
	sort(all(v));
	int s = v.size();
	int finans=1;
	For(i, 1, s){
		vector<int> vals;
		int ss=0;
		For(j, 0, n){
			if(A[j]%v[i]){
				vals.pb(A[j]%v[i]);
				ss+=A[j]%v[i];
			}
		}
		sort(all(vals));
		int nnn = vals.size();
		if(nnn){
			int numa=0;
			int num = ss/v[i];
			int j=nnn-1;
			for(int j=nnn-1; j>=nnn-num; j--){
				// cout<<v[i]<<" "<<vals[j]<<endl;
				numa+=v[i]-vals[j];
			}
			if(numa<=k){
				finans=max(finans, v[i]);
			}
		}
	}
	cout<<finans<<endl;

    return 0;
}
    



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

x = False
k = {}
for i in range(N):
    if not A[i] in k:
        k[A[i]] = 1
    else:
        k[A[i]] += 1
B = 0
a = 0
if len(k.keys()) == 3:
    B = 0
    for key, val in k.items():
        if val == N // 3:
            a += 1
        B = B ^ key
elif len(k.keys()) == 2:
    for key, val in k.items():
        if val == N // 3 and key == 0:
            a += 1
        elif val == N // 3 * 2:
            a += 2
    B = 0
elif len(k.keys()) == 1:
    a = list(k.keys())
    if a[0] == 0:
        x = True

if (N % 3 == 0 and B == 0 and a == 3) or x:
    ans = 'Yes'
else:
    ans = 'No'

print(ans)

Measured memory_bytes: 14212
S = input().split(" ")
A = int(S[0]) * int(S[1]) - int(S[0])*2 - (int(S[1])*2-4)
if (int(S[0]) == 1 or int(S[1]) == 1) and int(S[0]) * int(S[1]) != 1:
    A = int(S[0]) * int(S[1]) - 2
A = max(0,A)
print(A)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll int64_t
#define all(v) v.begin(), v.end()
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)
#define Graph vector<vector<int>>

int main() {
 
  int N;
 
  cin >> N ;
 
  vector<int> A(N),B(N),C(N);
 
  rep(i,N) cin >>A[i];
  rep(i,N) cin >>B[i];
  rep(i,N) cin >>C[i];//入力終了
 
  sort(all(A)); sort(all(C));//昇順
 
  ll ans=0;  
 
  rep(i,N){
    auto a=lower_bound(all(A),B[i]),b=upper_bound(all(C),B[i]);
    ans+=(a-A.begin())*(C.end()-b);
  }
 
  cout << ans <<endl;
 
  return 0;
}

Measured memory_bytes: 1408
#include<cstdio>
#include<queue>
using namespace std;
struct sav {
	int mod, num;
}a[100010];
struct cmp {
	bool operator () (sav a, sav b) {
		return a.num < b.num;
	}
};
int ans[100010], n;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++) {
		ans[i] = 0;
		int j = i;
		while (j > 0) {
			ans[i] += j % 10;
			j /= 10;
		}
	}
	ans[0] = ans[n];
	priority_queue<sav, vector<sav>, cmp> q;
	for (int i = 0; i < n; i ++)
		q.push((sav){i, ans[i]});
	while (!q.empty()) {
		sav now = q.top(); q.pop();
		if (now.num + 1 < ans[(now.mod + 1) % n]) {
	        q.push((sav){(now.mod + 1) % n, now.num + 1});
			ans[(now.mod + 1) % n] = now.num + 1;
		}
		if (now.num < ans[now.mod * 10 % n]) {
	        q.push((sav){now.mod * 10 % n, now.num});
			ans[now.mod * 10 % n] = now.num;
		}
	} 
	printf("%d\n", ans[0]);
}

Measured memory_bytes: 1784
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e9
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N, M, Q, H, W, D, L, R,K;
ll A;
ll B[200001];
ll ans;
string S;
char s[52][52];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}


int main() {
	ll N, i;
	cin >> N >> i;
	cout << N - i + 1 << endl;
	cin >> N;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
h,w=map(int,input().split())
S=[input() for _ in range(h)]
ans=0
inf=float("inf")
for i in range(h):
   for j in range(w):
      if S[i][j]!="#":
         dp=[[inf for _ in range(w)]for _ in range(h)]
         dp[i][j]=0
         que=deque([(i,j)])
         while que:
            si,sj=que.popleft()
            for ni,nj in [(si+1,sj),(si-1,sj),(si,sj+1),(si,sj-1)]:
               if 0<=ni<h and 0<=nj<w and S[ni][nj]!="#":
                  if dp[ni][nj]>dp[si][sj]+1:
                     dp[ni][nj]=dp[si][sj]+1
                     ans=max(ans,dp[si][sj]+1)
                     que.append((ni,nj))
print(ans)

Measured memory_bytes: 48348
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937_64 mt64(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/


int n;
string s;
vector<int>v[5005];
signed main() {
	cin >> n >> s;
	for (int i = 1; i < n; i++) {
		for (int j = 0; j + i < n; j++) {
			if (s[j] == s[i + j])v[i].push_back(j);
		}
	}
	int ans = 0;
	for (int i = 1; i < n - 1; i++) {
		if (v[i].empty())continue;
		int ma = 0, cnt = 0;
		rep(j, v[i].size()) {
			cnt++; chmax(ma, cnt);
			if (j < v[i].size() - 1 && v[i][j] + 1 != v[i][j + 1]) {
				cnt = 0;
			}
		}
		chmax(ans, min(i, ma));
	}
	cout << ans << endl;
}

Measured memory_bytes: 113152
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const double PI = 3.14159265358979323846;

int main(void) {
  int h, w, k;
  cin >> h >> w >> k;
  char c[6][6];
  rep(i, h) rep(j, w) cin >> c[i][j];
  int ans = 0;
  for (int bit = 0; bit < (1 << (h + w)); bit++) {
    int blackCnt = 0;
    rep(i, h) {
      if (bit & (1 << (i + w))) continue;
      rep(j, w) {
        if (bit & (1 << j)) continue;
        if (c[i][j] == '#') blackCnt++;
      }
    }
    if (blackCnt == k) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
N, M = map(int, input().split())
pref_dict = {}

for i in range(M):
    P, Y = map(int, input().split())
    pref_dict[i] = [P, Y]

sorted_dict = sorted(pref_dict.items(), key= lambda x: (x[1][0], x[1],[1]))
ans_dict = {}
buf = ""
count = 1

for tup in sorted_dict:

    row = tup[0]
    pref_name = "00000{}".format(tup[1][0])
    pref_name = pref_name[-6:]

    if pref_name == buf:
        count += 1
    else:
        count = 1

    pref_id = "00000{}".format(count)
    pref_id = pref_id[-6:]
    ans_dict[row] = [pref_name, pref_id]
    buf = pref_name

for key, value in sorted(ans_dict.items(), key=lambda x: x[0]):
    print(*value, sep="")

Measured memory_bytes: 124692
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
const long long mo = 1e9 + 7;
const int MAXN = 3000 + 10;
using namespace std;
int n, k;
long long ans, po[MAXN], f[MAXN][MAXN];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> k;
	po[0] = 1;
	for (register int i = 1; i <= n; i++) po[i] = po[i - 1] * 2 % mo;
	for (register int i = n; i >= 2; i--) f[1][i] = 1;
	for (register int i = 1; i < k - 1; i++)
	{
		register long long sum = f[i][n - i + 1];
		for (register int j = n - i; j >= 2; j--)
		{
			sum = (sum + f[i][j]) % mo;
			f[i + 1][j] = (f[i + 1][j] + sum) % mo;
		}
	}
	for (register int j = 2; j <= n - k + 2; j++) ans = (ans + f[k - 1][j]) % mo;
	if (k == 1) ans = 1;
	if (n - 1 - k < 0) cout << ans;
	else cout << ans * po[n - 1 - k] % mo;
	return 0;
}

Measured memory_bytes: 46976
#define ENABLE_DEBUG 1
// hidden common codes{{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(lint ngtkana_is_a_genius=0; ngtkana_is_a_genius<(lint)k; ngtkana_is_a_genius++)
using lint=long long;
using ld=long double;
template<class T> using numr=std::numeric_limits<T>;
struct input_t {
    template<class T> operator T() {
        T t;
        std::cin>>t;
        return t;
    }
} input;
#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

auto cmx=[](auto&x,auto y){if(x<y){x=y;return true;}return false;};

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

    lint n=input,m=input;
    std::vector<lint>a(n),b(n);
    for(lint&x:a)x=input;
    while(m--){
        lint u=(lint)input-1;
        lint v=(lint)input-1;
        cmx(b.at(u), a.at(v));
        cmx(b.at(v), a.at(u));
    }

    lint ans=0;
    for(lint i=0;i<n;i++){
        ans+=a.at(i)>b.at(i);
    }
    std::cout<<ans<<'\n';
}


Measured memory_bytes: 4784
"use strict"

const { ifError } = require("assert");

const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    const [w,h,n] = nextIntArray()
    let xMin = 0
    let xMax = w
    let yMin = 0
    let yMax = h
    while(hasNext()){
        let tmp = nextIntArray()
        switch(tmp[2]){
            case 1:
                xMin = Math.max(xMin, tmp[0])
                break
            case 2:
                xMax = Math.min(xMax, tmp[0])
                break
            case 3:
                yMin = Math.max(yMin, tmp[1])
                break
            case 4:
                yMax = Math.min(yMax, tmp[1])
                break
        }
    }
    if(xMin >= xMax || yMin > yMax){
        console.log(0)
        return
    }
    console.log((xMax-xMin)*(yMax-yMin))

}
Main()



Measured memory_bytes: 30596
N, M = map(int, input().split())

err_list = [0] * N
score_list = ['WA'] * N
sum_error = 0
sum_ac = 0

for i in range(M):
  idx, s = input().split()
  idx = int(idx)

  # 既にACとなった問題については評価対象から外す
  if score_list[idx - 1] == 'WA':
    # scoreによって分岐する
    if s == 'WA':
      err_list[idx - 1] += 1
    else:
      score_list[idx - 1] = 'AC'
      sum_ac += 1
      sum_error += err_list[idx - 1]

print(sum_ac, sum_error)

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

const int MAX_N=1500, MAX_M=1500, MAX_W=1000;
int roadV[MAX_N], roadH[MAX_M];
int widthV[MAX_N*MAX_W+1];
int widthH[MAX_M*MAX_W+1];

inline int min(int a, int b){
    if(a<b)return a;
    return b;
}


int main() {
    ios_base::sync_with_stdio(0);
    int n, m, i, j, sumV, sumH, cnt, minWidth;
    
    while(1){
        cin >> n >> m;
        if(n==0 && m==0)
            break;
        
        sumV=0;
        sumH=0;
        for(i=0; i<n; i++){
            cin >> roadV[i];
            sumV+=roadV[i];
        }
        for(i=0; i<m; i++){
            cin >> roadH[i];
            sumH+=roadH[i];
        }
        minWidth=min(sumV,sumH);
        
        for(i=1; i<=minWidth; i++){
            widthV[i]=0;
        }
        for(i=1; i<=minWidth; i++){
            widthH[i]=0;
        }
    
        for(i=0; i<n; i++){
            sumV=0;
            for(j=i;j<n;j++){
                sumV+=roadV[j];
                widthV[sumV]++;
            }
        }
        
        for(i=0; i<m; i++){
            sumH=0;
            for(j=i;j<m;j++){
                sumH+=roadH[j];
                widthH[sumH]++;
            }
        }
    
        cnt=0;
        for(i=1; i<=minWidth; i++){
            cnt+=widthV[i]*widthH[i];
        }
    
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 7080
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
 
 
int main() {
    int k,n;
    cin >> k >> n;
    vector<int> A(n);
    cout << k*(k-1)/2 + n*(n-1)/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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 MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> s(n, vector<int>());
    int k;
    REP(i, m) {
        cin >> k;
        int t;
        REP(j, k) {
            cin >> t;
            t--;
            s[t].emplace_back(i);
        }
    }
    vector<int> p(m);
    REP(i, m) cin >> p[i];
    
    ll ans = 0;
    REP(i, 1 << n) {
        vector<int> l(m, 0);
        REP(j, n) {
            if (s[j].empty()) continue;
            if ((i >> j) & 1 == 1) {
                for (auto u : s[j]) l[u]++;
            }
        }
        bool ok = true;
        REP(j, m) if (l[j] % 2 != p[j]) {
            ok = false;
            break;
        }
        if (ok) ans++;
    }
    cout << ans << endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/


int main() {


	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];

	vector<ll> ans(n, 0);

	// 一つ分かればすべて決まる
	// 解は1意に定まる
	// Nは奇数

	// 強引にやればいけるんじゃないか？
	// 0からどんどん大きくしていく
	ll first = 0;
	ll prev = first;
	ll next;

	rep(i, n - 1) {
		next = a[i] * 2 - prev;
		if (i % 2 == 0) {
			if (next < 0) {

			}
		}
		else {
			if (next < 0) {
				first += (-next);
				next = 0;
			}
		}
		/*if (next < 0) {
			// 調整してあげる
			first += (-next);
		}*/
		prev = next;
	}

	//cout << first << " " << next << endl;
	// 最後の処理
	first += (a[n - 1] - first / 2 - next / 2);
	
	ans[0] = first;
	Rep(i, 1, n) {
		ans[i] = a[i - 1] * 2 - ans[i - 1];
	}

	rep(i, n) {
		cout << ans[i] << " ";
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

ll n, s;

ll ds(ll n, int b){
	ll s = 0;
	while(n){
		s += n % b;
		n /= b;
	}
	return s;
}

int main(){
	cin >> n >> s;
	ll d = n - s;
	if(d <= 0){
		cout << (d == 0 ? n + 1 : -1) << endl;
		return 0;
	}
	int i;
	for(i = 2; ll(i) * i <= n; ++i){
		if(ds(n, i) == s){
			cout << i << endl;
			return 0;
		}
	}
	for(--i; i > 0; --i){
		if(d % i == 0 && s >= i && d / i >= max(ll(i), s - i)){
			cout << d / i + 1 << endl;
			return 0;	
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
#define per(i, a, b) for (int i = (a); i >= int(b); i--)
using namespace std;

typedef long long ll;
const int maxn = 200;
int T, n;
ll a[maxn + 5], b[80];
char s[maxn + 5];

void insert(ll x) {
	per(i, 60, 0) if (x >> i & 1) {
		if (!b[i]) { b[i] = x; return; }
		else x ^= b[i];
	}
}

bool check(ll x) {
	per(i, 60, 0) if (x >> i & 1) x ^= b[i];
	return x == 0;
}

int main() {
	scanf("%d", &T);
	while (T --> 0) {
		scanf("%d", &n);
		rep(i, 1, n) scanf("%lld", &a[i]);
		scanf("%s", s + 1);
		memset(b, 0, sizeof(b));
		per(i, n, 1) {
			if (s[i] == '0') {
				insert(a[i]);
			} else {
				if (!check(a[i])) { puts("1"); goto nxt; }
			}
		}
		puts("0");
		nxt: void();
	}
	return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner

fun main(args :Array<String>){
    val cin = Scanner(System.`in`)

    while(true){
	var x = cin.nextInt()
	var y = cin.nextInt()

	if(x == 0 && y == 0){
	    break
	}else{
	    if(x < y){
		println("$x $y")
	    }else{
		println("$y $x")
	    }
	}
    }
}



Measured memory_bytes: 35592
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX_N = 100;
const int MAX_W = 10000;

int n,W;
int w[MAX_N], v[MAX_N], m[MAX_N];

int dp[MAX_W+1];
int deq[MAX_W+1];
int deqv[MAX_W+1];

void solve()
{
	for(int i = 0;i<n;i++)
	{
		for(int a = 0;a<w[i];a++)
		{
			int s = 0,t = 0;
			for(int j = 0;j*w[i]+a<=W;j++)
			{
				int val = dp[j*w[i]+a]-j*v[i];
				while(s < t&&deqv[t-1] <= val)t--;
				deq[t] = j;
				deqv[t++] = val;
				dp[j*w[i]+a] = deqv[s] +j*v[i];
				if(deq[s] == j-m[i])
				{
					s++;
				}
			}
		}
	}
	cout<<dp[W]<<endl;
}

int main()
{
	cin >> n >> W;
	for(int i = 0;i<n;i++)
	{
		cin >>v[i] >>w[i] >> m[i];
	}
	solve();
}


Measured memory_bytes: 3208
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }
        if (list.contains(k)) {
            System.out.println("POSSIBLE");
            return;
        }
        Collections.sort(list);
        if (k > list.get(n - 1) || n == 1) {
            System.out.println("IMPOSSIBLE");
            return;
        }
        int min = list.get(0);
        long gcd = gcd(min, list.get(1));
        for (int i = 2; i < n; i++) {
            gcd = gcd(gcd, list.get(i));
        }
        System.out.println(k % gcd == 0 ? "POSSIBLE" : "IMPOSSIBLE");
    }

    private static long gcd(long a, long b) {
        long temp;
        while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        }
        return b;
    }
}

Measured memory_bytes: 59280
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;

int main(void) {
    ll n, d[100001];
    cin >> n;
    ll i, j;
    ll a[13];
    a[1]=1;
    for(i=2; i<=7; i++)
        a[i]=pow(6, i-1);
    for(i=8; i<=12; i++)
        a[i]=pow(9, i-7);
    
    for(i=0; i<=n; i++)
        d[i]=INF;
    d[0]=0;
    for(i=1; i<=12; i++) {
        for(j=0; j+a[i]<=n; j++) {
            d[j+a[i]]=min(d[j+a[i]], d[j]+1);
        }
    }
    cout << d[n] << endl;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<cmath>
#define LL long long 
using namespace std; 

LL k, ans = 1, cnt, cnt1, qwq = 1; 

LL s(LL x){
	LL res = 0; 
	while (x > 0) {
		res += x % 10; 
		x /= 10; 
	}
	return res; 
} 

bool cmp(LL a, LL b){
	return a * s(b) <= b * s(a);
}

int main(){
	scanf("%lld", &k); 
	while (cnt < k) {
		printf("%lld\n", ans); 
		cnt++; 
		while (!cmp(ans + qwq, ans + 2 * qwq)) {
			qwq *= 10; 
		} 
		ans += qwq;  
	}
	return 0;  
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
    string s1, s2;
    int k, m;
    string s3;
    cin >> s1 >> s2;
    cin >> k >> m;
    cin >> s3;
    if (s3 == s1)cout << (k - 1) << " " << m << endl;
    else cout << (k) << " " << (m - 1) << endl;
}
 

Measured memory_bytes: 256
#!/bin/env/perl

use strict;
use warnings;
use utf8;

my @lines;

while (my $line = <STDIN>) {
  chomp $line;
  push @lines, $line;
}
my ($n, $x) = split ' ', $lines[0];
my @l = split ' ', $lines[1];

unshift @l, 0;
my @d = (0, 0);

for (my $i = 2; $i <= ($n+1); $i++) {
  my $next_d = $d[$i - 1] + $l[$i - 1];
  last if $next_d > $x;
  push @d, $next_d;
}

print scalar(@d) - 1;

Measured memory_bytes: 640
n, k = map(int, input().split())
lis = list(map(int, input().split()))
c1, c2 = 0, 0
for i in range(n):
        for j in range(n):
                if lis[i] > lis[j]:
                        c2 += 1
                        if j > i:
                                c1 += 1
ans = c1*k + c2*k*(k-1)//2
print(ans % 1000000007)

Measured memory_bytes: 41324
#include <iostream>

using namespace std;

int N;
int a[100100],b[100100],c[100100];
long long dp[100100][3];

int main(){
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> a[i] >> b[i] >> c[i];
  }
  for(int i=0;i<=N;i++){
    dp[i][0]=0;dp[i][1]=0;dp[i][2]=0;
  }
  for(int i=0;i<=N;i++){
    dp[i+1][1]=max(dp[i+1][1],dp[i][0]+a[i]);
    dp[i+1][2]=max(dp[i+1][2],dp[i][0]+a[i]);
    dp[i+1][0]=max(dp[i+1][0],dp[i][1]+b[i]);
    dp[i+1][2]=max(dp[i+1][2],dp[i][1]+b[i]);
    dp[i+1][0]=max(dp[i+1][0],dp[i][2]+c[i]);
    dp[i+1][1]=max(dp[i+1][1],dp[i][2]+c[i]);
  }
  cout << max(dp[N][0],max(dp[N][1],dp[N][2])) << endl;
  return 0;
}


Measured memory_bytes: 3712
#include <utility>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <numeric>
#include <limits>
#include <queue>
#include <cstdint>
#define ll long long int
#define rep(i,rept) for (ll i = 0; i < rept; i++)
#define Yes(b) std::cout<< (b ? "Yes" : "No")<<std::endl
#define YES(b) std::cout<< (b ? "YES" : "NO")<<std::endl
#define fr first
#define se second
#define lolo 92233720368547757
#define susu 1000000007

using namespace std;
int main() {
	string k;
	ll o;
	cin >> k >> o;
	rep(i, k.size()) {
		if (i >= o) {
			break;
		}
		if (k[i] != '1') {
			cout << k[i];
			return 0;
		}
	}
	cout << 1;
}

Measured memory_bytes: 256
import math

a = []
for i in range(5):
    a.append(int(input()))

max_a_idx = 0
max_dif = 0
for i in range(5):
    if a[i]%10!=0:
        x = 10-(a[i]%10)
        if x > max_dif:
            max_dif=x
            max_a_idx=i


#print("------------")
time = 0
for i in range(5):
    if i!=max_a_idx:
        if a[i]%10!=0:
            time += (a[i]+(10-a[i]%10))
        else:
            time += a[i]
        #print(str(a[i])+" "+str(time))

time += a[max_a_idx]
print(time)

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	set<int> s;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		s.insert(a[i]);
	}
	cout << s.size() << endl;
}


Measured memory_bytes: 7764
from decimal import *
setcontext(Context(prec=200,rounding=ROUND_UP))
factorial=[1]
fac=Decimal('1')
for i in range(2,150):
    fac*=Decimal(i)
    factorial.append(fac)

def cos(s):
    cos=Decimal('1')
    s=Decimal(s)
    for i in range(4,100,4):
        cos+=(Decimal((s**Decimal(i)))/Decimal(factorial[i-1]))
    for i in range(2,100,4):
        cos-=(Decimal((s**Decimal(i)))/Decimal(factorial[i-1]))
    return cos

def radian_convert(s):
    s=Decimal(s)
    return s*Decimal('3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066')/Decimal('180')

a,b,c,d=input().split()
a=Decimal(a)
b=Decimal(b)
c=Decimal(c)
d=Decimal(d)
angle=(d/Decimal('60')*Decimal('360')-c/Decimal('12')*Decimal('360')-d/Decimal('60')*Decimal('30'))
ans=Decimal.sqrt(a*a+b*b-2*a*b*cos(radian_convert(angle)))
print(ans)

Measured memory_bytes: 9964
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int main()
{
    long long N;
    vector<long long> A;
    long long x;
    long long ans = 0;
    
    cin >> N;
    
    for (int i = 0;i < N;i++){
        cin >> x;
        A.push_back(x);
    }
    
    sort(A.begin(),A.end());
    
    if (N == 2){
        ans = A[1];
    }
    else if (N > 2 && N%2 == 0){
        ans += A[N-1];
        for (int i = 0;i < (N-2)/2;i++){
            ans += 2*A[N-2-i];
        }
    }
    else {
        ans += A[N-1];
        for (int i = 0;i < (N-3)/2;i++){
            ans += 2*A[N-2-i];
        }
        ans += A[(N-1)/2];
    }
    
    cout << ans << endl;
}


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

int main() {
        int n;
        int a[4];

        cin >> n;

        a[0] = (n % 10); n /= 10;
        a[1] = (n % 10); n /= 10;
        a[2] = (n % 10); n /= 10;
        a[3] = (n % 10); n /= 10;

        if( (a[2] == a[1] && a[1] == a[0]) || (a[1] == a[2] && a[2] == a[3] ) ){
        cout << "Yes" << endl;
        }else{
        cout << "No" << endl;
        }
        return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
main(){
	long long n,x;
	scanf("%lld%lld",&n,&x);
	long long ans=n;
	long long a=x,b=n-x;
	if(a<b)swap(a,b);
	for(;;){
		if(a%b==0){
			ans+=b*(2*(a/b)-1);
			break;
		}else{
			ans+=b*(2*(a/b));
			a%=b;
			swap(a,b);
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
#define all(s) s.begin(),s.end()
#define pb push_back
#define pi 3.1415926536
#define dig(a) fixed<<setprecision(a)
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL);
ll power(ll a, ll n) {ll res = 1; while (n) {if (n % 2) {res *= a;} n >>= 1; a *= a;} return res;}
ll powerm(ll a, ll n, ll m) {ll res = 1; while (n) {if (n % 2) {res = (res * a) % m;} n >>= 1; a = (a * a) % m;} return res;}

const int M=1e9+7;
ll mod(ll x){
      return ((x%M + M)%M);
}
ll add(ll a, ll b){
      return mod(mod(a)+mod(b));
}
ll mul(ll a, ll b){
      return mod(mod(a)*mod(b));
}
ll minu(ll a, ll b){
	return mod(mod(a)-mod(b));
}
ll dp[2005];
ll solve(ll s){
	if(s==0){
		return 1;
	}
	if(s==1 || s==2){
		return 0;
	}
	if(s>=3 && s<=5){
		return 1;
	}
	if(dp[s]!=-1){
		return dp[s];
	}
	ll t =0;
	for(ll i=3;i<=s;i++){
		if(s-i>=0){
			t = add(t,solve(s-i));
		}
	}
	return dp[s] = t;
}
int main(){
	fast();
	int test=1;
	//cin>>test;
	while(test--){
		int n;cin>>n;
		memset(dp,-1,sizeof(dp));
		dp[0]=1;
		cout<<solve(n)<<endl;
		
	}
	return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cstring>

//#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;

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

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

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;


const int INF = 1LL << 60;

class UnionFindTree {
private:
    vector<int> m_parent; // 親ノードの番号を格納。-1なら自分自身が親(root)

public:
    // 頂点数で初期化。最初は全てのノードが非連結。
    UnionFindTree(int x) : m_parent(x, -1) {}

    // xがどのグループに属しているかを調べる。
    int root(int x) {
        if (m_parent[x] < 0) {
            return x;
        }
        m_parent[x] = root(m_parent[x]); // 高速化のため、親を根に繋ぎかておく。
        return m_parent[x];
    }

    // xの属するグループの頂点数を調べる。
    int size(int x) { return -m_parent[root(x)]; }

    // xが属する集合とyが属する集合を連結する。
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) {
            return false; // すでにくっついているからくっつけない。
        }

        // ノード番号の大きい方(x)に小さい方(y)をくっつけたい。
        if (size(x) < size(y))
            swap(x, y);

        // xのサイズを更新。
        m_parent[x] += m_parent[y];
        // yの親をxにする。
        m_parent[y] = x;
        return true;
    }

    // 同じグループか？
    bool is_same_group(int x, int y) { return root(x) == root(y); }
};

signed main() {
    int n, k, l; cin >> n >> k >> l;
    UnionFindTree ufl(n), ufr(n);
    rep(i, k) {
        int a, b; cin >> a >> b; a--, b--;
        ufl.unite(a, b);
    }
    rep(i, l) {
        int a, b; cin >> a >> b; a--, b--;
        ufr.unite(a, b);
    }

    map<P, int> mp;
    rep(i, n) {
        mp[P(ufl.root(i), ufr.root(i))]++;
    }
    rep(i, n) {
        cout << mp[P(ufl.root(i), ufr.root(i))] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 15104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGC022B {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());
            int[] ans = new int[N];
            if (N == 3) {
                ans[0] = 2;
                ans[1] = 5;
                ans[2] = 63;
            } else {
                int div = N / 8;
                int rem = N % 8;
                for (int i = 0; i < div; i++) {
                    ans[i * 8] = 12 * i + 2;
                    ans[i * 8 + 1] = 12 * i + 3;
                    ans[i * 8 + 2] = 12 * i + 4;
                    ans[i * 8 + 3] = 12 * i + 6;
                    ans[i * 8 + 4] = 12 * i + 8;
                    ans[i * 8 + 5] = 12 * i + 9;
                    ans[i * 8 + 6] = 12 * i + 10;
                    ans[i * 8 + 7] = 12 * i + 12;
                }
                switch (rem) {
                    case 0:
                        break;
                    case 1:
                        ans[div * 8] = 12 * div + 6;
                        break;
                    case 2:
                        ans[div * 8] = 12 * div + 3;
                        ans[div * 8 + 1] = 12 * div + 9;
                        break;
                    case 3:
                        ans[div * 8] = 12 * div + 3;
                        ans[div * 8 + 1] = 12 * div + 9;
                        ans[div * 8 + 2] = 12 * div + 6;
                        break;
                    case 4:
                        ans[div * 8] = 12 * div + 3;
                        ans[div * 8 + 1] = 12 * div + 9;
                        ans[div * 8 + 2] = 12 * div + 2;
                        ans[div * 8 + 3] = 12 * div + 4;
                        break;
                    case 5:
                        ans[div * 8] = 12 * div + 3;
                        ans[div * 8 + 1] = 12 * div + 9;
                        ans[div * 8 + 2] = 12 * div + 2;
                        ans[div * 8 + 3] = 12 * div + 4;
                        ans[div * 8 + 4] = 12 * div + 6;
                        break;
                    case 6:
                        ans[div * 8] = 12 * div + 3;
                        ans[div * 8 + 1] = 12 * div + 9;
                        ans[div * 8 + 2] = 12 * div + 2;
                        ans[div * 8 + 3] = 12 * div + 4;
                        ans[div * 8 + 4] = 12 * div + 8;
                        ans[div * 8 + 5] = 12 * div + 10;
                        break;
                    case 7:
                        ans[div * 8] = 12 * div + 3;
                        ans[div * 8 + 1] = 12 * div + 9;
                        ans[div * 8 + 2] = 12 * div + 2;
                        ans[div * 8 + 3] = 12 * div + 4;
                        ans[div * 8 + 4] = 12 * div + 8;
                        ans[div * 8 + 5] = 12 * div + 10;
                        ans[div * 8 + 6] = 12 * div + 6;
                        break;
                }
            }
            Console.WriteLine(string.Join(" ", ans));
        }
    }
}


Measured memory_bytes: 13400