akhauriyash/Code-Regression huggingface dataset:
def c_streamline(N, M, X):
    if N >= M:
        return 0
    X.sort()
    x_diff = [0] * M
    for i in range(1, M):
        x_diff[i] = X[i] - X[i - 1]
    x_diff.sort()
    ans = sum(x_diff[:M - N + 1])
    return ans

N, M = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]
print(c_streamline(N, M, X))

Measured memory_bytes: 13840
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i, 0, n) cin >> h[i];

  vector<priority_queue<P>> vp(n);
  rep(i, 0, n) vp[i].push(make_pair(h[i], i));

  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    vp[a].push(make_pair(h[b], b));
    vp[b].push(make_pair(h[a], a));
  }

  int ans = 0;
  rep(i, 0, n) {
    if (vp[i].size() == 1) {
      ans++;
      continue;
    }
    P p1 = vp[i].top();
    vp[i].pop();
    P p2 = vp[i].top();
    if (p1.first > p2.first && p1.second == i)
      ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 12140
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args){
		try(Scanner scan = new Scanner(System.in)){
			String S = scan.nextLine();
			
			int max = (int) Math.pow(2,S.length()-1);
			long ans = 0;
			
			for(int bit = 0; bit<max; bit++){
				int left = 0;
				for(int i = 0; i < S.length()-1; i++){
					if( ((bit >> i) & 1) > 0){
						ans += Long.valueOf(S.substring(left, i+1));
						left = i+1;
					}
				}
				ans+=Long.valueOf(S.substring(left, S.length()));
			}
			
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 22100
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
  int n;
  cin >> n;
  unsigned long min;
  min = 1000000000;
  int cnt = 0;
  vector<unsigned int> a(n);
  for(int i = 0 ; i < n ; i++){
    cin >> a[i];
    while(a[i]%2 == 0 ){
      a[i] /= 2;
      cnt++;
    }
    if(min > cnt){
      min = cnt;
    }
    cnt = 0;
  }

  cout << min << endl;
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;
lint p=1000*1000*1000+7;

int main(){
  int N,M;
  cin>>N>>M;
  int A[N],B[M];
  set<int> As;
  set<int> Bs;
  bool f=false;
  REP(i,N){
    cin>>A[i];
    if(As.find(A[i])!=As.end())f=true;
    As.insert(A[i]);
  }
  REP(i,M){
    cin>>B[i];
    if(Bs.find(B[i])!=Bs.end())f=true;
    Bs.insert(B[i]);
  }
  if(f){
    cout<<0<<endl;
    return 0;
  }
  sort(A,A+N);
  sort(B,B+M);
  lint ans=1;
  REP(i,N*M){
    int temp;
    int AN=N-(lower_bound(A,A+N,i+1)-A);
    int BN=M-(lower_bound(B,B+M,i+1)-B);
    if(As.find(i+1)!=As.end()){
      if(Bs.find(i+1)!=Bs.end()){
        temp=1;
      }else{
        temp=BN;
      }
    }else if(Bs.find(i+1)!=Bs.end()){
      temp=AN;
    }else{
      temp=AN*BN-(N*M-1-i);
    }
    if(temp<=0){
      cout<<0<<endl;
      return 0;
    }
    // cerr<<temp<<endl;
    ans*=temp;
    ans%=p;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
from string import ascii_uppercase

n, s = int(input()), input()


def gen(n):
    ret = {k: k for k in ascii_uppercase}
    for i, c in enumerate(ascii_uppercase):
        ret[c] = ascii_uppercase[(i + n) % len(ascii_uppercase)]
    return ret


table = gen(n)
ans = ""
for c in s:
    ans += table[c]
print(ans)


Measured memory_bytes: 3772
#include<stdio.h>
int main() {
	int i;
	char num[1000];
	while(1){
		int ans=0;
		scanf("%s", &num);
		if(num[0]=='0') break;
		for(i=0; num[i]!='\0'; i++){
			ans += num[i] - '0';
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2100
N, Y = map(int, input().split())

def main():
  for x in range(N + 1):
    for y in range(N + 1 - x):
      z = N - x - y
      if 10000*x + 5000*y + 1000*z == Y:
        print(x, y, z)
        return
  print('-1 -1 -1')      

main()


Measured memory_bytes: 2940
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    // int N = scanner.nextInt();
    // scanner.nextLine();
    // int[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    static void solve(Scanner scanner) {
        String s = scanner.nextLine();
        if (s.charAt(0) == s.charAt(1)) {
            System.out.printf("%d %d\n", 1, 2);
            return;
        }
        for (int i = 0; i < s.length() - 2; i++) {
            char c1 = s.charAt(i);
            char c2 = s.charAt(i + 1);
            char c3 = s.charAt(i + 2);
            if (c1 == c2 || c1 == c3 || c2 == c3) {
                System.out.printf("%d %d\n", i + 1, i + 3);
                return;
            }
        }
        System.out.printf("%d %d\n", -1, -1);
    }

}


Measured memory_bytes: 25676
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		String[] line = reader.readLine().split(" ");
		int n = Integer.parseInt(line[0]);
		int q = Integer.parseInt(line[1]);
		Queue<String[]> queue = new ArrayDeque<String[]>();
		for (int i = 0; i < n; i++) {
			queue.add(reader.readLine().split(" "));
		}
		String[] work = new String[2];
		int elapse = 0;
		while ((work = queue.poll()) != null) {
			int time = Integer.parseInt(work[1]);
			if (time <= q) {
				elapse += time;
				builder.append(work[0]).append(" ").append(elapse).append("\n");
			} else {
				time -= q;
				elapse += q;
				work[1] = String.valueOf(time);
				queue.add(work);
			}

		}
		System.out.print(builder);
	}
}

Measured memory_bytes: 61740
import java.util.*;

public class Main {

	static int N;
	static HashMap<Integer, HashMap<Integer, Integer>> edges;
	static int[] values;
	static boolean[] visited;
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		N = in.nextInt();
		int M = in.nextInt();
		
		edges = new HashMap<Integer, HashMap<Integer, Integer>>();
		Input[] inputs = new Input[M];
		
		for (int i = 0; i < M; i++) {
			int l = in.nextInt();
			int r = in.nextInt();
			int c = in.nextInt();
			
			if (edges.containsKey(l)) {
				HashMap<Integer, Integer> e = edges.get(l);
				e.put(r, c);
			} else {
				HashMap<Integer, Integer> e = new HashMap<Integer, Integer>();
				e.put(r, c);
				edges.put(l, e);
			}
			
			if (edges.containsKey(r)) {
				HashMap<Integer, Integer> e = edges.get(r);
				e.put(l, -1 * c);
			} else {
				HashMap<Integer, Integer> e = new HashMap<Integer, Integer>();
				e.put(l, -1 * c);
				edges.put(r, e);
			}
			
			inputs[i] = new Input(l, r, c);
		}
		
		values = new int[N + 1];
		visited = new boolean[N + 1];
		
		for (int i = 1; i < N + 1; i++) {
			if (visited[i] == false) {
				dfs(i, 0);
			}
		}
		
		boolean answer = true;
		
		for (int i = 0; i < M && answer; i++) {
			if (values[inputs[i].l] + inputs[i].c != values[inputs[i].r]) {
				answer = false;
			}
		}
		
		System.out.println(answer ? "Yes" : "No");
	}
	
	public static void dfs(int n, int val) {
		visited[n] = true;
		values[n] = val;
		
		HashMap<Integer, Integer> e = edges.get(n);
		
		if (e == null) {
			return;
		}
		
		for (int next : e.keySet()) {
			if (visited[next] == false) {
				dfs(next, val + e.get(next));
			}
		}
	}
}

class Input {
	int l;
	int r;
	int c;
	
	public Input(int l, int r, int c) {
		this.l = l;
		this.r = r;
		this.c = c;
	}
}

Measured memory_bytes: 230608
package main

import "fmt"

func main() {
	var h int
	var n int

	fmt.Scan(&h)
	fmt.Scan(&n)

	hh := h

	for i := 0; i < n; i++ {
		a := 0
		fmt.Scan(&a)
		hh = hh - a
	}
	if hh <= 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}


Measured memory_bytes: 6324
#include <stdio.h>
int main() {
    long long L, R;
    int ans = 2020;
    scanf("%d%d",&L,&R);
    if (R-L+1 >= 2019) {
        printf("%d\n", 0);
    }
    else {
        L = L % 2019;
        R = R % 2019;
        for (int i=L; i<R+1;i++) {
            for (int j=i+1; j<R+1; j++){
                if (ans > ((i*j) % 2019)) {
                    ans = ((i*j) % 2019);
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 128
// Your code here!
#include <stdio.h>
#include <math.h>
double a,b,c;
int main(){
scanf("%lf %lf",&a,&b);
c=floor(log10(b)+1);
c=a*pow(10,c)+b;
if(pow(floor(sqrt(c)),2)==c){
printf("Yes");
}else{
printf("No");
}
return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <cstdint>
#include <numeric>
#define INF 1000000000
#define LLINF 2000000000000000
#define MOD 1000000007
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

signed main(){
  int x;
  int n = 100;
  cin >> x;
  int cnt = 0;
  while(n < x){
    cnt++;
    n = n*1.01;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n,k;
  cin >> n >> k;
  vec a(n);
  for(ll i=0;i<n;i++) cin >> a[i];
  mat dp(n+1,vec(k+1));
  dp[0][0]=1;
  for(ll i=0;i<n;i++) {
    vec s(k+1);
    s[0]=dp[i][0];
    for(ll j=0;j<k;j++) {
      s[j+1]=(s[j]+dp[i][j+1])%mod;
    }
    for(ll j=0;j<=k;j++) {
      dp[i+1][j]=s[j];
      if(j-a[i]>0) {
        dp[i+1][j]=(dp[i+1][j]-s[j-a[i]-1]+mod)%mod;
      }
    }
  }
  cout << dp[n][k] << endl;
}

Measured memory_bytes: 83144
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string s;
    int w;
    cin >> s >> w;
    rep(i,s.size()){
        if(i%w==0)cout << s[i];
    }
    cout << endl;
}

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

#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
#define vec vector<int>
#define dead not_bad
#define bad gooood

#define left not_right
#define y1 what

using namespace std;

const int N = (int) 1e3 + 10;
const int M = (int) 1e6 + 10;
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const int ALPHA = 26;
const int mod = INF + 2;
const double PI = 3.14159265359;
const ld EPS = (ld) 1e-12;

const int nx[4] = {0, 0, -1, 1};
const int ny[4] = {1, -1, 0, 0};

int n;
char ch[N][N];
int h[2][N][N], p[N];

void add(int &x, int y) {
  x += y;
  if (x >= INF)
    x -= INF;
  if (x < 0)
    x += INF;
}

int mult(int x, int y) {
  return 1ll * x * y % INF;
}

int get_hash(int i1, int j1, int i2, int j2) {
  int ans;
  if (i1 == i2) {
    ans = h[0][i1][j2];
    if (j1)
      add(ans, -h[0][i1][j1 - 1]);
    ans = mult(ans, p[n + n - 1 - j2]);
  } else {
    ans = h[1][j1][i2];
    if (i1)
      add(ans, -h[1][j1][i1 - 1]);
    ans = mult(ans, p[n + n - 1 - i2]);
  }
  return ans;
}

int main() {
  #define fn "saddle"
  #ifdef witch
      freopen("input.txt", "r", stdin);
  //    freopen("output.txt", "w", stdout);
  #else
      //freopen(fn".in", "r", stdin);
      //freopen(fn".out", "w", stdout);
  #endif
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> ch[i][j];
      ch[i][j + n] = ch[i][j];
      ch[i + n][j] = ch[i][j];
      ch[i + n][j + n] = ch[i][j];
    }
  }
  p[0] = 1;
  for (int i = 1; i < n + n; i++) {
    p[i] = mult(p[i - 1], 31);
  }
  for (int i = 0; i < n + n; i++) {
    for (int j = 0; j < n + n; j++) {
      add(h[0][i][j] = (j ? h[0][i][j - 1] : 0), mult(ch[i][j] - 'a' + 1, p[j]));
      add(h[1][j][i] = (i ? h[1][j][i - 1] : 0), mult(ch[i][j] - 'a' + 1, p[i]));
 //     cout << ch[i][j];
    }
  //  cout << endl;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      bool ok = 1;
      for (int k = 0; k < n; k++) {
        if (get_hash(i + k, j + k, i + k, j + n - 1) != get_hash(i + k, j + k, i + n - 1, j + k)) {
          ok = 0;
        }
      }
   //   if (!ok) cout << i << ' ' << j << endl;
      ans += ok;
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    string S, T = "hi";
    cin >> S;
    for (int i = 0; i < 10; i++){
        if (S == T){
            cout << "Yes" << endl;
            return 0;
        }
        T = T + "hi";
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

ll A, B, C, D;

ll pre(ll a, ll b, ll c) {
	return a / c - (b - 1) / c;
}

ll gcd(ll a, ll b) {
	if(b == 0) return a;
	else return gcd(b, a % b);
}

void solve() {
	cin >> A >> B >> C >> D;
	ll lcm = C * D / gcd(C, D);
	cout << (B - A + 1) - pre(B, A, C) - pre(B, A, D) + pre(B, A, lcm) << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define N 300005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
main()
{
    int x;
    cin>>x;
    for(int i=400,j=8;i<=1999;i+=200,j--)
    {
        if(x>=i&&x<=i+199)
        {
            cout<<j<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3628
program example
	implicit none
    
    integer(8) :: X,i,j
    
    read(*,*) X
    
    i=X
    
    do
   
    	do j=2,i
        
        	if (i==2) then
            	write(*,*) i
                goto 1
        	else if (mod(i,j)==0) then
            	exit
            end if
        end do
        
        if(j==i) then
        	write(*,*) i
            exit
        end if
        
        i=i+1
        
    end do
    
1 end program example

Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  string s;
  cin>>s;
  int n=s.size();
  if(s[0]==s[n-1]){
    cout<<(n%2?"Second":"First")<<endl;
  }else{
    cout<<(n%2==0?"Second":"First")<<endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    string s;
    cin >> s;
    int a, z;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'A'){
            a = i;
            break;
        }
    }
    
    for(int i = s.size() - 1; i >= 0; --i){
        if(s[i] == 'Z'){
            z = i;
            break;
        }
    }
    cout << z - a + 1 << endl;
    return 0;
}


Measured memory_bytes: 640
N = int(input())
t = []
for _ in range(N):
    A = int(input())
    tt = []
    for _ in range(A):
        tt.append(list(map(int, input().split())))
    t.append(tt)
ans = 0
for b in range(1 << N):
    f = True
    c = 0
    for i, tt in enumerate(t):
        if b >> i & 1:
            c += 1
            for x, y in tt:
                if b >> (x - 1) & 1 != y:
                    f = False
                    break
    if f:
        ans = max(ans, c)

print(ans)


Measured memory_bytes: 3064
#![allow(non_snake_case)]
#![allow(unused_variables)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let B: Vec<i64> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };

    let ans = B[0] + (0..(N - 2)).map(|i| std::cmp::min(B[i], B[i + 1])).sum::<i64>() + B[N - 2];

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


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e5;
const int size=1e5;
const int inf=1e9;
int main(){
	int N;cin>>N;
	string s;cin>>s;
	int cnt=0;
	rep(i,2,s.size()){
		if(s[i-2]=='A'&&s[i-1]=='B'&&s[i]=='C') cnt++;
	}cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=110;
char s[N];
int n,k,sum;
ll ans;
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	scanf("%d",&k);
	for (int i=1;i<=n;i++) {
		if (i==1||s[i]!=s[i-1]) {
			ans+=sum/2; sum=1;
		} else sum++;
	}
	ans+=sum/2;
	if (sum==n) {
		printf("%lld\n",(ll)n*k/2);
	} else if (s[1]==s[n]){
		int sum1=1;
		for (int i=2;i<=n;i++) if (s[i]==s[i-1]) sum1++; else break;
		ans=ans-sum/2-sum1/2;
		ans=(ll)ans*k;
		ans+=(ll)(sum1+sum)/2*(k-1);
		ans+=(ll)sum/2+sum1/2;
		printf("%lld\n",ans);
	} else printf("%lld\n",(ll)ans*k);
} 

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

using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    ll a[200009], sum = 0;
    for(int i=0; i<n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    ll res = 500000000000000LL;
    ll ps = a[0];
    for(int i=1; i<n; i++) {
        res = min(res, abs(sum - 2 * ps));
        ps += a[i];
    }
    cout << res << endl;
}

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

#define rep(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define repn(i, m, n) for (ll (i) = (m) ; (i) < (ll)(n) ; ++(i))
#define rep_rev(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define repn_rev(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= (m) ; --(i))

#define INF 2e9
#define ll long long
#define MOD 1e9+7

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

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

    vector<pair<int, int> > pairs(n);

    // 入力
    for(int i=0; i<n; i++){
        int a;
        cin>>a;
        pairs[i] = make_pair(i+1, a);
    }

    // b順にソート
    sort(pairs.begin(), pairs.end(), compare_by_b);

    for(int i=0; i<n; i++){
        cout<<pairs[i].first<<" ";
    }
    cout<<endl;

}

Measured memory_bytes: 1664
#include <iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int sum=0;
	if(a>b){
		sum+=a;
		a--;
		if(a>b)sum+=a;
		else
		sum+=b;
	}
	else{
		sum+=b;
		b--;
		if(b>a)sum+=b;
		else
		sum+=a;
	}
	cout<<sum;
	return 0;
}

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

int main()
{
  string w;
  string ans="Yes";

  cin >> w;
  int n = w.length();
  for(int i='a';i<='z';i++){
    int cnt=0;
    for(int j=0;j<n;j++){
      if (i==w[j])
	cnt++;
    }
    if(cnt%2==1){
      ans="No";
      break;
    }
  }
  cout<< ans  <<endl;
}


Measured memory_bytes: 256
# input
N = int(input())
T = list(map(int, input().split()))
M = int(input())
P = [list(map(int, input().split())) for _ in range(M)]

for i in range(M):
    temp = T[P[i][0] - 1]
    T[P[i][0] - 1] = P[i][1]
    print(sum(T))
    T[P[i][0] - 1] = temp

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

void solve(void){
	int N;
	cin >> N;
	string S;
	cin >> S;
	int cnt = 0;
	rep(N, i) {
		cnt += S[i] == 'E';
	}
	int ans = cnt-(S[0]=='E');

	rep(N-1, i) {
		if (ans <= 0) {
			cout << 0 << endl;
			return;
		}
		if (S[i] == 'E') cnt--;
		else cnt++;
		ans = min(ans, cnt-(S[i+1]=='E'));
	}
	cout << ans << endl;
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int n;
	cin>>n;
	double ans=0;
	double sum=0;
	for(int i=1;i<=n;i++){
		int p=i;
		if(p%2==1){
			ans++;
		}
	}
	sum=ans/n;
	printf("%.10lf",sum);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
const int MAXL = 1000000001;
typedef pair<int, int> SEG;
typedef pair<SEG, int> S;
//int data[MAXL];
int main(){
  int N;
  while(cin>>N && N){
    //memset(data, -1, sizeof(data));
    vector<S> data;
    data.push_back(S(SEG(-1, 0), -1));
    REP(time, N){
      string cmd; cin>>cmd;
      if(cmd == "W"){
        int l, s; cin>>l>>s;
        vector<S> add;
        REP(i, data.size()-1){
          if(s == 0) break;
          if(data[i].first.second < data[i+1].first.first){
            int fst = data[i].first.second;
            int len = min(s, data[i+1].first.first - fst);
            add.push_back(S(SEG(fst, fst + len), l));
            s -= len;
          }
        }
        if(s > 0){
          int fst = data.back().first.second;
          int len = s;
          add.push_back(S(SEG(fst, fst + len), l));
        }
        REP(i, add.size()) data.push_back(add[i]);
        sort(data.begin(), data.end());
        /*
        REP(i, MAXL){
          if(S == 0) break;
          if(data[i] == -1){
            data[i] = l;
            S --;
          }
        }
        */
      }else if(cmd == "D"){
        int l; cin>>l;
        //REP(i, MAXL)if(data[i] == l)data[i] = -1;
        vector<S>::iterator it = data.begin();
        while(it != data.end()){
          if(it->second == l){
            it = data.erase(it);
          }else{
            it++;
          }
        }
      }else if(cmd == "R"){
        int P; cin>>P;
        int res = -1;
        REP(i, data.size())if(data[i].first.first <= P && P < data[i].first.second){
          res = data[i].second;
        }
        cout<< res <<endl;
        //cout<<data[P]<<endl;
      }else{
        assert(false);
      }
      //REP(i, data.size())printf("%d:(%d, %d) ", data[i].second, data[i].first.first, data[i].first.second); cout<<endl;
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1012
#include <iostream>

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
  if (b > a) return gcd(b, a);
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

bool solve(ll A, ll B, ll C, ll D) {
  if (B > D) {
    return false;
  }
  if (B <= C) {
    if (A >= B) {
      return true;
    } else {
      return false;
    }
  }
  if (A < B) {
    return false;
  }

  ll g = gcd(B, D);
  ll m = B - g + (A % g);
  if (m > C) {
    return false;
  } else {
    return true;
  }
}

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    if (solve(A, B, C, D)) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define tmp(x) std::cout<<"& "<<(x)<<" &\n"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define mp make_pair
#define pii pair<int,int>
typedef long long ll;

using namespace std;
const int maxn=1e6+100;
int n,t;
int a[maxn],vis[maxn];
int isprime[maxn],p2[maxn];
int prime[maxn];
void genep(){
    int cnt=1;
    for(int i=2;i<maxn;++i){
        if(!isprime[i]){prime[cnt++]=i;   }
        for(int j=1;j<=cnt&&i*prime[j]<=maxn;++j){
            isprime[i*prime[j]]=1;
            if(i%prime[j]==0){
                break;
            }
        }
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    genep();
    int fl=1;
    rep(i,1,n){
        cin>>a[i];++vis[a[i]];
        if(a[i]>1&&vis[a[i]]>1)fl=0;
    }
    rep(uu,1,maxn){
        if(vis[uu]){
            int q=sqrt(uu)+1,j=1,v=uu;
            while(prime[j]<=q){
                if(v%prime[j]==0){
                    while(v%prime[j]==0)v/=prime[j];
                    if(!p2[prime[j]])p2[prime[j]]=1;
                    else {fl=0; ;}
                }
                ++j;
            }
            if(v>1){
                if(!p2[v])p2[v]=1;
                else fl=0; ;
            } 
        }
    }
    if(fl){
        cout<<"pairwise coprime";
    }
    else{
        int rr=a[1];
        rep(i,2,n){
            rr=__gcd(a[i],rr);
            if(rr==1)break;
        }
        if(rr==1)cout<<"setwise coprime";
        else cout<<"not coprime";
    }



    return 0;
}


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

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

int a[3];

int main () {
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
	bool is = 0;
	forn(i, 3) {
		cin >> a[i];
		is |= !(a[i] & 1);
	}	
	if (is) {
		cout << 0 << endl;
	} else {
		sort(a, a + 3);
		cout << 1ll * a[0] * a[1] << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <stdlib.h>
#include <iomanip>
#include <iostream>
#include <string.h>
#include <algorithm>
using  namespace  std;

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define ull unsigned long long
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define mst(ss,b) memset(ss,b,sizeof(ss));
#ifdef Cyberdebut
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef pair <int, int> pii;
ll gcd(ll a, ll b){return a ? gcd(b%a,a):b;}
ll pow_mod(ll x, ll n, ll mod){ll ret=1LL;while(n){if(n&1)ret=ret*x%mod;x=x*x%mod;n>>=1;}return ret;}
const int inf = 0x3f3f3f3f;
const ll INF = (1LL<<62)-1;
const ll mod = 1e9+7;
const int N = 300+5;

int a[N][N];
bool vis[N];
int n, m;
int h[N], cnt[N];

int  main(){
    scanf("%d%d", &n, &m);
    for(int i=1; i<=n; i++)for(int j=1; j<=m; j++)scanf("%d", &a[i][j]);
    for(int i=1; i<=n; i++)h[i] = 1;
    int ans = n;
    for(int i=1; i<=m; i++){
        mst(cnt, 0);
        for(int i=1; i<=n; i++)++cnt[a[i][h[i]]];
        int mx = 1;
        for(int i=2; i<=m; i++)if(cnt[i] > cnt[mx])mx = i;
        vis[mx] = 1;
        ans = min(ans, cnt[mx]);
        for(int i=1; i<=n; i++)while(vis[a[i][h[i]]])h[i]++;
    }
    printf("%d\n", ans);
    return 0;
}


// lower_bound()
// __builtin_popcount()
// ios::sync_with_stdio(false);
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
// const double eps=1e-12;
// #pragma comment(linker,"/STACK:102400000,102400000")


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

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n){
    cin >> a.at(i);
  }
  bool ans = true;
  rep(i, n)
  {
    if(a.at(i)%2==0&&a.at(i)%3!=0&&a.at(i)%5!=0){
      ans = false;
    }
  }
  if(ans){
    cout << "APPROVED"<< "\n";
  }
  else{
    cout << "DENIED"<< "\n";
  }
}

Measured memory_bytes: 256
// abc148_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int A, B;
    cin >> A >> B;

    int ans = 6 - A - B;
    print(ans);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int i, j, k, h, w;
   
    cin >> h >> w;
    while(h>0 || w>0)
    {
        for(i=1; i<=h; i++)
        {
            for(j=1; j<=w; j++)
            {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
        cin >> h >> w;
    }
}


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

ll knapSack(ll W, ll wt[], ll val[], ll n)
{
    ll i, w;
    ll K[n+1][W+1];

    // Build table K[][] in bottom up manner
    for (i = 0; i <= n; i++)
    {
        for (w = 0; w <= W; w++)
        {
            if (i==0 || w==0)
                K[i][w] = 0;
            else if (wt[i-1] <= w)
                K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]);
            else
                K[i][w] = K[i-1][w];
        }
    }

    return K[n][W];
}

int main()
{
    ll n , W;
    cin >> n >> W;
    ll val[n], wt[n];

    for(ll i=0;i<n;i++)
        cin >> wt[i] >> val[i];

    cout << knapSack(W, wt, val, n);

    return 0;
}

Measured memory_bytes: 79104
import sys
input = lambda: sys.stdin.readline().rstrip()

N, M = map(int, input().split())

def divisor(num):
    res = []
    for i in range(1, int(num**0.5)+1):
        if num % i == 0:
            res.append(i)
            res.append(num//i)
    return res

div = divisor(M)
div.sort(reverse=True)
for num in div:
    if num <= M//N:
        print(num)
        exit()

Measured memory_bytes: 64092
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    int n;
    cin >> n;
    vl a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    // pos start
    ll ret1 = 0;
    ll sum1 = 0;
    for (int i = 0; i < n; ++i) {
        sum1 += a[i];
        if (i % 2 == 0 && sum1 <= 0) {
            ret1 += -sum1 + 1;
            sum1 = 1;
        }
        if (i % 2 == 1 && sum1 >= 0) {
            ret1 += sum1 + 1;
            sum1 = -1;
        }
    }
    ll ret2 = 0;
    ll sum2 = 0;
    for (int i = 0; i < n; ++i) {
        sum2 += a[i];
        if (i % 2 == 1 && sum2 <= 0) {
            ret2 += -sum2 + 1;
            sum2 = 1;
        }
        if (i % 2 == 0 && sum2 >= 0) {
            ret2 += sum2 + 1;
            sum2 = -1;
        }
    }
    cout << min(ret1, ret2) << "\n";
    return 0;
}

Measured memory_bytes: 1024
# エラトステネスの篩, フェルマーの小定理
def make_prime_table(N):
    sieve = [0] * (N + 1)
    sieve[0] = -1
    sieve[1] = -1
    for i in range(2, N + 1):
        if sieve[i] != 0:
            continue
        sieve[i] = i
        for j in range(i * i, N + 1, i):
            if sieve[j] == 0:
                sieve[j] = i
    return sieve


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

m = 1000000007

sieve = make_prime_table(1000000)

lcm_factors = {}
for i in range(N):
    t = []
    a = A[i]
    while a != 1:
        if len(t) != 0 and t[-1][0] == sieve[a]:
            t[-1][1] += 1
        else:
            t.append([sieve[a], 1])
        a //= sieve[a]
    for k, v in t:
        if k not in lcm_factors or lcm_factors[k] < v:
            lcm_factors[k] = v

lcm = 1
for k in lcm_factors:
    for i in range(lcm_factors[k]):
        lcm *= k
        lcm %= m

result = 0
for i in range(N):
    result += lcm * pow(A[i], m - 2, m)
    result %= m
print(result)


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

void swap(int * x, int * y) {
    int tmp;
    tmp = *x;
    *x = *y;
    *y = tmp;
    return; 
}

int main(void) {
  vector<int> x;
  vector<int> y;

  while(1) {
    int num1, num2;
    cin >> num1 >> num2;
    if(num1 == 0 && num2 == 0) {
      break;
    } else {
      x.push_back(num1);
      y.push_back(num2);
    }
  }

  for(int i = 0; i < x.size(); i++) {
    if(x[i] > y[i]){
        swap(&x[i], &y[i]);
    }
    cout << x[i] << " " << y[i] << endl;
  }
  return 0;
}


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

#define forn(i, n) for (int i = 0; i < n; i++)
#define re return
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define point pair <int, int>
#define re return
#define se second
#define fi first
#define mp(a, b) make_pair(a, b)
#define mp1(a, b, c, d) make_pair(mp(a, b), mp(c, d))
using namespace std;
typedef long long ll;
const int mod = int(1e9) + 7;
const int ma = 2 * 128 * 1024;
const int k1 = 8, k2 = 8;
using namespace std;

int n, m;

int main() {
    iostream::sync_with_stdio(0);
    string s;
    cin >> s;
    int ans = 0;
    forn (i, sz(s)) ans += s[i] - '0';
    if (ans == 1) cout << 10;
    else
        cout << ans;
} 

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int H,W;
  register int i,s;

  while(1){
    scanf("%d %d",&H,&W);
    if((H == 0) & (W == 0)){
      break;
    }
    for(i = 0;i < H;i++){
      for(s = 0;s < W;s++){
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0;i<(intl)(n);i++)
#define Rep1(i,n) for(intl i=1;i<(intl)(n)+1;i++)
#define vec vector
#define fi first
#define se second
#define pub push_back
#define pob pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
#define All(a) (a).begin(),(a).end()
using intl = int64_t;
using vi = vec<intl>;
using vvi = vec<vi>;
using pi = pair<intl,intl>;
using vpi = vec<pi>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr intl INF = 9223372036854775807;


int main(){
  intl A,B,V,W,T;
  cin >>A>>V>>B>>W>>T;
  if( V-W == 0){cout <<"NO";return 0;} 
  if(  V-W > 0 && abs(A-B) <= T*(V-W)){cout <<"YES";}
  else{cout <<"NO";}
}
  

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#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 INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  ll N;
  cin >> N;
  ll s[N];
  ll sum = 0;
  REP(i, N) {
    cin >> s[i];
    sum += s[i];
  }
  sort(s, s + N);

  REP(i, N) {
    if (sum % 10 == 0) {
      if (s[i] % 10 == 0) {
        continue;
      } else {
        sum -= s[i];
      }
    } else {
      cout << sum;
      return 0;
    }
  }

  cout << 0;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int queue_point = 0;
int queue_size = 0;
int queue[8192];

void enqueue(int p) {
  queue[queue_size++] = p;
}
int dequeue() {
  if (queue_point >= queue_size) return -1;
  else return queue[queue_point++];
}

int stack[4] = {-1, 0, 0, 0};
int stack_pointer = 0;
void push(int p) {
  stack[stack_pointer++] = p;
}
int pop() {
  return stack[--stack_pointer];
}

// 白のマス数から最短経路長を引くとすぬけ君の最大スコアになる
int main() {
  int i, j;
  int H, W;
  int p, goal, distance = 0;
  char S[50][51];
  int visited[50][50];
  int white = 0;

  scanf("%d %d", &H, &W);
  goal = H*W-1;
  for (i = 0; i < H; i++) {
    scanf("%s", S[i]);
    for (j = 0; j < W; j++) {
      if (S[i][j] == '.') {
        visited[i][j] = 0;
        white++;
      }
      else visited[i][j] = 1;
    }
  }

  int n = 0;

  // 幅優先探索
  enqueue(0);
  while ((n = queue_size - queue_point) > 0) {
    distance++;
    while (n--) {
      p = dequeue();
      if (p == goal) goto end;
      i = p / W;
      j = p - W*i;
      visited[i][j] = 1;
      if (i > 0   && !visited[i-1][j]) {
        enqueue(W*(i-1)+j);
        visited[i-1][j] = 1;
      }
      if (i < H-1 && !visited[i+1][j]) {
        enqueue(W*(i+1)+j);
        visited[i+1][j] = 1;
      }
      if (j > 0   && !visited[i][j-1]) {
        enqueue(W*i+j-1);
        visited[i][j-1] = 1;
      }
      if (j < W-1 && !visited[i][j+1]) {
        enqueue(W*i+j+1);
        visited[i][j+1] = 1;
      }
    }
  }

end:
  if (distance < H+W-1) {
    puts("-1");
  } else {
    printf("%d\n", white - distance);
  }

  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
vector<int> l(n);
for(int i=0;i<n;i++){
cin>>l[i];
}
sort(l.begin(),l.end());
int ans=0;
for(int i=0;i<k;i++){
ans+=l[n-1-i];
}
cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
double a,b;
while(cin >> a >> b){
string ans="NA";
if(a<70.0&&b<148.0)ans="E";
if(a<55.0&&b<116.0)ans="D";
if(a<50.0&&b<105.0)ans="C";
if(a<43.0&&b<89.0)ans="B";
if(a<40.0&&b<83.0)ans="A";
if(a<37.5&&b<77.0)ans="AA";
if(a<35.5&&b<71.0)ans="AAA";
cout << ans << "\n";
}
return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define IN(type, n) type n; cin >> n
using namespace std;

int main() {
  int flag = 0;
  REP (i, 3) {
    IN (char, c);
    if (c == 'R') flag |= 1 << i;
  }
  switch (flag) {
    case 0:
      cout << 0 << endl;
      break;
    case 3:
    case 6:
      cout << 2 << endl;
      break;
    case 7:
      cout << 3 << endl;
      break;
    default:
      cout << 1 << endl;
      break;
  }

  return 0;
}


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

int main() {
  int N, M, C;
  cin >> N >> M;
  C = 0;

  if (N == 1 && M == 1) {
    // 偶数にならない
  }
  if (N >= 2) {
    C = C + N * (N-1) / 2; // Nから2個で偶数
  }
  if (M >= 2) {
    C = C + M * (M-1) / 2; // Mから2個で偶数
  }
  
  cout << C;

}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int m,a,b,x,y,r,g,i;
	for(;scanf("%d%d%d%d",&m,&a,&b,&x)>3;){
		for(g=0,i=1;i<m;i++){
			scanf("%d",&y);
			if(a<=i&&i<=b && x-y>=g)g=x-y,r=i;
			x=y;
		}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 1028
import itertools
n = int(input())
a = []
for i in range(1,n+1):
    a.append(i)
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

r = []
for z in list(itertools.permutations(a, n)):
    r.append(z)
print(abs((r.index(p)+1)-((r.index(q)+1))))

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

void setmax(ll& a, ll b) {
  if (a < b) a = b;
}

int main() {
  in(ll, n);
  vector<pair<ll, ll>> ai(n);
  rep(i, n) {
    cin >> ai[i].first;
    ai[i].second = i;
  }
  sort(all(ai), greater());
  vector<vector<ll>> dp(n + 1, vector(n + 1, 0LL));
  rep(i, n) rep(j, i + 1) {
    auto [a, index] = ai[i];
    setmax(dp[i + 1][j + 1], dp[i][j] + a * abs(index - j));
    setmax(dp[i + 1][j], dp[i][j] + a * abs(index - (n - 1 - (i - j))));
    // dbg(a, index, j, dp[i][j], dp[i + 1][j + 1], dp[i + 1][j]);
  }
  ll ans = 0;
  rep(i, n + 1) setmax(ans, dp[n][i]);
  out(ans);
}


Measured memory_bytes: 34624