akhauriyash/Code-Regression huggingface dataset:
// 26.07.2020
// 00:38:12

#pragma GCC optimize("O3")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define IOS ios::sync_with_stdio(false); cin.tie(0)
#define ll long long
#define ld long double
#define rep(i,a,n) for (int i=(int)(a);i<(int)(n);i++)
#define per(i,a,n) for (int i=(int)(n-1);i>=(int)(a);i--)
#define mp(a, b) make_pair(a, b)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define fi first
#define se second


const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1};


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


int main() {
    long long n, sum = 0;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }

    if (sum % (n * (n + 1) / 2)) {
        cout << "NO\n";
        return 0;
    }

    long long cnt = sum / (n * (n + 1) / 2);
    long long sum_b = 0;

    for (int i = 0; i < n; ++i) {
        long long dif = a[i] - a[(i + 1) % n];
        dif += cnt;
        if (dif < 0 || dif % n != 0) {
            cout << "NO\n";
            return 0;
        }
        sum_b += dif / n;
    }

    if (sum_b == cnt) {
        cout << "YES\n";
    }
    else {
        cout << "NO\n";
    }
}


Measured memory_bytes: 4012
import std;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    long ans;
    foreach (i; 1 .. N + 1)
    {
        if (i % 3 != 0 && i % 5 != 0)
            ans += i;
    }
    writeln(ans);
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <vector>
using namespace std;
const int INF = 0x3f3f3f3f;

