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

#define ll                                       long long
#define eb                                     emplace_back
#define pii                                     pair<int,int>
#define pll                                      pair<ll,ll>
#define mp                                     map<int,int>
#define _fastio                              ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define DB(x)                                cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define Pi                                      acos(-1.0)
#define open                                  freopen("input.txt","r",stdin)         //opening input file
#define close                                  freopen ("output.txt","w",stdout)     //opening output file
#define fori(i,n)                              for(int i=1;i<=n;++i)
#define forn(i,n)                             for(int i=0;i<n;++i)
#define sz(x)                                  int(x.size())
#define error(x)                              cout<<#x<<" "<<x<<endl
#define sorted(v)                            sort(v.begin(),v.end())
int main()
{
    _fastio;
    //open;
    //close;
    vector<int>v;
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        v.push_back(x);
    }
    int cnt=0,mx=0;
    for(int i=v.size()-1; i>0; i--)
    {
        if(v[i-1]>=v[i])
            cnt++;
        else
            cnt=0;
        if(mx<cnt)
            mx=cnt;
        //cout<<cnt<<endl;
    }
    cout<<mx<<endl;
    return 0;
}

/// DO PEN AND PAPERWORK AFTER READING QUESTIONS CAREFULLY
/// Be confident to Solve if others can do.***
/// Common sense: do something instead of nothing
/// Even a single second counts...
/// be super cool, super patient and super focused





Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,a[N],b[N];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
        b[i]=i;
    int ans=0;
    for(int i=2;i<n;i++)
    {
        int x=a[i-1],y=a[i],z=a[i+1];
        if(y<x) swap(x,y);if(z<x) swap(x,z);if(z<y) swap(y,z);
        if(a[i]==y) ans++;
    }
    printf("%d\n",ans);
}


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

using namespace std;

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

  for (int yy = 0; yy <= 100; ++yy) {
    for (int xx = 0; xx <= 100; ++xx) {

      int hh = -1;
      for (int i = 0; i < N; ++i) {
        if (h[i] == 0) continue;
        int tmp = h[i] + abs(y[i]-yy) + abs(x[i]-xx);
        if (hh == -1) {
          hh = tmp;
        } else {
          if (hh != tmp) {
            hh = -2;
            break;
          }
        }
      }

      if (hh == -2) continue;

      for (int i = 0; i < N; ++i) {
        if (h[i] > 0) continue;

        int diff = abs(y[i]-yy) + abs(x[i]-xx);
        if (hh > diff) {
          hh = -2;
          break;
        }
      }

      if (hh == -2) continue;

      printf("%d %d %d\n", xx, yy, hh);
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int m,f,r,i,j;
  while(1){
    scanf("%d %d %d",&m,&f,&r);
    if(m==-1 && f==-1 && r==-1)break;
    if(m==-1 || f==-1)printf("F\n");
    else if(m+f>=80)printf("A\n");
    else if(m+f<80 && m+f>=65)printf("B\n");
    else if(m+f<65 && m+f>=50)printf("C\n");
    else if(m+f<50 && m+f>=30){
      if(r>=50)printf("C\n");
      else printf("D\n");
    }
    else if(m+f<30)printf("F\n");
  }
  return 0;
}

Measured memory_bytes: 1012
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;

const ll MOD = 1000000007;
//const ll MOD = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        return mint(*this) /= a;
    }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int n;
    cin >> n;

    vll a(n);
    REP(i, n) cin >> a[i];

    mint s = 0;
    REP(i, n) s += a[i];

    mint ans = 0;
    REP(i, n) {
        s -= a[i];
        ans += s * a[i];
    }

    print(ans);

}


Measured memory_bytes: 4740
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n,k,cnt=0;
string s;
signed main(){
    cin>>n>>k>>s;
    rep(i,n-1){
        if(s[i]!=s[i+1])cnt++;
    }
    cnt-=k*2;
    if(cnt<=0)cnt=0;
    cout<<n-(cnt+1)<<endl;
    return 0;
}


Measured memory_bytes: 512
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> P;
const long long mod = 1000000007;
const double eps = 1e-11;
const int inf = 1ll << 61;
int fn[30];
signed main() {
	string s; cin >> s;
	rep(i, s.size())fn[s[i] - 'a']++;
	rep(i, 26) {
		if (!fn[i]) {
			cout << (char)('a' + i) << endl; return 0;
		}
	}cout << "None" << endl;
}

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

