akhauriyash/Code-Regression huggingface dataset:
const MAX_K: usize = 51;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();

    let a: Vec<usize> = (0..n).map(|_| sc.read()).collect();
    let b: Vec<usize> = (0..n).map(|_| sc.read()).collect();

    let mut ans: Vec<usize> = Vec::new();

    for k in (0..(MAX_K + 1)).rev() {
        let mut ok = vec![vec![false; MAX_K + 1]; MAX_K + 1];
        for i in 0..(MAX_K + 1) {
            ok[i][i] = true;
        }

        for from in 0..(MAX_K + 1) {
            for i in 1..k {
                let to = from % i;
                ok[from][to] = true;
            }
        }
        for from in 0..(MAX_K + 1) {
            for &i in &ans {
                let to = from % i;
                ok[from][to] = true;
            }
        }
        for k in 0..(MAX_K + 1) {
            for i in 0..(MAX_K + 1) {
                for j in 0..(MAX_K + 1) {
                    ok[i][j] = ok[i][j] || (ok[i][k] && ok[k][j]);
                }
            }
        }

        let mut check = true;
        for i in 0..n {
            if !ok[a[i]][b[i]] {
                check = false;
                break;
            }
        }

        if !check {
            if k == 51 {
                println!("-1");
                return;
            }

            ans.push(k);
        }
    }

    let mut cost = 0;
    for &a in &ans {
        cost += ((1 as usize) << a);
    }
    println!("{}", cost);
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner { ptr: 0, length: 0, buf: vec![0; 1024], small_cache: vec![0; 1024] }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool { b == b'\n' || b == b'\r' || b == b'\t' || b == b' ' }

    fn read<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)]).parse().unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}



