akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        string s = Console.ReadLine();
        long sum = 0;
        long last = 0;
        foreach (var match in Regex.Matches(s, ">*<*", RegexOptions.Compiled).Cast<Match>())
        {
            var val = match.Value;
            Debug.WriteLine(val);
            long decr = val.Count(x => x == '>');
            long incr = val.Count(x => x == '<');
            sum += decr * (decr - 1) / 2;
            sum += incr * (incr - 1) / 2;
            sum += Max(decr, last);
            last = incr;
        }
        sum -= last;
        Console.WriteLine(sum);
    }
}


Measured memory_bytes: 50032
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const input = stdin.split('\n')

const s = input[0]

const t = ['Sunny', 'Cloudy', 'Rainy', 'Sunny', 'Cloudy', 'Rainy']

const ans = () => {
  const i = t.indexOf(s)
  console.log(t[i + 1])
}

ans()


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


void print_vec(vector<int> vec) {
  cout << "{ ";
  for (int i = 0; i < vec.size(); i++) {
    cout << vec.at(i)+1 << " ";
  }
  cout << "}" << endl;
}

int main() {
    int N,X,Y; cin >> N >> X >> Y;
    Graph G(N);
    map<int,int> m;
    for(int i = 0; i < N; i++)
        m[i+1] = 0;
    for(int i = 0; i < N-1; i++) {
        G.at(i).push_back(i+1);
        G.at(i+1).push_back(i);
    }
    G.at(X-1).push_back(Y-1);
    G.at(Y-1).push_back(X-1);

/*
    for(int i = 0; i < N; i++)
        print_vec(G.at(i));
        */


        for(int i = 0; i < N; i++) {
            vector<int> dist(N,-1); // 全頂点を「未訪問」に初期化
            queue<int> que;

            dist[i] = 0;
            que.push(i); 

            while (!que.empty()) {
                int v = que.front(); 
                que.pop();
                m[dist.at(v)]++;

                for (int nv : G[v]) {
                    if (dist[nv] != -1) continue; 

                    dist[nv] = dist[v] + 1;
                    que.push(nv);
                }
            }
            //for (int v = 0; v < N; ++v) cout << v+1 << ": " << dist[v] << endl;
        }

    for(int i = 0; i < N-1; i++) {
        cout << m[i+1]/2 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			double q=in.nextDouble();
			double x=Math.abs(q/2);
			if(q==-1)
				return;
			while(Math.abs((x*x*x)-q)>=0.00001*q)
				x=x-((x*x*x-q)/(3*x*x));
			System.out.printf("%.6f\n",x);
		}
	}
}

Measured memory_bytes: 12000
#include <algorithm>
#include <iostream>
#include <stdio.h>

//?????\?????????

const int MAX = 100;

using namespace std;

//?????????????´?????????????????????????
void trace(int a[],int n){
    for (int i=0;i<n;i++){
        if(i>0){cout << " ";}
        cout << a[i];
    }
    cout << endl;
}

void InsertionSort(int A[],int n){
    int v,j;
    for (int i=1; 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;
        trace(A, n);
    }
}

int main(){
    int A[MAX], n;
    cin >> n;
    for(int i=0;i<n;i++){
    scanf("%d", &A[i]);
    }
    trace(A,n);
    InsertionSort(A, n);
    return 0;
}

Measured memory_bytes: 3236
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cfloat>
#include <algorithm>
#include <memory>
#define ll long long
#define ull unsigned long long
#define uint unsigned
#define l_double long double
#define PB push_back
#define EB emplace_back
#define gcd __gcd
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define PIE (3.1415926535897932384626433832795)
#define MOD 1'00'00'00'007
#define TEST uint _ {}; cin >> _; while (_--)
using namespace std;
ull lcm (ull a, ull b) { return ((a*b)/gcd(a, b)); }
ull countDigits(const ull &N) { return (floor(log10(N)) + 1); }
bool isPowOfTwo(ull const &N) { return (N && (!(N&(N-1)))); }
// ----------------------------------------------------------

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<boolalpha<<fixed<<setprecision(3);
    // --------------------------------------

    string s;
    cin >> s;
    if (s.at(2) == s.at(3) && s.at(4) == s.at(5)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
n, q = [int(_) for _ in stdin.readline().rstrip().split()]
s = list(stdin.readline().rstrip())
data = [list(map(int, stdin.readline().rstrip().split())) for _ in range(q)]
l = [0]
for i in range(n):
    l.append(l[i]+1 if i+1 < n and s[i] == 'A' and s[i+1] == 'C' else l[i])
for d in data:
    print(l[d[1]-1]-l[d[0]-1])

Measured memory_bytes: 31316
#include<bits/stdc++.h>
using namespace std;
long long int n,a[10000001],x,y;
int main(){
  cin>>n;
  a[0]=0;
  for(int i=1;i<=n;i++){
    a[i]=a[i-1]+i;
    if(a[i]>=n){
      x=a[i]-n;
      y=i;
      break;
    }
  }
  for(int i=1;i<=y;i++){
    if(x!=i) cout<<i<<endl;
  }
  return(0);
}


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

using namespace std;

const int t[10][10] = {
	{3, 2, 6, 1, 5, 4},
	{4, 2, 1, 6, 5, 3},
	{2, 6, 3, 4, 1, 5},
	{5, 1, 3, 4, 6, 2}

};

int main()
{
	int d[10], a[10], k[200];
	string s;
	k['W'] = 0, k['E'] = 1, k['N'] = 2, k['S'] = 3;
	
	for(int i = 0; i<6; i++)
	{
		cin >> d[i];	
	}
	cin >> s;
	
		for(int i = 0; i< s.size(); i++)
	{
		for(int j = 0; j < 6; j++)	
		{
			a[j] = d[t[k[s[i]]][j]-1];
		}
		for(int j = 0; j < 6; j++)	
		{
			d[j] = a[j];
		}		
	}
	cout << d[0] << endl;
	return 0;	
 } 


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

// header area

int main(){
    double A, B, H, M; cin >> A >> B >> H >> M;

    // 長：30/h, 0.5/m 短：6.0/m

    // step1: 角度
    double h_kakudo = 30.0*H + 0.5*M;    // 長
    double m_kakudo = 6.0*M;    // 短
    double kakudo = abs(h_kakudo-m_kakudo);
    if (kakudo > 180) kakudo = 360.0-kakudo;

    // cout << "kakudo: "<< kakudo << endl;
    double r_kakudo = kakudo/180.0 * M_PI;
    // cout << "r_kakudo: "<< r_kakudo << endl;

    double ans_pow = pow(A, 2) + pow(B, 2) - 2 * A * B * cos(r_kakudo);
    double ans = sqrt(ans_pow);

    cout << std::fixed << std::setprecision(15) << ans << endl;

    return 0;
}

Measured memory_bytes: 4248
N = gets.chomp.to_i
s = gets.chomp
t = gets.chomp
if s == t
    puts s.length
    exit
end
(1..N-1).reverse_each do |i|
    if s[(N-i)..-1] == t[0..(i-1)]
        puts (s[0..(N-i-1)] + t).length
        exit
    end
end
puts (s + t).length

Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

    class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string s = Console.ReadLine();
            var arr = s.ToCharArray();
            for(var i=0; i<arr.Length; i++)
            {
                if (arr[i] == '?')
                {
                    if (i > 0 && arr[i - 1] == 'P')
                        arr[i] = 'D';
                    else if (i < arr.Length - 1 && arr[i + 1] == 'P')
                        arr[i] = 'D';
                    else if (i < arr.Length - 1 && arr[i + 1] == 'D')
                        arr[i] = 'P';
                    else if (i < arr.Length - 1 && arr[i + 1] == '?')
                        arr[i] = 'P';
                    else
                        arr[i] = 'D';
                }
            }

            string result = string.Join("", arr);

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }


