akhauriyash/Code-Regression huggingface dataset:
use std::io::BufRead;
use std::io;

fn main() {
    let mut buffer = String::new();
    let stdin = io::stdin();
    let mut handle = stdin.lock();
    handle.read_line(&mut buffer).unwrap();
    let buffer = buffer.trim();
    let n:i32 = buffer.split_whitespace().next().unwrap()
            .parse().unwrap();
    let mut v = Vec::new();
    for _i in 0..n {
        let mut buffer = String::new();
        handle.read_line(&mut buffer).unwrap();   
        v.push(buffer.trim().to_owned());
    }
    v.sort();
    let mut ans = 1;
    for i in 0..v.len()-1 {
        if v[i] != v[i+1] {
            ans+=1;
        }
    }
    println!("{}",ans);
}

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

using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second

unordered_map<ll,vector<ll>> graph,graph1;

vector<pair<ll,pair<ll,ll>>> v;
unordered_map<ll,ll> vis,vis1;


void dfs(ll s){
    for(ll i=0;i<graph[s].size();i++){
        if(!vis[graph[s][i]])
        {
            vis[graph[s][i]] = 1;
            dfs(graph[s][i]);
        }
    }
}


void dfs1(ll s){
    for(ll i=0;i<graph1[s].size();i++){
        if(!vis1[graph1[s][i]])
        {
            vis1[graph1[s][i]] = 1;
            dfs1(graph1[s][i]);
        }
    }
}
void bellmanford(ll n,ll m)
{
    vector<ll> dist(n+1);
    for(ll i=1;i<=n;i++){
        dist[i] = INT_MIN;
        
    }
    dist[1]=0;
    
    for(ll i=0;i<n-1;i++){
        
        for(ll j=0;j<m;j++){
            ll a = v[j].ff;
            ll b = v[j].ss.ff;
            ll c = v[j].ss.ss;
            
            if((dist[a] + c) > dist[b])
            {
                
                dist[b] = dist[a] + c;
                // cout<<b<<" "<<dist[b]<<"\n";
            }
                
        }
        
    }
    
    // if(dist[n]<0)
    // {
    //     cout<<0<<endl;
    //     return;
        
    // }
    
    for(ll j=0;j<m;j++){
        ll a = v[j].ff;
        ll b = v[j].ss.ff;
        ll c = v[j].ss.ss;
        
        if((dist[a] + c) > dist[b] and vis[b])
        {
            cout<<-1<<endl;
            return;
        }
            
    }
    
    
    cout<<max(0LL, dist[n])<<endl;
            
}


int main() {
    
    ll n,m,p;
    cin>>n>>m>>p;
    
    for(ll i=0;i<m;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        // a--;
        // b--;
        graph[a].pb(b);
        
        graph1[b].pb(a);
        
        v.pb({a,{b,c-p}});
    }
    
    dfs(1);
    dfs1(n);
    
    for(ll i=1;i<=n;i++){
        vis[i] = vis[i] & vis1[i];
    }
    
    sort(v.begin(),v.end());
    
    // for(ll i=0;i<m;i++){
    //     ll a = v[i].ff;
    //     ll b = v[i].ss.ff;
    //     ll c = v[i].ss.ss;
    //     cout<<a<<" "<<b<<" "<<c<<endl;
    // }
    
    bellmanford(n,m);
    
	
	return 0;
}













Measured memory_bytes: 1152
#include <stdio.h>
int main(void)
{
    int tm[5],i;
    for(i=0;i<4;i++)
        scanf("%d",&tm[i]);
    tm[4]=tm[0]+tm[1]+tm[2]+tm[3];
    printf("%d\n%d\n",tm[4]/60,tm[4]%60);
    return 0;
}

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

#define int long long
#define fi first
#define se second
#define pb push_back

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

int n, suff[200005], nxt[200005][26], ini;
string s;

