akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

typedef long long ll;

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

  int exps[1003] = {0};
  const ll mod = int(1e9) + 7;

  for (int i = 2; i <= n; i++) {
    int t = i, div = 2;
    while ( div*div <= n ) {
      if (t % div == 0) {
        exps[div]++;
        t /= div;
      } else {
        div++;
      }
    }
    if (t != 1) { exps[t]++; }
  }

  ll ans = 1;
  for (int i = 2; i <= n; i++) {
    ans *= (exps[i] + 1);
    ans %= mod;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
	
	void run() {
		
		int n = sc.nextInt();
		int u[] = new int[n];
		int v[] = new int[n];
		int w[] = new int[n];
		
		Map<Integer,List<Integer>> g = new HashMap<Integer,List<Integer>>();
		
		for(int i = 0; i < n-1;i++) {
			u[i] = sc.nextInt()-1;
			v[i] = sc.nextInt()-1;
			w[i] = sc.nextInt();
			
			g.computeIfAbsent(u[i], x -> new ArrayList<Integer>()).add(i);
			g.computeIfAbsent(v[i], x -> new ArrayList<Integer>()).add(i);
		}
		
		int current = 0;
		int color = 0;
		int[] res = new int[n];
		Arrays.fill(res, -1);
		res[0] = 0;
		coloring(g,res,current,color,u,v,w);
		
		for(int i =0 ;i < n;i++) {
			System.out.println(res[i]);
		}
	}
	
	
	void coloring(Map<Integer,List<Integer>> g,int[] res, int current,int color, int[]u,int v[],int[] w) {
		for(int nextv : g.get(current)) {
			int next = u[nextv]+v[nextv]-current;	
			if(res[next] != -1) {
				continue;
			}
			int nextColor= (color + w[nextv])%2;
			res[next] = nextColor;
			
			coloring(g,res,next,nextColor,u,v,w);
		}
	}
}

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

int main()
{
	int n,x,m[100];
	cin>>n>>x;
	for(int i=0;i<n;i++) cin>>m[i];
	
	int r=x,minv=*min_element(&m[0],&m[n]);
	for(int i=0;i<n;i++) r-=m[i];
	
	cout<<r/minv+n<<endl;
	
	return 0;
}


Measured memory_bytes: 256
using System;

