akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
const int MAX = 2e5;

int n; // 都市の数
ll k; // テレポート回数
int a[MAX]; // 都市iのテレポート先
bool visited[MAX]; // 訪問状況
int ans;

int main() {
// input
    cin >> n >> k;
    rep(i, n) {
        cin >> a[i];
        a[i]--; // 0-indexed
    }
// solve
    int pos = 0;
    visited[pos] = true;
    int cnt = 0;
    rep(i, n) {
        cnt++;
        pos = a[pos];
        if (visited[pos]) break;
    }
    // printf("テレポート回数%d\n", cnt);
    int loop_start = pos;
    // printf("テレポート始点%d\n", loop_start);
    if (cnt >= k) {
        pos = 0;
        rep(i, k) {
            pos = a[pos];
        }
        ans = pos;
    } else {
        pos = 0;
        rep(i, n) {
            if (pos == loop_start) break;
            pos = a[pos];
            cnt--;
            k--;
        }
        int loop_size = cnt;
        // printf("ループの大きさ%d\n", loop_size);
        pos = loop_start;
        rep(i, k%loop_size) {
            pos = a[pos];
        }
        ans = pos;
    }
// output
    ans++;
    cout << ans << "\n";
}

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

int main()
{
	cin.tie(NULL);

	int X;
	cin >> X;

	if ((X == 3) || (X == 5) || (X == 7) )
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;
ll n,l,t,x,w,ans[100005];
int main(){
    scanf("%lld%lld%lld",&n,&l,&t);
    ll p=1;
    for (int i=1; i<=n; i++){
        scanf("%lld%lld",&x,&w);
        if (w==1)
		{
            ans[i]=(x+t)%l;
            p+=(x+t)/l;
        }
		else
		{
            ans[i]=(x-t)%l;
            p+=(x-t)/l;
            if(ans[i]<0)ans[i]+=l,p--;
        }
    }
    sort(ans+1,ans+n+1);
    p=(p%n+n)%n;
    if (p==0) p=n;
    for (int i=p; i<=n; i++)
        printf("%lld\n",ans[i]);
    for (int i=1; i<=p-1; i++)
        printf("%lld\n",ans[i]);
    return 0;
}

Measured memory_bytes: 4596
#include <cstdio>
#include <algorithm>

int w[2001][2001];

int main()
{
  int n, k;
  scanf("%d%d", &n, &k);
  const int kk = 2 * k;
  int black = 0;
  for (int i = 0; i < n; ++i)
  {
    int x, y;
    char c;
    scanf("%d%d %c", &x, &y, &c);
    if (c == 'B')
    {
      w[y % kk + 1][x % kk + 1] -= 1;
      ++black;
    }
    else
    {
      w[y % kk + 1][x % kk + 1] += 1;
    }
  }

  for (int y = 1; y <= kk; ++y)
  {
    for (int x = 2; x <= kk; ++x)
    {
      w[y][x] += w[y][x - 1];
    }
  }
  for (int x = 1; x <= kk; ++x)
  {
    for (int y = 2; y <= kk; ++y)
    {
      w[y][x] += w[y - 1][x];
    }
  }
  int ans = 0;
  for (int y = 0; y < kk; ++y)
  {
    for (int x = 0; x < kk; ++x)
    {
      int X[] = {x - k, x + k, x - kk, x, x - k, x + k, x - kk, x};
      int Y[] = {y + k, y + k, y, y, y - k, y - k, y - kk, y - kk};
      int r = black;
      for (int i = 0; i < 8; ++i)
      {
        int cx = std::min(std::max(0, X[i]), kk);
        int cy = std::min(std::max(0, Y[i]), kk);
        int dx = std::min(std::max(0, X[i] + k), kk);
        int dy = std::min(std::max(0, Y[i] + k), kk);
        r += w[dy][dx] - w[cy][dx] - w[dy][cx] + w[cy][cx];
      }
      if (r > ans) ans = r;
    }
  }
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 15744
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;

int main() {
    ll N;
    cin >> N;
    vector<ll> W(N);
    ll sum = 0;
    for (auto& w : W) {
        cin >> w;
        sum += w;
    }
    ll cur = 0;
    ll res = 1e9;
    for (auto& w : W) {
        cur += w;
        res = min(res, abs(sum - 2 * cur));
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define F  first
#define S  second
#define ff(i,n) for(i=0;i<n;i++)
int main()
{ 
	ll t;
	t=1;
	while(t--)
	{
		ll i,n,cum=0;
		cin>>n;
		ll arr[n];
		ff(i,n)
		{
			cin>>arr[i];
			cum= cum^arr[i];
		}
		ff(i,n)
		{
			ll f = cum^arr[i];
			printf("%lld ",f);
		}
	}
	return 0;
}

Measured memory_bytes: 5312
#include <stdio.h>
int main()
{

    int i,h,a,b,d,c;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    i=a+b;
    h=c+d;

    if(i>h){
        printf("Left\n");
    } else if(i==h){
        printf("Balanced\n");
    }
    else{
        printf("Right\n");
    }
    return 0;
}

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005;

int main(){
    
    string S;cin>>S;
    int cnt1=0,cnt2=0,cnt3=0;
    for(int i=0;i<S.size();i++){
        if(S[i]=='a') cnt1++;
        if(S[i]=='b') cnt2++;
        if(S[i]=='c') cnt3++;
    }
    vector<int> T={cnt1,cnt2,cnt3};
    sort(all(T));
    if(T[2]-T[0]==1||T[2]-T[0]==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
}


Measured memory_bytes: 512
from itertools import accumulate
n = int(input())
A = list(map(int, input().split()))
Acum = list(accumulate(reversed(A)))
Acum.reverse()

flexibility = 1
ans = 0
for i, a in enumerate(A):
    if flexibility < a:
        print(-1)
        exit()
    ans += min(flexibility, Acum[i])
    flexibility = 2*(flexibility-a)

print(ans)


Measured memory_bytes: 20172
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
public class Main {
    public static void main(String[]args) {
        FastScanner sc=new FastScanner();
        int n=sc.nextInt(),m=sc.nextInt();
        int sum=0;
        for(int i=0;i<m;i++){
            sum+=sc.nextInt();
        }
        System.out.println(Math.max(-1,n-sum));
    }
}

//高速入力コピペ
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 33356
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>

using namespace std;

int main() {
  int N, M;
  cin >> N;
  vector<string> s(N);
  for (int i=0; i<N; i++) {
    cin >> s.at(i);
  }
  cin >> M;
  vector<string> t(M);
  for (int i=0; i<M; i++) {
    cin >> t.at(i);
  }
  int ans = 0;

  for (int i=0; i<N; i++) {
    string str = s.at(i);
    int tmp = 1;
    for (int j=0; j<N; j++) {
      if (i==j) {
        continue;
      }
      if (str == s.at(j)) {
        tmp++;
      }
    }
    for (int j=0; j<M; j++) {
      if (str == t.at(j)) {
        tmp--;
      }
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

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

testimony_list = [[] for _ in range(N)]
for i in range(N):
    Ai = int(input())
    for j in range(Ai):
        x, y = map(int, input().split(' '))
        testimony_list[i].append((x, y))

def judge(bit):
    for i in range(N):
        if not (bit & (1<<i)):
            continue
        for x, y in testimony_list[i]:
            if y == 1 and not (bit & (1<<(x-1))):
                return False
            if y == 0 and (bit & 1<<(x-1)):
                return False
    return True

max_num = 0
for bit in range(1<<N):
    res = judge(bit)
    if res == True:
        num = 0
        for i in bin(bit)[2:][::-1]:
            if int(i) == 1:
                num += 1
        max_num = max(max_num, num)
print(max_num)

Measured memory_bytes: 45148
import java.util.*;
import java.util.function.BiPredicate;
import java.util.function.BinaryOperator;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int inputD = Integer.parseInt(sc.next());
        int inputN = Integer.parseInt(sc.next());

        int[] arr = IntStream.range(1, 10000000)
                .filter(num -> calc(num,inputD)).toArray();
        System.out.println(arr[inputN -1]);
    }
    private static boolean calc(int x, int d) {
        int count = 0;
        int tmp = x;
        while (true) {
            if (tmp % 100 == 0) {
                count++;
                tmp = tmp/ 100;
            } else {
                break;
            }
        }
        if (count == d) {
            return true;
        } else {
            return false;
        }
    };
}


Measured memory_bytes: 131920
n,p=map(int,input().split())
"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
    
    
lst=factorization(p)

ans=1
for i in range(len(lst)):
    p,q=lst[i]
    while q>=n:
        q-=n
        ans=ans*p
print(ans)
        

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <random>
#include <fstream>
#include <sstream>
#include <time.h>
// #define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  ll n,m;
  cin>>n>>m;
  vector<ll> a(n);
  rep(i,n) cin>>a[i];
  sort(a.begin(), a.end());
  // rep(i,n) {
  //   debug(a[i]);
  // }
  pair<ll,ll> cb[m];
  rep(i,m) {
    cin>>cb[i].second>>cb[i].first;
  }
  sort(cb, cb+m, greater<>());
  // rep(i,m) {
  //   debug(cb[i].first);debug(cb[i].second);
  // }
  ll ans = 0;
  ll wa[n+1];
  wa[0] = 0;
  rep(i,n) {
    wa[i+1] = wa[i] + a[i];
    ans += a[i];
  }
  // rep(i,n+1) {
  //   debug(wa[i]);
  // }
  ll s = 0;
  rep(i,m) {
    ll x = cb[i].first;
    auto it = lower_bound(a.begin(),a.end(),x);
    ll num = it - a.begin()-1;
    if (num < s) continue;
    ll init = cb[i].second + s - 1;
    ll end = min(init, num);
    ans += (end-s + 1) * x - (wa[end+1]-wa[s]);
    s = end+1;
  }
  cout << ans << endl;
  




  return 0;
}


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

int main()
{
  int N; cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++) cin >> v[i];

  sort(v.begin(), v.end());

  double ans = v[0];

  for (int i = 1; i < N; i++)
  {
    ans += v[i];
    ans /= 2;
  }

  printf("%.12f\n", ans);
}

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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define f(i,a,b) for(int i=a;i<b;i++)
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd_ll(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int abs(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int fiv(int n){
  if(n==0){
    return 0;
  }
  else if(n==1){
    return 1;
  }
  return fiv(n-1)+fiv(n-2);
}
ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}
int main(){
  int n;
  cin>>  n;
  vl t(n);
  rep(i,n) cin>>t[i];
  ll ans =1;
  rep(i,n){
    ll ggcd= gcd_ll(ans,t[i]);
    ans = (max(ans,t[i])/ggcd)*min(ans,t[i]);
  }
  cout <<ans<<endl;
}



Measured memory_bytes: 256
def main():
    S = map(int, input())

    a, b = 0, 1
    for s in S:
        a, b = a + s if a + s < b + 10 - s else b + 10 - s, a + (s + 1) if a + (s + 1) < b + 10 - (s + 1) else b + 10 - (s + 1)

    print(a)


main()

Measured memory_bytes: 5492
#include <iostream>
using namespace std;
string smallchange(string a){ 
  for(int i = 0;i < a.length();i++){
    if(a[i] >= 'A' && a[i] <= 'Z'){
      a[i] = a[i] + 0x20;
    }   
  }
  return a;
}
int main(){
 std::string bun;
 int a[29] = {0};
 string c = "a";
 while(cin >> bun){
 bun = smallchange(bun);
 for(int i = 0;i < bun.length();i++){
   for(int j = 0;j < 26; j++){
     if(bun[i] == 'a'+j){
       a[j]++;
     }   
   }   
 }
 }
 for(int i = 0;i < 26;i++){
   cout << c << " : " << a[i]<< endl;
   c[0]++;
 }
}

Measured memory_bytes: 3072
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
int main(){
	string S;
	cin>>S;
	S[3]='8';
	cout<<S<<endl;
	return 0;
}

Measured memory_bytes: 768
// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include <bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                   long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0) 
#define inf                  (ll)1<<60
#define eps                  0.000000000000001
#define endl                       '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={-2,-2,1,-1,-1,-1,1,1};
int dy[8]={1,-1,-2,-2,-1,1,-1,1};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    int n,k;
    cin>>n>>k;
    vector<ll> h(n);
    f(i,n)
    {
        cin>>h[i];
    }
    vector<ll> dp(n+1,inf);
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i-1;j>=i-k;j--)
        {
            if(j>=0)
            {
                dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
            }
        }
        
    }
    cout<<dp[n-1]<<endl;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	int n;cin>>n;
	vl 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));
	vl A(n),B(n),e(n),d(n);
	rep(i,n){
		A[i]=b.end()-upper_bound(all(b),a[i]);
		B[i]=c.end()-upper_bound(all(c),b[i]);
        e[i]=upper_bound(all(b),a[i])-b.begin();
        d[i]=upper_bound(all(c),b[i])-c.begin();
	}
	ll ans=0,sum1[n+1],sum2[n+1];
	sum1[0]=0;sum2[0]=0;
	rep(i,n){
        sum1[i+1]=sum1[i]+A[i];
		sum2[i+1]=sum2[i]+B[i];
	}
    rep(i,n){
        ans+=(sum2[n]-sum2[e[i]]);
    }
	cout<<ans<<endl;
}