int main(){
	int ans = 0;
	char ch;
	stack<int> s1;
	stack<pair<int, int> > s2;
	for(int i = 0; cin >> ch; i++){
		if(ch == '\\')
			s1.push(i);
		else if(ch == '/' && s1.size() > 0){
			int j = s1.top();
			s1.pop();
			ans += i - j;
			int temp = i  - j;
			while(s2.size() > 0 && s2.top().first > j){
				temp += s2.top().second;
				s2.pop();
			}
			s2.push(make_pair(j, temp));
		}
	}
	vector<int > v;
	while(s2.size() > 0){
		v.push_back(s2.top().second);
		s2.pop();
	}
	reverse(v.begin(), v.end());
	printf("%d\n%d", ans, v.size());
	for(int i = 0; i < v.size(); i++)
		printf(" %d", v[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 3284
#!/usr/bin/env python3

n, capa, k = [int(x) for x in input().split()]
T = sorted([int(input()) for _ in range(n)])

bus = now = 0
limit = T[0] + k
for t in T:
    if now == capa or t > limit:
        bus += 1
        now = 1
        limit = t + k
    else:
        now += 1

if now > 0:
    bus += 1

print(bus)


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

int func(int l, int r, int N){
  int size=to_string(N).size();
  int count=0;
  int c=1;
  for(int i=1; i<=size; i++){
    if(i==1){
      if(l==r&&l<=N){
        count++;
      }
    }else{
      for(int k=0; k<c; k++){
        if(l*10*c+k*10+r<=N){
          count++;
        }
      }
      c*=10;
    }
  }
  return count;
}

int main(){
  int N; cin >> N;
  int count=0;
  for(int i=1; i<=N; i++){
    int l=to_string(i)[0]-'0',r=to_string(i)[to_string(i).size()-1]-'0';
    if(l*r>0) count+=func(r,l,N);
  }
  cout << count << endl;
}

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

string s[200005];
int main()
{
    int n;
    cin>>n;
    map<string,int>m;
    set<string>q;
    int ans=0;
    for(int i=0;i<n;i++){
        cin>>s[i];
        m[s[i]]++;
        ans=max(m[s[i]],ans);
    }
    for(int i=0;i<n;i++)
        if(m[s[i]]==ans) q.insert(s[i]);

    for(set<string>::iterator i=q.begin();i!=q.end();i++) cout<<*i<<endl;
}


Measured memory_bytes: 36096
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
using namespace std;
typedef long long int ll;
ll mod=1000000007;
int gcd(ll a,ll b){ return (b%a==0)?a:gcd(b-a*(b/a),a);}
int main()
{
   ll i,j,k=0,n,t,x;
   cin>>n;ll a[n];
   for(i=0;i<n;i++){cin>>a[i];}
   j=a[0];
   for(i=1;i<n;i++){
   	if(a[i]<j){k+=j-a[i];}
   	else{j=a[i];}
   }
   cout<<k;
   return 0;
}
		

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

int main()
{
    string s;
    cin >> s;

    int count = 0;

    for(int i = 0; i < s.size()-1; i++)
    {
        if(s.at(i) == s.at(i+1))
        {
            if(s.at(i+1) == '0')s.at(i+1) = '1';
            else s.at(i+1) = '0';
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
int n;

struct Node {
    int k;
    Node *l, *r, *p;
};

Node *root = nullptr;


void insert(Node* inode) {
    if (root == nullptr) {
        root = inode;
        return;
    }
    Node* tgt = root;
    while (true) {
        if (inode->k < tgt->k) {
            if (tgt->l == nullptr) {
                tgt->l = inode;
                inode->p = tgt;
                break;
            }else{
                tgt = tgt->l;
            }
        }else{
            if (tgt->r == nullptr) {
                tgt->r = inode;
                inode->p = tgt;
                break;
            }else{
                tgt = tgt->r;
            }
        }
    }
}

Node* find(int k) {

    Node *tgt = root;
    while (tgt != nullptr) {
        if (tgt->k == k) {
            return tgt;
        }
        if (k < tgt->k) tgt = tgt->l;
        else tgt = tgt->r;
    }
    return nullptr;
}

void Delete(Node *tgt) {
    if (tgt == root) {
        root == nullptr;
    }
    if ((tgt->l == tgt->r) && tgt->l == nullptr) {
        if (tgt->p->l == tgt) tgt->p->l = nullptr;
        else tgt->p->r = nullptr;
    }else if((tgt->l != nullptr) && (tgt->r != nullptr)) {
        Node *m = tgt->r;
        while (m->l != nullptr) {
            m = m->l;
        }
        int nk = m->k;
        Delete(m);
        tgt->k = nk;
    }else{
        Node *c = tgt->l != nullptr? tgt->l: tgt->r;
        c->p = tgt->p;
        if (tgt->p->l == tgt) tgt->p->l = c;
        else tgt->p->r = c;
    }
}

void Preorder(Node* n) {
    if (n == nullptr) {
        return;
    }
    std::cout << " " << n->k;
    Preorder(n->l);
    Preorder(n->r);
}
void Inorder(Node* n) {
    if (n == nullptr) {
        return;
    }
    Inorder(n->l);
    std::cout << " " << n->k;
    Inorder(n->r);
}

int main() {
    std::cin >> n;
    std::vector<Node> T;
    T.reserve(n);

    FOR(i, 0, n){
        std::string instruction;
        std::cin >> instruction;
        if (instruction == "insert") {
            Node n{0, nullptr, nullptr, nullptr};
            std::cin >> n.k;
            T.push_back(n);
            insert(&T[T.size() - 1]);
        }else if(instruction == "print") {
            Inorder(root);
            std::cout << std::endl;
            Preorder(root);
            std::cout << std::endl;
        }else if(instruction == "find") {
            int k;
            std::cin >> k;
            if (find(k) == nullptr) std::cout << "no" << std::endl;
            else std::cout << "yes" << std::endl;
        }else if(instruction == "delete") {
            int k;
            std::cin >> k;
            Delete(find(k));
        }
    }
}


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

inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}

using namespace std;



int main( int argc , char * argv[] ){
	int n = read() , k = read() , gcd = 0 , mx = 0;
	for(int i = 1 ; i <= n ; ++ i){
		int x = read();
		mx = max( mx , x );
		gcd = __gcd( gcd , x );
	}
	if( k > mx )
		puts( "IMPOSSIBLE" );
	else if( k % gcd == 0 )
		puts( "POSSIBLE" );
	else
		puts( "IMPOSSIBLE" );
	return 0;
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  
  vector<long long> d(n);
  for(int i = 0; i < n; i++) cin >> d[i];
  
  long long sum = 0;
  for(int i = 0; i < n - 1; i++){
    for(int j = i + 1; j < n; j++){
      sum += d[i] * d[j];
    }
  }
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::cmp::max;

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s
}

fn main() {
    let (A, B, C) = {
        let v: Vec<i32> = read_line().split_whitespace().map(|a| a.parse().unwrap()).collect();
        (v[0], v[1], v[2])
    };
    println!("{}", max(0, C-(A-B)));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> num(n);
  for(int i = 0; i < n; i++){
    cin >> num.at(i);
  }
  for(int j = n - 1; j > 0; j--){
    cout << num.at(j) << " ";
  }
  cout << num.at(0) << endl;
}


Measured memory_bytes: 3084
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func calc(radius string)  {
	iRadius, _ := strconv.Atoi(radius)
	fmt.Println(3*iRadius*iRadius)
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
			calc(scanner.Text())
	}
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	int t;
	scanf("%d",&t);
	rep(ppp,t){
		int n,d;
		scanf("%d%d",&n,&d);
		if((n-1)%2 == 0)cout << (n-1)*127+d << endl;
		else cout << n*127-d << endl;
	}
}



Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    int n; string s, t; cin >> n >> s >> t;
    string r = s + t;
    int res = r.size();
    for(int i=n-1; i>=0; i--){
        if(r.size() == 1) break;
        r.erase(i, 1);
        string a = r.substr(0, n), b = r.substr(r.size()-n);
        if(a == s && b == t)
            res = r.size();
    }
    cout << res << ln;
}


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

int main(){
  int N;
  cin >> N;
  vector<int64_t> A(N),B(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i) >> B.at(i);
  }
  int64_t ans=0;
  for(int i=N-1;i>=0;i--){
    A.at(i)+=ans;
    ans+=B.at(i)*((A.at(i)+B.at(i)-1)/B.at(i))-A.at(i);
  }
  cout << ans << endl;
  return 0;
}


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

const int INF=200000000;
int edge[100][100][20],dist[100][100][20],p[20],q[51],r[50],d2cost[20000],cost[100][100];

int main(){
    int n,m,c,s,g;
    for(;;){
        cin>>n>>m>>c>>s>>g;
        s--;g--;
        if(n==0) break;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                for(int k=0;k<c;k++){
                    edge[i][j][k]=INF;
                }
            }
        }
        int x,y,d,cc;
        for(int i=0;i<m;i++){
            cin>>x>>y>>d>>cc;
            x--;y--;cc--;
            edge[x][y][cc]=min(edge[x][y][cc],d);
            edge[y][x][cc]=min(edge[y][x][cc],d);
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                for(int k=0;k<c;k++){
                    dist[i][j][k]=edge[i][j][k];
                }
            }
        }
        for(int i=0;i<c;i++){
            cin>>p[i];
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cost[i][j]=INF;
            }
        }
        for(int ii=0;ii<c;ii++){
            for(int k=0;k<n;k++){
                for(int i=0;i<n;i++){
                    for(int j=0;j<n;j++){
                        if(dist[i][j][ii]>dist[i][k][ii]+dist[k][j][ii]){
                            dist[i][j][ii]=dist[i][k][ii]+dist[k][j][ii];
                        }
                    }
                }
            }
            q[0]=0;
            q[p[ii]]=INF;
            for(int i=1;i<p[ii];i++){
                cin>>q[i];
            }
            for(int i=0;i<p[ii];i++){
                cin>>r[i];
            }
            d2cost[0]=0;
            int qat=0;
            for(int i=1;i<20000;i++){
                d2cost[i]=d2cost[i-1]+r[qat];
                while(q[qat+1]<=i) qat++;
            }
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    if(dist[i][j][ii]<INF){
                        cost[i][j]=min(cost[i][j],d2cost[dist[i][j][ii]]);
                    }
                }
            }
        }
        for(int k=0;k<n;k++){
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    if(cost[i][j]>cost[i][k]+cost[k][j]){
                        cost[i][j]=cost[i][k]+cost[k][j];
                    }
                }
            }
        }
        if(cost[s][g]<INF) cout<<cost[s][g]<<endl;
        else cout<<-1<<endl;
    }
}