namespace AizuOnline
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var x = Console.ReadLine().Split(' ');
            Console.WriteLine(Convert.ToInt32(x[0]) * Convert.ToInt32(x[1]) + " "
                + (2 * Convert.ToInt32(x[0]) + 2 * Convert.ToInt32(x[1])));
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9156
function Main(input){
  
  var str = input.trim().split(" ");
  var a = str[0];
  var b = str[1];
  
  var kekka = 0;
  
  if(a-b>0){
    kekka = a*2 -1;
    
  }else if(b-a>0){
     kekka = b*2 -1;
  }else if(a-b==0){
    kekka = a*2;
  }
 
   
   console.log(kekka);
}//function end
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main()
{
    #ifdef LOCAL_EXEC
    #else
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #endif // LOCAL_EXEC
    string s,t,result;
    cin>>s>>t;
    long long int i,j;
    long long int dp[s.size()+1][t.size()+1];
    for(i=0;i<=t.size();i++){
        dp[0][i]=0;
    }
    for(i=0;i<=s.size();i++){
        dp[i][0]=0;
    }
    for(i=1;i<=s.size();i++){
        for(j=1;j<=t.size();j++){
            if(s[i-1]==t[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
                else
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);

        }
    }
    /*for(i=0;i<=s.size();i++){
        for(j=0;j<=t.size();j++){
        cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
    i=s.size();
    j=t.size();
    while(i>0&&j>0){
        if(s[i-1]==t[j-1]){
            result.push_back(s[i-1]);
            i-=1;
            j-=1;
        }
        else if(dp[i-1][j]>dp[i][j-1])
            i-=1;
        else
            j-=1;
    }
    reverse(result.begin(),result.end());
    cout<<result;
    return 0;
}


Measured memory_bytes: 70656
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
using namespace std;
#define int ll

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int dp[k+1][n+1];
	for(int i=0;i<=k;i++)
		for(int j=0;j<=n;j++)
			dp[i][j]=0;
	
	for(int i=0;i<=k;i++)
		dp[i][0]=0;
	for(int i=0;i<=min(k,a[0]);i++)
		dp[i][1]=1;
	for(int i=2;i<=n;i++)
	{
		dp[0][i]=1;
		int su=1;
		for(int j=1;j<=k;j++)
		{
			su=(su+dp[j][i-1])%mod;
			if(j>a[i-1])
				su=((su-dp[j-a[i-1]-1][i-1])%mod+mod)%mod;
			dp[j][i]=su;
			if(su==1)
				break;
			//cout<<dp[j][i]<<' ';
		}
		//cout<<endl;
	}
	//for(int i=0;i<=n;i++)
	//{
	//	for(int j=0;j<=k;j++)
	//		cout<<dp[j][i]<<' ';
	//	cout<<endl;
	//}
	cout<<(dp[k][n]%mod+mod)%mod<<endl;
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
void chmax(ll &a, ll b){
  if( a < b){ swap(a,b);} return ;}
void chmin(ll &a, ll b){
  if( a > b){ swap(a,b);} return ;}
//けんちょん解説AC 
int main(){
ll N,Z,W; cin >> N >>Z>>W; vector<ll> A(N);
  for(ll i = 0; i < N; i++){ cin >> A[i];}
  
  vector<vector<ll>> dp(N+1, vector<ll> (2));
   ll Y;
  for(ll i = N-1; i >= 0; i--){
    dp[i][0] = -INF;
    if(!i){ Y = W;} else{ Y = A[i-1];}
    chmax(dp[i][0], abs(Y-A[N-1])); //XがA[i+1] ~~ A[N-1]まで全部取ってしまった時
    for(ll j = i+1; j < N; j++){ chmax( dp[i][0], dp[j][1]);}
    
    dp[i][1] = INF;
    ll X;
    if(!i){ X = Z;} else{ X = A[i-1];}
    chmin(dp[i][1], abs(X-A[N-1]));
    
    for(ll j = i+1; j < N; j++){ chmin( dp[i][1], dp[j][0]);}
  }
  
  cout << dp[0][0] << endl; return 0;}
     

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

signed main(){
  int n;
  cin>>n;
  vector<int> a(n),b(n);
  rep(i,n)cin>>a[i]>>b[i];
  int ans=0;
  for(int i=n-1;i>=0;i--){
    if(a[i]%b[i]==0){
      if(i>0)a[i-1]+=ans;
    }else{
      int dif=0;
      if(a[i]>b[i])dif=(a[i]/b[i]+1)*b[i]-a[i];
      else dif=b[i]-a[i];
      ans+=dif;
      if(i>0)a[i-1]+=ans;
    }
  }

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


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  int N;
  cin >> N;
  ll A,B;
  cin >> A >> B;
  vector<ll> X(N);

  for(int i = 0;i < N;i++)cin >> X[i];

  ll ans = 0;
  for(int i = 1;i < N;i++){
    if((X[i] - X[i-1]) * A < B)ans += (X[i] - X[i-1]) * A;
    else ans += B;
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

int main()
{
    int n, x, y;
    cin >> n >> x >> y;
    x--;
    y--;
    vector<int> ans(n, 0);
    vector<vector<int>> dis(n, vector<int>(n, n + 100));
    vector<vector<int>> g(n);
    for (int i = 0; i < n - 1; i++) {
        g[i].push_back(i + 1);
        g[i + 1].push_back(i);
    }
    g[x].push_back(y);
    g[y].push_back(x);

    for (int s = 0; s < n; s++) {
        vector<int> d(n, -1);
        queue<int> q;
        d[s] = 0;
        q.push(s);
        while (!q.empty()) {
            int v = q.front();  // キューから先頭頂点を取り出す
            q.pop();

            // v から辿れる頂点をすべて調べる
            for (int nv : g[v]) {
                if (d[nv] != -1) continue;  // すでに発見済みの頂点は探索しない

                // 新たな白色頂点 nv について距離情報を更新してキューに追加する
                d[nv] = d[v] + 1;
                q.push(nv);
            }
        }
        for (int i = 0; i < n; i++) {
            int dd = min(d[i], dis[s][i]);
            dis[s][i] = dis[i][s] = dd;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) { ans[dis[i][j]]++; }
    }
    for (int i = 1; i < n; i++) { cout << ans[i] << endl; }
}


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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

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

  if (n % 2 == 1) {
    ANS(0);
  } else {
    ll num_of_five = 0;
    ll i = 5;
    while (i < n) {
      num_of_five += n / i / 2;
      i *= 5;
    }
    ANS(num_of_five);
  }
  return 0;
}


Measured memory_bytes: 256
#include<time.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

template<typename ...Ts>
void show(Ts... ts){
  cout<<"#:";
  auto print=[](auto v){cout<<v<<" ";};
  initializer_list<int>{(void(print(ts)),0)...};
  cout<<endl;
}

int main(void){
    int n,m;
    cin>>n>>m;
    vi sx(n,0);
    vi sy(n,0);
    vi cx(m,0);
    vi cy(m,0);
    
    rep(i,n){
        cin>>sx[i]>>sy[i];
    }
    
    rep(i,m){
        cin>>cx[i]>>cy[i];
    }
    int alt;
    vi ans(n,0);
    vi tmp(n);
    rep(i,n){
        tmp[i]=1e9;
        rep(j,m){
            alt=abs(sx[i]-cx[j])+abs(sy[i]-cy[j]);
            if (alt<tmp[i]){
                tmp[i]=alt;
                ans[i]=j+1;
            }
        }
    }
    rep(i,n)cout<<ans[i]<<endl;
}







Measured memory_bytes: 256
S = list(input())

seikai=["A", "C", "G", "T"]
ansList=[]
for i in range(len(S)):
  if S[i] in seikai:
    ansList.append(1)
  else:
    ansList.append(0)

maxans=0
ans=0
for i in range(len(ansList)):
  if ansList[i] ==1:
    ans+=1
    if maxans<ans:
      maxans=ans
  else:
    ans=0
print(maxans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Text;

namespace Kyoupro
{
    class Plactice
    {
        static void Main()
        {
            string[] arr = Console.ReadLine().Split(' ');
            int a = int.Parse(arr[0]);
            int b = int.Parse(arr[1]);
            int c = int.Parse(arr[2]);

            if(a+b+c >= 22)
            {
                Console.WriteLine("bust");
            }
            else
            {
                Console.WriteLine("win");
            }

        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define S second
#define vi vector
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define mod 1000000007
#define pb push_back
#define ll long long 
#define db double
#define all(v) v.begin(),v.end()

using namespace std;

/*

ll expo(ll n){
    ll t;
    if(n==0)return 1;
    else if(n==1) return 2;
    t=expo(n/2);
    if(n%2){
        return t*t*2;
    }
    else return t*t;
}

//ffrom geek for geek
ll exponentMod(ll A, ll B, ll C)  
{  
    if (A == 0)  
        return 0;  
    if (B == 0)  
        return 1;  
    ll y;  
    if (B % 2 == 0) {  
        y = exponentMod(A, B / 2, C);  
        y = (y * y) % C;  
    }  
    else {  
        y = A % C;  
        y = (y * exponentMod(A, B - 1, C) % C) % C;  
    }  
  
    return (ll)((y + C) % C);  
}

*/
/*
class dsu{
public:    
vi<ll> v;


void init(ll n){
    v.assign(n+1,-1);
}

 
ll dsufind(ll x){
    if(v[x]<0){
        return x;
    }
    v[x]=dsufind(v[x]);
    return v[x];
}
 
void dsujoin(ll x,ll y){
    x=dsufind(x);
    y=dsufind(y);
    
    if(x==y)
    return;
    if(v[x]>v[y])swap(x,y);
    v[y]+=v[x];
    v[x]=y;
}

};
*/



int main(){
    IOS;
    ll t;
    t=1;
    //cin>>t;
    while(t--){
       ll h,w;
       cin>>h>>w;
       char s[h+1][w+1];
       ll dp[h+1][w+1];
     
       FORE(i,1,h){
           FORE(j,1,w){
               dp[i][j]=0;
               cin>>s[i][j];
           }
       }
        dp[h][w]=1;

       for(int i=h;i>=1;i--){
           for(int j=w;j>=1;j--){
               if(s[i-1][j]!='#')
               dp[i-1][j]+=dp[i][j],dp[i-1][j]%=mod;
               if(s[i][j-1]!='#')
               dp[i][j-1]+=dp[i][j],dp[i][j-1]%=mod;
           }
       }

       cout<<dp[1][1]%mod;

    }
    return 0;
} 

Measured memory_bytes: 12364
program kadai
implicit none
character(len=4) ::  s

read(*,*) s

if (s(1:1)==s(2:2) .or. s(2:2)==s(3:3) .or. s(3:3)==s(4:4)) then
    write(*,*) "Bad"
    stop
end if
write(*,*) "Good"

end program kadai


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;


public static class P
{
    static void Main()
    {
        var count = new[] { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
        var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        BigInteger[] dp = new BigInteger[nm[0] + 10];
        for (int i = 0; i <= nm[0]; i++)
        {
            if (i != 0 && dp[i] == 0) continue;
            foreach (var c in a)
            {
                dp[i + count[c]] = BigInteger.Max(dp[i + count[c]], dp[i] * 10 + c);
            }
        }
        Console.WriteLine(dp[nm[0]]);
    }
}


Measured memory_bytes: 27980
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
count = 0
B = []
if N == X:
  print(0)
else:
  for x in range(X,N+1):
    if x in A:
      count += 1
  B.append(count)
  count = 0
  for x in range(X,0,-1):
    if x in A:
      count += 1
  B.append(count)
  print(min(B))

Measured memory_bytes: 3188
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>

using namespace std;

int main()
{
    int a, b;
    if (scanf("%d%d", &a, &b) < 2) return 0;

    printf("%s\n", a * b % 2 == 0 ? "Even" : "Odd");

    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

#define FOUND 1
#define NOT_FOUND 0

int linearsearch(int *,int ,int );

int main(){
  int i,n,s[10000],q,t[500],c=0;

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&s[i]);
  }
  scanf("%d",&q);
  for(i = 0;i < q;i++){
    scanf("%d",&t[i]);
    c = c + linearsearch(s,n,t[i]);
  }

  printf("%d\n",c);

  return 0;
}
int linearsearch(int *p,int n,int key){
  int i=0,*a;
  a = p;
  a[n] = key;

  while(a[i] != key){
    i++;
    if(i == n){
      return NOT_FOUND;
    }
  }
  return FOUND;
}

Measured memory_bytes: 636
import Data.Array (Array, listArray, (!))

dp f s e = result ! e where
  result = listArray (s,e) $ map nth [s..]
  nth i = f result i

minjumpcost n hs = dp f 1 n where
  f _ 1 = 0
  f _ 2 = abs $ (hs!1) - (hs!2)
  f t i =
    let jump1 = (t!(i-1)) + abs ((hs!i) - (hs!(i-1)))
        jump2 = (t!(i-2)) + abs ((hs!i) - (hs!(i-2)))
    in
      min jump1 jump2

main = do
  n <- read . head . words <$> getLine :: IO Int
  hs <- listArray (1,n) . map read . words <$> getLine :: IO (Array Int Int)
  print $ minjumpcost n hs


Measured memory_bytes: 49532
#include<bits/stdc++.h>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
#include<chrono>
using namespace std;
using namespace std::chrono;
//using namespace __gnu_pbds;
#define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi         first
#define se         second
#define int         long long
#define pb         push_back
#define emp        emplace_back
#define vv(x)      vector<x>
#define mp(x,y)    map<x,y>
#define dq(x)      deque<x>
#define pql(x)     priority_queue<x>
#define pqs(x)     priority_queue<x,vv(x),greater<x> >
#define mod         1000000007
#define forf(i,a,b) for(int i=a;i<b;i++)
#define it(x)      x::iterator
#define ll         long long
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
#define vii        vector<int>
#define big        3e18
#define sm         -2e9
#define mkr        make_pair
#define vpi        vector<pair<int,int> >
#define pii        pair<int,int>
#define rng        500005
#define sz(x)      (int)x.size()
#define rv(x)      reverse(x.begin(),x.end())
#define out(x)     cout<<x.fi<<" "<<x.se<<endl;
 
//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
 
void pr_init()
{
 
#ifndef ONLINE_JUDGE
  freopen("gin.txt", "r", stdin);
  //freopen("gout.txt", "w", stdout);
#endif
}

void solve()
{
  
 //  int n,k;
 //  cin >> n >> k;
  
 //  map<int,int>mp;

 //  forf(i,1,n+1) cin >> a[i];
  
 //  int cn = 0 , s=0;
 // // mp[-1]=1;
 //  forf(i,1,n+1)
 //  {
 //    if((a[i])%k==1) cn++;
 //    int v == s+a[i]
 //    cn += mp[(s+a[i]-i-1+k)%k];
 //    cout<<cn<<"\n";
 //    mp[(s-i+k)%k]++;
 //    s+=a[i];
 //  }
 //  cout<<cn;
 
 int n,m;
 cin >> n >> m;
 string s;
 cin >> s;
 vector<int>sq;
 for(int i=0;i<sz(s);i++)
 {
   if(s[i]=='0')sq.pb(i);
 }
 if(s[0]=='1'||s[n]=='1')
 {
  cout<<"-1\n";
  return ;
 }

 int c = n,is=1;
 vii mv;

 while(c!=0)
 {
   mv.pb(c);
   auto it = lower_bound(sq.begin(),sq.end(),c-m);
  
   if(*it==c)
   {
    //cout<<"helln";
     is=0;
     break;
   }
   c = *it;
 }
 if(!is)
 {
  cout<<"-1";
  return ;
 }
 mv.pb(0);
 rv(mv);

 vii an;

 for(int i=1;i<sz(mv);i++)
 {
   an.pb(mv[i]-mv[i-1]);
 }
 // for(auto x:mv) cout<<x<<" ";
 //  cout<<"\n";
 for(auto x:an)
 {
  cout<<x<<" ";
 }
}
 
 
int32_t main()
{
  pr_init();
  fastio;
   
  
  solve();
   
}
 


Measured memory_bytes: 6432
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();

            SelectionSort(A, N);
        }

        static void SelectionSort(int[] A, int N)
        {
            var count = 0;

            for (var i = 0; i < N; i++)
            {
                var minj = i;
                for (var j = i; j < N; j++)
                {
                    if (A[j] < A[minj])
                        minj = j;
                }

                if (i != minj)
                {
                    var tmp = A[i];
                    A[i] = A[minj];
                    A[minj] = tmp;
                    count++;
                }
            }

            Console.WriteLine(string.Join(" ", A));
            Console.WriteLine(count);
        }
    }
}



