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

int main()
{
	int sa = 0, sb = 0;
	for (int i = 0; i < 4; i++) {
		int a;
		cin >> a;
		sa += a;
	}
	for (int i = 0; i < 4; i++) {
		int b;
		cin >> b;
		sb += b;
	}
	cout << max(sa, sb) << endl;
	return 0;
}



Measured memory_bytes: 3072
#include <stdio.h>

int main(void)
{
    int a,b,c,d;
    c = 1;
    d = 0;
    scanf("%d%d",&a,&b);
    while(c < b){
        c += a - 1;
        d++;
    }
    printf("%d",d);
	return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<ll> A(N + 1), B(N);
    for(int i = 0; i <= N; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];
    ll ans = 0;
    for(int i = 0; i < N; i++){
        ll l = min(A[i], B[i]);
        A[i] -= l;
        B[i] -= l;
        ans += l;
        l = min(A[i + 1], B[i]);
        A[i + 1] -= l;
        B[i] -= l;
        ans += l;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

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

int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  
  int c = 0;
  rep(i,n-1) if(s[i] == s[i+1]) c++;
  
  cout << min(c + 2 * k, n - 1) << endl;
  return 0;
}

Measured memory_bytes: 3728
#include<stdio.h>
#include<math.h>
int main(){
	double PI=3.14159265359;
	int a;
	while(scanf("%d",&a),a){
		double sa=0;
		int c;
		int now=360;
		for(int i=0;i<a-1;i++){
			scanf("%d",&c);
			now-=c;
			sa+=sin((double)c*PI/180);
		}
		sa+=sin((double)now*PI/180);
		double sb=0;
		int b;
		scanf("%d",&b);
		now=360;
		for(int i=0;i<b-1;i++){
			scanf("%d",&c);
			now-=c;
			sb+=sin((double)c*PI/180);
		}
		sb+=sin((double)now*PI/180);
		if(sa>sb+0.0000001)printf("1\n");
		else if(sb>sa+0.0000001)printf("2\n");
		else printf("0\n");
	}
}

Measured memory_bytes: 0
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		Card[] A=new Card[n];

		for(int i=0;i<n;i++) {
			A[i]=new Card(in.next().charAt(0),Integer.parseInt(in.next()));
		}
		in.close();
		Card[] B=A.clone();
		quickSort(A,0,n-1);
		margeSort(B,0,n-1);

		PrintWriter out=new PrintWriter(System.out);
		int s=0;
		for(;s<A.length;s++) {
			if(A[s].s!=B[s].s)break;
		}
		out.println((s==A.length)? "Stable":"Not stable");
		//System.out.println(s);
		for(int i=0;i<n;i++) {
			out.println(A[i].s+" "+A[i].v);
		}
		out.flush();
	}
	
	static int partition(Card A[],int l,int r) {
		int i=l-1,j=l,x=A[r].v;
		Card t;
		
		for(;j<r;j++) {
			if(A[j].v<=x) {
				t=A[++i]; A[i]=A[j]; A[j]=t;
			}
		}
		t=A[++i]; A[i]=A[r]; A[r]=t;
		return i;
	}
	
	static void quickSort(Card A[],int l,int r) {
		if(l<r) {
			int m=partition(A,l,r);
			quickSort(A,l,m-1);
			quickSort(A,m,r);
		}
	}

	static void margeSort(Card A[],int left,int right) {
		int middle=left+((right-left+1)/2);
		if(left!=right) {
			margeSort(A,left,middle-1);
			margeSort(A,middle,right);
		}
		else return;

		int k=left,l=middle,cnt=0;
		Card B[]=new Card[right-left+1];
		while(k<middle && l<=right) {
			if(A[k].v<=A[l].v)B[cnt++]=A[k++];
			else B[cnt++]=A[l++];
		}

		while(k<middle) B[cnt++]=A[k++];
		while(l<=right) B[cnt++]=A[l++];

		for(int i=0;i<B.length;i++)A[left+i]=B[i];
	}

}

class Card{
	int v;
	char s;

	Card(char c,int v){
		s=c;
		this.v=v;
	}

	int getN(){
		return v;
	}
}





Measured memory_bytes: 75764
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    S = input()
    for s in S:
        if s == '7':
            print('Yes')
            return
    print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 72744
n = int(input())
p = [list(map(int, input().split())) for _ in range(n)]
def distances(x1,x2,y1,y2):
    return ((x2-x1)**2+(y2-y1)**2)**0.5

td =0
for i in range(n):
    for j in range(n):
        if i != j :
            td += distances(p[i][0],p[j][0],p[i][1],p[j][1])

a =1
for i in range(1,n+1):
    a = a*i
print(td/n)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] s = new String[n];
        long count = 0;
        for (int i = 0; i < n; i++) {
            s[i] = sc.next();
            char[] c = s[i].toCharArray();
            Arrays.sort(c);
            s[i] = "";
            for (int j = 0; j < c.length; j++) {
                s[i] += String.valueOf(c[j]);
            }
        }
        Arrays.sort(s);
        Map<String, Long> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            if (map.containsKey(s[i])) {
                map.put(s[i], map.get(s[i]) + 1);
            } else {
                map.put(s[i], (long) 1);
            }
        }
        for (long i : map.values()) {
            count += i * (i - 1) / 2;
        }
        System.out.println(count);
    }
}


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