Measured memory_bytes: 7296
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
using namespace std;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	cout<<a[0]+a[1]<<endl;
	
	
	return 0;
}

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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;


int32_t main()
{
	GO;
	int n;
	cin >> n;
	set<string > s;
	for (int i = 0; i < n; i++) {
		string str;
		cin >> str;
		s.insert(str);
	}
	cout << s.size() << endl;
	return 0;
}

//!

Measured memory_bytes: 19144
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

void dijkstra_deque(int n, vector<edge> G[], int s, ll d[]) {
	vector<bool> vis(n, false);
	fill(d, d + n, LLONG_MAX); d[s] = 0;
	deque<ll> deq; deq.push_back(s);
	while (!deq.empty()) {
		int u = deq.front(); deq.pop_front();
		if (vis[u]) continue;
		vis[u] = true;
		for (int i = 0; i < G[u].size(); i++) {
			edge e = G[u][i];
			if (d[e.v] > d[u] + e.w) {
				d[e.v] = d[u] + e.w;
				if (e.w == 0) deq.push_front(e.v);
				else deq.push_back(e.v);
			}
		}
	}
}

vector<edge> G[100000];
ll d[100000];

int main() {
	int N; cin >> N;
	vector<int> p(N);
	for (int i = 0; i < N; i++) cin >> p[i];
	for (int i = 0; i < N; i++) {
		if (p[i] != 0) {
			edge e = {i, i + p[i], 0};
			G[i].push_back(e);
			continue;
		}
		for (int j = 1; j <= 6 && i + j < N; j++) {
			edge e = {i, i + j, 1};
			G[i].push_back(e);
		}
	}
	dijkstra_deque(N, G, 0, d);
	cout << d[N - 1] << endl;
}