Measured memory_bytes: 2840
var
	A,B,C,K:Longint;
begin
	read(A,B,C,K);
	while A>=B do begin
		dec(K);
		B:=B*2;
	end;
	while B>=C do begin
		dec(K);
		C:=C*2;
	end;
	if K<0 then writeln('No')else writeln('Yes');
end.

Measured memory_bytes: 1364
n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
ans = 0

from heapq import heappush, heappop
for i in range(1, k+1):
  for j in range(0, i+1):
    minus = []
    l = min(n, j)
    r = min(n-l, i-l)
    cur = 0
    for ll in range(l):
      cur += v[ll]
      if v[ll]<0:
        heappush(minus, v[ll])
    for rr in range(r):
      cur += v[n-rr-1]
      if v[n-rr-1]<0:
        heappush(minus, v[n-rr-1])
    rm = k-l-r
    while rm>0 and len(minus)>0:
      rm -= 1
      cur -= heappop(minus)
    ans = max(ans, cur)
print(ans)

Measured memory_bytes: 60380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<bool> ok(30,false);
    int a;
    rep(i,28) cin >> a,ok[--a]=true;
    rep(i,30) if (!ok[i]) cout << i+1 << endl;
}


Measured memory_bytes: 3140
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long LL;
double PI=acos(-1);

LL n;

int f(LL s)
{
    int i=0;
    while(s>=1){
        i++;
        s/=10;
    }
    return i;
}

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

        int s=sqrt(n*1.0);
        while(s>=1){
            if(n%s==0){
                break;
            }
            s--;
        }
        cout<<f(n/s)<<endl;

    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>                                             
#include <vector>                                               
#include <algorithm>                                            
using namespace std;                                            
                                                                
int main(void) {                                                
  int x;                                                        
  vector<int> v;                                                
  for (int i=0; i<3; i++) {                                     
    cin >> x;                                                   
    v.push_back(x);                                             
  }                                                             
  sort(v.begin(),v.end());                                      
  for (int i=0; i<v.size(); i++) {                              
    cout << (i==0?"":" ") << v[i] << flush;                     
  }                                                             
  cout << endl;                                                 
  return 0;                                                     
}                                                               
                                   

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

counter = 0
while a%2==b%2==c%2==0:
    a, b, c = (b+c)//2, (a+c)//2, (a+b)//2
    counter += 1
    if counter > 26:
        counter = -1
        break
print(counter)

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

using namespace std;

