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

using namespace std;

int const N = 541;

int n, m;
char ma[N][N], r[N][N], b[N][N];

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;++i){
		getchar();
		for(int j=0;j<m;++j){
			ma[i][j] = getchar();
		}
	}

	for(int i=0;i<m;++i){
		r[0][i] = '#';
		b[n-1][i] = '#';
	}
	
	bool curRed = true;
	for(int i=0;i<m;++i){
		if(curRed){
			for(int j=1;j<n-1;++j){
				r[j][i] = '#';
			}
		}else{
			for(int j=1;j<n-1;++j){
				b[j][i] = '#';
			}
		}
		curRed ^= true;
	}
	for(int i=0;i<n;++i){
		for(int j=0;j<m;++j){
			if(r[i][j] == '#' || ma[i][j] == '#'){
				printf("#");
			}else{
				printf(".");
			}
		}
		printf("\n");
	}

	printf("\n");
	for(int i=0;i<n;++i){
		for(int j=0;j<m;++j){
			if(b[i][j] == '#' || ma[i][j] == '#'){
				printf("#");
			}else{
				printf(".");
			}
		}
		printf("\n");
	}

	

	return 0;
}

Measured memory_bytes: 1536
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};


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

int N, M, Q;
int A[11];
int a[50], b[50], c[50], d[50];

int ans = 0;

void dfs(int n){
    if (n == N){
        int sum = 0;
        for (int i = 0;i < Q;i++){
            if (A[b[i]] - A[a[i]] == c[i]){
                sum += d[i];
            } 
        }

        ans = max(ans, sum);
        return;
    }

    for (int i = min(A[n], M);i <= M;i++){
        A[n+1] = i;
        dfs(n+1);
    }
}

