akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

struct node{
    int key;
    struct node *prev;
    struct node *next;
};
typedef struct node node_t;

node_t *head, *tail;

int getint(char str[], int c);
void insert(int x);
void delete(int x);
void deleteFirst();
void deleteLast();

int main( void ){
    int n,i,d;
    head = malloc(sizeof(node_t));
    head->key = -1; head->next = NULL; head->prev = NULL;
    tail = head;
    char com[40], num[20];

    fgets(num,20,stdin);
    n = atoi(num);

    for(i = 0; i < n; i++){
        fgets(com, 40, stdin);
        if(strncmp(com,"deleteFirst",11) == 0){
            deleteFirst();
        }
        else if(strncmp(com,"deleteLast",10) == 0){
            deleteLast();
        }
        else if(strncmp(com,"insert",6) == 0){
            d = getint(com, 6);    //文字を数字として取得
            insert(d);
        }
        else if(strncmp(com,"delete",6) == 0){
            d = getint(com, 6);
            delete(d);
        }
    }
    node_t *p;
    p = malloc(sizeof(node_t));
    for(p = head; p != tail; p = p->next){
        printf("%d", p->key);
        if(p != tail->prev){
            printf(" ");
        }
    }
    printf("\n");
    return 0;
}

int getint(char str[], int c){    //cは文字部分の長さ
    int count = 0, x = 0;
    int i, a = 0;
    for(i = c + 1; str[i] != '\n'; i++){    // 012345_6_789...
        count++;
    }
    for(i = c + count; i >= c + 1; i--){
        a++;
        x += (str[i] - '0') * pow(10, a - 1);
    }
    return x;
}

void insert(int x){
    node_t *p;
    p = malloc(sizeof(node_t));
    p->key = x;
    p->next = head;
    p->prev = NULL;
    p->next->prev = p;
    head = p;
}

void delete(int x){
    node_t *p;
    p = malloc(sizeof(node_t));
    for(p = head; p != tail; p = p->next){
        if(p->key == x){
            if(p == head){
                deleteFirst();
            }
            else if(p == tail){
                deleteLast();
            }
            else{
                p->prev->next = p->next;
                p->next->prev = p->prev;
            }
            break;
        }
    }
}

void deleteFirst(){
    head = head->next;
    free(head->prev);
    head->prev = NULL;
}

void deleteLast(){
    tail = tail->prev;
    free(tail->next);
    tail->next = NULL;
}



Measured memory_bytes: 33120
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue(優先度付きキュー)：最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n)  for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;
/*ビットxにi番目のフラグが立っているかどうか
if(x & (1 << i))
↑ a << b == a*pow(b,2)
/*{0, 1, ..., n-1} の部分集合の全探索
for (int bit = 0; bit < (1 << n); ++bit)
*/