int main() {
    
    int l,n,i;
    cin >> n >> l;
    std::vector<string> s(n);
    for(i = 0;i<n;i++){
        cin >> s[i];
    }
    sort(s.begin(),s.end());
    for(i=0;i<n;i++){
        cout << s[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> >vvi;
const ll MOD=1000000007LL;
int main(){
  int n,W;
  cin>>n>>W;
  vi v(n),w(n);
  rep(i,n)cin>>v[i]>>w[i];
  vector<int>dp(W+1);
  for(int i=0;i<n;i++){
    for(int j=w[i];j<=W;j++){
      dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
    }
  }
  cout<<dp[W]<<endl;
}


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

typedef long long int ll;

int main(){
    ll n,k;
    std::cin >> n >> k;
    std::vector<ll> h(n);
    ll sum=0;
    for(ll i=0;i<n;++i){
        std::cin >> h[i];
    }
    std::sort(h.begin(),h.end());
    
    for(ll i=0;i<n-k;++i){
        sum+=h[i];
    }
    std::cout << sum << std::endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;
    
#define EPS (1e-7)
#define INF (1<<30)
#define LLINF (1LL<<60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> v(n),c(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    for(int i=0;i<n;i++){
        cin>>c[i];
        v[i]-=c[i];
    }
    int res=0;
    for(int i=0;i<n;i++){
        if(v[i]>=0){
            res+=v[i];
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
    vector<vector<char>>v(3,vector<char>(3));
    for(int i=0;i<v.size();i++)
    {
        for(int j=0;j<v[i].size();j++)
        {
            cin>>v[i][j];
        }
    }
    string s="";
    for(int i=0;i<v.size();i++)
    {
        for(int j=0;j<v[i].size();j++)
        {
            if(i==j)
            {
                s+=v[i][j];
            }
        }
    }
    cout<<s;
}

Measured memory_bytes: 3540
# include <bits/stdc++.h>
using namespace std;
# define lli long long int
# define MOD 1000000007
# define INF 10000000000009
# define MAX 1000000



void solve(){
    lli n, k;
    cin >> n >> k;

    lli arr[n + 1];
    for(lli i = 1; i <= n; i++){
        cin >> arr[i];
    }

    lli dp[n + 1][k + 1];
    for(lli i = 0; i <= k; i++){
        dp[1][i] = (i <= arr[1] ? 1 : 0);
    }

    for(lli i = 2; i <= n; i++){
        for(lli j = 0; j <= k; j++){
            if(j == 0)
                dp[i][j] = dp[i - 1][j];
            else
                dp[i][j] = (MOD + dp[i][j - 1] + dp[i - 1][j] - ((j - arr[i] - 1 >= 0)
                    ? dp[i - 1][j - arr[i] - 1] : 0)) % MOD;
        }
    }

    cout << dp[n][k];

}


int main(){
    int t;
    t = 1;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 81688
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;


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

    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: 256
#include <bits/stdc++.h>

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 29
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

string s;
int cnt= 0;

int main(){
  cin >> s;
  char prev = s[0];
  FOR(i,1,s.size()){
    if(s[i]==prev) continue;
    cnt++;
    prev = s[i];
  }
  cout << cnt<<endl;
}


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

bool isprime(int n){
  if(n == 2) return true;
  if(n % 2 == 0) return false;
  for(int i=3; i*i<=n; i+=2){
    if(n % i == 0) return false;
  }
  return true;
}

int main(){
  int n; cin >> n;
  int ans = 0;
  for(int i=0; i<n; i++){
    int a; cin >> a;
    if(isprime(a)) ans++;
  }
  cout << ans << endl;
}


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

main(void)
{
    int x, y, z;
    cin>>x>>y>>z;
    vector<int> a(z+1);
    vector<int> b(z+1);
    vector<int> c(z+1);
    vector<int> d(z+1);
    for(int i=1;i<=z;i++)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    vector<int> ans(10);
    int fans = 0;
    //ansの配列を考える
    // for(int p=1;p<=10;p++){
    // ans[j]=p;
    // }
    for (int e = 1; e <= y; e++)
    {
        ans[1] = e;
        for (int f = e; f <= y; f++)
        {
            ans[2] = f;
            for (int g = f; g <= y; g++)
            {
                ans[3] = g;
                for (int h = g; h <= y; h++)
                {
                    ans[4] = h;
                    for (int k = h; k <= y; k++)
                    {
                        ans[5] = k;
                        for (int l = k; l <= y; l++)
                        {
                            ans[6] = l;
                            for (int m = l; m <= y; m++)
                            {
                                ans[7] = m;
                                for (int n = m; n <= y; n++)
                                {
                                    ans[8] = n;
                                    for (int o = n; o <= y; o++)
                                    {
                                        ans[9] = o;
                                        for (int p = o; p <= y; p++)
                                        {
                                            ans[10] = p;
                                            int chans = 0;
                                            for (int i = 1; i <= z; i++)
                                            {
                                                if ((ans[b[i]] - ans[a[i]]) == c[i]) chans += d[i];
                                            }
                                            fans = max(chans, fans);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    cout<<fans<<endl;
}

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

int main(){
    ll n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i)cin>>a[i];
    sort(a,a+n);
    ll sum=a[n-1];
    if(n==2){cout<<sum;return 0;}
    if(n&1){
    	sum = sum + a[n/2];
    	for(int i=(n/2)+1;i<=n-2;++i)sum = sum + 2*a[i];
    }
    else {
    	sum = sum + 2*a[n/2];
    	for(int i=(n/2)+1;i<=n-2;++i)sum = sum + 2*a[i];
    }
    cout<<sum;
    
    return 0;
}

Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int count=0;
	int i;
	int ans=s.size();
	for( i=(s.size()-1);i>=0;i--){
		if(s[i]=='T') count++;
		if(s[i]=='S' && count>0) {count--;ans-=2;}
	}
	cout<<ans;
}

Measured memory_bytes: 640
num = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

temp = int(input())

print(num[temp-1])


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<stdio.h>
#include<fstream>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<string.h>
#include<stack>

using namespace std;
struct point{
  int a,b;
  point *l,*r,*pa;
  point(){l=r=pa=NULL;}
  point(int sa,int sb):a(sa),b(sb){l=r=pa=NULL;};
};
point *root;
point *rightRotate(point *t){
  point *s=t->l;
  t->l=s->r;
  s->r=t;
  return s;
}
point *leftRotate(point *t){
  point *s=t->r;
  t->r=s->l;
  s->l=t;
  return s;
}
point* insert(point *p,int a,int b){
  if(p==NULL)return new point(a,b);
  if(a==p->a)return p;
  if(a<p->a){
    p->l=insert(p->l,a,b);
    if(p->b<p->l->b)
      p=rightRotate(p);
  }else{
    p->r=insert(p->r,a,b);
    if(p->b<p->r->b)
      p=leftRotate(p);
  }return p;
}
point *_del(point *p, int a);
point *del(point *p,int a){
  if(p==NULL)return NULL;
  if(a<p->a)p->l=del(p->l,a);
  else if(a>p->a)p->r=del(p->r,a);
  else return _del(p,a);
  return p;
}
point *_del(point *p, int a){
  if(p->l==NULL&&p->r==NULL)return NULL;
  else if(p->l==NULL)p=leftRotate(p);
  else if(p->r==NULL)p=rightRotate(p);
  else{
    if(p->l->b>p->r->b)p=rightRotate(p);
    else p=leftRotate(p);
  }return del(p,a);
}
bool find(int a){
  point *p=root;
  while(p){
    if(a==p->a)return 1;
    if(a>p->a)p=p->r;
    else p=p->l;
  }
  return 0;
}
void dfs1(point *p){
  if(!p)return;
  dfs1(p->l);
  printf(" %d",p->a);
  dfs1(p->r);
}
void dfs2(point *p){
  if(!p)return;
  printf(" %d",p->a);
  dfs2(p->l);
  dfs2(p->r);
}
int main(){
  ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  int T;cin>>T;
  int ta,tb;
  string s;
  while(cin>>s){
    if(s=="insert"){
      cin>>ta>>tb;
      //if(!root)root=new point(ta,tb);
      //else
      root=insert(root,ta,tb);
    }else if(s=="find"){
      cin>>ta;
      if(find(ta))printf("yes\n");
      else printf("no\n");
    }else if(s=="print"){
      dfs1(root);
      printf("\n");
      dfs2(root);
      printf("\n");
    }else if(s=="delete"){
      cin>>ta;
      root=del(root,ta);
    }
  }
  return 0;
}



Measured memory_bytes: 12676
while True:
  h,w,n = map(int,input().split())
  if not h: break
  sss = [[1 if s == "1" else 0 for s in input().split()] for i in range(h)]
  dp = [[0 for i in range(w + 1)] for j in range(h + 1)]
  dp[0][0] = n - 1
  for x in range(h):
    for y in range(w):
      a = dp[x][y]
      if sss[x][y]:
        if a % 2:
          dp[x + 1][y] += a // 2
          dp[x][y + 1] += a // 2 + 1
        else:
          dp[x + 1][y] += a // 2
          dp[x][y + 1] += a // 2
      else:
        if a % 2:
          dp[x + 1][y] += a // 2 + 1
          dp[x][y + 1] += a // 2
        else:
          dp[x + 1][y] += a // 2
          dp[x][y + 1] += a // 2
      sss[x][y] = (sss[x][y] + dp[x][y]) % 2

#  print(sss)
#  print(dp)
  x = y = 0
  while x < h and y < w:
    if sss[x][y]:
      y += 1
    else:
      x += 1
  print(x + 1,y + 1)



Measured memory_bytes: 30308
#include <bits/stdc++.h>
using namespace std;
queue<string>p;
unordered_map<string,int>q;
int main(){
    int n,m,i,temp,ans=0;
    string a;
    cin>>n>>m;
    for(i=0;i<n;i++){
        cin>>a>>temp;
        q[a]=temp;
        p.push(a);
    }
    while(!p.empty()){
        if(q[p.front()]-m>0){
            p.push(p.front());
            q[p.front()]-=m;
            ans+=m;
            p.pop();
        }else{
            ans+=q[p.front()];
            q.erase(p.front());
            cout<<p.front()<<" "<<ans<<endl;
            p.pop();
        }
    }
    return 0;
}


Measured memory_bytes: 8556
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long lint;

int main()
{
	int n;
	int a[200][3];
	int occ[101][3];
	int point[200];
	
	scanf("%d", &n);
	
	memset(occ, 0, sizeof(occ));
	
	for (int i = 0; i < n; i++){
		for (int j = 0; j < 3; j++){
			scanf("%d", &a[i][j]);
			occ[a[i][j]][j]++;
		}
	}
	
	memset(point, 0, sizeof(point));
	
	for (int i = 0; i < n; i++){
		for (int j = 0; j < 3; j++){
			point[i] += (occ[a[i][j]][j] == 1 ? a[i][j] : 0);
		}
	}
	
	for (int i = 0; i < n; i++) printf("%d\n", point[i]);
	
	return (0);
}

Measured memory_bytes: 1028
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using graph = vector<vector<int>>;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int n,m;
    cin >> n >> m;
    graph G(n);
    vector<int> signal(n,-1);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    queue<int> que;
    signal[0] = 0;
    que.push(0);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        for(int nv : G[v]){
            if(signal[nv] != -1) continue;
            signal[nv] = v + 1;
            que.push(nv);
        }
    }

    cout << "Yes" << endl;
    rep1(i,n-1) cout << signal[i] << endl;
}

Measured memory_bytes: 10288
#!/usr/bin/env python3
import sys


input = sys.stdin.readline
def IS(cb): return cb(input().strip())
def IL(cb): return [cb(s) for s in input().strip().split()]
def IR(cb, rows): return [IS(cb) for _ in range(rows)]
def ILL(cb, rows): return [IL(cb) for _ in range(rows)]


def solve():
    N, M, X = IL(int)
    CA = ILL(int, N)
    ans = float('Inf')
    ok = False
    for bit in range(2 ** N):
        skill = [0] * M
        cost = 0
        for i in (b for b in range(N) if (0x01 << b) & bit):
            for j in range(M):
                skill[j] += CA[i][j + 1]
            cost += CA[i][0]
        if all(j >= X for j in skill):
            ok = True
            ans = min(ans, cost)

    print(ans if ok else -1)


solve()


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

using namespace std;

int main(){
  long long int N, cnt=0, ans=0, tmp;
  bool prime = true;
  cin >> N;
  long long int X = N, i;
  for(i=2; i*i<=X; i++){
    cnt = 0;
    while(N%i == 0){
      if(prime) prime = false;
      N /= i;
      cnt++;
    }
    if(cnt > 0){
      tmp = (long long int)(-1+sqrt(1+8*cnt))/2;
      ans += tmp;
    }
  }
  if(N > i) ans++;
  if(prime && X != 1) cout << 1 << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3680
N=int(input())
arr=[0 for i in range(N+1)]
for i,x in enumerate(input()):
    if x == 'W':
        arr[i+1]+=arr[i]+1
    else:
        arr[i+1]=arr[i]

min_=float('inf')
for l in range(N):
    tmp = arr[l]+N-arr[N]-l-1+arr[l+1]
    if tmp<min_:
        min_=tmp
print(min_)

Measured memory_bytes: 15196
#include <bits/stdc++.h>
#include <string.h>
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
	char s[12],t[12];
	cin>>s>>t;
	int x=strlen(t);
	
	t[x-1]='\0';
	//cout<<t;
	int y=strcmp(t,s);
	if(y==0){
		cout<<"Yes"<<endl;
	}
	else
		cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 3636
n,m,c= map(int,input().split())
b = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(n)]
ans = 0
for i in range(n):
         judge = 0
         for j in range(m):
                  judge += a[i][j] * b[j]
         if judge + c > 0:
                  ans += 1
print(ans)


Measured memory_bytes: 3060
//srinivas
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
// using namespace __gnu_pbds;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define fr(x,in,n,r) for(x=in;x<n;x+=r)
#define ifr(x,n) for(x=0;x<n;x++)
#define dfr(x,n) for(x=n;x>=1;x--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pof(a) pop_front(a)
#define pob(a) pop_back(a)
#define eb(a) emplace_back(a)
#define ef(a) emplace_front(a)
typedef long long ll;
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007
#define N 100001

ll dp[N+2];

ll fun(ll a[],ll n)
{
	if(n==0 || n==1)
		return dp[n];
	if(dp[n]!=-1)
		return dp[n];
	dp[n]=min(fun(a,n-1)+abs(a[n-1]-a[n]),fun(a,n-2)+abs(a[n-2]-a[n]));
	return dp[n];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt","r",stdin);
    ll n,i,j;
    cin>>n;
	ll a[n];
	ifr(i,N) dp[i]=-1;
	ifr(i,n)
		cin>>a[i];
	dp[0]=0;
	dp[1]=abs(a[0]-a[1]);
	fun(a,n-1);
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 4224
using System;
using System.Collections.Generic;
using System.Linq;
namespace CsProgramSpace
{
    class Program
    {
        static void Main(string[] args)
        {
            double r = double.Parse(Console.ReadLine());
            double pi = 3.14159265359;
            double s1 = (double)r * r * pi;
            double s2 = (double)2 * r * pi;
            Console.WriteLine(string.Format("{0:F6} {1:F6}", s1, s2));
        }
    }
}


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

int main() {
  int sum = 0;
  for (int i = 0; i < 3; i = i + 1) {
    int a;
    cin >> a;
    sum = sum + a;
  }
  if (sum >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
}
  

Measured memory_bytes: 256
integer sx,sy,tx,ty,dx,dy
character(10**5) ans
read*,sx,sy,tx,ty
dx=tx-sx;dy=ty-sy
ans=""
ans=trim(ans)//repeat("R",dx)//repeat("U",dy)
ans=trim(ans)//repeat("L",dx)//repeat("D",dy)
ans=trim(ans)//"D"//repeat("R",dx+1)//repeat("U",dy+1)//"L"
ans=trim(ans)//"U"//repeat("L",dx+1)//repeat("D",dy+1)//"R"
print"(A)",trim(ans)
end

Measured memory_bytes: 512
fun main(args: Array<String>) {
    val (a, b, c) = readLine()!!.split(" ").map(String::toInt)
    val k = readLine()!!.toInt()
    val max = Math.max(a, Math.max(b, c))
    val result = max * Math.pow(2.toDouble(), k.toDouble()).toInt() - max + a + b + c
    println(result)
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, q;
	cin >> n >> q;

	string s; cin >> s;
	vector<pair<char,char>> queries(q);
	for (auto &p: queries) cin >> p.xx >> p.yy;
	
	auto simulate = [&](ll i) {
		for (auto p: queries) {
			if (s[i] == p.xx) {
				if (p.yy == 'L') i--; else i++;
			}
			if (i < 0 || i >= n) return i;
		}
		return i;
	};
	
	//FOR(i,0,n) TR(simulate(i));

	ll Lmin = -1, Lmax = n;
	while (Lmax-Lmin > 1) {
		ll L = (Lmin+Lmax)/2;
		if (simulate(L) == -1) Lmin = L; else Lmax = L;
	}
	
	ll Rmin = -1, Rmax = n;
	while (Rmax-Rmin > 1) {
		ll R = (Rmin+Rmax)/2;
		if (simulate(R) == n) Rmax = R; else Rmin = R;
	}
	
	ll res = n - Lmax - (n-Rmax);
	cout << res << endl;

}



Measured memory_bytes: 976
#include<stdio.h>
int main(void)
{
    long long int N,A,B;
    scanf("%lld %lld %lld",&N,&A,&B);
    if((N*A)>B)
        printf("%lld\n",B);
    else if((N*A)<B)
        printf("%d",(N*A));
    else if((N*A)==B)
        printf("%lld\n",B);
    return 0;
}


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

const int max_n = 123456*2;
int prime[max_n];
bool is_prime[max_n+1];

int sieve(int n)
{
	int p = 0;
	for(int i=0;i<=2*n;i++){
		is_prime[i] = true;
	}
	is_prime[0] = is_prime[1] = false;
	for(int i=2;i<=2*n;i++){
		if(is_prime[i]){
			if(n<i && i <= 2*n)
				prime[p++] = i;
			for(int j=2*i;j<=2*n;j+=i)
				is_prime[j] = false;
		}
	}
	return p;
}

int main()
{
	int n;
	while(cin >> n){
		if(!n)
			break;
		cout << sieve(n) << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define nl '\n'
#define dbg(a) cout<<#a<<"="<<a<<endl
#define fast ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define ll long long
#define vl vector<ll>
#define pll pair<ll, ll>
#define ii pair<ll,ll>
#define vi vector<ll>
#define MX 600000
#define MXX 1000000000
using namespace std;

void solve(){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    int i=0, j=n-1;
    int ct=0;
    while(i<j)
    {
        if(s[i]=='W' and s[j]=='R')
        {
            ct++;
            i++, j--;
        }
        else
        {
            if(s[i]=='R') i++;
            if(s[j]=='W') j--;
        }
        

    }
    cout<<ct<<endl;
}

int main()
{
    fast;
    solve();
    return 0;
}


Measured memory_bytes: 3740
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int k = 0;
		long ans = 0;

		Scanner sc = new Scanner(System.in);
		k = sc.nextInt();
		sc.close();

		for (int i = 1; i < k + 1; i++) {
			for (int j = 1; j < k + 1; j++) {
				for (int m = 1; m < k + 1; m++) {
					if (i == 1 || j == 1 || m == 1) {
						ans += 1;
					} else if (i == j && j == m) {
						ans += i;
					} else {
						ans += gcd(i, j, m);
					}
				}
			}
		}
		System.out.println(ans);
	}

	public static final int gcd(final int... param) {
		final int len = param.length;
		int g = gcd(param[0], param[1]);
		for (int i = 1; i < len - 1; i++) {
			g = gcd(g, param[i + 1]);
		}
		return g;
	}

	public static final int gcd(int a, int b) {
		// a > b にする（スワップ）
		if (a < b) {
			int tmp = a;
			a = b;
			b = tmp;
		}
		// ユークリッドの互除法
		int r = -1;
		while (r != 0) {
			r = a % b;
			a = b;
			b = r;
		}
		return a;
	}
}

Measured memory_bytes: 38496
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		long ans = 0;
		int ans2 = 0;

		Scanner sc = new Scanner(System.in);
		int  n = sc.nextInt();
//		long  k = sc.nextLong();
//		longd = sc.nextInt();
//
//		boolean f = false;
		int[] a = new int[n+1];
		for (int i = 1; i < n+1; i++) {
			a[i] = sc.nextInt();
		}
		int[] b = new int[n+1];
		int[] c = new int[n+1];
		for (int i = 1; i <n+1; i++) {
			b[i] = sc.nextInt();
		}
		for (int i = 1; i <n; i++) {
			c[i] = sc.nextInt();
		}

		int chash = 0;

		for(int i : a) {
			ans2 += b[i];
			if(chash+1 == i) {
				ans2 += c[chash];
			}
			chash = i;
		}


		System.out.println(ans2);

		sc.close();
	}
}

Measured memory_bytes: 22608
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);
 
#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;
 
int main(){ IO;
  string s;
  cin >> s;
 
  int a = -1;
  int b = -1;
  for (char c = 'a'; c <= 'z'; ++c) {
    int last = -1;
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == c){
        if (last != -1) {
          int cnt = i - last + 1;
          if (cnt <= 3) {
            a = last + 1;
            b = i + 1;
          }
        }
        last = i;
      }
    }
  }
  cout << a << " " << b << endl;
 
  return 0;
}

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

struct edge { int to, cap, rev; };

vector<edge> G[110];
int level[110];
int iter[110];
int INF = 1000000000;

void add_edge(int from, int to, int cap) {
	G[from].push_back({ to, cap, (int)G[to].size() });
	G[to].push_back({ from, 0, (int)G[from].size() - 1 });
}

void BFS(int S) {
	memset(level, -1, sizeof(level));
	queue<int> Q;
	level[S] = 0;
	Q.push(S);
	while (!Q.empty()) {
		int V = Q.front(); Q.pop();
		for (int i = 0; i < G[V].size(); i++) {
			edge& E = G[V][i];
			if (E.cap > 0 && level[E.to] < 0) {
				level[E.to] = level[V] + 1;
				Q.push(E.to);
			}
		}
	}
}

int DFS(int V, int T, int F) {
	if (V == T) return F;
	for (int &i = iter[V]; i < G[V].size(); i++) {
		edge& E = G[V][i];
		if (E.cap > 0 && level[V] < level[E.to]) {
			int D = DFS(E.to, T, min(F, E.cap));
			if (D > 0) {
				E.cap -= D;
				G[E.to][E.rev].cap += D;
				return D;
			}
		}
	}
	return 0;
}

int max_flow(int S, int T) {
	int flow = 0;
	for (;;) {
		BFS(S);
		if (level[T] < 0) return flow;
		memset(iter, 0, sizeof(iter));
		int F;
		while ((F = DFS(S, T, INF)) > 0) {
			flow += F;
		}
	}
}

int main() {
	int V, E;
	cin >> V >> E;
	for (int i = 0; i < E; i++) {
		int v, e, c;
		cin >> v >> e >> c;
		add_edge(v, e, c);
	}
	cout << max_flow(0, V - 1) << endl;
}


Measured memory_bytes: 3204
from sys import stdin
import sys

# A, B, C, D = [int(x) for x in stdin.readline().rstrip().split()]
N, K = [int(x) for x in stdin.readline().rstrip().split()]
ans = [0 for i in range(N)]
for i in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    for i in range(len(A)):
        ans[A[i]-1] += 1
cnt=0
for i in range(len(ans)):
    if ans[i] == 0:
        cnt += 1
print(cnt)


Measured memory_bytes: 67968
def gcd(a,b):
    if a > b:
        x = a
        y = b
    else:
        x = b
        y = a
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

def lcm(a,b,c):
    return int(a*b/c)

while 1:
    try:
        a,b = [int(x) for x in input().split()]
        res_gcd = gcd(a,b)
        res_lcm = lcm(a,b,res_gcd)
        print('{} {}'.format(res_gcd,res_lcm))
    except:
        break

Measured memory_bytes: 5604
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int X = scan.nextInt();
		int Y = scan.nextInt();
		scan.close();
		long ans = 0;
		int res = 0;
		if(A + B <= 2 * C) {
			ans = A * X + B * Y;
			System.out.println(ans);
			System.exit(0);
		}else {
			if(X - Y >= 0) {
				ans += 2 * C * Y;
				res = X - Y;
				if(A > 2 * C) {
					ans += 2 * C * res;
				}else {
					ans += A * res;
				}
			}else {
				ans += 2 * C * X;
				res = Y - X;
				if(B > 2 * C) {
					ans += 2 * C * res;
				}else {
					ans += B * res;
				}
			}
		}
		System.out.println(ans);

	}
}

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

ll calc(vector<ll> v, ll n, ll p)
{
  ll tmp = 0;
  for (ll i = 0; i < n; i++)
  {
    tmp += (v[i]-p) * (v[i]-p);
  }
  return tmp;  
}

int main()
{
  ll n;
  cin >> n;
  vector<ll> v(n);
  rep(n) cin >> v[i];

  ll tmp = calc(v,n,1);

  for (ll i = 2; i < 101; i++)
  {
    tmp = min(tmp,calc(v,n,i));
  }
  
  cout << tmp << endl;
  

  return 0;
}

Measured memory_bytes: 256
s = input()
ans = 'Yes'
for i,k in enumerate(s):
  num = i + 1
  if num % 2 == 0 and k not in set('LUD'):
    ans = 'No'
    break
  if num % 2 == 1 and k not in set('RUD'):
    ans = 'No'
    break
print(ans)

Measured memory_bytes: 9004
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N;
int p[200000];

signed main(){
    cin >> N;
    rep(i, N){
        cin >> p[i];
        p[i]--;
    }

    int cnt = 0;
    if(p[N-1] == N-1){
        swap(p[N-2], p[N-1]);
        cnt++;
    }
    rep(i, N-1){
        if(p[i] == i){
            swap(p[i], p[i+1]);
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


x, a, b = ints()
# https://atcoder.jp/contests/abc071/tasks/abc071_a
print('A' if abs(x - a) < abs(x - b) else 'B')


Measured memory_bytes: 68776