int main(){
    cin >> N >> M >> Q;
    for(int i = 0;i < Q;i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    A[0] = 1;
    dfs(0);
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 3632
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main()
{
	auto s = readln.strip;
	auto k = readln.strip.to!int;
	
	string[] subs;
	auto delta = k - 1;
	
	foreach( letter; s.getLetterList )
	{
		for( long index = 0; index < s.length; index++ )
		{
			index = s.indexOf( letter, index );
			if( index < 0 ) break;
			
			for( auto length = 1; index + length <= s.length && length <= k; length++ )
			{
				subs ~= s[ index .. index + length ];
			}
		}
		
		subs = sort( subs ).uniq.array;
		if( delta < subs.length ) break;
		
		delta -= subs.length;
		subs = subs.init;
	}
	
	writefln( subs[ delta ] );
}



auto getLetterList( string s )
{
	dchar[] results;
	
	foreach( c; s )
	{
		results ~= c;
	}
	
	return sort( results ).uniq;
}


Measured memory_bytes: 2684
using System;
using System.Linq;

namespace ABC110
{
    class A
    {
        static void Main(string[] args)
        {
            var h = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(x => x).ToArray();
            Console.WriteLine(h[0] * 10 + h[1] + h[2]);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#include <regex>
#ifdef _DEBUG
#include "debug.h"
#endif
#define int ll
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define all(v) (v).begin(),(v).end()
#define mkpr make_pair
#define mktp make_tuple
#define tv(tp, i) get<(i)>(tp)
#define CLEAR(obj) obj = decltype(obj)()
#define var auto
#define OUT(type) type &
#define IN(type) const type &
#define self (*this)
#define in :
#define True true
#define False false
using namespace std; using int32 = int32_t; using str = string; using cstr = const str;
using ll = long long; using ull = unsigned long long; using cint = const int; using cll = const ll;
using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>;
using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using psl = pair<string, ll>;
using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>;
static const int MGN = 10; static const int ARYSZ_MAX = (int)1e7;
static const ll LINF = LLONG_MAX/2;
#ifdef int
static const int INF = LINF;
#else
static const int INF = INT_MAX/2;
#endif
static double EPS = 1e-9;
#define FASTCIN() cin.tie(0);ios::sync_with_stdio(false);
#ifdef IMPORT_SAMPLE
#define DEBUG_IMPORT(file) vs args(argv, argv+argc);str sample = make_sample(args, file);ifstream ifs(sample); cin.rdbuf(ifs.rdbuf());
#else
#define DEBUG_IMPORT(file)
#endif
static inline bool DBLEQ(double a, double b) {return abs(a - b) < EPS;}
static inline void EPR(str msg) {cerr << msg << endl;}
static inline void AST(bool exp, str msg) {if(!exp){EPR(msg);} assert(exp);}
static inline void TAST(bool exp, str msg) {if(!exp){EPR(msg);} while(!exp){}}


int32 main(int32 argc, char* argv[]) {
    FASTCIN();
    DEBUG_IMPORT("sample-1");


    int N,M; cin>>N>>M;
    vi W(N), V(N); REP(i,N) cin>>W[i]>>V[i];

    var dp = vvi(N+1, vi(M+4, 0));
    // dp[i][j] := [0,i) の品から、重さ j 以下で得られる価値の最大値

    REP(i, N) {
        REP(j, M+1) {
            if (j + W[i] <= M) { // W[i] を取れるなら
                //dp[i+1][j+W[i]] = max(dp[i+1][j+W[i]], dp[i][j] + V[i]);
                dp[i+1][j+W[i]] = dp[i][j] + V[i]; // 先の値を予め更新
            }
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]); // 予め更新されている値と直上から来るものの大きい方
        }
    }

    int ans = dp[N][M];
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
 
 
#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;
 
ll mod = 1e9 + 7ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll inf = 1ll << 60;
int n;
vector<vector<int>> tree(200010);
vector<int> gp(200010);
vector<int> parent(200010);
vector<set<int>> ntree(200010);
vector<int> color(200010);
int main(){
    vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a.at(k-1) << endl;
    return 0;
}



Measured memory_bytes: 16640
N = int(input())
inf = 10 ** 6
graph = [[] for i in range(N)]
visited = [0 for i in range(N)]
time = [[inf,inf] for i in range(N)]

for i in range(N):
  a = list(map(int,input().split()))
  a = list(map(lambda x: x - 1,a))
  k,n = a[0],a[1]
  if n >= 0:
    graph[k] = a[2:]

con = 0

def dfs(cur,par):
  #print("v",visited)
  global con
  visited[cur] = 1
  con += 1
  time[cur][0] = min(time[cur][0],con)
  #print("cur1,con1",cur,con)
  if (graph[cur] == [] or graph[cur] == [cur]):
    visited[cur] = 1
    time[cur][0] = min(con,time[cur][0])
    con += 1
    time[cur][1] = min(con,time[cur][1])
    #print("curif,conif",cur,con)
    return 
  else:
    for chi in graph[cur]:
      if visited[chi] == 0:
        dfs(chi,cur)
      if any(visited[i] == 0 for i in graph[cur]):
        continue
      else:
        con += 1
        time[cur][1] = min(con,time[cur][1])
        #print("cur2,con2",cur,con)
        return
dfs(0,-1)

if any([i == 0 for i in visited]):
  f = visited.index(0)
  dfs(f,f - 1)

for i,t in enumerate(time):
  print(i + 1 ,*t)


Measured memory_bytes: 5752
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n;
    vector<ll> a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];

    sort(all(a)), sort(all(b)), sort(all(c));

    ll count = 0;
    rep(i, n) {
        count += max(ll(lower_bound(all(a), b[i]) - a.begin()), 0ll) * max(n - (ll)(upper_bound(all(c), b[i]) - c.begin()), 0ll);
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 2560
H, W = map(int, input().split())

A = []
for i in range(H):
  A.append(list(map(int, input().split())))
  
Q = []

for i in range(H):
  if sum(A[i]) % 2 == 1 and i < H-1:
    kurikosi_flag = True
  else:
    kurikosi_flag = False
   
  for j in range(W):
    #print(i,j)
    if A[i][j] % 2 == 0:
      continue
    elif kurikosi_flag:
      Q.append([i+1, j+1, i+2, j+1])
      A[i+1][j] += 1
      kurikosi_flag = False
    elif i < H-1:
      Q.append([i+1, j+1, i+1, j+2])
      A[i][j+1] += 1
    elif j+1 < W:
      Q.append([i+1, j+1, i+1, j+2])
      A[i][j+1] += 1
      
print(len(Q))
for i in range(len(Q)):
  print(" ".join(map(str,Q[i])))

Measured memory_bytes: 30208
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int K,N; cin >> K >> N;
  int tmp=0;
  vector<int> house(N); REP(i,N) cin >> house[i];
  REP(i,N){
    tmp = max(tmp,house[i+1] - house[i]);
  }
  tmp = max(tmp,house[0]+(K - house[N-1]));
  cout << K - tmp << endl;
}

Measured memory_bytes: 4040
n=input()
for i in range(len(n)-1):
  if n[i]==n[i+1]:
    print(i+1,i+2)
    exit()
for i in range(len(n)-2):
  if n[i]==n[i+2]:
    print(i+1,i+3)
    exit()
print(-1,-1)

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

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

    int D = 0;
    int counter[100] = {};
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;

        counter[a]++;
        D = max(D, a);
    }
    // Dが奇数の場合
    int cnt = 0;
    if (D % 2 == 1) {
        if ((cnt += counter[(D + 1) / 2]) != 2) {
            cout << "Impossible" << endl;
            return 0;
        }
        for (int d = (D + 1) / 2 + 1; d <= D; d++) {
            if (counter[d] < 2) {
                cout << "Impossible" << endl;
                return 0;
            }
            cnt += counter[d];
        }
    } else {
        if ((cnt += counter[D / 2]) != 1) {
            cout << "Impossible" << endl;
            return 0;
        }
        for (int d = D / 2 + 1; d <= D; d++) {
            if (counter[d] < 2) {
                cout << "Impossible" << endl;
                return 0;
            }
            cnt += counter[d];
        }
    }
    if (cnt == N) cout << "Possible" << endl;
    else cout << "Impossible" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int N = 100;

int main(){
int M[N][N];
int n,u,v,k;

cin >> n;

for(int i = 0; i < n; i++){
  for(int j = 0;j < n; j++) M[i][j] = 0;
}

for(int i = 0;i < n;i++){
  cin  >> u >> k;
 u--;
 for(int j = 0; j < k; j++){
  cin >> v;
  v--;
  M[u][v] = 1;
  }
 }
 for(int i = 0;i < n; i++){
   for(int j = 0; j < n; j++){
   if(j)cout << " ";
   cout << M[i][j];
   }
   cout << endl;
  }
   return 0;
}

Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;
const int MAX = 10010;
int n; 
int A[2001000];
int B[2001000];
int C[MAX] = {0};

void countingSort() {
    for (int i = 1; i <= n; i++) ++C[A[i]];
    for (int i = 1; i < MAX; ++i) C[i] += C[i-1];
    for (int i = n; i > 0; --i) B[C[A[i]]] = A[i], --C[A[i]];
}
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> A[i];
    countingSort();
    for (int i = 1; i <= n ; i++) {
        if (i > 1) cout << " ";
        cout << B[i];
    }
    cout << endl;
}



Measured memory_bytes: 18752
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = list(input())
    t = list(input())
    que = deque(t)
    n = len(s)

    for i in range(n):
        if s == list(que):
            print("Yes")
            break
        a = que.popleft()
        que.append(a)
    else:
        print("No")


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3316
using System;
class p
{
  static void Main()
  {
    string[] ipt = Console.ReadLine().Split(' ');
    long A = long.Parse(ipt[0]);
    long B = long.Parse(ipt[1]);
    long max = Math.Max(A, B);
    long min = Math.Min(A, B);
    for (long i = 1; i <= min; i++) {
      if (max * i % min == 0) {
        Console.WriteLine(max * i);
        break;
      }
    }
  }
}

Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i=0; i<n; i++)
#define loop(i, j, n) for(int i=j; i<n; i++)
using namespace std;
int main()
{
	string S;
	int n, cnt=0;
	bool ans = true;

	cin >> S;
	n = S.size();

	if(S[0] != 'A'){
		ans = false;
		goto Looped;
	}

	loop(i, 2, n-1){
		if(S[i] == 'C') cnt++;
	}

	if(cnt != 1){
		ans = false;
		goto Looped;
	}
		
	loop(i, 1, n){
		if((S[i] >= 'a' && S[i] <= 'z') || S[i] == 'C'){
			;
		}else{
			ans = false;
			goto Looped;
		}
	}
Looped:
	if(ans) cout<< "AC"<<endl;
	else cout << "WA" <<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

const ll MOD = 998244353;

ll modpow(ll x, ll n, ll m){
    ll res = 1, r = x;
    while(n){
        if(n % 2) res = res * r % m;
        r = r * r % m;
        n /= 2;
    }
    return res;
}

ll primroot(ll m, int inv = 0){
    if(!inv){
        if (m == 2) return 1;
        if (m == 167772161) return 3;
        if (m == 469762049) return 3;
        if (m == 754974721) return 11;
        if (m == 998244353) return 3;
    }
    else{
        if (m == 2) return 1;
        if (m == 167772161) return 55924054;
        if (m == 469762049) return 156587350;
        if (m == 754974721) return 617706590;
        if (m == 998244353) return 332748118;
    }
    return -1;
}

vector<ll> NTT(const vector<ll> &f, int k, const ll &m, ll *z){
    if(k == 0){
        return f;
    }
    vector<ll> f0(1 << (k - 1)), f1(1 << (k - 1));
    for(int i = 0; i < (1 << (k - 1)); i++){
        f0[i] = f[i * 2];
        f1[i] = f[i * 2 + 1];
    }
    vector<ll> Ff0 = NTT(f0, k - 1, m, z), Ff1 = NTT(f1, k - 1, m, z);
    vector<ll> Ff(1 << k);
    ll zz = 1;
    for(int i = 0; i < (1 << k); i++){
        Ff[i] = (Ff0[i & ((1 << (k - 1)) - 1)] + zz * Ff1[i & ((1 << (k - 1)) - 1)]) % m;
        zz = zz * z[k] % m;
    }
    return Ff;
}

vector<ll> Convolution(vector<ll> a, vector<ll> b, const ll m){
    int k = 0;
    while((1 << k) < (int)a.size() + (int)b.size() - 1) k++;
    ll z[2][30];
    for(int j = 0; j < 2; j++){
        for(int i = 0; i <= k; i++){
            z[j][i] = modpow(primroot(m, j), m / (1 << i), m);
        }
    }
    a.resize(1 << k);
    b.resize(1 << k);
    vector<ll> Fa = NTT(a, k, m, z[0]), Fb = NTT(b, k, m, z[0]);
    vector<ll> Fc(1 << k);
    for(int i = 0; i < (1 << k); i++) Fc[i] = Fa[i] * Fb[i] % m;
    vector<ll> c = NTT(Fc, k, m, z[1]);
    ll r = modpow((1 << k), m - 2, m);
    for(int i = 0; i < (1 << k); i++) c[i] = c[i] * r % m;
    return c;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<ll> a(n), b(m);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];
    vector<ll> c = Convolution(a, b, 998244353);
    for(int i = 0; i < n + m - 1; i++) cout << c[i] << " ";
    cout << endl;
}


