akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define files(name) name!=""?freopen(name".in","r",stdin),freopen(name".out","w",stdout):0
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define elif else if
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;
///#define int long long

typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;

const int arr=2e5+10;
const int ar=2e3+10;
const ld pi=acos(-1);
const ld eps=1e-10;
const ll md=1e9+7;

///---program start---///

#define ar (int)(5000+10)

int bpow(int a,int n)
{
    int res=1;
    while (n){
        if (n&1){
            res=1ll*res*a%md;
        }
        n/=2;
        a=1ll*a*a%md;
    }
    return res;
}

int inv(int a)
{
    return bpow(a,md-2);
}

int dp[ar][ar];

void inc(int& a,int b)
{
    a+=b;
    if (a>=md){
        a-=md;
    }
}

main()
{
    #ifdef Barik
        files("barik");
        freopen("debug.txt","w",stderr);
    #endif



    int n;
    cin>>n;
    string s;
    cin>>s;
    int k=len(s);

    dp[0][0]=1;
    for (int i=0;i<n;i++){
        for (int j=0;j<=i;j++){
            inc(dp[i+1][j+1],1ll*dp[i][j]*2%md);
            inc(dp[i+1][max(0,j-1)],dp[i][j]);
        }
    }
    int ans=1ll*dp[n][k]*inv(bpow(2,k))%md;
    cout<<ans<<"\n";
}


Measured memory_bytes: 96512
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse = True, key = lambda x: abs(x))
mod = 10**9+7
nega = 0
posi = 0
zero = 0
for i in range(n):
    if a[i] > 0:
        posi += 1
    elif a[i] == 0:
        zero += 1
    else:
        nega += 1

if n == k:
    ans = 1
    for i in range(k):
        ans *= abs(a[i])
        ans %= mod
    if nega%2 == 1:
        ans *= -1

elif posi == 0:

    if k % 2 == 0:
        ans = 1
        for i in range(k):
            ans *= abs(a[i])
            ans %= mod

    else:
        if zero > 0:
            ans = 0
        else:
            a.reverse()
            ans = 1
            for i in range(k):
                ans *= abs(a[i])
                ans %= mod

            ans *= -1


else:
    posi = 0
    nega = 0
    zero = 0
    ans = 1
    for i in range(k):
        ans *= abs(a[i])
        ans %= mod

    for i in range(k):
        if a[i] > 0:
            posi += 1
        elif a[i] < 0:
            nega += 1
        else:
            zero += 1

    if zero > 0:
        ans = 0

    elif nega % 2 != 0:
        minposi = 0
        minnega = 0
        for i in range(k-1, -1, -1):
            if a[i] > 0:
                if minposi == 0:
                    minposi = a[i]
            else:
                if minnega == 0:
                    minnega = a[i]

        maxposi = 0
        maxnega = 0
        for i in range(k, n):
            if a[i] > 0:
                if maxposi == 0:
                    maxposi = a[i]
            elif a[i] < 0:
                if maxnega == 0:
                    maxnega = a[i]


        if minposi == 0:
            ans *= pow(abs(minnega), mod-2, mod)
            ans *= abs(maxposi)

        elif abs(minposi*maxposi) <= abs(minnega*maxnega):
            ans *= pow(abs(minposi), mod-2, mod)
            ans *= abs(maxnega)

        else:
            ans *= pow(abs(minnega), mod-2, mod)
            ans *= abs(maxposi)



print(ans % mod)