Measured memory_bytes: 11300
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i,s,e) for(i=s;i<e;i++)
#define ms(arr,val) memset(arr,val,sizeof(arr))
using namespace std;

const int mxn=2e5+1;

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

  int t=1;
  //cin>>t;
  int tt=1;
  while(t--){
    int n,i,ans=1e8;
    cin>>n;
    string s;
    cin>>s;
    int left[n],right[n];
    fr(i,0,n)
    {
      left[i]=(s[i]=='#');
      if(i)
        left[i]+=left[i-1];
      
       //cout<<"Case #"<<tt<<": ";
       //tt++;
    }
    right[n-1]=(s[n-1]=='.');
    for(i=n-2;i>=0;i--)
    {
      right[i]=right[i+1];
      right[i]+=(s[i]=='.');
    }
    fr(i,0,n)
    {
      ll temp=right[i];
      temp+=left[i];
      if(s[i]=='#')
        temp--;
      ans=min(1ll*ans,temp);
      temp=left[i]+right[i];
      if(s[i]=='.')
        temp--;
      ans=min(1ll*ans,temp);
    }
    cout<<ans;
    }
  return 0;
}



Measured memory_bytes: 2196
"""
解説動画のコードを参考にしました
https://atcoder.jp/contests/abc175/submissions/15945829
"""