Measured memory_bytes: 85092
N = int(input())
S = input()

ans = 0
for i in range(N-1):
    a = [0]*26
    b = [0]*26
    for j in S[0:i+1]:
        if a[ord(j)-ord('a')]==0:
            a[ord(j)-ord('a')]=1
    for j in S[i+1:N]:
        if b[ord(j)-ord('a')]==0:
            b[ord(j)-ord('a')]=1
    subans = 0    
    for i in range(26):
        if a[i]*b[i]==1:
            subans+=1
    ans = max(ans,subans)
    
print(ans)

Measured memory_bytes: 9100
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        sc.close();

        int cnt = k;
        for (int i = 1; i < n; i++) {
            cnt *= (k - 1);
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 9680
#include <iostream>
#include <assert.h>
#include <vector>
#include <algorithm>
//#include <functional>
#include <set>
//#include <cmath>
//#include <queue>

int main(){
    int32_t N;
    std::cin >> N;

    std::vector<int32_t> A(N);
    for(auto& i : A){
        std::cin >> i;
    }

    // naiive: detect ascending sequence for each Ai?
    // Greedy: start from An and search max j where Aj < An. repeat to A0
    //  - delete from the queue? -> high deletion cost and O(N^2)
    //  -> not feasible where N = 10^5
    // building buckets with the minimux val so far
    //  if next item > every min -> new bucket
    //  if next item < mina && next item < minb -> attach to mina (where  mina < minb)
    //  to avoid bucket check every time, hold max val and min pointer 
    //std::priority_queue<int32_t, std::vector<int32_t>, std::greater<int32_t>> colour_que;
    //std::vector<int32_t> colour_que;
    std::multiset<int32_t> colour_que;
    for(int32_t i = A.size() -1; i >= 0; i--){
        auto it = colour_que.upper_bound(A[i]);
        if(it != colour_que.end()){
            //std::cout << "colour update from: " << *it << " to " << A[i] << std::endl;
            colour_que.erase(it);
        }
        colour_que.insert(A[i]);
        //for(auto& q : colour_que){
        //    std::cout << "i:pqs " << i << ":" << q << std::endl;
        //}
    }
    std::cout << colour_que.size();

    return 0;
}


Measured memory_bytes: 5376
module Main where

import Control.Applicative
import Numeric

main :: IO ()
main = do
  { _  <- getInts
  ; xs <- getInts
  ; putInts (reverse xs)
  }

--

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn  .  unwords .  map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""



Measured memory_bytes: 4240
#include <cstdio>
#include <queue>

using namespace std;

typedef pair<int, int> P;
const int MAX_N = 1010;
const int INF = 0x3f3f3f3f;

int H, W, N;
char M[MAX_N][MAX_N];

int si[10], sj[10];
int di[4] = {-1, 0, 1, 0}, dj[4] = {0, 1, 0, -1};
int d[MAX_N][MAX_N];

int bfs(int m) {
  queue<P> que;
  for (int i = 1; i <= H; i++)
    for (int j = 1; j <= W; j++) d[i][j] = INF;
  d[si[m]][sj[m]] = 0;
  que.push(P(si[m], sj[m]));
  while (!que.empty()) {
    P p = que.front();
    que.pop();
    if (p.first == si[m + 1] && p.second == sj[m + 1]) break;
    for (int i = 0; i < 4; i++) {
      int ni = p.first + di[i], nj = p.second + dj[i];
      if (0 < ni && ni <= H && 0 < nj && nj <= W && M[ni][nj] != 'X' &&
          d[ni][nj] == INF) {
        que.push(P(ni, nj));
        d[ni][nj] = d[p.first][p.second] + 1;
      }
    }
  }
  return d[si[m + 1]][sj[m + 1]];
}

int main() {
  scanf("%d%d%d", &H, &W, &N);
  for (int i = 1; i <= H; i++) {
    char c;
    for (int j = 1; j <= W; j++) {
      do {
        c = getchar();
      } while (c == '\n' || c == ' ');
      if (c == 'S') {
        si[0] = i;
        sj[0] = j;
        c = '.';
      } else if (c >= '1' && c <= N + '0') {
        si[c - '0'] = i;
        sj[c - '0'] = j;
        c = '.';
      }
      M[i][j] = c;
    }
  }
  //   for (int i = 1; i <= H; i++) {
  //     for (int j = 1; j <= W; j++) putchar(M[i][j]);
  //     putchar('\n');
  //   }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += bfs(i);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 7544
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

class UnionFind(object):
    def __init__(self, N):
        self.parent = [-1] * N #parent[i] は(i+1)番目の要素が含まれる要素数の(-1)倍
    #要素が負-->その数を親とするグループに属する要素の数×(-1)
    #要素が正-->親のindex

    #Aがどのグループに属しているかを調べる
    def root(self, A):
        if self.parent[A-1] < 0: #負の数-->その数は親
            return A
        self.parent[A-1] = self.root(self.parent[A-1]) #負では無い時、親の場所が入っているから、親が属しているグループを、自分自身に入れる(一度確認したところは直接親を見れるようにする)
        return self.parent[A-1] #親の位置を返す

    #Aが含まれているグループに属している数を返す
    def size(self, A):
        return -1 * self.parent[self.root(A)-1]

    #AとBをくっ付ける
    def connect(self, A, B):
        A = self.root(A) #Aを含むグループの親を返す
        B = self.root(B) #Bを含むグループの親を返す
        if A == B: #親が同じならなにもしない
            return False
        
        #大きい方(A)に小さい方(B)をつなぎたい
        if self.size(A) < self.size(B): #大小関係が逆の時は入れ替える
            A, B = B, A
        
        self.parent[A-1] += self.parent[B-1] #大きい方に小さい方を加える　（負の数＋負の数 = 新しいグループに含まれる数×(-1)）
        self.parent[B-1] = A #加えられた親の値を、加えた先の親の位置に書き変える
        return True
    
    def same(self, A, B):
        if self.root(A) == self.root(B):
            return True
        else:
            return False


N, M = map(int, input().split())

uni = UnionFind(N)
for _ in range(M):
    a, b = map(int, input().split())
    uni.connect(a, b)

group1 = uni.size(1)
group2 = uni.size(2)

other = 0 #どっちとも繋がっていない頂点の数
for i in range(3, N + 1):
    # print ('親', uni.root(i))
    if (uni.same(1, i)):
        continue
    if (uni.same(2, i)):
        continue
    other += 1

#片方に固めたほうが良い？
if group1 < group2:
    group2 += other
else:
    group1 += other

# print (group1, group2)
ans = group1 * (group1 - 1) // 2 + group2 * (group2 - 1) // 2 - M
print (ans)
# print (uni.parent)

Measured memory_bytes: 5340
fn main() {
    let n: i32 = read_line_as_value();
    println!("{}", n.pow(3));
}

fn read_line_as_value<T: std::str::FromStr>() -> T {
    let mut input = String::new();
    let res = std::io::stdin().read_line(&mut input);
    if let Err(error) = res {
        panic!("io error at stdin.read_line: {}", error);
    };
    match input.trim().parse() {
        Ok(val) => val,
        _ => panic!("error while parsing input: {}", input)
    }
}

Measured memory_bytes: 2096
N,M = map(int,input().split())
INF = float('inf')
es = [tuple(map(int,input().split())) for i in range(M)]

ds = [INF] * N
ds[0] = 0

for i in range(N):
    for a,b,c in es:
        a,b,c = a-1,b-1,-c
        if ds[a] != INF and ds[b] > ds[a] + c:
            ds[b] = ds[a] + c
            if i == N-1 and b == N-1:
                print('inf')
                exit()
print(-ds[-1])


Measured memory_bytes: 3308
<?php
fscanf(STDIN, "%d %d %d", $a, $b, $c);
$input = array($a, $b, $c);
$result = false;
$target = array(5, 5, 7);
foreach ($input as $data) {
    $index = array_search($data, $target);
    if ($index === false) {
        echo 'NO';
        exit;
    }
    unset($target[$index]);
}
if (empty($target)) {
    echo 'YES';
} else {
    echo 'NO';
}
?>

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

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

    int n;
    cin >> n;

    int d, c, b, a;
    a = n%10;
    n /= 10;

    b = n%10;
    n /= 10;

    c = n%10;
    n /= 10;

    d = n%10;
    
    if((a==b && b==c) || (b==c && c==d)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

typedef long long ll;

int N;
int arr[100005];
int dp[100005];
const int INF=1e9;
int solve(int i)
{
    int &ret=dp[i];
    if(ret!=-1)return ret;
    if(i==N-1)return 0;
    if(i>=N)return INF;
    if(i+1<N)ret=solve(i+1)+abs(arr[i+1]-arr[i]);
    if(i+2<N)ret=min(ret,solve(i+2)+abs(arr[i+2]-arr[i]));
    return ret;
}

int main()
{
    cin>>N;
    for(int i=0;i<N;i++)
        cin>>arr[i];
    memset(dp,-1,sizeof(dp));
    cout<<solve(0);
}


Measured memory_bytes: 4096
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
struct Main {
    n: usize,
    m: usize,
    x: usize,
    prices: Vec<usize>,
    points: Vec<Vec<usize>>,
    min: Option<usize>,
}

#[allow(dead_code)]
impl Main {
    fn rec(&mut self, ptn: Vec<bool>) {
        if ptn.len() == self.n {
            let mut my_price: usize = 0;
            let mut my_points = vec![0; self.m];
            for (i, v) in ptn.iter().enumerate() {
                if *v {
                    my_price += self.prices[i];
                    for (j, w) in self.points[i].iter().enumerate() {
                        my_points[j] += *w;
                    }
                }
            }
            let mut ok = true;
            for v in my_points.iter() {
                if *v < self.x {
                    ok = false;
                }
            }
            if ok {
                match self.min {
                    None => {
                        self.min = Some(my_price);
                    }
                    Some(min) => {
                        if my_price < min {
                            self.min = Some(my_price);
                        }
                    }
                }
            }
            return;
        }
        for v in vec![true, false].iter() {
            let mut new_ptn = ptn.clone();
            new_ptn.push(*v);
            self.rec(new_ptn);
        }
    }
    fn invoke(&mut self) {
        self.rec(vec![]);
        match self.min {
            None => {
                println!("-1");
            }
            Some(min) => {
                println!("{}", min);
            }
        }
    }
}

fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let x = read::<usize>();
    let mut prices = vec![0; n];
    let mut points: Vec<Vec<usize>> = vec![vec![0; m]; n];
    for i in 0..n {
        prices[i] = read::<usize>();
        for j in 0..m {
            points[i][j] = read::<usize>();
        }
    }
    Main {
        n,
        m,
        x,
        prices,
        points,
        min: None,
    }
    .invoke()
}


Measured memory_bytes: 2148
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto S = readln.chomp;
    if (N%2 == 1) {
        writeln("No");
        return;
    }
    foreach (i; 0..N/2) {
        if (S[i] != S[N/2+i]) {
            writeln("No");
            return;
        }
    }
    writeln("Yes");
}

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

char buf[1 << 20], *p1, *p2;
#define getchar() ((p1 == p2) && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++)

template<typename T>
void read(T &x) 
{
	x = 0;
	int f = 1; char c = getchar();
	while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); }
	while (isdigit(c)) { x = x * 10 + c - 48; c = getchar(); }
	x *= f;
}