signed main(){
	ios_base::sync_with_stdio(0);
	cin >> s;
	n = s.length();
	s = '*' + s;
	for(int i = n; i >= 1; i--){
		ini |= (1 << (s[i] - 'a'));
		if(ini == ((1 << 26) - 1)){
			suff[i] = suff[i + 1] + 1;
			ini = 0;
		}
		else suff[i] = suff[i + 1];
		//cout << suff[i] << "\n";
	}
	for(int i = 0; i < 26; i++) nxt[n][i] = n + 1;
	for(int i = n - 1; i >= 0; i--){
		for(int j = 0; j < 26; j++) nxt[i][j] = nxt[i + 1][j];
		nxt[i][s[i + 1] - 'a'] = i + 1;
	}
	string ans = "";
	int pos = 0;
	//cout << suff[1] << "\n";
	//cout << s.length() << "\n";
	for(int i = 1; i <= suff[1] + 1; i++){
		//cout << pos << "\n";
		for(int j = 0; j < 26; j++){
			//if(nxt[pos][j] > n) continue;
			//if(nxt[pos][j] == n && i != (suff[1] + 1)) continue;
			//cout << i << " " << j << " " << nxt[pos][j] + 1 << " " << suff[nxt[pos][j] + 1] << " " << suff[1] + 1 - i << "\n";
			if(nxt[pos][j] <= n && suff[nxt[pos][j] + 1] >= (suff[1] + 1 - i) && (i != (suff[1] + 1))) continue;
			if(i == (suff[1] + 1) && nxt[pos][j] <= n) continue;
			pos = nxt[pos][j];
			ans += char(97 + j);
			break;
		}
	}
	cout << ans;
}


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

int main() {
  int N , D;
  cin >> N >> D ;
  int ans = 0;
  D = D + D + 1;
  
  while (N > D) {
    
    N = N - D;
    ans++;
  }
  
  cout << ans + 1 << endl;
  
}

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

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

int main() {

  int N, X;
  cin >> N >> X;

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

  int answer = abs(x[0] - X);

  for (int i = 0; i < N; i++){
    int gcd_ = abs(x[i] - X);
    answer = gcd(gcd_, answer);
  }

  cout << answer << endl;

  return 0;

}

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

#define MAX 50

int N, M;
string A[MAX];
string B[MAX];

int main() {
	cin >> N >> M;
	for( int i = 0; i < N; i++ ) {
		cin >> A[i];
	}
	for( int i = 0; i < M; i++ ) {
		cin >> B[i];
	}

	int ans = 0;
	if( M > N ) {
		ans = 1;
	}
	else {
		int d = N - M;
		int same = 0;
		for( int k = 0; k <= d; k++ ) {
			for( int j = 0; j <= d; j++ ) {
				int flag = 0;
				for( int i = 0; i < M; i++ ) {
					string b = B[i];
					string a = A[i + k].substr( j, M );
					if( a != b ) {
						flag = 1;
						break;
					}
				}
				if( flag == 0 ) {
					same = 1;
					break;
				}
			}
		}
		if( same == 0 ) {
			ans = 1;
		}
	}

	if( ans == 0 ) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
cnt = [0] * N
for a in A:
    cnt[a - 1] += 1

for ai in range(N):
    if K - Q + cnt[ai] > 0:
        print("Yes")
    else:
        print("No")


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

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    int ans = max({10 * A + B + C, A + 10 * B + C, A + B + C * 10});

    cout << ans << endl;

    return 0;
}

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

int main(){
  int i,n;
  cin >> n;
  long long a[n+1],sum=0;
  for(i=1;i<=n;i++){
    cin >> a[i];
    a[i]-=i;
  }
  sort(a+1,a+n+1);
  long long ans=0; 
  for(i=1;i<=n;i++){
    ans+=abs(a[i]-a[(n+1)/2]);
  }
  cout << ans << endl;
  return 0;
}
  
  


Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
int n,a,b;
char in[M];
int main()
{
	while(~scanf("%d %d %d",&n,&a,&b))
	{
		scanf("%s",in);

		int ca=0, cb=0;
		REP(i,0,n-1)
		{
			if(in[i]=='a' && ca+cb<a+b)
			{
				ca++;
				puts("Yes");
			}
			else if(in[i]=='b' && ca+cb<a+b && cb<b)
			{
				cb++;
				puts("Yes");
			}
			else puts("No");
		}
	}
	return 0;
}



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

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

const int N = 2e5;
ll a[N];
ll used[N];
ll sum[N];
ll pos[N];

void solve() {
  ll n, x, MOD; cin >> n >> x >> MOD;
  a[0] = x; used[x] = 1;
  ll period, periodsum;
  sum[0] = x;
  int pred = 0;
  for (int i = 1; ; i++) {
    ll v = (a[i - 1] * a[i - 1]) % MOD;
    if (used[v]) {
      pred = used[v] - 1;
      period = (i+1) - used[v];
      periodsum = sum[i - 1];
      if (pred != 0)
        periodsum -= sum[pred - 1];
      break;
    }
    a[i] = v; used[v] = i + 1;
    sum[i] = a[i] + sum[i - 1];
    //cout << i << " " << a[i] << " " << sum[i] << endl;
  }
  //cout << period << " " << periodsum << endl;
  if (n <= pred) {
    cout << sum[n - 1]; return;
  }
  ll res = ((n-pred) / period) * periodsum;
  if (pred != 0) res += sum[pred - 1];
  n -= pred;
  n %= period;
  n += pred;
  res += sum[n - 1];
  if (pred != 0) res -= sum[pred - 1];
  cout << res;
}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES (n == 1)

