akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Extentions;

class IO
{
    int idx;
    string[] input = In.ReadToEnd().Split(new[] { " ", "\n", "\r" },
        StringSplitOptions.RemoveEmptyEntries);

    T Get<T>(Func<string, T> parser) => parser(input[idx++]);

    public string S => Get(s => s);
    public char C => Get(char.Parse);
    public int I => Get(int.Parse);
    public long L => Get(long.Parse);
    public double F => Get(double.Parse);
    public decimal D => Get(decimal.Parse);
    public BigInteger B => Get(BigInteger.Parse);

    T[] Gets<T>(int n, Func<string, T> parser)
        => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray();

    public string[] Ss(int n) => Gets(n, s => s);
    public char[] Cs(int n) => Gets(n, char.Parse);
    public int[] Is(int n) => Gets(n, int.Parse);
    public long[] Ls(int n) => Gets(n, long.Parse);
    public double[] Fs(int n) => Gets(n, double.Parse);
    public decimal[] Ds(int n) => Gets(n, decimal.Parse);
    public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse);

    public void Write<T>(params T[] xs) => WriteLine(string.Join(" ", xs));
    public void Write(params object[] xs) => WriteLine(string.Join(" ", xs));
}

static class Extentions
{
}

static class Program
{
    public static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { NewLine = "\n" };
#if DEBUG
        sw.AutoFlush = true;
#else
        sw.AutoFlush = false;
#endif
        SetOut(sw);
        Solve(new IO());
        Out.Flush();
    }

    static void Solve(IO io)
    {
        io.Write(io.S.Contains("AC") ? "Yes" : "No");
    }
}

Measured memory_bytes: 13268
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            var s = Console.ReadLine().Trim();
            s = s.Replace("[", "a");
            s = s.Replace("]", "b");
            var ma = Regex.Matches(s, @"a\d+b");
            foreach (Match x in ma)
            {
                var a0 = x.Value.Substring(1, x.Length - 2);
                var a = int.Parse(a0);
                var b = (a + 1) / 2;
                s = s.Replace(x.Value, b.ToString() + ",");
            }
            s = s.Replace(",b", "b");
            getAns(s);
        }
    }
    static void getAns(string s)
    {
        while (true)
        {
            var ma = Regex.Matches(s, @"a[0-9,]+b");
            if (ma.Count == 0) break;
            foreach (Match x in ma)
            {
                var a0 = x.Value.Substring(1, x.Length - 2).Split(',');
                var a1 = new List<int>();
                for (int i = 0; i < a0.Length; i++) a1.Add(int.Parse(a0[i]));
                a1.Sort();
                var a2 = 0;
                for (int i = 0; i < (a1.Count() + 1) / 2; i++) a2 += a1[i];
                s = s.Replace(x.Value, a2.ToString()+ ",");
                s = s.Replace(",b", "b");
            }
        }
        s = s.Replace(",", "");
        Console.WriteLine(s);
    }
}



Measured memory_bytes: 45948
def main():
    s = list(map(int,input()))
    n = len(s)
    sq = [2**i for i in range(10)]
    ans = 0
    for i in range(n):
        ans += s[i]*2**i*10**(n-1-i)
    for i in range(n-1):
        for j in range(n-1-i):
            ans += s[i]*2**(n-2-j)*10**j

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main() {
    int n, b[105];
    cin >> n;
    for (int i = 0; i < n - 1; i++) cin >> b[i];

    int a[105];
    a[0] = b[0];
    for (int i = 0; i < n - 2; i++) {
        a[i + 1] = min(b[i], b[i + 1]);
    }
    a[n - 1] = b[n - 2];

    int ans = 0;
    for (int i = 0; i < n; i++) ans += a[i];
    cout << ans << endl;


}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

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

long lcm(long a, long b) {
    return a / gcd(a, b) * b;
}