const int Mod = 1e9 + 7;

inline int add(int a, int b) { return a + b >= Mod ? a + b - Mod : a + b; }
inline int sub(int a, int b) { return a - b < 0 ? a - b + Mod : a - b; }
inline int mul(int a, int b) { return 1LL * a * b % Mod; }
inline void updateA(int &a, int b) { a = add(a, b); }
inline void updateM(int &a, int b) { a = mul(a, b); }

const int MAXN = 2e5 + 9;

int fac[MAXN], inv[MAXN], ifac[MAXN];

void Call(int n) 
{
	fac[0] = 1; for (int i = 1; i <= n; ++i) fac[i] = mul(fac[i - 1], i);
	inv[1] = 1; for (int i = 2; i <= n; ++i) inv[i] = mul(sub(Mod, Mod / i), inv[Mod % i]);
	ifac[0] = 1; for (int i = 1; i <= n; ++i) ifac[i] = mul(ifac[i - 1], inv[i]);
}

int n;

struct Edge { int ver, nxt; } e[MAXN << 2];
int head[MAXN], tot = 0, Head[MAXN];

inline void Add(int x, int y) { e[++tot].ver = y, e[tot].nxt = head[x], head[x] = tot; }
inline void Add_(int x, int y) { e[++tot].ver = y, e[tot].nxt = Head[x], Head[x] = tot; }