using namespace std;

int main() {

	string s;
	cin >> s;

	for (int i = 1; i < 4; i++) {
		if (s[i] == s[i - 1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
}

Measured memory_bytes: 256
def main():
    S = input()
    b = []
    w = []
    for i, v in enumerate(S):
        if v == 'B':
            b.append(i)
        else:
            w.append(i)
    if len(b) == 0 or len(w) == 0:
        return 0
    return sum(w) - (len(w) * (len(w)-1))//2

print(main())


Measured memory_bytes: 11368
#include<stdio.h>
#include<string.h>
int main(void){
  char a[11],b[11];
  int k;
  scanf("%s %s",a,b);
  b[strlen(a)]='\0';
  if(strcmp(a,b)==0) puts("Yes");
  else puts("No") ;
  
 return 0; 
}


Measured memory_bytes: 1616
#include <iostream>

using namespace std;

int main() {
    int N;
    cin >> N;
    string strN = to_string(N);
    int S = 0;
    for (int i = 0; i < strN.size(); ++i) {
        S += (int)strN[i] - '0';
    }
    if ((N % S) == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3712
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: usize,
        a: [usize1; n - 1],
    }
    let mut b = vec![0; n];
    for &a in &a {
        b[a] += 1;
    }
    for i in 0..n {
        puts!("{}\n", b[i]);
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 3384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char>cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main()	{
  int n;
  cin>>n;
  vector<int>p(n);
  int com=200001,ans=0;
  rep(i,n) cin>>p[i];
  rep(i,n){
    if(com>p[i]){
      ans++;
    }
    com=min(com,p[i]);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
#define N 10000
int Isprime(int);
int main(){
  int n,i,b=0;
  int a[N];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<n;i++){
    if(Isprime(a[i])==1){
      b++;
    }
  }
  printf("%d\n",b);
  return 0;
}

int Isprime(x){
  int i=3;
  if(x==2){
    return 1;
  }
  if(x<2||x%2==0){
    return 0;
  }
  while(i<=sqrt(x)){
    if(x%i==0){
      return 0;
    }
    i=i+2;
  }
  return 1;
}


Measured memory_bytes: 2072
#include <bits/stdc++.h>
using namespace std;
const int mod=1000000007;
int n,c,a[405],b[405],f[405][405],dp[405][405];
int main()
{
    scanf("%d%d",&n,&c);
    for (int i=1;i<=n;++i) scanf("%d",&a[i]);
    for (int i=1;i<=n;++i) scanf("%d",&b[i]);
    for (int i=1;i<=n;++i)
        for (int k=a[i];k<=b[i];++k) {
            for (int j=0,x=1;j<=c;++j) {
                f[i][j]=(f[i][j]+x)%mod;
                x=1ll*x*k%mod;
            }
        }
    dp[0][0]=1;
    for (int i=1;i<=n;++i)
        for (int j=0;j<=c;++j)
            for (int k=0;k+j<=c;++k)
                dp[i][j+k]=(dp[i][j+k]+1ll*dp[i-1][j]*f[i][k]%mod)%mod;
    printf("%d\n",dp[n][c]);
    return 0;
}


Measured memory_bytes: 5096
import math

num_list=list(map(int,input().split()))

laptured_time = num_list[2] *60 + num_list[3]
 

degrees = abs(num_list[3]*6-laptured_time/2)

degrees=math.radians(degrees)
length= math.sqrt(num_list[0]**2+num_list[1]**2-2*num_list[0]*num_list[1]*math.cos(degrees))
print(length)


Measured memory_bytes: 9564
object Main extends App {
  val scanner = new java.util.Scanner(System.in)
  val a = scanner.nextInt
  val b = scanner.nextInt

  val result =
    if(a < b) {
      "a < b"
    } else if(a > b) {
      "a > b"
    } else {
      "a == b"
    }

  println(result)
}

Measured memory_bytes: 45000
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define FL "a"
using namespace std;
typedef vector<int> VI;
typedef long long ll;
typedef double dd;
const int N=1e5+10;
const int mod=1e9+7;
inline ll read(){
  ll data=0,w=1;char ch=getchar();
  while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
  if(ch=='-')w=-1,ch=getchar();
  while(ch<='9'&&ch>='0')data=data*10+ch-48,ch=getchar();
  return data*w;
}
inline void file(){
  freopen(FL".in","r",stdin);
  freopen(FL".out","w",stdout);
}

inline void upd(int &a,int b){a+=b;if(a>=mod)a-=mod;}
inline void dec(int &a,int b){a-=b;if(a<0)a+=mod;}
inline int poww(int a,int b){
  int res=1;
  for(;b;b>>=1,a=1ll*a*a%mod)
    if(b&1)res=1ll*res*a%mod;
  return res;
}
inline void er(){puts("0");exit(0);}

int n,a[N],ans;
int d[N],head[N],nxt[N<<1],to[N<<1],cnt;
inline void add(int u,int v){to[++cnt]=v;nxt[cnt]=head[u];head[u]=cnt;}
int t[N],f[N];

int vis[N],line[N],dis[N],cal[N],top,cir[N],len;
void dfs(int u){
  vis[u]=1;cal[++top]=u;
  for(int i=head[u],v;i;i=nxt[i])
    if(~i&1){
      if(!vis[v=to[i]])dfs(v);
      else
	for(int j=top;cal[j]!=v;j--)
	  cir[++len]=cal[j];
    }
  top--;
}

inline void solve(int x){
  top=len=0;
  for(int p=0;!vis[x];vis[x]=1,cal[++top]=x,p=x,x=a[x]);
  for(int i=top,k=1;i;i--){
    k?cir[++len]=cal[i],dis[cal[i]]=len:vis[cal[i]]=0;
    if(cal[i]==x)k=0;
  }  
  reverse(cir+1,cir+len+1);
  for(int i=1;i<=len;i++)dis[cir[i]]=len-dis[cir[i]]+1;
  //for(int i=1;i<=len;i++)printf("%d ",cir[i]);puts("");
  for(int k=1,u;k<=len;k++){
    u=cir[k];if(d[u]>2)er();line[u]=0;
    for(int i=head[u],v;i;i=nxt[i])
      if(!vis[v=to[i]]){
	line[u]++;vis[v]=1;
	for(v;d[v];v=to[head[v]],vis[v]=1,line[u]++)
	  if(d[v]>1)er();
      }
  }
  for(int k=1;!line[cir[k]];k++)
    if(k==len){t[len]++;return;}
  if(len==1&&line[cir[1]]<=1)return;
  top=0;
  for(int k=1;k<=len;k++)
    if(line[cir[k]])cal[++top]=cir[k];
  /*for(int i=1;i<=top;i++)
    printf("(%d,%d,%d)",cal[i],dis[cal[i]],line[cal[i]]);puts("");*/
  
  if(line[cal[1]]>dis[cal[1]]+(len-dis[cal[top]]))er();
  else ans=1ll*min(2,dis[cal[1]]+(len-dis[cal[top]])-line[cal[1]]+1)*ans%mod;
  
  for(int i=2;i<=top;i++)
    if(line[cal[i]]>dis[cal[i]]-dis[cal[i-1]])er();
    else ans=1ll*min(2,dis[cal[i]]-dis[cal[i-1]]-line[cal[i]]+1)*ans%mod;
}

int main()
{
  n=read();cnt=1;ans=1;
  for(int i=1;i<=n;i++){
    a[i]=read();d[a[i]]++;add(a[i],i);
    //printf("%d %d\n",i,a[i]);
    if(a[i]>n)er();
  }
  for(int i=1;i<=n;i++)
    if(!vis[i])solve(i);
  for(int i=1;i<=n;i++)
    if(t[i]){
      f[0]=1;
      for(int j=1;j<=t[i];j++){
	f[j]=1ll*((i&1)&&i!=1?2:1)*f[j-1]%mod;
	upd(f[j],1ll*(j-1)*i%mod*f[j-2]%mod);
      }
      ans=1ll*ans*f[t[i]]%mod;
    }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 5376
import java.io.*;
import java.util.Scanner;
 
class Main {
  public static void main(String args[]) {
	Scanner scanner = new Scanner(System.in);
    int k = scanner.nextInt();
    int i = 0;
    while(i<k){
      System.out.print("ACL");
      i++;
    }
  };
};

Measured memory_bytes: 35712
import java.util.Scanner;

/**
 * Coins
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            double[] P = new double[N + 1];
            for (int i = 1; i <= N; i++) {
                P[i] = sc.nextDouble();
            }

            double[][] dp = new double[N + 1][N + 1];
            dp[0][0] = 1;

            for (int i = 1; i <= N; i++) {
                for (int j = 0; j <= i; j++) {
                    dp[i][j] = dp[i - 1][j] * (1 - P[i]);
                    if (j > 0) {
                        dp[i][j] += dp[i - 1][j - 1] * P[i];
                    }
                }
            }

            double sum = 0;
            for (int i = N / 2 + 1; i <= N; i++) {
                sum += dp[N][i];
            }

            System.out.println(sum);
        }
    }

}


Measured memory_bytes: 124204
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;
const int maxn = 2e2+10;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int to[maxn*maxn],net[maxn*maxn],h[maxn],e=1;
inline void add(int x,int y){
	to[++e]=y;net[e]=h[x];h[x]=e;
}

int k,m,n,v[maxn];
char c[maxn];
queue<int> q;
int solve(int now){
	v[now]=1;
	int sum=0;
	while(!q.empty())q.pop();q.push(now);
	while(!q.empty()){
		int x=q.front();q.pop();
		sum=max(sum,v[x]);
		for(register int i=h[x];i;i=net[i]){
			int y=to[i];
			if(!v[y]){
				v[y]=v[x]+1;
				q.push(y);
			}
			else if(v[y]!=v[x]-1 && v[y]!=v[x]+1)return -1;
		}
	}
	return sum;
}

int main(){
	n=read();
	for(register int i=1;i<=n;i++){
		scanf("%s",c+1);
		for(register int j=1;j<=n;j++){
			if(c[j]=='1')add(i,j);
		}
	}
	int ans=-1;
	for(register int i=1;i<=n;i++){
		memset(v,0,sizeof(v));
		ans=max(ans,solve(i));
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll a,b,c;
    cin>>a>>b>>c;
    if((a==b && a!=c)||(a==c && b!=c)||(b==c && a!=b)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n;
  cin >> n;
  vector<queue<ll>> a(n);
  ll num;
  REP(i, n){
    REP(j, n-1){
      cin >> num;
      num--;
      a[i].push(num);
    }
  }

  bool goFlag =true;
  bool endFlag = false;
  ll ans = 0;
  while(goFlag&&!endFlag){
    vector<bool> battled(n, true);
    goFlag = false;
    endFlag = true;
    ans++;

    REP(i, n){
      if(a[i].empty())
        continue;
      endFlag = false;
      ll Y = a[i].front();
      ll I = a[Y].front();
      if(i != I)
        continue;
      if(battled[I] && battled[Y]){
        battled[I] = battled[Y] = false;
        a[I].pop();
        a[Y].pop();
        goFlag = true;
      }
    }
  }

  //cout << goFlag << endl;
  //cout << endFlag << endl;
  if(!goFlag && !endFlag)
    cout << -1 << endl;
  else
    cout << ans-1 << endl;
  
}


Measured memory_bytes: 11008
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


const int MAX_N = 100010;
const long double PI = 3.14159265359;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	string s; cin >> s;
	rep(i, s.size()) {
		s[i] += n;
		if (s[i] > 'Z')s[i] -= 26;
	}
	cout << s << endl;
	return 0;
}

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

int main()
{
  int a,b;
  
  cin >> a >> b;
  
  int ans=0;
  
  for(int i=0;i<21;i++){
    if(i*a-i+1>=b){
      ans=i;
      break;
    }
    else
      continue;
  }
  
  cout << ans;
  
  return 0;
}



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

int main()
{
	string s;
	cin>>s;
	int n=s.size(),i;
	int a=(n-1)/2,b=(n+3)/2;
	for(i=0; i<n; i++)
	{
		if(s[i]!=s[n-i-1])
		{
			cout<<"No";
			return 0;
		}
	}
	for(i=0; i<a; i++)
	{
		if(s[i]!=s[a-i-1])
		{
			cout<<"No";
			return 0;
		}
	}
	for(i=b; i<n; i++)
	{
		if(s[i]!=s[n-i-1])
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
 } 

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

int main(){
  long X;
  cin >> X;
  long ans = 0;
  while(!ans){
    long x = X--;
    for(int i = 2; i <= x; i++){
      long tmp = x;
      int cnt = 0;
      while(tmp % i == 0) {
        tmp /= i;
        cnt++;
      }
      if(tmp == 1 && cnt > 1) ans = x;
    }
    if(x == 1) ans = 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } 
using ll=long long;
 int main(){
 ll a,b,n,x;
   cin>>a>>b>>n;
   if(b<=n)cout<<a*(b-1)/b<<endl;
   else cout<<a*n/b<<endl;
}

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

// バブルソート

void bubblesort(vector<string> &card,int &n){
    for(int i=1; i < n; i++){
        for(int j = n-1; j>=i ; j--){
            char str_card1 = card.at(j).at(1);
            char str_card2 = card.at(j-1).at(1);
            if(str_card1 < str_card2){
                swap(card.at(j),card.at(j-1));
            }
        }
    }
}

void selectsort(vector<string> &card, int &n){
    for(int i=0; i<n; i++){
        char minv = card.at(i).at(1);
        int index = i;
        for(int j=i; j<n; j++){
            if(minv > card.at(j).at(1)){
                minv = card.at(j).at(1);
                index = j;
            }
        }
        swap(card.at(i),card.at(index));
    }
}


int main(){
    int n;
    cin >> n;
    vector<string> card(n);
    vector<string> card_copy(n);
    for(int i=0; i<n; i++) cin >> card.at(i);
    for(int i=0; i<n; i++) card_copy.at(i) = card.at(i);
    bubblesort(card,n);
    selectsort(card_copy,n);
    for(int i=0; i<n; i++){
        if(i==n-1){
            cout << card.at(i) << endl;
        }else{
        cout << card.at(i) << " ";}
    }
    cout << "Stable" << endl;
    bool flag = true;
    for(int i=0; i<n; i++){
        if(i==n-1){
            cout << card_copy.at(i) << endl;
        }else{
        cout << card_copy.at(i) << " ";}
        if(card.at(i) != card_copy.at(i)){
        flag = false;
    }
    }
    if(flag){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
    
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n, m;
    ll k;
    cin >> n >> m >> k;
    vector<ll> a, b;
    ll sum=0;
    bool flag=true;
    a.push_back(sum);
    rep(i, n){
        ll x;
        cin >> x;
        sum += x;
        if(flag){
            if(sum<=k){
                a.push_back(sum);
            }else{
                flag=false;
            }
        }
    }
    sum=0;
    flag = true;
    b.push_back(sum);
    rep(i, m) {
      ll x;
      cin >> x;
      sum += x;
      if (flag) {
        if (sum <= k) {
            b.push_back(sum);
        } else {
            flag = false;
        }
      }
    }
    int maxim=0;
    for(int i=a.size()-1;i>=0;i--){
      ll rem = k - a[i];
      vector<ll>::iterator pos = upper_bound(b.begin(), b.end(), rem);
      int dis = distance(b.begin(), pos)-1;
      maxim = max(maxim, i+dis);
    }
    cout << maxim << endl;
    return 0;
}

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

using namespace std;

int x, t = 2, z, ans, temp = 0x7fffffff;

int main() {
    cin >> x;
    if (x == 1) {
        cout << 1 << endl;
        return 0;
    }
    for (int j = 2; j * j <= x; j++) {
        t = j * j;
        while (t <= x) {
            if (x - t < temp) {
                temp = x - t;
                ans = t;
            }
            t *= j;
        }
    }
    cout << ans << endl;
}

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

int main() {
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;
    int max = -1;
    int maxp;
    for(int i = 0; i < n; i++) {
      int p, d1, d2;
      cin >> p >> d1 >> d2;
      int tmp = d1+d2;
      if(tmp > max) {
	max = tmp;
	maxp = p;
      }
    }
    cout << maxp << " " << max << endl;
  }
  return 0;
}

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

int main()
{
  int a,b,c,d,e,f;
  cin >> a;
  cin >> b;
  c=(a+b);
  d=((c+1)/2);
  e=(c%2);
  f=(c/2);
  if (e==0)
  {
    cout << f<< endl;
  }
  else 
  {
    cout << d<< endl;
  }
  return 0;
 }

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iomanip>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define int long long
#define For(i,x,y) for(int i = x; i <= y; ++i)
#define FOR For
#define rev_For(i,x,y) for(int i = x; i >= y; --i)
#define REV_FOR rev_For
#define ll long long
#define Size(v) ((int)v.size())
#define _section "\n--------------------\n"
#define fi first
#define se second
#define pb push_back
using namespace std;
// using namespace __gnu_pbds;


int n;
vector<char> s;
vector<int> red, green, blue;
set<int> r, g, b;

void input() {
	cin >> n;
	s.resize(n + 1);
	FOR (i, 1, n) {
		cin >> s[i];
		if (s[i] == 'R') r.insert(i);
		else if (s[i] == 'G') g.insert(i);
		else b.insert(i);
	}
	for (auto &c : r) red.pb(c);
	for (auto &c : g) green.pb(c);
	for (auto &c : b) blue.pb(c);
}

void solve() {
	int sum = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			if (s[i] != s[j]) {
				if (s[i] != 'R' && s[j] != 'R') {
					auto pos = lower_bound(red.begin(), red.end(), j);
					int add = red.end() - pos;
					if (r.find(i + 2 * (j - i)) != r.end()) --add;
					sum += add;
				}
				else if (s[i] != 'G' && s[j] != 'G') {
					auto pos = lower_bound(green.begin(), green.end(), j);
					int add = green.end() - pos;
					if (g.find(i + 2 * (j - i)) != g.end()) --add;
					sum += add;
				}
				else if (s[i] != 'B' && s[j] != 'B') {
					auto pos = lower_bound(blue.begin(), blue.end(), j);
					int add = blue.end() - pos;
					if (b.find(i + 2 * (j - i)) != b.end()) --add;
					sum += add;
				}
			}
		}
	}

	cout << sum;
}

signed main() {
#ifdef _DEBUG
	// freopen("INPUT.inp", "r", stdin);
	//freopen("OUTPUT.out", "w", stdout);
	clock_t start, end;
	start = clock();
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
//------------------------------------------------------------------------------------
//----------------------------------MAIN PROGRAM--------------------------------------
	int t = 1;
	while (t--) {
		input();
		solve();
	}
//--------------------------------------END-------------------------------------------
//------------------------------------------------------------------------------------
#ifdef _DEBUG
	end = clock();
	cerr << "\n----------\nTime Elapsed: " << fixed << double(end - start) / double(CLOCKS_PER_SEC) << setprecision(6) << '\n';
#endif
	return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n)       for(int i=(int)m; i<(int)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define prt(var)         cout << var << endl
#define prtd(n, var)     cout << fixed << setprecision(n) << var << endl
#define prt2(var1, var2) cout << var1 << " " << var2 << endl
#define prseq(var, n)    rep(i,n){cout << var[i] << " ";} cout << endl
#define prseql(var, n)   rep(i,n){cout << var[i] << " " << endl;}

//----------------------------------------------------------------
class Graphs{

public:
  vector<vector<int>> graph;
  vector<int> check; // For DFS
  vector<ll> dist;   // For BFS
  queue<int> q; // For BFS

  Graphs(int n){
    graph.resize(n);
    init(n);
  }
  ~Graphs(){}

  void addpath(int m){
    int a, b;
    rep(i,m){
      cin >> a >> b;
      a--; b--;
      graph[a].push_back(b);
      graph[b].push_back(a);
    }
  }
  void init(int n){
    check.assign(n, false);
    dist.assign(n, 0);
  }
  void resetCheck(){
    rep(i,check.size()){
      check[i] = false;
    }
  }

  //----------------------------
  void dfs(int v){
    check[v] = true;


    for(auto next_v : graph[v]){
      if(check[next_v]) continue;
      dist[next_v] += dist[v];
      dfs(next_v);
    }
  }

  //---------------------------
  void bfs(int v){
    dist[v] = 0;
    q.push(v);

    while(!q.empty()){
      int cur_v = q.front();
      q.pop();

      for(int next_v : graph[cur_v]){
        if(dist[next_v] != -1){
          continue;
        }

        dist[next_v] = dist[cur_v] + 1;
        q.push(next_v);
      }
    }
  }
  //---------------------------
};

int main(void) {
  int n, q;
  cin >> n >> q;

  Graphs g(n);
  g.addpath(n-1);

  rep(i,q){
    int p;
    ll x;
    cin >> p >> x;
    p--;
    g.dist[p] += x;
  }

  g.dfs(0);
  prseq(g.dist,n);

}


Measured memory_bytes: 20864
#include <bits/extc++.h>

#ifndef DUMP
#define DUMP(...) (void)0
#endif

using namespace std;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int h, w, m;
  cin >> h >> w >> m;
  vector<vector<int>> js(h);
  vector<int> a(w);
  while (m--) {
    int i, j;
    cin >> i >> j;
    --i, --j;
    js[i].push_back(j);
    ++a[j];
  }
  int res = 0;
  multiset ms(begin(a), end(a));
  for (int i = 0; i < h; ++i) {
    for (int j : js[i]) {
      ms.erase(ms.find(a[j]));
      --a[j];
      ms.insert(a[j]);
    }
    res = max(res, (int)size(js[i]) + *rbegin(ms));
    for (int j : js[i]) {
      ms.erase(ms.find(a[j]));
      ++a[j];
      ms.insert(a[j]);
    }
  }
  cout << res << '\n';
}


Measured memory_bytes: 34872
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
using ll = long long;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int k, ans = 0;
	cin >> k;
	if (a >= b && a >= c)ans = a * pow(2, k) + b + c;
	else if (b >= a && b >= c)ans = b * pow(2, k) + a + c;
	else ans = c * pow(2, k) + a + b;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	long long a=2,b=1;
	int x;
	scanf("%d",&x);
	long long anc=1;
	for(int i=2;i<=x;i++)
	{
		anc=a+b;
		a=b;
		b=anc;
	 } 
	 printf("%lld\n",anc);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

void process();

int main(){
    int X,Y;
    int A,B,C;
    int i,j;
    ULL *g,*n,*r;
    ULL *rg;
    cin >> X >> Y;
    cin >> A >> B >> C;
    ULL *rg_sum;
    ULL *n_sum;
    rg_sum = new ULL[X+Y+1];
    n_sum = new ULL[X+Y+1];
    ULL max_dis;
    r = new ULL[A];
    g = new ULL[B];
    n = new ULL[C];
    rg = new ULL[X+Y];
    for(i=0;i<A;i++){
        cin >> r[i];
    }
    sort(r,r+A,std::greater<ULL>());
    for(i=0;i<B;i++){
        cin >> g[i];
    }
    sort(g,g+B,std::greater<ULL>());
    for(i=0;i<C;i++){
        cin >> n[i];
    }
    sort(n,n+C,std::greater<ULL>());
    for(i=0;i<X;i++){
        rg[i] = r[i];
    }
    for(j=0;j<Y;j++,i++){
        rg[i] = g[j];
    }
    sort(rg,rg+X+Y,std::greater<ULL>());
    n_sum[0] = 0;
    rg_sum[0] = 0;
    for(i=1;i<=X+Y;i++){
        rg_sum[i] = rg_sum[i-1] + rg[X+Y-i];
    }
    for(i=1;i <= X+Y && i <= C;i++){
        n_sum[i] = n_sum[i-1] + n[i-1];   
    }
    max_dis = 0;
    for(i=1;i<=X+Y && i<= C; i++){
        if(n_sum[i] > rg_sum[i]){
            if(max_dis < n_sum[i] - rg_sum[i]){
                max_dis = n_sum[i] - rg_sum[i];
            }
        }
    }
    std::cout << rg_sum[X+Y]+ max_dis << std::endl;
    //std::cout << TEMP << std::endl;
    return 0;
    
}

void process(){
    
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  IN(N);
  string ans = "";
  ll diff = 'z'-'a'+1;
  while(N>0){
    ans += ((N-1)%diff)+'a';
    N--;
    N/=diff;
  }
  reverse(ALL(ans));
  OUT(ans);

  return 0;
}

Measured memory_bytes: 3652
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long X = sc.nextLong();
		long D = sc.nextLong();
		System.out.println(solve(N, X, D));
//		for (long n = 1; n < 10; ++n) {
//			for (long x = -10; x <= 10; ++x) {
//				for (long d = -10; d <= 10; ++d) {
//					if (solve(n, x, d) != exact(n, x, d)) {
//						tr(n, x, d, solve(n, x, d), exact(n, x, d));
//						return;
//					}
//				}
//			}
//		}
	}

	long exact(long N, long X, long D) {
		long[] A = new long[(int) N];
		A[0] = X;
		for (int i = 1; i < A.length; ++i) {
			A[i] = A[i - 1] + D;
		}
		HashSet<Long> set = new HashSet<Long>();
		for (int s = 0; s < 1 << N; ++s) {
			long sum = 0;
			for (int shift = 0; shift < N; ++shift) {
				if ((s >> shift) % 2 == 1) {
					sum += A[shift];
				}
			}
			set.add(sum);
		}
		return set.size();
	}

	long solve(long N, long X, long D) {
		if (D < 0) {
			X *= -1;
			D *= -1;
		} else if (D == 0) {
			if (X == 0) {
				return 1;
			} else {
				return N + 1;
			}
		}
		HashSet<Long> set = new HashSet<>();
		for (int i = 1; i <= N; ++i) {
			set.add(((X * i % D) + D) % D);
		}
		set.add(0L);
		long[] id = new long[set.size()];
		int p = 0;
		for (long v : set) {
			id[p++] = v;
		}
		Arrays.sort(id);
		PriorityQueue<long[]>[] pq = new PriorityQueue[set.size()];
		for (int i = 0; i < pq.length; ++i) {
			pq[i] = new PriorityQueue<long[]>(new Comparator<long[]>() {
				@Override
				public int compare(long[] o1, long[] o2) {
					if (o1[0] != o2[0]) {
						return Long.compare(o1[0], o2[0]); // start, end
					} else {
						return Long.compare(o1[1], o2[1]);
					}
				}
			});
		}
		long ans = 0;
		for (long i = 1; i <= N; ++i) {
			long mod = (X * i % D + D) % D;
			int idx = Arrays.binarySearch(id, mod);
			if (idx < 0)
				throw new AssertionError();
			long start = i * (i - 1) / 2;// 0+1+...+i-1=(1/2)i(i-1)
			long end = N * i - i * (i + 1) / 2;// (n-i)...+(n-2)+(n-1)=ni-i(i+1)/2
			pq[idx].add(new long[] { start * D + X * i, end * D + X * i });
		}
		pq[0].add(new long[] { 0, 0 });
		for (int i = 0; i < pq.length; ++i) {
			while (!pq[i].isEmpty()) {
				long[] a = pq[i].poll();
				while (!pq[i].isEmpty() && a[1] >= pq[i].peek()[0]) {
					if (a[1] > pq[i].peek()[1]) {
						pq[i].poll();
					} else {
						long[] b = pq[i].poll();
						a[1] = b[1];
					}
				}
				ans += (a[1] - a[0] + D) / D;
			}
		}
		return ans;
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


Measured memory_bytes: 69188
{-# OPTIONS_GHC -Wno-tabs #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE BangPatterns #-}

-- Default Imports

import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Class

import qualified Control.Monad.Reader as Reader
import Control.Monad.Reader (Reader, ReaderT, runReader, runReaderT)

import qualified Data.Array.MArray as MArray
import qualified Data.Array.ST as STArray
import Data.Array.ST (STArray, STUArray, runSTArray, runSTUArray)
import Data.Ix (Ix)

import qualified Data.Bits as Bits
import Data.Bits ((.&.), (.|.))

import qualified Data.ByteString.Char8 as BS
import Data.ByteString.Char8 (ByteString)

import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import Data.Map.Strict (Map)
import qualified Data.Maybe as Maybe
import qualified Data.Set as Set
import Data.Set (Set)

import qualified Data.Vector as Vector
import qualified Data.Vector.Generic as GVector
import qualified Data.Vector.Mutable as MVector
import Data.Vector.Mutable (STVector)
import qualified Data.Vector.Unboxed as UVector

import Numeric

import Debug.Trace
-- ----------

-- Custom Import Here


-- ----------

-- Default Definitions

type Vector = Vector.Vector
-- type GVector = GVector.Vector
type UVector = UVector.Vector

readIntToList :: ByteString -> [Int]
readIntToList = List.unfoldr (fmap (second $ BS.dropWhile Char.isSpace) . BS.readInt)

readToList :: Read a => ByteString -> [a]
readToList = List.unfoldr $ fmap (mapTaken . mapRemain) . span' (not . Char.isSpace)
	where
		mapTaken  = first $ read . BS.unpack
		mapRemain = second $ BS.dropWhile Char.isSpace
		span' pred s
			| BS.null taken = Nothing
			| otherwise     = Just (taken, remain')
			where
				(taken, remain) = BS.span pred s
				remain' = BS.dropWhile Char.isSpace remain

readToListN :: Read a => Int -> ByteString -> [a]
readToListN n = take n . readToList

readIntToVector :: ByteString -> Vector Int
readIntToVector = Vector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVector :: ByteString -> UVector.Vector Int
readIntToUVector = UVector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToVectorN :: Int -> ByteString -> Vector.Vector Int
readIntToVectorN n = Vector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVectorN :: Int -> ByteString -> UVector.Vector Int
readIntToUVectorN n = UVector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace


first :: (a -> a') -> (a, b) -> (a', b)
first f (a, b) = (f a, b)

second :: (b -> b') -> (a, b) -> (a, b')
second f (a, b) = (a, f b)

average :: Fractional a => [a] -> a
average xs = sum xs / (fromIntegral . length) xs

-- ----------

main :: IO ()
main = do
	s <- getLine
	print $ case s of
		"RRR" -> 3
		"RRS" -> 2
		"SRR" -> 2
		"RSS" -> 1
		"SRS" -> 1
		"SSR" -> 1
		"RSR" -> 1
		_     -> 0

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

# define ll long long
ll mod=pow(10,9)+7;

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

    int n;
    cin>>n;
    int ar[n][3];

    for(int i=0;i<n;i++)
        cin>>ar[i][0]>>ar[i][1]>>ar[i][2];

    int dp[n][3];
    dp[0][0]=ar[0][0],dp[0][1]=ar[0][1],dp[0][2]=ar[0][2];

    for(int i=1;i<n;i++){
        dp[i][0]=ar[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=ar[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=ar[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
}


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

typedef long long ll;
const ll INF=1000000000000000;

#define chmin(a,b) a=min(a,b)

int main(){
	static ll n;
	static ll a[200010];
	scanf("%lld",&n);
	for(int i=0;i<n;i++)scanf("%lld",&a[i]);
	
	ll sum=0;
	for(int i=0;i<n;i++)sum+=a[i];
	ll ret=INF;
	ll s=0;
	for(int i=0;i<n-1;i++){
		s+=a[i];
		chmin(ret,abs(sum-s-s));
	}
	cout<<ret<<endl;
}



Measured memory_bytes: 1792
n = int(input())

otc = []
for _ in range(n):
    x, u = input().split()
    otc.append((x, u))

score = 0
for x, u in otc:
    if u == "JPY":
        score += float(x)
    if u == "BTC":
        score += 380000 * float(x)

print(score)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef int shar;
typedef double shara;
typedef string w;
int main(){
    w s;
    cin>>s;
    if(s.at(0)==s.at(1)&&s.at(2)==s.at(3)&&s.at(0)==s.at(3)){cout<<"No";}
    else if(s.at(0)==s.at(1)&&s.at(2)==s.at(3))
    {cout<<"Yes";}
    else if(s.at(0)==s.at(2)&&s.at(1)==s.at(3))
    {cout<<"Yes";}
    else if(s.at(1)==s.at(2)&&s.at(0)==s.at(3))
    {cout<<"Yes";}
    else{cout<<"No";}
  return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
s_list = [input() for i in range(H)]
flag = True

for i in range(1, H - 1):
	for j in range(1, W - 1):
		if s_list[i][j] == "#":
			if s_list[i-1][j] == "." and s_list[i+1][j] == "." and s_list[i][j-1] == "." and s_list[i][j+1] == ".":
				flag = False
				break
if flag:
	print("Yes")
else:
	print("No")

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end() 
#define size(x) ll(x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

int main() {
  int n,cnt=0;
  
  cin >> n;
  vvi d(n,vi(2));
  rep(i,n){
    cin >> d[i][0] >> d[i][1];
  }
  rep(i,n) {
    if(d[i][0] == d[i][1]) {
      cnt++;
      if(cnt == 3) {
        break;
      }
    }else{
      cnt=0;
    }
  }
  if(cnt >= 3) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3588
n = int(input())
rest = {}
for i in range(n):
  s, p = input().strip().split()
  if s in rest:
    rest[s].append((int(p), i))
  else:
    rest[s] = [(int(p), i)]

for k, v in sorted(rest.items(), key=lambda x: x[0]):
  for _, i in sorted(v, key=lambda x: -x[0]):
    print(i+1)


Measured memory_bytes: 3060
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

class UnionFind {
private:
	vector<int> data;
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }

public:
	UnionFind(int size) : data(size, -1) { }
	bool is_same(int x, int y) { return root(x) == root(y); }
	int size(int x) { return -data[root(x)]; }

	void unify(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
};


int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

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

	vector<int> p(N);
	UnionFind uf(N);
	for (int i = 0; i < N; i++) cin >> p[i];
	int x, y;
	for (int i = 0; i < M; i++) {
		cin >> x >> y;
		x--, y--;
		uf.unify(x, y);
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (uf.is_same(i, p[i] - 1))ans++;
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
#define all(a) a.begin(),a.end()
using namespace std;
int n,m,k;
int x[300005]={0},y[300005]={0};
int a[300005],b[300005];
bool mx[300005]={0},my[300005]={0};
map<pii,bool>g;
vi vx,vy;
int main(void){
	cin>>n>>m>>k;
	REP(i,k){
		cin>>a[i]>>b[i];
		a[i]--;
		b[i]--;
		g[mp(a[i],b[i])]=1;
		x[a[i]]++;
		y[b[i]]++;
	}
//	REP(i,n)cout<<x[i]<<' ';
//	cout<<endl;
//	REP(i,m)cout<<y[i]<<' ';
//	cout<<endl;
	int maxx=-1,maxy=-1;
	REP(i,n)maxx=max(maxx,x[i]);
	REP(i,m)maxy=max(maxy,y[i]);
//	cout<<maxx<<' '<<maxy<<endl;
	REP(i,n)if(x[i]==maxx){
		vx.pb(i);
		mx[i]=1;
//		cout<<i<<' ';
	}
//	cout<<endl;
	REP(i,m)if(y[i]==maxy){
		vy.pb(i);
		my[i]=1;
//		cout<<i<<' '<<endl;
	}
	int ans=-1;
	REP(i,vx.size()){
		REP(j,vy.size()){
			if(!g[mp(vx[i],vy[j])]){
				ans=maxx+maxy;
				break;
			}
		}
		if(ans!=-1)break;
	}
//	cout<<endl;
//	cout<<endl;
	if(ans!=-1)cout<<ans;
	else cout<<maxx+maxy-1;
	return 0;
}

Measured memory_bytes: 31384