int main(){
  ll n,k;  cin >> n >> k;
  ll ans = 0;
  rep1(i,n){
    int h;  cin >> h;
    if(k <= h){
      ans++;
    }
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

int main(){

	string S;

	cin >> S;

	long long count = 0;
	for(long long i = 0; i < S.size(); i++){
		if(S[i] == '0'){
			count++;
		}
	}
			
	if(count > S.size()-count){
		count = S.size() - count;
	}

	cout << 2 * count << endl;

	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
using namespace std;

struct point{
	long long x,y;
	int id;
}p[150000];

int par[150000];

int find(int a)
{
	if(a == par[a]) return a;
	return par[a] = find(par[a]);
}

priority_queue<pair<int,pair<int,int> > > pq;

bool cmp1(point a,point b)
{
	return a.x < b.x;
}

bool cmp2(point a,point b)
{
	return a.y < b.y;
}

int main()
{
	int n;
	cin>>n;
	for(int a=0;a<n;a++) par[a] = a;
	for(int b=0;b<n;b++) 
	{
		cin>>p[b].x>>p[b].y;
		p[b].id = b;
	}
	sort(p,p+n,cmp1);
	for(int a=0;a<n-1;a++)
	{
		int dx = p[a+1].x - p[a].x;
		pq.push(mp(-dx,mp(p[a].id,p[a+1].id)));
	}
	sort(p,p+n,cmp2);
	for(int a=0;a<n-1;a++)
	{
		int dy = p[a+1].y - p[a].y;
		pq.push(mp(-dy,mp(p[a+1].id,p[a].id)));
	}
	long long ans = 0;
	while(!pq.empty())
	{
		int v = -pq.top().ff;
		int x1 = pq.top().ss.ff;
		int x2 = pq.top().ss.ss;
		pq.pop();
		if(find(x1) != find(x2))
		{
			ans += v;
			par[find(x1)] = find(x2);
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 8692
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
using namespace std;

int main(void) {
    int n;
    cin >> n;
    bool c[52];
    for(int i=0; i<52; i++)c[i]=false;
    for (int i=0;i<n;i++){
        char a;
        int b;
        cin >> a >> b;
        c[b-1+((a=='H')?13:0)+((a=='C')?26:0)+((a=='D')?39:0)] = true;
    }
    for(int i=0; i<52; i++){
        char d[4] = {'S','H','C','D'};
        if (!c[i]) {
            cout << d[i/13] << " " << (i%13+1) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3072
#include<iostream>
#include<math.h>

using namespace std;

int main(){
	int a;
	
	cin >> a;
	
	int temp;
	int max = 1;
	
	for(int i=2;a >= i*i;i++){
		for(int j=2;;j++){
			if(pow(i,j) > a){
				temp = pow(i,j-1);
				break;
			}
		}
		if(temp>max){
			max = temp;
		}
	}
	cout << max << endl;
	return 0;
}

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

using namespace std;

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

    int n;

    cin >> n;

    vector<int> v(n);

    for(int i=0; i<n; i++){
        cin >> v[i];
    }

    int ans = 1000000000;

    for(int i=1; i<=100; i++){
        int tot = 0;
        for(int j=0; j<n; j++){
            tot += (v[j] - i)*(v[j] - i);
        }
        ans = min(ans, tot);
    }

    cout << ans << endl;

    return 0;
}


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

int main()
{
    long long int a,b,c,n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>> a >> b >> c;

        if((a*a)+(b*b)==(c*c) || (a*a)+(c*c)==(b*b) || (b*b)+(c*c)==(a*a))
        {
            cout<<"YES"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }

    }
    return 0;
}

Measured memory_bytes: 3004
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;
template<class T> T ika_max(set<T> &S, const T &x){
    typename set<T>::iterator it = S.lower_bound(x);
    if(it == S.end())it--;
    else if(*it > x)it--;
    return *it;
}
template<class T> T ijo_min(set<T> &S, const T &x){
    return *S.lower_bound(x);
}
int main(){

    ll N;
    cin >> N;
    vector<P>v;
    rep1(i, N){
        ll x;
        cin >> x;
        v.push_back(P(x, i));
    }
    sort(v.begin(), v.end());
    ll ans = 0;
    set<ll>S;
    S.insert(0);
    S.insert(N + 1);
    rep(i, N){
        ll idx = v[i].second;
        ll l = ika_max(S, idx);
        ll r = ijo_min(S, idx);
        ans += (i + 1) * (idx - l) * (r - idx);
        S.insert(idx);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    ll n,k;
    cin >> n >> k;
    cout << min(n%k,k-n%k) << endl;
    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
g=[[] for _ in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    g[a].append(b)
    g[b].append(a)
#print(g)
for i in range(1,n+1):
    print(len(g[i]))

Measured memory_bytes: 3060
#include <stdio.h>

typedef long long ll;

int INF = 1000100100;

int N, M, L;

int dist[305][305];
int dist2[305][305];


int min(int a, int b) {
	if (a < b) { return a; }
	else { return b; }
}

int main() {

	scanf("%d %d %d", &N, &M, &L);

	int i, j, k;

	for (i = 0; i < 305; i++) {
		for (j = 0; j < 305; j++) {
			if (i == j) { 
				dist[i][i] = 0; 
				dist2[i][i] = 0; 
			}
			else { 
				dist[i][j] = INF;
				dist2[i][j] = INF;
			}
		}
	}

	for (i = 0; i < M; i++) {
		int A, B, C;
		scanf("%d %d %d", &A, &B, &C);
		dist[A - 1][B - 1] = C;
		dist[B - 1][A - 1] = C;
	}

	for (k = 0; k < N; k++) {
		for (i = 0; i < N; i++) {
			for (j = 0; j < N; j++) {
				dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}

	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			if (dist[i][j] <= L) { dist2[i][j] = 1; }
		}
	}

	for (k = 0; k < N; k++) {
		for (i = 0; i < N; i++) {
			for (j = 0; j < N; j++) {
				dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]);
			}
		}
	}

	int Q;

	scanf("%d",&Q);

	for (i = 0; i < Q; i++) {
		int s, t;
		scanf("%d %d", &s, &t);
		if (dist2[s - 1][t - 1] == INF) { printf("-1\n"); }
		else { printf("%d\n", dist2[s - 1][t - 1] - 1); }
	}

	return 0;
}

Measured memory_bytes: 1152
n = gets.chomp.split.map(&:to_i).sort!
res = 0
res += (n[2] - n[0]) / 2
n[0] += 2 * ((n[2] - n[0]) / 2)
res += (n[2] - n[1]) / 2
n[1] += 2 * ((n[2] - n[1]) / 2)
n.sort!
if n[1] == n[2] && n[0] + 1 == n[1]
  res += 2
elsif n[0] == n[1] && n[1] + 1 == n[2]
  res += 1
end
puts res


Measured memory_bytes: 1788
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String s=sc.next();
		int c=0;
		for(int i=0;i<n-2;i++) {
			if(s.charAt(i)=='A'&&s.charAt(i+1)=='B'&&s.charAt(i+2)=='C')c++;
			
		}
		System.out.println(c);
	}
}

Measured memory_bytes: 22100
n=int(input())
cnt=[]
def prime(x):
    for i in range(2,x+1):
        while x%i==0:
            x/=i
            cnt.append(i)   
           
if n==1:
    print(1)
else:
    li=[]
    for j in range(2,n+1):
        prime(j)
    cnt.sort() 
    
    ans=[1]*len(set(cnt))
    x=-1
    for k in cnt:
      if k in li:
        ans[x]+=1
      else:
        li.append(k)
        x+=1
        ans[x]+=1
    y=1
    for l in ans:
      y*=l
        
    print(y%(10**9+7))        

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static long[] ReadLongArray()
    {
	return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
    }
}

class Program
{
    static long[] a;
    static long[] p;

    public static void Main()
    {
	a = new long[51];
	p = new long[51];

	a[0] = p[0] = 1;
	for (int i = 1; i <= 50; i++)
	{
	    a[i] = a[i-1] * 2 + 3;
	    p[i] = p[i-1] * 2 + 1;
	}

	var tmp = ReadLongArray();
	int n = (int)tmp[0];
	long x = tmp[1];
	WriteLine(f(n, x));
    }

    static long f(int lv, long x)
    {
	if (lv == 0) return 1;
	
	if (x == 1)
	    return 0;
	else if (x < a[lv-1] + 2)
	    return f(lv - 1, x - 1);
	else if (x == a[lv-1] + 2)
	    return p[lv-1] + 1;
	else if (x < a[lv])
	    return p[lv-1] + 1 + f(lv - 1, x - a[lv-1] - 2);
	else
	    return p[lv-1] * 2 + 1;
    }
}


Measured memory_bytes: 13396
H, W = map(int, input().split())
s=[]

for i in range(0, H):
    s.append(input())

ans="Yes"
for y in range(0, H):
    for x in range(0, W):
        if s[y][x]==".":
            continue

        c=0
        for dx in range(-1, 2, 2):
            xx = x + dx
            if 0<=xx and xx<W:
                if s[y][xx]=="#":
                    c+=1
                    
        for dy in range(-1, 2, 2):
            yy = y + dy
            if 0<=yy and yy<H:
                if s[yy][x]=="#":
                    c+=1

        if c==0:
            ans="No"
print(ans)    

Measured memory_bytes: 3064
#include<iostream>
#include<string>
 
int main(){
  std::string s;
  std::cin >> s;
  
  int n = s.size();
  
  std::string ans = "";
  for(int i = 0; i < n; i++){
    if(i == 5 || i == 13) ans += " ";
    else ans += s[i];
  }
  
  std::cout << ans << std::endl;
  return 0;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int i,n;
    cin>>n;
    int x[n],y[n];
    for(i=0;i<n;i++)cin>>x[i]; 
    for(i=0;i<n;i++)cin>>y[i];
    double manhattan=0,euclidean2=0,euclidean3=0,chebyshev=0;
    for(i=0;i<n;i++){
        manhattan+=abs(x[i]-y[i]);
        if(chebyshev<abs(x[i]-y[i]))chebyshev=abs(x[i]-y[i]);
    }
    for(i=0;i<n;i++)euclidean2+=pow(abs(x[i]-y[i]),2);
    for(i=0;i<n;i++)euclidean3+=pow(abs(x[i]-y[i]),3);
    printf("%.5f\n%.5f\n%.5f\n%.5f\n",manhattan,sqrt(euclidean2),cbrt(euclidean3),chebyshev);
    return 0;
}


Measured memory_bytes: 3396
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#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())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll N,A,B;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>A>>B;
    if(B<A) cout <<0<<"\n";
    else if(A==B) cout <<1<<"\n";
    else{
        if(N==1) cout <<0<<"\n";
        else cout <<(B-A)*(N-2)+1<<"\n";
    }
}

Measured memory_bytes: 256
#include <iostream>  
#include <cstdio>  
#include <fstream>  
#include <algorithm>  
#include <cmath>  
#include <deque>  
#include <vector>  
#include <queue>  
#include <string.h>  
#include <cstring>  
#include <map>  
#include <stack>  
#include <set> 
#include <iterator> 
#include <list>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
//#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define ll long long
typedef vector <ll> vi;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,m,i,j,k,ta,tb,l1=-1,l2,x,c=0,u=0,ans=0;
	string s;
	cin>>s;
	n=s.length();
	vi v;
	if(n<3){
	    cout<<0;
	    return 0;
	}
	for(i=0;i<n-1;i++){
	    if(s[i]=='A') v.pb(1);
	    else if(s[i]=='B' && s[i+1]=='C'){ v.pb(0); i++;}
	    else v.pb(2);
	}
	for(i=0;i<v.size();i++){//cout<<v[i]<<" ";
	    if(v[i]==1 && l1==-1) l1=i;
	    if(v[i]==1 && c==0) c=1;
	    if(v[i]==0 && c==1){ ans+=(i-l1); l1++;}
        if(v[i]==2){ l1=-1; c=0;}
	}
	cout<<ans;
	return 0;
}



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

//#define int long long
#define reps(i,st,n) for(int (i)=(st);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) reps(i,0,((n)+1))
#define repst(i,s,n) reps(i,s,((n)+1))
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (i==n-1?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ');}}

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int h, w, d, a[300][300], q, l, r;
ll imo[301][90001];
pii rev[100100];

signed main() {
	cin >> h >> w >> d;
	rep(i,h) rep(j,w) {
		cin >> a[i][j];
		rev[a[i][j]] = {i,j};
	}
	
	if (d>=300) {
		cin >> q;
		rep(i,q) {
			cin >> l >> r;
			ll ans = 0, x = rev[l].fi, y = rev[l].se;
			while (l<r) {
				int nx = rev[l+d].fi, ny = rev[l+d].se;
				ans += abs(nx-x) + abs(ny-y);
				x = nx, y = ny, l += d;
			}
			cout << ans << ln;
		}
	} else {
		// iからスタートしてdごとに進みjまで行くコスト
		rep(i,d) {
			for (int t = i+d; t <= h*w; t+=d) {
				if (t==d) continue;
				int x = rev[t].fi, y = rev[t].se, nx = rev[t-d].fi, ny = rev[t-d].se;
				imo[i][t] = abs(x-nx) + abs(y-ny);
			}
			repst(j,1,300*300) imo[i][j] += imo[i][j-1];
		}
		cin >> q;
		rep(i,q) {
			cin >> l >> r;
			int s = l%d;
			ll ans = imo[s][r] - imo[s][l];
			cout << ans << ln;
		}
	}
}

Measured memory_bytes: 181248
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
N = int(input())
B = [int(input()) for _ in range(N)]
ans = False
if A1[0] in B and A2[0] in B and A3[0] in B:
    ans = True
if A1[1] in B and A2[1] in B and A3[1] in B:
    ans = True
if A1[2] in B and A2[2] in B and A3[2] in B:
    ans = True
if A1[1] in B and A1[0] in B and A1[2] in B:
    ans = True
if A2[1] in B and A2[0] in B and A2[2] in B:
    ans = True
if A3[1] in B and A3[0] in B and A3[2] in B:
     ans = True
if A1[0] in B and A2[1] in B and A3[2] in B:
     ans = True
if A3[0] in B and A2[1] in B and A1[2] in B:
     ans = True
if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
int stringcount(string s, char c) {
        return count(s.cbegin(), s.cend(), c);
    }

int main(void) {
    
    
    string s;
    cin>>s;
    cout<<700+stringcount(s,'o')*100<<endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n,c[1001],cc[1001];
  int q,t,x,d;
  rep(i,1001) cc[i]=0;
  cin>>n;
  repi(i,1,n+1) cin>>c[i];
  cin>>q;
  rep(i,q){
    cin>>t>>x>>d;
    if(t==1){
      cc[x]+=d;
      if(cc[x]>c[x]){cout<<x<<endl;return 0;}
    }
    else{
      cc[x]-=d;
      if(cc[x]<0){cout<<x<<endl;return 0;}
    }
  }
  cout<<0<<endl;
    

  return 0;
}






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

using namespace std;
 
#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair
 
#define debug(_x)		cerr << #_x << '=' << (_x) << endl;
#define debug2(_x, _y)	cerr << #_x << '=' << (_x) << ' ' << #_y << '=' << (_y) << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << (_x) << ' '; cerr << endl;

#define HERE debug(__LINE__);

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX>>1;
const int NINF = LONG_LONG_MIN/2;

const int N = 3009;
int dp[N][N];

int32_t main() {
	FAST_IO;
	
	int n;
	cin >> n;
	
	int a[n];
	for (int& x: a) cin >> x;
	
	for (int l = n-1; l >= 0; l--) {
		for (int r = l; r < n; r++) {
			if (l == r) {
				dp[l][r] = a[l];
			} else {
				dp[l][r] = max(a[l] - dp[l+1][r], a[r] - dp[l][r-1]);
			}
		}
	}
	
	cout << dp[0][n-1] << endl;
}

// g++ -Wall -Wextra -Wshadow -fsanitize=undefined


Measured memory_bytes: 70016
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
const ll mod=998244353;

int main(){
    ll A, B, C, N;
    cin >> N;

    ll count = 0;
    for(ll a=1; a<=N; a++) {
        ll x = (N-1)/a;
        count += x;
    }
    cout << count << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)



ll gcd(ll a , ll b){
  if(b==0)return a;
  return gcd(b,a%b);
}
int main(){
  ll n,x;
  string s;
  cin >>s;
  ll res0=0,res1=0;
  rep(i,s.size()){
    if(s[i]=='0')res0++;
    if(s[i]=='1')res1++;
  }
  cout << min(res0,res1)*2 << endl;
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>

using namespace std;

int main()
{
    int n;
    if (scanf("%d", &n) < 1) return 0;

    map<char, int> pre;
    map<char, int> cur;
    map<char, int> tmp;
    for (int i = 0; i < n; i++)
    {
        char x[51];
        if (scanf("%s", x) < 1) return 0;

        if (i > 0) for (int j = 0; j < (signed)strlen(x); j++) cur[x[j]]++;
        else for (int j = 0; j < (signed)strlen(x); j++) pre[x[j]]++;

        if (i > 0)
        {
            for (pair<char, int> p : pre)
            {
                // key count
                if (cur.count(p.first) == 0) continue;

                tmp[p.first] = min(cur[p.first], p.second);
            }
            pre.clear();
            cur.clear();
            pre = tmp;
            tmp.clear();
        }
    }

    for (pair<char, int> p : pre)
    {
        for (int i = 0; i < p.second; i++) printf("%c", p.first);
    }

    printf("\n");
    return 0;
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> A(n), tmp(n);
  for (int i = 0; i < n; i++)
    cin >> A[i];

  for (int i = 0; i < n; i++)
    tmp[A[i] - 1] = i + 1;
  for (int i = 0; i < n; i++)
    cout << tmp[i] << endl;
}

Measured memory_bytes: 1536
N, K = map(int,input().split())
x = list(map(int,input().split()))
#l = 0#最後はl = N - K
#r = K - 1#最後はr = N - 1
ans = 10 ** 15

for i in range(N - K + 1):#K個の連続したろうそくの選び方で全探索
  l = i 
  r = l + K - 1
  sum1 = abs(x[l]) + abs(x[r] - x[l])
  sum2 = abs(x[r]) + abs(x[l] - x[r])#l地点とr地点のどちらに先に行くか
  ans = min(ans, sum1, sum2) 
  
print(ans)
  

      
      


Measured memory_bytes: 14252
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1100000000;
constexpr long long LLINF = 1100000000000000000LL;
constexpr long long MOD = 1000000007;

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


int main()
{
  string s;
  cin >> s;
  REP(i, 3) {
    if (s[i] == s[i + 1]) {
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

vector<ll> cal(ll n){
    vector<ll>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            res.pb(i);
            while(n%i==0)n/=i;
        }
    }
    if(n!=1)res.pb(n);
    sort(res.begin(),res.end());
    return res;
}


int main(){fastio
    ll n;cin>>n;
    if(n==1){
        cout<<1<<endl;return 0;
    }
    vector<ll>div=cal(n);
    //for(auto x:div){cout<<x<<" ";}
    ll m=div.size();
    ll ans=n;
    for(ll i=1;i<=(1<<m)-1;i++){
        ll cou=0;
        ll res=1;
        rep(j,0,m-1){
            if((i>>j)&1){
                cou++;
                res*=div[j];
            }
        }
        ll vd=n/res;
        if(cou%2==1)vd*=-1;
        //cout<<res<<" "<<vd<<endl;
        ans+=vd;
    }
    cout<<ans<<endl;
    
    return 0;
}





Measured memory_bytes: 3204
from collections import deque
n, k = map(int, input().split())
p = deque(map(int, input().split()))

adjacent = deque()
for i in range(k):
    adjacent.append(p.pop())

ans = sum(adjacent)
count = ans

while p:
    pp = p.pop()
    count -= adjacent.popleft()
    count += pp
    adjacent.append(pp)
    ans = max(ans, count)

print((ans + k) / 2)

Measured memory_bytes: 23912
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int R = sc.nextInt();
        int S = sc.nextInt();
        int P = sc.nextInt();
        char[] history = new char[N];
        // rock:     r
        // scissors: s
        // paper:    p

        char[] T = sc.next().toCharArray();
        char[] W = new char[T.length];
        int score = 0;
        // A greedy method.
        for (int i = 0; i < K; i++) {
            // build partial charactors.
            StringBuilder sb = new StringBuilder();
            for (int t = i; t < N; t += K) {
                sb.append(T[t]);
            }

            char[] s = sb.toString().toCharArray();
            boolean suc = false; // Same chars succeed.
            for (int j = 0; j < s.length; j++)  {
                char c = s[j];
                if (suc) {
                    suc = false;
                } else {
                    if (j > 0 && s[j] == s[j - 1]) {
                        suc = true;
                        continue;
                    }
                }

                if (c == 'r') score += P;
                if (c == 's') score += R;
                if (c == 'p') score += S;
            }
        }

        System.out.println(score);

    }
}


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

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef vector<LL> 		VL;
#define si(n) cin>>n
#define dout(n) cout<<n<<"\n"
#define DRT() int t; si(t); while(t--)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//# define M_PI           3.14159265358979323846264338327950288
// DSU
void IO(){
	#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
	#endif
	srand(chrono::steady_clock::now().time_since_epoch().count());
	off;
}

int main(){
	IO();
	LL n;
	cin>>n;
	LL a = (n + 999)/1000;
	LL r = a*1000 - n;
	cout<<r;
	return 0;
}

Measured memory_bytes: 3648
n, y = map(int, input().split())
for i in range(n+1):
  for g in range(n-i+1):
    s = n-i-g
    if 10000*i + 5000*g + 1000*s == y:
      print(i, g, s)
      exit()
print('-1 -1 -1')

Measured memory_bytes: 9036
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others

//Hang in there!
//LOVE Nyantako_GG

using namespace std;


int main() {
	string S;
	cin >> S;
	int ans = 1;
	for (int i = 1; i < S.size() / 2; i++) {
		if (S.substr(0, i) == S.substr(0 + i, i)) {
			ans = i * 2;
		}
	}
	if (ans == 1) {
		cout << 0 << endl;
	}
	else {
		cout << ans << endl;
	}
}


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

using namespace std;

bool isPrime(long long int num){
  if(num == 2){
    return true;
  }
  
  if(num < 2 || num%2 == 0){
    return false;
  }

  int i = 3;
  while(i <= sqrt(num)){
    if(num%i == 0){
      return false;
    }
    i += 2;
  }

  return true;
}

int main(){
  int n, cnt=0;
  cin >> n;

  for(int i = 0; i < n; i++){
    long long int num;
    cin >> num;
    if(isPrime(num)){
      cnt++;
    }
  }

  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 3092
s = int(input())

def f(n):
    if n % 2 == 0:
        return int(n / 2)
    else:
        return 3 * n + 1

a = [s]
i = 2
ai = s
while True:
    ai = f(ai)
    if ai in a:
        break
    a.append(ai)
    i += 1
print(i)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
//main
signed main(){
  int a,b,k;cin>>a>>b>>b>>b>>b>>k;
  if(b-a<=k)cout<<"Yay!"<<endl;
  else cout<<":("<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <memory.h>

using namespace std;
int main() {
    string s;
    cin >> s;
    int sc = 0;
    for (int i = 0; i < s.size(); i++) {

        int tmp = s[i] == 'p' ? -1 : 0;

        if (i % 2 == 1) {
            tmp += 1;
        }
        if (tmp > 0) {
            sc++;
        }
        if (tmp < 0) {
            sc--;
        }
    }
    cout << sc << endl;

    
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define N 100005
#define MXN 200005
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    char ans1[505][505],ans2[505][505];
    MEM(ans1),MEM(ans2);
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)
            ans2[i][j]='#',ans1[i][j]='.';
    }
    
    char c[505][505];
    for(int i = 0;i<n;i++)
        scanf("%s",c[i]);
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(c[i][j]=='#'){
                ans1[i][j]='#';
            }
        }
    }
    for(int i =1;i<n;i+=2){
        for(int j=1;j<m;j++){
            if(c[i][j]=='#');
            else{
                ans1[i][j]='#';
                ans2[i][j]='.';
            }
        }
        ans1[i+1][m-1]='#';
        ans2[i+1][m-1]='.';
    }
    for(int i = 0;i<n;i++)
        printf("%s\n",ans1[i]);
    printf("\n");
    for(int i = 0;i<n;i++)
        printf("%s\n",ans2[i]);
}


Measured memory_bytes: 1536
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int HP = sc.nextInt();
		int variousOfAttack = sc.nextInt();
		int sum_attack = 0;
		int[] attack = new int[variousOfAttack];
		for(int i=0; i < variousOfAttack; i++){
			attack[i] = sc.nextInt();
			sum_attack += attack[i];
		}
		if(sum_attack < HP){
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}
	}
}

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