int ans = 0;

std::vector<int> G;
bool vis[MAXN];
int edge = 0, s, t;
void GetLoop(int x, int Fa) 
{
	G.push_back(x);
	vis[x] = true;
	for (int i = head[x]; i; ++edge, i = e[i].nxt)
	{
		int y = e[i].ver;
		if (!vis[y]) GetLoop(y, x);
		else if (y != Fa)
			s = x, t = y;
	}
}

int pr[MAXN];
void GetPr(int x) 
{
	for (int i = head[x]; i; i = e[i].nxt) 
	{
		int y = e[i].ver;
		if (y == pr[x] || y == s) continue;
		pr[y] = x;
		GetPr(y);
	}
}

int deg[MAXN];
void Build()
{
	for (auto x : G)
		for (int i = head[x]; i; i = e[i].nxt) 	
		{
			int y = e[i].ver;
			if (y < pr[x]) Add_(x, y), ++deg[y];
			// 令每个点认领它的入边
			// 按照限制关系建边 
		}
}

int sz[MAXN];
void Dfs(int x) 
{
	sz[x] = 1;
	for (int i = Head[x]; i; i = e[i].nxt)
	{
		int y = e[i].ver;
		if (y == pr[x]) continue;
		Dfs(y);
		sz[x] += sz[y];
	}
}

int Calc() 
{
	for (auto i : G)
		Head[i] = deg[i] = 0;
	
	int res = fac[G.size()];
	
	pr[s] = t;
	GetPr(s);
	Build();

	for (auto i : G)
		if (!deg[i])
			Dfs(i);
	for (auto i : G) 
		updateM(res, inv[sz[i]]);
		
	return res;
}

int main() 
{
	read(n);
	for (int i = 1; i <= n << 1; ++i)
	{
		int x, y;
		read(x), read(y);
		Add(x, y + n), Add(y + n, x); 
	}

	n <<= 1; 
	Call(n);

	ans = fac[n];

	for (int i = 1; i <= n; ++i) 
		if (!vis[i])
		{
			GetLoop(i, 0);
			if (G.size() << 1 != edge) { ans = 0; break; } // 是否是基环树 
			updateM(ans, ifac[G.size()]);
			int res = 0;
			updateA(res, Calc());
			std::swap(s, t); // 换个方向 
			updateA(res, Calc());
			updateM(ans, res);
	
			G.clear();
			edge = 0;
		}

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

	return 0;
}