int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(2);
  //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl;
  solve();
}


Measured memory_bytes: 5108
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  100005

int main()
{
	
	io
	
	ll x;
	cin>>x;
	ll res=0;
	ll zz=(x/500);
	ll rem=(x%500);
	res+=(1000*zz);
	zz=(rem/5);
	res+=(zz*5);
	cout<<res;
}

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

int main(){
  int m,g;
  int a[7],b[7];
  int n;
  int t[1001];
  int c[1001];

  while(1){
    cin >> m;
    if(!m)break;

    for(int i=0;i<m;i++)cin >> a[i] >> b[i];
    for(int i=1;i<=1000;i++){
      t[i] = 0;
      c[i] = 0;
    }
    t[0] = 1;
    c[0] = 1;
    
    for(int i=0;i<m;i++){
      for(int j=1;j<=b[i];j++){
	for(int k=0;k<=1000-a[i]*j;k++){
	  if(c[k]){
	    t[k+a[i]*j]+=c[k];
	  }
	}
      }
      for(int j=0;j<=1000;j++){
	if(t[j]>0)c[j] = t[j];
      }
    }
    
    cin >> g;
    for(int i=0;i<g;i++){
      cin >> n;
      cout << t[n] << endl;
    }
  }
}

Measured memory_bytes: 0
#include <stdio.h>
int main(void){
    // Your code here!
    long long int K,A,B,C=1,num;
    
    scanf("%lld %lld %lld",&K,&A,&B);
    
    C+=A-1;
    K-=A-1;
    
    if(K%2==1){
        K--;
        C++;
    }
    
    num=B-A;
    
    
    if(num>2){
        C+=(K/2)*num;
    }else{
        C+=K;
    }
    
    printf("%lld\n",C);
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , bytes ) => { read_value ! ( $ next , String ) . into_bytes ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
#[allow(dead_code)]
pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
    let out = stdout();
    let writer = BufWriter::new(out.lock());
    f(writer)
}
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) } ; }
#[allow(dead_code)]
fn main() {
    input!{
        n: usize,
        s: [u64; n],
    }
    let mut ans = 0;
    for &v in &s {
        ans += v;
    }
    let mut mins = 100;
    for &v in &s {
        if v % 10 != 0 && v < mins {
            mins = v;
        }
    }
    if mins == 100 {
        println!("{}", 0);
        return;
    }
    if ans % 10 == 0 {
        ans -= mins;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
//#define int long long
int main(){
  string a;
  cin>>a;
  if(a.size()>=4){
  if(a[0]=='Y'&&a[1]=='A'&&a[2]=='K'&&a[3]=='I')cout<<"Yes";
  else cout<<"No";
  }else cout<<"No";
  return 0;
}

Measured memory_bytes: 256
import java.util.Comparator;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int num=0;
        int N = sc.nextInt();
        ArrayList<Integer> L = new ArrayList<>();
        for(int a=0;a<2*N;a++){
            int l = sc.nextInt();
            L.add(l);
        }
        Collections.sort(L);
        for(int a=0;a<N;a++){
            num += L.get(2*a);
        }
        System.out.println(num);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#define ll long long
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
template <typename T>
inline void w(T x) {
	if (x > 9) w(x / 10);
	putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x, char c) {
	w(x);
	putchar(c);
}
template <typename T>
inline void read(T &x) {
	x = 0;
	T f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
ll gcd(ll a, ll b){
	return b == 0 ? a : gcd(b, a % b);
}
int main(){
	ll n;
	cin >> n;
	ll ans = 0;
	for(ll i = 1; i <= n; i++){
		for(ll j = 1; j <= n; j++){
			for(ll k = 1; k <= n; k++){
				ans += gcd(i, gcd(j, k));
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

char s[50][50];
int dx[]{1,-1,0,0},dy[]{0,0,1,-1};
int d[50][50];

signed main(){
	int h,w;scanf("%d%d",&h,&w);
	rep(i,h)scanf("%s",s[i]);
	queue<P>que;que.push(P(0,0));
	memset(d,-1,sizeof(d));d[0][0]=0;
	while(!que.empty()){
		P p=que.front();que.pop();
		rep(i,4){
			int nx=p.first+dx[i],ny=p.second+dy[i];
			if(0<=nx&&nx<h&&0<=ny&&ny<w&&d[nx][ny]==-1&&s[nx][ny]!='#'){
				d[nx][ny]=d[p.first][p.second]+1;
				que.push(P(nx,ny));
			}
		}
	}
	int cnt=0;
	rep(i,h)rep(j,w){
		if(s[i][j]=='#')cnt++;
	}
	if(d[h-1][w-1]==-1){puts("-1");return 0;}
	int a=h*w-d[h-1][w-1];
	cout<<a-cnt-1<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
using namespace std;

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

	if (K == 1) {
		cout << 0 << endl;
	}
	else {
		int ans1 = (N - K) + 1;
		int ans2 = ans1 - 1;

		cout << ans2 << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  double a,b,h,m;
  cin >> a >> b >> h >> m;
  double radb=m/60.0*360;
  double rada=h/12.0*360+m/60.0*30;
  double rad=rada-radb;
  while(rad<0) rad+=360;
  if(rad>=180) rad=360-rad;
  double ans=sqrt(a*a+b*b-2*a*b*cos(rad/180.0*M_PI));
  cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 4228
x, y, a, b, c = map(int, input().split())

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse = True)
q.sort(reverse = True)
for i in range(x):
    r.append(p[i])

for i in range(y):
    r.append(q[i])

r.sort(reverse = True)

ans = 0
for i in range(x + y):
    ans += r[i]

print(ans)

Measured memory_bytes: 22560
using System;

namespace AtCoderProblems
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);

            Console.WriteLine(a * b);

        }
    }

}

Measured memory_bytes: 27320
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int a,b,n,x,y;
    cin>>a>>b;
    if(b<10)
    {
        n=a*10+b;
    }
    else if(b<100 && b>=10)
    {
        n=a*100+b;
    }
    else if(b==100)
    {
        n=a*1000+b;
    }
    x=sqrt(n);
    y=x*x;
    if(y==n)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

int main(void) {
    int a, b, c, d;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;

    int out;

    out += (a > b ? b : a);
    out += (c > d ? d : c);

    cout << out << endl;

    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
np = n

if k == 1:
    n = 0
else:
    if abs(n - k) > np:
        print(n)
        exit()
    
    while abs(n - k) < np:
        i = 1
        if k ** i < n:
            while k ** i < n :
                i += 1
            n = n - k ** (i - 1)
        np = n
        n = abs(n - k)
print(n)


Measured memory_bytes: 2940
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
sum_a = [0]*n
sum_a[0] = a[0]
for i in range(1, n):
    sum_a[i] = sum_a[i-1] + a[i]
#print(sum_a)
ans = 0
for i in range(n):
    sum_i = sum_a[n-1] - sum_a[i]
    ans = (ans + sum_i*a[i] % mod) % mod
print(ans % mod)

Measured memory_bytes: 105252
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <map>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
#define MP make_pair
int main(){
  string s,key="apple",ans="peach";
  while(getline(cin,s)){
    for(int i=0;i<s.size();i++){
      if(s[i]=='a'){
        bool f=true;
        for(int j=0;j<5;j++){
          if(s[i+j]!=key[j])f=false;
        }
        if(f)for(int j=0;j<5;j++){
          s[i+j]=ans[j];
        }
        continue;
      }
      if(s[i]=='p'){
        bool f=true;
        for(int j=0;j<5;j++)if(s[i+j]!=ans[j])f=false;
        if(f)for(int j=0;j<5;j++)s[i+j]=key[j];
        continue;
      }
    }
    cout<<s<<endl;
  }
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please


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

	
	string S;
	cin >> S;
	
	rep(i, 26) {
		int dame = 0;
		rep(ii, S.size()) {
			if (S[ii] == 'a' + i) dame = 1;
		}
		if (dame == 0) {
			char c = 'a' + i;
			co(c);
			return 0;
		}
	}

	co("None");

	Would you please return 0;
}

Measured memory_bytes: 512
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n, start = Is()
X = LI()
m = min(X+[start])
ans = reduce(gcd, [x-m for x in X+[start]])
print(ans)


Measured memory_bytes: 87532
#include <iostream>
#include <map>
#include <queue>
#include <functional>
#include <algorithm>
using namespace std;

class Vertax
{
public:
	int n, d, c;
	Vertax(){}
	Vertax(int n, int d, int c) : n(n), d(d), c(c){}
};
bool operator > (Vertax v1, Vertax v2)
{
	if (v1.c == v2.c) return v1.d > v2.d;
	return v1.c > v2.c;
}
bool operator < (Vertax v1, Vertax v2)
{
	if (v1.c == v2.c) return v1.d < v2.d;
	return v1.c < v2.c;
}

typedef pair<int, int> p;
const int INF = 99999999;

int C, N, M, S, D; //??????????????°???????????°???????????°???????????°???????????°

int main()
{
	while (cin >> C >> N >> M >> S >> D, C + N + M + S + D)
	{
		vector<p> edge[101];
		priority_queue<Vertax, vector<Vertax>, greater<Vertax>> que;
		int distance[11][101];

		for (int i = 0; i < M; i++)
		{
			int a, b, f;
			cin >> a >> b >> f;
			edge[a].push_back(p(b, f));
			edge[b].push_back(p(a, f));
		}
		for (int i = 0; i <= C; i++)
		{
			for (int j = 0; j <= N; j++)
			{
				distance[i][j] = INF;
			}
		}
		
		Vertax start;
		start.n = S;
		start.d = 0;
		start.c = 0;
		que.push(start);
		distance[0][S] = 0;

		while (!que.empty())
		{
			int n = que.top().n;
			int d = que.top().d;
			int c = que.top().c;
			que.pop();

			for (int i = 0; i < edge[n].size(); i++)
			{
				int to = edge[n][i].first;
				int dis = edge[n][i].second;

				if (distance[c][to] > d + dis)
				{
					distance[c][to] = d + dis;
					que.push(Vertax(to, d + dis, c));
				}
				if (c < C && distance[c + 1][to] > d + (dis / 2))
				{
					distance[c + 1][to] = d + (dis / 2);
					que.push(Vertax(to, d + (dis / 2), c + 1));
				}
			}
		}

		int ans = INF;
		for (int i = 0; i <= C; i++)
		{
			ans = min(ans, distance[i][D]);
		}
		cout << ans << endl;
	}

	return 0;
}

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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	int n;
	long long k;
	cin >> n >> k;
	vector<int> a(n+1, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i + 1];
	}

	vector<int> index(n + 1, -1);
	index[1] = 0;
	int cur = 1;
	int rest = 0;
	for (int i = 1; i <= k; i++) {
		cur = a[cur];
		if (index[cur] == -1) {
			index[cur] = i;
		}
		else {
			int loop = i - index[cur];
			rest = (k - index[cur]) % loop;
			break;
		}
	}

	int res = cur;
	for (int i = 0; i < rest; i++) {
		res = a[res];
	}
	cout << res << endl;
	return 0;
}



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

int main(){
	int t[200000];
	int n,T,sumt = 0,sum=0;

	cin >> n >>T;

	for(int i = 0;i < n;++i)
		cin >> t[i];

	for(int i = 1; i < n;++i){
		if(t[i] - t[i-1]>=T)
			sum += T;
		else
			sum += t[i] - t[i-1];
	}

	cout << sum + T << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
class sai
{
    public :
    int ue;
    int tem;
    int migi;
    int hidari;
    int oku;
    int sita;
};


int main(void){
    int a1,a2,a3,a4,a5,a6;
    cin >> a1 >> a2 >> a3 >> a4 >> a5 >> a6 ;
    sai b = {a1,a2,a3,a4,a5,a6};
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'S') {
            b = {b.oku,b.ue,b.migi,b.hidari,b.sita,b.tem};
        } else if (s[i] == 'N') {
            b = {b.tem,b.sita,b.migi,b.hidari,b.ue,b.oku};
        } else if (s[i] == 'E') {
            b = {b.hidari,b.tem,b.ue,b.sita,b.oku,b.migi};
        } else if (s[i] == 'W') {
            b = {b.migi,b.tem,b.sita,b.ue,b.oku,b.hidari};
        }
    }
    cout << b.ue << endl;
    return 0;
}


Measured memory_bytes: 3220
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> heights(N);
    rep(i,0,N) {
        cin >> heights[i];
    }
    vector<bool> good(N, true);
    rep(i,0,M) {
        ll A, B;
        cin >> A >> B;
        A--;
        B--;
        if (heights[A] <= heights[B]) {
            good[A] = false;
        }
        if (heights[B] <= heights[A]) {
            good[B] = false;
        }
    }
    ll good_cnt = 0;
    rep(i,0,N) {
        if (good[i]) {
            good_cnt++;
        }
    }
    cout << good_cnt << endl;
}


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 2010

int N, X, Y;
int A[MAX_N];

// 0: X 1: Y
// 次が i さんのターンで、相手が持っているのが山札の上から j 番目のカードの場合
// 0 は初期手札とする
int dp[2][MAX_N];

int main()
{
    ZERO(dp);

    cin >> N >> X >> Y;

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

    dp[0][N-1] = abs(A[N] - A[N-1]);
    dp[1][N-1] = abs(A[N] - A[N-1]);
    for(int j = N - 2; j >= 0; --j) {
        int cand = abs(A[N] - A[j]);
        for(int i = 0; i < 2; ++i) {
            for(int k = j + 1; k < N; ++k) {
                if(i == 0) { cand = max(cand, dp[1][k]); }
                else { cand = min(cand, dp[0][k]); }
            }
            dp[i][j] = cand;
        }
    }
    printf("%d\n", dp[0][0]);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

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

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> t(N + 1), x(N + 1), y(N + 1);
    t[0] = 0;
    x[0] = 0;
    y[0] = 0;
    REP(i, N) { cin >> t.at(i + 1) >> x.at(i + 1) >> y.at(i + 1); }

    REP(i, N) {
        int dt = t[i + 1] - t[i];
        int dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
        if (!(dt >= dist && dist % 2 == dt % 2)) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
const int mod=1e9+7;
const int N=2001;
int dp[N][N],n,k;
int fac[N*N],inv[N*N];
inline int C(int n,int m){if(m>n)return 0;return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;}
inline int fpow(int x,int k){
	int ret=1;
	for(;k;k>>=1,x=1ll*x*x%mod) if(k&1) ret=1ll*ret*x%mod;return ret;
}
int main()
{
	scanf("%d %d",&n,&k);int tot=n*k;fac[0]=1;
	if(k==1) return puts("1"),0;
	for(int i=1;i<=tot;++i) fac[i]=1ll*fac[i-1]*i%mod;
	inv[tot]=fpow(fac[tot],mod-2);
	for(int i=tot-1;i;--i) inv[i]=1ll*inv[i+1]*(i+1)%mod;inv[0]=1;
	dp[0][0]=1;
	for(int i=1;i<=n;++i)
		for(int j=0;j<=i;++j){
			dp[i][j]=dp[i-1][j];
			if(j) (dp[i][j]+=1ll*dp[i][j-1]*C(tot-i-1-(j-1)*(k-1),k-2)%mod*(n-j+1)%mod)%=mod;
		}
	printf("%d\n",dp[n][n]);
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

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

  vi h(n);
  rep(i, 0, n) cin >> h[i];

  vi dp(n, inf);
  dp[0] = 0;
  rep(i, 0, n){
    if(i+1 < n) chmin(dp[i+1], dp[i] + abs(h[i]-h[i+1]));
    if(i+2 < n) chmin(dp[i+2], dp[i] + abs(h[i]-h[i+2]));
  }

  cout << dp[n-1] << endl;

  return 0;
}


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

int n, re[1024 * 1024], rw[1024 * 1024], *e = re + 1, *w = rw + 1;
char str[1024 * 1024];

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

   for (;;)
   {
      n = 0;
      if (2 != scanf("%d%s", &n, str) || n <= 0)
         break;

      auto m = n;
      for (auto i = 0; i < n; ++i)
      {
         e[i] = 'E' == str[i];
         w[i] = 'E' != str[i];
         if (i)
         {
            e[i] += e[i - 1];
            w[i] += w[i - 1];
         }
      }
      e[n] = e[n - 1];
      w[n] = w[n - 1];

      const auto te = e[n - 1], tw = w[n - 1];
      m = min({m, te, tw});
      for (auto i = 0; i < n; ++i)
      {
         const auto ce = w[i] + te - e[i],
            cw = w[i - 1] + te - e[i - 1];
         m = min({m, ce, cw});
      }

      cout << m << '\n';
#ifdef _DEBUG
      memset(re, 0, sizeof re);
      memset(rw, 0, sizeof rw);
#else
      break;
#endif
   }
   return 0;
}


Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n,a,b;
    cin >> n >> a >> b;
    int p[n];
    REP(i,n){
        cin >> p[i];
    }
    int cnt_a = 0, cnt_b = 0, cnt_c = 0;
    REP(i,n){
        if(p[i] <= a){
            cnt_a++;
        }else if(p[i] <= b){
            cnt_b++;
        }else{
            cnt_c++;
        }
    }
    cout << min(cnt_a, min(cnt_b, cnt_c)) << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, K,W, H, Q, X, Y;
  ll ans;
  string S, T;
  cin >> X >> Y;
  cout << X + Y/2 <<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);

int main(){
  int a,b;
  cin >>a >> b;
  cout << 6-a-b << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int a,b,i = 0;
	char s[128];

	while(fgets(s,sizeof(s),stdin) != NULL){
		sscanf(s,"%d %d" , &a , &b);
		printf("%d\n",f(a+b));
	}
	return(0);
}

int f(int i){
	int c = 1;
	while(1){
		if(i/10 > 0){
			i = i /10;
			c++;
		}else break;
	}
	return c;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

int W, H;
string m[120];
bool visit[120][120];
const int di[4] = {0,0,-1,1};
const int dj[4] = {1,-1,0,0};

void dfs(const int ci, const int cj, const char cc) {
  for (int i = 0; i < 4; ++i) {
    int ni = ci + di[i], nj = cj + dj[i];
    if (ni < 0 || nj < 0 || H <= ni || W <= nj) continue;
    if (m[ni][nj] != cc || visit[ni][nj]) continue;
    visit[ni][nj] = true;
    dfs(ni, nj, cc);
  }
}

int solve() {
  memset(visit, 0, sizeof visit);
  int ret = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (!visit[i][j]) {
        dfs(i, j, m[i][j]);
        ++ret;
      }
    }
  }
  return ret;
}

