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

#define all(x)        (x).begin(),(x).end()
#define eb            emplace_back
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define sz(x)         ((int)(x).size())
#define rep(x,y,z)    for(int x=y;x<z;x++)
#define per(x,z,y)    for(int x=z-1;x>=y;x--)
#define trav(y,x)     for(auto& y:x)
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define vi            vector<int>
#define vpi           vector<pii>

int dbg = 0;
#define cri           if(0)
#define shame         cri cerr<<(++dbg)<<"\n\n";

// aaaaaaaaaaaaaaaa
void solve() {
  int N;
  scanf("%d", &N);

  vi a(N);
  rep(i, 0, N)
    scanf("%d", &a[i]);

  ll ans = 0;
  map<int, int> u;
  rep(i, 0, N) {
    int seek = i - a[i];
    auto it = u.find(seek);
    if (it != u.end())
      ans += u[seek];

    int put = i + a[i];
    it = u.find(put);
    if (it == u.end())
      u[put] = 0;
    u[put]++;
  }
  printf("%lld\n", ans);
}

int main() {
  // int _; scanf("%d", &_); while (_--)
  // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // int _; cin >> _; while(_--)
  solve();
	return 0;
}



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

int main() {
  int N;
  cin >> N;
  string u;
  double sum, x;
  sum=0;
  for(int i =0; i< N; i++){
    cin >> x >> u;
    if(u=="JPY"){
      sum += x;
    }
    else{
      x *=380000;
      sum += x;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
int n,m;
int sr[10010];
int A[110][110];
bool book[10010];
int B[110][110];
int C[110][110];

int s,t;
struct data{
    int to,nxt,c,id;
}mp[100100];
int head[1010],cnt=1;
void link(int x,int y,int c,int id)
{
    mp[++cnt].to=y;
    mp[cnt].nxt=head[x];
    mp[cnt].c=c;
    mp[cnt].id=id;
    head[x]=cnt;
}
void add(int x,int y,int c,int id)
{
    link(x,y,c,id);
    link(y,x,0,id);
}
int cur[1010];
int dis[1010];
queue<int>q;
bool BFS()
{
    memset(dis,0,sizeof(dis));dis[s]=1;
    q.push(s);
    int x;
    while(!q.empty())
    {
        x=q.front();q.pop();
        for(int i=head[x];i;i=mp[i].nxt)
            if(!dis[mp[i].to]&&mp[i].c&&!book[mp[i].id])
                dis[mp[i].to]=dis[x]+1,q.push(mp[i].to);
    }
    return dis[t];
}
int dfs(int x,int f)
{
    if(x==t)return f;
    int rf=0,fl;
    for(int& i=cur[x];i;i=mp[i].nxt)
        if(dis[mp[i].to]==dis[x]+1&&mp[i].c&&!book[mp[i].id])
        {
            fl=dfs(mp[i].to,min(f,mp[i].c));
            if(fl)
            {
                rf+=fl;
                f-=fl;
                mp[i].c-=fl;
                mp[i^1].c+=fl;
                if(!f)break;
            }
        }
    return rf;
}
void Dinic()
{
    int mf=0,fl;
    while(BFS())
    {
        memcpy(cur,head,sizeof(head));
        while(fl=dfs(s,inf))mf+=fl;
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
        {
            scanf("%d",&A[i][j]);
            sr[m*(i-1)+j]=i;
        }
    s=n*2+1;t=s+1;
    for(int i=1;i<=n;++i)
        add(s,i,1,0),add(i+n,t,1,0);
    int tc=cnt;
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
            add(sr[A[i][j]],i+n,1,A[i][j]);
    int x;
    for(int j=1;j<=m;++j)
    {
        for(int i=2;i<=tc;i+=2) mp[i].c=1,mp[i^1].c=0;
        Dinic();
        for(x=1;x<=n;++x)
            for(int i=head[x];i;i=mp[i].nxt)
                if(!book[mp[i].id]&&mp[i].to>n&&!mp[i].c)
                {
                    book[mp[i].id]=1;
                    B[mp[i].to-n][j]=mp[i].id;
                    C[x][j]=mp[i].id;
                    break;
                }
    }
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)printf("%d ",B[i][j]);
        puts("");
    }
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)printf("%d ",C[i][j]);
        puts("");
    }
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
using namespace std;
const int MAXN = 200005;
const LL MOD = 998244353;

struct Interval {
	int l, r, a;
	bool operator < (const Interval &it) const {
		return r < it.r;
	}
};

struct ST {
	LL maxv[4*MAXN], tag[4*MAXN];
	void add(int ql, int qr, LL v, int l, int r, int idx) {
		if (ql <= l && r <= qr) {
			maxv[idx] += v;
			tag[idx] += v;
			return;
		}
		
		int m = (l + r) >> 1;
		if (qr <= m) add(ql, qr, v, l, m, idx << 1);
		else if (ql > m) add(ql, qr, v, m + 1, r, idx << 1 | 1);
		else {
			add(ql, qr, v, l, m, idx << 1);
			add(ql, qr, v, m + 1, r, idx << 1 | 1);
		}
		
		maxv[idx] = max(maxv[idx << 1], maxv[idx << 1 | 1]) + tag[idx];
	}
	
	LL rmq(int ql, int qr, int l, int r, int idx) {
		if (ql <= l && r <= qr) return maxv[idx];
		
		int m = (l + r) >> 1;
		if (qr <= m) return rmq(ql, qr, l, m, idx << 1) + tag[idx];
		else if (ql > m) return rmq(ql, qr, m + 1, r, idx << 1 | 1) + tag[idx];
		else {
			LL q1 = rmq(ql, qr, l, m, idx << 1);
			LL q2 = rmq(ql, qr, m + 1, r, idx << 1 | 1);
			return max(q1, q2) + tag[idx];
		}
	}
} tree;

int N, M, last[MAXN];
Interval intv[MAXN];
LL dp[MAXN];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		cin >> intv[i].l >> intv[i].r >> intv[i].a;
	}
	
	int pos = 1;
	sort(intv + 1, intv + 1 + M);
	for (int i = 1; i <= N; i++) {
		while (pos <= M && intv[pos].r < i) pos++;
		last[i] = pos - 1;
	}
	
	pos = 1;
	for (int i = 1; i <= M; i++) {
		tree.add(intv[i].l, intv[i].r, intv[i].a, 1, N, 1);
		while (pos <= intv[i].r) {
//			cout << "Pos " << pos << " -> " << last[pos] << "\n";
			tree.add(pos, pos, dp[last[pos]], 1, N, 1);
			pos++;
		}
		
		dp[i] = max(0LL, tree.rmq(1, intv[i].r, 1, N, 1));
//		cout << i << " -> " << dp[i] << '\n';
	}
	
	cout << dp[M] << "\n";
}