Measured memory_bytes: 17396
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    n = int(readline())
    act = []
    for _ in range(n):
        a, b, c = map(int, readline().split())
        act.append((a, b, c))

    #dp[i][j]:= 太郎くんがi日目に活動jを行って得る幸福度の総和の最大値

    dp = [[0, 0, 0] for _ in range(n)]
    for j in range(3):
        dp[0][j] = act[0][j]

    for i in range(n-1):
        dp[i+1][0] = max(dp[i][1]+act[i+1][0], dp[i][2]+act[i+1][0])
        dp[i+1][1] = max(dp[i][0]+act[i+1][1], dp[i][2]+act[i+1][1]) 
        dp[i+1][2] = max(dp[i][0]+act[i+1][2], dp[i][1]+act[i+1][2])

    print(max(dp[n-1]))
if __name__ == '__main__':
    main()


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

void rotate_s(int (*dice)[4]){
	swap(dice[0][1], dice[1][1]);
	swap(dice[0][1], dice[2][1]);
	swap(dice[0][1], dice[1][3]);
}

void rotate_n (int (*dice)[4]){
	swap(dice[0][1], dice[1][1]);
	swap(dice[1][1], dice[2][1]);
	swap(dice[2][1], dice[1][3]);
}

void rotate_e (int (*dice)[4]){
	swap(dice[0][1], dice[1][0]);
	swap(dice[1][2], dice[2][1]);
	swap(dice[1][0], dice[1][2]);
}

void rotate_w (int (*dice)[4]){
	swap(dice[0][1], dice[1][2]);
	swap(dice[1][0], dice[2][1]);
	swap(dice[1][0], dice[1][2]);
}

bool compare_dice(int (*dice1)[4], int (*dice2)[4]){
    if(dice1[0][1] == dice2[0][1] && dice1[1][1] == dice2[1][1] && dice1[1][2] == dice2[1][2] && dice1[1][0] == dice2[1][0] && dice1[1][3] == dice2[1][3] && dice1[2][1] == dice2[2][1]){
        return true;
    }
    return false;
}

bool judge(int (*dice1)[4], int (*dice2)[4]){
    string command = "NSNNNWNNNWNNNENNNENNNWNNN";
    bool hit = false;

    for(int i = 0; i < command.size(); i++){
		switch (command[i])
		{
		case 'E':
			rotate_e(dice2);
            hit = compare_dice(dice1, dice2);
			break;
		case 'W':
			rotate_w(dice2);
            hit = compare_dice(dice1, dice2);
			break;
		case 'N':
			rotate_n(dice2);
            hit = compare_dice(dice1, dice2);
			break;
		case 'S':
			rotate_s(dice2);
            hit = compare_dice(dice1, dice2);
			break;
		default:
			break;
		}
        if(hit) return true;
	}
    return false;
}