N,K = map(int, input().split())
*P, = map(int, input().split())
*C, = map(int, input().split())

ans = int(-1e18)

for start in P:
    pos = start
    scores = [] # スコア格納用

    while True:
        pos = P[pos-1] # 移動
        scores.append(C[pos-1]) # スコアの格納
        # 1周したかどうか
        if pos == start: break

    # 周期途中のどこでやめるか判定
    L = len(scores)
    S = sum(scores)
    period_score = 0
    for i in range(L):
        period_score += scores[i] # スコアの加算
        # 試行回数を超えていないか
        if i+1 > K: break
        total_score = period_score
        # 1周期の合計スコアが正なら、周期を重ねるごとにスコア増
        if S > 0:
            total_score += S * ((K-(i+1)) // L)
        ans = max(ans, total_score)

print(ans)


Measured memory_bytes: 80312
import math
n=int(input())
x=[]
for k in range(n-1):
  a,b,c=[int(i) for i in input().split(' ')]

  x=[max(math.ceil((j-b)/c)*c+b,b) + a for j in x]

  x.append(a+b)
x.append(0)
for i in range(n):
  print(x[i])

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a.at(i);
  int cnt = 0;
  rep(i,n){
    if(i%2==0 && a.at(i)%2==1) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i,n) for (long long i=0;i<(n);i++)
using namespace std;
template<typename V,typename Weight>
class Dijekstra {
private:
	struct edge {
		Weight dist;V node;V prev;
		bool operator<(edge const& a) const {
			return dist < a.dist;
		}
		bool operator>(edge const& a) const {
			return dist > a.dist;
		}
	};
	vector<V> trace;
	vector<vector<pair<V,Weight>>> E;
	V sz;
public:
	Weight inf = numeric_limits<Weight>::max();
	vector<Weight> D;
	Dijekstra(V v) :
		E(v),sz(v),D(v,inf),trace(v,numeric_limits<V>::max()) {}

	void addEdgeDirected(V from,V to,Weight dis){
		E[from].push_back(make_pair(to,dis));
	}
	void addEdgeUndirected(V from,V to,Weight dis){
		E[from].push_back(make_pair(to,dis));
		E[to].push_back(make_pair(from,dis));
	}

	V size() {return sz;}
	Weight & operator[] (V n) { if (0 <= n && n < sz) return D[n];} 

	void dijekstra(V start){
		priority_queue<pair<Weight,V>,vector<pair<Weight,V>>,greater<pair<Weight,V>>> que;
		D[start] = 0;
		//trace[start] = start;
		que.push(make_pair(0,start));
		Weight d;V v;
		while(!que.empty()){
			pair<Weight,V> cur = que.top();que.pop();
			d = cur.first;v = cur.second;
			if (D[v] < d) continue; //既により最適が見つかっている
			for(pair<V,Weight> e : E[v]){
				Weight newCost = d + e.second;
				if (D[e.first] > newCost) {
					D[e.first] = newCost;
					trace[e.first] = v;
					que.push(make_pair(d+e.second,e.first));
				}
				else if (D[e.first] == newCost) {
					trace[e.first] = min(trace[e.first],v);
				}
			}
		}
	}

	vector<V> show_trace(V start,V goal){ // startからgoalの最短距離上のノード
		vector<V> ret;
		for (V node = goal;node != start;node = trace[node]) ret.push_back(node);
		ret.push_back(start);
		return ret; // 配列の先頭がgoal,末尾がstart
	}
};


int main(void){
	long V,E,R;
	long s,t,d;
	cin >> V >> E >> R;
	Dijekstra<long,long> dij(V);

	REP(i,E){
		cin >> s >> t >> d;
		dij.addEdgeDirected(s,t,d);
	}

	dij.dijekstra(R);
	REP(i,V) {
		if (dij[i] == dij.inf) cout << "INF" << endl;
		else cout << dij[i] << endl;
	}
		
	return 0;
}





Measured memory_bytes: 20084
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,ans;
  double a[100005]={},b[100005]={};
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    b[i]=a[i];
  }
  sort(a,a+n);
  for(int i=0; i<n; i++) {
    ans=0;
    ans+=(lower_bound(a,a+n,b[i])-a)*3;
    ans+=(upper_bound(a,a+n,b[i])-a)-(lower_bound(a,a+n,b[i])-a)-1;
    cout << ans << "\n";
  }
}


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