Measured memory_bytes: 16640
#include<stdio.h>
int main()
{
     int a,b,c,d,e;
     scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
     if(a==0)
          printf("1\n");
     if(b==0)
          printf("2\n");
          if(c==0)
          printf("3\n");
          if(d==0)
          printf("4\n");
          if(e==0)
          printf("5\n");
}


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

int main()
{
    int h, n;
    cin >> h >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    bool win = false;
    rep(i, n)
    {
        h -= a[i];
        if (h <= 0)
            win = true;
    }
    if (win)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int A, B, H, res;
  rd(A);
  rd(B);
  rd(H);
  res = (A+B) * H / 2;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// {
//   int A, B, H, res;
//   rd(A,B,H);
//   res = (A+B) * H / 2;
//   wt(res);
// }


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

vector<int> prime;
vector<bool> isPrime;
void sieve(int n) {
  isPrime.resize(n+1, true);
  isPrime[0] = isPrime[1] = false;
  for(int i = 2; i <= n; i++) {
    if(isPrime[i]) {
      prime.push_back(i);
      for(int j = 2*i; j <= n; j += i) isPrime[j] = false;
    }
  }
}

int main () {
  int N = 1e5;
  sieve(N);
  vector<int> S(N+1, 0);
  rep(i,N) {
    S[i+1] = S[i] + (((i+1) & 1) && isPrime[i+1] && isPrime[(i+2)/2]);
  }

  int Q;
  cin >> Q;
  while(Q--) {
    int l, r;
    cin >> l >> r;
    cout << S[r] - S[l-1] << endl;
  }

  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <map>
#include <string>

using namespace std;

bool check(string s1, string s2) {
    map<char, char> check_s1;
    for (int i = 0; i < s1.length(); ++i) {
        decltype(check_s1)::iterator itr = check_s1.find(s1[i]);
        if (itr != check_s1.end()) {
            if (check_s1[s1[i]] != s2[i])
                return false;
        } else {
            check_s1[s1[i]] = s2[i];
        }
    }

    map<char, char> check_s2;
    for (int i = 0; i < s2.length(); ++i) {
        decltype(check_s2)::iterator itr = check_s2.find(s2[i]);
        if (itr != check_s2.end()) {
            if (check_s2[s2[i]] != s1[i])
                return false;
        } else {
            check_s2[s2[i]] = s1[i];
        }
    }

    return true;
}

int main() {
    string s, t;
    cin >> s >> t;
    if (check(s, t))
        cout << "Yes\n";
    else
        cout << "No\n";
}


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

int main() {

    string s;

    cin >> s ;

    int b , e;

    for(int i=0 ; i<s.size() ; i++){
        if(s.at(i)=='A'){
            b = i;
            break;
        } 
    }
    for(int i=s.size()-1 ; i>=0 ;i--){
        if(s.at(i)=='Z'){
            e = i;
            break;
        }
    }
    cout << e-b+1 << endl;
}

Measured memory_bytes: 640
import sys
N = int(input())
dif = [0] * N
mini = [0] * N
for _ in range(N):
    S = input()
    m = 0
    now = 0
    for i in range(len(S)):
        if S[i] == '(':
            now += 1
        else:
            now -= 1
        m = min(m, now)
    dif[_] = now
    mini[_] = m

sum = 0
for i in range(N):
    sum += dif[i]
if sum != 0:
    print('No')
    sys.exit()

plus = []
minus = []
for i in range(N):
    if dif[i] >= 0:
        plus.append((mini[i], dif[i]))
    else:
        minus.append((dif[i] - mini[i], mini[i], dif[i]))
plus.sort(reverse=True)
minus.sort(reverse=True)


now = 0
for i in range(len(plus)):
    if now + plus[i][0] < 0:
        print('No')
        sys.exit()
    now += plus[i][1]

for i in range(len(minus)):
    if now + minus[i][1] < 0:
        print('No')
        sys.exit()
    now += minus[i][2]
print('Yes')


Measured memory_bytes: 182956
fun main(args: Array<String>) {
    val s = readLine() ?: return
    val t = readLine() ?: return
    val ss = s.toCharArray().sorted().joinToString(separator = "")
    val tt = t.toCharArray().sortedDescending().joinToString(separator = "")
    if (ss < tt) {
        println("Yes")
    } else {
        println("No")
    }
}

Measured memory_bytes: 35776
import java.awt.Point;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.*;

public class Main {	
	Scanner in = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new AOJ0096();
	}
	class AOJ0096{
		int doIt(){
			int result=0;
			int n=in.nextInt();
			/*(a,b)+(c,d)と考える。
			 * n=2で
			 * (a,b)=0なら1通り(0,0)      *       (c,d)=(1,1)(2,0)(0,2) =3
			 * 		=1なら2通り(1,0)(0,1)			     =(1,0)(0,1)      =4
			 * 		=2なら3通り(1,1)(2,0)(0,2)         =(0,0)          =3
			 * 

			 * (a,b)=0なら1通り(0,0)
			 *      =1なら2通り(1,0)(0,1)
			 *      =2なら3通り(1,1)(2,0)(0,2)
			 *      =3なら4通り(3,0)(0,3)(1,2)(2,1)
			 *      =4なら5通り(0,4)(4,0)(1,3)(3,1)(2,2)
			 *      =5なら6通り(0,5)(5,0)(1,4)(4,1)(2,3)(3,2)
			 *      =6なら7通り(6,0)(0,6)(1,5)(5,1)(2,4)(4,2)(3,3)
			 *      =7なら8通り(7,0)(0,7)(1,6)(6,1)(2,5)(5,2)(3,4)(4,3)
			 *      
			 */

			for(int i=0;i<=2000;i++){
				if(n-i<0)break;
				if(n-i>2000)continue;
				result+=list[i]*list[n-i];
			}
			return result;
		}
		int[] list;
		public AOJ0096() {
			list = new int[2001];
			for(int i=0;i<=1000;i++)for(int s=0;s<=1000;s++)list[s+i]++;
			while(in.hasNext())System.out.println(doIt());
		}
	}

}

Measured memory_bytes: 19772
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;
using namespace chrono;
 
typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

//#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define loop(x,n) for(int x = 0; x < n; ++x)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 100001;

string get_str() {
    string temp;
    cin >> temp;
    return temp;
}
int get_int() {
    int temp;
    cin >> temp;
    return temp;
}




int main() {
    
    string s;
    cin >> s;
    if(islower(s[0])) cout << 'a' << endl;
    else cout << 'A' << endl;

}

Measured memory_bytes: 3576
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans = a*c;
    ans=max(ans,a*d);
    ans=max(ans,b*c);
    ans=max(ans,b*d);
    cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 3632
while True:
    H,W = map(int,input().split())



    if H == 0 and W == 0:
        break

    else:
        for tate in range(1,H+1):
            for yoko in range(1,W+1):
                if ((tate+yoko)%2 == 0):
                    print("#",end="")

                else:
                    print(".",end="")
            print()
        print()


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

int main(){
    int a, b;
    char op;
    
    while(true){
        cin >> a >> op >> b;
        
        if(op == '+') cout << a + b << endl;
        else if(op == '-') cout << a - b << endl;
        else if(op == '*') cout << a * b << endl;
        else if(op == '/') cout << a / b << endl;
        else break;
    }
    
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
 
#include <algorithm> // std::max
#include <utility> // std::pair
#include <vector> // std::vector
 
using ull = unsigned long long;
 
// First element is weight, second element is value.
using Item = std::pair<int, ull>;
 
// Time complexity is O(n * W),
// auxiliary space is O(W),
// where n = items.size(),
//       W = min(capacity, sum(weight)).
ull knapsack_01_small_capacity(const std::vector<Item> &items, int capacity) {
    int n = items.size();
    int weight_sum = 0;
    for (const Item &item: items) {
        weight_sum += item.first;
    }
    int W = std::min(capacity, weight_sum);
    std::vector<ull> dp(W + 1, 0);
    for (const Item &item: items) {
        for (int w = W; w >= item.first; --w) {
            dp[w] = std::max(dp[w], dp[w - item.first] + item.second);
        }
    }
    return dp[W];
}
 
int main() {
    using namespace std;
 
    int N, W;
    cin >> N >> W;
    vector<Item> items(N);
    for (int i = 0; i < N; ++i) {
        int v, w;
        cin >> v >> w;
        items[i] = make_pair(w, v);
    }
    cout << knapsack_01_small_capacity(items, W) << endl;
    return 0;
}


Measured memory_bytes: 3196
#include <iostream>
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int mod = 998244353;

int32_t main() {
    
    int n, k;
    cin >> n >> k;
    vector<int> l(k), r(k);
    for(int i=0; i<k; i++){
        cin >> l[i] >> r[i];
    }
    vector<int> dp(n+1);
    dp[1] = 1;
    for(int i=1; i<=n; i++){
        if(i != 2){
            dp[i] += dp[i-1];
            dp[i] %= mod;
        }
        for(int j=0; j<k; j++){
            if(i+r[j] < n){
                dp[i+r[j]+1] -= dp[i];
                dp[i+r[j]+1] = (dp[i+r[j]+1]+mod)%mod;
            }
            if(i+l[j] <= n){
                dp[i+l[j]] += dp[i];
                dp[i+l[j]] %= mod;
            }
        }
    }
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 4820
from itertools import product

H, W, K = map(int, input().split())
S = [[int(i) for i in input()] for _ in range(H)]

T = [t for t in zip(*S)]
if sum(map(sum, T)) <= K:
    print(0)
    quit()

ans = float("inf")
for P in product([0, 1], repeat=H - 1):
    cnt = sum(P)

    II = [[0]]
    for i, p in enumerate(P, 1):
        if p:
            II.append([])
        II[-1].append(i)

    A = [0] * len(II)
    for t in T:
        for i, I in enumerate(II):
            A[i] += sum(t[x] for x in I)

        if any(a > K for a in A):
            cnt += 1
            if cnt >= ans:
                break

            A = [sum(t[x] for x in I) for I in II]
            if any(a > K for a in A):
              cnt = 1 + ans
              break

    ans = min(ans, cnt)

print(ans)

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

using namespace std;

int main()
{
     int a[3],cnt,k1,k2;
     cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    k1=a[2]-a[0];
    k2=a[2]-a[1];
    cnt=k1/2+k2/2;
    //cout<<cnt<<endl;
    if(k1&1 && k2&1) cnt++;
    else if(k1%2==0 && k2%2==0) cnt+=0;
    else cnt+=2;
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define int ll;
#define se second
#define vl vector<ll>
#define pb push_back
#define pi pair<int,int>
#define mp make_pair
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
using namespace std;

ll A[100001];
//vector<pair<ll,ll>> pairs;
ll n,m;
vl a;
signed main(){
cin>>n>>m;
n*=3;
cout<<(n+m)/2<<endl;
};

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

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

////////////////////////////////////////////////////////////////

int main(void) {
	ll N, A, B, C;
	cin >> N >> A >> B >> C;
	vector<string> s(N);
	for(int i=0; i<N; i++){
		cin >> s[i];
	}

	ll sum = A + B + C;
	vector<char> ans;
    //sum==1の場合が無くても通るはず!!
	// if(sum == 1){
	// 	for(int i=0; i<N; i++){
	// 		if(s[i]=="AB"){
	// 			if(A==0 && B==0){ cout << "No" << endl; return 0;}
	// 			if(A==1){ A--; B++; ans.push_back('B');}
	// 			else {A++; B--; ans.push_back('A');}
	// 		}
	// 		if(s[i]=="BC"){
	// 			if(B==0 && C==0){ cout << "No" << endl; return 0;}
	// 			if(B==1){ B--; C++; ans.push_back('C');}
	// 			else {B++; C--; ans.push_back('B');}
	// 		}
	// 		if(s[i]=="AC"){
	// 			if(A==0 && C==0){ cout << "No" << endl; return 0;}
	// 			if(A==1){ A--; C++; ans.push_back('C');}
	// 			else {A++; C--; ans.push_back('A');}
	// 		}
	// 	}
	// 	cout << "Yes" << endl;
	// 	for(int i=0; i<N; i++) cout << ans[i] << endl;
	// 	return 0;
	// }

	s.push_back("  ");//番兵
	for(int i=0; i<N; i++){
		if(s[i]=="AB"){
			if(A==0 && B==0){cout << "No" << endl; return 0;}
			if(A < B){ A++; B--; ans.push_back('A'); continue; }
			else if(A>B){A--; B++; ans.push_back('B'); continue;}
			//以下A==Bの場合
			if(s[i+1]=="BC"){ A--; B++; ans.push_back('B'); continue;}
			else {A++; B--; ans.push_back('A'); continue;}
		}
		else if(s[i]=="BC"){
			if(B==0 && C==0){cout << "No" << endl; return 0;}
			if(B < C){ B++; C--; ans.push_back('B'); continue;}
			else if(B>C){B--; C++; ans.push_back('C'); continue;}
			//以下B==Cの場合
			if(s[i+1]=="AC"){ B--; C++; ans.push_back('C'); continue;}
			else {B++; C--; ans.push_back('B'); continue;}
		}
		else if(s[i]=="AC"){
			if(A==0 && C==0){cout << "No" << endl; return 0;}
			if(A < C){ A++; C--; ans.push_back('A'); continue;}
			else if(A>C){A--; C++; ans.push_back('C'); continue;}
			//以下A==Cの場合
			if(s[i+1]=="BC"){ A--; C++; ans.push_back('C'); continue;}
			else {A++; C--; ans.push_back('A'); continue;}
		}
	}
	//cout << " A: " << A << " B: " << B << " C: " << C << endl;
	cout << "Yes" << endl;
	for(int i=0; i<ans.size(); i++){
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 9600
N = int(input())

count = [[0 for _ in range(9)] for _ in range(9)]
for i in range(1, N + 1):
    s = str(i)
    prefix = int(s[0])
    surfix = int(s[-1])
    if surfix != 0:
        count[prefix - 1][surfix - 1] += 1

ans = 0
for i in range(9):
    for j in range(9):
        ans += count[i][j] * count[j][i]

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> doup;
ll N, M, R;
ll i, j, k;
ll a, b, c;
ll d[201][201];
vector<ll> r;
ll sum;

int main(void) {
    ll N, i;
    ll a[200100];
    cin >> N;
    for(i=0; i<N; i++) {
        cin >> a[i];
    }
    ll dp[200100]={0};
    ll ans=0;
    for(i=0; i<N; i++) {
        ll p=a[i];
        dp[p]=dp[p-1]+1;
        ans=max(ans, dp[p]);
    }
    
    cout << N-ans << endl;
}


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


int main() {
  string s,t;
  cin >> s>>t;
   
  vector<bool> a(26);
  vector<long> c[26];
  rep(i,s.size()) {
    a.at(s.at(i)-'a')=true;
    c[s.at(i)-'a'].push_back(i);
  }
  bool b=true;   
  rep(i,t.size()){
    if(!a.at(t.at(i)-'a')){
      b=false;
      break;
    }
  }
  if(b){
    long ans;
    vector<long> d(t.size());
    long ch=-1;
    rep(i,t.size()){     
      auto itr = upper_bound(c[t[i]-'a'].begin(), c[t[i]-'a'].end(), ch);
      if(itr==c[t[i]-'a'].end()){
        d.at(i)=c[t.at(i)-'a'].at(0);
        ch=d.at(i);
      }
      else{
        d.at(i)=*itr;
        ch=d.at(i);
      }
    }
    long co=0;
    rep(i,t.size()-1){
      if(d.at(i)>=d.at(i+1)){
        co++;
      }
    }
    ans=co*s.size()+d.at(t.size()-1)+1;
    cout<<ans<<endl;
  }
  else{
    cout<<"-1"<<endl;
  }
}

Measured memory_bytes: 5344
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = System.Console.ReadLine().Trim();
            //// 入力
            //StringBuilder stbS = new StringBuilder();
            //for (int i = 0; i < 100000 / 100000; i++)
            //{
            //    stbS.Append(new string('0', 50000));
            //    stbS.Append(new string('1', 50000));
            //}
            //string sS = stbS.ToString();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iS = sS.Length;
            List<int> lstCnt = new List<int>();
            lstCnt.Add(iS - sS.Replace("0", "").Length);
            lstCnt.Add(iS - sS.Replace("1", "").Length);
            lstCnt.Sort();

            // 出力
            System.Console.WriteLine("{0}", (lstCnt[0] * 2).ToString());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 16096
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

//code by lynmisakura.wish to be accepted!
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

/***************************/
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<long long> vl;
typedef pair<ll, ll> pi;
typedef vector<pair<ll, ll>> vpi;

//const long long INF = 1LL << 55;

#define itn ll
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(ll i = 0;i < n;i++)
#define rep(i,n) for(ll i = 0;i < n;i++)
#define flush fflush(stdout)
#define rrep(i,n) for(ll i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, ll mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

class CAtCoDeerAtCoDeerAndElectionReport {
public:
    static constexpr int kStressIterations = 0;
    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        ll N;cin >> N;
        vector<ll> t(N),a(N);rep(i,N)cin >> t[i] >> a[i];
        ll T,A;
        T = t[0],A = a[0];
        for(int i =1;i < N;i++){
            ll d = max(dup(T,t[i]),dup(A,a[i]));
            A = a[i]*d,T = t[i]*d;
        }
        cout << A + T << endl;
    }
};

int main() {
	CAtCoDeerAtCoDeerAndElectionReport solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
N = int(input())
U = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]
# open: True, close: False
f = False
for i in T:
    if i in U:
        if f:
            print("Closed by {}".format(i))
        else:
            print("Opened by {}".format(i))
        f = not f
    else:
        print("Unknown {}".format(i))



Measured memory_bytes: 5640
n = int(input())
a = list(map(int, input().split()))

count = 0
abs_a = []
for i in range(n):
	if a[i] < 0:
		count += 1
		abs_a.append(-a[i])
	else:
		abs_a.append(a[i])

total = sum(abs_a)

if count%2==0:
	print(total)
else:
	smallest = min(abs_a)
	print(total - (2*smallest))

Measured memory_bytes: 14212
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

int pow(int A){
    if( A == 0) return 1;
    return 2 * pow(A-1);
}

int main() {
    int x,y;
    scanf("%d %d", &x, &y);
    int ans = ( y * 1900 + ( x - y ) * 100) * pow(y);
    printf ("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
ABCD = list(input())
for i in range(len(ABCD)):
  ABCD[i] = int(ABCD[i])

r1 = ABCD[0] + ABCD[1] + ABCD[2] + ABCD[3]
r2 = ABCD[0] + ABCD[1] + ABCD[2] - ABCD[3]
r3 = ABCD[0] + ABCD[1] - ABCD[2] + ABCD[3]
r4 = ABCD[0] - ABCD[1] + ABCD[2] + ABCD[3]
r5 = ABCD[0] + ABCD[1] - ABCD[2] - ABCD[3]
r6 = ABCD[0] - ABCD[1] + ABCD[2] - ABCD[3]
r7 = ABCD[0] - ABCD[1] - ABCD[2] + ABCD[3]
r8 = ABCD[0] - ABCD[1] - ABCD[2] - ABCD[3]

if r1 == 7:
  a = str(ABCD[0]) + '+' + str(ABCD[1]) + '+' + str(ABCD[2]) + '+' + str(ABCD[3]) + '=7'
  print(a)
elif r2 == 7:
  a = str(ABCD[0]) + '+' + str(ABCD[1]) + '+' + str(ABCD[2]) + '-' + str(ABCD[3]) + '=7'
  print(a)
elif r3 == 7:
  a = str(ABCD[0]) + '+' + str(ABCD[1]) + '-' + str(ABCD[2]) + '+' + str(ABCD[3]) + '=7'
  print(a)
elif r4 == 7:
  a = str(ABCD[0]) + '-' + str(ABCD[1]) + '+' + str(ABCD[2]) + '+' + str(ABCD[3]) + '=7'
  print(a)
elif r5 == 7:
  a = str(ABCD[0]) + '+' + str(ABCD[1]) + '-' + str(ABCD[2]) + '-' + str(ABCD[3]) + '=7'
  print(a)
elif r6 == 7:
  a = str(ABCD[0]) + '-' + str(ABCD[1]) + '+' + str(ABCD[2]) + '-' + str(ABCD[3]) + '=7'
  print(a)
elif r7 == 7:
  a = str(ABCD[0]) + '-' + str(ABCD[1]) + '-' + str(ABCD[2]) + '+' + str(ABCD[3]) + '=7'
  print(a)
elif r8 == 7:
  a = str(ABCD[0]) + '-' + str(ABCD[1]) + '-' + str(ABCD[2]) + '-' + str(ABCD[3]) + '=7'
  print(a)

Measured memory_bytes: 3192
N=int(input())
A=list(map(int,input().split()))
plus=[]
minus=[]
for i in range(N):
  plus.append(A[i]+i+1)
  minus.append(-A[i]+i+1)
from collections import Counter
p=Counter(plus)
m=Counter(minus)
sp=set()
for k in p.keys():
  sp.add(k)
ans=0
for k,v in m.items():
  if k in sp:
    ans+=v*p[k]
print(ans)
    

Measured memory_bytes: 176632
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}


ll N ;
ll dist[100001];

map<ll, vector<pair<ll,ll> > > edge;

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

    cin >> N ;

    rep(i, N-1){
        ll a, b ,c;
        cin >> a >> b >> c;
        a--,b--;
        edge[a].pb(mp(b,c));
        edge[b].pb(mp(a,c));
    }

    queue<ll> nodes;

    nodes.push(0);
    dist[0] = 2;

    while(nodes.size() != 0){
        ll nxt = nodes.front();
        cerr << "nodes: " << nxt << endl;
        nodes.pop();
        rep(i, edge[nxt].size()){
            ll aim = edge[nxt][i].first;
            ll cost = edge[nxt][i].second;
            if(dist[aim] == 0){
                dist[aim] = cost + dist[nxt];
                nodes.push(aim);
            }
        }
    }
    rep(i, N){
        cerr << dist[i] << "   ";
        cout << (dist[i]%2) << endl;
     }

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 14080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll N, M;
    cin >> N >> M;
    vector<ll> x(N), y(M);
    for (ll i = 0; i < N; i++) {
        cin >> x[i];
    }
    for (ll i = 0; i < M; i++) {
        cin >> y[i];
    }

    ll X, Y;
    X = 0; Y = 0;
    ll tmp;
    for (ll i = 0; i < N-1; i++) {
        tmp = (x[i+1] - x[i]) % MOD;
        tmp = tmp * (i+1) % MOD;
        tmp = tmp * (N-i-1) % MOD;
        X = (X + tmp) % MOD;
    }
    for (ll i = 0; i < M-1; i++) {
        tmp = (y[i+1] - y[i]) % MOD;
        tmp = tmp * (i+1) % MOD;
        tmp = tmp * (M-i-1) % MOD;
        Y = (Y + tmp) % MOD;
    }

    ll ans;
    ans = X*Y%MOD;

    printf("%lld\n", ans);


}

Measured memory_bytes: 4776
import std.stdio;
import std.ascii;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

struct Edge {
    int from, to, cost;
}

class UnionFind {
    int[] parent;
    int rootCount;
    this(int N) {
        parent = new int[N];
        parent[] = -1;
        rootCount = N;
    }
    int root(int x) {
        if (parent[x] == -1) return x;
        return parent[x] = root(parent[x]);
    }
    bool query(int x, int y) {
        return root(x) == root(y);
    }
    void merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return;
        rootCount--;
        parent[y] = x;
    }
}

void main() {
    int N, M;
    Edge[] G;

    bool input() {
        scanf("%d %d\n", &N, &M);
        if (N == 0 && M == 0) return false;
        G.clear;
        foreach (i; 0 .. M) {
            int x, y, c;
            scanf("%d %d %d\n", &x, &y, &c);
            G ~= Edge(x, y, c);
        }
        return true;
    }

    void solve() {
        auto uf = new UnionFind(N);
        G.sort!"a.cost > b.cost";
        int Ans = reduce!"a + b.cost"(0, G);
        foreach (e; G) {
            if (e.cost <= 0) continue;
            if (uf.query(e.from, e.to)) {
                Ans -= e.cost;
            } else if (uf.rootCount > 2) {
                uf.merge(e.from, e.to);
                Ans -= e.cost;
            }
        }
        writeln(Ans);
    }

    while (input) solve;
}

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

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

    int n = s.length();

    ll k;
    cin >> k;

    int che[n];
    for(int i = 0; i < n; i++){
        if(s[i] != 'a'){
            che[i] = 26 - (s[i] - 'a');
        }else{
            che[i] = 0;
        }
    }

    string ans = s;

    for(int i = 0; i < n; i++){
        if(k == che[i]){
            ans[i] = 'a';
            che[i] = 0;
            k = 0;
            break;
        }else if(k > che[i]){
            ans[i] = 'a';
            k -= che[i];
            che[i] = 0;
        }
    }

    int cou = 0;
    for(int i = 0; i < n; i++){
        if(che[i] == 0){
            cou++;
        }
    }

    if(k != 0){
        if(cou == n){
            k %= 26;
            ans[n - 1] = (char)('a' + k);
        }else{
            for(int i = n - 1; i >= 0; i--){
                if(ans[i] != 'a'){
                    ans[i] = (char)(ans[i] + k);
                    break;
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define FOR(i,n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
 
typedef long long ll;
typedef long double ld;
typedef pair<int, ll> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

const int MX = 305;
int n, res = 0;
char c[MX][MX], s[MX][MX];

int main () {
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    cin >> n;
    for (int i = 0; i < n; i++)
    	cin >> c[i];

    for (int a = 0; a < n; a++) {
    	for (int i = 0; i < n; i++)
    		for (int j = 0; j < n; j++)
    			s[(i+a)%n][j] = c[i][j];

    	bool f = 1;
    	for (int i = 0; i < n; i++)
    		for (int j = i + 1; j < n; j++)
    			f &= s[i][j] == s[j][i];

    	if (f)
    		res += n - a;
    }

    for (int b = 1; b < n; b++) {
    	for (int i = 0; i < n; i++)
    		for (int j = 0; j < n; j++)
    			s[i][(j+b)%n] = c[i][j];

    	bool f = 1;
    	for (int i = 0; i < n; i++)
    		for (int j = i + 1 ; j < n; j++)
    			f &= s[i][j] == s[j][i];

    	if (f)
    		res += n - b;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main()
{
    int a;
    int b;
    int count[4];
    int count2[2];
    int i;

    for(i = 0; i < 4; i++) {
        count[i] = 0;
    }

    for(i = 0; i < 3; i++) {
        scanf("%d %d", &a, &b);
        count[a-1] += 1;
        count[b-1] += 1;
    }

    for(i = 0; i < 2; i++) {
        count2[i] = 0;
    }
    for(i = 0; i < 4; i++) {
        if(count[i] == 1) {
            count2[0] += 1;
        }
        if(count[i] == 2) {
            count2[1] += 1;
        }
    }

    if(count2[0] == 2 && count2[1] == 2) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }

    return 0;
}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
int main(){
  int n,m,x,y;cin>>n>>m>>x>>y;
  vector<int>xx(n);
  vector<int>yy(m);
  for(int i=0;i<n;i++)
    cin>>xx[i];
  for(int i=0;i<m;i++)
    cin>>yy[i];
  sort(ALL(xx));
  sort(ALL(yy));
  if((xx[n-1]<yy[0])&&((x<xx[n-1]&&y>xx[n-1])||(x<yy[0]&&y>=yy[0])))
    cout<<"No War"<<endl;
  else cout<<"War"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100

void sort(int *,int);
int main() {
  int i,n;
  int array[N];

  scanf("%d",&n);
  for (i = 0; i < n; i++) {
    scanf("%d",&array[i]);
  }

  sort(array,n);

  return 0;
}

void sort(int *A,int n){
  int i,j,k,cnt=0,temp,flag=1;
  i = 0;
  while (flag) {
    flag = 0;
    for (j = n-1; j >= i+1; j--) {
      if (A[j] < A[j-1]) {
        temp = A[j];
        A[j] = A[j-1];
        A[j-1] = temp;
        cnt++;
        flag = 1;
      }
    }
    i++;
  }
  for (i = 0; i < n; i++) {
      if (i > 0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",cnt);
}

Measured memory_bytes: 604
#include<iostream>
#include<string>
using namespace std;
int main(){
	string a[3];
	int i;
	
	cin>>a[0]>>a[1]>>a[2];
	for(i=0;i<3;i++){
		if(a[i][0]=='a')cout<<"A";
		if(a[i][0]=='b')cout<<"B";
		if(a[i][0]=='c')cout<<"C";
		if(a[i][0]=='d')cout<<"D";
		if(a[i][0]=='e')cout<<"E";
		if(a[i][0]=='f')cout<<"F";
		if(a[i][0]=='g')cout<<"G";
		if(a[i][0]=='h')cout<<"H";
		if(a[i][0]=='i')cout<<"I";
		if(a[i][0]=='j')cout<<"J";
		if(a[i][0]=='k')cout<<"K";
		if(a[i][0]=='l')cout<<"L";
		if(a[i][0]=='m')cout<<"M";
		if(a[i][0]=='n')cout<<"N";
		if(a[i][0]=='o')cout<<"O";
		if(a[i][0]=='p')cout<<"P";
		if(a[i][0]=='q')cout<<"Q";
		if(a[i][0]=='r')cout<<"R";
		if(a[i][0]=='s')cout<<"S";
		if(a[i][0]=='t')cout<<"T";
		if(a[i][0]=='u')cout<<"U";
		if(a[i][0]=='v')cout<<"V";
		if(a[i][0]=='w')cout<<"W";
		if(a[i][0]=='x')cout<<"X";
		if(a[i][0]=='y')cout<<"Y";
		if(a[i][0]=='z')cout<<"Z";
	}
}

	
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k, x, i;
    scanf("%d%d", &k, &x);
    for(i=x-k+1; i<x+k-1; i++)
        printf("%d ", i);
    printf("%d\n", i);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  char S[][10] = {"Sunny","Cloudy","Rainy"};
  char a[10];
  scanf("%s",a);
  switch(a[0]){
  case 'S':
    printf("%s",S[1]);
    return 0;    
  case 'C':
    printf("%s",S[2]);
    return 0;
  case 'R':
    printf("%s",S[0]);
    return 0;
  }
}
  


Measured memory_bytes: 128
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    #define all(x) (x).begin(), (x).end()
    #define bit(n) (1LL<<(n))
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
template<typename T>
struct BinaryIndexedTree{
    int sz;
    vector<T> data;
    BinaryIndexedTree(int sz): sz(sz),data(sz+1) {}
    T sum(int k){
        // [0, k]
        T res = 0;
        for(k++; k > 0; k -= k & -k) res += data[k];
        return res;
    }
    T sum(int l, int r){
        // [l, r)
        return sum(r-1)-sum(l-1);
    }
    void add(int k, T x){
        for(k++; k <= sz; k += k & -k) data[k] += x;
    }

};
#pragma endregion library

int main(){
    int n,k;  cin >> n >> k;
    vi a(n); rep(i,n) cin >> a[i];
    rep(i,n) a[i]-=k;
    vll ac(n+1); repi(i,1,n+1) ac[i]=ac[i-1]+a[i-1];
    vll acidx = ac; sort(all(acidx));
    ll ans = 0;
    BinaryIndexedTree<int> bt(n+1);
    rep(i,n+1){
        auto it = lower_bound(all(acidx),ac[i]);
        int idx = distance(acidx.begin(),it);
        ans += bt.sum(idx);
        bt.add(idx,1);
    }
    cout << ans << '\n';
    

}

Measured memory_bytes: 7948
from collections import defaultdict
s = input()
lens = len(s)
"""
1, 10, 100～900に対して13で割って5余るものは存在する？
"""
modl = [[] for i in range(len(s))]
modl[0] = [i for i in range(10)]
for i in range(1, len(s)):
	modl[i] = [(modl[i-1][j]*10)%13 for j in range(10)]
mod = 10**9+7

unta = defaultdict(lambda: 0)
unta[0] += 1
for i, j in enumerate(s[::-1]):
	newunta = defaultdict(lambda: 0)
	if j != "?":
		a = modl[i][int(j)]
		for k in range(13):
			newunta[(k+a)%13] = (newunta[(k+a)%13] + unta[k]) % mod
	else:
		for l in range(10):
			a = modl[i][l]
			for k in range(13):
				newunta[(k+a)%13] = (newunta[(k+a)%13] + unta[k]) % mod
	unta = newunta

print(unta[5] % mod)

Measured memory_bytes: 70320
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int N[3];
	for (int i = 0; i < 3; ++i) cin >> N[i];
	sort(N, N + 3);
	cout << N[0] * N[1] / 2;
}

Measured memory_bytes: 256
import std.algorithm;
import std.conv;
import std.stdio;
import std.string;

void main()
{
	auto ns = readln.strip;
	writeln( solve( ns ) );
}

int solve( in string ns )
{
	auto ds = ns.map!( a => a - '0' );
	auto r = ds.sum;
	
	if( 1 < r ) return r;
	else        return solve( ( ns.to!int / 2 ).to!string ) * 2;
}

unittest
{
	assert( solve( "15" ) == 6 );
	assert( solve( "100000" ) == 10 );
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <bitset>
using namespace std;

typedef long long ll;
int main() {
    int n;
    cin>>n;
    vector<ll> A(n), B(n);
    for (int i=0; i<n; ++i)
        cin>>A[i]>>B[i];
    ll ans=0, incr=0;
    for (int i=n-1; i>=0; --i) {
        A[i]+=incr;
        if (B[i]==1) continue;
        ll r=A[i]%B[i];
        if (r==0) continue;
        ll q=A[i]/B[i];
        if (!q) {
            ll t=(B[i]-A[i]);
            ans+=t;
            incr+=t;
        } else {
            ll t=(B[i]*(q+(ll)1))-A[i];
            ans+=t;
            incr+=t;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [d,s,t] <- getIntList
    let a = (d-1) `div` s + 1
    putStrLn $ if a <= t then "Yes" else "No"

Measured memory_bytes: 3716
L=int(input());S=bin(L);N=len(S)-2;print(N,N+N+S.count("1")-3)
for i in range(1,N):
 x=i-1;print(i,-~i,1<<x,i,-~i,0)
 if int(S[-i]):L^=1<<x;print(i,N,L)


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  string s;
  cin >> s;
  int n = s.size();
  if(n & 1){
    int res = 0;
    for(int i = n/2;i < n;i++){
      if(s[n/2] == s[i])res++;
      else break;
    }
    int res_ = 0;
    for(int i = n/2;i >= 0;i--){
      if(s[n/2] == s[i])res_++;
      else break;
    }
    cout << min(res,res_)+n/2 << endl;
  }else{
    int res = 0;
    int k = 0;
    for(int i = n/2;i < n;i++){
      if(s[i-1] == s[i])k++;
      else break;
    }
    res = n/2+k;
    k = 0;
    for(int i = n/2-1;i >= 0;i--){
      if(s[i+1] == s[i])k++;
      else break;
    }
    res = min(res,n/2+k);
    cout << res << endl;
  }




  return 0;
}

Measured memory_bytes: 3664
N = int(input())

ans = [0 for i in range(N)]

def prime(n):
    c = 2
    while 0 < c <= n**0.5:
        if n%c == 0:
            c = -1
        c += 1
    if c == 0:
        return "No"
    else:
        return "Yes"
    
cnt = 0
c = 2
while cnt < N:
    if c%5 == 2:
        if prime(c) == "Yes":
            ans[cnt] = str(c)
            cnt += 1
    c += 1
    
print(' '.join(ans))

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long modpow(long long a, long long b){
  long long ans = 1;
  while (b > 0){
    if (b % 2 == 1){
      ans = ans * a % MOD;
    }
    a = a * a % MOD;
    b /= 2;
  }
  return ans;
}
int main(){
  long long m, n;
  cin >> m >> n;
  cout << modpow(m, n) << endl;
}


Measured memory_bytes: 3088
import java.util.*;
import java.math.*;

public class Main{
    public static void main(final String[] args){
        final Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        int ans = 0;
        long q = 2;
        int e = 1;
        long div;

        while(true){
            div = (long) Math.pow(q, e);
            if(N % div == 0){
                N /= div;
                ans++;
                e++;
                continue;
            }

            while(N % q == 0){
                N /= q;
            }
            if(q == 2) q ++;
            else q += 2;
            e = 1;
            if(q * q > N) break;
        }

        if(N != 1){
            ans++;
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 35860
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,b;
	cin>>x>>b;
	int a[100+1];
	for(int i=1;i<=b;i++)
	{
		int y;
		cin>>y;
		a[y]=-1; 
	} 
	int j=0;
	for(int i=1;i<=100000;i++)
	{
		if(a[x-j]!=-1)
		{
			cout<<x-j;
			return 0;
		}
		if(a[x+j]!=-1)
		{
			cout<<x+j;
			return 0;
		}
		j++;
	}
 } 

Measured memory_bytes: 3624