int main() {
    long n, k;
    cin >> n >> k;
    long a, b, c;
    cin >> a;
    c = a;
    REP(i,n-1) {
        cin >> b;
        a = gcd(a, b);
        c = max(c, b);
    }
    if (k % a == 0 && k <= c) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(int n,int s,int w,int q){
    vector<int> a(n);
    {
        int g=s;
        for(int i=0; i<n; i++) {
            a[i]=(g/7)%10;
            if(g%2==0) g=(g/2);
            else g=(g/2)^w;
        }
    }

    if(q==2){
        int ans=0,count=0;
        for(int i=n-1; i>=0; --i){
            if(a[i]%2==0) ++count;
            if(a[i]!=0) ans+=count;
        }
        cout << ans << endl;
        return;
    }
    if(q==5){
        int ans=0,count=0;
        for(int i=n-1; i>=0; --i){
            if(a[i]==0 or a[i]==5) ++count;
            if(a[i]!=0) ans+=count;
        }
        cout << ans << endl;
        return;
    }

    map<int,int> count;
    int64_t k=1,ans=0,x=0;
    ++count[0];
    for(int i=n-1; i>=0; --i){
        x+=a[i]*k;
        x%=q;
        k*=10;
        k%=q;
        if(a[i]!=0) ans+=count[x];
        ++count[x];
    }
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    for(;;){
        int64_t n,s,w,q;
        cin >> n >> s >> w >> q;
        if(n==0 and s==0 and w==0 and q==0) break;
        solve(n,s,w,q);
    }
    return 0;
}

Measured memory_bytes: 7220
S = input()

strs = {}

for i in range(len(S)):
    if S[i] in strs:
        strs[S[i]] += 1
    else:
        strs[S[i]] = 1

if len(strs) != 2:
    print('No')
    exit()

values = strs.values()
for val in strs.values():
    if val != 2:
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define WR "txt"

void Open() { freopen(WR".in", "r", stdin); freopen(WR".out", "w", stdout); }
void Close() { fclose(stdin); fclose(stdout); }
using namespace std;
int Read()  {
	int val = 0, opt = 1; char ch;
	while (!isdigit(ch = getchar() )) if (ch == '-') opt = -1;
	while (isdigit( ch )) (val *= 10) += ch - '0', ch= getchar();
	return val * opt;
}

char s[100100];
int Ans;

void work()  {
	scanf("%s", s + 1);
	char ch;
	int l = strlen(s + 1);
	Ans = l / 2;
	if (l % 2)  {
		ch = s[l / 2 + 1];
		for (int i = 0;i <= l / 2; i++)  {
			if (s[l / 2 - i + 1] == s[l / 2 + i + 1] && s[l / 2 - i + 1] == ch) Ans++;
			else {
				break;
			}
		}
		printf("%d\n", Ans);
		return ;
	}
	ch = s[l / 2];
	for (int i = 1;i <= l / 2; i++)  
		if (s[l / 2 - i + 1] == s[l / 2 + i] && s[l / 2 - i + 1] == ch) Ans++;
		else  {
			break;
		}
	printf("%d\n", Ans);
}

int main(void)  {
	//Open();
	work();
	//Close();
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>

using namespace std;

#define rep(i,N) for (int i = 0; i < N; i++)
#define llong long long

llong N, K, Q;
vector<llong> a;

const string rep[2] = {"No", "Yes"};

int main() {
    cin >> N >> K >> Q;
    a.resize(N);
    rep(i,Q) {
        llong temp; cin >> temp;
        a[--temp]++;
    }
    rep(i,N) {
        cout << rep[(K-Q+a[i] > 0)] << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  map<int, int> ans;
  reps(x, 100){
    reps(y, 100){
      reps(z, 100){
	ans[x * x + y * y + z * z + x * y + y * z + z * x] ++;
      }
    }
  }
  reps(i, n){
    cout << ans[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 5340
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    a.sort()

    import bisect

    ok = 0
    ng = 2 * max(a) + 1

    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        count = 0
        i = 0
        for elem in a:
            minlim = mid - elem
            count += (n - bisect.bisect_left(a, minlim))

        if count >= m:
            ok = mid
        else:
            ng = mid

    from itertools import accumulate

    a_cum = list(accumulate(a[::-1]))
    a_cum = a_cum[::-1] + [0]
    ans = 0
    j = n
    cnt_over = 0

    for elem in a:
        minlim = ok - elem + 1
        idx = bisect.bisect_left(a, minlim)
        ans += a_cum[idx]
        ans += elem * (n - idx)
        cnt_over += (n - idx)

    ans += ok * (m - cnt_over)

    print(ans)


if __name__ == '__main__':
    main()


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

template<typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b%a, a);
}

template<typename T>
T lcm(T a, T b) {
  return (a*b)/gcd(b%a, a);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
  int a, b;
  cin >> a >> b;
  if (a >= 13) {
    cout << b << endl;
  } else if (a >= 6) {
    cout << b/2 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
const int MAX_D = 10;

int sol[1024];
const int INF = 2000;

int main() {
  int d, g;
  cin >> d >> g;
  g /= 100;
  vector<int> p(d);
  vector<int> c(d);
  rep(i, d) cin >> p[i] >> c[i];
  rep(i, d) c[i] /= 100;

  rep(bm, 1 << d) {
    int di = 0;
    int nowscore = 0;
    vector<int> cnt(d);
    rep(di, d) if(bm >> di & 1) {
      cnt[di] = p[di];
      nowscore += (di + 1) * p[di];
      nowscore += c[di];
    }
    int nowsolved = 0;
    rep(di, d) nowsolved += cnt[di];
    sol[bm] = nowsolved;
    if(nowscore >= g) continue;
    for(int di = d - 1; di >= 0; di--) {
      if(bm >> di & 1) continue;
      cnt[di] = min(p[di], (g - nowscore + di) / (di + 1));
      nowscore += cnt[di] * (di + 1);
      sol[bm] += cnt[di];
      if(g < nowscore) break;
    }
  }
  int ans = INF;
  rep(bm, 1 << d) ans = min(ans, sol[bm]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
int main() {
    int p, q, r;
    int ans = 0;
    cin >> p >> q >> r;
    ans = min(p+q, min(q+r, r+p));
    cout << ans << endl;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    if(a > b){
        rep(i,a){
            cout << b;
        }
    }

    else{
        rep(i,b){
            cout << a;
        }
    }
    return 0;
}

Measured memory_bytes: 256
from collections import deque

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

graph=[[] for _ in range(N)]
for i in range(M):
    A,B=map(int,input().split())
    A-=1
    B-=1
    graph[A].append(B)
    graph[B].append(A)

def bfs(maze,start):
    queue=deque([start])
    d=[float("inf")]*N
    d[start]=0
    while queue:
        x=queue.popleft()
        for y in graph[x]:
            if d[y]==float("inf"):
                d[y]=d[x]+1
                queue.append(y)
    return d

d=bfs(graph,0)
ans=[0]*N
for i in range(1,N):
    flag=0
    for vertex in graph[i]:
        if d[vertex]==d[i]-1:
            ans[i]=vertex+1
            flag=1
            break
    if flag==0:
        print("No")
        exit()
print("Yes")
print(*ans[1:])

Measured memory_bytes: 39236
#include<stdio.h>
int main(void)
{
	int H,W;
	int i, j;
	while(1){
	scanf("%d %d" ,&H ,&W);
	if(H == 0 && W == 0) break;
		for ( i = 0; i < H; i++ ){
		for ( j = 0; j < W; j++ ){
	if(j==0||j==W-1||i==0||i==H-1){
			printf("#");
	}else{
			printf(".");
		}
	}
		printf("\n");
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 2588
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

ull count2(ull a)
{
  ull count = 0;
  while (a % 2 == 0)
  {
      a /= 2;
      count++;
  }
  return (count);
}

int main()
{
  int N; cin >> N;
  vector<ull> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
  
  long count = 0;
  int min;
  min = count2(a[0]);
  
  for (int i = 1; i < N; i++)
  {
    if (min > count2(a[i]))
      min = count2(a[i]);
  }
  cout << min << endl;  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

int main()
{
    long long k;
    string s, ans;
    cin >> s >> k;
    ans = "1";
    for (long long i = 0; i < k; ++i){
        if (s[i] != '1') {
            ans = s[i];
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

struct LowestCommonAncestor {

  int V, MAX_LOG_V;
  vector<vector<int>> edge;

  vector<vector<int>> parent;
  vector<int> depth;

  LowestCommonAncestor(int V, int MAX_LOG_V = 17) : V(V), MAX_LOG_V(MAX_LOG_V) {
    edge.resize(V);
    parent.resize(MAX_LOG_V);
    REP(i, MAX_LOG_V) parent[i].resize(V);
    depth.resize(V);
  }

  void add_edge(int a, int b) {
    edge[a].push_back(b);
    edge[b].push_back(a);
  }

  void dfs(int v, int par, int dep) {
    parent[0][v] = par;
    depth[v] = dep;
    for (auto child : edge[v]) {
      if (child != par) dfs(child, v, dep + 1);
    }
  }

  void init(int root = 0) {
    dfs(root, -1, 0);
    for (int k = 0; k + 1 < MAX_LOG_V; k++) {
      for (int v = 0; v < V; v++) {
        if (parent[k][v] < 0) {
          parent[k+1][v] = -1;
        } else {
          parent[k+1][v] = parent[k][parent[k][v]];
        }
      }
    }
  }

  tuple<int, int, int> run(int u, int v) {
    int u_cnt = 0, v_cnt = 0;
    bool swapflag = false;
    if (depth[u] > depth[v]) swap(u, v), swapflag = true;
    for (int k = 0; k < MAX_LOG_V; k++) {
      if ((depth[v] - depth[u]) >> k & 1) {
        v = parent[k][v];
        v_cnt += 1 << k;
      }
    }
    if (u == v) {
      if (swapflag) swap(u_cnt, v_cnt);
      return make_tuple(u, u_cnt, v_cnt);
    }
    for (int k = MAX_LOG_V - 1; k >= 0; k--) {
      if (parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
        u_cnt += 1 << k;
        v_cnt += 1 << k;
      }
    }
    u_cnt++, v_cnt++;
    if (swapflag) swap(u_cnt, v_cnt);
    return make_tuple(parent[0][u], u_cnt, v_cnt);
  }

  int get_cntup_node(int v, int cnt) {
    for (int k = MAX_LOG_V - 1; k >= 0; k--) {
      if (cnt >> k & 1) {
        v = parent[k][v];
      }
    }
    return v;
  }
};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  LowestCommonAncestor lca(N);
  REP(i, N) {
    int K; cin >> K;
    REP(_, K) {
      int c; cin >> c;
      lca.add_edge(i, c);
    }
  }

  lca.init();

  int Q; cin >> Q;
  REP(i, Q) {
    int u, v; cin >> u >> v;
    int anc, u_cnt, v_cnt; tie(anc, u_cnt, v_cnt) = lca.run(u, v);
    cout << anc << endl;
  }

  return 0;
}

Measured memory_bytes: 18324
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main(){

  	int W, H, x, y, r;
	cin >> W >> H >> x >> y >>r;
  	bool answer = false;
  
  	if(x>0 && y >0){
  		if(W >= x+r && H >= y+r ) answer = true;
    }
  	
  	if(answer) cout << "Yes" << endl;
  	else cout << "No" << endl;
  	return 0;
}


Measured memory_bytes: 3104
#include<stdio.h>
#define N 100
int main(void){
	int A[N], n, v, i, j;
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", A+i);
	}
	for(i=0; i<n; i++){
		v = *(A+i);
		j = i-1;
		while(j >= 0 && *(A+j) > v){
			*(A+j+1) = *(A+j);
			j--;
		}
		*(A+j+1) = v;
		for(j=0; j<n-1; j++){
			printf("%d ", *(A+j));
		}
		printf("%d\n", *(A+j));
	}
    return 0;
}

Measured memory_bytes: 600
///   ***   ---   |||		 In the name of ALLAH		|||   ---   ***   ///



#include<bits/stdc++.h>
using namespace std;


typedef long long ll;
typedef vector<int> vi;
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 double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {			cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

ll gcd ( ll a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }


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

const int mx = 2e5+123;
ll a[mx];

int main()
{
	optimize();

	int n;
	cin >> n;

	for ( int i = 1; i <= n; i++ ) cin >> a[i];

	ll Mx = 0, ans = 0;
	for ( int i = 1; i <= n; i++ ) {
		if ( a[i] < Mx ) ans += abs ( a[i] - Mx );
		Mx = max ( Mx, a[i] );
	}

	cout << ans << endl;


	return 0;
}


















Measured memory_bytes: 5208
#include "bits/stdc++.h"
using namespace std;

int main(){

	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif

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

	int n; cin >> n;
	int ans = 0;
	for(int i=0; i<n;i++){
		int a; cin >> a;
		if(i%2 == 0){
			if(a%2 == 1) ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 50
#define M 1000000010
ll s[N], t[N];

int main(){
	ll n, q;
	cin>>n>>q;
	s[0] = 1; t[0] = 0; t[1] = 1;
	rep(i, N-2){
		s[i+1] = s[i]*n;
		t[i+2] = t[i+1]+s[i+1];
		if(t[i+2]>M) break;
	}
	while(q--){
		ll a, b;
		cin>>a>>b;
		if(n==1){
			cout<<min(a, b)<<endl;
			continue;
		}
		if(a<b) swap(a, b);
		int p = 0;
		while(t[p]<a) p++;
		while(a!=b){
			if(a<b) swap(a, b);
			while(t[p-1]>=a) p--;
			ll a2 = a-t[p-1];
			a = t[p-2]+1+(a2-1)/n;
		}
		cout<<a<<endl;
	}
	return 0;
}


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

using namespace std;


void solve()
{
	int n;
	while (cin >> n, n)
	{
		vector<int> h(n + 1);
		for (int i = 0; i <= n; ++i)
		{
			cin >> h[i];
		}
		for (int i = 0; i <= n; ++i)
		{
			vector<int> use;
			for (int j = 0; j <= n; ++j)
			{
				if (j == i)
				{
					continue;
				}
				use.push_back(h[j]);
			}
			bool isAllSameDiff = true;
			int diff = use[1] - use[0];
			for (int j = 2; j < use.size(); ++j)
			{
				if (use[j] - use[j - 1] != diff)
				{
					isAllSameDiff = false;
					break;
				}
			}
			if (isAllSameDiff)
			{
				cout << h[i] << endl;
				break;
			}
		}
	}
}

int main()
{
	solve();
	return(0);
}

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

using namespace std;
long long gcd(long long a, long long b){
	if(b==0){
		return a;
	}
	return gcd(b,a%b);
}

long long lcm(long long a, long long b){
	long long g = gcd(a,b);
	return a/g * b;
}

int main(){
	long long i,n,m;
	string s,t;
	char a[100010],b[100010];
	cin >> n >> m >> s >> t;
	long long k = lcm(n,m);
	for(i=0;i<n;i++){
		a[i] = s[i];
	}
	for(i=0;i<m;i++){
		b[i] = t[i];
	}
	for(i=0;i<n;i++){
		if(i*m%n==0){
			if(i*m/n < n && a[i]!=b[i*m/n]){
				cout << -1 << endl;
				//cout << i << endl;
				return 0;
			}
		}
	}
	for(i=0;i<m;i++){
		if(i*n%m==0){
			if(i*n/m < m && b[i]!=a[i*n/m]){
				cout << -1 << endl;
				//cout << i << endl;
				return 0;
			}
		}
	}
	cout << k << endl;
}

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

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            var d = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
            Console.WriteLine("a {0} b", d[0] == d[1] ? "==" : (d[0] - d[1]) >> 31 == 0 ? ">" : "<" );
        }
    }
}

Measured memory_bytes: 5700
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int w, h;
string s[70];
string dp[70][70];

bool check(int i, int j, string &prev) {
	if (i >= h || j >= w) return false;
	if (prev.length() > 0) {
		return '0' <= s[i][j] && s[i][j] <= '9';
	}
	return '1' <= s[i][j] && s[i][j] <= '9';
}

string Max(string a, string b) {
	if (a.length() > b.length()) return a;
	if (b.length() > a.length()) return b;
	return max(a, b);
}

int main() {
	int i, j;
	
	while (cin >> w >> h) {
		if (!w) break;
		rep(i, h) cin >> s[i];
		rep(i, h) {
			rep(j, w) {
				if ('1' <= s[i][j] && s[i][j] <= '9') dp[i][j] = s[i][j];
				else dp[i][j] = "";
			}
		}
		
		rep(i, h) {
			rep(j, w) {
				if (check(i + 1, j, dp[i][j])) dp[i + 1][j] = Max(dp[i + 1][j], dp[i][j] + s[i + 1][j]);
				if (check(i, j + 1, dp[i][j])) dp[i][j + 1] = Max(dp[i][j + 1], dp[i][j] + s[i][j + 1]);
			}
		}
		
		string ans = "";
		rep(i, h) {
			rep(j, w) {
				ans = Max(ans, dp[i][j]);
			}
		}
		cout << ans << endl;
	}
	return 0;
}


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

using namespace std;

#define int long long
#define pii pair<int, int>
#define pb push_back

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    set<string> s;
    for(int i = 0; i < n; i++) {
        string p; cin >> p;
        s.insert(p);
    }
    cout << s.size() << endl;

    return 0;
}



Measured memory_bytes: 19280
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    vector<int>v(10,0);

    for(int i = 0;i < 3;i++){
        int a;
        cin >> a;
        v[a-1]++;
    }
    
    if(v[4] == 2 && v[6] == 1)cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
import itertools

if __name__ == '__main__':
    N = int(input())
    F = [list(map(int, input().split())) for _ in range(N)]
    P = [list(map(int, input().split())) for _ in range(N)]

    # print(list(itertools.product(range(2), repeat=10)))

    max1 = -float('inf')
    max2 = -float('inf')

    for target in list(itertools.product(range(2), repeat=10)):
        sum_every_shop = 0
        for i in range(N):
            sum_same_time = 0
            for j in range(10):
                if target[j] == 1 and F[i][j] == 1:
                    sum_same_time += 1

            sum_every_shop += P[i][sum_same_time]

        if max2 < sum_every_shop:
            max2 = sum_every_shop

        if max1 < max2:
            max1, max2 = max2, max1
            result_target = target

    if result_target == (0, 0, 0, 0, 0, 0, 0, 0, 0, 0):
        print(max2)
    else:
        print(max1)


Measured memory_bytes: 3188
N, K = map(int, input().split())
A = list(map(int, input().split()))

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

A.sort()
max_sum, min_sum = 0, 0
for i in range(N-1, K-2, -1):
    max_i = A[i]
    max_sum += A[i] * cmb(i, K-1, p) % p
    max_sum %= p

    j = N - 1 - i
    min_j = A[j]
    min_sum += A[j] * cmb(i, K-1, p) % p
    min_sum %= p

ans = (max_sum - min_sum) % p

print(ans)

Measured memory_bytes: 26072
#include <bits/stdc++.h>
using namespace std;
int main(){
long long int n,c,k,now=0,count=0;
  cin >> n >> c >> k;
  long long int t[n];
  for (int i=0;i<n;i++)cin >> t[i];
  sort (t,t+n);
  while(now<n){
    int fuya=0;
    for (int i=now;i<min(now+c,n);i++){
      if (t[now]+k>=t[i])fuya++;
    }
    count++;
    now+=fuya;
  }
  cout << count <<endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long INF=INT_MAX/4;
const long long MOD=1'000'000'007;
const double EPS=1e-14;
const bool DEBUG=true;

const string YES = "YES";
const string NO = "NO";
const string Yes = "Yes";
const string No = "No";

template<class T>
void debug(T head){
    if(DEBUG){
        cout<<head<<endl;
    }
}

template <class Head, class... Body>
void debug(Head head, Body... body){
    if(DEBUG){
        cout<<head<<" ";
        debug(body...);
    }
}

/////


class Operation{
public:
    int y1, x1, y2, x2;
};

void answer(){
    int H, W;
    cin>>H>>W;

    vector<vector<int>> a(H, vector<int>(W));
    for(int i=0; i<H; ++i){
        for(int j=0; j<W; ++j){
            cin>>a[i][j];
        }
    }

    int N=0;
    vector<Operation> ope;
    for(int i=0; i<H; ++i){
        for(int j=0; j<W-1; ++j){
            if(a[i][j] & 1){
                ope.push_back({i, j, i, j+1});
                a[i][j]--;
                a[i][j+1]--;
                N++;
            }
        }
    }

    for(int i=0; i<H-1; ++i){
        if(a[i][W-1] & 1){
            ope.push_back({i, W-1, i+1, W-1});
            a[i][W-1]--;
            a[i+1][W-1]++;
            N++;
        }
    }

    cout<<N<<endl;
    for(int i=0; i<N; ++i){
        cout<<ope[i].y1+1<<" "<<ope[i].x1+1<<" "<<ope[i].y2+1<<" "<<ope[i].x2+1<<endl;
    }

    return;
}

/////

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.precision(16);

    answer();

    return 0;
}


Measured memory_bytes: 5236
#include <stdio.h>
#define MAX_N (105)

int A[MAX_N];

static
void
checkArray( int *p_A, int N ) {
    int i;
    for ( i = 0; i < N; i++ ) {
	printf("%d%c", p_A[i], (i == N-1) ? '\n' : ' ');
    }
}


static
void
insertionSort( int *p_A, int N )
{
    int i;
    for ( i = 1; i < N; i++ ) {
	int v = p_A[i];
	int j = i - 1;

	checkArray( p_A, N );

	while ( j >= 0 && v < p_A[j] ) {
	    p_A[j+1] = p_A[j];
	    j--;
	}
	p_A[j+1] = v;
    }

    checkArray( p_A, N );
}

int main()
{
    int N;
    int i;
    scanf("%d", &N);
    
    for ( i = 0; i < N; i++ ) {
	scanf("%d", &A[i]);
    } 
    
    insertionSort( A, N );


    return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	int x, n;
	cin >> x >> n;
	vector<bool> a(102, true);
	rep(i,n){
		int p; cin >> p;
		a[p] = false;
	}
	pair<int, int> ans(99999, -1);
	rep(i,102){
		if(!a[i]) continue;
		int dif = abs(i-x);
		ans = min(ans, pair<int, int>(dif, i));
	}
	cout << ans.second << endl;
	return 0;
}

Measured memory_bytes: 3604
from collections import Counter
n = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

div = make_divisors(n)
a = 10**12
for i in range( 0, len(div[:-1]), 2):
    a = min(a, div[i]+div[i+1])
if len(div) % 2 == 1:
    a = min(a, div[-1]*2)
print(a-2)

Measured memory_bytes: 3564
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

answer = 0
A.append(0)

for i in range(0,N):
    answer = answer + B[A[i]-1]
for j in range(0,N):
    if (A[j+1] - A[j] ) == 1:
        answer = answer +  C[A[j]-1]
print(answer)        


Measured memory_bytes: 3064
def cmb(n,r,p):
    if r<0 or r>n:
        return 0
    r = min(r,n-r)
    return fact[n] * factinv[r] *factinv[n-r] % p
p =  998244353
N = 2*(10**5)+1

fact=[1,1] #fact[n] = (n! modp)
factinv = [1,1] #factinv[n] = ((n!)^(-1) modp)
inv = [0,1] #factinv計算用

for i in range(2,N+1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p%i]*(p//i)) %p)
    factinv.append((factinv[-1] * inv[i]) %p)


    

n,m,k = map(int,input().split())
ans = 0
beki = [1,m-1]
for i in range(2,N+1):
    beki.append(((beki[-1]*(m-1)) % p))
for x in range(k+1):
    ans += (((cmb(n-1,n-x-1,p) * m) %p)*beki[n-x-1]) %p
    ans = ans % p
print(ans)

Measured memory_bytes: 41108
#include <stdio.h>
int n, m, k[10], s[10][10], p[10];
int check(int state) {
	int sw[10], on[10], i, j;
	for(i = 0; i < n; i++)
		sw[i] = state & (1 << i);
	for(i = 0; i < m; i++) {
		on[i] = !p[i];
		for(j = 0; j < k[i]; j++)
			if(sw[s[i][j]])
				on[i] = !on[i];
		if(!on[i])
			break;
	}
	return i == m;
}
int main() {
	int c = 0, i, j;
	scanf("%d %d", &n, &m);
	for(i = 0; i < m; i++) {
		scanf("%d", &k[i]);
		for(j = 0; j < k[i]; j++) {
			scanf("%d", &s[i][j]);
			s[i][j]--;
		}
	}
	for(i = 0; i < m; i++)
		scanf("%d", &p[i]);
	
	for(i = 0; i < (1 << n); i++)
		c += check(i);
	printf("%d", c);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	REP(i, n) cin >> a[i];
	vector<bool> dp(k + 1, false);
	dp[0] = false;
	FOR(i, 1, k + 1) {
		REP(j, n) {
			if(i - a[j] >= 0) dp[i] = dp[i] | (!dp[i - a[j]]);
		}
	}
	if(dp[k]) cout << "First" << endl;
	else cout << "Second" << endl;
	return 0;
}

/* --------------------------------------- */


Measured memory_bytes: 256
#include <iostream>

unsigned int calculate_num_monitor (const unsigned int* num_tree_all, const unsigned int* num_range)
{
	return (*num_tree_all + *num_range * 2U) / (*num_range * 2U + 1U);
}

int main (void)
{
	// variables for main process
	register unsigned int N;
	register unsigned int D;

	// STEP.01
	// read out the given data
	std::cin >> N >> D;

	// STEP.02
	// output the answer of this task
	std::cout << calculate_num_monitor (&N, &D) << std::endl;

	// STEP.END
	return EXIT_SUCCESS;
}

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

#define ll long long

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    int cur = 1;
    for (int i = 1; i <= n; i++) {
        if (cur == 2) {
            cout << ans << '\n';
            exit(0);
        }
        cur = a[cur];
        ans++;
    }
    if (cur != 2) cout << -1 << '\n';
    return 0;
}

Measured memory_bytes: 640
n = int(input())
ans = []
for i in range(n):
    a = list(map(int, input().split()))
    a = sorted(a)
    if a[0]**2 + a[1]**2 == a[2]**2:
        ans.append('YES')
    else:
        ans.append('NO')
print(*ans, sep='\n')



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

int main() {
  int H, W, X = 0;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char A;
      cin >> A;
      if (A == '#') X++;
    }
  }
  if (X == H + W - 1) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}

Measured memory_bytes: 3552
/* ***********************************************
Author        :guanjun
Created Time  :2016/10/10 12:01:32
File Name     :1.cpp
************************************************ */
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
	int x,y;
};
struct cmp{
    bool operator()(Node a,Node b){
        if(a.x==b.x) return a.y> b.y;
        return a.x>b.x;
	}
};

bool cmp(int a,int b){
    return a>b;
}
string t="CODEFESTIVAL2016";
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
    #endif
    //freopen("out.txt","w",stdout);
	int n,a,b;
	string s;
	while(cin>>n>>a>>b>>s){
		int num=0,nb=0;
		for(int i=0;i<n;i++){
			if(s[i]=='a'){
				num++;
				if(num<=a+b)puts("Yes");
				else puts("No");
			}
			else if(s[i]=='b'){
				num++;
				nb++;
				if(num<=a+b){
					if(nb<=b)puts("Yes");
					else puts("No"),num--;
				}
				else puts("No");
			}
			else puts("No");
		}
	}
    return 0;
}


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

typedef long long ll;
int MOD = 1000000007;

int main() {
  int S; cin >> S;
  
  vector<ll> dp(2010, 0);
  
  dp[0] = 1;
  int x = 0;
  for (int i = 3; i <= 2010; i++) {
    x += dp[i-3];
    x %= MOD;
    dp[i] = x;
    
  }
  
  cout << dp[S] << endl;
}

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

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

  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d.at(i);
  }

  int sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      sum += (d.at(i) * d.at(j));
    }
  }

  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3572
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<string>
#include<string.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a > b)swap(a, b);
	if (b > c) {
		swap(b, c);
	}
	if (a > b)swap(a, b);
	if (a + b == c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))
lcm = defaultdict(int)


for i in range(N):
    a=A[i]
    for j in range(2,a):
        temp=0
        while a%j==0:
            a=a//j
            temp+=1
        lcm[j]=max(lcm[j],temp)
        if a==1 or j*j>A[i]:
            break
    if a!=1:
        lcm[a]=max(lcm[a],1)
                
        
l=1
for d in lcm.items():
    l*=pow(d[0],d[1])
    

ans=0
mod=10**9+7

for i in range(N):
    ans+=l//A[i]
    
print(ans%mod)

Measured memory_bytes: 48860
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int n, k;
llong T[MAX];

int check(llong p) {
	int i=0;
	for(int j = 0; j < k; j++ ) {
		llong sum = 0;
		while( sum + T[i] <= p) {
			sum += T[i];
			i++;
			if(i == n ) return n;
		}
	}
	return i;
}

int solve() {
	llong left = 0;
	llong right = 100000 * 10000;
	llong mid;
	while(right-left>=1) {
		mid = (left + right) / 2;
		int v = check(mid);
		if(v == n) right = mid;
		else left = mid + 1;
	}
	return right;
}

main() {
	cin >> n >> k;
	for( int i = 0; i < n; i++) cin >> T[i];
	llong ans = solve();
	cout << ans << endl;
}

Measured memory_bytes: 3864
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#define ll long long
long long min(long long a, long long b){
    if(a < b) return a;
    else return b;
}
long long max(long long a, long long b){
    if(a < b) return b;
    else return a;
}
int main(){
  ll int x,point=100;
  scanf("%lld",&x);
  for(ll int ans=0; ;ans++){
    point*=1.01;
    if(x<=point){
     printf("%lld",ans+1);
      return 0;
    }
  }
}
  

Measured memory_bytes: 1736
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 文字列の入力
		String[] s = sc.next().split("");
        String ans = "";
        for(String n : s) {
          if (n.equals("1")) {
            ans += "9";
          } else if (n.equals("9")) {
            ans += "1";
          } else {
            ans += n;
          }
        }
    
		// 出力
		System.out.println(ans);
	}
}


Measured memory_bytes: 23252
storeNum, canNum = input().split()
storeNum = int(storeNum)
canNum = int(canNum)
costs = [0] * storeNum
maxCanNumbers = [0] * storeNum

for i in range(storeNum):
    costs[i], maxCanNumbers[i] = input().split()
    costs[i] = int(costs[i])
    maxCanNumbers[i] = int(maxCanNumbers[i])

currentStoreHasMoreCans = False
totalPrice = 0

costs, maxCanNumbers = (list(x) for x in zip(*sorted(zip(costs, maxCanNumbers))))

for i in range(storeNum):
    if canNum >= maxCanNumbers[i]:
        totalPrice = totalPrice + costs[i] * maxCanNumbers[i]
        canNum = canNum - maxCanNumbers[i]
        if canNum is 0:
            break
    else:
        totalPrice = totalPrice + costs[i] * canNum
        canNum = 0    
        break

print(totalPrice)

Measured memory_bytes: 26780
#include<stdio.h>
int main(){
  int h,w,i,j;
  while(1){
  scanf("%d %d",&h, &w);
  if(w*h==0)break;
  for(j=0;j<h;j++){
    for(i=0;i<w;i++){
      if((i+j)%2==0){
	printf("#");
      }	else printf("."); 
    } 
    printf("\n");
 }
  printf("\n");
  }
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


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

}



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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

ll k,n;
vll a;

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  cin >> k >> n;
  a.resize(n);
  rep(i,0,n) cin >> a[i];
   sort(a.begin(),a.end());
  
  ll res=k;
  
  ll m=a[0]+(k-a[n-1]);
  rep(i,0,n-1) m=max(a[i+1]-a[i],m);
  
  cout << res-m << endl;
  
 
 
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	char str[a+b+1];
	scanf("%s", str);
	int flag = 0;
	for (int i=0; str[i] != '\0'; i++){
		if (str[i] >= '0' && str[i] <= '9'){
			continue;
		}
		else{
			flag++;
		}
		if (str[a] != '-'){
			flag = 0;
			break;
		}
		if (flag > 1){
			break;
		}
	}
	
	if (flag == 1){
		printf("Yes\n");
	}	
	else{
		printf("No\n");
	}
    return 0;
}


Measured memory_bytes: 1628
using System;

class Program
{
    static void Main(string[] args)
    {

        string[] a = Console.ReadLine().Split(' ');
        string[] b = Console.ReadLine().Split(' ');

        int n = int.Parse(a[0]);
        int k = int.Parse(a[1]);

        int[] l = new int[n];
        for (int i = 0; i < n; i++)
        {
            l[i] = int.Parse(b[i]);
        }

        for (int p = 1; p < n; p++)
        {

            for (int q = p; q > 0; q--)
            {
                if (l[q] < l[q - 1])
                {
                    int t = l[q - 1];
                    l[q - 1] = l[q];
                    l[q] = t;
                }
                else
                {
                    break;
                }
            }
        }

        int ans = 0;
        for (int r = n - 1; r >= n - k; r--)
        {
            ans += l[r];
        }

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
from bisect import bisect_left
from itertools import accumulate
def resolve():
    def getCount(x):
        count = 0
        for Ai in A:
            idx = bisect_left(A, x - Ai)
            count += N - idx
        return count >= M


    N, M = map(int, input().split())
    A = sorted(map(int, input().split()))
    A_r = A[::-1]
    B = [0] + list(accumulate(A_r))

    MIN = 0
    MAX = 2 * 10 ** 5 + 1
    while MAX - MIN > 1:
        MID = (MIN + MAX) // 2
        if getCount(MID):
            MIN = MID
        else:
            MAX = MID

    ans = 0
    count = 0

    for Ai in A_r:
        idx = bisect_left(A, MIN - Ai)
        ans += Ai * (N - idx) + B[N - idx]
        count += N - idx
    print(ans - (count - M) * MIN)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 21036
// AtCoder My Practice
// author: Leonardone @ NEETSDKASU

fn modpow(x: i64, p: i64, m: i64) -> i64 {
    if p == 0 {
        1
    } else if p % 2 == 0 {
        modpow((x * x) % m, p / 2, m)
    } else {
        (x * modpow(x, p - 1, m)) % m 
    }
}
struct ModBinomial { m: i64, f: Vec<i64>, p: Vec<i64> }
impl ModBinomial {
    fn new(n: i64, m: i64) -> ModBinomial {
        let mut f = vec![1; n as usize + 1];
        let mut p = vec![1; f.len()];
        for i in 2..f.len() {
            f[i] = (i as i64 * f[i - 1]) % m;
            p[i] = modpow(f[i], m - 2, m);
        }
        ModBinomial { m: m, f: f, p: p }
    }
    fn bin(&self, n: i64, k: i64) -> i64 {
        (((self.f[n as usize] * self.p[k as usize])
            % self.m) * self.p[(n - k) as usize]) % self.m
    }
}


fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let m = 998244353_i64;
    let n = get!();
    let a = get!();
    let b = get!();
    let k = get!();
    let mb = ModBinomial::new(300_000, m);
    let mut ans = 0;
    for ac in 0..n+1 {
        let rem = k - ac * a;
        if rem < 0 { continue; }
        let bc = rem / b;
        if bc * b != rem { continue; }
        if bc > n { continue; }
        if ac + bc > n + n { continue; }
        ans += (mb.bin(n, ac)
                 * mb.bin(n, bc)
                 ) % m;
        ans %= m;
    }
    if k == 0 { ans = 1; }
    println!("{}", ans);
}

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

const long long int INF = 1e15;

int main() {
  long long int N;
  cin>>N;
  long long int ans = N - 1;
  for(int i=1;i<=sqrt(N);i++){
    if(N % i == 0){
      ans = min(ans, i + (N / i) - 2);
    }
  }
  cout<<ans<<endl;
}

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

#define ll long long

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int h, w;
    cin >> h >> w;
    string s[h + 1];
    for (int i = 0; i < h; i++) {
        cin >> s[i];
        s[i] += 'X';
    }
    
    vector<vector<int>> dp(h + 1, vector<int>(w + 1, 1e9));
    dp[0][0] = (s[0][0] == '#');
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (s[i][j] == '.' && s[i + 1][j] == '#'));
            dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + (s[i][j] == '.' && s[i][j + 1] == '#'));
        }
    }

    cout << dp[h - 1][w - 1] << '\n';
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#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>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

ll add (int i, int n, int k) {
    ll mod = 0ll;
    ll ret = (i-k)*(n/i)+max((n%i)-k+1, 0);
    if (k == 0) --ret;
    //cout << i << " " << ret << endl;
    return ret;
}

int main(int argc, char const *argv[]) {
    int n, k;
    cin >> n >> k;
    ll ans = 0ll;
    for (int i = k+1; i <= n; ++i) {
        ans += add(i, n, k);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	int n;
	std::string s;
	
	std::cin>>n;
	std::cin>>s;

	for(int i=0; i<s.size(); i++){
		int num= s[i]- 'A';
		char c= 'A' + (num+n)%26;

		std::cout<< c;
	}

	std::cout<<std::endl;

	return 0;
}

Measured memory_bytes: 256