using namespace std;

typedef unsigned long long int ll;

ll inf = 1e9+7;

int main()
{
    ios::sync_with_stdio(0);
    std::cin.tie(0);
    ll n;
    char c;
    cin >> n;
    vector<ll> s(n+1,0);
    for(ll i = 1; i <= n; i++)
    {
        cin >> c;
        s.at(i) = (ll)((c-'a')+1);
    }

    sort(s.begin(), s.end());

    vector<ll> dp(1e5+1,0);
    vector<ll> b(1e5+1,0);
    ll tem, tem2;

    for(ll i = 1; i <= n; i++)
    {
        tem = s[i];
        if(b.at(tem) == 0)
        {
            dp.at(i) = (2*dp.at(i-1)+1)%inf;
        }
        else
        {
            dp.at(i) = ((2*dp.at(i-1)%inf) + inf - dp.at(b.at(tem)-1) )%inf;
        }
        b.at(tem) = i;
    }


    cout << dp.at(n);





    return 0;
}


Measured memory_bytes: 2560
from math import ceil
n=int(input())
lst=[]
for i in range(n-1):
    lst.append(list(map(int,input().split())))
def neccesary_time(m):
    t=0
    for i in range(m,n-1):
        s=lst[i][1]
        if t<=s:
            t=s+lst[i][0]
        else:
            t=s+lst[i][2]*ceil((t-s)/lst[i][2])+lst[i][0]
    return t
for i in range(n-1):
    print(neccesary_time(i))
print(0)

Measured memory_bytes: 3188
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
/*

*/
int main(void){
    int x1,y1,x2,y2,x3,x4,y3,y4;
    scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
    int vx,vy,nx,ny;
    vx = x2-x1;
    vy = y2-y1;
    nx = (-1)*vy;
    ny = vx;
    x3 = x2+nx;
    y3 = y2+ny;
    printf("%d %d ",x3,y3);
    x4 = x1+nx;
    y4 = y1+ny;
    printf("%d %d\n",x4,y4);

    return 0;
}

