akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define N 100010
#define inf 0x3f3f3f3f
int n,s,t;
int first[N],cnt=0;
int dis[N],vis[N];
struct edge{
	int u,v,w,nxt;
}e[N*20];

inline void add(int u,int v,int w){
	e[++cnt].u=u;e[cnt].v=v;e[cnt].w=w;
	e[cnt].nxt=first[u];first[u]=cnt;
}

void dijkstra(){
	typedef pair<int,int>T;
	priority_queue< T,vector<T>,greater<T> >q;
	memset(dis,inf,sizeof(dis));
	memset(vis,0,sizeof(vis));
	dis[s]=0;
	q.push(make_pair(0,s));
	while(!q.empty()){
		int u=q.top().second;
		int d=q.top().first;
		q.pop();
		if(vis[u]) continue;
		vis[u]=1;
		for(int i=first[u];i;i=e[i].nxt){
			int v=e[i].v;
			if(dis[v]>d+e[i].w){
				dis[v]=d+e[i].w;
				q.push(make_pair(dis[v],v));
			}	
		}
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=0;j<=9;j++)
			add(i,((i-1)*10+j)%n+1,j);
	for(int i=1;i<=9;i++) add(0,i+1,i);
	s=0,t=1;
	dijkstra();
	printf("%d",dis[t]);
	return 0;
}

Measured memory_bytes: 19956
/*
    ~A_Pessimist~:)
*/

#include<bits/stdc++.h>
#define ll long long int
using namespace std;

void solve()
{
    ll n,i;
    cin>>n;
    ll ar[n+5],dp[n+5];

    for(i=1;i<=n;i++)
    {
        cin>>ar[i];
        dp[i]=0;
    }

    dp[1]=0;
    dp[0]=0;

    for(i=2;i<=n;i++)
    {
        if(i==2) dp[i]=abs(ar[i]-ar[i-1]);
        else dp[i]=min(dp[i-1]+abs(ar[i]-ar[i-1]),dp[i-2]+abs(ar[i]-ar[i-2]));
    }
    cout<<dp[n]<<endl;
}

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

    int t=1;
   // cin>>t;

    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 5128
#include<bits/stdc++.h>
using namespace std ; 
# define pb push_back
# define ll long long
# define mp make_pair 
# define endl "\n"
# define vi vector<int>
# define vc vector<char>
# define vll vector<ll> 
# define pi pair<int,int> 
const int MOD = 1e9 + 7 ; 
const ll inf = 1e18 ; 


int main() {

	int x ; 
	cin >> x ; 
	if ( x >= 400 && x <= 599) cout << 8 ; 
	else if (x >= 600 && x <= 799 ) cout << 7 ; 
	else if (x >= 800 && x <= 999 ) cout << 6 ; 
	else if (x >= 1000 && x <= 1199 ) cout << 5 ; 
	else if (x >= 1200 && x <= 1399 ) cout << 4 ; 
	else if (x >= 1400 && x <= 1599 ) cout << 3 ; 
	else if (x >= 1600 && x <= 1799 ) cout << 2 ; 
	else 
	cout << 1 ;  
	return 0; 
}


Measured memory_bytes: 3616
n = int(input())
S = []
H = []
C = []
D = []

for x in range(0,n):
    L = raw_input().split()
    if L[0] == "S": S.append(int(L[1]))
    elif L[0] == "H": H.append(int(L[1]))
    elif L[0] == "C": C.append(int(L[1]))
    else: D.append(int(L[1]))

for x in range(1,14):
    if not x in S: print "S {}".format(x)
for x in range(1,14):
    if not x in H: print "H {}".format(x)
for x in range(1,14):
    if not x in C: print "C {}".format(x)
for x in range(1,14):
    if not x in D: print "D {}".format(x)

Measured memory_bytes: 6444
#include <bits/stdc++.h>
using namespace std;
typedef int int__;
#define int long long
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define fi first
#define se second
#define forn(i, n)for(int i=0;i<int__(n);i++) 
#define sz(a)int__(a.size())
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a){return out << "(" << a.first << ", " << a.second << ")";}
template<class A>ostream& operator<<(ostream& out,const vector<A>&v){out<<"[";forn(i,sz(v)){if(i)out<<", ";out<<v[i];}return out<<"]";}
const int MAX = 1e9 + 100;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
int Mod(int x){const int mm=998244353;x%=mm;if(x<0)x+=mm;return x;}
int Pow(int x,int n){if(n==0)return 1;int t=Pow(x,n/2);t=Mod(t*t);if(n&1)t=Mod(t*x);return t;}
#define watch(x) cout << #x << " : " << x << endl;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
vvi a;
vi dp;
int ans = 0;

vi vis;

void dfs(int x) {
	if(dp[x] != 0) return;
	dp[x] = 1;
	for(int v:a[x]) {
		dfs(v);
		dp[x] = max(dp[x],1 + dp[v]);
	}
	ans = max(ans,dp[x]);
}

int__ main() {
	fast;
	int n,m; cin >> n >> m;

	dp = vi(n+1,0);
	a.resize(n+1);

	for(int i=0;i<m;i++) {
		int u,v; cin >> u >> v; a[u].pb(v);
	}

	for(int i=1;i<=n;i++) {
		if(!dp[i]) {
			dfs(i);
		}
	}
	cout << ans - 1 << endl;

}