Measured memory_bytes: 32520
N, K = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
max_div = int(S**0.5)

# Sの約数を列挙する
small_div = []
large_div = []
for i in range(1, max_div+1):
  if S%i == 0:
    small_div.append(i)
    large_div.append(S//i)

# 約数を降順に並べる
div = large_div + small_div[::-1]

ans = 1
for d in div:
  r = []
  for a in A:
    r.append(a%d)
  
  r.sort()
  # (d-ri)足すか、ri引くか、それぞれ累積和を求めておく
  minus = [0]*(N+1)
  plus = [0]*(N+1)
  for i, ri in enumerate(r, 1):
    minus[i] = minus[i-1] + ri
  
  for i, ri in enumerate(r[::-1], 1):
    plus[i] = plus[i-1] + (d - ri)
  
  plus = plus[::-1]
  for m, p in zip(minus, plus):
    if m == p and m <= K:
      ans = d
      break
  
  else:
    continue
  
  break

print(ans)

Measured memory_bytes: 42860
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n,h,cnt,ans=0;
    cin >> n >> h;
    long a[n],b[n];
    for(int i=0;i<n;i++) cin >> a[i] >> b[i];
    sort(a,a+n);
    sort(b,b+n);
    for(int i=0;i<n;i++){
        if(b[i]>a[n-1]){
            cnt = i;
            break;
        } 
    }
    for(int i=n-1;cnt<=i;i--){
            h-=b[i];
            ans++;
            if(h<=0) break;
    }
    if(h>0) cout << ans+(h+a[n-1]-1)/a[n-1] << endl;
    else cout << ans << endl;
}


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

long long get_gcd(long long a,long long b){
    long long ret = 1;

    long long max_val = max(a,b);
    long long min_val = min(a,b);
    long long mod_val = max_val % min_val;

    while(mod_val!=0){
        max_val = min_val;
        min_val = mod_val;
        mod_val = max_val%min_val;
    }
    ret = min_val;

    return ret;
}

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

    vector<long long> x(N);
    for(int i=0;i<N;i++){
        cin >> x[i];
        x[i] = abs(x[i]-X);
    }

    for(int i=0;i<N-1;i++){
        x[i+1] = get_gcd(x[i],x[i+1]);
    }

    cout << x[N-1];

    return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  
  int total = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    
    int length;
    if (x < (K - x)) {
      length = 2 * x;
    }
    else {
      length = 2 * (K - x);
    }
    total += length;
  }
  cout << total << endl;
}

Measured memory_bytes: 3636
#include <stdio.h>

void acsess(int x,int y,int island[14][14]){
  if(island[x][y] != 1){
    return;
  }else{
    island[x][y] = 2;
  }

  acsess(x-1,y,island);
  acsess(x,y-1,island);
  acsess(x+1,y,island);
  acsess(x,y+1,island);
}

void print(int island[14][14]){
  int i,j;
  for(i = 0;i < 14; i++){
    for(j = 0;j < 14; j++){
      printf("%2d ",island[i][j]);
    }
    printf("\n");
  }
  printf("\n");
}