Measured memory_bytes: 18316
#include<stdio.h>

int main(void)
{

    int i, a[4], b[4], c[4];

    for(i = 0; i < 4; i++) {
        scanf("%d %d", &a[i], &b[i]);
        switch(a[i]) {
            case 1 : c[i] = 6000 * b[i]; break;
            case 2 : c[i] = 4000 * b[i]; break;
            case 3 : c[i] = 3000 * b[i]; break;
            case 4 : c[i] = 2000 * b[i]; break;
        }

    }

    for(i = 0; i < 4; i++)
        printf("%d\n", c[i]);

    return 0;
}

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

int main() {
    int x,y;cin>>x>>y;
    int ans = 0;
    if(x==1)ans+=300000;
    else if(x==2)ans+=200000;
    else if(x==3)ans+=100000;
    if(y==1)ans+=300000;
    else if(y==2)ans+=200000;
    else if(y==3)ans+=100000;
    if(x==1&&y==1)ans+=400000;
    cout<<ans<<endl;
}

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

int x;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> x;
	x = x / 5 * 5;
	x += x / 500 * 500;
	cout << x << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int height, width;
long long int dp[1010][1010];
string a[1001];
int main()
{
    ios::sync_with_stdio(false);
    cin >> height >> width;
    for (int i = 0; i < height; i++)
        cin >> a[i];
    dp[0][0] = 1;
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            if (a[i][j] == '#')
                continue;
            if (a[i][j + 1] == '.')
            {
                dp[i][j + 1] += dp[i][j];
                dp[i][j + 1] %= 1000000007;
            }
            if (a[i + 1][j] == '.')
            {
                dp[i + 1][j] += dp[i][j];
                dp[i + 1][j] %= 1000000007;
            }
        }
    }
    cout << dp[height - 1][width - 1] % (1000000007) << endl;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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);
  int N; cin >> N;
  int ans = 0;
  rep(i, N) {
    int tmp; cin >> tmp;
    if(i%2==0 && tmp%2==1) ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3644
n,q=map(int,input().split())
s=input()
a=[0]
for i in range(1,len(s)):
  a.append(a[i-1]+s[i-1:i+1].count('AC'))
for i in range(q):
  l,r=map(int,input().split())
  print(a[r-1]-a[l-1])

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

const int MOD = 1000000007;

// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

//最小公倍数
int lcm(int number1,int number2){
	return number1 * number2 / gcd(number1,number2);	
}
  
int main(){
    int A, B, C;
    cin >> A >> B >> C;

    int m = max(A, max(B, C));
    int mi = min(A, min(B, C));
    int ans = abs(m - mi);
    cout << ans << endl; 
}

Measured memory_bytes: 256
A = list(map(int,input().split()))
A = sorted(A)
ans = int((A[2]-A[0])/2) + int((A[2]-A[1])/2)
if A[0]%2 == A[1]%2 == A[2]%2:
  print(ans)
elif A[0]%2 == A[1]%2 and A[0]%2 != A[2]%2:
  print(ans +1)
else:
  print(ans + 2)

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
using namespace std;

//ABC126 B
int main() {
	string s;
	cin >> s;

	string first = s.substr(0, 2);
	string second = s.substr(2, 2);
	int first_num = stoi(first);
	int second_num = stoi(second);

	if ((first_num >= 1 and first_num <= 12) && (second_num >= 1 and second_num <= 12)) {
		cout << "AMBIGUOUS" << endl;
		return 0;
	}
	else if ((first_num < 1 or first_num > 12) && (second_num < 1 or second_num > 12)) {
		cout << "NA" << endl;
		return 0;
	}
	else if (first_num >= 1 and first_num <= 12) {
		cout << "MMYY" << endl;
		return 0;
	}
	else {
		cout << "YYMM" << endl;
		return 0;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.HashMap;

public class Main{
	public static void main(String[] args){
		HashMap<Integer,Integer> hashDictionary = new HashMap<Integer,Integer>();
		
		Scanner sc = new Scanner(System.in);								//標準入力
		int numOfInput = sc.nextInt();												//データ数
		
		for (int i = 0; i < numOfInput; i++){
			String order = sc.next();
			
			//入力された文字のハッシュ値を求める
			int newHash = hash(sc.next());
			
			//新しい辞書の追加
			if (order.equals("insert") == true){				
				//ハッシュ値を追加
				hashDictionary.put(newHash, 1);
				
			}else{
				if (hashDictionary.containsKey(newHash) == true){
					System.out.println("yes");
				}else{
					System.out.println("no");
				}
			}
		}
	}
	
	private static int hash(String word){
		int result = 0;
		
		for (int i = 0; i < word.length(); i++){
			char c = word.charAt(i);
			
			if (c == 'A'){
				result += 1 * Math.pow(5,i);
			}else if (c == 'C'){
				result += 2 * Math.pow(5,i);
			}else if (c == 'T'){
				result += 3 * Math.pow(5,i);
			}else{
				result += 4 * Math.pow(5,i);
			}
		}
		
		return result;
	}
}


Measured memory_bytes: 203524
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int a,b,c;
   cin>>a>>b>>c;
   if(c<=a+b && a<=c)
    cout<<"YES"<<endl;
   else
    cout<<"NO"<<endl;

    return 0;
}


Measured memory_bytes: 3632
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
s = S()
n = len(s)
ans = 0
for i in range(1, n+1):
    temp_s = s[0:n-i]
    temp_n = len(temp_s)
    if temp_s[0:temp_n//2] == temp_s[temp_n//2:]:
        ans = temp_n
        break
print(ans)

Measured memory_bytes: 74584
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll a, b, c, d; cin >> a >> b >> c >> d;
    vector<ll>v(4);
    v[0] = a*c;
    v[1] = a*d;
    v[2] = b*c;
    v[3] = b*d;

    ll mx = *max_element(v.begin(), v.end());

    cout << mx << endl;

    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

string S; cin >> S;

int64_t cnt = 0, cntB = 0;
rep(i, 0, S.size()){
    if (S[i] == 'B') ++cntB;
    else cnt += cntB;
}

cout << cnt << endl;

}

// 書いて考える
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



Measured memory_bytes: 720
#include <iostream>

using namespace std;

typedef long long lint;

int main(void)
{
    lint A, B, C, K;
    cin >> A >> B >> C >> K;

    lint sub = 0;
    if(K % 2 == 0){
        sub = A - B;
    }
    else{
        sub = B - A;
    }
    if(abs(sub) >= 1e18){
        cout << "Unfair" << endl;
    }else{
        cout << sub << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    static <T extends Comparable<? super T>> boolean nextPermutation(T[] sequence) {
        int first = getFirst(sequence);
        if (first == -1) return false;
        int toSwap = sequence.length - 1;
        while (sequence[first].compareTo(sequence[toSwap]) >= 0) --toSwap;
        swap(sequence, first++, toSwap);
        toSwap = sequence.length - 1;
        while (first < toSwap) swap(sequence, first++, toSwap--);
        return true;
    }

    static <T extends Comparable<? super T>> int getFirst(T[] sequence) {
        for (int i = sequence.length - 2; i >= 0; --i)
            if (sequence[i].compareTo(sequence[i + 1]) < 0) return i;
        return -1;
    }

    static <T extends Comparable<? super T>> void swap(T[] sequence, int i, int j) {
        T tmp = sequence[i];
        sequence[i] = sequence[j];
        sequence[j] = tmp;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer[] p = new Integer[n];
        Integer[] q = new Integer[n];
        for (int i = 0; i < n; ++i) p[i]= sc.nextInt() - 1;
        for (int i = 0; i < n; ++i) q[i]= sc.nextInt() - 1;

        Integer[] arr = new Integer[n];
        for (int i = 0; i < n; ++i) arr[i] = i;
        int cnt = 1, pNum = 0, qNum = 0;
        do {
            if (Arrays.equals(arr, p)) pNum = cnt;
            if (Arrays.equals(arr, q)) qNum = cnt;
            ++cnt;
        } while(nextPermutation(arr));

        System.out.println(Math.abs(pNum - qNum));
    }
}

Measured memory_bytes: 23636
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

lli visited[1002][1002] = {};

int main(void) {

	lli H, W;
	cin >> H >> W;

	std::queue<tlll> q;

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			char c;
			cin >> c;
			if (c == '#') {
				q.push(tlll{ i + 1,j + 1,1 });
			}
		}
	}

	for (int i = 1; i <= H; i++) {
		visited[i][W + 1] = 1;
		visited[i][0] = 1;
	}
	for (int i = 1; i <= W; i++) {
		visited[0][i] = 1;
		visited[H + 1][i] = 1;
	}

	lli ans = 0;
	lli dir[] = { 1,0,-1,0,1 };

	while (!q.empty()) {

		tlll t = q.front();
		q.pop();

		if (visited[get<0>(t)][get<1>(t)] == 0) {
			visited[get<0>(t)][get<1>(t)] = get<2>(t);
			ans = get<2>(t);
			for (int i = 0; i < 4; i++)
				q.push(tlll{ get<0>(t) + dir[i] ,get<1>(t) + dir[i + 1] ,get<2>(t) + 1 });
		}

	}

	COUT(ans - 1);

	return 0;
}

Measured memory_bytes: 105400
#include<iostream>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<tuple>
#include<iomanip>
#include<list>
#include<climits>
#define endl '\n'
#define ll long long
#define ld long double
#define mod 1000000007
#define mod1 998244353
#define PI acos(-1)
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	ll n;
	cin>>n;
	ll sum=0;
	string str;
	cin>>str;
	ll arr[n][3]={0};
	
	arr[0][0]=0;
	arr[0][1]=0;
	arr[0][2]=0;

    int i=0;
	if(str[i]=='R')
	{
		arr[0][0]++;
	}
	else if(str[i]=='G')
	{
		arr[0][1]++;
	}
	else
	{
		arr[0][2]++;
	}
	for(int i=1;i<n;i++)
	{
		arr[i][0]=arr[i-1][0];
         arr[i][1]=arr[i-1][1];
		 arr[i][2]=arr[i-1][2];
		if(str[i]=='R')
		{
			
			arr[i][0]++;
		}
		else if(str[i]=='G')
		{
			
			arr[i][1]++;
		}
		else
		{
			
			arr[i][2]++;
		}
	}

	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(str[i]!=str[j])
			{
                if(str[i]=='R')
				{
					if(str[j]=='G')
					{
						if(2*j-i<n&& 2*j-i>j)
						{
							if(str[2*j-i]=='B')
							{
                                sum+= arr[n-1][2]-arr[j][2]-1; 
							}
							else
							{
								sum+= arr[n-1][2]-arr[j][2];
							}
							
						}
						else
						{
							sum+= arr[n-1][2]-arr[j][2];
						}
						
					}
					else
					{
						if(2*j-i<n&& 2*j-i>j)
						{
							if(str[2*j-i]=='G')
							{
                                sum+= arr[n-1][1]-arr[j][1]-1; 
							}
							else
							{
								sum+= arr[n-1][1]-arr[j][1];
							}
							
						}
						else
						{
							sum+= arr[n-1][1]-arr[j][1];
						}
					}
					
				}
				else if(str[i]=='G')
				{
					if(str[j]=='R')
					{
						if(2*j-i<n&& 2*j-i>j)
						{
							if(str[2*j-i]=='B')
							{
                                sum+= arr[n-1][2]-arr[j][2]-1; 
							}
							else
							{
								sum+= arr[n-1][2]-arr[j][2];
							}
							
						}
						else
						{
							sum+= arr[n-1][2]-arr[j][2];
						}
						
					}
					else
					{
						if(2*j-i<n&& 2*j-i>j)
						{
							if(str[2*j-i]=='R')
							{
                                sum+= arr[n-1][0]-arr[j][0]-1; 
							}
							else
							{
								sum+= arr[n-1][0]-arr[j][0];
							}
							
						}
						else
						{
							sum+= arr[n-1][0]-arr[j][0];
						}
					}
				}
				else
				{
					if(str[j]=='G')
					{
						if(2*j-i<n&& 2*j-i>j)
						{
							if(str[2*j-i]=='R')
							{
                                sum+= arr[n-1][0]-arr[j][0]-1; 
							}
							else
							{
								sum+= arr[n-1][0]-arr[j][0];
							}
							
						}
						else
						{
							sum+= arr[n-1][0]-arr[j][0];
						}
						
					}
					else
					{
						if(2*j-i<n&& 2*j-i>j)
						{
							if(str[2*j-i]=='G')
							{
                                sum+= arr[n-1][1]-arr[j][1]-1; 
							}
							else
							{
								sum+= arr[n-1][1]-arr[j][1];
							}
							
						}
						else
						{
							sum+= arr[n-1][1]-arr[j][1];
						}
					}
				}
			}
            
		}
	}

	cout<<sum;

	return 0;
}

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