Measured memory_bytes: 4476
fun main(args: Array<String>)
{
    val n = readLine()!!.toInt()
    val d = readLine()!!.split(" ").map{ it.toInt() }.toIntArray()

    var sum = 0
    for (i in 0 until n) {
        for (k in (i+1) until n)
            sum += d[i] * d[k]
    }

    println(sum)
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define pb push_back
#define mp make_pair

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define f first
#define s second

#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

#define println1(a) printf("%d\n", a);
#define println2(a, b) printf("%d %d\n", a, b);
#define println3(a, b, c) printf("%d %d %d\n", a, b, c);

const int MAX = 5005;
const int MOD = 1000000007;

ll dp[MAX][MAX];
/* dp[i][j]: 1^j+2^j+...+i^j */
ll powx(int i, int j) {
    if (j == 0) { return 1; }
    ll a = ((ll)powx(i,j/2)*powx(i,j/2))%MOD;
    if (j%2) { a*=(ll)i; }
    return a%MOD;
}

int main() {
    int n; cin >> n;
    string s; cin >> s; int k = s.length();
    dp[1][0] = 1; dp[1][1] = 2;
    FOR(i, 1, n+1) {
        F0R(j, MAX-1) {
            dp[i+1][j+1] = ((ll)dp[i+1][j+1] + dp[i][j] * 2)%MOD;
            dp[i+1][max(0, j-1)] = ((ll)dp[i+1][max(0, j-1)]+ dp[i][j])%MOD;
        }
    }
    cout << ((ll)dp[n][k]*powx(powx(2, k), MOD-2))%MOD << endl;
}


Measured memory_bytes: 195712
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>
 
using namespace std;
 
int main(int argc, char* argv[])
{
 
	string A,B,C;
 
	cin >> A >> B >> C;
 
	cout << (char)(A[0]- 0x20) << (char)(B[0]- 0x20) << (char)(C[0]- 0x20) << endl;
 
	return 0;
 
}

Measured memory_bytes: 256
n = int(input())
a = list(input().split())
if n == 1:
    print(a[0])
    exit()
a_o = a[::2]
a_e = a[1::2]
if n % 2 == 0:
    a_e.reverse()
    print(' '.join(a_e),end = ' ')
    print(' '.join(a_o),end = ' ')
else:
    a_o.reverse()
    print(' '.join(a_o),end = ' ')
    print(' '.join(a_e),end = ' ')


Measured memory_bytes: 24644
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 998244353;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 100005;

ll power(ll a,ll n,ll m=M){
    ll ans=1;
    while(n){
        if(n&1) ans=ans*a;
        a=a*a;
        n=n>>1;
        ans=ans%m;
        a=a%m;
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,m,k;
    cin>>n>>m>>k;
    ll ans=0;
    ll p = 1;
    rep(i,0,k+1){
        ll cnt = ((p * m)%M * power(m-1, n-i-1)) % M;
        ans = (ans + cnt) % M;
        // err2(p, cnt);
        p = ((p * (n-1-i))%M * power(i+1, M-2))%M;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3552
#include<stdio.h>
int main(void)
{
    double a,b,c,d,e,f,x,y;

    while (scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f) != EOF){

    y=(a*f-d*c)/(a*e-b*d);
    x=(c-b*y)/a;
    x+=0.0005;
    y+=0.0005;
    x*=1000;
    y*=1000;
    x= floor(x);
    y= floor(y);
    x=x/1000;
    y=y/1000;
    printf("%.3lf %.3lf\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 0
fun main(args:Array<String>) {
    val N = readLine()!!.toInt()
    val xu = (1..N).map {
        val s = readLine()!!.split(" ")
        Pair(s[0],s[1])
    }
    xu.map{
        when(it.second) {
            "JPY" -> it.first.toDouble()
            "BTC" -> it.first.toDouble() * 380000.0
            else -> {
                0.0
            }
        }
    }.fold(0.0) {sum,ele-> sum+ele}.run(::println)
}
 

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

using namespace std;

int main() {
  int n;
  cin >> n;
  int cnt = 0;
  bool good = false;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    if (a == b) {
      cnt++;
      if (cnt >= 3) good =true;
    } else {
      cnt = 0;
    }
  }
  if (good) puts("Yes");
  else puts("No");
  return 0;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pll pair<LL,LL>
#define pii pair<int,int>
#define y second
#define x first
#define LL long long 
#define MEM(x) memset(x,0,sizeof(x))
using namespace std;
int main(){
    int n;
    scanf("%d\n",&n);
    vector<pii> v;
    int cnt[105][105];
    MEM(cnt);
    for(int i = 0;i<n;i++){
        char c[30];
        cin.getline(c,30);
        LL x=0,y=0;
        LL ok=0,tot=0;
        for(int i = 0;c[i]!=0;i++){
            if(c[i]=='.'){
                ok=1;
                continue;
            }
            if(ok){
                tot++;
                y=y*10+c[i]-'0';
            }
            else{
                x=x*10+c[i]-'0';
            }
        }
        while(tot<9){
            y=y*10;
            tot++;
        }
        int two=0,five=0;
        LL num=x*1000000000+y;
        while(num%2==0)two++,num/=2;
        while(num%5==0)five++,num/=5;
        cnt[two][five]++;
        v.pb(mp(two,five));
     //   printf("%d %d\n",two,five);
    }
    for(int i = 99;i>=0;i--){
        for(int j =99;j>=0;j--){
            cnt[i][j]+=cnt[i+1][j]+cnt[i][j+1]-cnt[i+1][j+1];
        }
    }
    LL ans=0;
    for(auto it:v){
        ans+=cnt[max(18-it.x,0)][max(18-it.y,0)];
        if(it.x>=9&&it.y>=9)ans--;
    }
    printf("%lld\n",ans/2);
}
/*
100
5
5 4
4 2
4 2 3
5 4 2 3 1
*/

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

int main(){
  int N,K;
  string S;
  cin>>N>>S>>K;
  string s;
  s=S[K-1];
  string ss;
  for (int i=0;i<N;i++){
    ss=S[i];
    if (ss!=s){
      S.replace(i,1,"*");
    }
  }
  cout<<S;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a,b,c,count=0;
	
	scanf("%d %d %d",&a,&b,&c);
	
	for(int i=a;i<=b;i++){
		if(c%i==0)	count++;
	}
	
	printf("%d\n",count);
	
	return 0;
}


Measured memory_bytes: 2116
#include <bits/stdc++.h>
using namespace std;
int main(){

	long long a,b;
	cin>>a>>b;
	long long sum=0;
	long long cnt=1;
	long long ar[a],d[a+1];
	d[0]=0;
	for(int i=0;i<a;i++){
		cin>>ar[i];
	}
	for(int i=1;i<=a;i++){
		d[i]=d[i-1]+ar[i-1];
		if(d[i]<=b){
			cnt++;
		}
	}
	cout<<cnt<<endl;;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int N, M, A;
  scanf("%d %d", &N, &M);
  
  while(M--) {
    scanf("%d", &A);
    N -= A;
    if (N < 0) {
      printf("-1");
      return 0;
    }
  }
  
  printf("%d", N);
  return 0;
}

Measured memory_bytes: 1736
#define _DEBUG 1

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define check(s)
#endif

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

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

int COLOR_SIZE = 8;
int TOP_RATE_COLOR = -1;

int color(ll rate) {
  if (rate <= 399) {
    return 0;
  } else if (rate <= 799) {
    return 1;
  } else if (rate <= 1199) {
    return 2;
  } else if (rate <= 1599) {
    return 3;
  } else if (rate <= 1999) {
    return 4;
  } else if (rate <= 2399) {
    return 5;
  } else if (rate <= 2799) {
    return 6;
  } else if (rate <= 3199) {
    return 7;
  } else {
    return TOP_RATE_COLOR; // over 3200
  }
}

void solve(ll N, std::vector<ll> a) {
  vector<ll> colorCount(COLOR_SIZE, 0);
  ll topRates = 0;

  for (ll x : a) {
    int c = color(x);
    if (c == TOP_RATE_COLOR) {
      topRates++;
    } else {
      colorCount.at(c)++;
    }
  }

  int variation = 0;
  rep(i, COLOR_SIZE) {
    ll count = colorCount.at(i);
    if (count != 0)
      variation++;
  }
  int min = variation;
  if (variation == 0 && topRates >= 1) {
    min = 1;
  }
  int max = variation + topRates;

  cout << min << " " << max << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  ll N;
  scanf("%lld", &N);
  std::vector<ll> a(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &a[i]);
  }
  solve(N, std::move(a));
  return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    A = [tuple(map(int, input().split())) for _ in range(3)]
    N = int(input())
    B = [int(input()) for _ in range(N)]

    ans = [[[] for _ in range(3)] for _ in range(3)]
    for i in range(3):
        for j, a in enumerate(A[i]):
            ans[i][j] = a in B

    yes = []
    for i in range(3):
        yes.append(all(ans[i]))
        yes.append(all([ans[0][i], ans[1][i], ans[2][i]]))
    yes.append(all([ans[0][0], ans[1][1], ans[2][2]]))
    yes.append(all([ans[2][0], ans[1][1], ans[0][2]]))

    if any(yes):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>

int main(void){
    int N, ans=0;
    std::cin >> N;

    for(int i=0; i<N; ++i){
        int a;
        std::cin >> a;
        while(a % 2 == 0 && a > 1){
            ++ans;
            a >>= 1; 
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3588
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		long h = sc.nextLong();
		long w = sc.nextLong();
		
		// 計算
		long result = 0;
		if(h%3 != 0 && w%3 != 0){
		    long S1 = (h/3)*w;
		    result = minS(h - h/3, w, S1);
		    S1 = ((h+2)/3)*w;
		    result = min(result, minS(h - (h+2)/3, w, S1));
		    S1 = h*(w/3);
		    result = min(result, minS(h, w - w/3, S1));
		    S1 = h*((w+2)/3);
		    result = min(result, minS(h, w - (w+2)/3, S1));
		}
		
		// 出力
		System.out.println(result);
	}
	
	static long minS(long h, long w, long S1){
	    long S2 = max((h/2)*w, h*(w/2));
	    long S3 = h*w - S2;
	    return max(S1, max(S2, S3)) - min(S1, min(S2, S3));
	}
}


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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int N;
int A[101010];
ll sum;
ll X[101010];

int main()
{
    cin >> N;
    rep(i, N)
    {
        cin >> A[i + 1];
        sum += A[i + 1];
    }

    ll asum = 0;
    for (int i = 2; i <= N; i = i + 2)
    {
        asum += A[i];
    }
    X[1] = sum - 2 * asum;
    for (int i = 2; i <= N; i++)
    {
        X[i] = 2 * A[i - 1] - X[i - 1];
    }

    rep(i, N)
    {
        cout << X[i + 1];
        if (i != N - 1)
        {
            cout << " ";
        }
    }
}


Measured memory_bytes: 2432
S = input()
S = S +'R'
#ATCG = 'ATCG'                   
count = 0
j=0
num=[]
for i in range(len(S)):
    # for j in range(4):
    #     if S[i]==ATCG[j]:
    # if (S[i] == 'A' or S[i]=='T' or S[i]=='C' or S[i]== 'G') and (i==(len(S)-1)):
    #     count =count+1
    #     print(S[i])
    #     num.append(count)

    if S[i] == 'A' or S[i]=='T' or S[i]=='C' or S[i]== 'G':
        count=count+1
        #print(S[i])
       
    else:
        num.append(count)
        j=j+1
        count=0


#print(num)
max_num=max(num)
print(max_num)



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

if s >= 3600: 
    h = s//3600
    m = s%3600
    s = m%60
    m = m//60
elif s >= 60:
    h = 0
    m = s//60
    s = s%60
else:
    h = 0
    m = 0

print("{0}:{1}:{2}".format(h,m,s))

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

using namespace std;

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

int main(){
    ll r, d, x;
    cin >> r >> d >> x;
    for(int i = 0; i < 10; i++){
        x = r*x-d;
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <cassert>
using namespace std; typedef long long ll; const int INF=1e9; typedef pair<ll,ll> P;

int main() {
  int n,m; cin>>n>>m;
  int a[m], b[m];
  for(int i=0;i<m;i++) cin>>a[i]>>b[i];
  bool u[n]; fill(u,u+n,false);
  for(int i=0;i<m;i++) {
    if (a[i] == 1) u[b[i]-1]=true;
    if (b[i] == 1) u[a[i]-1]=true;
  }
  bool ok=false;
  for(int i=0;i<m;i++) {
    if (u[a[i]-1] && b[i]==n) ok=true;
    if (u[b[i]-1] && a[i]==n) ok=true;
  }
  if (ok) cout<<"POSSIBLE"<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 2048
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
using namespace std;
int px[100005],py[100005],par[100005];
pair<int,int> sx[100005],sy[100005];
int find(int x)
{
	return x==par[x]?x:par[x]=find(par[x]);
}
int unite(int u,int v)
{
	u=find(u);
	v=find(v);
	if(u==v)
	    return 0;
	par[u]=v;
    return 1;
}
int dist(int x,int y)
{
	return min(abs(px[x]-px[y]),abs(py[x]-py[y]));
}
int main()
{
	int n;
	cin>>n;
	for(int j=0;j<n;j++)
	{
		cin>>px[j]>>py[j];
		par[j]=j;
		sx[j]=make_pair(px[j],j);
		sy[j]=make_pair(py[j],j);
	}
	sort(sx,sx+n);
	sort(sy,sy+n);
	set<pair<int,pair<int,int> > > st;
	for(int j=0;j<n-1;j++)
	{
		st.insert(make_pair(dist(sx[j].second,sx[j+1].second),make_pair(sx[j].second,
		sx[j+1].second)));
		st.insert(make_pair(dist(sy[j].second,sy[j+1].second),make_pair(sy[j].second,
		sy[j+1].second)));
	}
	long long res=0;
	while(st.size())
	{
		pair<int,pair<int,int> > cur=*st.begin();
		st.erase(st.begin());
		int u=cur.second.first,v=cur.second.second;
		res+=unite(u,v)*dist(u,v);
	}
	cout<<res;
	return 0;
} 

Measured memory_bytes: 15488
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    string s;
    cin>>s;
    bool a=false,b=false,c=false;
    if(s[0]=='R') a=true;
    if(s[1]=='R') b=true;
    if(s[2]=='R') c=true;

    if(a&&b&&c) cout<<3<<endl;
    else if((a&&b)||(b&&c)) cout<<2<<endl;
    else if(a||b||c) cout<<1<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

struct item{
  int value;
  int weight;
};

int max(int a,int b)
{
  if(a>b)
    return a;
  else 
    return b;
}

int main(void)
{
  int N,W,i,j,**c,**g,w;
  struct item *a;
  scanf("%d %d",&N,&W);

  c=malloc(sizeof(int *)*(N+1));
  for(i=0;i<N+1;i++)
    c[i]=malloc(sizeof(int )*(W+1));
  g=malloc(sizeof(int *)*(N+1));
  for(i=0;i<N+1;i++)
    g[i]=malloc(sizeof(int)*(W+1));
  a=malloc(sizeof(struct item)*(N+1));
  for(i=1;i<N+1;i++)
    scanf("%d %d",&a[i].value,&a[i].weight);
  
  for(i=0;i<W+1;i++)
    c[0][i]=0;
  for(i=1;i<N+1;i++)
    c[i][0]=0;

  for(i=0;i<W+1;i++)
    g[0][i]=1;

  for(i=1;i<N+1;i++)
    for(w=1;w<W+1;w++){
      if(a[i].weight<=w)
	if(a[i].value+c[i-1][w-a[i].weight]>c[i-1][w]){
	  c[i][w]=a[i].value+c[i-1][w-a[i].weight];
	  g[i][w]=1;
	}
	else{
	  c[i][w]=c[i-1][w];
	  g[i][w]=0;
	}
      else
	c[i][w]=c[i-1][w];
      g[i][w]=0;
    }
  printf("%d\n",c[N][W]);
 
  return 0;
}

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

#define FOR(i,a,n) for(int i = a;i<n;i++)
#define REP(i,n) FOR(i,0,n)
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) SET(a,0)
#define MAX(a,b) (a>b)?a:b
#define MIN(a,b) (a<b)?a:b

using namespace std;

int deck[50];
int bucket[50];
int n,r;

void init(){
  REP(i,n) deck[i] = n-i;
}

int solve(){
  int p,c;
  init();
  REP(i,r){
    cin >> p >> c;
    REP(j,c){
      bucket[j] = deck[p+j-1];
    }
    for(int j = p-2;j >= 0;j--){
      deck[j+c] = deck[j];
    }
    REP(j,c){
      deck[j] = bucket[j];
    }
  }
  return deck[0];
}

int main(){
  while(true){
    cin >> n >> r;
    if((n|r) == 0) break;
    cout << solve() << endl;
  }
  
}


Measured memory_bytes: 1160
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

const int N = 405;
const long long inf = (long long) 2e18;

int n;
long long dp[N][N];
long long arr[N];
long long pref[N];

long long sum(int x, int y) {
  return (pref[y] - (x > 0 ? pref[x - 1] : 0));
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    dp[i][i] = arr[i];
    pref[i] = arr[i] + (i > 0 ? pref[i - 1] : 0);
  }
  for (int L = 2; L <= n; L++) {
    for (int i = 0; i + L - 1 < n; i++) {
      int j = i + L - 1;
      if (L == 2) {
        dp[i][j] = arr[i] + arr[j];
      } else {
        dp[i][j] = inf;
        for (int k = i; k <= j; k++) {
          if (k == i) {
            dp[i][j] = min(dp[i][j], dp[i + 1][j] + sum(i, j));
          } else if (k == j) {
            dp[i][j] = min(dp[i][j], dp[i][j - 1] + sum(i, j));
          } else {
            long long ans = 0, lef = dp[i][k], rig = dp[k + 1][j];
            if (k - i > 0) ans += lef;
            if (j - k > 1) ans += rig;
            dp[i][j] = min(dp[i][j], ans + sum(i, j));
          }
        }
      }
    }
  }
  cout << dp[0][n - 1] << endl;
  return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  string s;
  cin>>s;
  cout<<s.front()<<s.size()-2<<s.back()<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
 
int main() {
    int a = 0;
 
    while (1) {
        int n, w, l, d;
        vector<string> name(10);
 
        cin >> n;
        if (n == 0) break;
        if (a == 1) cout << endl;
        vector< pair<int, int> > vp(n);
 
        for (int i = 0; i < n; i++) {
            cin >> name[i];
            cin >> w >> l >> d;
             
            int p = 3 * w + d;
 
            vp[i].first = p;
            vp[i].second = (-1) * i;
        }
        sort(vp.begin(), vp.end());
        for (int i = n - 1; i >= 0; i--) {
            cout << name[vp[i].second * (-1)] << "," << vp[i].first << endl;
        }
        a = 1;
    }
}


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

namespace A_AtCoDeer_and_Paint_Cans
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(' ')
                .Select(s => int.Parse(s)).ToArray();

            var types = inputs.GroupBy(x => x)
                .Select(x => new { Count = x.Count()}).ToArray();

            Console.WriteLine(types.Length);
        }
    }
}


Measured memory_bytes: 13536
N, Y = map(int, input().split())

man_max = Y // 10000
gosen_max = Y // 5000

for x in range(man_max+1):
  for y in range(gosen_max+1):
    z = N - x - y
    if 0 <= z <= 2000 and 10000*x + 5000*y + 1000*z == Y:
      print(x, y, z)
      exit()
      
print(-1, -1, -1)


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

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

    string s;
    cin >> s;

    int n = s.size();
    rep(i, n){
        if(s[i] == ','){
            s[i] = ' ';
        }
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n,m; cin>>n>>m;
	int l=1,r=n; 
	rep(i,0,m){
		int a,b; cin>>a>>b;
		chmax(l,a);
		chmin(r,b);
	}
	if(r-l<0) cout<<0;
	else cout<<r-l+1;
	return 0;
}

Measured memory_bytes: 256
R,C,K = gets.chomp.split(" ").map(&:to_i)
r,c,v = K.times.map{gets.split.map(&:to_i)}.transpose
value = Array.new(R){Array.new(C,0)}
K.times do |i|
  value[r[i]-1][c[i]-1] = v[i]
end
#２つのdp配列を使いまわす
dp0 = Array.new(C+1){Array.new(4,0)}
dp1 = Array.new(C+1){Array.new(4,0)}
R.times do |i|
  C.times do |j|
    #今いるマスを1つずつ処理
    v = value[i][j]
    if v != 0
      #もらうDP、やる必要のない処理(1つもアイテムを取得してないのに3を計算するみたいな)も入ってる
      dp0[j][3] = [dp0[j][3],dp0[j][2]+v].max
      dp0[j][2] = [dp0[j][2],dp0[j][1]+v].max
      dp0[j][1] = [dp0[j][1],dp0[j][0]+v].max
    end
    #次の行にうつるとき、その列での最大値を渡す
    dp1[j][0] = dp0[j].max
    #次のマスへの受け渡し
    dp0[j+1][0] = dp0[j][0] if dp0[j+1][0] < dp0[j][0] #0の遷移のときは列も考慮する必要がある
    dp0[j+1][1] = dp0[j][1]
    dp0[j+1][2] = dp0[j][2]
    dp0[j+1][3] = dp0[j][3]
  end
  #配列の使いまわし
  dp0,dp1 = dp1,dp0
end
puts dp0[C-1][0]

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

using namespace std;

int main()
{
	string str, action;
	int q;
	int i;
	int a, b;

	cin >> str;

	cin >> q;

	for (i = 0; i < q; i++){
		cin >> action;
		if (action == "print"){
			cin >> a >> b;
			for (int j = a; j <= b; j++){
				cout << str[j];
			}
			cout << endl;
		}
		else if (action == "reverse"){

			cin >> a >> b;

			string temp;

			int k = 0;

			for (int j = a; j <= b; j++){
				temp[k] = str[j];
				k++;
			}
			k = 0;
			for (int j = b; j >= a; j--){
				str[j] = temp[k];
				k++;
			}
		}
		else if (action == "replace"){
			cin >> a >> b;

			string str2;

			cin >> str2;

			int k = 0;

			for (int j = a; j <= b; j++){
				str[j] = str2[k];
				k++;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1212
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

int main(){
ll X;
cin>>X;
ll count=0;
ll x = 100;
while(X>x){
    x= x*1.01;
    count++;
}

cout<<count<<endl;

return 0;

}

Measured memory_bytes: 3596
#include <stdio.h>
#define MAX(a,b) ((a>b)? a:b)

int data[10][10];

int drop(int x, int y){
  if(0 <= x && x < 10 && 0 <= y && y < 10) data[x][y]++;
}

int main(){
  int i,j;
  for(i=0;i<10;i++) for(j=0;j<10;j++) data[i][j] = 0;

  int x,y,r;
  while(scanf("%d,%d,%d", &x,&y,&r)!=EOF){
    switch(r){
    case 3:
      drop(x-2,y);drop(x+2,y);drop(x,y-2);drop(x,y+2);
    case 2:
      drop(x-1,y-1);drop(x+1,y-1);
      drop(x-1,y+1);drop(x+1,y+1);
    case 1:
      drop(x,y);drop(x-1,y);drop(x+1,y);drop(x,y-1);drop(x,y+1);
    }
  }

  int max=0;
  int num=0;
  for(i=0;i<10;i++){
    for(j=0;j<10;j++){
      if(data[i][j] == 0) num++;
      else max = MAX(max, data[i][j]);
    }
  }

  printf("%d\n%d\n", num, max);
}

Measured memory_bytes: 0
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,ii ) for( typeof(gg.begin()) ii=gg.begin();ii!=gg.end();ii++)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define sz(a) int((a).size())
#define N 1000010
#define MAX 30
#define mod 1000000007
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define all(a) a.begin(),a.end()
const ll INF = 1e18+1;

int main()
{
	ll n,a,b,x,y,ans=0;
	scanf("%lld%lld%lld",&n,&a,&b);
	REP(i,n)
	{
		scanf("%lld",&x);
		if (i) ans+=min(b,(x-y)*a);
		y=x;
	}
	printf("%lld\n",ans);
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,a[25],b[25],c[25],ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<n;i++)
		cin>>c[i];
	for(int i=1;i<=n;i++){
		ans+=b[a[i]];
		if(i>1&&a[i]==a[i-1]+1)
			ans+=c[a[i]-1];
	}
	cout<<ans;
    return 0;
}


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

const int MAX_N = 100010;
int par[MAX_N], uniteRank[MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, C;
    cin >> N >> C;
    vector<pll> sushies;
    for (int i = 1; i <= N; i++)
    {
        ll X, V;
        cin >> X >> V;
        sushies.emplace_back(X, V);
    }
    sort(sushies.begin(), sushies.end());
    //右(順回り)にある地点まで移動可能な時の最大
    vector<ll> ruisekiRightMax(N + 1);
    ll ruisekiRValue = 0;
    for (int i = 0; i < N; i++)
    {
        ll distance, value;
        tie(distance, value) = sushies.at(i);
        ruisekiRValue += value;
        ruisekiRightMax.at(i + 1) = max(ruisekiRightMax.at(i), ruisekiRValue - distance);
    }
    //左(逆回り)にある地点まで移動可能な時の最大
    vector<ll> ruisekiLeftMax(N + 1);
    ll ruisekiLValue = 0;
    for (int i = N - 1; i >= 0; i--)
    {
        ll distance, value;
        tie(distance, value) = sushies.at(i);
        ruisekiLValue += value;
        ruisekiLeftMax.at(i) = max(ruisekiLeftMax.at(i + 1), ruisekiLValue - (C - distance));
    }
    //左→右のケース(左の距離2倍)
    //左を固定して右の累積Maxとあわせる
    ll answer = 0;
    answer = max(answer, ruisekiRightMax.at(N));
    ruisekiLValue = 0;
    for (int i = N - 1; i >= 0; i--)
    {
        ll distance, value;
        tie(distance, value) = sushies.at(i);
        ruisekiLValue += value;
        answer = max(answer, ruisekiLValue - (C - distance) * 2 + ruisekiRightMax.at(i));
    }
    //右→左のケース(右の距離2倍)
    //右を固定して左の累積Maxとあわせる
    answer = max(answer, ruisekiLeftMax.at(0));
    ruisekiRValue = 0;
    for (int i = 0; i < N; i++)
    {
        ll distance, value;
        tie(distance, value) = sushies.at(i);
        ruisekiRValue += value;
        answer = max(answer, ruisekiRValue - distance * 2 + ruisekiLeftMax.at(i + 1));
    }
    cout << answer << endl;
    return 0;
}


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

using namespace std;

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

ll comb[55][55];

void init_comb (void){
	rep (i, 55) rep (j, 55) comb[i][j] = 0LL;
	rep (i, 55) comb[i][0] = comb[0][i] = 1LL;
	
	for (int k = 1; k < 55; ++k){
		for (int j = 1; j <= k; ++j){
			int i = k - (j - 1);
			comb[i][j] = comb[i][j-1] + comb[i-1][j];
		} // end for
	} // end for
}

ll nCr(int n, int r){
	if (n < r) return 0LL;
	if (n / 2 < r){
		r = n - r;
	} // end if

	return comb[n-r][r];
}

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

	int N, P; cin >> N >> P;
	int odd = 0;
	int even = 0;

	rep (i, N){
		int a; cin >> a;
		odd += (int)(a % 2 == 1);
		even += (int)(a % 2 == 0);
	} // end rep

	ll res = 0LL;
	
	for (int k = 0 + P; k <= odd; k += 2){
		res += (ll)pow(2, even)*nCr(odd, k);
	} // end for

	cout << res << endl;
		
	return 0;
}

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

using namespace std;

vector<int> parents;
vector<int> sizes;

void init(int n) {
    parents = vector<int>(n, 0);
    sizes = vector<int>(n, 1);
    for (int i = 0; i < n; ++i) {
        parents[i] = i;
    }
}

int find(int x) {
    if (parents[x] == x) {
        return x;
    }
    else {
        parents[x] = find(parents[x]);
        return parents[x];
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) {
        return;
    }

    if (sizes[x] < sizes[y]) {
        parents[x] = y;
    }
    else { // if (sizes[x] >= sizes[y]) {
        parents[y] = x;
    }
    int total = sizes[x] + sizes[y];
    sizes[x] = total;
    sizes[y] = total;
}

bool same(int x, int y) {
    return find(x) == find(y);
}

void Main() {
    int N, M;
    cin >> N >> M;
    vector<int> p(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> p[i];
        --p[i];
    }
    init(N);
    for (int i = 0; i < M; ++i) {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        unite(x, y);
    }

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        if (same(i, p[i])) {
            ++ans;
        }
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 4092
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MAX   1e9
#define MIN  -1e9
typedef map<int,int> mpi;
typedef set<int> seti;
typedef multiset<int> mseti;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
struct Interval {int start, end;};
bool compare(Interval i1, Interval i2) {return (i1.start < i2.start);}
ll mod=1e9+7;
ll power(ll x,ll y,ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m;

    return (y%2 == 0)? p : (x * p) % m;
}
int main()
{
    string s;
    cin>>s;
    ll len=s.length();
    ll ans=0;
    ans=(ans+power(3,len-1,mod))%mod;
    ll curr=2;
    ll coun=1;
    repA(i,1,len-1)
    {
        if(s[i]=='1')
        {
            ll p=((curr%mod)*(power(3,len-1-coun,mod)%mod))%mod;
            ans=(ans+p)%mod;
            curr=(curr*2)%mod;
            coun++;
        }
        else
            coun++;
    }
    cout<<(ans+curr)%mod;
    return 0;
}


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

int OneTo[200001];
int ToN[200001];

int N;
int M;

int main()
{
    cin >> N >> M;

    int a,b;
    for(int i = 0;i < M;i++)
    {
        cin >> a >> b;
        if(a == 1)
        {
            OneTo[b] = 1;
        }
        else if(a == N)
        {
            ToN[b] = 1;
        }
        if(b == 1)
        {
            OneTo[a] = 1;
        }
        else if(b == N)
        {
            ToN[a] = 1;
        }
    }

    for(int i = 1;i <= N;i++)
    {
        if(OneTo[i] == 1 && ToN[i] == 1)
        {
            cout << "POSSIBLE";
            return 0;
        }
    }

    cout << "IMPOSSIBLE";
    return 0;
}



Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
N, X = map(int, input().split())
m = [int(input()) for _ in range(N)]

left = X
minimum = m[0]
counter = 0
for donut in m:
    if donut < minimum:
        minimum = donut
    left -= donut
    counter += 1

counter += left//minimum
print(counter)


Measured memory_bytes: 3060
import java.io.*;
import java.util.*;

public class Main {

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null; }
        String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try { tokenizer = new StringTokenizer(reader.readLine()); } 
                catch (IOException e) { throw new RuntimeException(e);} }
            return tokenizer.nextToken(); }
        public int nextInt() { return Integer.parseInt(next()); }
        public long nextLong() { return Long.parseLong(next()); }
        public double nextDouble() { return Double.parseDouble(next()); }
    }

    static InputReader r = new InputReader(System.in);
    static PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) {
        
        int n = r.nextInt();
        String s = r.next();
        char cur = s.charAt(0);
        int ans = 1;
        for(int i = 1; i < n; i++){
            char c = s.charAt(i);
            if(c != cur){
                cur = c;
                ans++;
            }
        }   
        pw.println(ans);
        pw.close();
    }
}

/**
                _        _                 _                                                
               | |      | |               | |                                               
   ___ ___   __| | ___  | |__  _   _    __| | __ _ _ __ _ __ ___ _ __     _   _  __ _  ___  
  / __/ _ \ / _` |/ _ \ | '_ \| | | |  / _` |/ _` | '__| '__/ _ \ '_ \   | | | |/ _` |/ _ \ 
 | (_| (_) | (_| |  __/ | |_) | |_| | | (_| | (_| | |  | | |  __/ | | |  | |_| | (_| | (_) |
  \___\___/ \__,_|\___| |_.__/ \__, |  \__,_|\__,_|_|  |_|  \___|_| |_|   \__, |\__,_|\___/ 
                                __/ |                               ______ __/ |            
                               |___/                               |______|___/             
 */

Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
const int maxn = 300010;
set<string> a;
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n;
	cin >> n;
	while (n--) {
		string w;
		cin >> w;
		a.insert(w);
	}
	cout << a.size() << '\n';
}



Measured memory_bytes: 19140
#include <iostream>
using namespace std;
int main(void){
    int n, p[10100];
    int d1[10100], d2[10100];
 
    while(true){
        cin >> n;
        if(n == 0) {
            break;
        }
 
        for(int i = 0; i < n; i++){
            cin >> p[i] >> d1[i] >> d2[i];
        }
 
        int d_sum[10100];
        int d_max = 0, p_max;
         
        for(int i = 0; i < n; i++){
            d_sum[i] = d1[i] + d2[i];
            if(d_sum[i] > d_max){
                d_max = d_sum[i];
                p_max = p[i];
            }
        }
        cout << p_max << " " << d_max << endl;
    }
}


Measured memory_bytes: 3204
<?php
  list($n, $m) = explode(" ", trim(fgets(STDIN)));
  $ary = array();
  for ($i = 1; $i <= $n; $i++) {
    array_push($ary, explode(" ", trim(fgets(STDIN))));
  }
  $ary_2 = array();
  for ($i = 1; $i <= $m; $i++) {
    array_push($ary_2, trim(fgets(STDIN)));
  }
  $result = 0;
  foreach ($ary as $key => $val) {
    foreach ($val as $val_key => $v) {
      $result = $result + ($v * $ary_2[$val_key]);
    }
    if ($key < (count($ary)-1)) {
      print($result . "\n");
    } else {
      print $result;
    }
    $result = 0;
  }
?>

Measured memory_bytes: 8408
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;

namespace Atcoder
{
	class Program
	{
		/*
			string s = Console.ReadLine();
			string[] ST = Console.ReadLine().Split(' ').ToArray();
			string S = strArray[0];
			string T = strArray[1];

			int[] HWN = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
			int H = intArray[0];
			int W = intArray[1];
			int N = int.Parse(Console.ReadLine());

			List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToList());
			
			double[] R = Console.ReadLine().Split(' ').Select(i => double.Parse(i)).ToArray();

			Boolean ok = false;
			
			List<int> dp = Enumerable.Repeat(値, 個数).ToList();
			
			Console.WriteLine(ans);
			Console.WriteLine("Yes");
			Console.WriteLine("No");
			Console.ReadKey();
			Console.WriteLine(cnt);

			for(int i= 0; i < N; i++)
		*/

		static void Main(string[] args)
		{
			int N = int.Parse(Console.ReadLine());
			int[] d = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
			int ans = 0;

			for (int i = 0; i < N; i++)
            {
				for (int j = i + 1; j < N; j++)
                {
					ans += d[i] * d[j];
                }
			}
			Console.WriteLine(ans);
		}
		class Item : IComparable
		{
			public string A;
			public int B;
			public Item(string a, int b)
			{
				this.A = a;
				this.B = b;
			}
			public int CompareTo(object obj)
			{
				return B - ((Item)obj).B;
			}
		}

		/// <summary>
		/// 回文
		/// </summary>
		/// <param name="Target"></param>
		/// <param name="len"></param>
		/// <returns></returns>
		static bool Palindrome(string Target , int len)
        {
			bool yes = true;

			for(int i = 0;i < len; i++)
            {
				if(Target[i] != Target[len - 1 - i])
                {
					yes = false;
					break;
                }
            }
			return yes;
        }

		/// <summary>
		/// アナグラム
		/// </summary>
		/// <param name="word1"></param>
		/// <param name="word2"></param>
		/// <returns></returns>
		static bool IsAnagramOf(string word1, string word2)
		{
			char[] val1 = word1.ToCharArray();
			char[] val2 = word2.ToCharArray();
			Array.Sort(val1);
			Array.Sort(val2);
			word1 = new string(val1);
			word2 = new string(val2);

			return word1 == word2;
			//return word1.OrderBy(x => x).SequenceEqual(word2.OrderBy(x => x));
		}

		/// <summary>
		/// 最小公倍数
		/// </summary>
		/// <param name="a"></param>
		/// <param name="b"></param>
		/// <returns></returns>
		public static BigInteger Lcm(BigInteger a, BigInteger b)
		{
			return a * b / Gcd(a, b);
		}

		/// <summary>
		/// 最大公約数
		/// </summary>
		/// <param name="a"></param>
		/// <param name="b"></param>
		/// <returns></returns>
		public static BigInteger Gcd(BigInteger a, BigInteger b)
		{
			if (a < b)
				// 引数を入替えて自分を呼び出す
				return Gcd(b, a);
			while (b != 0)
			{
				var remainder = a % b;
				a = b;
				b = remainder;
			}
			return a;
		}
	}
}

Measured memory_bytes: 28192
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int A, B, M, mina = 100000, minb = 100000;
    cin >> A >> B >> M;
    vector<int> a(A), b(B), x(M), y(M), c(M);
    for (auto& i : a) {
        cin >> i;
        if (i < mina) mina = i;
    }
    for (auto& i : b) {
        cin >> i;
        if (i < minb) minb = i;
    }
    int ans = mina + minb;
    for (int i = 0; i < M; i++) {
        cin >> x[i] >> y[i] >> c[i];
        int t = a[x[i] - 1] + b[y[i] - 1] - c[i];
        if (t < ans) ans = t;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    int A,B;
    cin >> A >> B;
    if(A != 1 && B!= 1){
        cout <<1<< "\n";
    }else if(A != 2 && B!= 2){
        cout <<2<< "\n";
    }else{
        cout <<3<< "\n";
    }
}

Measured memory_bytes: 256
fun main(args:Array<String>) {
	val(n,t)= readLine()!!.split(" ").map {it.toInt()}
	val a= readLine()!!.split(" ").map {it.toInt()}
	
	var min=1000010000
	var maxDiff=0
	var count = 0
	for(i in a.indices){
		val diff=a[i]-min
		if(diff<0){
			min = a[i]
		}else if(diff==maxDiff){
			count++
		}else if(diff>maxDiff){
			maxDiff=diff
			count=1
		}
	}
	println(count)
	
}

Measured memory_bytes: 51504
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>

class union_find {
  mutable std::vector<intmax_t> c;

public:
  union_find(size_t n): c(n, -1) {}

  size_t find(size_t v) const {
    if (c[v] < 0) return v;
    return (c[v] = find(c[v]));
  }

  bool unite(size_t u, size_t v) {
    u = find(u);
    v = find(v);
    if (u == v) return false;
    if (-c[u] > -c[v]) std::swap(u, v);
    c[v] += c[u];
    c[u] = v;
    return true;
  }

  bool connected(size_t u, size_t v) const { return (find(u) == find(v)); }

  size_t size() const { return c.size(); }
  size_t size(size_t v) const {
    return -c[find(v)];
  }
};

int testcase_ends() {
  size_t N, M;
  scanf("%zu %zu", &N, &M);
  if (N == 0 && M == 0) return 1;

  std::vector<std::tuple<int, size_t, size_t>> tsd(M);
  for (auto& p: tsd) {
    int t;
    size_t s, d;
    scanf("%d %zu %zu", &t, &s, &d);
    --s, --d;
    p = std::make_tuple(t, s, d);
  }
  std::sort(tsd.begin(), tsd.end());

  union_find uf(N);
  for (auto& p: tsd) {
    int t;
    size_t s, d;
    std::tie(t, s, d) = p;
    if (!uf.connected(0, s)) continue;
    uf.unite(s, d);
  }
  printf("%zu\n", uf.size(0));
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 3336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

P calc(P p1, P p2) {
  P res = make_pair(min(p1.first, p2.first), max(p1.second, p2.second));
  return res;
}

ll score(P p) { return max(0LL, p.first - p.second + 1); }

int main() {
  ll n;
  cin >> n;
  vector<P> a;
  ll ans = 0;
  REP(i, n) {
    ll l, r;
    cin >> l >> r;
    ans = max(ans, r - l + 1);
    a.push_back(make_pair(r, l));
  }
  auto comp = [&](P p, P q) {
    if (p.first == q.first) return p.second > q.second;
    return p.first < q.first;
  };
  sort(ALL(a), comp);
  vector<P> left(n), right(n);
  P cur = make_pair(1e18, 0);
  REP(i, n - 1) {
    cur = calc(cur, a[i]);
    left[i] = cur;
  }
  cur = make_pair(1e18, 0);
  IFOR(i, 1, n) {
    cur = calc(cur, a[i]);
    right[i] = cur;
  }
  REP(i, n - 1) { ans = max(ans, score(left[i]) + score(right[i + 1])); }
  FOR(i, 1, n - 1) {
    ll t = score(a[i]) + score(calc(left[i - 1], right[i + 1]));
    ans = max(ans, t);
  }
  cout << ans << endl;
}

Measured memory_bytes: 5104
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

S = sys.stdin.buffer.readline().decode().rstrip()
X, Y = list(map(int, sys.stdin.buffer.readline().split()))

# X 軸と Y 軸は独立に考えられる。
d = 0
cnt = 0
xy = [[], []]
for c in S:
    if c == 'F':
        cnt += 1
    else:
        xy[d].append(cnt)
        cnt = 0
        d = d + 1 & 1
xy[d].append(cnt)
X -= xy[0].pop(0)


def can_make(moves, obj):
    if obj < -8000:
        return False
    obj = 1 << (8000 + obj)
    dp = 1 << 8000
    for mv in moves:
        if mv == 0:
            continue
        dp = (dp << mv) | (dp >> mv)
    return (dp & obj) > 0


ok = can_make(xy[0], X) and can_make(xy[1], Y)
if ok:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3188