Measured memory_bytes: 128
'use strict';
function main(input) {
  const arr = input.trim().split('\n');
  const str = arr[1];
  let count = 0;

  for (let i = 0; i < str.length - 2; i ++) {
    if (str[i] === 'A' && str[i + 1] === 'B' && str[i + 2] === 'C') {
      count ++;
    }
  }
  
  console.log(count);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7496
#include<bits/stdc++.h>
using ll = int_fast64_t;
const int MOD = 1000000007;
const int MAX = 510000;

ll fac[MAX], finv[MAX], inv[MAX];

void combinit(){
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for(int i=2; i<MAX; i++){
                fac[i] = fac[i - 1]*i % MOD;
                inv[i] = MOD - inv[MOD%i]*(MOD/i) % MOD;
                finv[i] = finv[i-1]*inv[i] % MOD;
        }
}

ll comb(ll n, ll k){
        if(n<0 or k<0) return 0;
        if(n<k) std::swap(n, k);
        return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main(){
        int h, w, a, b;
        scanf("%d %d %d %d", &h, &w, &a, &b);

        combinit();
        ll ans = 0;
        for(int i=b+1; i<=w; i++){
                ans += comb(h-a+i-2, i-1) * comb(a+w-i-1, w-i) % MOD;
                ans %= MOD;
        }
        printf("%ld\n", ans);
        return 0;
}

Measured memory_bytes: 12160
#require 'pp'

class Element
    attr_reader :data, :priority

    def initialize(data, priority)
        @data, @priority = data, priority
    end

    def <=>(other)
        @priority <=> other.priority
    end
end

class PriorityQueue
    def initialize
        @entries = []
    end

    def push(element)
        i = @entries.bsearch_index {|e| e.priority >= element.priority }
        if i
            @entries.insert(i, element)
        else
            @entries.push(element)
        end
    end

    def pop
        @entries.pop
    end

    def empty?
        @entries.empty?
    end
end

n, m = gets.chomp!.split(" ").map(&:to_i)
memo = {}
n.times do |i|
    a, b = gets.chomp!.split(" ").map(&:to_i)
    memo[a] ||= []
    memo[a] << Element.new(b, b)
end

pq = PriorityQueue.new

sum = 0
1.upto(m) do |i|
    if memo[i]
        memo[i].each do |e|
            pq.push(e)
        end
    end

    next if pq.empty?
    e = pq.pop
    sum += e.data
end

puts sum


Measured memory_bytes: 20604
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

 
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
  int a,b;
  cin >> a >> b;
  cout << a+b/2;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long A,B;
        cin>>A>>B;
        long long sum=A*B;
        long long s=sqrt(sum);
        if(A!=B&&s*s==sum)
            cout<<(2*s-3);
        if(s*s==sum&&A==B&&s*(s+1)>=sum)
            cout<<(2*s-2);
        if(s*s<sum&&A!=B&&s*(s+1)>=sum)
            cout<<(2*s-2);
       else if(s*(s+1)<sum&&A!=B)
            cout<<(2*s-1);
        cout<<endl;
    }
    return 0;
}


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