Measured memory_bytes: 8576
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <fstream>
#include <string>
#include <sstream>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
    int n;
    cin >> n;
    string s;
    unordered_map<string, int> m;
    m["AC"] = 0;
    m["WA"] = 0;
    m["TLE"] = 0;
    m["RE"] = 0;
    for(int i = 0; i < n; ++i) {
    	cin >> s;
    	if(s == "AC" || s == "WA" || s == "TLE" || s == "RE") {
    		m[s]++;
    	}
    }
    cout << "AC x " << m["AC"] << "\n";
    cout << "WA x " << m["WA"] << "\n";
    cout << "TLE x " << m["TLE"] << "\n";
    cout << "RE x " << m["RE"] << "\n";
	return 0;
}


Measured memory_bytes: 3304
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N, M;
vector<P> edge;
vector<vector<int>> root(51);  //pair<辺の距離, 行先の頂点>
int from, to;
bitset<51> used;

void rec(int corrent = 1){
    for(int i = 0; i < root[corrent].size(); ++i){
        int next = root[corrent][i];
        if(used[next] || (corrent == from && next == to) || (corrent == to && next == from)) continue;
        used[next] = true;
        rec(next);
    }
    return;
}

int main(void){
    
    scanf("%d %d", &N, &M);
    for(int i = 0; i < M; ++i){
        int a, b; scanf("%d %d", &a, &b);
        edge.push_back(make_pair(a, b));
        root[a].push_back(b), root[b].push_back(a);
    }
    
    int ans = 0;
    for(int i = 0; i < edge.size(); ++i){
        from = edge[i].first; to = edge[i].second;
        used.reset();
        rec();
        for(int i = 1; i <= N; ++i){
            if(!used[i]){ ++ans; break; }
        }
    }
    printf("%d\n", ans);
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a[100001],b[100001];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		b[a[i]-1]=i+1;
	}
	for(int i=0;i<n;i++) cout<<b[i]<<' ';
	return 0;
}


Measured memory_bytes: 1536
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
		//int c = sc.nextInt();
		// 文字列の入力
		//String s = sc.next();
		
		// 出力
		if(a%3==0||b%3==0||(a+b)%3==0)
		System.out.println("Possible");
		else
		System.out.println("Impossible");






	}
}


Measured memory_bytes: 23124
#include <iostream>
#include <string>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, s, n) for(int i = s; i < n; i++)
using namespace std;

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

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

using ll = long long;
using pii = pair<int, int>;

template <typename T> T inf;
template <> int inf<int> = 1e9;
template <> ll inf<ll> = 1e18;