int main(int argc,char* argv[]){
  int island[14][14];
  char str[13];
  int i,j,end = 0;
  
  for(i = 0;i < 14; i++){
    for(j = 0;j < 14; j++){
      if(i == 0 || i == 13 || j == 0 || j == 13){
	island[i][j] = -1;
      }else{
	island[i][j] = 0;
      }
    }
  }

  for(;;){
    int sum = 0;
    for(i = 1; i < 13; i++){
      if(scanf("%s",str) == EOF){
	end = 1;
	break;
      }
      
      for(j = 1; j < 13; j++){
	island[i][j] = str[j-1] - '0';
      }
    }

    if(end == 1){
      break;
    }
    
    for(i = 1;i < 13; i++){
      for(j = 1;j < 13; j++){
	if(island[i][j] == 1){
	  //print(island);
	  acsess(i,j,island);
	  sum++;
	}
      }
    }

    printf("%d\n",sum);
    
    //printf("str = %s\n",str);
    

  }
  
  return 0;
  
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
  using namespace std;
int a,b;
inline void into(){
  scanf("%d%d",&a,&b);
}
inline void work(){
}
inline void outo(){
  if (a<=0&&b>=0) printf("Zero\n");
  else if (a>0) printf("Positive\n");
    else if ((min(b,0)-a)&1)printf("Positive\n");
      else printf("Negative\n");
}
int main(){
  into();
  work();
  outo();
  return 0;
}

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

constexpr int mod = 1e9 + 7;

int64_t pow_mod(int64_t n, int64_t k) {
    if(k == 0)          return 1;
    else if(k == 1)     return n % mod;
    else if(k % 2 == 0) return pow_mod(n * n % mod, k / 2) % mod;
    else if(k % 2 == 1) return pow_mod(n * n % mod, k / 2) * n % mod;
    return -1;
}

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

    vector<int64_t> num(k + 1);
    for(int i = k; i >= 1; i--) {
        num[i] = pow_mod(k / i, n);
        for(int j = i + i; j <= k; j += i) {
            num[i] = (num[i] - num[j] + mod) % mod;
        }
    }

    int64_t ans = 0;
    for(int i = 1; i <= k; i++) {
        ans += i * num[i] % mod;
        ans %= mod;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4052
import sys
from collections import Counter

# sys.stdin = open('d1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


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


def read_str():
    return input()


def solve(n, a, b, v):
    c = Counter(v)
    res = 0
    m = max(v)
    if c[m] >= a:
        for k in range(a, b + 1):
            res += coef[c[m]][k]
        mean = m
        return mean, res
    else:
        values = sorted(set(v), reverse=True)
        s = 0
        r = a
        for value in values:
            if c[value] < r:
                r -= c[value]
                s += value * c[value]
            else:
                res = coef[c[value]][r]
                s += value * r
                break
        mean = s / a
        return mean, res


coef = [[0] * 51 for i in range(51)]
for i in range(0, 51):
    coef[i][0] = 1
    for k in range(1, i + 1):
        coef[i][k] = coef[i - 1][k - 1] + coef[i - 1][k]

n, a, b = read_int_list()
v = read_int_list()
mean, res = solve(n, a, b, v)
print(mean)
print(res)


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

int main(){
    int n, q;
    std::cin >> n >> q;

    std::string s;
    std::cin >> s;

    std::vector<int> s2(n-1, 0);
    std::vector<int> s3(n-1);
    int counter = 0;
    for(int i=0; i<n-1; i++){
        if(s[i]=='A' and s[i+1]=='C'){
            s2[i] = 1;
            counter++;
        }
        s3[i] = counter;
    }

    std::vector<int> l(q);
    std::vector<int> r(q);
    std::vector<int> ans(q);
    for(int i=0; i<q; i++){
        std::cin >> l[i] >> r[i];
        if(l[i]==1){
            ans[i] = s3[r[i]-2];
        }else{
            ans[i] = s3[r[i]-2] - s3[l[i]-2];
        }
        // ans[i] = std::accumulate(s2.begin()+l[i]-1, s2.begin()+r[i]-1, 0);
    }
    for(int i=0; i<q; i++){
        std::cout << ans[i] << std::endl;
    }
	return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono; 
#define ll long long
#define ld long double
#define fo(i,v,e) for(v=i;v<e;v++)
#define rfo(i,v,e) for(v=i;v>e;v--)
#define pb(x) push_back(x)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fi first 
#define se second
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
#define sz(x) (int)x.size()
#define ull unsigned long long
#define vvi vector<vi>
#define vvl vector<vl>
#define vpi vector<pii>
#define vpl vector<pll>
ll mod = 1000000007;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
#define openfile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x);
#else
#define openfile
#define deb(x...)
#endif
const ll N = 1e7+5;
bool primes[N];
vl cd(N);
void init()
{
    ll i,j;
    memset(primes, true, sizeof(primes)); 
    for(int i =2;i*i<=N;i++)
    {
        if(primes[i])
        {
            for(int j = i*i;j<=N;j+=i)
            {
                primes[j] = false;
                cd[j] = i;
            }
        }
    }
}
vl divs(N);
void solve()
{
    ll n,i,j,k,ans = 0;
    cin>>n;
    divs[1] = 1;
    fo(2,i,n+1)
    {
        if(primes[i])
        {
            divs[i] = 2;
        }
        else{
            ll temp = i,cnt = 0;
            while(temp%cd[i]==0)
            {
                cnt++;
                temp/=cd[i];
            }
            divs[i] = (cnt+1)*(divs[temp]);
        }
    }
    fo(1,i,n+1)
    {
        ans+=i*divs[i];
    }
    cout<<ans<<endl;
}
int main()
{
    init();
    // openfile;fastio;
    int T = 1;
    // cin>>T;
    while(T--)
    {
        solve();
    }
}

Measured memory_bytes: 169168
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}

vector<ll> pw2(51,1);vector<ll> pw10(19,1);
ll high_order_bit(ll n){
    ll tmp=1,i=-1;
    while(tmp<=n){
        tmp*=2;
        i++;
    }
    if(n==0) return 0;
    else return i;
}
vector<ll> binary_expansion(ll n){
    vector<ll> B(high_order_bit(n)+1);
    ll tmp=n;
    for(ll i=high_order_bit(n);i>=0;i--){
        B[i]=tmp/pw2[i];
        tmp%=pw2[i];
    }
    return B;
}
vector<ll> divisor(ll x){
    vector<ll> div;
    for(int i=1;i*i<=x;i++){
        if(i*i!=x && x%i==0){
            div.pb(i);
            div.pb(x/i);
        }
        else if(x%i==0) div.pb(i);
    }
    return div;
}
vector<ll> vectorprime(ll x){
    vector<bool> is_prime(x+1);
    vector<ll> prime;
    rep(i,x+1) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=x;i++){
        if(is_prime[i]){
            prime.pb(i);
        }
        for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
    }
    return prime;
}

int main(){
    {rep1(i,50) pw2[i]=(-2)*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N,tmp; cin>>N;
    if(N==0){
        cout<<0;
        return 0;
    }
    tmp=N;
    vector<ll> ans;
    ll now=0; //0の位見てる
    while(tmp!=0){
        if(tmp%(pw2[now+1]) !=0 ){
            ans.pb(1ll);
            tmp -= pw2[now];
        }
        else{
            ans.pb(0ll);
        }
        now++;
    }
    rrep(i,sz(ans)) cout<<ans[i];
}

Measured memory_bytes: 3616
import math
def gcd(x, y): 
   while(y): 
       x, y = y, x % y 
  
   return x 
n = int(input())
a = [int(i) for i in input().split()]
#print(n)
prefix,suffix=[0]*n,[0]*n
prefix[0]=a[0]
suffix[n-1]= a[n-1]
#print(prefix)
for i in range(1,n):
    prefix[i]= gcd(prefix[i-1],a[i])
    suffix[n-i-1]= gcd(suffix[n-i],a[n-i-1])
    pass
maxgcd= max(suffix[1],prefix[-2])
for i in range(1,n-1):
    maxgcd = max(maxgcd, gcd(prefix[i-1],suffix[i+1]))
print(maxgcd)

Measured memory_bytes: 14436
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    int n , m ;
    cin >> n >> m ;
    int like[m] ;
    for(int i = 0; i < m ; i++){
        like[i] = 0;
    }
    

    int an ;
    int ln ;
    for(int i = 0; i < n ; i++){
        cin >> an ;
        for(int j = 0; j < an ; j++){
            cin >> ln ;
            like[ln-1]++ ;
        }
    }
    
    int ans = 0;
    for(int i = 0 ;i < m ; i++){
        if(like[i]==n){
            ans ++ ;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = [int(s) for s in input().split()]

import datetime

time1 = datetime.datetime(2020,5,5,n[0],n[1])
time2 = datetime.datetime(2020,5,5,n[2],n[3])

time3 = time2 - time1

time3=int(time3.seconds)

result=int(time3/60)
summary = result - n[4]

print(summary)

Measured memory_bytes: 9400
//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define s(x) scanf("%d",&x)
#define rep(i,x) for(int i=0;i<x;i++)
bool f[3005][3005];
int main()
{
	int w,h;
	while(1)
	{
		int x1[1005],y1[1005],x2[1005],y2[1005];
		memset(f,0,sizeof(f));
		vector<int>x(0),y(0);
		scanf("%d %d",&w,&h); if(!w) return 0;
		int n;
		scanf("%d",&n);
		x.pb(0); y.pb(0);
		x.pb(w-1); y.pb(h-1);
		for(int i=0;i<n;i++)
		{
			scanf("%d %d %d %d",&x1[i],&y1[i],&x2[i],&y2[i]);
			if(x1[i]) x.pb(x1[i]-1);
			if(x1[i]!=w) x.pb(x1[i]);
			if(x2[i]) x.pb(x2[i]-1);
			if(x2[i]!=w)x.pb(x2[i]);
			if(y1[i]) y.pb(y1[i]-1);
			if(y1[i]!=h)y.pb(y1[i]);
			if(y2[i]!=h)y.pb(y2[i]);
			if(y2[i]) y.pb(y2[i]-1);
		}
		sort(x.begin(),x.end());
		sort(y.begin(),y.end());
		x.erase(unique(x.begin(),x.end()),x.end());
		y.erase(unique(y.begin(),y.end()),y.end());
		for(int i=0;i<n;i++)
		{
			int xx1=lower_bound(x.begin(),x.end(),x1[i])-x.begin();
			int yy1=lower_bound(y.begin(),y.end(),y1[i])-y.begin();
			int xx2=lower_bound(x.begin(),x.end(),x2[i]-1)-x.begin();
			int yy2=lower_bound(y.begin(),y.end(),y2[i]-1)-y.begin();
			for(int j=xx1;j<=xx2;j++)
			{
				for(int k=yy1;k<=yy2;k++)
				{
					f[j][k]=true;
				}
			}
		}
		int ret=0;
		for(int i=0;i<x.size();i++)
		{
			for(int j=0;j<y.size();j++)
			{
				if(!f[i][j])
				{
					ret++;
					queue<P>que;
					que.push(mp(i,j));
					int dx[4]={0,1,0,-1};
					int dy[4]={1,0,-1,0};
					while(!que.empty())
					{
						P p=que.front();
						que.pop();
						int a=p.first;
						int b=p.second;
						f[a][b]=true;
						for(int k=0;k<4;k++)
						{
							int aa=a+dx[k];
							int bb=b+dy[k];
							if(!(0<=aa && aa<x.size())) continue;
							if(!(0<=bb && bb<y.size())) continue;
							if(f[aa][bb]) continue;
							f[aa][bb]=true;
							que.push(mp(aa,bb));
						}
					}
				}
			}
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 10076
#include<stdio.h>
#include<stdlib.h>
#define MAX 20000  // スタックの最大値

typedef struct {
	int top;         // スタックポインタ(一番上の位置)
	int S[MAX];
} Stack;


// スタック st の初期化
void initialize(Stack *st)
{
	st->top = 0;
	st->S[st->top] = 0;
}

// スタック st が空かどうかを確認
int isEmpty(Stack *st)
{
	return st->top == 0;
}

// スタック st が一杯かどうかを確認
int isFull(Stack *st)
{
	return st->top >= MAX - 1;
}

// スタック st に要素 x をプッシュ(一番上に要素を追加)
void push(int x, Stack *st)
{
	if (isFull(st))
		exit(1);

	st->top++;
	st->S[st->top] = x;
}

// スタック st から要素をポップ(一番上の要素を取り出す)
int pop(Stack *st) {
	if (isEmpty(st))
		exit(1);

	st->top--;
	return st->S[st->top+1];
}


int main(void)
{
	Stack st1;     // '\' の開始位置を格納するスタック
	Stack st2_j;   // 各水たまりの最も左の'\' の位置を格納するスタック
	Stack st2_a;   // 各水たまりの水量を格納するスタック

	// スタック初期化
	initialize(&st1);
	initialize(&st2_j);
	initialize(&st2_a);

	char c;
	int sum = 0;  // 水たまりの総水量
	
	// 地形を読み込み，各水たまりの水量を計算
	for (int i = 0; (c = getchar()) != EOF; i++) {
		if (c == '\\') {                                 // '\' が出た時の処理
			// 位置 i を st1 にプッシュ(write your code)
			push(i,&st1);
		} else if (!isEmpty(&st1) && c == '/') {          // '/' が出た時の処理
			int j=pop(&st1);
			// 水たまりの総水量 sum を更新(write your code)
			sum += i-j;
			// st2_j と st2_a を用いて水たまりの水量を更新
			int a = i - j;   // 更新する水たまりの水量を a に格納していく
			while (!isEmpty(&st2_j) && st2_j.S[st2_j.top] > j) {  // 最も左の '\' の位置が j よりも大きい場合，以下を繰り返す
				// 水たまりの水量を求めていく (write your code)
				a+=pop(&st2_a);
				pop(&st2_j);
			}
			// 更新した水たまりの「最も左の'\' の位置」および「水量」を更新 (write your code)
			push(j,&st2_j);
			push(a,&st2_a);
		}
	}

	printf("%d\n", sum);       // 水たまりの総水量を出力
	printf("%d", st2_a.top);   // 水たまりの個数を出力

	// 各水たまりの水量を断面図の左から出力(スタックの底から出力)
	for (int i = 1; i <= st2_a.top; i++)
		printf(" %d", st2_a.S[i]);
	printf("\n");

	return 0;
}


Measured memory_bytes: 2108
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

ll MODP = 998244353;


int main(){
  int n;
  cin >> n;
  map<string,int> m;
  m["AC"] = 0;
  m["WA"] = 0;
  m["TLE"] = 0;
  m["RE"] = 0;
  rep(i,n){
    string s;
    cin >> s;
    m[s] += 1;
  }

  cout << "AC x " << m["AC"] << endl;
  cout << "WA x " << m["WA"] << endl;
  cout << "TLE x " << m["TLE"] << endl;
  cout << "RE x " << m["RE"] << endl;

  return 0;
}


Measured memory_bytes: 3600
def sort_two_numbers(a, b):
    """
    a: int
    b: int
    returns a sorted list

    >>> sort_two_numbers(1, 3)
    [1, 3]
    >>> sort_two_numbers(3, 1)
    [1, 3]
    """
    result = []
    
    if a < b:
        result.append(a)
        result.append(b)
    else:
        result.append(b)
        result.append(a)

    return result

if __name__ == '__main__':
#    import doctest
#    doctest.testmod()

    while True:
        try:
            (a, b) = [int(i) for i in input().split(' ')]
            if a == 0 and b == 0:
                break
            print('{0[0]} {0[1]}'.format(sort_two_numbers(int(a), int(b))))
        except EOFError:
            break

Measured memory_bytes: 7672
#include <stdio.h>
int main(){
	int x, tokoA, tokoB, o, p;
	scanf("%d %d %d", &x, &tokoA, &tokoB);
	o= tokoA - x;
	p= tokoB - x;
	if(o<0){
		o=o*(-1);
	} 
	if(p<0){
		p=p*(-1);
	}
	if(o>p){
		printf("B\n");
	}else if (o<p){
		printf("A\n");
	}
	return 0;
}


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

typedef long long ll;

const int mod = 998244353;
const int Maxn = 400005;

int pw2[Maxn];
int n;
char str[Maxn];
char my[Maxn];
int ans[Maxn];
int res;

int main()
{
    pw2[0] = 1;
    for (int i = 1; i < Maxn; i++)
        pw2[i] = 2ll * pw2[i - 1] % mod;
    scanf("%d", &n);
    scanf("%s", str);
    int cur = 0;
    for (int i = 0; i < n; i++)
        cur = (2ll * cur + int(str[i] - '0')) % mod;
    res = ll(cur + 1) * 2ll * n % mod;
    for (int i = n - 1; i >= 1; i--) if (n % i == 0 && n / i % 2) {
        int lft = i;
        for (int j = 0; j < i; j++) {
            lft--;
            if (str[j] == '1') ans[i] = (ans[i] + pw2[lft]) % mod;
            char A = str[j];
            char B = A == '1'? '0': '1';
            for (int z = j; z < n; z += i) {
                my[z] = A;
                swap(A, B);
            }
        }
        bool ok = true;
        for (int j = 0; j < n; j++)
            if (my[j] != str[j]) { ok = my[j] < str[j]; break; }
        if (ok) ans[i] = (ans[i] + 1) % mod;
    }
    for (int i = 1; i < n; i++) if (n % i == 0 && n / i % 2) {
        res = (res - ll(ans[i]) * (2 * n - 2 * i) % mod + mod) % mod;
        for (int j = i + i; j < n; j += i)
            ans[j] = (ans[j] - ans[i] + mod) % mod;
    }
    printf("%d\n", res);
    return 0;
}


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

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main(){
	int N, A, B, C;
	cin >> N >> A >> B >> C;
	vector<string> s(N);
	rep(i,N) cin >> s[i];
	vector<char> ans(N);
	rep(i,N-1){
		if(s[i]=="AB"){
			if(A==0&&B==0){
				cout << "No" << endl;
				return 0;
			}
			else if(A==0){
				A++;
				B--;
				ans[i]='A';
			}
			else if(B==0){
				B++;
				A--;
				ans[i]='B';
			}
			else{
				if(s[i+1]=="AB"){
					A++;
					B--;
					ans[i]='A';
				}
				else if(s[i+1]=="AC"){
					A++;
					B--;
					ans[i]='A';
				}
				else{
					A--;
					B++;
					ans[i]='B';
				}
			}
		}
		if(s[i]=="AC"){
			if(A==0&&C==0){
				cout << "No" << endl;
				return 0;
			}
			else if(A==0){
				A++;
				C--;
				ans[i]='A';
			}
			else if(C==0){
				C++;
				A--;
				ans[i]='C';
			}
			else{
				if(s[i+1]=="AC"){
					A++;
					C--;
					ans[i]='A';
				}
				else if(s[i+1]=="AB"){
					A++;
					C--;
					ans[i]='A';
				}
				else{
					A--;
					C++;
					ans[i]='C';
				}
			}
		}
		if(s[i]=="BC"){
			if(B==0&&C==0){
				cout << "No" << endl;
				return 0;
			}
			else if(B==0){
				B++;
				C--;
				ans[i]='B';
			}
			else if(C==0){
				C++;
				B--;
				ans[i]='C';
			}
			else{
				if(s[i+1]=="BC"){
					B++;
					C--;
					ans[i]='B';
				}
				else if(s[i+1]=="AB"){
					B++;
					C--;
					ans[i]='B';
				}
				else{
					B--;
					C++;
					ans[i]='C';
				}
			}
		}
	}
	if(s[N-1]=="AB"){
		if(A==0&&B==0){
			cout << "No" << endl;
			return 0;
		}
		else if(A==0) ans[N-1]='A';
		else ans[N-1]='B';
	}
	if(s[N-1]=="AC"){
		if(A==0&&C==0){
			cout << "No" << endl;
			return 0;
		}
		else if(A==0) ans[N-1]='A';
		else ans[N-1]='C';
	}
	if(s[N-1]=="BC"){
		if(B==0&&C==0){
			cout << "No" << endl;
			return 0;
		}
		else if(B==0) ans[N-1]='B';
		else ans[N-1]='C';
	}
	cout << "Yes" << endl;
	rep(i,N) cout << ans[i] << endl;

	return 0;
}

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

int main()
{
	int a, b;

	cin >> a >> b;

	if (15 == (a + b))
	{
		cout << "+" << endl;
	}
	else if (15 == (a * b))
	{
		cout << "*" << endl;
	}
	else
	{
		cout << "x" << endl;
	}

	return 0;
}



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

int main() {
	int n;
	int w;
	long long vmax = 0;
	cin >> n;
	cin >> w;
	vector<vector<int> > arr(n, vector<int> (2));
	vector<long long> dp(w + 1, 0);

	for(int i = 0; i < n; i++) {
		for(int j = 0; j < 2; j++) {
			cin >> arr[i][j];
		}
	}
	for(int i = 0; i < n; i++) {
		for(int weight = w; weight >= arr[i][0]; weight--) {
			dp[weight]= max(dp[weight - arr[i][0]] + arr[i][1], dp[weight]);
		}
	}
	for(int i = 1; i <= w; i++) {
		vmax = max(vmax, dp[i]);
	} cout << vmax << endl;
	return 0;
}

Measured memory_bytes: 1024
N,M = map(int,input().split())
A = [int(input()) for _ in range(M)]

isbroken = [1 for _ in range(N+1)]
for i in range(M):
  isbroken[A[i]] = 0


dp = [0 for _ in range(N+1)]
dp[0] = 1
mod = 10**9 + 7

dp[1] = dp[0] * isbroken[0]
  
for j in range(1,N):
  dp[j+1] = (dp[j] * isbroken[j] + dp[j-1] * isbroken[j-1]) % mod
    
print(dp[N])

Measured memory_bytes: 15608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int n; cin>> n;
    cout << t[n-1] << endl;
}

Measured memory_bytes: 256
n,*t=`dd`.split;a,*z=0;t.map!{|e|e.to_i*2}.pop(n.to_i).map{|v|z[0]=a=[a,v].min;t.shift.times{z=a=[a+1,v].min,*z}};m=-1;z.map{|a|$.+=m=[m+1,a].min};p$./4.0

Measured memory_bytes: 96660
#define REP(i, n) for(int i = 0;i < n;i++)
#define INF 2e9
#define ll long long
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ALL(v) v.begin(), v.end()

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

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

int main(){
    ll m=0, N, M; cin >> N >> M;
    vector<pair<double, ll>> D(N);
    REP(i, N) {
        cin >> D.at(i).first >> D.at(i).second;
    }
    sort(ALL(D));
    ll i = 0;
    while(M>0) {
        if (M>D.at(i).second) {
            m += D.at(i).second * D.at(i).first;
            M -= D.at(i).second;
        } else {
            m += M * D.at(i).first;
            M = 0;
        }
        i++;
    }
    cout << m << endl;
}



Measured memory_bytes: 1792
// In The Name Of Allah
// Mehrkish Makuei
// Islamic Republic Of Iran

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

typedef long long ll;

const int maxx = 1e6 + 19;
int k, n;
string s;

void Input(){
	cin >> n >> k;
	cin >> s;
}

void Solve(){
	s[k - 1] = tolower(s[k - 1]);
	cout << s << endl;
}

int main(){
	ios::sync_with_stdio(false),	cin.tie(0),		cout.tie(0);
	Input(),	Solve();
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] sticks = new int[n];
    for (int i = 0; i < n; i++)
      sticks[i] = sc.nextInt();
    Arrays.sort(sticks);
    int count = 0;
    int k;
    for (int i = 0; i < n - 2; i++)
      for (int j = i + 1; j < n - 1; j++) {
        k = j + 1;
        while (k < n && sticks[i] + sticks[j] > sticks[k])
          k++;
        count += k - 1 - j;
      }
    System.out.println(count);
  }
}

Measured memory_bytes: 26460
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

using namespace std;

const int INF = numeric_limits<int>::max() / 2;

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<pair<int, int> > >edge(n);
    for(int i = 0; i < m; i++){
        int l, r, d;
        cin >> l >> r >> d;
        l--; r--;
        edge[l].push_back(make_pair(r, d));
        edge[r].push_back(make_pair(l, -d));
    }

    vector<int> d(n, INF);
    for(int s = 0; s < n ; s++){
        if(d[s] != INF) continue;
        queue<int> q;
        d[s] = 0;
        q.push(s);
        while(!q.empty()){
            int v = q.front();
            q.pop();
            for(auto item : edge[v]){
                if(d[item.first] != INF){
                    if(d[item.first] != d[v] + item.second){
                        cout << "No" << endl;
                        return 0;
                    }
                }else{
                    d[item.first] = d[v] + item.second;
                    q.push(item.first);
                }
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int mod10(int a){
  return a%10;
}

int top(int a){
 if (mod10(a) == 0) return a;
  return (a/10 + 1)*10;
}

int main(){
  int a[5];
  rep (i,5) cin >> a[i];
  vi b(5);
  rep (i ,5) b.at(i) = mod10(a[i]);
  
//  rep(i,5) cout << b.at(i) << endl;
  
  
  int j = 200;
  rep(i,5){
    if (b.at(i) != 0) j = min (j,b.at(i));
  }
  
  if (j > 10) j = 10;
      
/*  cout << j << endl;
  
 
  
  rep (i,5)  cout << top(a[i]) << endl; */
  int t = 0;
  
    rep(i,5) t += top(a[i]);
  
//  cout << a[j] << endl;
  
  
  t = t - 10 + j;
    
    cout << t << endl;
  
  
  
  
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
using R = double;
using P = complex<R>;
#define x real()
#define y imag()
const R eps = 1e-9,PI = acos(-1);

bool equal(R a,R b){return abs(b-a)<eps;}
bool equal0(R a){return equal(a,0.0);}

P operator*(const P& p,const R& d){
    return P(p.x*d,p.y*d);
}

istream &operator>>(istream& is,P& p){
    R a,b;
    is >> a >> b;
    p = P(a,b);
    return is;
}

ostream &operator<<(ostream& os,P& p){
    os << fixed << setprecision(10) << p.real() << " " << p.imag();
}
//内積
double dot(P a,P b) {return (conj(a)*b).real();}
//外積
double cross(P a,P b) {return (conj(a)*b).imag();}

struct L{
    P a,b;
    L(P a,P b):a(a),b(b){}
    L(R A,R B,R C){
        if(equal(A,0)) a = P(0,C/B),b = P(1,C/B);
        else if(equal(B,0)) b = P(C/A,0),b = P(C/A,1);
        else a = P(0,C/B),b = P(C/A,0);
    }
};

//pをbに射影
P projection(P p,P b) {return b*dot(p,b)/norm(b);}

//pとp1 to p2 に射影
P projection(L l,P p){
    p -= l.a; l.b -= l.a;
    P proj = projection(p,l.b);
    return l.a+proj;
}

struct S:L{
    S(P a,P b):L(a,b){}
};

//点の回転方向を判定
int ccw(P& p0,P p1,P p2){
    p1 -= p0,p2 -= p0;
    if(cross(p1,p2)>eps) return 1; //"COUNTER_CLOCKWISE"
    if(cross(p1,p2)<-eps) return -1; //"CLOCKWISE"
    if(dot(p1,p2)<0) return 2; //"ONLINE_BACK"
    if(norm(p1)<norm(p2)) return -2; //"ONLINE_FRONT"
    return 0; //"ON_SEGMENT"
}

bool is_parallel(L l1,L l2){
    return equal0(cross(l1.b-l1.a,l2.b-l2.a));
}

bool is_orthogonal(L l1,L l2){
    return equal0(dot(l1.b-l1.a,l2.b-l2.a));
}

//pをlに関して対称移動
P reflection(L l,P p){
    P pj = projection(l,p);
    return 2.0*pj-p;
}

//pがl上にあるか
bool is_online(L& l,P& p){
    return abs(ccw(l.a,l.b,p))!=1;
}

bool is_onsegment(S& s,P& p){
    return ccw(s.a,s.b,p)==0;
}

//線分の交差判定
bool intersect(S s,S t){
    return ccw(s.a,s.b,t.a)*ccw(s.a,s.b,t.b)<=0 && ccw(t.a,t.b,s.a)*ccw(t.a,t.b,s.b)<=0;
}

P crosspoint(L l1,L l2){
    R a = cross(l1.b-l1.a,l2.b-l2.a);
    R b = cross(l1.b-l1.a,l1.b-l2.a);
    if(equal0(abs(a)) && equal0(abs(b))) return l2.a;
    return l2.a+(l2.b-l2.a)*b/a;
}

P crosspoint(S s1, S s2){
    return crosspoint(L(s1),L(s2));
}
int main(){
    int Q;
    cin >> Q;
    for(int i=0;i<Q;i++){
        P p1,p2,p3,p4;
        cin >> p1 >> p2 >> p3 >> p4;
        P res = crosspoint(S(p1,p2),S(p3,p4));
        cout << res << endl;
    }
}


Measured memory_bytes: 3296
#include <iostream>
#include <map>
#include <set>

using namespace std;

#define P(s) cout << s << endl;
#define DEBUG(x) cout << #x << ": " << x << endl;

int main() {
  int n, l, r;
  cin >> n;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    sum = sum + (r - l) + 1;

  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, m;
  cin >> n >> m;
  map<ll, ll, greater<ll>> mp;
  rep(i, n) {
    ll a;
    cin >> a;
    mp[a]++;
  }
  rep(i, m) {
    ll b, c;
    cin >> b >> c;
    mp[c] += b;
  }
  ll ans = 0;
  for(auto v : mp) {
    if(n == 0) break;
    ans += v.first * min(n, v.second);
    n -= min(n, v.second);
  }
  cout << ans << endl;
}

Measured memory_bytes: 12800
#include <iostream>
#define N_MAX 100000
int dp[N_MAX]={0};
int h[N_MAX]={0};
using namespace std;
int main(){
  int N,i;
  cin>>N;
  for(i=0;i<N;i++){
    cin>>h[i];
  }
  dp[0]=0;dp[1]=abs(h[1]-h[0]);
  for(i=2;i<N;i++){
    dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
  }
  cout << dp[N-1]<<endl;
}

Measured memory_bytes: 1024
from operator import itemgetter
n = int(input())
x =[]
y =[]
info = [list(map(int,input().split())) for i in range(n)]
for i in range(n):
  x.append([i,info[i][0]])
  y.append([i,info[i][1]])

x = sorted(x,key=itemgetter(1))
y = sorted(y,key=itemgetter(1))
tree = []
#for i in range(n):
#  if i==0:
#    tree[x[i][0]].append([x[i+1][0],abs(x[i][1]-x[i+1][1])])
#    tree[y[i][0]].append([y[i+1][0],abs(y[i][1]-y[i+1][1])])
#  elif i==n-1:
#    tree[x[i][0]].append([x[i-1][0],abs(x[i][1]-x[i-1][1])])
#    tree[y[i][0]].append([y[i-1][0],abs(y[i][1]-y[i-1][1])])
#  else:
#    tree[x[i][0]].append([x[i+1][0],abs(x[i][1]-x[i+1][1])])
#    tree[x[i][0]].append([x[i-1][0],abs(x[i][1]-x[i-1][1])])
#    tree[y[i][0]].append([y[i+1][0],abs(y[i][1]-y[i+1][1])])
#    tree[y[i][0]].append([y[i-1][0],abs(y[i][1]-y[i-1][1])])
    
for i in range(n-1):
    tree.append([x[i][0],x[i+1][0],abs(x[i][1]-x[i+1][1])])
    tree.append([y[i][0],y[i+1][0],abs(y[i][1]-y[i+1][1])])

#UnionFindクラス
class UnionFind(object):

  def __init__(self, n=1):
    self.par = [i for i in range(n)]
    self.rank = [0 for _ in range(n)]

  def find(self, x):
  
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
  
  # xとyの根を結合させる
  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x != y:
      if self.rank[x] < self.rank[y]:
        x, y = y, x
      if self.rank[x] == self.rank[y]:
        self.rank[x] += 1
      self.par[y] = x
  
  # x,yの根が同じかどうかを返す（根が同じ:True、根が異なる:False）
  def is_same(self, x, y):
    return self.find(x) == self.find(y)

uf = UnionFind(len(tree))
tree = sorted(tree,key=itemgetter(2))
ans = 0

for i in tree:
  x,y,kyori = i
  if not uf.is_same(x,y):
    uf.union(y,x)
    ans += kyori
print(ans)

Measured memory_bytes: 86568
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <stdio.h>

int main(void){
  int ans=0;
  std::string n;
  std::cin >> n;
  for(int i=0;i<n.size();i++){
    ans += (int)(n[i] - '0');
  }
  if(ans % 9 == 0) std::cout << "Yes";
  else std::cout << "No";
  return 0;
}

Measured memory_bytes: 3720
#include<stdio.h>

int main()
{
    int X, A, B;

    scanf("%d", &X); //total what I have
    scanf("%d", &A); //cake bill
    scanf("%d", &B); //donuts bill

    //int temp= X-A;
    //int rem= temp % B;

    printf("%d", ((X-A)%B) );
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

const int N=505;
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};
int p[N][N],f[N][N],x[N*N],y[N*N];
vector<pii> q[N];
int n,l,r;
ll ans;

int main(){
	read(n);
	int cur=0;
	rep(i,1,n) rep(j,1,n){
		int tmp;
		read(tmp);
		int xx=(tmp-1)/n+1;
		int yy=tmp-(xx-1)*n;
		p[xx][yy]=++cur;
	}
	rep(i,1,n) rep(j,1,n){
		x[p[i][j]]=i;
		y[p[i][j]]=j;
		f[i][j]=min(min(abs(1-i),abs(i-n)),
					min(abs(1-j),abs(j-n)))+1;
	}
	rep(k,1,n*n){
		//cout<<x[k]<<" "<<y[k]<<" "<<f[x[k]][y[k]]<<endl;
		ans+=--f[x[k]][y[k]];
		q[f[x[k]][y[k]]].pb(mp(x[k],y[k]));
		rep(t,0,n+1){
			while(q[t].size()){
				int x=q[t].back().fi;
				int y=q[t].back().se;
				q[t].pop_back();
				REP(d,4){
					int xx=x+dx[d];
					int yy=y+dy[d];
					if(xx<1||n<xx||yy<1||n<yy) continue;
					int w=f[x][y]+(p[xx][yy]>k);
					if(w<f[xx][yy]){
						//cout<<x<<" "<<y<<"  "<<xx<<" "<<yy<<"  "<<w<<endl;
						f[xx][yy]=w;
						q[f[xx][yy]].pb(mp(xx,yy));
					}
				}
			}
		}
	}	
	cout<<ans<<endl;
	return 0;
}

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

int sum[15][1005];

int main(){
  int h,w,k;
  cin>>h>>w>>k;
  string st[15];
  int s[15][1005];
  rep(i,h) cin>>st[i];
  rep(i,h) rep(j,w) s[i][j]=st[i][j]-'0';

  rep(i,h){
    sum[i][0]=0;
    rep(j,w) sum[i][j+1]=sum[i][j]+s[i][j];
  }
  int ans=1e9;
  for(int bits=0; bits<1<<h-1; bits++){
    int d=0;
    rep(i,h-1) if(bits&(1<<i)) d++;
    int l=0,r=1;
    bool can=true;
    while(1){
      int add=0;
      bool can2=true;
      rep(i,h){
	add+=sum[i][r]-sum[i][l];
	if(i==h-1||bits&(1<<i)){
	  if(add>k){
	    can2=false;
	  }
	  add=0;
	}
      }
      if(!can2&&r-l==1){
	can=false;
	break;
      }
      if(can2) r++;
      else{
	l=r-1;
	d++;
      }
      if(r==w+1) break;
    }
    if(can) ans=min(ans,d);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
using namespace std;

int N;

void func(){

	double minimum = (double)BIG_NUM,tmp,bunbo=(double)N;
	int ans_S,ans_A,ans_C,M=256,R[N+1],input[N+1],O[N+1],check[256];

	for(int i = 1; i <= N; i++)scanf("%d",&input[i]);

	for(int s = 0; s <= 15; s++){
		for(int a = 0; a <= 15; a++){
			for(int c = 0; c <= 15; c++){
				for(int i = 0; i <= 255; i++)check[i] = 0;
				R[0] = s;
				for(int i = 1; i <= N; i++){
					R[i] = (a*R[i-1]+c)%M;
					O[i] = (input[i]+R[i])%M;
					check[O[i]]++;
				}
				tmp = 0.0;
				for(int i = 0; i <= 255; i++){
					if(check[i] == 0)continue;
					tmp -= ((double)check[i]/bunbo)*log((double)check[i]/bunbo);
				}

				if(minimum - tmp > 0.0000000001){
					minimum = tmp;
					ans_S = s;
					ans_A = a;
					ans_C = c;
				}
			}
		}
	}

	printf("%d %d %d\n",ans_S,ans_A,ans_C);

}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 2820