int main() {
  ios_base::sync_with_stdio(false);
  while (cin >> H >> W, H || W) {
    for (int i = 0; i < H; ++i)
      cin >> m[i];
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 2180
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int, int>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) FOR(i, 0, n)
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define FILLINF(a) memset(a, 0x3f, sizeof(a))
#define POW(n) (1LL << (n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i, a, b) ((a) <= (i) && (i) <= (b))
using namespace std;
template <typename T> inline bool CHMIN(T& a, T b) { if(a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a, T b) { if(a < b) { a = b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(begin(a), end(a)); }
template <typename T> inline void REV(T& a) { reverse(begin(a), end(a)); }
template <typename T> inline void UNI(T& a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }
template <typename S, typename T> inline T LB(S& v, T a) { return *lower_bound(begin(v), end(v), a); }
template <typename S, typename T> inline int LBP(S& v, T a) { return lower_bound(begin(v), end(v), a) - begin(v); }
template <typename S, typename T> inline T UB(S& v, T a) { return *upper_bound(begin(v), end(v), a); }
template <typename S, typename T> inline int UBP(S& v, T a) { return upper_bound(begin(v), end(v), a) - begin(v); }
template <typename S, typename T> ostream& operator << (ostream& os, const pair<S, T>& p) { os << p.first << " " << p.second; return os; }
template <typename S, typename T> istream& operator >> (istream& is, pair<S, T>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T>& v) { for (int i = 0; i < v.size(); ++i) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator >> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) { for(auto &e : t) fill_v(e, v); }
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const lint MOD = 1000000007;

void _main() {
    int K, A, B;
    cin >> K >> A >> B;
    int x = B / K * K;
    cout << (A <= x ? "OK" : "NG") << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i')) freopen("in.txt", "r", stdin);
        if (strchr(argv[1], 'o')) freopen("out.txt", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 3652
function main()
    data = readlines()
    N = parse(Int, data[1])
    A = parse.(BigInt, split(data[2]))
    mod = 10^9 + 7
    B = A[end]
    ans = 0
    for a in A[end-1:-1:1]
        ans += a * B
        B += a
    end
    return println(ans%mod)
end
main()

Measured memory_bytes: 282432
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

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;
}

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return a;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

void solve(void){
    int n,k;
    cin >> n >> k;
    int h[n];
    rep(i,0,n) cin >> h[i];
    int dp[n];
    dp[0] = 0;
    rep(i,1,n){
        dp[i] = INF;
    }
    
    rep(i,1,n){
        rep(j,1,k+1){
            if(i - j >=0) chmin(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }

    cout << dp[n-1] << endl;

}

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

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

#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define MOD 1000000007

const int MAX_M = 100000;


ll beki(ll x, ll y){	//xのy乗をmodで割った余り
  ll sum = 1;
  
  rep(i,1,y+1){
    sum *= x;
    sum %= MOD;
  }
  
  return sum;
}

int main(){
  ll n;
  //string s;
  cin >> n;
  
  //vector<ll> a(n);
  //queue<ll> q;
  //map<string,ll> d{};
  
  ll ans = 0;
  
  ans = beki(10,n);
  ans -= beki(9,n);
  ans -= beki(9,n);
  ans += beki(8,n);
  ans %= MOD;
  
  cout << (ans+MOD)%MOD << endl;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

ll A, B, N;

ll f(ll x) {
  if (1 <= x && x <= N) {
    return (A*x/B) - A*(x/B);
  }
  return -1;
}

int main2() {
  A = nextLong();
  B = nextLong();
  N = nextLong();
  ll ans = 0;
  for (ll x = 1; x <= 10000000; x++) {
    chmax(ans, f(x));
  }
  for (ll x = N - 10000000; x <= N; x++) {
    chmax(ans, f(x));
  }

  if (N / B <= 10000000) {
    for (ll x = B - 1; x <= N; x += B) {
      chmax(ans, f(x));
    }
  }

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

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 3808
#include<stdio.h>
#include<algorithm>
using namespace std;
int dp[200][101];
int c[200];
int d[200];
int e[200];
int f[200];
int ABS(int a){return max(a,-a);}
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%d",c+i);
	for(int i=0;i<b;i++)scanf("%d%d%d",d+i,e+i,f+i);
	for(int i=0;i<a;i++)
		for(int j=0;j<101;j++)
			dp[i][j]=-99999999;
	for(int i=0;i<b;i++)if(d[i]<=c[0]&&c[0]<=e[i])dp[0][f[i]]=0;
	for(int i=0;i<a-1;i++){
		for(int j=0;j<101;j++){
			if(dp[i][j]>=0){
				for(int k=0;k<b;k++)if(d[k]<=c[i+1]&&c[i+1]<=e[k])dp[i+1][f[k]]=max(dp[i+1][f[k]],dp[i][j]+ABS(j-f[k]));
			}
		}
	}
	int ret=0;
	for(int i=0;i<101;i++)ret=max(ret,dp[a-1][i]);printf("%d\n",ret);
}

Measured memory_bytes: 1108
#include<stdio.h>
int main(){
  int c[500],s[500],f[500],n,i,j,t;
  scanf("%d",&n);
  for(i=0;i<n-1;i++)scanf("%d%d%d",&c[i],&s[i],&f[i]);
  for(i=0;i<n;i++){
    t=0;
    for(j=i;j<n-1;j++){
      if(t<s[j])t=s[j];
      else t=(t/f[j]+(t%f[j]!=0))*f[j];
      t+=c[j];
    }
    printf("%d\n",t);
  }
}


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

int main(){
	int n,k;
	int pos1;
	int temp;
	int ans;
	
	cin >> n>>k;
	
	pos1=0;
	while(temp!=1){
		cin >> temp;
		pos1++;
	}
	int right=(n-pos1+k-2)/(k-1);
	int rt = right*(k-1) - (n-pos1);
	int left=(pos1-1+k-2)/(k-1);
	int lt = left*(k-1) - (pos1-1);
	
	ans = right+left;
	if(lt+rt>=k-1)ans--;
	// cout << right <<endl;
	// cout << rt <<endl;
	// cout << left <<endl;
	// cout << lt <<endl;
	
	cout << ans << endl;
	
	return 0;
}

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

using namespace std;

#define RPT(i, b, e) for (int i = (b); i <= (e); i++)
#define RPT0(i, n) RPT(i, 0, n - 1)
#define RPT1(i, n) RPT(i, 1, n)

void resolve()
{
    int N, X, Y;
    cin >> N >> X >> Y;

    int cnt[2001] = {0};
    RPT1(i, N - 1) RPT(j, i + 1, N)
    {
        int d = min(j - i, abs(i - X) + 1 + abs(j - Y));
        cnt[d]++;
    }
    RPT(i, 1, N - 1) cout << cnt[i] << endl;
}

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


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	int A[110];
	int ans = 0;

	cin >> N;
	rep(i, 0, N)
	{
		cin >> A[i];
		ans += A[i];
	}

	sort(A, A + N);

	rep(i, 0, N)
	{
		if (ans % 10 != 0)
		{
			cout << ans << endl;
			return 0;
		}
		if (A[i] % 10 == 0)continue;
		ans -= A[i];
		cout << ans << endl;
		return 0;
	}

	cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 256