int main() {
    int N;
    cin >> N;
    vector<int> D(N);
    for(int i = 0; i < N; ++i) {
        cin >> D[i];
    }
    if(find(D.begin(), D.end(), 0) != D.end()) {
        cout << 0 << endl;
        return 0;
    }
    vector<bool> dp(1 << 24);
    dp[1] = true;
    for(int i = 0; i < N; ++i) {
        vector<bool> nxt(1 << 24);
        for(int S = 0; S < (1 << 24); ++S) {
            if(!dp[S]) {
                continue;
            }
            if(!(S & (1 << D[i]))) {
                int nS1 = S | (1 << D[i]);
                nxt[nS1] = true;
            }
            if(D[i] != 0 && !(S & (1 << (24 - D[i])))) {
                int nS2 = S | (1 << (24 - D[i]));
                nxt[nS2] = true;
            }
        }
        dp = move(nxt);
    }
    int res = 0;
    for(int S = 0; S < (1 << 24); ++S) {
        vector<int> pos;
        if(dp[S]) {
            int t = 24;
            for(int i = 0; i < 24; ++i) {
                if(S & (1 << i)) {
                    pos.push_back(i);
                }
            }
            //for(auto x : pos) {
            //    cout << x << ' ';
            //}
            //cout << endl;
            for(int i = 0; i + 1 < pos.size(); ++i) {
                t = min(t, abs(pos[i] - pos[i + 1]));
            }
            t = min(t, 24 - pos.back() + pos[0]);
            res = max(res, t);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 4476
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
long long A[100000];
int main()
{
	int N, count = 0;
	long long sum = 0;
	long long min = 100000000;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (A[i] < 0) {
			count++;
		}
		if (abs(A[i]) < min) {
			min = abs(A[i]);
		}
		sum += abs(A[i]);
	}
	if (count % 2 == 0) {
		cout << sum << endl;
	}
	else {
		cout << sum - 2 * min << endl;
	}
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,K; cin >> N >> K;
    int A[3]; cin >> A[0] >> A[1] >> A[2];
    vi T[K];
    int ans=0;
    string S; cin >> S;
    rep(i,N){
        if(S[i]=='s'){
            T[i%K].eb(0);
        } else if(S[i]=='p'){
            T[i%K].eb(1);
        } else {
            T[i%K].eb(2);
        }
    }
    int cnt=1;
    rep(i,K){
        rep(j,SZ(T[i])){
            if(!j) continue;
            if(T[i][j]==T[i][j-1]){
                cnt++;
            } else {
                ans+=((cnt+1)/2)*A[T[i][j-1]];
                cnt=1;
            }
        }
        ans+=A[T[i][SZ(T[i])-1]]*((cnt+1)/2);
        cnt=1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5200
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<queue>
using namespace std;
int a, b, n, ans = 0, memo[25][25];//!! 1 origin !!
bool s[25][25];

int sol(int x, int y) {
	if (memo[x][y] != 0)return memo[x][y];
	else if (!s[x][y])return 0;
	else if (x*y == 1)return memo[x][y] = 1;
	else {
		if (x == 1) return memo[x][y] += sol(x,y-1);
		else if (y == 1)return memo[x][y] += sol(x-1,y);
		else return memo[x][y] += sol(x - 1, y) + sol(x, y - 1);
	}
	return memo[x][y];
}

int main() {
	for (int dd = 0; dd < 5; dd++) {
		cin >> a >> b;
		if (a + b == 0) break;
		else {
			cin >> n;
			for (int i = 1; i <= a; i++) {
				for (int j = 1; j <= b; j++) {
					memo[i][j] = 0;
					s[i][j] = true;
				}
			}
			for (int i = 0; i < n; i++) {
				int x, y;
				cin >> x >> y;
				s[x][y] = false;
			}
			cout << sol(a, b) << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3084
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    a,b,c,d=map(int,input().split())
    while True:
        c-=b
        if c<=0:
            print('Yes')
            break
        else:
            a-=d
            if a<=0:
                print('No')
                break


resolve()

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

typedef long long int ll;
#define endl "\n"
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pair<int, int>>
#define mems(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define forn(i, s, e) for (int i = s; i < (e); ++i)
#define FASTIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define FILEIO                          \
    freopen("./input.txt", "r", stdin); \
    freopen("./output.txt", "w", stdout);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)                                                               \
    for (                                                                       \
        auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second;                                                       \
        debug("%s : %lld ms\n ", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
const int M = 1e9 + 7;

template <class T>
T ABS(const T &x) { return x > 0 ? x : -x; }
ll gcd(ll n1, ll n2) { return n2 == 0 ? ABS(n1) : gcd(n2, n1 % n2); }
ll lcm(ll n1, ll n2) { return n1 == 0 && n2 == 0 ? 0 : ABS(n1 * n2) / gcd(n1, n2); }

const int N = 1e6 + 10;
int s[N];

bool findDiv(int n)
{
    for (int i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            if ((s[i] > 0 && i != n) || (n / i != n && s[n / i] > 0))
                return false;
        }
    }
    return true;
}

int main()
{
    FASTIO
#ifdef LOCAL
    FILEIO
#endif
    int n;
    cin >> n;
    int a[n];
    forn(i, 0, n)
    {
        cin >> a[i];
        s[a[i]]++;
    }
    int ans = 0;
    sort(a, a + n);
    forn(i, 0, n)
    {
        if (s[a[i]] > 1)
            continue;
        if (findDiv(a[i]))
        {
            // cout << a[i] << endl;
            ++ans;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 8220
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <random>
#include <string.h>      //文字列の代入に使う                                                                                           
#include <bits/stdc++.h> //piの利用で必要(M_PI)                                                                                         
#include <algorithm>
#include <climits>
#include <map>
#define rep(i, c) for (int i = 0; i < (int)c; i++) //atcoderの解説コードに利用されていたので，ある程度一般生があるかと思われる．        

int main()
{
  int A,B,C;
  std::cin >> A>>B>>C;


  std::cout << C<<" "<<A<<" "<<B << std::endl;

    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int k,b ;
    cin>>k >> b;
    char arr[k][b];
    for(int i = 0 ; i < k; i++)
    {
        for(int i2 = 0; i2 < b ; i2++)
        {
            cin>>arr[i][i2];
        }
    }
    for(int i = 0 ; i < k; i++ )
    {
        for(int i2 = 0 ; i2 < b ; i2 ++)
        {
            cout<<arr[i][i2];
        }
        cout<<endl;
        for(int i2 = 0 ; i2 < b ; i2 ++)
        {
            cout<<arr[i][i2];
        }
        cout<<endl;
    }

}


Measured memory_bytes: 256
H, N = map(int, input().split())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

INF = float('inf')

dp = [[INF] * (H+1) for _ in range(N+1)]

dp[0][0] = 0

for i in range(N):
    for j in range(H+1):
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        dp[i+1][min(H, j+A[i])] = min(dp[i+1][min(H, j+A[i])], dp[i+1][j] + B[i])

print(dp[N][H])

Measured memory_bytes: 289672
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

const int MAX = 401;

int N, Ma, Mb;
int dp[MAX][MAX];
vector<int> a, b, c;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> Ma >> Mb;
  a.resize(N);
  b.resize(N);
  c.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }

  fill(dp[0], dp[MAX], INF);
  dp[0][0] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = MAX - 1; j >= 0; j--) {
      for (int k = MAX - 1; k >= 0; k--) {
        if (dp[j][k] != INF) {
          dp[j + a[i]][k + b[i]] = min(dp[j + a[i]][k + b[i]], dp[j][k] + c[i]);
        }
      }
    }
  }

  int ans = INF;
  for (int j = 1; j < MAX; j++) {
    for (int k = 1; k < MAX; k++) {
      if (dp[j][k] == INF) {
        continue;
      }
      if (j * Mb == k * Ma) {
        ans = min(ans, dp[j][k]);
      }
    }
  }

  if (ans == INF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 896
public class Main {

  private static void solve() {
    int[] a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4,
        1, 4, 1, 51};

    int k = ni();

    System.out.println(a[k - 1]);


  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 22996
# Maximum Sum
# start10:18-
A = gets.chomp.split(" ").map(&:to_i)
K = gets.chomp.to_i
ans = 0
for i in 1..K do
   A[A.index(A.max)] = A.max * 2
end
for i in 0..A.length-1 do
    ans = ans + A[i]
end
puts ans

Measured memory_bytes: 1788
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10

    S = deque(input())
    N = len(S)
    ans = 0
    if len(S) == 1:
        print(0)
        return
    left = S.popleft()
    right = S.pop()
    while True:
        if left == right:
            if len(S) >= 2:
                left = S.popleft()
                right = S.pop()
                continue
            else:
                break
            
        if left != 'x' and right!='x':
            print(-1)
            return

        ans += 1
        if left == 'x':
            if len(S)>0:
                left = S.popleft()
            else:
                break
        elif right == 'x':
            if len(S)>0:
                right = S.pop()
            else:
                break

    print(ans)



            

        

main()

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

using ll = long long int;

ll n;

int ans;

int main(void) {
    // Here your code !
    scanf("%lld\n", &n);

    ans = 10 + 5;
    for (ll i = 1; i * i <= n; ++i) {
      if (n % i != 0) continue;
      ll co = n / i;
      int tmp = max(to_string(i).size(), to_string(co).size());
      ans = min(ans, tmp);
    }

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

    return 0;
}


Measured memory_bytes: 256
a,b,c = map(int,input().split())

g = 0
if a == 5:
  g = g + 1
if b == 5:
  g = g + 1
if c == 5:
  g = g + 1

h = 0
if a == 7:
  h = h + 1
if b == 7:
  h = h + 1
if c == 7:
  h = h + 1
  
if h == 1 and g == 2:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3064
object Main extends App {
  val (us, limits) = {
    val s = new java.util.Scanner(System.in)
    (s.nextDouble(), (1 to 5).map(_ => s.nextLong()))
  }

  // ボトルネックで切り上げ + 残りの移動回数
  val ans = (us / limits.min).ceil.toLong + 4
  println(ans)
}


Measured memory_bytes: 25420
<?php

fscanf(STDIN, "%d", $n);

const N_MAX = 100005;

$dp = array_fill(0, N_MAX, 0);


for ($i = 0; $i < N_MAX; ++$i) {
    $dp[$i] = $i; 

    $yen = 6;
    while ($yen < N_MAX) {
        if ($i - $yen >= 0) {
            $dp[$i] = min($dp[$i], $dp[$i - $yen] + 1);
        }
        $yen *= 6;
    }

    $yen = 9;
    while ($yen < N_MAX) {
        if ($i - $yen >= 0) {
            $dp[$i] = min($dp[$i], $dp[$i - $yen] + 1);
        }
        $yen *= 9;
    }
}
echo $dp[$n], PHP_EOL;


Measured memory_bytes: 8696
#include<bits/stdc++.h>
#define   ll   long long int
#define   sz   200010

using namespace std;


ll id=1;
ll num[sz];

void creat(ll x)
{
    num[id]=x;
    id++;
    if(x>3234566667)
        return;

    ll d=x%10;

    ll a=x*10+(d-1);
    if(d!=0 && a<=3234566667)creat(a);

    ll b=x*10+d;
    if(b<=3234566667)creat(b);

    ll k=x*10+(d+1);
    if(d!=9 && k<=3234566667)creat(k);

}
int main()
{


    ll i,j,k,n,p,a,b;



    for(i=1; i<=9; i++)
    {
        creat(i);
    }


    sort(num+1,num+id);


    cin>>n;

    cout<<num[n]<<endl;


    return 0;
}


Measured memory_bytes: 1024
import bisect

n = int(input())
a = list(map(int,input().split()))
a.sort()
sect = 0
col = 0
for i in range(400,3201,400):
    nsect = bisect.bisect_left(a,i)
    if nsect>sect:
        sect = nsect
        col += 1
print(max(col,1),col+n-nsect)

Measured memory_bytes: 62156
program ABC110A
    implicit none
    integer(8)::i
    integer(8),dimension(3)::A

    read(5,*)(A(i),i=1,3)
    A=iqsort(A)

    print'(i0)',A(1)+A(2)+10*A(3)
contains
    recursive function iqsort(ix) result(ires)
      integer(8), allocatable :: ires(:)
      integer(8), intent(in)  :: ix(:)
      integer :: k
      if (size(ix) <= 1) then 
        ires = ix
      else  
        k = ix(size(ix) / 2)
        ires = [iqsort(pack(ix, ix < k)), pack(ix, ix == k), iqsort(pack(ix, ix > k))] 
      end if
    end function iqsort
end program ABC110A

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


#define lp(i, n)         for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)     for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)     for(int i=(j);i>=(int)(n);--i)
#define sci(a)	scanf("%d",&a)
#define scll(a)	scanf("%lld",&a)
#define scii(a, b)	scanf("%d%d",&a, &b)
#define pri(a)	printf("%d\n",a)
#define prll(a)	printf("%lld\n",a)
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)



const double eps = 1e-8;

typedef  long long ll;

const ll mod = 1e9+7;

const int inf = 1<<30;
const int maxn = 900500;//2e5+5;
const double EPS = 1e-7;

//int a[maxn], b[maxn];

void no(){
    puts("-1");
    exit(0);
}

char s[maxn];


void solve() {
    scanf("%s",s);
    int n = strlen(s);
    if(s[0]=='0'||s[n-1]=='1')
        no();
    lpi(i,1,n-1) if(s[i]!=s[n-i-2])
        no();
    puts("1 2");
    int last = 1;
    lpi(i,1,n-1){
        printf("%d %d\n",last+1,i+2);
        if(s[i]=='1')
            last = i+1;
    }
}


int main(){
  //  freopen("in.txt","r",stdin);
    int tc = 1;
    //sci(tc);
    lp(tt,tc){
//        printf("Case %d:\n",tt+1);
        solve();
    }
}

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

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

int main() {
  int num;
  
  cin >> num;
  
  long long dp[num];
  long long h[num];
  
  for(int i = 0; i < num; i++) cin >> h[i];
  
  for(int i = 0; i < num; i++) dp[i] = 1LL << 60;
  
  dp[0] = 0;
  
  for(int i = 0; i < num; i++){
    chkMin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
    if(i > 1) chkMin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
  }
  
  cout << dp[num-1];
}


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

int main(void){
  int H, W;

  cin >> H >> W;
  do{
    for( int i = 0; i < H; i++ ){
      for( int j = 0; j < W; j++ ){
	cout << '#';
      }
      cout << endl;
    }
    cout << endl;

    cin >> H >> W;
  }while( H != 0 || W != 0);
  
  return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
  int a,b;
  cin >> a >> b;
  string s;
  cin >>s;
  bool c=false;
  bool d=true;
  if(s.size()==a+b+1)c=true;
  rep(i,s.size()){
      if(i==a && s.at(i)!='-'){
          d=false;
          break;
      }
      else if(i!=a && s.at(i)=='-'){
          d=false;
          break;
      }
  }
  if(c && d)cout << "Yes"<< endl;
  else cout << "No"<< endl;  
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.Comparator;
import java.util.Random;
import java.util.Map;
import java.util.HashMap;

class Main{
        public static void main(String args[]){
                Scanner sc = new Scanner(System.in);
                int H = sc.nextInt();
                int W = sc.nextInt();
                String[] grid = new String[H+2];
                for(int i=1; i<=H; i++){
                        grid[i] = sc.next();
                        grid[i] = "." + grid[i] + ".";
                }
                grid[0] = ".";
                grid[H+1] = ".";
                for(int j=1; j<=W+1; j++){
                        grid[0] += ".";
                        grid[H+1] += ".";
                }
/*
                for(int i=0; i<=H+1; i++){
                        for(int j=0; j<=W+1; j++){
                                System.out.print(grid[i].charAt(j));
                        }
                        System.out.println("");
                }
*/
                boolean ch = true;

                for(int i=1; i<=H; i++){
                        for(int j=1; j<=W; j++){
                                if(grid[i].charAt(j) == '#'){
                                        if( (grid[i].charAt(j-1) == '.' && grid[i].charAt(j+1) == '.')
                                        && (grid[i-1].charAt(j) == '.' && grid[i+1].charAt(j) == '.') ){
                                        ch=false;
                                        break;
                                        }
                                }

                        }
                        if(!ch)break;
                }

                if(ch){
                        System.out.println("Yes");
                }else{
                        System.out.println("No");
                }
        }
}


Measured memory_bytes: 24020
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <map>
#include <stdio.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll MOD = (ll)pow(10.0, 9.0) + 7;
pint dx[4] = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} };
char da[4] = { 'R', 'L', 'D', 'U' };
char dad[4] = { 'L', 'R', 'U', 'D' };
ll min(ll a, ll b)
{

	return (a < b) ? a : b;
}
ll max(ll a, ll b) { return (a > b) ? a : b; }

ll N;





string S[2 * 10000];
int main() {
	cin >> N;
	rep(i, N)
		cin >> S[i];


	ll ans = 0;
	ll cntA = 0, cntB = 0, cntAB = 0;
	rep(i, N) {
		rep(j, S[i].size() - 1) {

			if (S[i][j] == 'A' && S[i][j + 1] == 'B') {
				ans += 1;
			}




		}

		if (S[i][S[i].size() - 1] == 'A' && S[i][0] != 'B') {
			cntA += 1;
		}

		if (S[i][S[i].size() - 1] != 'A' && S[i][0] == 'B') {
			cntB += 1;
		}

		if (S[i][S[i].size() - 1] == 'A' && S[i][0] == 'B') {
			cntAB += 1;
		}

	}

	

	if (cntAB != 0) {
		ans += cntAB - 1;
	
	}

	if (cntAB != 0 && cntA > 0) {
		ans += 1;
		cntA--;
	}

	if (cntAB != 0 && cntB > 0) {
		ans += 1;
		cntB--;
	}
	
	
	ans += min(cntA, cntB);

	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 896
#include<bits/stdc++.h>
 
using namespace std;
 
int main() {
  string s, t;
  cin >> s >> t;
  int ans = 0;
  for (int i = 0; i < 3; ++i)
    ans += s[i] == t[i];
  cout << ans;
  	return 0;
}

Measured memory_bytes: 256
def swap(list,i,j,count):
    if(list[j]<list[i]):
        list[i],list[j]=list[j],list[i]
        count[0]+=1
        return 1
    return 0

def merge(list,left1,left2,right2,count):#ソート済みの２つの区間(list[left1]〜list[left2-1]と、list[left2]〜list[right2-1]）を結合する
    i=left1
    j=left2
    tmp_list=[]
    while(1):
        if(list[i] <=list[j]):
            tmp_list.append(list[i])
            i+=1
        else:
            tmp_list.append(list[j])
            j+=1
            count[0]+=left2-i
        if(i==left2):
            for k in range(j,right2):
                tmp_list.append(list[k])
            break
        if(j==right2):
            for k in range(i,left2):
                tmp_list.append(list[k])
            break
    for k in range(left1,right2):
        list[k]=tmp_list[k-left1]
    

                
                
    
        



def merge_sort(list,left,right,count):#list[left]からlist[right]までの要素でマージソート
    if(right  == left ):
        return None
    if(left+1 == right):
        swap(list,left,right,count)
    else:
        mid=(left + right)//2
        merge_sort(list,left,mid,count)
        merge_sort(list,mid+1,right,count)
        merge(list,left,mid+1,right+1,count)
        

n=int(input())
data=list(map(int,input().split()))
count=[0]
merge_sort(data,0,n-1,count)
print(count[0])


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


int N,M,x,y;

int main(){
	int sum = 0, mx = 0;
	scanf("%d%d",&N,&M);
	for(int i = 0; i < M; i++){
		scanf("%d%d",&x,&y);
		if(x < N){
			sum += N - x;
			if(N - x > mx){
				mx = N -x;
			}
		}
	}
	printf("%d\n",sum - mx);
	return 0;
}

Measured memory_bytes: 2700
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin>>N;
    while(100>N>999)
    {
        cin>>N;
    }

   int second = N / 100 % 10;
   int  third = N / 10 % 10;
    int fourth = N % 10;
    if(second==7||third==7||fourth==7){

      cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }

}


Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

int main(){
  int H,W;
  while(~scanf("%d %d",&H,&W)){
    if(H==0 && W==0) break;

    int res_h = H+1;
    int res_w = W+1;
    for(int h=150;h>=1;h--){
      for(int w=150;w>=1;w--){
	if(h*h + w*w < H*H + W*W) continue;
	if(h*h + w*w == H*H + W*W
	   && h <= H) continue;
	if(h >= w) continue;

	if(h*h + w*w == res_h*res_h + res_w*res_w
	   && h < res_h){
	  res_h = h;
	  res_w = w;
	}
	else if(h*h + w*w < res_h*res_h + res_w*res_w){
	  res_h = h;
	  res_w = w;
	}
      }
    }
    printf("%d %d\n",res_h,res_w);
  }
}

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

constexpr int INF = (1<<29);

int g[201][201];

int main()
{
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r(R);
    for (auto & x : r) {
        cin >> x;
        x--;
    }
    for (int i = 0; i < N; ++i)
        for (int j = i+1; j < N; ++j)
            g[j][i] = g[i][j] = INF;

    for (int i = 0; i < M; ++i) {
        int A, B, C;
        cin >> A >> B >> C;
        A --;
        B --;
        if (g[A][B] > C)
            g[A][B] = g[B][A] = C;
    }

    for (int k = 0; k < N; ++k)
        for (int i = 0; i < N; ++i)
            for (int j = i+1; j < N; ++j)
                if (g[i][j] > g[i][k] + g[k][j])
                    g[j][i] = g[i][j] = g[i][k] + g[k][j];
    sort(r.begin(), r.end());
    int ans = INT_MAX;
    do {
        int d = 0;
        for (int i = 0; i < R-1; ++i) {
            // cout << r[i] << ',';
            d += g[r[i]][r[i+1]];
        }
        // cout << endl;
        // cout << d << endl;
        ans = min(d, ans);
    } while (next_permutation(r.begin(), r.end()));
    cout << ans << endl;
    return 0;
}


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

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			int N = Integer.parseInt(str);
			int[] a = new int[N];
			for(int i = 0;i < N;i++) {
				str = br.readLine();
				a[i] = Integer.parseInt(str);
			}
			int s = 1;
			int count = 0;
			while(true) {
				if(s == 2) {
					break;
				}
				if(count == N) {
					count = -1;
					break;
				}
				s = a[s-1];
				count++;
			}
			System.out.println(count);
		}catch (Exception e) {
			System.exit(0);
		}
	}
}


Measured memory_bytes: 31116
package main

import (
        "fmt"
)

func solution(a, b int) string {
        out := ""
        switch {
        case a > 0:
                out = "Positive"
        case a < 0 && b > 0:
                out = "Zero"
        case b < 0:
                if abs(-a-b)%2 != 0 {
                        out = "Positive"
                } else {
                        out = "Negative"
                }
        }
        return out
}

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

func main() {
        var a, b int
        fmt.Scan(&a, &b)
        fmt.Println(solution(a, b))
}

Measured memory_bytes: 512
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <fstream>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#include <set>
typedef long long int ll;
typedef double ld;
using namespace std;

class CWelcomeToAtCoder {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int n,m,i;
	    in>>n>>m;
	    int a,ac=0,lwa=0;
	    string s;
	    map<int,bool> ma;
	    map<int,int>wa;
	    for(i=0;i<m;i++)
        {
	        in>>a>>s;

	        if(ma[a]== false && s[0]=='W')
	            wa[a]++;

            if(ma[a]== false && s[0]=='A') {
                ac++;
                lwa+=wa[a];
                ma[a]=true;
            }
        }
	    out<<ac<<" "<<lwa<<endl;
	}
};


int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
	CWelcomeToAtCoder solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 9600
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//11:48

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 200000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;

int DP[N][2], n, x;
pii dp[N];
vi G[N];

void DFS(int v, int p = 0){
	if (G[v].size() == 1 & v != 1){
		DP[v][0] = 1;
		DP[v][1] = 0;
		return;
	}
	int res = 0;
	int ted = 0;
	for (auto u:G[v]){
		if (u == p) continue;
		ted++;
		DFS(u, v);
		res += min(DP[u][0], DP[u][1]);
	}
	DP[v][0] = res + (ted / 2 + (ted % 2));
	ted--;
//	cout << res << ' ' << ted << '\n';
	
	DP[v][1] = res + (ted / 2 + (ted % 2));
//	cout << v << ' ' << DP[v][0] << ' ' << DP[v][1] << '\n';
}

int Best(vi A){
	int pnt = A.size() - 1;
	int res = 0;
	for (int i = 0; i < A.size() / 2; i++){
		if (pnt <= i) break;
		while (pnt > i && A[pnt] + A[i] > x) pnt--;
		if (pnt == i) break;
		res++;
	}
	return res;
}

void DFS2(int v, int p = 0){
	if (G[v].size() == 1 && v != 1){
		dp[v] = {0, 0};
		return;
	}
	int sm = 0;
	vi num;
	for (auto u:G[v]){
		if (u == p) continue;
		DFS2(u, v);
		sm += dp[u].F;
		if (dp[u].S + 1 == x)sm++;
		else num.pb(dp[u].S + 1);
	}
	if (SZ(num) == 0){
		dp[v] = {sm, 0};
		return;
	}
	sort(all(num));
	int B = Best(num);
	dp[v] = {B + SZ(num) - 2 * B + sm, 0};
//	cout << v << ' ' << B << endl;
	vi GG;
	for (int i = 0; i < (int)num.size() - 1; i++){
		GG.pb(num[i]);
	}
	B = Best(GG);
	if (dp[v].F == sm + B + SZ(num) - 2 * B - 1){	
//		cout << v << ' ' << dp[v].F << ' ' << dp[v].S << '\n';
		return;
	}
	int l = -1, r = SZ(num) - 1;
	dp[v].F = sm + B + SZ(num) - 2 * B - 1;
	while (r - l > 1){
		int md = (l + r) >> 1;
		GG.clear();
		for (int i = 0; i < SZ(num); i++){
			if (i != md) GG.pb(num[i]);
		}
		int xx = Best(GG);
		if (dp[v].F == xx + sm + SZ(num) - 2 * B - 1) r = md;
		else l = md;
	}
	dp[v].S = num[r];
	if (dp[v].S == x) dp[v] = {dp[v].F + 1, 0};	
//	cout << v << ' ' << dp[v].F << ' ' << dp[v].S << '\n';
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n - 1; i++){
		int v, u;
		cin >> v >> u;
		G[v].pb(u), G[u].pb(v);
	}
	memset(DP, 31, sizeof DP);
	DFS(1);
	cout << DP[1][0] << ' ';
	int l = 0, r = n;
	while (r - l > 1){
		x = (l + r) >> 1;
		DFS2(1);
		if ((dp[1].F + (dp[1].S != 0) <= DP[1][0])) r = x;
		else l = x;
	}
//	x = 3;
//	DFS2(1);
	cout << r;







	return 0;
}


Measured memory_bytes: 32384
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"

using namespace std;

const long long int MOD = 1000000007;

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


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

	cin >> N;
	while (N) {
		vector<int>num(N);
		vector<int>sum(N);
		for (int i = 0; i < N; i++) {
			string s;
			cin >> s;
			num[i] = s.size();
		}
		for (int i = 0; i < N; i++) {
			M = 0;
			K = 0;
			for (int j = i; j < N; j++) {
				M += num[j];
				if (M == 5 || M == 12 || M == 17 || M == 24 || M == 31) {
					K++;
				}
			}
			if (K == 5) {
				cout << i + 1 << endl;
				break;
			}
		}
		cin >> N;
	}

	return 0;
}

Measured memory_bytes: 3216
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array

main :: IO ()
main = do
  n <- readLn
  print $ solve n

-- solve :: Int -> Int
solve n = traceShow mp $ (combination n4 2)*(n2-2)+n14*(n4-1)+n24*(n2-1)+n74
  where
    -- mp = toCountMap . primeFactors $ factorial n
    mp = facts n
    n2 = Map.size . Map.filter (>=2) $ mp
    n4 = Map.size . Map.filter (>=4) $ mp
    n14 = Map.size . Map.filter (>=14) $ mp
    n24 = Map.size . Map.filter (>=24) $ mp
    n74 = Map.size . Map.filter (>=74) $ mp

facts n = toCountMap . join . map primeFactors $ [1..n]

primeFactors n | n < 2 = []
primeFactors n = go n [2,3,5,7,11,13,17,19]
   where
     go !n pps@(p:ps)
       | n < p*p   = [n]
       | r > 0     = go n ps
       | otherwise = p:go q pps
      where
        (q,r) = quotRem n p
     go n [] = [n]

combination m i = (factorial m) `div` (factorial i) `div` (factorial (m - i))

toCountMap :: (Ord k, Integral a) => [k] -> Map.Map k a
toCountMap xs = Map.fromListWith (+) $ zip xs (repeat 1)

factorial n = foldr (*) 1 [1..n]


Measured memory_bytes: 636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int n;
    cin >> n;
    int a[n];
    int max1 = 0;
    int max2 = 0;
    int max_num = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(max1 < a[i]){
            max_num = i;
            max1 = a[i];
        }
    }
    for(int i = 0; i < n; i++){
        if(i == max_num){
            continue;
        }else{
            max2 = max(max2,a[i]);
        }
    }
    for(int i = 0; i < n; i++){
        if(max1==a[i]){
            cout << max2 << endl;
        }else{
            cout << max1 << endl;
        }
    }
}