Measured memory_bytes: 31820
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main(){
	int ans=0,situ=0,cnt[3],min;
	char str[1000001];
	cin>>str;
	for(int i=0;str[i]!='\0';i++){
		if(str[i]=='J'){
			if(situ==1){
				cnt[0]++;
			}
			else{
				cnt[0]=1;cnt[1]=0;cnt[2]=0;
				situ=1;
			}
		}
		else if(str[i]=='O'){
			if(situ==1){
				cnt[1]=1;
				situ=2;
			}
			else if(situ==2){
				cnt[1]++;
			}
			else{
				situ=0;
			}
		}
		else{
			if(situ==2){
				cnt[2]=1;
				situ=3;
			}
			else if(situ==3){
				cnt[2]++;
			}
			else{
				situ=0;
			}
			if(situ>=2){
				min=1000000;
				for(int j=0;j<3;j++){
					//printf("%d ",cnt[j]);
					if(min>cnt[j]) min=cnt[j];
				}//puts("");
				if(ans<min && cnt[1]<=min) ans=min;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2100
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	r := intScanner()
	fmt.Println(3 * r * r)
}


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

int main()
{
    int K, S;
    cin >> K >> S;

    int ans = 0;
    for (int x = 0; x <= K; x++)
    {
        for (int y = 0; y <= K; y++)
        {
            int z = S - x - y;
            if (0 <= z && z <= K)
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int n, ans = 0;
   cin >> n;
   for (int i = 1; i <= n; i += 2)
   {
      int ctr = 0;
      for (int j = 1; j < ceil(sqrt(i)); j++)
      {
         if (i % j == 0)
            ctr += 2;
         if (i == j * j)
            ctr--;
      }
      if (ctr == 8)
         ans ++;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int n,m;
	while(cin>>n>>m,n+m){
		int a[11]={0};
		rep(i,n){
			int b,c;cin>>b>>c;
			a[c]+=b;
		}
		int out=0;
		for(int i=10;i>=0;i--){
			if(a[i])out+=i*(max(0,a[i]-m));
			m=max(0,m-a[i]);
		}
		cout<<out<<endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>

int main()
{
	int A;
	int B;
	std::cin >> A;
	std::cin >> B;
	std::string str;
	if (A > B) {
		for (int i = 0; i < A; i++) {
			std::cout << B;
		}
	}
	else {
		for (int i = 0; i < B; i++) {
			std::cout << A;
		}
	}
}

Measured memory_bytes: 256
def answer():
    N = int(input())
    distances = list(map(int, input().split()))

    result = 1
    mod = 998244353

    if distances[0] != 0:
        result = 0
    elif 0 in distances[1:]:
        result = 0
    else:
        distances.sort()
        maximum = distances[-1]
        counts = [0] * (maximum + 1)
        counts[0] = 1
        for d in distances[1:]:
            counts[d] += 1
            result *= counts[d-1]
            result %= mod

    print(result)


if __name__ == '__main__':
    answer()


Measured memory_bytes: 54324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()	
{
	int n,m,a,sum=0;
	cin>>n>>m;
	vector<int>v(m),w;
	for(int i=0;i<m;i++)cin>>v[i];
	if(n>=m)
	{
		cout<<0<<endl;
		return 0;
	}
	sort(v.begin(),v.end());
	for(int i=1;i<m;i++)
	{	
		w.push_back(abs(v[i]-v[i-1]));
		sum+=v[i]-v[i-1];
	}	
	sort(w.begin(),w.end());
	for(int i=0;i<n-1;i++)
	{
		sum-=w[m-2-i];
	}
	cout<<sum<<endl;
	return 0;
}

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


template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v){
    if(!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p) {
    out << "[" << p.first << ", " << p.second << "]";
    return out;
}
//---------

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    set<int> s;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#define MAX 100000
using namespace std;

struct Queue{
    int head;
    int tail;
    int q[MAX];

    void initialize(){
        head = 0;
        tail = 0;
    }
    bool isEmpty(){
        return (head == tail);
    }
    bool isFull(){
        return (head == (tail+1)%MAX);
    }
    void enqueue(int x){
        if(isFull()){
            cout << "queue overflow\n";
            //exit(0);
        }
        q[tail] = x;
        if(tail == MAX-1){
            tail = 0;
        }
        else{
            tail += 1;
        }
    }
    int dequeue(){
        if(isEmpty()){
            cout << "queue underflow\n";
            //exit(0);
        }
        int x = q[head];
        if(head == MAX-1){
            head = 0;
        }
        else{
            head += 1;
        }
        return x;
    }
};

void calc(Queue q_name, string name[], Queue q_time, int quantum){
    int t_sum = 0;
    while(q_name.head != q_name.tail){
        if(q_time.q[q_time.head] <= quantum){
            t_sum += q_time.dequeue();
            int i_name = q_name.dequeue();
            cout << name[i_name] << " " << t_sum << '\n';
        }
        else{
            t_sum += quantum;
            q_name.enqueue(q_name.q[q_name.head]);
            q_time.enqueue(q_time.q[q_time.head]-quantum);

            if(q_name.head == MAX-1){
                q_name.head = 0;
                q_time.head = 0;
            }
            else{
                q_name.head += 1;
                q_time.head += 1;
            }
        }
    }
}

int main(){
    Queue q_name, q_time;
    int num, quantum;
    string name[MAX];
    int t;

    q_name.initialize();
    q_time.initialize();

    cin >> num >> quantum;
    for(int i=0; i<num; i++){
        string str;
        cin >> str;
        name[i] = str;
        cin >> t;
        q_name.enqueue(i);
        q_time.enqueue(t);
    }

    calc(q_name, name, q_time, quantum);

    return 0;
}


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

using namespace std;

int main() {
    char a[4], b[4];

    scanf("%s %s", a, b);

    if (a[0]==b[2] && a[1]==b[1] && a[2]==b[0]) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

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

int main(){

    int n, m, x;
    set<int> a;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x;
        a.insert(x);
    }
    
    cin >> m;
    set<int> b;
    for(int i = 0; i < m; i++){
        cin >> x;
        b.insert(x);
    }

    set<int> dif;
    set_difference(a.begin(), a.end(), b.begin(), b.end(), inserter(dif, dif.end()));

    for(auto x : dif){
        cout << x << endl;
    }

    return 0;
}


Measured memory_bytes: 31212
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<int> vec;

int h, w;
char mp[52][52];
void solve(){
	rep(i, 52)rep(j, 52)mp[i][j] = '.';
	cin >> h >> w;
	rep1(i, h)rep1(j, w)cin >> mp[i][j];
	rep1(i, h)rep1(j, w) {
		if (mp[i][j] == '.') {
			int cnt = 0;
			for (int x = i - 1; x <= i + 1; x++) {
				for (int y = j - 1; y <= j + 1; y++) {
					if (mp[x][y] == '#')cnt++;
				}
			}
			mp[i][j] = '0' + cnt;
		}
	}
	rep1(i, h) {
		rep1(j, w) {
			cout << mp[i][j];
		}
		cout << endl;
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(6);
	//init();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 256
(* 配列版素集合データ構造 *)
module UnionFind : sig
  type t

  module Class : sig
    type t
    val compare : t -> t -> int
  end

  (* n要素の素集合データ構造を作る *)
  val make : int -> t
  (* 要素がどの集合に属するか調べる *)
  (* 要素は0からn-1の整数である必要がある *)
  val find : t -> int -> Class.t
  (* 与えられた集合同士を合併する *)
  (* 破壊的操作であるため注意 *)
  val unite : t -> Class.t -> Class.t -> unit
  (* 与えられた集合に属する要素の数を求める *)
  val cardinal : t -> Class.t -> int
end = struct
  type t = int array

  module Class = struct
    type t = int
    let compare = compare
  end

  let make n = Array.make n (-1)

  let rec find uf x =
    if uf.(x) < 0 then x
    else begin
      let y = find uf uf.(x) in
      uf.(x) <- y; y
    end

  let unite uf x y =
    if x <> y then begin
      let x, y = if uf.(x) <= uf.(y) then x, y else y, x in
      uf.(x) <- uf.(x) + uf.(y);
      uf.(y) <- x
    end

  let cardinal uf x = ~- (uf.(x))
end

module WeightedGraph
  (Weight : sig
    type t
    val compare : t -> t -> int
  end) :
sig
  type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

  (*
   * HashtblやMapを用いているとプリム法と大差ない計算時間になってしまうため，
   * より汎用的な実装が欲しければそちらを当たること
   *)
  val kruskal :
    (* 頂点の数n *)
    int ->
    (* 辺のリスト *)
    (* 頂点は0からn-1までの整数でなくてはならない *)
    (int * int * Weight.t) church_list ->
    (* 最小全域木に含まれる辺のリスト
       畳み込む関数と初期値まで与えられて初めて計算を開始するので，
       最小全域木に対して色々な操作をしたい場合は，
       一度リストにして覚えておくとよい．
       最小全域木の重さの和だけ欲しいとか一回しか使わない場合は，
       直接畳み込む関数と初期値を与えるとdeforestationになっていい感じ． *)
    (int * int * Weight.t) church_list
end =
struct
  module WMap = Map.Make (Weight)
  type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

  let kruskal n es =
    { fold = fun f init ->
      let uf = UnionFind.make n in
      WMap.fold (fun w ->
        List.fold_right @@ fun (u, v) acc ->
        let c = UnionFind.find uf u in
        let d = UnionFind.find uf v in
        if UnionFind.Class.compare c d = 0
        then acc
        else (UnionFind.unite uf c d; f (u, v, w) acc))
      (es.fold (fun (u, v, w) m -> WMap.add w ((u, v) :: try WMap.find w m with Not_found -> []) m) WMap.empty) init }
end
 
module Int = struct
  type t = int
  let compare = compare
end
 
module G = WeightedGraph (Int)
 
let () =
  let n = Scanf.scanf "%d\n" @@ fun n -> n in
  let xys = Array.to_list @@ Array.init n @@ fun i ->
    Scanf.scanf "%d %d\n" @@ fun x y -> x, y, i in
  let xedges =
    List.sort (fun (x, _, _) (x', _, _) -> compare x x') xys
    |> (fun ((x, y, i) :: xys) ->
        List.fold_left (fun (acc, x, y, i) (x', y', j) ->
          ((i, j, x' - x) :: acc, x', y', j)) ([], x, y, i) xys)
    |> (fun (acc, _, _, _) -> acc) in
  let yedges =
    List.sort (fun (_, y, _) (_, y', _) -> compare y y') xys
    |> (fun ((x, y, i) :: xys) ->
        List.fold_left (fun (acc, x, y, i) (x', y', j) ->
          ((i, j, y' - y) :: acc, x', y', j)) ([], x, y, i) xys)
    |> (fun (acc, _, _, _) -> acc) in
  Printf.printf "%d\n" @@
  (G.kruskal n { G.fold = fun f acc -> List.fold_right f xedges @@ List.fold_right f yedges acc }).G.fold (fun (_, _, d) -> ( + ) d) 0


Measured memory_bytes: 39036
#include<bits/stdc++.h>
using namespace std;
map<char,char> mem;
main(){
  char c;
  int n,m;
  while(cin>>n,n){
    mem.clear();
    for(int i=0;i<n;i++){
      char a,b;
      cin>>a>>b;
      mem[a]=b;
    }
    cin>>m;
    for(int i=0;i<m;i++){
      cin>>c;
      if(mem.find(c)!=mem.end()){
	cout<<mem[c];
      }
      else{
	cout<<c;
      }
    }
    cout<<endl;
  }
}

Measured memory_bytes: 1188
#include<iostream>
#include<algorithm>
#include<cstdlib>

using namespace std;

int N,d[100001],x=0,y=0,z;

int main(){

  cin >>N;

  for(int i=0;i<N;i++){
    cin >> d[i];
  }

  sort(d,d+N);

 z=d[N/2-1]-d[N/2];

 z=abs(z);



 cout << z <<endl;


  return 0;
}


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


int abc117_b(){
    // 入力
    int a,b;
    cin >> a;
    vector<int> v;
    for (int i = 0; i < a; ++i) {
        cin >> b;
        v.push_back(b);
    }
    
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    int c=0;
    for(int i=1;i<a;++i){
        c+=v[i];
    }
    string flag = v[0]<c ? "Yes" : "No";
    cout << flag << endl;
    return 0;
}

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


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

int main() {
  int col,row,col_,row_;
  col_ = 0;
  row_ = 0;
  cin >> col >> row;
  vector<vector<char>> map(col,vector<char>(row));
  vector<bool> col_e(col,false);
  vector<bool> row_e(row,false);
  
  //cout << col_ << endl;
  
  for(int i = 0; i < col; i++){
    for(int j = 0; j < row; j++){
      cin >> map.at(i).at(j);
      if(map.at(i).at(j) == '#')
        col_e.at(i) = true;
      //cout << map.at(i).at(j);
    }
    if(col_e.at(i)){
      col_++;
    }
    //cout << endl;
  }
  
  for(int i = 0; i < row; i++){
    for(int j = 0; j < col; j++){
      if(map.at(j).at(i) == '#')
        row_e.at(i) = true;
    }
    if(row_e.at(i)){
      row_++;
    }
    //cout << row_e.at(i);
  }
  //cout << "col_" << col_ << " row_" << row_ << endl;
  for(int i = 0; i < col; i++){
    for(int j = 0; j < row; j++){
      //cout << col_e.at(i) << row_e.at(j) << ':' << map.at(i).at(j) << ' ';
      if(col_e.at(i) == 1 && row_e.at(j) == 1)
        cout << map.at(i).at(j);
    }
    if(col_e.at(i))
      cout << endl;
  }
                            
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 1200

int main(){
 int i=0,j;
 char c[MAX];
  gets(c);
  while(c[i]!='\0'){
   if(isupper(c[i])){printf("%c",tolower(c[i]));}
   else if(islower(c[i])){printf("%c",toupper(c[i]));}
   else{printf("%c", c[i]);}
   i++;
  }
 printf("\n");
 return 0;
}
  

Measured memory_bytes: 524
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)
#define FORR(i,n,m) for(ll i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string str;
    cin >> str;
    REP(i,(int)str.length()){
        if(str[i] == '1'){
            cout << 9;
        }else{
            cout << 1;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
   
    while(true){
      int m = sc.nextInt();
      int f = sc.nextInt();
      int r = sc.nextInt();
      if(m==-1 && f==-1 && r==-1){
        break;
      }
      if(m==-1 || f == -1){
        System.out.println("F");
      }else if(m+f>=80){
        System.out.println("A");
      }else if(m+f>=65){
        System.out.println("B");
      }else if(m+f>=50){
        System.out.println("C");
      }else if(m+f>=30){
        if(r>=50){
          System.out.println("C");
        }else{
          System.out.println("D");
        }
      }else{
        System.out.println("F");
      }
    }
  }
}


Measured memory_bytes: 26312
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Satoshi
{
	class Program
	{
		public static void Main(string[] args)
		{
			int x = 0;
			int max = 0;
			int n = int.Parse(Console.ReadLine());
			string s = Console.ReadLine();
			for (int i = 0; i < n; i++)
			{
				if (s[i] == 'I')
				{
					x++;
					if (max < x)
						max = x;
				}
				else if (s[i] == 'D')
				{
					x--;
				}
			}
			Console.WriteLine(max);
		}
	}
}

Measured memory_bytes: 2648
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  ll a,b,x;
  cin>>a>>b>>x;
  ll c=a%x;
  if(c!=0) a+=(x-c);
  ll d=b-a;
  cout<<(d+x)/x<<endl;
  return 0;
}




Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int antenas[5], K, aux;

    for (int i = 0; i < 5; i++)
    {
        scanf("%d", &antenas[i]);
    }
    scanf("%d", &K);
    for (int i = 0; i < 5; i++)
    {
        for (int j = (i + 1); j < 5; j++)
        {
            if (antenas[i] > antenas[j])
            {
                aux = antenas[i];
                antenas[i] = antenas[j];
                aux = antenas[j];
            }
        }
    }

    if ((antenas[4] - antenas[0]) <= K)
        printf("Yay!");
    else
        printf(":(");

    return 0;
}

Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
const int inf = 1e9;
const int mod = 1e9+7;

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

    int x[N][D];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> x[i][j];
        }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            int dist = 0;
            for (int k = 0; k < D; k++) {
                int t = abs(x[i][k] - x[j][k]);
                dist += t * t;
            }

            for (int power = 1; power <= 126; power++) {
                int tt = power * power;
                if (tt == dist) ans++;
            }
        }
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,answer;
  cin >> a >> b >> c;
  a=b/a;
  if(a>c) {
    answer=c;
  }
  else {
    answer=a;
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,t,a,b,da,db,c=0,sum=0;
	vector<int>v;
	string s;
	cin>>s;
	if((s[0]==s[1]&&s[1]==s[2])||(s[1]==s[2]&&s[2]==s[3]))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

ll gcd(ll a2,ll b2){
	int t;
	while(b2!=0){
		t=a2%b2;
		a2=b2;
		b2=t;
	}
	return a2;
}

ll lcm(ll a1,ll b1){
	if(a1*b1==0){return 0;}
	return (a1*b1/gcd(a1,b1));
}
int main() {

	int r1,r2;
	cin>>r1>>r2;
	int t=lcm(r1,r2)/r1+lcm(r1,r2)/r2;
	cout<<setprecision(12)<<double(lcm(r1,r2))/t<<endl;

	return 0;
}


Measured memory_bytes: 380
#include <stdio.h>

int main(void)
{
    int a, b, c, x, n, m;

    scanf("%d%d%d", &a, &b, &c);

    // A>=B>=C となるように
    if (a<b) { x=a; a=b; b=x; }
    if (a<c) { x=a; a=c; c=x; }
    if (b<c) { x=b; b=c; c=x; }

    m = b-c;
    n = (a-b) + ((m%2)? m/2+2 : m/2);

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

    return 0;
}

Measured memory_bytes: 128
// URL: https://atcoder.jp/contests/code-festival-2017-qualb/tasks/code_festival_2017_qualb_b

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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

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

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

  ll n, m;
  cin >> n;
  map<ll, int> mp;
  rep(i, n) {
    ll d;
    cin >> d;
    mp[d]++;
  }
  cin >> m;
  vector<ll> t(n);
  rep(i, m) {
    ll t;
    cin >> t;
    mp[t]--;
  }
  for(auto m: mp) {
    if (m.second < 0) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 14336
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int h, w;
	cin >> h >> w;

	vector<string> grid(h);
	for (int i = 0; i < h; ++i) {
		cin >> grid[i];
	}

	int i = 0, j = 0;
	grid[0][0] = 'O';
	while (i < h && j < w) {
		if (i + 1 < h && grid[i + 1][j] == '#') {
			grid[i + 1][j] = 'O';
			++i;
		}
		else if (j + 1 < w && grid[i][j + 1] == '#') {			
			grid[i][j + 1] = 'O';
			++j;
		} else {
			cout << "Impossible\n";
			return 0;
		}

		if (i == h - 1 && j == w - 1) {
			break;
		}
	}

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) { 
			if (grid[i][j] == '#') {
				cout << "Impossible\n";
				return 0;
			}
		}
	}

	cout << "Possible\n";

	return 0;

}

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

int main() {
    int N, T;
    cin >> N >> T;
    int ans = 1001;
    for (int i = 0; i < N; i++) {
        int c, t;
        cin >> c >> t;
        if (t <= T && c < ans) {
            ans = c;
        }
    }
    if (ans == 1001) {
        cout << "TLE" << endl;
    }
    else {
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    priority_queue<double> q;
    rep(i,n){
        double vin;
        cin >> vin;
        q.push(-vin);
    }
    while(q.size() >= 2){
        double d = 0;
        d += -1 * q.top();
        q.pop();
        d += -1 * q.top();
        q.pop();
        q.push(-1 * ((double)d / 2));
    }
    double ans = -1 * q.top();
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int r;
	cin>>r;
	cout<<3*r*r<<endl;
}


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

int main() {
    string s;
    cin >> s;
    int n = s.length();
    int a = (n - 1) / 2;
    int b = (n + 3) / 2;

    //条件1
    for (int i = 0; i < a; i++)
    {
        if (s[i] != s[n - (i + 1)]) {
            cout << "No" << endl;
            return 0;
        }
    }

    //条件2
    for (int i = 0; i < (a - 1) / 2; i++)
    {
        if (s[i] != s[a - (i + 1)])
        {
            cout << "No" << endl;
            return 0;
        }
    }

    //条件3
    for (int i = b; i < n; i++)
    {
        if (s[i - 1] != s[n - (i - b + 1)])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

int main() {
    int N, D, A;
    cin >> N >> D >> A;
    priority_queue<tuple<int64, int, int64>, vector<tuple<int64, int, int64>>, greater<tuple<int64, int, int64>>> que;
    for(int i = 0; i < N; ++i) {
        int64 X, H;
        cin >> X >> H;
        que.emplace(X, 0, (H + A - 1) / A);
    }
    int64 ans = 0, damage = 0;
    while(!que.empty()) {
        int64 x, n;
        int q;
        tie(x, q, n) = que.top();
        que.pop();
        if(q == 0) {
            n -= damage;
            if(n >= 0) {
                ans += n;
                damage += n;
                que.emplace(x + 2 * D, 1, n);
            }
        } else {
            damage -= n;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 8432
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	string s;
	cin >> s;
	rep(i, 3) {
		if (s[i] == s[i + 1]) {
			cout << "Bad";
			return 0;
		}
	}
	cout << "Good";
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N;
    cin >> N;
    vector<P> vec(N);
    for(int i = 0;i < N;i++) {
        ll A,B;
        cin >> A >> B;
        vec.at(i) = P(A,B);
    }
    ll ret1 = vec.at(0).first;
    ll ret2 = vec.at(0).second;
    for(int i = 1;i < N;i++) {
        ll cnt = max((vec.at(i).first + ret1 - 1) / vec.at(i).first,(ret2 + vec.at(i).second - 1) / vec.at(i).second);
        ret1 = vec.at(i).first * cnt;
        ret2 = vec.at(i).second * cnt;
    }
    cout << ret1 + ret2 << endl;
}

Measured memory_bytes: 256
class Point

    attr_accessor :x,:y

    def initialize(x,y)
        @x = x
        @y = y
    end

    def calc_distance(pt)
        return (@x - pt.x).abs + (@y - pt.y).abs
    end

end

n,m = gets.chomp.split(" ").map(&:to_i)

student = []
cpoint = []

n.times do |i|
    x,y = gets.chomp.split(" ").map(&:to_i)
    student << Point.new(x,y)
end

m.times do |i|
    x,y = gets.chomp.split(" ").map(&:to_i)
    cpoint << Point.new(x,y)
end

for s in student
    min_cp_dist = s.calc_distance(cpoint[0])
    min_cp = 0
    cpoint.each.with_index do |cp,i|
        if min_cp_dist > s.calc_distance(cp) then
            min_cp_dist = s.calc_distance(cp)
            min_cp = i
        end
    end
    p min_cp + 1
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  	int N;
  	string S;
  	cin >> N;
  	if (N<1200){
      S="ABC";
    }
    else if(N<2800){
      S="ARC";
    }
    if (N>=2800){
      S="AGC";
    }
    cout << S;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define mod 1000000007
typedef long long ll;
using namespace std;

const int MAX_n = 2005;
int AB[MAX_n * MAX_n];
int L[MAX_n];
int main(){
  int n; cin >> n;
  for(int i=0;i<n;i++) cin >> L[i];
  sort(L,L+n);
  
  int ans = 0;
  for(int i=n-1;i>=0;i--){
    for(int j=i-1;j>=0;j--){
      auto itr = lower_bound(L, L+n, L[i] + L[j]);
      int d = distance(itr,L+n);
      ans += n - 1 - i - d;
    }
  }

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

Measured memory_bytes: 256
S = list(input())
even_list = S[::2]
odd_list =  S[1::2]

even_black = even_list.count('0')
even_white = even_list.count('1')
odd_black = odd_list.count('0')
odd_white = odd_list.count('1')

if even_white + odd_black < even_black + odd_white:
    print(even_white + odd_black)
else:
    print(even_black + odd_white)

Measured memory_bytes: 4652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n;
    cin >> n;
    ll num = 0;
    vector<ll> c(n), d(n);
    map<string,ll> mp;
    REP(i, n) {
        string s;
        cin >> s >> d[i];
        if(mp.find(s) == mp.end()) mp[s] = num++;
        c[i] = mp[s];
    }
    ll m;
    cin >> m;
    vector<ll> v(m);
    REP(i, m) {
        string s;
        cin >> s;
        if(mp.find(s) == mp.end()) mp[s] = num++;
        v[i] = mp[s];
    }

    ll sz = mp.size();
    vector<ll> itr(sz);
    vector<vector<ll>> g(sz);
    REP(i, n) g[c[i]].push_back(d[i]);
    REP(i, sz) sort(ALL(g[i]));

    dump(sz);
    dump(mp);
    dump(g);

    ll last = 0;
    REP(i, m) {
        while(itr[v[i]] < (ll)g[v[i]].size() && g[v[i]][itr[v[i]]] <= last) {
            itr[v[i]]++;
        }
        if(itr[v[i]] == (ll)g[v[i]].size()) {
            cout << "No" << endl;
            return 0;
        }
        last = g[v[i]][itr[v[i]]];
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 23972
#pragma GCC optimize("O3", "unroll-loops")
#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e5 + 10;
int arr[maxn], n, k, ans;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> k, k--;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	sort(arr, arr + n), ans = arr[k] - arr[0];
	for (int i = 1; i + k < n; i++)
		ans = min(ans, arr[i + k] - arr[i]);
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

std::vector<long long> base;
std::map<long long, int> numMap;

void init() {
	base.push_back(0);
	numMap[0] = 0;
	long long p = 1;
	long long ans;
	while (ans <= 1152921504606846976L) {
		ans = p * p * p * p * p;
		base.push_back(ans);
		numMap[ans] = p;
		p++;
	}
}

int main()
{
	init();
	
	long long x;
	scanf("%lld", &x);
	
	for (int i = 0 ; i < base.size() ; i++) {
		long long left = x - base[i];
		if (numMap.find(left) != numMap.end()) {
			int a = i;
			int b = -numMap[left];
			printf("%d %d\n", a, b);
			return 0;
		}
		
		left = x + base[i];
		if (numMap.find(left) != numMap.end()) {
			int a = numMap[left];
			int b = i;
			printf("%d %d\n", a, b);
			return 0;
		}
		
	}

	return 0;
}


Measured memory_bytes: 3588
#! python3
#  solve_133B.py

import math



N,D = map(int,input().split())
X = []
ans = 0


def dis(Y,Z):
    ans = 0
    for i in range(D):
        ans += (Y[i] - Z[i])**2
    return math.sqrt(ans)

for i in range(N):
    X.append(list(map(int,input().split())))

for i in range(N):
    for j in range(i+1,N):
       if dis(X[i],X[j]) % 1 == 0:
           ans += 1

print(ans)

Measured memory_bytes: 9208
#include <iostream>

using namespace std;

int main() {
    
    string s;
    cin>>s;
    
    string left, right;
    int ans = 0;
    for(int i=1; i<(int)s.length()/2;i++)
    {
         left = s.substr(0,i);
         right = s.substr(i,i);
//         cout<<left<<" "<<right<<"\n";
         if(left == right)
         {
              ans = max(ans, i*2);
         }
    }
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i,n) for (int i = (int)(n); i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { int to, cost; };
using P = pair<int, int>;
using PP = pair<P, int>;
using D = pair<double, double>;
//const long long mod = 998244353;
const long long mod = 1e9 + 7, inf = 3e18;
const string sp = " ";

template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

int fact[1000000];
void f_init(int n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

int comb(int n, int r) {
	if (n < r) return 0;
	if (n == r) return 1;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

int nck[1010][1010];
void comb(int n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

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

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

bool pri(int p) {
	for (int i = 2; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1;
}

map<int, int> factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

int n, ans;
int d[55];
signed main() {
	cin >> n;
	rep(i, n) {
		cin>> d[i];
	}
	rep(i, n) {
		for (int j = i + 1; j < n; j++) {
			ans += d[i] * d[j];
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
def read_vector
  gets.split(" ").map(&:to_f)
end

def minkowski(x, y, p)
  (x.zip(y).map {|a| (a.first - a.last).abs ** p}.reduce(:+)) ** (1 / p.to_f)
end

def chebyshev(x, y)
  x.zip(y).map {|a| (a.first - a.last).abs}.max
end

n = gets.to_i
x = read_vector
y = read_vector
puts "%.6f"%minkowski(x, y, 1)
puts "%.6f"%minkowski(x, y, 2)
puts "%.6f"%minkowski(x, y, 3)
puts "%.6f"%chebyshev(x, y)

Measured memory_bytes: 8856
loop do
  h, w = gets.split.map(&:to_i)
  break if h.zero? && w.zero?

  (1..h).each do |he|
    (1..w).each do |wi|
      is_black = ((he + wi) % 2).zero?
      is_black ? print('#') : print('.')
    end
    puts
  end
  puts
end



Measured memory_bytes: 6860
# -*- coding: utf-8 -*-
import math
INF = 2**62-1

def read_int():
    return int(input())


def slv(K):
    ans = 0
    for i in range(1, K+1):
        for j in range(1, K+1):
            for k in range(1, K+1):
                ans += math.gcd(math.gcd(i, j), k)
    return ans


def main():
    K = read_int()
    print(slv(K))


if __name__ == '__main__':
    main()


Measured memory_bytes: 67624
#include<bits/stdc++.h>
#define ll long long
#define res register int
#define N 550
using namespace std;
int n,m;
char b[N][N],r[N][N];

int main()
{
	scanf("%d%d",&n,&m);
	
	for(res i=1;i<=n;i+=2)
	  for(res j=1;j<=m;j++)
	    r[i][j]='#',b[i][j]='.';
	    
	for(res i=2;i<=n;i+=2)
	  for(res j=1;j<=m;j++)
	    r[i][j]='.',b[i][j]='#';    	
	
	for(res i=1;i<=n;i++)
	  for(res j=1;j<=m;j++)
	  {
	  	 char ch;
	  	 cin>>ch;
	  	 if(ch=='#')
	  	 {
	  	 	r[i][j]='#';
	  	 	b[i][j]='#';
		 }
	  }
	  	 
    for(res i=1;i<=n;i++)
	r[i][1]='#',b[i][1]='.',r[i][m]='.',b[i][m]='#';
	
	for(res i=1;i<=n;i++)
	{
	  for(res j=1;j<=m;j++)
	  printf("%c",r[i][j]);
	  printf("\n");
    }
	  printf("\n");
	for(res i=1;i<=n;i++)
	{
	  for(res j=1;j<=m;j++)
	  printf("%c",b[i][j]);
	  printf("\n");
    }
	
}


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

#define fi first
#define se second

const int N = 100100;

using namespace std;

int n;
int A[N];
int B[N];

int main()
{
        ios_base::sync_with_stdio(false);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        cin >> n;
        for(int i = 1; i <= n; i++){
                int x;
                cin >> x;
                A[x] += i;
                B[x] += i;
        }
        for(int i = 1; i <= n; i++){
                A[i] += A[i - 1];
        }
        for(int i = n; i >= 1; i--){
                B[i] += B[i + 1];
        }
        for(int i = 1; i <= n; i++){
                A[i] += i;
                B[n - i + 1] += i;
        }
        for(int i = 1; i <= n; i++){
                cout << A[i] << " \n"[i == n];
        }
        for(int i = 1; i <= n; i++){
                cout << B[i] << " \n"[i == n];
        }
}


Measured memory_bytes: 768
import java.util.*;
class Main{
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
		String str;
		HashMap<Integer,Integer> map=new HashMap<Integer,Integer>();
		int table[]=new int[1000];
		int now=0;
		while((str=s.nextLine()).length()>2){
			int a=Integer.parseInt(str.split(",")[0]);
			int b=Integer.parseInt(str.split(",")[1]);
			if(map.containsKey(a)){
				int c=map.get(a);
				map.put(a,c+1);
			}else{
				map.put(a,1);
				table[now++]=a;
			}
		}
		while(s.hasNext()){
			str=s.nextLine();
			int a=Integer.parseInt(str.split(",")[0]);
			int b=Integer.parseInt(str.split(",")[1]);
			if(map.containsKey(a)){
				int c=map.get(a);
				map.put(a,c+10000);
			}else{
			}
		}
		Arrays.sort(table,0,now);
		for(int i=0;i<now;i++){
			int t=map.get(table[i]);
			int q=map.get(table[i])%10000+map.get(table[i])/10000;
			if(t>10000)System.out.println(table[i]+" "+q);
		}
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<time.h>
#include<climits>
#include<string>
//#define IONAME "cttf"
//#define E_DEBUG
//#define TIMECOMP

int n,t,m;
std::vector<int> io,ii;
std::vector<std::vector<int> > vv;

void getData(){
    std::cin>>n>>m;
    vv.resize(n+1);
    io.assign(n+1,0);
    ii.assign(n+1,0);
    for (int i=1;i<=m;i++){
        int u,v;
        std::cin>>u>>v;
        vv[u].push_back(v);
    }
}

int dfs(int u){
    int ans=0;
    if (ii[u]!=0) return ii[u];
    for (auto v:vv[u]){
        ans=std::max(ans,dfs(v)+1);
    }
    ii[u]=ans;
    return ans;
}

void marota(){
    getData();
    int ans=0;
    for (int i=1;i<=n;i++){
        if (ii[i]==0){
            ans=std::max(ans,dfs(i));
        }
    }
    std::cout<<ans;
}

int main(){
    #ifdef TIMECOMP
    clock_t tStart = clock();
    #endif
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    #if defined(IONAME)
    freopen(IONAME".INP","r",stdin);
    freopen(IONAME".OUT","w",stdout);
    #endif
    marota();
    #ifdef TIMECOMP
    printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    #endif
    return 0;
}

Measured memory_bytes: 11548
#include <bits/stdc++.h>
using namespace std;
#define int long long
int c[15],b[15];
int w[200010];
int t[200010];
int best[200010][15];

int dp[1<<15];
signed main(){
		int M,N;
		cin >> M >> N;
		vector< pair<int,int> > v;
		for(int i = 0 ; i < M ; i++){
			cin >> w[i] >> t[i];
			//w[i] = rand() % 100 + 1;
			//t[i] = rand() % 100 + 1;
		}
		for(int i = 0 ; i < N ; i++){
			cin >> c[i] >> b[i];
			//c[i] = rand() % 1000000 + 1;
			//b[i] = rand() % 1000000 + 1;
			int r=0;
			int W=0,T=0;
			for(int j = 0 ; j < M ; j++){
				while( r < M and W + w[r] <= c[i] and T + t[r] <= b[i] ){
					W += w[r];
					T += t[r];
					r++;
				}
				best[j][i] = r;
				//cout << i << "; " << j << "->" <<  r << " " << W << " " << T << endl;
				if(j<r){
					W -= w[j];
					T -= t[j];
				}else{
					r++;
				}
				
			}
			
		}
		for(int i = 0 ; i < (1<<N) ; i++){
			for(int j = 0 ; j < N ; j++){
				if( !(i >> j & 1) ){
					dp[i|(1<<j)] = max(dp[i|(1<<j)],best[dp[i]][j]);
				}
			}
		}
		cout << dp[(1<<N)-1] << endl;
}

Measured memory_bytes: 29900