int main()
{
    int A, B, K;
    cin >> A >> B >> K;
    for (int i = min(A, B); i >= 1; i--)
    {
        if (A % i == 0 && B % i == 0)
        {
            K--;
            if (K == 0)
            {
                cout << i << endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 256
def main():
    s = input()
    q = int(input())
    r = 1
    front = ""
    back = ""
    for _ in range(q):
        n, *fc = input().split()
        if n == "1":
            r *= -1
        else:
            f, c = fc
            f = 1 if f == "1" else -1
            if f*r == 1:
                front += c
            else:
                back += c
    if r == 1:
        print(front[::-1]+s+back)
    else:
        print(back[::-1]+s[::-1]+front)

if __name__ == "__main__":
    main()

Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int L, R;
  cin >> L >> R;

  if (L / 2019 == R / 2019)
  {
    L %= 2019;
    R %= 2019;

    int ans = 2020;
    for (int i = L; i < R; i++)
	{
      for (int j = i + 1; j <= R; j++)
	  {
        ans = min(ans, (i * j) % 2019);
      }
    }
    cout << ans << endl;

  } else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
from collections import deque


def main():
    N = int(input())
    adj = [set() for _ in range(N+1)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        adj[a].add(b)
        adj[b].add(a)
    state = [None] * (N+1)
    q = deque([(1, "B"), (N, "W")])
    while len(q):
        node, color = q.popleft()
        if state[node] is not None:
            continue
        state[node] = color
        for nxt in adj[node]:
            if state[nxt] is None:
                adj[nxt].remove(node)
                q.append((nxt, color))
    result = {"B": 0, "W": 0}
    for s in state:
        if s in result:
            result[s] += 1
    if result["B"] > result["W"]:
        print("Fennec")
    else:
        print("Snuke")


if __name__ == "__main__":
    main()


Measured memory_bytes: 76448
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static long Mod = (long)1e9 + 7;
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            (int H, int W) = Slice2<int>();
            for(var h=0;h<H;++h)
            {
                var s = ReadLine();
                WriteLine(s);
                WriteLine(s);
            }
        }
    }
}

Measured memory_bytes: 27596
sx, sy, tx, ty = map(int, input().split())

ans = ""
ans = "R"*(tx-sx) + "U"*(ty-sy) + "L"*(tx-sx) + "D"*(ty-sy) + "L" + "U"*(ty+1-sy) + "R"*(tx+1-sx) + "D" +"R" + "D"*(ty+1-sy) + "L"*(tx+1-sx) + "U"

print(ans)

Measured memory_bytes: 9120
import sys
input = sys.stdin.readline
N, C = map(int, input().split())
a = list(map(int, input().split()))

from collections import deque
deq = deque()
def check(f1, f2, f3):
    return (f2[0] - f1[0]) * (f3[1] - f2[1]) >= (f2[1] - f1[1]) * (f3[0] - f2[0])
def f(f1, x):
    return f1[0]*x + f1[1]

# add f_i(x) = a*x + b
def add_line(a, b):
    f1 = (a, b)
    while len(deq) >= 2 and check(deq[-2], deq[-1], f1):
        deq.pop()
    deq.append(f1)

# min f_i(x)
def query(x):
    while len(deq) >= 2 and f(deq[0], x) >= f(deq[1], x):
        deq.popleft()
    return f(deq[0], x)

add_line(-2 * a[0], a[0] ** 2 + C)
dp = [0] * N
for i in range(1, N):
  x = query(a[i]) + a[i] ** 2
  add_line(-2 * a[i], x + C + a[i] ** 2)
  dp[i] = x
print(dp[-1])

Measured memory_bytes: 77900
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const ll MOD = 1e9+9;

VL matvec(vector<VL> A, VL x){
    int n = x.size();
    VL y(n);
    REP(i,n) REP(j,n){
        y[i] = (y[i] + A[i][j] * x[j]) % MOD;
    }
    return y;
}

vector<VL> matprod(vector<VL> A, vector<VL> B){
    int n = A.size();
    vector<VL> C(n, VL(n));
    REP(i,n) REP(j,n) REP(k,n){
        C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
    }
    return C;
}

vector<VL> matpow(vector<VL> A, ll p){
    int n = A.size();
    vector<VL> B(n, VL(n));
    REP(i,n) B[i][i] = 1;
    while (p){
        if (p & 1) B = matprod(B, A);
        A = matprod(A, A);
        p /= 2;
    }
    return B;
}

int main() {
    int w, n, t = 0;
    ll h;
    while (cin >> w >> h >> n && w){
        t++;
        printf("Case %d: ", t);
        vector<PL> p(n);
        REP(i,n){
            cin >> p[i].second >> p[i].first;
            p[i].first--;
            p[i].second--;
        }
        sort(p.begin(),p.end());
        VL a;
        a.push_back(0);
        REP(i,n){
            if (a[a.size()-1] != p[i].first)
                a.push_back(p[i].first);
        }
        a.push_back(h-1);
        int m = a.size();

        VL x(w);
        x[0] = 1;
        REP(i,m-1){
             vector<VL> A(w,VL(w));
             REP(k,w){
                A[k][k] = 1;
                A[k][min(w-1,k+1)] = 1;
                A[min(w-1,k+1)][k] = 1;
             }
             A = matpow(A, a[i+1]-a[i]);
             x = matvec(A, x);
             REP(j,n){
                if (p[j].first == a[i+1]) x[p[j].second] = 0;
             }
        }
        cout << x[w-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 3424
#include<stdio.h>
#include<iostream>
using namespace std;
int main (){
    int n,a,b,total=0;
    cin >> n >> a >> b;
    for(int i=1; i<=n; i++){
        int x = i;
        int sum = 0;
        for(int j=0; j<5; j++){
            sum += x % 10;
            x /= 10;
        }
        if( sum >= a && sum <= b ) total += i;
    }
    cout << total << endl;
    return 0;
}


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

mp = dict()
mp[s] = 1
cnt = 1
while True:
    if s % 2 == 0:
        s = s//2
    else:
        s = 3*s + 1

    cnt += 1

    if s in mp:
        break
    else:
        mp[s] = 1

print(cnt)


Measured memory_bytes: 2940
#include <iostream>
// #include <cassert>
#include <vector>
#include <algorithm>
#include <climits>

// #include <stack>
// #include <queue>
// #include <deque>
// #include <set>
// #include <map>
// #include <string>
// #include <unordered_set>
// #include <unordered_map>

// #include <tuple>
// #include <cmath>
// #include <numeric>

using namespace std;
typedef long long ll;
typedef pair<long,long> pll;
typedef pair<int,int> pii;
typedef pair<int,long> pil;
typedef pair<long,int> pli;
typedef vector<vector<long long>> vvll;
typedef vector<vector<long>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;

#define emplace_back pb
const char el = '\n';

/*
Edge cases:


*/

//offsets in range:  -2000,2000;

//increase by 2000 so that it is 

bool badab[16001];
bool badbc[16001];
bool badac[16001];
const int maxlen = 2000;

bool match(char ch1,char ch2) {
    return (ch1=='?' || ch2=='?' || (ch1==ch2) );
}


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


    string a,b,c;
    cin>>a;
    cin>>b;
    cin>>c;

    int n1,n2,n3;
    n1=(int)a.length();
    n2=(int)b.length();
    n3=(int)c.length();

    // cout<<"strrings are "<<a<<" "<<b<<" "<<c<<el;

    for (int i = 0; i<n1; ++i)
        for (int j=0; j<n2; ++j) {
            if ( !match(a[i],b[j]) ) {
                badab[i-j+4*maxlen]=true;
            }
        }
    for (int i = 0; i<n2; ++i)
        for (int j=0; j<n3; ++j) {
            if ( !match(b[i],c[j]) ) {
                badbc[i-j+4*maxlen]=true;
            }
        }
    for (int i = 0; i<n1; ++i)
        for (int j=0; j<n3; ++j) {
            if ( !match(a[i],c[j]) ) {
                badac[i-j+4*maxlen]=true;
            }
        }

    //k1 = a,b offset
    //k2 = a,c offset
    //k3 = f(k1,k2) = b,c offset

    int shortestlength = 6000;
    for (int k1 = -2*maxlen; k1<=2*maxlen; ++k1) 
        for (int k2 = -2*maxlen; k2<=2*maxlen; ++k2) {
            if (!badab[k1+4*maxlen] && !badac[k2+4*maxlen] && !badbc[k2-k1+4*maxlen]) {
                int right = max({n1-1,n2+k1-1,n3+k2-1});
                int left = min({0,k1,k2});
                // right = max({right,k1+(n1-1),k2+(n1-1)});
                shortestlength = min(shortestlength,right-left+1);

            }
        }

    cout<<shortestlength<<el;

}

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

int main ()
{
    int n, k, count=0;
    cin >> n >> k;
    vector<int> ball(n);

    for (int i = 0; i<n; i++)
    {
        cin>> ball.at(i);
        count += min(ball.at(i), k - ball.at(i))*2;
    }
    
    cout<< count<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
    int i;
    int x, y, z;
    int tmp;
    int count = 0;
    scanf("%d %d %d", &x, &y, &z);
    
    if(x > y) {
        tmp = x;
        x = y;
        y = tmp;
    }
    for(i = x; i <= y; i++) {
        if( (z % i) == 0 ) {
            count++;
        }
    }
    printf("%d\n", count);
    
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	int k;
	cin >> k;
	map<int,int> mp;
	rep(i,k){
		int d;
		cin >> d;
		mp[d]++;
	}
	for (int i = n; i <= 1000000; ++i) {
		string s = to_string(i);
		bool ok = true;
		rep(j,s.size()){
			if(mp[s[j] - '0'] != 0) ok = false;
		}
		if(ok){
			cout << i << endl;
			return 0;
		}
	}
	
    return 0;
}



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

using namespace std;

template <class T>
using lim = numeric_limits<T>;

typedef long long ll;
typedef long double ld;

const int maxBit = 62;
int bitCount[maxBit+1];

void addToCount(ll x){
	for (int i = 0; i < maxBit; i++){
		bitCount[i] += x%2;
		x /= 2;
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	memset(bitCount, 0, sizeof bitCount);
	
	int n;
	ll k;
	cin >> n >> k;
	
	ll a[n];
	// add the number to the bitCount
	for (int i = 0; i < n; i++){
		cin >> a[i];
		addToCount(a[i]);
	}
	
	ll best = 0;
	// computing the optimal x
	// 1 if more 0's than 1's, 0 otherwise
	for (int i = maxBit; i >= 0 ; i--){
		ll toAdd = (bitCount[i]<=n/2)*(1LL<<i);
		if (best + toAdd <= k){
			best += toAdd;
		}
	}

	ll ans = 0;
	for (int i = 0; i < n; i++){
		ans += best^a[i];
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
	char a;
	cin >> a;
	if (a=='A') cout << 'T';
	else if (a=='T') cout << 'A';
	else if (a=='G') cout << 'C';
	else cout << 'G';
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
ps = [input().split() for i in range(M)]

ans = set()
pre_wa = [0]*(N+1)
wa = 0
for p, s in ps:
    p = int(p)
    if s == 'AC':
        ans.add(p)
        wa += pre_wa[p]
        pre_wa[p] = 0
    if s == 'WA' and p not in ans:
        pre_wa[p] += 1

print(len(ans), wa)

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

int main(){
  
  int N,M;
  cin >> N >> M;
  vector<int> sw(N);
  for (int i=0;i<M;i++){
    int K;
    cin >> K;
    for (int j=0;j<K;j++){
      int s;
      cin >> s;
      s --;
      sw[s] |= 1 << i;
    }
  }
  
  // for (int i=0;i<N;i++) cout << sw[i] << endl; //test
  // cout << endl; //test
  
  int P = 0;
  for (int i=0;i<M;i++){
    int x;
    cin >> x;  
    P |= x << i;
  }
  
  // cout << P << endl << endl; //test
  
  int ans = 0;
  
  for (int i=0;i<(1<<N);i++){
    int state = 0;
    for (int j=0;j<N;j++){
      if((i>>j)&1 == 1){
        state ^= sw[j];
      }
    }
    // cout << state << endl; //test
    if (state == P) ans++;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int matrix[15][15];

int visited[15][15];

void tansaku(int r,int c,int n) {
	if(r<0 || r>=n || c<0 || c>=n)return;
	if(visited[r][c])return;
	visited[r][c]=1;
	if(r>0 && matrix[r][c]==matrix[r-1][c])tansaku(r-1,c,n);
	if(r+1<n && matrix[r][c]==matrix[r+1][c])tansaku(r+1,c,n);
	if(c>0 && matrix[r][c]==matrix[r][c-1])tansaku(r,c-1,n);
	if(c+1<n && matrix[r][c]==matrix[r][c+1])tansaku(r,c+1,n);
}

int main(void) {
	int n,m;
	int i,j;
	int opCount;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++) {
		for(j=0;j<n;j++)scanf("%d",&matrix[i][j]);
	}
	for(opCount=0;opCount<m;opCount++) {
		int query;
		int r,c,size,angle;
		scanf("%d",&query);
		switch(query) {
			case 0:
				scanf("%d%d%d%d",&r,&c,&size,&angle);r--;c--;
				for(;angle>0;angle-=90) {
					for(i=0;i<size;i++) {
						for(j=0;j<size;j++) {
							visited[i][j]=matrix[r+size-j-1][c+i];
						}
					}
					for(i=0;i<size;i++) {
						for(j=0;j<size;j++) {
							matrix[r+i][c+j]=visited[i][j];
						}
					}
				}
				break;
			case 1:
				scanf("%d%d%d",&r,&c,&size);r--;c--;
				for(i=0;i<size;i++) {
					for(j=0;j<size;j++) {
						matrix[r+i][c+j]=1-matrix[r+i][c+j];
					}
				}
				break;
			case 2:
				scanf("%d",&r);r--;
				c=matrix[r][0];
				for(i=0;i+1<n;i++)matrix[r][i]=matrix[r][i+1];
				matrix[r][n-1]=c;
				break;
			case 3:
				scanf("%d",&r);r--;
				c=matrix[r][n-1];
				for(i=n-1;i>0;i--)matrix[r][i]=matrix[r][i-1];
				matrix[r][0]=c;
				break;
			case 4:
				scanf("%d%d",&r,&c);r--;c--;
				for(i=0;i<n;i++) {
					for(j=0;j<n;j++)visited[i][j]=0;
				}
				tansaku(r,c,n);
				for(i=0;i<n;i++) {
					for(j=0;j<n;j++) {
						if(visited[i][j])matrix[i][j]=1-matrix[i][j];
					}
				}
				break;
		}
	}
	for(i=0;i<n;i++) {
		for(j=0;j<n;j++) {
			printf("%d%c",matrix[i][j],j+1<n?' ':'\n');
		}
	}
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;
constexpr i64 MOD = 1e9 + 7;

int main() {
    int n, m;
    cin >> n >> m;
    vvi pos(n * m + 1, vi(2, -1));
    vi as(n), bs(m);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        as[i] = a;
        if (pos[a][0] != -1) {
            cout << 0 << endl;
            return 0;
        }
        pos[a][0] = i;
    }
    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;
        bs[i] = a;
        if (pos[a][1] != -1) {
            cout << 0 << endl;
            return 0;
        }
        pos[a][1] = i;
    }

    i64 ans = 1;
    i64 fixi = 0, fixj = 0;
    i64 fixed = 0;
    for (int i = n * m; i > 0; i--) {
        if (pos[i][0] != -1 && pos[i][1] != -1) {
            fixi++, fixj++;
            fixed++;
        } else if (pos[i][0] == -1 && pos[i][1] == -1) {
            ans *= (fixi * fixj - fixed);
            fixed++;
            ans %= MOD;
        } else if (pos[i][0] != -1) {
            fixi++;
            ans *= fixj;
            fixed++;
            ans %= MOD;
        } else if (pos[i][1] != -1) {
            fixj++;
            ans *= fixi;
            fixed++;
            ans %= MOD;
        }
        if (fixi > n && fixj > m) {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 54912
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int[] lengths = new int[n];
		int maxLengths = 0;
		int sumLengths = 0;
		
		for (int i = 0; i < n; i++) {
			int length = sc.nextInt();
			maxLengths = Math.max(maxLengths, length);
			sumLengths += length;
		}
		
		if ((sumLengths - maxLengths) > maxLengths) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
	
	static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine()); 
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}


Measured memory_bytes: 22996
import sys
X, N = [int(x) for x in input().split()]
if(N != 0):
  p = [int(x) for x in input().split()]
else:
  print(X)
  sys.exit()

i = 0
x = 0
while True:
  delta1 = X - i
  delta2 = X + i
  if((delta1 in p)==False):
    x = delta1
    print(x)
    sys.exit()
  elif((delta2 in p)==False):
    x = delta2
    print(x)
    sys.exit()
  i += 1

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

int main() {
  char s1,s2,s3;
  cin >> s1 >> s2 >> s3;
  if(s1!=s2&&s1!=s3&&s2!=s3) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3604
Option Explicit On

Module Module1

    Sub Main()

        Dim N As String = Console.ReadLine()
        Dim ans As String = ""

        Select Case Right(N, 1)

            Case 3
                ans = "bon"
            Case 0, 1, 6, 8
                ans = "pon"
            Case Else
                ans = "hon"
        End Select

        Console.WriteLine(ans)

    End Sub

End Module


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

typedef long long ll;
typedef pair<int,int> ii;

#define MAX 120
int N;
ll A[MAX], dp[MAX];

int main() {
  cin >> N;
  rep(i,N) cin >> A[i];
  dp[0] = 1000;
  ll maxi = 1000;
  rep(i,N) {
    REP(j,i+1,N) {
      dp[j] = max(dp[j],dp[i]);
      maxi = max(maxi,dp[j]);


      ll k = dp[i] / A[i];
      ll nex = ( dp[i] - k * A[i] ) + k * A[j];
      dp[j] = max(dp[j], nex);
      maxi = max(maxi,dp[j]);
      /*
      while( k * A[i] <= dp[i] ) {
	++k;
      }
      */
    }
  }
  cout << maxi << endl;
  return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)

#define MAXN (200000)
#define MOD (998244353)


// 優先度付きキュー Priority Queue
// 最大を保持
// 二分ヒープで実装
typedef struct 
{
    int64_t pri;
    int64_t val;
}que;
que pq[MAXN+1];
int pq_size=0;

void PQadd(int64_t pri, int64_t val)
{
    pq_size++;
    pq[pq_size].pri = pri;
    pq[pq_size].val = val;
    int i = pq_size;
    while( (i>1) && (pq[i].pri > pq[i/2].pri))
    {
        que temp;
        temp = pq[i];
        pq[i] = pq[i/2];
        pq[i/2] = temp;
        i /= 2;
    }
}

que PQget(void)
{
    que ret;
    ret = pq[1];
    pq[1] = pq[pq_size];
    pq_size--;

    int i = 1;
    while(i*2 <= pq_size) // 葉ならやめる
    {
        int j;
        if(i*2 == pq_size) //左の子しかいない
        {
            j = i*2;
        }else
        {
            j = pq[i*2].pri > pq[i*2+1].pri ? i*2 : i*2+1;
        }

        if(pq[i].pri < pq[j].pri)
        {
            que temp;
            temp = pq[i];
            pq[i] = pq[j];
            pq[j] = temp;
            i = j;
        }else
        {
            break;
        }
        
    }

    return ret;
}

int a[MAXN];
int b[MAXN];

int main(void)
{
    int n;
    scanf("%d",&n);

    for(int i=0;i<n;i++) scanf("%d",&(a[i]));
    for(int i=0;i<n;i++) scanf("%d",&(b[i]));

    for(int i=0;i<n;i++)
    {
        if(a[i] > b[i])
        {
            printf("-1\n");
            return 0;
        }else if(a[i] < b[i])
        {
            PQadd(b[i],i);
        }
    }

    int64_t cnt = 0;
    while(pq_size)
    {
        int i = PQget().val;
        int j = (i+n-1)%n;
        int k = (i+1)%n;
        int diff = b[j] + b[k];

        if(b[i] < diff)
        {
            printf("-1\n");
            return 0;
        }

        if(b[i]%diff == a[i]%diff)
        {
            cnt += (b[i]-a[i])/diff;
            b[i] = a[i];
        }else{
            cnt += b[i]/diff;
            b[i] %= diff;
            if(b[i] < a[i])
            {
                printf("-1\n");
                return 0;
            }
            PQadd(b[i],i);
        }
    }

    printf("%ld\n",cnt);
    return 0;
}







Measured memory_bytes: 4864
#include <bits/stdc++.h>//復習必須
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
int main () {
    int n , m ;
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    priority_queue<int> q;
    for (int i = 1; i <= n; i++) {
        int k; cin >> k;
        q.push(k);
    }
    for (int i = 1; i <= m; i++) {
        int now = q.top();
        q.pop();
        now /= 2;
        q.push(now);
    }
    long long ans = 0;
    while (q.size()) {
        int p = q.top();
        q.pop();
        ans += p;
    }
    cout << ans << endl;
    return 0 ;
}

 


Measured memory_bytes: 892
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();
		
		int[][] curr   =new int[3][2];
		int[][] next   =new int[3][2];
		for(int i=0; i<3; i++)curr[i][0]=1;
		
		int[]   dayPlan=new int[N];
		for(int i=0; i<K; i++)
			dayPlan[sc.nextInt()-1] = sc.nextInt();
		
		for(int i=0; i<N-1; i++)
		{	
			for(int j=0; j<3; j++)
			{
				if(dayPlan[i] != 0 && j != dayPlan[i]-1)
					continue;
				
				for(int k=0; k<3; k++)
				{
					if(j==k){ next[k][1]+=curr[j][0]; next[k][1]%=10000; }
					else    { next[k][0]+=curr[j][0]; next[k][0]%=10000; }

					if(j!=k){ next[k][0]+=curr[j][1]; next[k][0]%=10000; }
				}
			}
			
			for(int j=0; j<3; j++)
			{
				curr[j][0]=next[j][0];  next[j][0]=0;
				curr[j][1]=next[j][1];  next[j][1]=0;
			}
		}
		
		int ans = 0;
		for(int i=0; i<3; i++)
		{
			if(dayPlan[N-1]==0 || i==dayPlan[N-1]-1)
				ans += curr[i][0]+curr[i][1];
		}
		ans %= 10000;
		System.out.println(ans);
	}
}

Measured memory_bytes: 19820
#include<stdio.h>
int main(){
char a[100]={0};
int cnt=0,i,MAX=0;
  
scanf("%s",a);
for(i=0;i<10;i++){
if(a[i]=='A'||a[i]=='T'||a[i]=='G'||a[i]=='C'){
    cnt++;
  if(MAX<cnt){
   MAX=cnt;}
}
  else{
    cnt=0;}

 if(a[i]=='\0')
    break;
} 
  
 printf("%d\n",MAX);
  return(0);
}

Measured memory_bytes: 128
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <sstream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define F first
#define S second
using namespace std;
using ll = long long;
using P = pair<int,int>;

// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  // BIT(int n=0):n(n),d(n+1) {}
  void init(int n) {
    this->n = n;
    d.clear();
    d.assign(n + 1, 0);
  }

  void add(int i, T x=1) {
    while(i < d.size()) {
      d[i] += x;
      i += (i & -i);
    }
    // for (i++; i <= n; i += i&-i) {
    //   d[i] += x;
    // }
  }
  T sum(int i) {
    T t = 0;
    while (i > 0) {
      t += d[i];
      i -= (i & -i);
    }
    return t;
    // T x = 0;
    // for (i++; i; i -= i&-i) {
    //   x += d[i];
    // }
    // return x;
  }

  void show() {
    rep(i, n+1) {
      cout << d[i] << ' ';
    }
    cout << endl;
  }
};

int main() {
  int n, q;
  string s;

  cin >> n;
  cin >> s;
  cin >> q;

  vector<BIT<int> > bits(26);
  rep(i, 26) {
    bits[i].init(n);
  }

  rep(i, n) {
    bits[s[i] - 'a'].add(i + 1, 1);
  }

  rep(_i, q) {
    int type;
    cin >> type;

    if (type == 1) {
      int i;
      char c;
      cin >> i >> c;
      i--;
      bits[s[i] - 'a'].add(i + 1, -1);
      s[i] = c;
      bits[s[i] - 'a'].add(i + 1, 1);
    } else {
      int l, r;
      cin >> l >> r;
      int res = 0;
      rep(i, 26) {
        int t = bits[i].sum(r) - bits[i].sum(l - 1);
        res += (t > 0);
      }
      printf("%d\n", res);
    }
  }

  return 0;
}


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

int main() {
    int N;
    int a[110];  // 最大 100 個ですが余裕をもたせます
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> a[i];

    sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート
    int Alice = 0;
    int Bob = 0;
    for (int i = 0; i < N; ++i) {
        if (i % 2 == 0) { // Alice のターン
            Alice += a[i];
        }
        else { // Bob のターン
            Bob += a[i];
        }
    }
    cout << Alice - Bob << endl;
}

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	vector<int> a(3);
	for (int i=0; i<3; i++)
		cin>>a[i];
	sort(a.begin(), a.end());
	cout << a[2]-a[0] << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
//#define inf 1000000000000000000
using namespace std;
  
// Main function which finds difference 

int main(){
    string s;
    cin>>s;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='?')s[i]='D';
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 3752
#include<stdio.h>
int main(void)
{
	int a,b,c;

	scanf("%d %d %d", &a, &b, &c);
	if(a<b){
		if(b<c){
		printf("Yes\n");
	}else {
		printf("No\n");
	}
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=-1;cin>>n;
  lvector V(n),C(n);rep(i,n) cin>>V[i];rep(i,n) cin>>C[i];
  for(ll bit=0;bit<(1<<n);++bit) {
    ll tmp=0;
    rep(i,n) if(bit&(1<<i)) tmp+=V[i]-C[i];
    ans=max(tmp,ans);
  }
  print(ans);
  return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int N, M, K; cin >> N >> M >> K;

  map<int, int> mp, mprev;
  int darkcnt = 0;

  rep(i, M) {
    int d; cin >> d; d--;
    mp[d] = darkcnt;
    mprev[darkcnt++] = d;
  }

  vector<vector<int>> G(N);

  rep(i, N) {
    rep(k, K) {
      int to; cin >> to; to--;
      G[i].push_back(to);
    }
  }

  int dp[1 << M];
  rep(i, 1 << M) dp[i] = inf;

  dp[(1 << M) - 1] = 0;
  queue<int> q;
  q.push((1 << M) - 1);

  while(!q.empty()) {
    auto const S = q.front(); q.pop();
    rep(to_dir, K) {
      auto T = S;
      auto TAdd = 0;
      rep(from, M) {
        if(T >> from & 1) {
          T &= ~(1 << from);
          auto to = G[mprev[from]][to_dir];
          if(mp.find(to) != mp.end()) {
            TAdd |= 1 << mp[to];
          }
        }
      }
      T |= TAdd;
      if(dp[T] > dp[S] + 1) {
        dp[T] = dp[S] + 1;
        q.push(T);
      }
    }
  }

  cout << dp[0] << endl;
  
  return 0;
}

Measured memory_bytes: 3568
local n=io.read("n")
local zero=false
local even=0
local min=10^9+1
local total=0
for i=1,n do
    local input=io.read("n")
    zero=(input==0 or zero)
    even=(input<0 and even+1 or even)
    local absinput=math.abs(input)
    min=math.min(absinput,min)
    total=total+absinput
end

if even%2==0 or zero then
    print(total)
else
    print(total-2*min)
end

Measured memory_bytes: 760
def main():
    S = input()

    N = len(S)

    for i in range(int(N/2)):
        if S[i] != S[i*-1-1]:
            print('No')
            exit()

    S2 = S[0:int(N/2)]
    N2 = len(S2)

    for i in range(int(N2/2)):
        if S2[i] != S2[i*-1-1]:
            print('No')
            exit()

    S3 = S[int((N+3)/2)-1:]
    N3 = len(S3)

    for i in range(int(N3/2)):
        if S3[i] != S3[i*-1-1]:
            print('No')
            exit()

    print('Yes')

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
using System;

public class hello
{
    public static void Main()
    {
        var n = long.Parse(Console.ReadLine().Trim());
        var ret = getStart(n);
        var ans = getAns(ret + 1, n);
        Console.WriteLine(ans);
    }
    public static string getAns(long st, long n)
    {
        var a = getL(st - 1);
        var w = "";
        if (n == 1) st = 1;
        for (long i = st; i <= st + 20; i++)
        {
            if (i % 15 == 0) w += "FizzBuzz";
            else if (i % 3 == 0) w += "Fizz";
            else if (i % 5 == 0) w += "Buzz";
            else w += i.ToString();
        }
        if (n == 1) return w.Substring(0, 20);
        else return w.Substring((int)(n - a - 1), 20);
    }
    public static long getStart(long n)
    {
        var ng = n;
        var ok = 1L;
        while (ng - ok > 1)
        {
            var mid = (ng + ok) / 2;
            if (getL(mid) < n) ok = mid;
            else ng = mid;
        }
        return ok;
    }
    public static long getL(long n)
    {
        var m = n.ToString().Length;
        var ret = fs(n);
        if (m == 1) return ret;
        while (m >= 2)
        {
            var t = (long)Math.Pow(10, m - 1) - 1;
            ret += fs(t);
            m--;
        }
        return ret;
    }
    public static long fs(long n)
    {
        var m = n.ToString().Length;
        var st = (long)Math.Pow(10, m - 1) - 1;
        var c15 = n / 15 - st / 15;
        var c35 = (n / 3 - st / 3) + (n / 5 - st / 5) - c15 * 2;
        var cother = n - st  - c15 - c35;
        return 8 * c15 + 4 * c35 + m * cother;
    }
}


Measured memory_bytes: 17968
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  set<int> S;
  for (int i = 0; i < N; i++){
    int A;
    cin >> A;
    if (S.count(A)){
      S.erase(A);
    } else {
      S.insert(A);
    }
  }
  cout << S.size();
}

Measured memory_bytes: 4864
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007

using namespace std;

struct UnionFind{
  vector<int> par,num;

  UnionFind(int N) : par(N),num(N){
    for(int i=0;i<N;i++){
      par[i] = i;
      num[i] = 1;
    }
  }

  int root(int x){
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    par[rx] = ry;
    num[ry] = num[ry]+num[rx]; 
  }

  int get_num(int x){
    int rx = root(x);
    return num[rx];
  }

  bool same(int x, int y){
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};


int main(void){
  int s,w;
  cin >> s >> w;

  if(s <= w){
    cout << "unsafe" << endl;
  }
  else{
    cout << "safe" << endl;
  }
  return 0;
}


Measured memory_bytes: 3636
fun main(args: Array<String>) {
    val (N, A, B) = readLine()!!.split(" ").map(String::toInt)
    var sum = 0
    for (i in 1..N) {
        val c = i.toString().toCharArray().sumBy { it.toString().toInt() }
        if (c in A..B) {
            sum += i
        }
    }
    println(sum)
}



Measured memory_bytes: 40688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;
//stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
//小数点の表し方 cout << fixed << setprecision(5);

int main(){
    string s;
    cin >> s;
    int n = s.size();
    map<char,int> m;
    for(int i=0;i<n;i++){
        m[s[i]]++;
    }
    if(m.size() == 1){
        cout << 0 << endl;
        return 0;
    }
    int ans = 200;
    for(char c = 'a';c<='z';c++){
        if(m[c] == 0)continue;
        int cnt = 0;
        map<char,int>ma;
        ma = m;
        string sc = s;
        while(ma.size() > 0){
            for(int i = 0;i<s.size()-1;i++){
                if(sc[i] == c || sc[i+1] == c){
                    sc[i] = c;
                }
            }
            sc.pop_back();
            //cout << sc << endl;
            ma.clear();
            for(int i=0;i<sc.size();i++){
                ma[sc[i]]++;
            }
            if(ma.size() == 1) break;
        }
        cnt = n - sc.size();
        ans = min(ans,cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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 main() {
  string a, b, c;
  cin >> a >> b >> c;
  if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) YES;
  else NO;
  return 0;
}

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

#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, k, n) for (int i = (k); i < (n); i++)
#define rrep(i, k, n) for (int i = (k); i > (n); i++)
#define pb push_back
#define vec vector
#define ref(a) &(a)

typedef long long ll;

using namespace std;

int a, b, c;

string solve() {
  if (a + b + c >= 22) return "bust";
  else return "win";
}

int main() {
  cin >> a >> b >> c;
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
 
//Aのn乗modM

long long modpow(long long a,long long n,long long p)
{
    if(n==1)
    {
        return a%p;
    }
    if(n%2==1)
    {
        return a*modpow(a,n-1,p)%p;
    }
    long long t = modpow(a,n/2,p);
    return t*t%p;
}
 
//O(K)でnCkを求める
int comb( int N, int K ){
  int X = 1; //分子
  int Y = 1; //分母
  for( int i = N; i > N-K; i-- ){
    X = (X*i)%MOD;
  }
  for( int i = 1; i <= K; i++ ){
    Y = (Y*i)%MOD;
  }
  return X * modpow(Y, MOD-2, MOD)%MOD;   //Aの逆元を取る場合、modpow(A, MOD-2, MOD) https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a 3-4参照
}
 
signed main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  int ans = modpow(2, N, MOD);
  //mod上で引き算を行うときは負になる可能性があるのでmodを足してからmodを取る
  ans = (ans-1+MOD)%MOD;
  ans = (ans-comb(N,A)+MOD)%MOD;
  ans = (ans-comb(N,B)+MOD)%MOD;
  cout<<ans<<endl;

}

Measured memory_bytes: 256
from collections import deque
n=int(input())
a=deque(list(map(int,input().split())))
a.appendleft(0)
a.append(0)
a=list(a)
#print(a)
#全部回った場合
tot=0
for i in range(1,n+2):
    tot+=abs(a[i]-a[i-1])
#print(tot,a)
for i in range(1,n+1):#前後を参照していく」
    if a[i-1]<=a[i]<=a[i+1] or a[i-1]>a[i]>=a[i+1]:
        print(tot)
    else:
        print(tot-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]))

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

int main() {
	int n, k; cin >> n >> k;
	vector<int> x(n); rep(i, 0, n) cin >> x[i];

	int ans = 0;
	rep(i, 0, n) {
		ans += min(x[i], k - x[i]) * 2;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  vector<int> b(n);
  for(int i=0;i<n;i++){
    b[a[i]-1]=i+1;
  }
  for(int i=0;i<n;i++){
    cout<<b[i]<<' ';
  }
}

Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;cin>>N;
  ll ans=0;
  ll a=0,b=0,ba=0;
  repeat(i,N){
    string s;cin>>s;
    repeat(j,s.length()-1){
      ans += s[j]=='A'&&s[j+1]=='B';
    }
    a += s.back()=='A'&&s[0]!='B';
    b += s.back()!='A'&&s[0]=='B';
    ba += s.back()=='A'&&s[0]=='B';
  }
  //debug(ans);
  //debug(ba);
  //debug(a);
  //debug(b);
  if(min(a,b)>0&&ba>0){
    ans += ba+min(a,b);
  }else if(ba>0){
    ans += ba-1;
    if(max(a,b)>0)ans++;
  }else{
    ans += min(a,b);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256