int main()
{
	string s;
	cin >> s;
	vector<char> res;
	for(int i = 0; i < s.size(); i++){
		switch (s[i]){
			case '0':
			case '1':
				res.push_back(s[i]);
				break;
			case 'B':
				if(res.size() > 0)
					res.erase(res.end()-1);
				break;
			default:
				cerr << "Invalid input" << endl;
		}
	}
	for(int i = 0; i < res.size(); i++){
		cout << res[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
import sys

n, m = map(int, sys.stdin.readline().split())
A = [int(sys.stdin.readline()) for _ in range(m)]
bloken = [0 for i in range(n+1)]
for a in A:
    bloken[a]=1
    

dp = [0 for i in range(n+1)]
dp[0] =1
#print(dp)

for i in range(1, n+1):
    if bloken[i]==1:
        continue
    if i-2>=0:
        dp[i] = dp[i-1] + dp[i-2]
    else:
        dp[i] = dp[i-1]


print(dp[-1]%1000000007)

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

long long n;
int a[1010], cnt;

int main(void) {
  scanf("%lld", &n);
  deque<int> q;
  int m = 0;
  n++;
  while((1LL << m) <= n) m++;
  m -= 2;
  while(~m) {
    q.push_back(++cnt);
    if(n >> m & 1) q.push_front(++cnt);
    m--;
  }
  int now = 0;
  while(!q.empty()) {
    a[++now] = q.front(); q.pop_front();
  }
  cout << now * 2 << endl;
  for(int i = 1; i <= now; i++)
    a[now + i] = i;
  for(int i = 1; i <= now * 2; i++)
    cout << a[i] << " ";
  cout << endl;
  return 0;
}


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

int main(int argc, char *argv[]){
  int N;
  cin>>N;
  vector<long long> A(N,0);
  for(int i=0; i<N; i++){
    int a; cin>>a;
    A[a]++;
  }
  if(N%2==0){
    if(A[0]!=0){
      cout<<0<<endl;
      return 0;
    }
  }
  else{
    if(A[0]!=1){
      cout<<0<<endl;
      return 0;
    }
  }
  
  for(int i=1; i<N; i++){
    if(A[i]==0) continue;
    else if(N%2==0){
      if(A[i]!=2){
	cout<<0<<endl;
	return 0;
      }
    }
    else{
      if(A[i]!=2){
	cout<<0<<endl;
	return 0;
      }
    }
  }

  long long ans=1;
  for(int i=0; i<N/2; i++){
    ans=(ans*2)%1000000007;
  }
  cout<<ans<<endl;
}







  


Measured memory_bytes: 1024
#include<iostream>
#include<string>

using namespace std;

int main(){
    while(1){    
        int n;
        cin >>n;
        if(n==0)break;
        string s;
        int l=0,r=0;
        int ans=0;
        bool f=0;
        for(int i=0;i<n;i++){
            cin>>s;
            if(s=="lu"&&l==0)l++;
            if(s=="ld"&&l==1)l--;
            if(s=="ru"&&r==0)r++;
            if(s=="rd"&&r==1)r--;
            if(l==r&&l!=f){
                ans++;
                f=!f;
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3112
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<10)
#define LLINF (1LL<<60)
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  ll a[200005];
  ll dp[200005][2];

  cin>>n;
  for(int i=1;i<=n;i++)cin>>a[i];
  for(int i=0;i<=n;i++){
    for(int j=0;j<3;j++)dp[i][j]=-LLINF;
  }

  for(int i=1;i<=n;i++){
    if(i==1){
      dp[1][0]=0;
      dp[1][1]=a[i];
    }
    else if(i==2){
      dp[2][0]=0;
      dp[2][1]=max(dp[1][1],a[2]);
    }
    else{
      if(i%2==1){
        dp[i][0]=max(dp[i-1][1],dp[i-2][0]+a[i]);
        dp[i][1]=dp[i-2][1]+a[i];
      }
      else{
        dp[i][0]=max(dp[i-1][0],dp[i-2][0]+a[i]);
        dp[i][1]=max(dp[i-1][1],dp[i-2][1]+a[i]);
      }
    }
  }

  if(n%2==1)cout<<dp[n][0];
  else cout<<dp[n][1];
  
  return 0;
}


Measured memory_bytes: 8308
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  long long tot=0;
  for(int i=0;i<(int)s.size();i++){
    tot+=s[i]-'0';
  }
  if(tot%9==0){
    cout << "Yes\n";
  }
  else cout << "No\n";
  return 0;
}

Measured memory_bytes: 3724
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int count = 0;
        for (int i = 0; i < 3; i++) {
            if (s.charAt(i) == t.charAt(i)) {
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 23636
import heapq

N, M = [int(n) for n in input().split()]
hq = []
[heapq.heappush(hq, v) for v in [-1*int(n) for n in input().split()]]
for _ in range(M):
   heapq.heappush(hq, -1*(-1*heapq.heappop(hq)//2))
print(-1*sum(hq))


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

using namespace std;

//#define FILE_IO

int N;
char a[505][505];

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d\n", &N);
    for(int i = 1; i <= N; i++)
        scanf("%s\n", a[i] + 1);

    int cnt = 0;
    int sumall = 0;
    for(int j = 1; j <= N; j++)
    {
        int sum = 0;
        for(int i = 1; i <= N; i++)
            sum += (a[i][j] == '#'), sumall += (a[i][j] == '#');
        cnt += (sum == N);
    }
    cnt = N - cnt;
    if(sumall == 0)
    {
        printf("-1\n");
        exit(0);
    }

    int ans = N + 1;
    for(int i = 1; i <= N; i++)
    {
        int nr0 = 0;
        for(int j = 1; j <= N; j++)
            nr0 += (a[i][j] == '.');
        int nrc = 0;
        for(int j = 1; j <= N; j++)
            nrc += (a[j][i] == '#');

        if(nrc == 0)    nr0++;
        ans = min(ans, nr0);
    }

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

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <string>

using namespace std;
int main() {
	string A;
	cin >> A;
	
	string T = "ATCG";
	int sum = 0;
	
	for (int i = 0; i < A.size(); i++)
	{
		int t = 0;
		for (int j = i; i < A.size(); j++)
		{
			
			if (A[j] == T[0]or A[j]==T[1] or A[j] == T[2] or A[j] == T[3])
			{
				t = t + 1;
				

			}
			else
			{
				if (sum < t)
					sum = t;
				break;
			}
		}
	}
	cout << sum;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000
int L[(MAX/2)+2],R[(MAX/2)+2];
int cnt;
void merge(int A[],int n,int left,int mid,int right){
  int n1=mid-left;
  int n2=right-mid;
  for(int i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(int i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=R[n2]=SENTINEL;
  int i=0,j=0;
  for(int k=left;k<right;k++){
    cnt++;
    if(L[i]<=R[j]){
      A[k]=L[i++];
    }
    else{
        A[k]=R[j++];
    }
  }
}

void mergeSort(int A[],int n,int left,int right){
  if(left+1<right){
    int mid=(left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int main(){
    int A[MAX],n,i;
    cnt=0;
    cin>>n;
    for(i=0;i<n;i++){
        cin >> A[i];
    }
    mergeSort(A,n,0,n);
    
    for(i=0;i<n;i++){
        if(i)cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << cnt << endl;
    return 0;
}   



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

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	char S[5];
	char c[7][5] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};

	cin >> S;
	for(int i = 0; i < 7; i++) if(strcmp(S, c[i]) == 0) cout << (12 - i) % 7 + 1 << "\n";
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 && W == 0) {
                break;
            }
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    System.out.print("#");
                }
                System.out.print("\n");
            }
            System.out.print("\n");
        }
    }
}



Measured memory_bytes: 38348
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k, s;
  cin >> k >> s;
  int count =0;
  for (int x=0;x<=k;x++){
    for (int y=0;y<=k;y++){
      int z=s-x-y;
      if(z>=0&&z<=k){
        count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,m;
    cin>>n;
    set<string>st;
    map<string,int>mp;
    int mx=0;
    string s;
    for(int i=0; i<n; i++)
    {
        cin>>s;
        st.insert(s);
        mp[s]++;
    }
    cin>>m;
    for(int i=0;i<m;i++){
        cin>>s;
        mp[s]--;
    }
    for(auto i:st)
        mx=max(mx,mp[i]);
        cout<<mx<<endl;
    return 0;
}


Measured memory_bytes: 3616
int a[31];
main(i,n){
  for(a[0]=a[1]=1,a[2]=2,i=3;i<31;i++)a[i]=a[i-1]+a[i-2]+a[i-3];
  for(;scanf("%d",&n),n;printf("%d\n",(a[n]+3649)/3650));
  return 0;
}

Measured memory_bytes: 600
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int xX = sc.nextInt();
        int yY = sc.nextInt();
        List<Integer> x = new ArrayList<>();
        List<Integer> y = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            x.add(sc.nextInt());
        }
        for (int i = 0; i < m; i++) {
            y.add(sc.nextInt());
        }
        sc.close();
        x.add(xX);
        y.add(yY);

        Collections.sort(x);
        Collections.sort(y);

        if (x.get(n) < y.get(0)) {
            System.out.println("No War");
        } else {
            System.out.println("War");
        }

    }

}


Measured memory_bytes: 23252
#include"bits/stdc++.h"
//#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define print(x) cout<<x<<endl;
typedef long long ll;

int main() {
	ll s, c;
	cin >> s >> c;
	ll cnt = 0;
	ll hc = c / 2;
	if (hc < s) { print(hc); return 0; }
	cnt += s;
	hc -= s;
	cnt += hc / 2;
	print(cnt);
	return 0;
}

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

using namespace std;

int main() {
    char b; cin >> b;
    char ans;
    if(b == 'A') ans = 'T';
    if(b == 'C') ans = 'G';
    if(b == 'G') ans = 'C';
    if(b == 'T') ans = 'A';

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 256
from itertools import combinations


def main():
    N = int(input())
    L = tuple(map(int, input().split()))

    answer = solve(N, L)

    print(answer)


def solve(N, L):
    three_bar_combinations = tuple(combinations(L, 3))

    if not three_bar_combinations:
        return 0

    count = 0
    for c in three_bar_combinations:
        if len(c) != len(set(c)):
            continue

        if max(c) < sum(c) - max(c):
            count += 1

    return count


if __name__ == "__main__":
    main()


Measured memory_bytes: 20808