using namespace std;
using ll = long long;

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

  int n;
  cin >> n;

  vector<int> v;
  function<void(int, int, bool, bool, bool)> f = [&](int d, int cur, bool three,
                                                     bool five, bool seven) {
    if (d >= 10)
      return;
    if (three && five && seven)
      v.push_back(cur);

    f(d + 1, cur * 10 + 3, true, five, seven);
    f(d + 1, cur * 10 + 5, three, true, seven);
    f(d + 1, cur * 10 + 7, three, five, true);
  };

  f(0, 0, false, false, false);

  int ans = 0;
  for (auto e : v) {
    if (e <= n)
      ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned long;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

    void Solve() {
        UL N, M; cin >> N >> M;
        vector<UL> A(N); rep(i, N) { cin >> A[i]; A[i]--; }
        vector<LL> FC(M + 2);
        vector<LL> FL(M + 2);
        rep(i, N - 1) {
            if (A[i] > A[i + 1]) {
                FC[0] += A[i + 1] + 2;
                FL[0] += -1;
                FC[A[i + 1] + 1] += M - (A[i] - A[i + 1]) - 1;
                FL[A[i + 1] + 1] += 1;
                FL[A[i] + 2] -= 1;
            }
            else {
                FC[0] += (A[i + 1] - A[i]);
                FL[A[i] + 2] += -1;
                FL[A[i + 1] + 1] += 1;
                FC[A[i + 1] + 1] += A[i + 1] - A[i] - 1;
            }
        }
        rep(i, M) FL[i + 1] += FL[i];
        rep(i, M) FC[i] += FL[i];
        rep(i, M) FC[i + 1] += FC[i];
        LL ans = (LL)1e15;
        rep(i, M) ans = min(ans, FC[i]);
        cout << ans << endl;
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    cout << fixed << setprecision(10);
    p->Solve();
    return 0;
}


Measured memory_bytes: 2560
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
const char dir[4] = { 'u','l','d','r' };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

const int MAXN = 1010;
int w[MAXN];
bool done[MAXN];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, mini = 100000;
	cin >> n;
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		mp[w[i]] = 0;
		mini = min(mini, w[i]);
	}
	{
		int k = 0;
		for (auto& p : mp) p.second = k++;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (done[i]) continue;
		int cnt = 0, now = i, mi = 100000, sum = 0;
		while (1) {
			if (done[now]) break;
			cnt++;
			done[now] = true;
			mi = min(mi, w[now]);
			sum += w[now];
			now = mp[w[now]];
		}
		int tmp = sum + (cnt - 2)*mi;
		tmp = min(tmp, sum + mi + mini*(cnt + 1));
		ans += tmp;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3268
<?php
$ans = "No\n";
fscanf(STDIN, '%d', $n);
for ($i=1; $i <= 9; $i++) { 
    $div = $n / $i;
    $mod = $n % $i;
    if ($mod === 0 && $div >= 1 && $div <= 9) {
        $ans = "Yes\n";
        break;
    }
}
echo $ans;

Measured memory_bytes: 4728
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll mod=1e9+7;

struct mint {

  ll x; 

  mint(ll x=0):x((x%mod+mod)%mod){} //コンストラクタを呼んで自動的にmodを取っている。

  mint operator-() const { return mint(-x);}

  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    //メンバ関数にはthisポインタがある。メンバ変数の値を返す。
    return *this;
  }

  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }

  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }

  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }

  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }

  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }

  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1); //a=x/2
    a *= a; //繰り返し二乗法
    if (t&1) a *= *this; //tが奇数のときはxを1回かける
    return a;
  }



  // for prime mod

  mint inv() const {
    return pow(mod-2);
  }

  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }

  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
    
};
mint choose(ll n,ll r){
  mint x=1, y=1;
  rep(i,r){
    x*=n-i;
    y*=i+1;
  }
  return x/y;
}