int main(){
  vector<long long> A(5);
  long long N;
  cin>>N;
  for(int i=0;i<5;i++){
    cin>>A.at(i);
  }
  sort(A.begin(),A.end());
  long long ans=0;
  ans+=(N-1)/A.at(0)+1+4;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<int> l(n);
    for(int i = 0;i < n;i++)cin >> l[i];
    //l[n] = -10;
    //l[n+1] = 100000;
    sort(l.begin(),l.end());
    ll ans = 0;
    for(int i = 0;i < n;i++){
        for(int j = i+1;j < n;j++){
            int a = l[i];
            int b = l[j];
            int m = upper_bound(l.begin(),l.end(),b-a)-l.begin();
            int M = lower_bound(l.begin(),l.end(),a+b)-l.begin()-1;
            //cout << a+b <<" " << l[M] << " "  << M <<" " << l[m] << " "  << m << " "<< b-a << endl;
            int un = 0;
            if(m <= i && i <= M)un--;
            if(m <= j && j <= M)un--;
            //cout << un << endl;
            ans += max(0,M-m+1+un);
            //cout << ans << endl;
        }
    }
    cout << ans/3 << endl;
    //cin >> n;
}

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


int main() {
  int s, w;
  cin >> s >> w;
  if (s <= w) cout << "unsafe" << endl;
  else cout << "safe" << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    long long cities,roads,a,b;
    cin >> cities >> roads;
    long long grid[cities]={0};
    for (long long i=0; i<roads; i++){
        cin >> a >> b;
        grid[a-1]++;
        grid[b-1]++;}
    for (long long i=0; i<cities; i++){
        cout << grid[i];
        if (i<cities-1) {cout << "\n";}}}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define ins insert