Measured memory_bytes: 2432
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    (N-1)
    (a_1^a_2^...^a_n)**(N-1) = a_1^a_2^...^a_n
    """
    N = read_int()
    A = read_ints()
    total = 0
    for a in A:
        total ^= a
    return ' '.join(map(str, (total^a for a in A)))


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 110216
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int u,v;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&u,&v);
        ans+=v-u+1;
    }
    printf("%d\n",ans);
}



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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define sz(x) int(x.size())
const int INF = 1001001001;
const ll mod = 998244353;
const ll INFL = 1001001001001001000;

vector<ll> divisor(ll N) {
    vector<ll> RES;
    for (ll I = 1; I*I <= N; I++) {
        if (N%I == 0) {
            RES.push_back(I);
            if (I != N/I) RES.push_back(N/I);
        }
    }
    return RES;
}

ll gcd(ll A, ll B) {
    return B ? gcd(B,A%B) : A;
}

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

int main() {
    ll n; cin >> n;
    if (n <= 100) {
        ll k = 1;
        while (1) {
            if ((k*(k+1)/2)%n == 0) {
                cout << k << endl;
                return 0;
            }
            k++;
        }
    }
    vector<ll> divi = divisor(2*n);
    ll ans = INFL;
    for (ll pp : divi) {
        ll p = pp;
        ll q = (2*n)/p;
        ll g = gcd(p,q);
        if (g != 1) continue;
        ll a,b;
        extGCD(p,q,a,b);
        a = -a;
        //printf("%lld %lld\n", a,b);
        if (a == 0 || b == 0) continue;
        if (a < 0 || b < 0) {
            ll dd1 = (-a+q-1)/q;
            ll dd2 = (-b+p-1)/p;
            ll dd = max(dd1, dd2);
            a += q*dd;
        }
        //printf("a = %lld, b = %lld\n", a,b);
        ans = min(ans, p*a);

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


Measured memory_bytes: 3784
N=int(input())
a=list(map(int,input().split()))
a.sort()
a=a[::-1]
ans=0
N-=1
if N%2==1:
    ans+=a[0]
    N-=1
    for i in range(N//2):
        ans+=2*a[i+1]
else:
    for i in range(N//2-1):
        ans+=2*a[i+1]
    ans+=a[0]+a[N//2]
print(ans)


Measured memory_bytes: 31516
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define pb push_back
using namespace std;
const int P=139;
const int mod=998244353;
const int maxn=1e6+5;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int minn=0xc0c0c0c0;
ll k,m,n,x,ans,f[maxn],pre[maxn];
int main()
{
    scanf("%lld%lld%lld",&n,&x,&m);
    for(int i=0;i<m;i++)
    	f[i]=-1;
    int a=0;
    ans=0;
    while(n--)
    {
    	f[x]=a++;
    	pre[x]=ans;
    	ans+=x;
    	x=x*x%m;
    	if(f[x]>=0)
    	{
    		int b=a-f[x];
    		ans+=(ans-pre[x])*(n/b);
    		n%=b;
		}
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 5248
def bomb(x,y):
    global M
    s=M[y+2]
    R=[-3,-2,-1,1,2,3]
    if s[x+2]=="0":return
    M[y+2]=s[:x+2]+"0"+s[x+3:]
    for d in R:
        bomb(x+d,y)
        bomb(x,y+d)
    return

A=range(14)
B=range(3,11)
M=["00000000000000" for i in A]
z="000"
n=input()
for i in range(n):
    s=raw_input()
    for j in B:
        M[j]=z+raw_input()+z
    x=input()
    y=input()
    bomb(x,y)
    print "Data %d:" %(i+1)
    for j in B:
        print M[j][3:-3]

Measured memory_bytes: 4284