int main()
{
    ll n, k;
    cin >> n >> k;
    for(ll i=1;i<=k;i++){
        mint a=choose(n-k+1,i);
        mint b=choose(k-1,i-1);
        a*=b;
        cout << a.x << endl;
    }
    
    return 0;
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using  namespace std;
#define ll long long
int main()
{
    string s;
    cin>>s;
    int n=s.size();
    string ss=s;
    string sss=s;
     bool ok=false,ok1=false,ok2=false;
    int i=0;
    int j=n-1;
    while(i<j)
    {
        swap(sss[i],sss[j]);
        i++;
        j--;
    }
    if(sss==s)
        ok2=true;

    i=0;
    j=(n-1)/2-1;
   int k=j;


   while(i<j)
   {
       swap(ss[i],ss[j]);
       i++;
       j--;

   }
  // cout<<ss<<endl;
   if(s.substr(0,k+1)==ss.substr(0,k+1))
    {
        ok=true;
    }

    i=((n+3)/2)-1;
    k=i;
    j=n-1;
     //cout<<i<<" "<<j;
    while(i<j)
    {
    swap(ss[i],ss[j]);
         i++;
         j--;
    }
   // cout<<ss<<endl;
    // cout<<ss.substr(k,n-k);
    if(s.substr(k,n-k)==ss.substr(k,n-k));
  ok1=true;

    if(ok&&ok1&&ok2)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;



}


Measured memory_bytes: 256
#include<stdio.h>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <functional>
#include <stdio.h>
#include <array>
#include <algorithm>
#include <string>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <queue>
#include<iomanip>
#include<bitset>
#include<stack>
#include<set>
#include<limits>
#include <complex>
#include<cstdlib>
using namespace std;

bool isso(long long int a) {
	if (a == 1||a==0)return false;
	for (long long int i = 2; i*i <= a; ++i) {
		if ((a%i)) {
		}
		else {
			return false;
		}
	}
	return true;
}

int main() {
	while (1) {
		string st; cin >> st;
		if (st.size() == 1 && st[0] == '0')break;
		vector<int>ns;
		vector<bool>oks;
		ns.emplace_back(0);
		for (int i = 0; i < st.size(); ++i) {
			oks.push_back(st[i] != '0');
			if (!(i % 2)) {
				ns.push_back(st[i] - '0');
			}
			else {
				ns.push_back((11-(st[i] - '0'))%11);
			}
		}
		vector<vector<int>>ruiseki(0, vector<int>(11,0));
		vector<int>ruinums;
		vector<int>rs(11, 0);
		int now = 0;
		for (int i = 0; i < st.size(); ++i) {
			now += ns[i];
			now %= 11;
			ruinums.push_back(now);
			if (oks[i]) {
				rs[now]++;
			}
			ruiseki.push_back(rs);
		}
		now += ns[st.size()];
		now %= 11;
		ruinums.push_back(now);
		int ans = 0;
		for (int i = 2; i <= st.size(); ++i) {
			ans += ruiseki[i - 2][ruinums[i]];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 11568
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <stack>
#include <limits>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <numeric>
//#include <tuple>

constexpr long long mod = static_cast<long long>(1e9 + 7);

inline int string2num(const std::string str) {
    if(str == "Male") return 0;
    else if(str == "Female") return 1;
    else return -1;
}

int main() {
    int N;
    std::cin >> N;
    std::cout << 0 << std::endl;
    std::string str;
    std::cin >> str;
    std::vector<int> states(N, 2); //-1: vacant, 0: male, 1: female, 2: unknown
    states[0] = string2num(str);
    if(states[0] < 0) return 0;
    std::cout << N / 2 << std::endl;
    std::cin >> str;
    states[N / 2] = string2num(str);
    if(states[N / 2] < 0) return 0;

    int l, r;
    if(states[0] == states[N / 2]) {
        if((N / 2 - 1) % 2 == 0) {
            l = 0;
            r = N / 2;
        } else {
            l = N / 2;
            r = N;
        }
    } else {
        if((N / 2 - 1) % 2 == 0) {
            l = N / 2;
            r = N;
        } else {
            l = 0;
            r = N / 2;
        }
    }

    while(l + 1 < r) {
        int q = (l + r) / 2;
        std::cout << q << std::endl;
        std::string str;
        std::cin >> str;
        states[q] = string2num(str);
        if(states[q] < 0) return 0;
        if((q - l) % 2 == 1 && states[l] == states[q]) {
            r = q;
        } else if((q - l) % 2 == 0 && states[l] != states[q]) {
            r = q;
        } else if((r - q) % 2 == 1 && states[r % N] == states[q]) {
            l = q;
        } else if((r - q) % 2 == 0 && states[r % N] != states[q]) {
            l = q;
        } else {
            assert(false && "unknown state");
        }
    }

    return 0;
}


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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, r;
    cin >> n >> r;
    if(n < 10) {
        cout << r + 100 * (10 - n);
    } else {
        cout << r;
    }
    return 0;
}


Measured memory_bytes: 256