#define fi first
#define se second
#define okay ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define llmax 2e18
#define PI 3.14159265
using namespace std;

int main() {
	okay;
//	int t;
//	cin>>t;
//	while(t--)
	{
		int a;
		cin>>a;
		cout<<a+(a*a)+(a*a*a);
	}
}

Measured memory_bytes: 3584
#include <cstdio>
int n, a[200005];
int main() {
	int i;
	scanf("%d", &n);
	for(i=0; i<n; i++) scanf("%d", &a[i]);
	for(i=n-1; i>=0; i-=2) printf("%d ", a[i]);
	for(i = n%2?1:0; i<n; i+=2) printf("%d ", a[i]);
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    vstr s(n);
    rep(i, n) cin >> s[i];
    int ans = 0;
    int ab = 0, a = 0, b = 0;
    rep(i, n) {
        rep(j, s[i].length()-1) {
            if (s[i][j] == 'A' && s[i][j+1] == 'B') ans++;
        }
        if (s[i].back() == 'A' && s[i].front() == 'B') ab++;
        if (s[i].back() == 'A' && s[i].front() != 'B') a++;
        if (s[i].back() != 'A' && s[i].front() == 'B') b++;
    }
    
    if (a+b == 0) ans += max(ab-1, 0);
    else ans += ab + min(a, b);

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

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

using namespace std;

int main () {
  int k;
  cin >> k;
  int ans = 1;
  int val = 7 % k;
  while (val) {
    val = (10 * val + 7) % k;
    if (ans > 1e7) {
      cout << -1;
      return 0;
    }
    ans++;
  }
  cout << ans;
  return 0;
}

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

int main()
{
  int ans = 0;
  int n, m;
  cin >> n >> m;
  int k[m];
  vector<vector<int>> s(m);
  vector<int> p(m);
  REP(i,0,m){
    cin >> k[i];
    s[i].resize(k[i]);
    REP(j,0,k[i]){
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  REP(i,0,m){
    cin >> p[i];
  }

  for (int i = 0; i < (1 << n); ++i) {
		bool ok = true;
		REP(j,0,m) {
			int c = 0;
			for (int id : s[j]) {
				if ((i >> id) & 1) {
					++c;
				}
			}
			c %= 2;
			if (c != p[j]) {
				ok = false;
			}
		}
		if (ok) {
			++ans;
		}
	}

  cout << ans << endl;

  //--debug : end_stoper
  //string end_stoper; cin >> end_stoper;

  return 0;
}

Measured memory_bytes: 3604
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
    int n;
    cin >> n;
    cout << n * 800 - n / 15 * 200;
    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
    string s;
    cin >> s;
    vector<pair<int, int> > A(26, make_pair(0, -1));
    vector<bool> B(26, 0);
    for(int i = 0; i < s.size(); i++) {
        int now = s.at(i) - 'a';
        A.at(now).first = max(A.at(now).first, i - A.at(now).second - 1);
        A.at(now).second = i;
        B.at(now) = 1;
    }
    for(int i = 0; i < 26; i++) {
        A.at(i).first = max(A.at(i).first, (int)s.size() - A.at(i).second - 1);
    }
    
    int ans = 10000;

    for(int i = 0; i < 26; i++) {
        //cout << i << ':' << A.at(i).first << endl;
        if(B.at(i)) {
            ans = min(ans, A.at(i).first);
        }
    }

    cout << ans << endl;



    return 0;
}

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

void solve(void) {
  int N; cin >> N;

  double res = 0.0;
  for (int i = 0; i < N; ++i) {
    double a; cin >> a;
    res += (double)(1.0 / a);
  }

  cout << setprecision(16) << (double)(1.0 / res) << endl;
}
int main(void) {
  solve();
  return 0;
}

Measured memory_bytes: 256
/*
 * ALDS1_10_B.cpp
 *
 *  Created on: May 5, 2018
 *      Author: 13743
 */

#include<iostream>
#include<algorithm>

using namespace std;

struct Mat {
	int row;
	int col;
};

long mcm(Mat* M, int n) {
	long dp[101][101];
	for(int i=2; i<=n; i++) {
		for(int j=0; j<=n-i; j++) {
			dp[i][j] = 99999999999L;
			for(int k=1; k<i; k++) {
				dp[i][j] = min(dp[k][j]+dp[i-k][j+k]+M[j].row*M[j+k].row*M[j+i-1].col, dp[i][j]);
			}
		}
	}
	return dp[n][0];
}

long dpR[101][101];

long mcmRec(Mat* M, int l, int r) {
	if(r - l < 2) return 0;
	if(dpR[l][r] == 0) {
		dpR[l][r] = 9999999999L;
		for(int i=1; i<r-l; i++) {
			dpR[l][r] = min(mcmRec(M,l,l+i)+mcmRec(M,l+i,r)+M[l].row*M[l+i].row*M[r-1].col, dpR[l][r]);
		}
	}
	return dpR[l][r];
}

int main() {
	int n;
	Mat M[100];

	cin >> n;
	for(int i=0; i<n; i++) {
		cin >> M[i].row >> M[i].col;
	}

//	long ans = mcm(M, n);
	long ans = mcmRec(M, 0, n);
	cout << ans << endl;

}





Measured memory_bytes: 3148
using System;
using System.Collections;
using System.Collections.Generic;

class Program {
    static void Main (string[] args) {
        var s = Console.ReadLine ();
        if (s == s.ToLower ()) {
            Console.WriteLine ("a");
        } else {
            Console.WriteLine ("A");
        }

    }
}

//dotnet run --project test

Measured memory_bytes: 26308
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
    char s[11], t[12], tc[11];
    cin >> s >> t;
    strncpy(tc, t, strlen(t) - 1);
    tc[strlen(t) - 1] = '\0';
    if (strcmp(s, tc) == 0)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX_N = 100;
int N, K;
int X[MAX_N];
int main(){
scanf("%d", &N);
scanf("%d", &K);
for(int i = 0; i < N; ++i){
scanf("%d", X + i);
}
int ans = 0;
for(int i = 0; i < N; ++i){
int tmp = min(X[i], K - X[i]);
ans += tmp;
}
printf("%d\n", ans * 2);
return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main(){
	char a[100004],b[100004];
	cin>>a;
	int k=strlen(a);
	k--;
	for(int i=0;i<=k;i++) 	b[i]=a[k-i];
		for(int i=0;i<=k;i++) {
		if(b[i]=='b') b[i]='d';
		else if(b[i]=='d') b[i]='b';
		else if(b[i]=='q') b[i]='p';
		else b[i]='q';
		if(a[i]!=b[i]) {
			cout<<"No"<<endl;
			return 0;
		}
		}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void solve(){
  int n;
  cin>>n;
  cout<<(1000-n%1000)%1000<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3508
//-------------
//include
//-------------
#include <map>
#include <list>
#include <cmath>
#include <vector>
#include <string>
#include <cctype>
#include <random>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
//-------------
//typedef
//-------------
typedef long long LL;
typedef  vector<int> VI;
typedef  pair<int, int> PII;
typedef  vector<int, int> VII;
typedef  map<string, int> MSI;
//-------------
//utillty
//-------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MK make_pair
#define PB push_back
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//-------------
//repetition
//-------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//-------------
//debug
//-------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define W1 while(1);
const int MOD = 1000000007;
int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	if (C >= A&&C <= B)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256