int main() {
    int n;
    bool is_same = false;

    cin.tie(0);
    ios::sync_with_stdio(0);

	cin >> n;

    int dices[n][3][4];

    for (int i = 0; i < n; i++){
        cin >> dices[i][0][1] >> dices[i][1][1] >> dices[i][1][2] >> dices[i][1][0] >> dices[i][1][3] >> dices[i][2][1];
    }

    for (int i = 0; i < n - 1; i++){
        for (int j = 1; i + j < n; j++){
            if(judge(dices[i], dices[i + j])){
                is_same = true;
                break;
            }
        }
    }

    if(!is_same) cout << "Yes" << endl;
    else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3232
#include <stdio.h>

int main(void)
{
    char S[20];

    scanf("%s",S);

    if(S[0] == 'S' && S[1] == 'U'){
        printf("7\n");
    } else if(S[0] == 'M'){
        printf("6\n");
    } else if(S[0] == 'T' && S[1] == 'U'){
        printf("5\n");
    } else if(S[0] == 'W'){
        printf("4\n");
    } else if(S[1] == 'H'){
        printf("3\n");
    } else if(S[0] == 'F'){
        printf("2\n");
    } else {
        printf("1\n");
    }

    return 0;
}

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

using namespace std;

using int64 = long long;

bool ask(int x)
{
  cout << x << endl;
  string s;
  cin >> s;
  if(s[0] == 'V') exit(0);
  return (s[0] == 'M');
}

int main()
{
  int N;
  cin >> N;
  int low = 1, high = N - 1;
  auto L = ask(0);
  while(true) {
    int mid = (low + high) / 2;
    auto M = ask(mid);
    if((mid - low) % 2 == 1) {
      if(L == M) {
        low = mid + 1;
        L = M;
      } else {
        high = mid - 1;
      }
    } else {
      if(L != M) {
        low = mid + 1;
        L = M;
      } else {
        high = mid - 1;
      }
    }
  }
}



Measured memory_bytes: 852
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
R = p[0:X]
G = q[0:Y]
eat = R + G
eat += r
eat.sort(reverse = True)
eat = eat[0:X + Y]
print(sum(eat))


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

int main() {
    ll n, max_num, num, ans;
    cin >> n;
    vector<ll> v(n);
    max_num = 1000000007;
    for (int i=0; i<n; i++) {
        cin >> v[i];
        num += v[i];
        num %= max_num;
    }
    
    ans = 0;
    rep(i,n-1){
        num -= v[i];
        if (num < 0) num += max_num;
        ans += v[i] * num;
        ans %= max_num;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4844
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int n,a,b,c; cin>>n>>a>>b>>c;
    int cd,bd,ad,ans=inf,m=1,cnt;
    vector<int> l(n,0);
    rep(i,n) cin>>l[i];
    rep(i,n) m*=4;
    rep(i,m){
        cnt=0;
        cd=0; bd=0; ad=0; 
        int p=i;
        rep(i,n){
            if(p%4==0){
                if(cd>0) cnt+=10;
                cd+=l[i];
            }
            else if(p%4==1){
                if(bd>0) cnt+=10;
                bd+=l[i];
            }
            else if(p%4==2){
                if(ad>0) cnt+=10;
                ad+=l[i];
            }
            p/=4;
        }
        cnt+=abs(cd-c)+abs(bd-b)+abs(ad-a);
        if(cd!=0 && bd!=0 && ad!=0)
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n,q = map(int, input().split())
s = input()

count_seq = [0]*n

for i in range(n-1):
  if s[i:i+2] == 'AC':
    count_seq[i+1] = 1

for i in range(n-1):
  count_seq[i+1] = count_seq[i+1] + count_seq[i]
  
for _ in range(q):
  l,r = map(int, input().split())
  print(count_seq[r-1]-count_seq[l-1])

Measured memory_bytes: 7748
#include<bits/stdc++.h>
#define  ll   long long int
#define  sz   300010

using namespace std;


ll tani(ll n,ll p)
{
    ll a,b,i,d,x,k;

    d=0;

    while(n>0)
    {
        d+=(n%p);
        n=n/p;
    }


    return d;
}

int main()
{

     ll n,i,j,k,a,b,x,y,d,mn=10000000000;

     cin>>n;

     for(i=0;i<=n;i++)
     {
         a=i;
         b=n-i;

         a=tani(a,6);
         b=tani(b,9);

         x=a+b;
         mn=min(mn,x);
     }

     cout<<mn<<endl;

    return 0;
}



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

int main()
{
    string s;
    cin >> s;
    
    int ans = 0;
    for(int i = 0, j = s.length() - 1; i < j; i++, j--) {
        if(s[i] != s[j]) {
            ans++;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
ans = 0
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


mod = 10**9+7
N = 500001
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


for i in range(n+1):
    ans += pow(-1, i) * cmb(n, i, mod) * g1[m-i]*g2[m-n]
    ans %= mod

ans *= g1[m]*g2[m-n]
ans %= mod
print(ans)


Measured memory_bytes: 162904
#include<algorithm>
#include<cstdio>
#include<cstring>
#define N 2000002
using namespace std;
char a[N],b[N];int c[N],d[N],e,f,i,j,k,l,m,n,o[N],p[N],q,r,s,t;
int main()
{
    scanf("%d%d%d%s%s",&m,&n,&k,a+1,b+1),reverse(a+1,a+m+1),reverse(b+1,b+n+1),*o=*p=1000000000;
    for(i=m,j=n;i||j;)
    if(i<j)for(p[++t]=j--;b[j]==48;j--);
    else if(j<i)for(o[++s]=i--;a[i]==48;i--);
    else if(i==j)
    {
        for(l=i,q=k;;)
        if(o[s]<p[t])
        {
            if(l+q<o[s])
            {
                o[++s]=p[++t]=l+q;
                break;
            }
            for(q-=o[s]-l,l=o[s],d[++f]=l;o[s]==l;s--)l++;
            while(p[t]<l)d[++f]=p[t--];
            if(l!=p[t])
            {
                o[++s]=l;
                break;
            }
            else t--;
        }
        else
        {
            if(l+q<p[t])
            {
                o[++s]=p[++t]=l+q;
                break;
            }
            for(q-=p[t]-l,l=p[t],c[++e]=l;p[t]==l;t--)l++;
            while(o[s]<l)c[++e]=o[s--];
            if(l!=o[s])
            {
                p[++t]=l;
                break;
            }
            else s--;
        }
        while(e)o[++s]=c[e--];
        while(f)p[++t]=d[f--];
        while(a[--i]==48);
        while(b[--j]==48);
    }
    for(memset(a,48,o[1]),i=1;i<=s;i++)a[o[i]]=49;
    for(memset(b,48,p[1]),i=1;i<=t;i++)b[p[i]]=49;
    reverse(a+1,a+o[1]+1),reverse(b+1,b+p[1]+1),printf("%s\n%s\n",a+1,b+1);
    return 0;
}

Measured memory_bytes: 18304
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define PI  3.14159265358979323846
#define lp(i,n) for(int i = 0; i <n;i++)
#define range1(i,a,b,c) for(int i = int(a);i <= int(b);i+=int(c))
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define fr first
#define sc second
#define sz(v) ((int)((v).size()))
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef pair<int, int> pii;
template<class T> using ordered_set=tree<T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;
const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)2e5;
int dx[] = {0,0,-1,1};
int dy[] = {1,-1,0,0};
void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int val[26];
int bits[100][33];
int freq[33];
int a[N];
int power(int n,int p){
    if(p==0)return 1;
    int sq = power(n,p/2);
    sq =sq*sq;
    if(p&1)sq=sq*n;
    return sq;
}
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int n;
    scanf("%d",&n);
    int x=0;
    lp(i,n){
        scanf("%d",&a[i]);
        x^=a[i];
    }  
    // cout<<x<<endl;
    lp(i,n){
        printf("%d ",a[i]^x);        
    }
    return 0;
}

Measured memory_bytes: 4496
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        int x = Integer.parseInt(br.readLine());
        int count500 = x / 500;
        int count5 = x % 500 / 5;
        
        out.println(1000 * count500 + 5 * count5);
        
        out.close();
        
    }
}

Measured memory_bytes: 32752
package main

import (
  "fmt"
)

func pow(args ...int) int {
  x, y := args[0], args[1]
  res := 1
  if len(args) == 3 {
    mod := args[2]
    for y != 0 {
      if y & 1 == 1 {res = res * x % mod}
      y >>= 1
      x = x * x % mod
    }
  }  else {
    for y != 0 {
      if y & 1 == 1 {res *= x}
      y >>= 1
      x *= x
    }
  }
  return res
}

func main() {
  var d, n int 
  fmt.Scan(&d, &n)
  if n == 100 {
    fmt.Println(pow(100, d) * 101)
  } else {
    fmt.Println(pow(100, d) * n)
  }

}

Measured memory_bytes: 512
#include <iostream>
#include <cstdlib>
#include <vector>
//shellSort(A, n) は、一定の間隔 g だけ離れた要素のみを対象とした挿入ソートである insertionSort(A, n, g) を、最初は大きい値から g を狭めながら繰り返します。これをシェルソートと言います。
//上の疑似コードの ? を埋めてこのプログラムを完成させてください。n と数列 A が与えられるので、疑似コード中の m、m 個の整数 Gi(i=0,1,...,m－1)、入力 Aを昇順にした列を出力するプログラムを作成してください。ただし、出力は以下の条件を満 たす必要があります。


using namespace std;
int cnt = 0;
vector<int> G;
int c = 0;
void insertionSort(int A[], int n, int g){
	for(int i = g; i < n; i++){
		int v = A[i];
		int j = i - g;
		while(j >= 0 && A[j] > v){
			A[j + g] = A[j];
			j -= g;
			cnt++;
		}
		A[j + g] = v;
	}
}
void shellSort(int A[], int n){
	int h = 1;
	do{
		G.push_back(h);
		h = 3 * h + 1;
		c++;
	}while(h < n);
	for(int i = c - 1; i >= 0; i--) insertionSort(A, n, G[i]); 
}
int main(){
	int n;
	cin >> n;
	int A[n];
	for(int i = 0; i < n; i++) cin >> A[i];
	shellSort(A, n);
	cout << c << '\n';
	
	for(int i = c - 1; i >= 0; i--){
		cout << G[i]; 
		if(i != n - 1) cout << ' ';
	}
	cout << '\n';
	cout << cnt << '\n';
	for(int i = 0; i < n; i++) cout << A[i] << endl;
}




Measured memory_bytes: 7016
#include<stdio.h>


#define L 100


int main(){
  int M[L][L];
  int n,u,k,v,i,j;

  scanf("%d",&n);

  for(i = 0;i<n;i++){
    for(j = 0;j<n;j++)
      M[i][j] = 0;
  }

  for(i = 0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j = 0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  for(i = 0;i<n;i++){
    for(j = 0;j<n;j++){
      if(j >0)printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }
  

  return 0;
}



Measured memory_bytes: 2068
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(a,i,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,-1,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);   
}
int main()
{

   // fopen();
    fastio;
    map<string,int>m;
    int n;
    cin>>n;
    string s;
    rep(i,n)
    {
        cin>>s;
        m[s]+=1;
    }
    int k=0;
    trav(a,m)
    {
        if(a.S>k)
        {
            k=a.S;
        }
    }
    vector<string>w;
    trav(a,m)
    {
        if(a.S==k)
        {
            w.pb(a.F);
        }
    }
    sort(w.begin(),w.end());
    trav(a,w)
    {
        cout<<a<<endl;
    }
}


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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int s = 0;
  for (int i = 1; i <= N; i++) {
    int c = 0; int n = i;
    while (n > 0) {
      c += n%10;
      n /= 10;
    }
    if (c >= A && c <= B)
      s += i;
  }
  cout << s << endl;
}


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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long> VLL;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
/*--------------------------------------------*/
int n;
V take(3+1);
V l(8+1);//l[i]の竹をAで使うか，Bで使うか，Cで使うか，使わないかの全探索
//その都度合成していき最後に伸ばしたり縮めたりして調整
//4^8=66536通り
int ans=INF;
int tmp;
int dfs(int depth,V use){
    if(depth==n){//0~n-1までの竹,A,B,C,Xのどれに使うかがuseに格納されている
        V flag(4,0);
        rep(i,n){
            REP(j,3){
                if(use[i]==j)flag[j]=1;
            }
        }REP(j,3){
            if(flag[j]==0)return INF;//A,B,Cに一本も使われていないことはない
        }    
        V length(3,0);//0index
        rep(i,n){
            REP(j,3){//a...j=1
                if(use[i]==j)length[j-1]+=l[i];//i番目の竹をjとして利用,0indexに注
            }
        }
        tmp=0;
        rep(i,3){
            tmp+=abs(take[i]-length[i]);//延長，短縮
        }
        return tmp;
    }
    use[depth]=0;
    //not use
    int res=dfs(depth+1,use);
    //use
    REP(i,3){
        use[depth]=i;
        res=min(dfs(depth+1,use)+10,res);
    }
    return res;
}
int main(){
    cin>>n;rep(i,3){cin>>take[i];}
    rep(i,n){cin>>l[i];}
    V use(9);
    cout<<dfs(0,use)-30<<endl;//無邪気に使用する竹全てに合成魔法使っているので,30引け
}


Measured memory_bytes: 256
n,m = map(int,input().split())
ps = [list(input().split()) for _ in range(m)]

li = ['WA'] * n
countwa = [0] * n
ac = 0
wa = 0

for p,s in ps:
    if s == 'AC':
        if li[int(p)-1] == 'WA':
            li[int(p)-1] = 'AC'
            ac += 1
    else:
        if li[int(p)-1] == 'WA':
            countwa[int(p)-1] += 1

ac = li.count('AC')
for i in range(n):
    if li[i] == 'AC':
        wa += countwa[i]

print(ac, wa)


Measured memory_bytes: 27456
#pragma GCC optimize ("-O3")
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define f(i,x,n) for(ll i=x;i<n;i++)
#define pb push_back
#define mp make_pair
#define debug(x) cout<<x<<"\n";
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
long long MOD=pow(10,9)+7;

int main() {
	
	int t;
	t=1;
	//cin >> t;
	while(t--){
     ll a,b,c,d;
     cin>>a>>b>>c>>d;
     ll ans=-1e18;
    
     
       ans=max(ans,ll(b*d));
       ans=max(ans,ll(a*c));
       if(a<=0&&b>=0||c<=0&&d>=0)
       {
       	ans=max(ans,ll(0));
	   }
	   ans=max(ans,ll(b*c));
	   ans=max(ans,ll(a*d));
	 

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

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>

int main() {
	long long x;

	std::cin >> x;

	long long a = 100;
	long long ans = 0;

	while (a < x) {
		a = a * 1.01;
		ans++;
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 3580