akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(n);
// string p=s.substr(0,len);
// string q=s.insert(0,str);
// sort(arr, arr+n, greater<int>());
// cout<<fixed<<setprecision(9)<<pi<<endl
// const  double pi = acos(-1.0);
// sort(v.rbegin(),v.rend());
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
	int x;
	cin>>x;
	if(x==0)
	{
		cout<<1<<endl;
	}	
	else
	{
		cout<<0<<endl;
	}
}

Measured memory_bytes: 3576
n, x = input().split()
n = int(n)
x = int(x)
m = []
i_min = 0
result = 0

for i in range(n):
 m.append(int(input()))

for i in range(len(m)):
 x = x - m[i]
 result = result + 1

for i in range(len(m)):
 if m[i_min] > m[i]:
  i_min = i

for i in range(x):
 if x >= m[i_min]:
  result = result + 1
  x = x - m[i_min]
 else:
  break

print(result)

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

int main(){
    int n;
    cin >> n;
    string S;
    int a = 0;
    int w = 0;
    int t = 0;
    int r = 0;

    rep(i, n){
        cin >> S;
        if (S[0] == 'A') a++;
        else if (S[0] == 'W') w++;
        else if (S[0] == 'T') t++;
        else if (S[0] == 'R') r++;
    }

    cout << "AC x " << a << endl;
    cout << "WA x " << w << endl;
    cout << "TLE x " << t << endl;
    cout << "RE x " << r << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  for(int i=0;i<s.size()-1;i++){
    if(s.at(i)=='A'){
      if(s.at(i+1)=='C'){
        cout<<"Yes";
        return 0;
      }
    }
  }
  cout<<"No";
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int k, x;
  cin >> k >> x;
  vi32 ans;
  for (int i = -1000000; i <= 1000000; i++) {
    if (x - k + 1 <= i && i <= x + k - 1) {
      ans.emplace_back(i);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long mod = 998244353;
vector<long long>fact;
long long bigmod(long long a, long long p){
    if(p == 0){
        return 1;
    }
    long long ans = bigmod(a, p/2);
    ans = (ans * ans) % mod;
    if(p % 2 == 1){
        ans = (ans * a) % mod;
    }
    return ans;
}
long long nCr(long long a, long long b){
    long long ans = (fact[a] * bigmod((fact[b] * fact[a - b]) % mod, mod - 2)) % mod;
    return ans;
}
int main(){
    long long n, m, k;
    cin >> n >> m >> k;
    fact = vector<long long>(n + 3);
    fact[0] = 1;
    for(long long i = 1; i <= n; i++){
        fact[i] = (fact[i - 1] * i) % mod;
    }
    vector<long long>power(n + 3);
    power[0] = 1;
    for(long long i = 1; i <= n; i++){
        power[i] = (power[i - 1] * (m - 1)) % mod;
    }
    long long ans = 0;
    for(int i = 0; i <= k; i++){
        long long x = nCr(n - 1, i);
        long long y = power[n - i - 1];
        long long z = (x * y) % mod;
        z = (m * z) % mod;
        ans = (ans + z) % mod;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 6344
#include <bits/stdc++.h>
//#include <map>
//#include <set>
//#include <list>
//#include <cmath>
//#include <ctime>
//#include <deque>
//#include <queue>
//#include <stack>
//#include <string>
//#include <bitset>
//#include <cstdio>
//#include <limits>
//#include <vector>
//#include <climits>
//#include <cstring>
//#include <cstdlib>
//#include <fstream>
//#include <numeric>
//#include <sstream>
//#include <iomanip>
//#include <iostream>
//#include <algorithm>
//#include <unordered_map>

using namespace std;

#define file freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define PI 3.141592653589793238462643383279502884
#define MAX 1000100
#define mod 1000000007
#define EPS 1E-9
#define int long long
#define endl "\n"

int fix(int cur, int m)
{
    return ((cur%m) + m) % m;
}

int fast_power(int x, int y,int m)
{
    if (y == 0)
        return 1;
    int temp = fast_power(x, y / 2, m) ;
    temp = (temp*temp)% m;
    if (y % 2 != 0)
        temp = (temp*x)% m;
    return temp;

}


int32_t main()
{
    //freopen("D:/Important Files/Cocktail/SOLVE/TestLib/testcases/input/input11.txt", "r", stdin);
    //freopen("D:/Important Files/Cocktail/SOLVE/TestLib/testcases/output/output11.txt", "w", stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.tie(0);

    string s;
    cin >> s;
    cout << string(s.size(),'x') << endl;




    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//typedef vector<ll> vec;
//typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

ll n,a;


int main(){
  cin>>n>>a;
  bool fl=false;
  for(ll i=0;i<=a;i++){
    if((n-i)%500 == 0)fl=true;
  }
  if(fl)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int W=sc.nextInt(),a=sc.nextInt(),b=sc.nextInt();
		if(Math.abs(b-a)<=W){
			System.out.println("0");
		}
		else{
			System.out.println(Math.abs((b-a))-W);
		}
	}
}

Measured memory_bytes: 23764
#include <iostream>
using namespace std;
int h,w,dp[50][50],dx[]={0,0,1,1,1,-1,-1,-1},dy[]={1,-1,0,1,-1,0,1,-1},ch[50][50],ans;
void dfs(int x,int y){
    for(int i=0;i<8;i++){
        int nx=x+dx[i];
        int ny=y+dy[i];
        if(0<=nx&&nx<h&&0<=ny&&ny<w&&dp[nx][ny]==1){
            if(ch[nx][ny]==0){
                ch[nx][ny]=1;
                dfs(nx,ny);
            }
        }
    }
    return ;
}
int main(void){
    while(1){
        cin>>w>>h;
        if(w==0&&h==0)return 0;
        ans=0;
        for(int i=0;i<h;i++)for(int j=0;j<w;j++){
            ch[i][j]=0;
            cin>>dp[i][j];
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(dp[i][j]==1&&ch[i][j]==0){
                    dfs(i,j);
                    ans++;
                }
            }
        }
        cout<<ans<<endl;
    }
}



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

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

    string num;

    while (1) {
        cin >> num;
        if (num == "0") {
            break ;
        }
        int sum = 0;
        for (int i = 0; i < num.size(); i++) {
            sum += num[i] - '0';
        }
        cout << sum << '\n';
    }
    return 0;
}


Measured memory_bytes: 3220
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
long long t[10];
int main(){
    long long a,b,c;
    cin>>a>>b>>c;
    if((a%2 == 0)||(b%2 == 0)||(c%2 == 0)){
        cout<<"0"<<endl;
        return 0;
    }
    t[1] = a*b; t[2] = a*c; t[3] = b*c;
    long long ans = t[1];
    if(ans > t[2]) ans = t[2];
    if(ans > t[3]) ans = t[3];
    cout<<ans<<endl;
    return 0; 
}

Measured memory_bytes: 256
import sys
import collections


input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    c = collections.Counter(A)

    mod = 1
    if N & 1:
        mod = 0

    for k in c.keys():
        if mod == 0 and k == 0:
            continue

        if k % 2 != mod:
            print(0)
            break
        elif c[k] != 2:
            print(0)
            break
    else:
        print(pow(2, N // 2, 10 ** 9 + 7))



if __name__ == '__main__':
    main()


Measured memory_bytes: 14756
// (ÀWð\»·éÏÍSÄA}CiXð\»·é½ßÉ+70·é)

#include<iostream>
#include<queue>
#define MAX_COOR 150
using namespace std;

//}bvÌBÅ«éR}Ìð¦éÖ
int mapsearch(int t, int x, int y, bool endcnt[][MAX_COOR]);

int main(){
	
	//t = ^[, n = áQ¨Ì
	int t, n;
	
	while(cin >>t >>n){
		if(t == 0 && n == 0) break;
		
		// obs[áQ¨ÌxÀW][áQ¨ÌyÀW] = áQ¨ÌÀW(true:áQ¨ è, false:áQ¨Èµ)
		//endcnt[] = JEgµIíÁ½R}ðL^(true:JEgÏ, false:Ü¾JEgµÄÈ¢) áQ¨Ì éR}Íß©çtrueÆ·é
		int startx, starty;
		bool endcnt[MAX_COOR][MAX_COOR] = {false};
		
		for(int i = 0; i < n; i++){
			int obsx, obsy;
			cin >>obsx >>obsy;
			endcnt[obsx + 70][obsy + 70] = true;
		}
		cin >>startx >>starty;
		startx += 70;
		starty += 70;
		endcnt[startx][starty] = true;
		
		cout <<mapsearch(t, startx, starty, endcnt) <<endl;
	}
	return 0;
}

int mapsearch(int t, int x, int y, bool endcnt[][MAX_COOR]){
	
	//cnt = }bvÌBÅ«éR}ÌðL¯·éÏ
	int cnt = 1;
	
	//movex[] = Ú®·éxÀWðì·ézñ, movey[] = Ú®·éyÀWðì·ézñ
	int movex[6] = {0, 1, 1, 0, -1, -1}, movey[6] = {1, 1, 0, -1, -1, 0};
	
	//qunextx = Ì[³Å²×éxÀW, qunexty = Ì[³Å²×éyÀW
	//qunowx = ¡Ì[³Å²×éxÀW, qunowy = ¡Ì[³Å²×éyÀW
	queue<int> qunextx, qunexty, qunowx, qunowy;
	
	//X^[gn_ÌÀWðqunowÉL^
	qunowx.push(x);
	qunowy.push(y);
	
	//§ÀÌ^[ªéÜÅAÌ[³És¯éÀWðL^¨[³ðißé
	for(int i = 0; i < t; i++){
		
		//L^µÄ¢éÀWªóÉÈéÜÅ
		while(qunowx.empty() != 1){
			
			//×èÁÄ¢éR}ðSÄ²×é
			for(int k = 0; k < 6; k++){
				
				//nowx = ²×½¢xÀW, nowy = ²×½¢yÀW
				int nowx = qunowx.front() + movex[k], nowy = qunowy.front() + movey[k];
				
				//Ú®Å«é©Ç¤©(Å«éÈçÌ½ßÌì)
				if(endcnt[nowx][nowy] == false){
					qunextx.push(nowx);
					qunexty.push(nowy);
					endcnt[nowx][nowy] = true;
					cnt++;
				}
			}
			qunowx.pop();
			qunowy.pop();
		}
		//qunowÉqunextðüêé
		while(qunextx.empty() != 1){
			qunowx.push(qunextx.front());
			qunextx.pop();
			qunowy.push(qunexty.front());
			qunexty.pop();
		}
	}
	return cnt;
}

Measured memory_bytes: 0
N, C = map(long, raw_input().split())
Sushi_clock  = [map(long, raw_input().split()) for i in range(N)]
Sushi_anticlock = [[C-x[0], x[1]] for x in Sushi_clock[::-1]]
Sushi_clock.insert(0, [0L, 0L])
Sushi_anticlock.insert(0, [0L, 0L])
N += 1
ans = 0
eatcal = 0
getcal_clock_max = 0
getcal_clock_max_oa = 0
getcal_clock_maxes = []
getcal_clock2_max = 0
getcal_clock2_max_oa = 0
getcal_clock2_maxes = []
for i in Sushi_clock:
  eatcal += i[1]
  getcal = eatcal-i[0]
  getcal_clock_max_oa = i[0] if getcal > getcal_clock_max else getcal_clock_max_oa
  getcal_clock_max = getcal if getcal > getcal_clock_max else getcal_clock_max
  getcal_clock_maxes.append([getcal_clock_max,getcal_clock_max_oa])
  getcal2 = eatcal-i[0]*2
  getcal_clock2_max_oa = i[0] if getcal2 > getcal_clock2_max else getcal_clock2_max_oa
  getcal_clock2_max = getcal2 if getcal2 > getcal_clock2_max else getcal_clock2_max
  getcal_clock2_maxes.append([getcal_clock2_max,getcal_clock2_max_oa])
eatcal = 0
for anti, oa, oa2 in zip(Sushi_anticlock, getcal_clock_maxes[::-1], getcal_clock2_maxes[::-1]):
  eatcal += anti[1]
  getcal_oa2 = eatcal-anti[0]+oa2[0]
  getcal_ob2 = eatcal-anti[0]*2+oa[0]
  ans = max(ans, getcal_oa2, getcal_ob2)
print ans


Measured memory_bytes: 73588
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
#define pii pair<int,int>
#define pll pair<LL,LL>

using namespace std;

int main(){

    int N;cin>>N;
    pll p[N];
    REP(i,N){
        LL H,P;cin>>H>>P;
        p[i].first=P+H,p[i].second=H;
    }
    sort(p,p+N);
    LL dp[N+1][N+1];
    fill(dp[0],dp[N+1],INT_MAX);
    dp[0][0]=0;

    REP(i,N){
        REP(j,i+1){
            dp[i+1][j+1]=dp[i][j+1];
            if(p[i].second >=dp[i][j]){
                dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j] + (p[i].first-p[i].second));
            }
        }
    }



    int ans =0;
    REP(i,N+1)if(dp[N][i]<INT_MAX)ans=i;
    cout<<ans<<endl;








    return 0;
}

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

int main()
{
    int n;
    string s;
    cin >> n >> s;
    for(int i=0;i<s.size();i++)
    {
        s[i]=s[i]+n;
        if(s[i]>90)
            s[i]=s[i]-26;
    }
    cout << s <<endl;
    return 0;
}


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

int main() {
    int A, B,K;
    scanf("%d%d%d",&A,&B,&K);
    bool a=1;
    for(int i=0;i<K;i++){
		a=!a;
		if(a){
			A+=B/2;
			B=B/2;
		}else{
			B+=A/2;
			A=A/2;
		}
	}
	printf("%d %d", A, B);
}
	


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n,m,k=map(int,input().split())

class UF():
  def __init__(self, N):
    self._parent=[n for n in range(0, N)]
    self._size=[1] * N

  def find_root(self, x):
    if self._parent[x]==x:return x
    self._parent[x]=self.find_root(self._parent[x])
    return self._parent[x]

  def unite(self, x, y):
    gx=self.find_root(x)
    gy=self.find_root(y)
    if gx==gy:return

    if self._size[gx]<self._size[gy]:
      self._parent[gx]=gy
      self._size[gy]+=self._size[gx]
    else:
      self._parent[gy]=gx
      self._size[gx]+=self._size[gy]

  def size(self, x):
    return self._size[self.find_root(x)]

  def samegroup(self, x, y):
    return self.find_root(x)==self.find_root(y)

  def groupnum(self):
    N=len(self._parent)
    ans=0
    for i in range(N):
      if self.find_root(i)==i:
        ans+=1
    return ans

cf=[[] for i in range(n)]
cb=[[] for i in range(n)]

UFa=UF(n)
for i in range(m):
  x,y=map(int,input().split())
  UFa.unite(x-1,y-1)
  cf[x-1].append(y-1)
  cf[y-1].append(x-1)
UFa.groupnum()

for i in range(k):
  x,y=map(int,input().split())
  cb[x-1].append(y-1)
  cb[y-1].append(x-1)

ans=[]
for i in range(n):
  x=(UFa.size(i)-1)-len(cf[i])
  for j in range(len(cb[i])):
    if UFa.samegroup(i,cb[i][j]):
      x-=1
  ans.append(str(x))
print(' '.join(ans))

Measured memory_bytes: 111152
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    string S, T;
    cin >> S >> T;

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

    string U;
    cin >> U;

    if(U == S) A = A - 1;
    if(U == T) B = B - 1;

    cout << A << " " << B << endl; 
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  ll a,b; cin>>a>>b;
  ll g = __gcd(a,b);
  ll lcm = a/g*b;
  cout<<lcm;
  

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
func main(){
    a := nextInt()
    b := nextInt()
    if (a<b){
		fmt.Printf("a < b\n")
    } else if (a>b){
		fmt.Printf("a > b\n")
    } else {
    	fmt.Printf("a == b\n")
    }
}

/* templates */

func Max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func Min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func Sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}

func Abs(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}

func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	return p[i].b < p[j].b
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func nextString() string {
	return nextReader()
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}



Measured memory_bytes: 1068
#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
LL n,x,ans,x1,x2;
int main()
{
	scanf("%lld%lld",&n,&x);
	ans=n;
	x1=x,x2=n-x;
	while(1)
	{
		if(x1<x2) swap(x1,x2);
		if(!x2) break;
		if(x1%x2==0) ans-=x2;
		ans+=x2*(x1/x2)*2;
		x1-=x2*(x1/x2);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 128
mod = 1000000007


def mul(a, b):
    return ((a % mod) * (b % mod)) % mod


def power(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x % mod
    elif y % 2 == 0:
        return power(x, int(y/2))**2 % mod
    else:
        return power(x, int(y/2))**2 * x % mod


def div(a, b):
    return mul(a, power(b, mod-2))


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

s = int(0)
r = int(0)
for a in A:
    s = int(s + a)
    r = int(r + a * a)

print(div(s * s - r, 2))


Measured memory_bytes: 31612
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    a,b,n = LI()
    r = 0
    if b < 10**6:
        for k in range(1,min(b,n+1)):
            u = a*k//b - a*(k//b)
            if r < u:
                r = u
        return r

    i = 1
    while True:
        t = b*i
        if t % a == 0:
            k = t // a
        else:
            k = t // a + 1
        if k > n:
            break
        u = a*k//b - a*(k//b)
        if r < u:
            r = u
        i += 1

    return r


print(main())





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

using namespace std;

int main(void) {
	int N,K;
	cin >> N >> K;
	vector<int> ball(N+1,N+2);
	int count = 0;
	for (int i = 0; i < N; ++i) {
		int temp;
		cin >> temp;
		if (ball[temp] == N+2) {
			ball[temp] = 1;
			++count;
		}
		else {
			++ball[temp];
		}
	}
	sort(ball.begin(),ball.end());

	int res = 0;
	for (int i = 0; i < count-K; ++i) {
		res += ball[i];
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 100005;
struct Node {
	int oya = -1, kai = 0;
	string shu = "root";
	vi ko;
};
vector<Node> T(MAX);
inline void rec(int u, int p) {
	T[u].kai = p;
	rep(i, 0, len(T[u].ko)) {
		rec(T[u].ko[i], p + 1);
	}
}
int main() {
	int n; cin >> n;
	int v, d, c;
	rep(i, 0, n) {
		cin >> v >> d;
		if(d == 0 && T[v].shu == "leaf") continue;
		rep(j, 0, d) {
			cin >> c;
			if(T[v].shu == "leaf") T[v].shu = "internal node";
			T[v].ko.eb(c);
			T[c].oya = v;
			if(len(T[c].ko)) T[c].shu = "internal node";
			else T[c].shu = "leaf";
		}
	}
	int root = 0;
	rep(i, 0, n) {
		if(T[i].shu == "root") root = i;
	}
	rec(root, 0);
	rep(i, 0, n) {
		cout << "node " << i << ": parent = " << T[i].oya << ", depth = " << T[i].kai
				<< ", " << T[i].shu << ", [";
		int len_ko = len(T[i].ko);
		rep(j, 0, len_ko) {
			cout << T[i].ko[j];
			if(j + 1 != len_ko) p(", ");
		}
		P("]");
	}
	return 0;
}

Measured memory_bytes: 12308
N = int(input())
div = 2
dic = {}
while div**2 <= N:
  if N % div == 0:
    count = 0
    while N % div == 0:
      N = N // div
      count += 1
    dic[div] = count
  div += 1
if N != 1:
  dic[N] = 1
ans = 0
for v in dic.values():
  tmp = 1
  while v >= tmp:
    v -= tmp
    tmp += 1
    ans += 1
print(ans)

Measured memory_bytes: 9180
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
ll A, B, C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z;
void FlipFlipAndFlip() {
	cin >> N >> M;
	if (N == 1 && M == 1) {
		cout << 1 << endl;
	}
	else if (N == 1) {
		cout << max(M - 2, 0LL) << endl;
	}
	else if (M == 1) {
		cout << max(N - 2, 0LL) << endl;
	}
	else {
		cout << ((N - 2) * (M - 2)) << endl;
	}
	
}
int main() {
	FlipFlipAndFlip();
	return 0;
}

Measured memory_bytes: 256
#define NODE 0
#define WEIGHT 1
#define COST_IDX 0
#define TIME_IDX 1
#define P_IDX 0
#define Q_IDX 1
#define R_IDX 2
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

int n, m, k;
map<int, map<int, int*> > weights;
int **requests;

bool read_input() {
  cin >> n >> m;
  if (n*m == 0) 
    return false;
  for (int i = 0; i < n; i++) {
    int a, b, c, t;
    cin >> a >> b >> c >> t;
    weights[a][b] = new int[2];
    weights[b][a] = new int[2];
    weights[a][b][COST_IDX] = weights[b][a][COST_IDX] = c;
    weights[a][b][TIME_IDX] = weights[b][a][TIME_IDX] = t;
  }
  cin >> k;
  requests = new int*[k];
  for (int i = 0; i < k; i++) {
    requests[i] = new int[3];
    cin >> requests[i][P_IDX] >> requests[i][Q_IDX] >> requests[i][R_IDX];
  }
  return true;
}

int resolve_request(int i_th) {
  int p, q, r;
  p = requests[i_th][P_IDX];
  q = requests[i_th][Q_IDX];
  r = requests[i_th][R_IDX];

  /* keep track of latest weight_sum of each node since values 
   * in priority queue might not be up to date (since STL prioroty 
   * queue does not support value change, ignore popped itmes
   * that does not match values in this map). */  
  map<int, int> weight_sum_map;
  
  /* starting node has weight_sum of 0 */
  weight_sum_map[p] = 0;

  /* create priority queue and push p into it as the initial element */
  auto cmp = [](int *a, int *b) { return a[WEIGHT] > b[WEIGHT]; };
  priority_queue<int*, vector<int*>, decltype(cmp)> pq(cmp); 
  int *itm = new int[2];
  itm[NODE] = p;
  itm[WEIGHT] = 0;
  pq.push(itm);

  while (!pq.empty()) {
    itm = pq.top(); 
    int weight_sum = itm[WEIGHT];
    int node = itm[NODE];

    /* release allocated mem and remove from priority queue*/
    delete[] itm;
    pq.pop();

    // if q was popped, release all allocated mem and break 
    if (node == q) {/*
      while (!pq.empty()) {
	itm = pq.top();
	delete[] itm;
	pq.pop();
	}*/
      break;
    }

    /* ignore if wight_sum value not up to date */
    if (weight_sum != weight_sum_map[node]) {
      continue;
    }
    auto connections = weights[node];
    for (auto itr = connections.begin(); itr != connections.end(); itr++) {
      int adj_node = itr->first;
      int w = itr->second[r]; // get the requested weight type r == 0(cost) or 1(time)
      int new_weight_sum = weight_sum + w;
      if (weight_sum_map.count(adj_node) == 0 || new_weight_sum < weight_sum_map[adj_node]) {
	weight_sum_map[adj_node] = new_weight_sum;
	itm = new int[2];
	itm[NODE] = adj_node;
	itm[WEIGHT] = new_weight_sum;
	pq.push(itm);
      }
    }
  }
  return weight_sum_map[q];
}

void solve() {
  for (int i = 0; i < k; i++)
    cout << resolve_request(i) << endl;
}

void cleanup() {/*
  for (int i = 0; i < k; i++) {
    delete[] requests[i];
  }
  delete[] requests;
		*/
  /*
  for (auto itr_a = weights.begin(); itr_a != weights.end(); itr_a++) {
    auto m = itr_a->second;
    for (auto itr_b = m.begin(); itr_b != m.end(); itr_b++) {
      delete[] itr_b->second;
    }
    m.clear();
    }*/
  weights.clear();
}

int main() {
  while(read_input()) {
    solve();
    cleanup();
  }
  return 0;
}

Measured memory_bytes: 34372
from collections import defaultdict
N = int(input())
S = defaultdict(set)
for i in range(N):
    a = input()
    if a[0] ==  'M':
        S[0].add(a)
    if a[0] == 'A':
        S[1].add(a)
    if a[0] == 'R':
        S[2].add(a)
    if a[0] == 'C':
        S[3].add(a)
    if a[0] == 'H':
        S[4].add(a)
d = 1
count = 0
sv = []
for i in S.values():
    sv.append(len(i))
if len(sv) < 3:
    print(0)
else:
    ans = 0
    for i in range(len(sv)-2):
        for j in range(i+1,len(sv)-1):
            for k in range(j+1,len(sv)):
                ans += sv[i]*sv[j]*sv[k]
    print(ans)

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

#define REP(i, n) for(size_t i = 0; i < n; ++i)

using namespace std;

int main() {
    size_t N;
    cin >> N;
    vector<size_t> A(N+1);
    size_t count = 0, b = 0;
    
    REP(i, N + 1) cin >> A[i];
    REP(i, N) {
        cin >> b;
        if(b >= A[i]) {
            count += A[i];
            b -= A[i];
            if(b >= A[i + 1]) {
                count += A[i + 1];
                A[i + 1] = 0;
            }
            else {
                count += b;
                A[i + 1] -= b;
            }
        }
        else {
            count += b;
        }
    }
    cout << count << endl;
}


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

int main(){
    int a,b,c,t;
    cin >> a >> b >> c;
    if(a>b){t=a,a=b,b=t;}
    if(b>c){t=b,b=c,c=t;}
    if(a>b){t=a,a=b,b=t;}
    cout << a << " " << b << " " << c << endl;

    return 0;
    
}



Measured memory_bytes: 3112
#include"bits/stdc++.h"

using namespace std;

int main() {
	int N, K;
	cin >> N >> K;

	int ans = 1;
	for (int i = 0; i < N; i++) {
		ans = min(ans * 2, ans + K);
	}

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

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,P> PP;

struct edge {
	int to,cost;
	edge(int t,int c):to(t),cost(c) {}
};

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

//-----------------------------------------------------------------------------

int n,m;

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

	cin>>n>>m;
	ll t=1;
	REP(i,m) t*=2;

	cout<<(m*1900+(n-m)*100)*t<<endl;

	return 0;
}


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

const ll maxs = 2e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){
    
}

ll n;
ll a[maxs];
ll dp[maxs][4];
bool vis[maxs][4];

ll go(ll pos,ll have){
    if(pos >= n){
        if(have <= 1)
            return 0;
        return -oo;
    }
    ll& ans = dp[pos][have];
    if(vis[pos][have])
        return ans;
    vis[pos][have] = true;

    if(!have)
        ans =  a[pos] + go(pos+2,have);
    else
        ans = max(a[pos] + go(pos+2,have) , go(pos+1,have-1) );
    
    return ans;

}

void solve(){
    cin >> n;
    for(ll i=0;i<n;i++)
        cin >> a[i];
    
    ll ans;
    if(n&1){
        ans = go(0,2) ;
    }
    else{
        ans = go(0,1) ;
    }
    cout << ans << endl;
}

int main(){
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 16892
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    int A,B,M;
	cin >> A >> B >> M;
	vector<int> a(A),b(B);
	for(int i=0;i<A;i++) cin >> a[i];
	for(int i=0;i<B;i++) cin >> b[i];
 
	int ans = 1e18;
	for(int i=0;i<M;i++){
		int x,y,c;
		cin >> x >> y >> c;
		ans = min(ans,a[x-1]+b[y-1]-c);
	}
 
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
 
	ans = min(ans, a[0]+b[0]);
 
	cout << ans << endl;
}

Measured memory_bytes: 3984
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    vector<int> a(3);
    rep(i,3) cin >> a[i];
    sort(a.begin(), a.end());
    if (a[0] + a[1] == a[2])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main(){
  int A[3];
  rep(i,3) cin >> A[i];
  int five=0, seven=0;
  rep(i,3){
    if(A[i]==5)
      five++;
    else if(A[i]==7)
      seven++;
  }
  if(five==2 && seven==1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
// Daniel Grzegorzewski
// while (clock()<=69*CLOCKS_PER_SEC)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace __gnu_pbds;
using namespace std;

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

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

const int N = 5*(int)1e5 + 3;

string s, t;
int n, m, vis[N], dp[N], wyn;
VI child[N], topo;
bool cykl, odw[N];

VI calcPA(string s)
{
  VI res(s.size());
  int j = 0;
  for (int i = 1; i < (int)s.size(); ++i) {
      while (j > 0 && s[i] != s[j])
          j = res[j-1];
      if (s[i] == s[j])
          ++j;
      res[i] = j;
  }
  return res;
}

void dfs(int v) {
  vis[v] = 1;
  for (int x: child[v]) {
    if (vis[x] == 0)
      dfs(x);
    else if (vis[x] == 1) {
      cykl = true;
      return;
    }
  }
  vis[v] = 2;
}

void dfs2(int v) {
  odw[v] = true;
  for (int x: child[v])
    if (!odw[x])
      dfs2(x);
  topo.PB(v);
}

int main() {
  init_ios();
  cin >> s >> t;
  string rem = s;
  n = s.size();
  m = t.size();
  while ((int)s.size() <= n+m+5)
    s += rem;
  string hm = t+"!"+s;
  VI pa = calcPA(hm);
  for (int i = m+n; i < (int)pa.size(); ++i)
    if (pa[i] == m) {
      int v = (i-m-n)%n;
      if (child[v].size())
        break;
      int u = (v+m)%n;
      child[v].PB(u);
    }
  for (int i = 0; i < n; ++i)
    if (vis[i] == 0) {
      dfs(i);
    }
  if (cykl) {
    cout<<"-1\n";
    return 0;
  }
  for (int i = 0; i < n; ++i)
    if (!odw[i])
      dfs2(i);
  reverse(topo.begin(), topo.end());
  for (int i = (int)topo.size()-1; i >= 0; --i) {
    for (int x: child[topo[i]])
      dp[topo[i]] = max(dp[topo[i]], 1+dp[x]);
    wyn = max(wyn, dp[topo[i]]);
  }
  cout<<wyn<<"\n";
}

Measured memory_bytes: 64328
import sys
sys.setrecursionlimit(10**9)
N,M=map(int,input().split())
G=[[] for i in range(N)]
a,b=0,0
for i in range(M):
  a,b=map(int,input().split())
  G[b-1].append(a-1)
DP=[-1]*N
def f(x):
  if DP[x]!=-1:
    return DP[x]
  DP[x]=0
  for i in range(len(G[x])):
    DP[x]=max(DP[x],f(G[x][i])+1)
  return DP[x]

for i in range(N):
  f(i)
print(max(DP))

Measured memory_bytes: 209836
n,m=map(int,input().split())
edge=[[] for i in range(n+1)]
for i in range(m):
    a,b,c=map(int,input().split())
    edge[a].append((b,-c))

renew=set()
from heapq import *
INF=float('inf')
def dijkstra(s,n):
    d = [INF for i in range(n+1)]
    pq = []
    d[s]=0
    heappush(pq,(0,s))
    while pq:
        dist,u = heappop(pq)
        for v,cost in edge[u]:
            if d[v]<=dist+cost:
                continue
            d[v]=dist+cost
            if (u,v) in renew:
                d[v]=-INF
            renew.add((u,v))
            heappush(pq,(d[v],v))
    return d             
d=dijkstra(1,n)
print(-d[n])

Measured memory_bytes: 3572
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <math.h>
typedef long long int ll;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define INF 100000000
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};

int cnt[810],p[810],d[810];
int n;
int a[810][810];
void warshall_floyd(){
	int i,j,k;
    for (k = 0; k < n; k++){       // 経由する頂点
	    for (i = 0; i < n; i++) {    // 始点
	        if(a[i][k]==INF)continue;
	        for (j = 0; j < n; j++) {  // 終点
	        if(a[k][j]==INF)continue;
	        chmin(a[i][j], a[i][k] + a[k][j]);
	        }
	    }
    }
}


int main(void)
{
	scanf("%d",&n);
	while(n>0){
		int i,j;
		int ans=0;
		for(i=0;i<n-1;i++)scanf("%d",&p[i+1]);
		for(i=0;i<n-1;i++)scanf("%d",&d[i+1]);
		memset(cnt,0,sizeof(cnt));
		for(i=0;i<n-1;i++){
			cnt[i+1]++;
			cnt[p[i+1]-1]++;
			ans+=2*d[i+1];
		}
		int m = ans/2;
		for(i=0;i<n;i++){
			//printf("%d\n",cnt[i]);
			if(cnt[i]==1){
				if(i>0){
					ans-=d[i];
					m-=d[i];
				}
				else if(i==0){
					for(j=0;j<n-1;j++){
						if(p[j+1]-1==0){
							ans-=d[j+1];
							m-=d[j+1];
							break;
						}
					}
				}
			}
		}
		ans+=m;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				a[i][j]=INF;
			}
		}
		for(i=0;i<n-1;i++){
			if(cnt[i+1]!=1&&cnt[p[i+1]-1]!=1){
				a[i+1][p[i+1]-1]=d[i+1];
				a[p[i+1]-1][i+1]=d[i+1];
			}
		}
		warshall_floyd();
		int tmp=0;
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				//printf("%d %d %d\n",i,j,a[i][j]);
				if(a[i][j]!=INF){
					chmax(tmp,a[i][j]);
				}
			}
		}
		//printf("%d\n",tmp);
		printf("%d\n",ans-tmp);
		scanf("%d",&n);
	}
    return 0;
}


Measured memory_bytes: 4304
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[100000],dp[100][100];

int main(){
  cin >> s;
  m = 0;
  rep(i,0,s.sz){
    if(s[i] == 'A'){
      per(j,s.sz-1,i)if(s[j] == 'Z'){
        m = j-i+1;
        break;
      }
    }
    if(m != 0)break;
  }
  print(m);
  return 0;
}

Measured memory_bytes: 640
def main():
    n, s = open(0).read().split()
    n = int(n)

    before_s = ''
    ans = 0
    for _s in s:
        if _s != before_s:
            ans += 1
            before_s = _s
        else:
            continue
    print(ans)
    return()

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
N, T = map(int, input().split())
t = list(map(int, input().split()))

tmp = 0
sum_t = 0

for i in range(N-1):
    if t[i+1] - t[i] < T:
        sum_t += t[i+1] - t[i]
    else:
        sum_t += T

print(sum_t + T)

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

// #define zerol

#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif


const LL MOD = 1e9+7;

const int N = 2e5+50;

int a[N];
int n, m;
const LL INF = 1e18, INF2 = 2e14;

LL b[2][N];
map<int, LL> mp;

LL solve(int n) {
    if (mp.count(n))
        return mp[n];
    if (n == 1) {
        return max(0, a[1]);
    } else if (n == 0)
        return 0;
    if (n % 2)
        return mp[n] = max(solve(n-1), solve(n-2) + a[n]);
    else
        return mp[n] = max(solve(n-2) + a[n], b[1][n-1]);
}
int main() {
    scanf("%d", &n);
    m = n / 2;
    for (int i=1; i<=n; ++i) 
        scanf("%d", &a[i]);

    for (int i=1; i<=n; ++i) {
        b[i%2][i] = a[i];
    }

    for (int i=1; i<=n; ++i) {
        b[0][i] += b[0][i-1];
        b[1][i] += b[1][i-1];
        dbg(i, b[0][i], b[1][i]);
    }
    cout << solve(n) << endl;
    return 0;
}

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

int rec(int a, int b, int c){
	if(a == 0 && b == 0)return 0;
	if(c & 1)return rec(a>>1, b>>1, c>>1);
	if(b & 1)return rec(c>>1, b>>1, a>>1)+rec((a|b|c)>>1, 0, 0)+1;
	if(a & 1)return rec(a>>1, b>>1, c>>1)+2*rec((a|b|c)>>1, 0, 0)+2;
}

int main(){
	int n, m, dat[3], k, t, ans;
	while(1){
		ans = 1e9;
		scanf("%d%d", &n, &m);
		if(n+m == 0)break;
		for(int i = 0;i < 3;i++){
			scanf("%d", &k);
			dat[i] = 0;
			for(int j = 0;j < k;j++){
				scanf("%d", &t);
				dat[i] |= 1 << --t;
			}
		}
		
		ans = min(ans, rec(dat[0], dat[1], dat[2]));
		ans = min(ans, rec(dat[2], dat[1], dat[0]));
		if(ans > m)printf("-1\n");
		else printf("%d\n", ans);
	}
	return 0;
} 


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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int test; cin >> test;
	int ara[test];
	for (int i = 0; i < test; ++i)
	{
		cin >> ara[i];
		if (ara[i] % 2 == 0)
		{
			if (ara[i] % 3 == 0 || ara[i] % 5 == 0)
			{
				continue;
			}
			else
			{
				cout << "DENIED" << endl;
				return 0;
			}

		}
	}
	cout << "APPROVED" << endl;
	return 0;
}

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

int main(){
    deque<int> integers;
    vector<int> prime;
    for (int i=2; i<55555; i++) integers.push_back(i);
    while (!integers.empty()) {
        deque<int> tmp;
        int p = integers[0];
        integers.pop_front();
        prime.push_back(p);
        for (auto i : integers){
            if (i % p != 0) tmp.push_back(i);
        }
        integers = tmp;
    }
    int n;
    vector<int> ans;
    cin >> n;
    for (auto p : prime){
        if (p % 5 == 1) ans.push_back(p);
        if (ans.size() == n) break;
    }
    for (auto x : ans) cout << x << " ";
    return 0;
}

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

using namespace std;

int main(){
    int n;
    cin>>n;
    for(int i =n; i<= 999; i++){
        int t;
        t=i%10;
        if((i/10)%10 == t){
            if((i/100)%10 == t){
                cout<<i;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
n,m,c = gets.chomp.split(' ').map(&:to_i)
b = gets.chomp.split(' ').map(&:to_i)
count = 0
(0...n).each do |i|
  a = gets.chomp.split(' ').map(&:to_i)
  count += 1 if (0...m).map{|j| a[j] * b[j]}.inject(:+) + c > 0
end
puts count

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

int main(){
	int n,q;
	unordered_map<int,int> count;
	cin>>n;
	long long int sum = 0;
	for(int i=0;i<n;i++){
		int d;
		cin>>d;
		count[d]++;
		sum+=d;
	} 
	cin>>q;
	for(int i=0;i<q;i++){
		int b,c;
		cin>>b>>c;
		sum+= (count[b]*(c-b));
		count[c]+=count[b];
		count[b]=0;
		cout<<sum<<"\n";
	}
}

Measured memory_bytes: 7052
a,b,c,d = map(int,input())
op1,op2,op3 = "","",""
if a+b+c+d==7:
  op1,op2,op3 = "+","+","+"
elif a+b+c-d==7:
  op1,op2,op3 = "+","+","-"
elif a+b-c+d==7:
  op1,op2,op3 = "+","-","+"
elif a+b-c-d==7:
  op1,op2,op3 = "+","-","-"
elif a-b-c-d==7:
  op1,op2,op3 = "-","-","-"
elif a-b-c+d==7:
  op1,op2,op3 = "-","-","+"
elif a-b+c-d==7:
  op1,op2,op3 = "-","+","-"
elif a-b+c+d==7:
  op1,op2,op3 = "-","+","+"
print("%d%s%d%s%d%s%d=7" % (a,op1,b,op2,c,op3,d))

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

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

int main(){
	ios::sync_with_stdio(false);

	string str;

	getline(cin, str);

	str.insert(4, " ");

	cout<<str<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 1000000007
void setIO(string name) {
  ios_base::sync_with_stdio(0); cin.tie(0);
  freopen((name+".in").c_str(),"r",stdin);
  freopen((name+".out").c_str(),"w",stdout);
}
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}


int main() {
   fast(); 
   int n,x,t;
   cin>>n>>x>>t;
   if(n%x==0){
    cout<<(n/x)*t<<endl;
   }else{
    cout<<(n/x+1)*t<<"\n";
   }
   

} 

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

using namespace std;
const int N = 1e3 + 4  , MOD = 1e9 + 7;
bool vis[N];
vector < int > adj[N];
int n , m, x , y;
int mem[N][N];
char grid[N][N];
int solve(int r , int c){
    if(grid[r][c] == '#' )
        return 0;
    if(r == n-1 && c == m-1)
        return 1;
    int &ret = mem[r][c];
    if(~ret)
        return ret;
    ret = 0;
    if(r+1 <= n-1)
    ret+=(solve(r+1 ,c) % MOD);
    if(c+1 <= m-1)
    ret+=(solve(r ,c+1) % MOD);
    return ret % MOD;

}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    memset(mem , -1 , sizeof mem);
    cin >> n >> m;
    for(int i = 0 ; i < n; ++i){
        for(int j = 0 ; j < m ; ++j){
            cin >> grid[i][j];
        }
    }
    cout << solve(0 , 0) % MOD;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int ketawa(int n){
    int ret = 0;
    while(n > 0){
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

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

    int ans = INT_MAX;
    for(int a = 1; a < N; a++){
        int b = N - a;
        int tmp = ketawa(a) + ketawa(b);
        //cout << tmp << endl;
        chmin(ans, tmp);
    }

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


Measured memory_bytes: 256