akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<vector>
using namespace std;
int main(){
    int N;
    cin>>N;
    vector<string>W(100);
    for(int i=0;i<N;++i)cin>>W[i];
    for(int i=1;i<N;++i){
        if(W[i].front()!=W[i-1].back()){
            cout<<"No"<<endl;
            return 0;
        }
    }
    for(int i=0;i<N;++i){
        for(int j=i+1;j<N;++j){
            if(W[i]==W[j]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;

int main()
{
    long n;
    long i;
    long sum = 0;

    cin >> n;

    for(i=0; i<n; i++) {
        if(((i+1)%5!=0) && ((i+1)%3!=0)) {
            sum += i+1;
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;


vector<vector<pair<ll, ll > > > G;
//行きがけ順番を記憶（どんな順番で走査されたかを記憶）
vector<ll > pre;
//頂点から到達しうる最小の頂点
vector<ll > low;
//到達済みの頂点か
vector<bool > reach;
vector<pair<ll, ll > > ans;
//カウンター
void dfs(ll idx, ll from = -1, ll pre_count = -1){
    reach[idx] = true;
    pre[idx] = pre_count++;
    low[idx] = pre[idx];


    for(ll i = 0; i < G[idx].size(); i++){
        //cout << idx << endl;
        //次の行き先は？
        ll to = G[idx][i].first;
        //未探査のとき
        if(pre[to] == -1){
            //dfsを実行する
            //到達できる頂点の中で一番小さいpreを採用する
            dfs(to, idx, pre_count);
            low[idx] = min(low[idx], low[to]);
            //dfs(to, idx, pre_count);
            //low[idx] = min(low[idx], low[to]);

            //後退辺を使ったとしても根やそれ以上に戻ってきていない→つまりここが橋
            if(pre[idx] < low[to]){
                ans.push_back(make_pair(idx, to));
            }
        }else if(to != from){
            low[idx] = min(low[idx], pre[to]);
        }
 
    }

    //return low[idx];
}


int main(){
    ll N, M;
    cin >> N >> M;
    
    //初期化
    G.assign(N, vector<pair<ll, ll > >());
    //ns.assign(N, 0);
    pre.assign(N, -1);
    low.assign(N, -1);
    reach.assign(N, false);
 
    //グラフ入力
    for(ll i = 0; i < M; i++){
        ll u, v;
        //重みは今回は0
        ll w = 0;
        cin >> u >> v;
        u--;
        v--;
        //双方向に貼りましょうね
        G[u].push_back(make_pair(v, w));
        G[v].push_back(make_pair(u, w));
    }

    for(ll i = 0; i < N; i++){
        if(!reach[i])dfs(i);
    }
    
    cout << ans.size()<< endl;
    
    /*
    for(ll i = 0; i < ans.size(); i++){
        cout << ans[i].first << "," << ans[i].second << endl;
    }
    */
    

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  ll n;
  cin>>n;

  vector<ll> p(n);
  map<ll,ll> q;
  rep(i,n){
    cin>>p[i];
    if(q.count(p[i])) q.at(p[i])++;
    else q[p[i]]=1;
  }

  sort(all(p));

  ll ans=0;
  for(ll i=n-1;i>=0;i--){
    if(!q.count(p[i])) continue;
    ll x=2;
    while(1){
      if(x>2*p[i]) break;
      if(p[i]+1>x) {
        x*=2;
        continue;
      }
      if(q.count(x-p[i])) {
        if(q[p[i]]==1 && p[i]==x-p[i]) {
          x*=2;
          continue;
        }
        if(q[p[i]]==1) q.erase(p[i]);
        else q[p[i]]--;
        if(q[x-p[i]]==1) q.erase(x-p[i]);
        else q[x-p[i]]--;        
        ans++;
        break;
      }
      x*=2;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 17188
def abc_149_bb
    a,b,k = gets.chomp.split(/\s/).map{|x| x.to_i}

    if a >= k
        a -= k
        k = 0
    else
        k -= a
        a = 0
    end

    if b >= k
        b -= k
    else
        #b -= (k - b)
        b = 0
    end

    print "#{a} #{b}\n"
end

abc_149_bb


Measured memory_bytes: 1916
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
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)*}
    };
}
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)*}
    };
}
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, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn gcd(a: isize, b: isize) -> isize {
    if a == 0 { b }
    else { gcd(b % a, a) }
}
fn lcm(a: isize, b: isize) -> isize {
  a / gcd(a, b) * b
}
fn main() {
    input!{
        A: isize,
        B: isize,
        C: isize,
        D: isize,
    }
    let A = A - 1;
    let mut byc = (B + C)/C - (A + C)/C;
    let mut byd = (B + D)/D - (A + D)/D;
    let lcm = lcm(C, D) as isize;
    let mut bycd = (B + lcm)/lcm - (A + lcm)/lcm;

    println!("{}", B-A-(byc+byd-bycd));
}



Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;
typedef long long ll;
ll inf = 1e15;

class network_flow{
private:
	int N;
	struct edge{int to; ll cap; int rev;};
	vector<vector<edge>> G;
	vector<int> level,iter;
	void bfs(int s){
		for(int i=0;i<=N;i++) level[i] = -1;
		queue<int> Q;
		level[s] = 0;
		Q.push(s);
		while(!Q.empty()){
			int v = Q.front(); Q.pop();
			for(int i=0;i<G[v].size();i++){
				edge &e = G[v][i];
				if(e.cap > 0 && level[e.to]<0){
					level[e.to] = level[v]+1;
					Q.push(e.to);
				}
			}
		}
	}
	ll dfs(int v,int t,ll f){
		if(v==t) return f;
		for(int &i=iter[v];i<G[v].size();i++){
			edge &e = G[v][i];
			if(level[v]<level[e.to] && e.cap>0){
				ll d = dfs(e.to,t,min(f,e.cap));
				if(d>0){
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}
public:
	network_flow(int n){
		N = n;
		G = vector<vector<edge>>(N+1);
		level = iter = vector<int>(N+1);
	}
	void add_edge(int from, int to,ll cap){
		G[from].push_back((edge){to,cap,(int) G[to].size()});
		G[to].push_back((edge){from,0,(int) G[from].size()-1});
	}
	ll max_flow(int s,int t){
		ll flow = 0;
		for(;;){
			bfs(s);
			if(level[t]<0) return flow;
			for(int i=0;i<=N;i++) iter[i] = 0;
			ll f;
			while((f=dfs(s,t,inf))>0) flow += f;
		}
	}
};

ll solve(int N,int M,int L,vector<vector<ll>>& G,vector<ll> &P,vector<ll> &T){
    network_flow flow(2*L+2);
    for(int i=0;i<L;i++){
        flow.add_edge(0,i+1,1);
        flow.add_edge(i+L+1,2*L+1,1);
        for(int j=0;j<L;j++){
            if(i==j) continue;
            if(T[i]+G[P[i]][P[j]]<=T[j]){
                flow.add_edge(i+1,j+L+1,1);
            }
        }
    }
    return L-flow.max_flow(0,2*L+1);
}

int main(){
    int N,M,L;
    while(cin >> N >> M >> L && N){
        vector<vector<ll>> G(N,vector<ll>(N,inf));
        for(int i=0;i<M;i++){
            int a,b,c;
            cin >> a >> b >> c;
            G[a][b] = c;
            G[b][a] = c;
        }
        for(int k=0;k<N;k++) for(int i=0;i<N;i++) for(int j=0;j<N;j++){
            G[i][j] = min(G[i][j],G[i][k]+G[k][j]);
        }
        for(int i=0;i<N;i++) G[i][i] = 0;
        vector<ll> P(L),T(L);
        for(int i=0;i<L;i++) cin >> P[i] >> T[i];
        cout << solve(N,M,L,G,P,T) << endl;
    }
}


Measured memory_bytes: 32072
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //エラーの出ないエラーを起こした時にデバッグできる
#define rep(i, n) for (int i = 0; i < (n); i++)

int main(){
  int n, q, a, b, c, countChange;
  cin >> n;
  int64_t sum;
  sum = 0;
  map<int, int> A;
  for  (int i = 0; i < n; i++){
    cin >> a;
    sum += a; 
    if(A.count(a))
      A[a] += 1;
    else
      A[a] = 1;
  }
  
  cin >> q;

  for  (int i = 0; i < q; i++){
    cin >> b >> c;
    if(A.count(b)){
      countChange = A[b]; 
      sum += countChange*(c-b);

      A[b] = 0;
      if(A.count(c))
        A[c] += countChange;
      else
        A[c] = countChange;
      
      
      cout << sum << endl;
      
    }
    else
      cout << sum << endl;
  }
  
}

Measured memory_bytes: 7452
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
    int N , K ;
    cin >> N >> K ;
    int a ,b;
    a = N % K ;
    
    if(a != 0){
        cout << 1 << endl;
    }else {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    X = list(map(int, input().split()))

    MOD = [defaultdict(int) for _ in range(m + 1)]
    cnt = defaultdict(int)
    for x in X:
        MOD[x % m][x] += 1
        cnt[x % m] += 1

    res = cnt[0] // 2
    if m % 2 == 0:
        res += cnt[m // 2] // 2

    for i in range(1, (m + 1) // 2):
        res += min(cnt[i], cnt[m - i])

        if cnt[i] > cnt[m - i]:
            diff = (cnt[i] - cnt[m - i]) // 2
            for v in MOD[i].values():
                if diff == 0:
                    break
                t = min(diff, v // 2)
                diff -= t
                res += t
        elif cnt[i] < cnt[m - i]:
            diff = (cnt[m - i] - cnt[i]) // 2
            for v in MOD[m - i].values():
                if diff == 0:
                    break
                t = min(diff, v // 2)
                diff -= t
                res += t

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 51260
#include <iostream>
#include <unordered_set>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	unordered_set<int> S;
	while (n--)
	{
		int x;
		cin >> x;
		auto it = S.find(x);
		if (it == S.end())
			S.insert(x);
		else
			S.erase(it);
	}
	cout << S.size() << endl;
	return 0;
}

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

using namespace std;

vector <long long int> ar;

long long int f(long long int a) {
	for (int i = 0; i < ar.size(); ++i) {
		a -= a % ar[i];
	}
	return a;
}

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	ar.resize(n);
	for (int i = 0; i < n; ++i) {
		cin >> ar[i];
	}
	long long int l1 = 2;
	long long int l2 = 1000000000000000;
	while (l1 < l2 - 1) {
		long long int mid = (l1 + l2) / 2;
		if (f(mid) >= 2) l2 = mid;
		else l1 = mid;
	}
	if (f(l1) == 2) l2 = l1;
	if (f(l2) != 2) {
		cout << -1 << endl;
		return 0;
	}
	long long int r1 = 2;
	long long int r2 = 1000000000000000;
	while (r1 < r2 - 1) {
		long long int mid = (r1 + r2) / 2;
		if (f(mid) > 2) r2 = mid;
		else r1 = mid;
	}
	if (f(r2) == 2) r1 = r2;
	cout << l2 << " " << r1 << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int q=S[5]-'0'; int w=S[6]-'0';
  if(q==0 && w<=4){cout << "Heisei" << endl;}
  else{cout << "TBD" << endl;}
}

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

typedef struct 
{
	int f[9];
	int space;
	int path;
}P;

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

int V[MAX];

P Q[MAX];
int head, tail;

int kara()
{
    if (head == kara)
	    return 1;
    else
        return 0;  
}

void push(P x)
{
	Q[tail] = x;
	tail = (tail+1)%MAX;
}

P front()
{
	P x;
	x = Q[head];
	head = (head+1)%MAX;
	return x;
}

int cheak(P p)
{
	int i, j, fac, count, res = 0;
	for(i = 0, fac = 1; i < 9; fac*= ++i)
    {
		for(j = 0, count = 0; j < i; j++)
        {
			if(p.f[j] < p.f[i]) 
              count++;
		}
		res = res + (count*fac);
	}
	return res;	
}

int target(P p)
{
	int i;
	for(i = 0; i < 9; i++ )
		if(p.f[i] != (i + 1) ) return 0;
	return 1;
}

int bfs(P s)
{
	int sx, sy, tx, ty, r, temp;
	P u, v;
	
	s.path = 0;
	
	push(s);
	
	V[cheak(s)] = 1;
	
	while(!kara())
    {
		u = front();
		if( target(u)) return u.path;
		sx = u.space / 3;
		sy = u.space % 3;
		
		for ( r = 0; r < 4; r++ ) 
        {
			tx = sx + dx[r];
			ty = sy + dy[r];
			if(tx < 0 || ty < 0 || tx >= 3 || ty >= 3) continue;
			v = u;
			
			temp = v.f[u.space];
			v.f[u.space] = v.f[tx * 3 + ty];
			v.f[tx * 3 + ty] = temp;
			
			v.space = tx * 3 + ty;
			
			if( !V[cheak(v)] )
            {
				V[cheak(v)] = 1;
				v.path++;
				push(v);
			}
		}
	}
	return -1;
}

int main()
{
	int i, a;
	P in;
	
	for( i = 0; i < 9; i++ ) 
    {
		scanf("%d", &in.f[i]);
		if( in.f[i] == 0) 
        {
			in.f[i] = 9;
			in.space = i;
		}
	}
	
	a = bfs(in);
	printf("%d\n",a);
	
	return 0;
}


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


int main(){
  int n,m;
  cin>>n>>m;
  vector<int> a(n);
  string ans="Yes";
  int s=0;
  rep(i,n){
    cin>>a[i];
    s+=a[i];

  }
  sort(a.rbegin(),a.rend());
  rep(i,m){
if (a[i]*4*m<s)ans="No";
}
  cout<<ans;


  }


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

int main(void)
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        double x1, y1, x2, y2, x3, y3, x4, y4;
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
        if (((x2-x1)==0) && ((x4-x3)==0))
            cout << "YES" << endl;
        else {
            double d = abs((y2-y1)*(x4-x3) - (y4-y3)*(x2-x1));
            cout << ((d <= 1e-10)? "YES" : "NO") << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int N;
    string S;
    cin >> N >> S;
    int x = 0;
    int ans = 0;
    for(int i = 0; i < N;i++){
        if(S[i]=='I')x++;
        else if(S[i]=='D')x--;
        ans = max(ans,x);
    }
    
    cout << ans <<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int s=scan.nextInt();
int m=0;
int h=0;
if(s>=60){
	m=s/60;
	s=s-60*m;
}
else{
	m=0;
}
if(m>=60){
	h=m/60;
	m=m-60*h;
}
else{
	h=0;
}
System.out.println(h+":"+m+":"+s);
}

}

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    vector<int> a(100005);
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int v;
        cin >> v;
        v++;
        for (int j = -1; j < 2; j++) {
            a[v + j]++;
            ans = max(ans, a[v + j]);
        }
    }
    cout << ans << '\n';
}


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

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

  int now = 0, next, count = -1, max = -1;
  for(int i = 0; i < n; i++){
    cin >> next;
    if(now >= next){
      count++;
    } else{
      max = count > max ? count : max;
      count = 0;
    }
    now = next;
  }
  max = count > max ? count : max;
  cout << max << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>

#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;


ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}

ll gcd(ll a, ll b) {
  if (a == 0 || b == 0) return a + b;
  if (b > a) return gcd(b, a);
  return gcd(b, a % b);
}

int main(void) {

  int a, b, c, d;
  cin >> a >> b >> c >> d;

  while (1) {
    c -= b;
    if (c <= 0) {
      cout << "Yes\n";
      return 0;
    }
    a -= d;
    if (a <= 0) {
      cout << "No\n";
      return 0;
    }
  }
}


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

using namespace std;

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

  string s;
  cin >> s;
  for (size_t i = 0; i < s.size(); ++i) {
    if (s[i] == ',') {
      s[i] = ' ';
    }
  }
  cout << s << "\n";
}


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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    int c = w - a, d = h - b;
    for(int y = 0; y < b; y++){
        for(int x = 0; x < a; x++){
            cout << '0';
        }
        for(int x = 0; x < c; x++){
            cout << '1';
        }
        cout << endl;
    }
    for(int y = 0; y < d; y++){
        for(int x = 0; x < a; x++){
            cout << '1';
        }
        for(int x = 0; x < c; x++){
            cout << '0';
        }
        cout << endl;
    }
    return 0;
}


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

int main() {
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;

    if (x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}



Measured memory_bytes: 3124
#include<stdio.h>
int main()
{
    int k,a,b,flag;
    long long i;


    scanf("%d %d %d",&k,&a,&b);
    flag=0;
    for(i=k; i<=b; i=i+k)
    {
        if(i>=a&&i<=b)
        {
        flag=1;
        break;
        }
    }
    if(flag==1)
        printf("OK\n");
    else
        printf("NG\n");
    return 0;
}


Measured memory_bytes: 1660
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

int main()
{
    int x[10],ans;
    for(int i=1;i<=5;i++){
        cin>> x[i];
        if(x[i]==0) ans=i;
    }
    cout<< ans <<endl;
    return 0;
}

Measured memory_bytes: 3588
#include<iostream>
using namespace std;
int n, a, sum;
int main() {
	while (true) {
		cin >> n; sum = 0; if (!n) { break; }
		for (int i = 0; i < (n - 1)*n / 2; i++) {
			cin >> a;
			sum += a;
		}
		cout << sum / (n - 1) << endl;
	}
}

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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	for(int i = 0;i < (int)v.size(); i++){
		if(i)os<<", ";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int main(){
    int h1, m1, h2, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k;
    int a = h1 * 60 + m1, b = h2 * 60 + m2;
    cout << max(0, b - a - k) << endl;
}

Measured memory_bytes: 3596
#include<stdio.h>

int main(){

  int i,m,j,minj;
  int ba[100];
  int flag;
  int cnt = 0;
  int c = 0;
  int k;
  int ak = 0;
  

  scanf("%d",&i);

  for(m = 0; m < i; m++){
    scanf("%d",&ba[m]);
  }


  for(k = 0; k < i; k++){
    minj = k;
    for(j = k; j < i; j++){
      if(ba[j] < ba[minj]){
	minj = j;
      }
    }
      if(ba[k] != ba[minj]){
	ak = ba[k];
	ba[k] = ba[minj];
	ba[minj] = ak;
	cnt++;
      }
    
  }
  

 
   for(c = 0; c < i; c++){
     printf("%d",ba[c]);
     if(c != i-1){
       printf(" ");
   }
  }
   printf("\n%d\n",cnt);

   return 0;
}



Measured memory_bytes: 2048
#include <stdio.h>
#define MAX 2000000

int h,a[MAX+1];

void maxHeapify(int i){
  int l,r,largest;
  int oki;
 
  l = 2 * i ;
  r = 2 * i + 1;

  if(l<=h && a[l] >a[i])largest=l;
  else largest = i;
  if(r <=h && a[r] > a[largest]) largest = r;

  if(largest != i){
    oki = a[i];
    a[i] = a[largest];
    a[largest] = oki;
    maxHeapify(largest);
  }
}
int main(){
  int i;
  scanf("%d",&h);

  for(i=1;i<=h;i++) scanf("%d",&a[i]);

  for(i=h/2;i>=1;i--) maxHeapify(i);

  for(i=1;i<=h;i++){
    printf(" %d",a[i]);
  }
  printf("\n");

  return 0;
}

  



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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;

int n;

ll gcd(ll x, ll y){
  if(y==0)return x;
  else return gcd(y, x%y);
}

int main(){
  cin >> n;
  vector<ll> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  vector<ll> l(n+2, 0),r(n+2, 0);
  for(int i = 0; i<n; i++){
    l[i+1] = gcd(l[i], a[i]);
    r[n-i] = gcd(r[n-(i-1)], a[n-i-1]);
  }
  ll ans = 0;
  for(int i=1; i < n+1; i++){
    ans = max(ans, gcd(l[i-1], r[i+1])); //なぜこのlの添え字がi-1なのか？
    // L: 0 12 3 3
    //     \  \ \     このペアで比較している．
    // R: 3 3 18 0
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
use std::iter::FromIterator;
use std::collections::HashMap;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let k:usize = read();
    let mut map = HashMap::new();
    for _ in 0..n {
        let x:usize = read();
        *map.entry(x).or_insert(0) += 1;
    }
    let mut v = Vec::from_iter(map);
    v.sort_by(|&(_, a), &(_, b)| b.cmp(&a));

    let mut len = v.len();
    let mut ans = 0;

    while len > k {
        ans += v.pop().unwrap().1;
        len -= 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 9340
#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  char a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << ((a == b || b == c || c == d) ? "Bad" : "Good") << endl;
  return 0;
}

Measured memory_bytes: 256
import numpy as np
x1, y1, x2, y2 = map(int, input().split())
c1 = np.array([x1, y1])
c2 = np.array([x2, y2])
vec1 = c2 - c1
rot = np.array([[0, 1], [-1, 0]])
vec1 = np.dot(vec1, rot)
c3 = c2 + vec1
vec1 = np.dot(vec1, rot)
c4 = c3 + vec1
ans = c3.tolist() + c4.tolist()
ans = list(map(str, ans))
print(" ".join(ans))

Measured memory_bytes: 13680
#include <stdio.h>

int main() {
    int aiData[200001]; // Input配列
    int iNumOfQuery;    // 命令数
    int iQuery;         // 命令番号
    int iArg;           // 命令に応じた引数
    int iCount;         // counter
    int* piDataTail = aiData;   // 配列の末尾を指すポインタ

    // In: 命令数
    scanf("%d", &iNumOfQuery);
    for (iCount = 0; iCount < iNumOfQuery; iCount++) {
        // In: 命令番号
        scanf("%d", &iQuery);
        if (iQuery == 0) {  // Query: pushBack
            // In: 追加する数値
            scanf("%d", &iArg);
            *piDataTail = iArg; // 末尾に追加
            piDataTail++;       // 末尾を次に移動
        }
        else if (iQuery == 1) { // Query: randomAccess
            // In: 出力する配列の番号
            scanf("%d", &iArg);
            printf("%d\n", aiData[iArg]);
        }
        else if (iQuery == 2) { // Query: popBack
            *piDataTail = 0;    // 末尾を初期化 
            piDataTail--;       // 末尾を手前に移動 
        }
        else {
            // 何もしない
        }
    }
    
    return 0;
}


Measured memory_bytes: 2468
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		new Main().solver();
	}

	@SuppressWarnings("unchecked")
	void solver() {
		Scanner sc = new Scanner(System.in);
		int V = sc.nextInt();
		int E = sc.nextInt();
		ArrayList<Integer>[] g = new ArrayList[V];
		for (int i = 0; i < g.length; i++)
			g[i] = new ArrayList<>();
		for (int i = 0; i < E; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			g[a].add(b);
			g[b].add(a);
		}
		Integer[] color = new Integer[V];
		Arrays.fill(color, -1);
		int base = 0;
		Map<Integer, Integer> map = new HashMap<>();
		for (int i = 0; i < V; i++) {
			if (color[i] == -1) {
				color[i] = 0;
				counter[0] = 1;
				counter[1] = 0;
				if (!dfs(g, color, i)) {
					System.out.println(-1);
					return;
				} else {
					base += Math.min(counter[0], counter[1]);
					if (counter[0] != counter[1]) {
						int value = Math.abs(counter[0] - counter[1]);
						map.put(Math.abs(value), map.containsKey(value) ? map.get(value) + 1 : 1);
					}
				}
			}
		}
		boolean[] dp = new boolean[V / 2 - base + 1];
		dp[0] = true;
		Iterator<Entry<Integer, Integer>> it = map.entrySet().iterator();
		int x = 0;
		while (it.hasNext()) {
			Entry<Integer, Integer> entry = it.next();
			int value = entry.getKey();
			int c = entry.getValue();
			for (int i = dp.length - 1; i >= 0; i--) {
				if (dp[i]) {
					for (int j = 1; j <= c; j++) {
						if (i + j * value < dp.length) {
							dp[i + j * value] = true;
							x = Math.max(x, i + j * value);
						} else {
							break;
						}
					}
				}
			}
		}
		System.out.println((long) (base + x) * (long) (V - x - base) - E);
	}

	int[] counter = new int[2];

	boolean dfs(ArrayList<Integer>[] g, Integer[] color, int cur) {
		for (int v : g[cur]) {
			if (color[v] == -1) {
				color[v] = 1 ^ color[cur];
				counter[color[v]]++;
				if (!dfs(g, color, v)) {
					return false;
				}
			} else {
				if (color[cur] != (1 ^ color[v]))
					return false;
			}
		}
		return true;
	}
}

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

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcount(n)

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        int K, P;
        cin >> K >> P;
        cout << (K - 1) % P + 1 << endl;
    }
}




Measured memory_bytes: 3108
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

class State{
public:
  int y, x, c;
};

int w, h, dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1};
bool tate[30][30], yoko[30][30];

bool check(int y, int x){
  if(y<0 || y>=h) return false;
  if(x<0 || x>=w) return false;
  return true;
}

bool check2(int y, int x, int d){
  if(d == 0) return !yoko[y-1][x];
  if(d == 1) return !tate[y][x];
  if(d == 2) return !yoko[y][x];
  if(d == 3) return !tate[y][x-1];
}

int bfs(){
  bool vis[30][30];
  fill(vis[0], vis[30], false);
  State u, v;
  u.y = u.x = 0;
  u.c = 1;
  vis[u.y][u.x] = true;
  queue<State> q;
  q.push(u);
  while(!q.empty()){
    u = q.front();
    q.pop();
    if(u.y == h-1 && u.x == w-1) return u.c;
    for(int i=0;i<4;i++){
      int ny = u.y + dy[i];
      int nx = u.x + dx[i];
      if(!check(ny, nx)) continue;
      if(!check2(u.y, u.x, i)) continue;
      if(vis[ny][nx]) continue;
      vis[ny][nx] = true;
      v.y = ny;
      v.x = nx;
      v.c = u.c + 1;
      q.push(v);
    }
  }
  return 0;
}

main(){
  while(cin >> w >> h && (w|h)){
    for(int i=0;i<h-1;i++){
      for(int j=0;j<w-1;j++) cin >> tate[i][j];
      for(int j=0;j<w;j++) cin >> yoko[i][j];
    }
    for(int j=0;j<w-1;j++) cin >> tate[h-1][j];
    cout << bfs() << endl;
  }
}

Measured memory_bytes: 912
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    vector<bitset<32>> a(n);
    for (int i = 0; i < n; i++) {
        int b;
        cin >> b;
        a[i] = b;
    }
    bitset<32> det(0);
    for (int i = 0; i < n; i++) {
        det ^= a[i];
    }
    for (int i = 0; i < 32; i++) {
        if (det.test(i)) {
            for (int j = 0; j < n; j++) {
                a[j].flip(i);
            }
        }
    }
    for (int i = 0; i < n; i++) {
        cout << a[i].to_ulong();
        if (i != n - 1)
            cout << " ";
        else
            cout << endl;
    }
    return 0;
}


Measured memory_bytes: 4732
a, b, c, d = map(int, input().split())
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)

def divided_num(a,b,c):
    return b//c - a//c +1 if a%c==0 else b//c - a//c

print((b - a + 1) - divided_num(a,b,c) - divided_num(a,b,d) + divided_num(a,b,lcm(c, d)))

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    string S; cin>>S;

    uint64_t ans=0,wCnt=0;;
    for(auto s:S){
        if(s=='B') wCnt++;
        else ans+=wCnt;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define all(a) (a).begin(), (a).end()
#define msg(a) cout << #a << " " << a << endl
#define rep(i, n) for(int i = 0; i < n; ++i)

int main() {
    int h = 2, w;
    cin >> w;
    vector<vector<int> > v(h, vector<int>(w));

    rep(i, h) {
        rep(j, w) {
            cin >> v[i][j];
        }
    }

    int ans = 0, sum = 0;
    rep(i, w) {
        ans += v[0][i];
        sum += v[1][i];
    }
    ans += v[1][w-1];

    int sub = v[0][0];
    rep(i, w-1) {
        ans = max(ans, sub+sum);
        sub += v[0][i+1];
        sum -= v[1][i];
    }
    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
let lcs x y =
  let m = String.length x in
  let n = String.length y in
  let dp = Array.make_matrix (m+1) (n+1) 0 in
  for i = 1 to m do
    for j = 1 to n do
      dp.(i).(j) <-
        if x.[i-1] = y.[j-1] then dp.(i-1).(j-1) + 1
        else if dp.(i-1).(j) > dp.(i).(j-1) then dp.(i-1).(j)
        else dp.(i).(j-1)
    done
  done;
  dp.(m).(n)

let () =
  let q = read_int () in
  let rec doit i =
    if i < q then begin
      let x = read_line () in
      let y = read_line () in
      Printf.printf "%d\n" (lcs x y);
      doit (i + 1)
    end in
  doit 0

Measured memory_bytes: 18596
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
bool d[33554432];
map<char, int> k;

int c(char str[12]){
	int ans = str[0];
	for(int i = 1;i < strlen(str);i++){
		ans <<= 2;
		ans += k[str[i]];
	}
	return ans;
}

int main(){
	k['A'] = 0;k['C'] = 1;k['G'] = 2;k['T'] = 3;
	int n;scanf("%d", &n);
	char s[7], str[12];
	for(int i = 0;i < n;i++){
		scanf("%s %s", s, str);
		if(s[0] == 'i')d[c(str)] = true;
		else puts(d[c(str)] ? "yes" : "no");
	}
	return 0;
}

Measured memory_bytes: 4108
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    const int M = 2019;
    string S; cin >> S;
    vector<int> dp(M);

    ll ans = 0;
    REP(i,S.size()) {
        vector<int> tmp(M);
        swap(tmp,dp);
        int c = S[i] - '0';
        REP(j,M) {
            int k = (j*10+c) % M;
            dp[k] = dp[k] + tmp[j];
        }
        dp[c] += 1; 
        ans += dp[0];
        // cerr << ans << " ";
        // cerr << accumulate(ALL(dp[i+1]), 0);
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 3716
n = int(input())
#a, b, x = list(map(int, input().split()))
b = list(map(int, input().split()))
a = []
a.append(b[0])
for i in range(n-2):
    a.append(min(b[i], b[i+1]))
a.append(b[-1])

# print(a)
print(sum(a))


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int H,W;
		String work[] = new String[2];

		while(true){

			try {
				work = br.readLine().split("[\\s]+");

				if(work[0].equals("0") && work[1].equals("0"))break;

				H = Integer.parseInt(work[0]);
				W = Integer.parseInt(work[1]);

				for(int col = 0; col < W; col++){
					System.out.printf("#");
				}
				System.out.printf("\n");

				for(int row = 1; row <= H-2; row++){
					System.out.printf("#");
					for(int col = 1; col <= W-2; col++){
						System.out.printf(".");
					}
					System.out.printf("#\n");
				}

				for(int col = 0; col < W; col++){
					System.out.printf("#");
				}
				System.out.printf("\n\n");


			} catch (IOException e) {

				e.printStackTrace();
			}
		}
	}
}




Measured memory_bytes: 60168
#include"bits/stdc++.h"
//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
const int mod = 100000003;


int main() {
	int n, m;
	int a, b;
	int ans[52] = {};
	cin >> n >> m;
	rep(i, 0, m) {
		cin >> a >> b;
		ans[a]++;
		ans[b]++;
	}
	rep(i, 1, n+1) { print(ans[i]); }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000000
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void){
	int n; cin >> n;
	vector<int> num;
	for(int i = 0; i < n; i++){
		int a; cin >> a;
		num.push_back(a);
	}
	sort(begin(num), end(num));

		int N = num[0];
	vector<int> divi;
	for(int i = 1; i <= sqrt(N); i++){
		if(N%i == 0){
			divi.push_back(i);
			divi.push_back(N/i);
		}
	}

	//debug(0);
	sort(begin(divi), end(divi));
	//debug(1.5);

	divi.erase(unique(begin(divi), end(divi)), end(divi));

	//debug(1);

	vector<int> res;
	for(auto x: divi){
		//debug(x);
		bool check = true;
		for(int i = 1; i <= n-1; i++){
			if(num[i]%x != 0) check = false;
		}

		if(check) res.push_back(x);
	}

	for(auto x: res) cout << x << '\n';

	return 0;
}



Measured memory_bytes: 3156
l, r = map(int, input().split())
if r-l+(l%2019)<2019:
  tmp = 2019
  for i in range(l%2019, r%2019):
    for j in range(i+1, (r%2019)+1):
      tmp = min((i*j)%2019, tmp)
  print(tmp)
else:
  print(0)

Measured memory_bytes: 3060
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        
        int n;
        int[]R;
        
        Scanner scan = new Scanner(System.in);       
        n = scan.nextInt();
        R = new int[n];
        
        for(int i=0 ; i < n;i++) {
            R[i] = scan.nextInt();
        }
        
        
         int answer = R[1] - R [0] ; 
         int min = R[0];
        
        for (int i = 1 ; i < n; i++){
                    if (R[i] - min > answer){ 
                    answer = R[i] - min;
                   }
                   if(min> R[i]){
                    min = R [i];
                   }
                

            } 

       
        System.out.println(answer);
    }
  }

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

typedef long long ll;
const int maxn = 2e5+10;
const int mod = 1e9+7;

ll a[maxn];
ll sum[maxn];
int main(void){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		sum[i] = sum[i-1]+a[i];
		sum[i] %= mod;	
	}
	ll ans = 0;
	for(int i = 2; i <= n; i++){
		ans += a[i]*sum[i-1];
		ans %= mod; 
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 6760
MAX = 10000
primes=[]
isPrime = Array.new(MAX+1,true)
isPrime[0,2]=false,false
(2..MAX).each do |i|
  if isPrime[i]
    primes << i 
    (i*2).step(MAX,i) do |j|
      isPrime[j]=false
    end
  end
end
loop do
  n = gets.to_i
  break if n==0
  c=0
  (0...primes.size).each do |i|
    break if primes[i] > n
    sum=0
    (i...primes.size).each do |j|
      break if sum > n
      sum+=primes[j]
      if sum==n
        c+=1
        break
      end
    end
  end
  puts c
end

Measured memory_bytes: 2800
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
#define pcnt(b) __builtin_popcount(b)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int,int>>
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,sum[2]={0,0},ans[2]={0,0};
    cin>>n;
    vi a(n);
    rep(i,0,n){
        cin>>a[i];
    }
    rep(j,0,2){
        int c = 0;
        rep(i,0,n){
            sum[j]+=a[i];
            if(j%2){
                if(i%2){
                    if(sum[j]<=0){
                        c +=abs(sum[j])+1;
                        sum[j]=1;
                    }
                }
                else{
                    if(sum[j]>=0){
                        c += abs(sum[j])+1;
                        sum[j]=-1;
                    }
                }
            }
            else{
                if(i%2==0){
                    if(sum[j]<=0){
                        c +=abs(sum[j])+1;
                        sum[j]=1;
                    }
                }
                else{
                    if(sum[j]>=0){
                        c += abs(sum[j])+1;
                        sum[j]=-1;
                    }
                }
            }
        }
        ans[j]=c;
    }
    std::cout<<min(ans[0],ans[1])<<endl;
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;


namespace Test1 {

    class ClassMain {

        public static int[] fibo = new int[1001];
        public static int mod = 1001;

        static void initFibo() {
            fibo[0] = 1; fibo[1] = 2;
            for (int i = 2; i <= 1000; i++) {
                fibo[i] = (fibo[i - 1] + fibo[i - 2]) % mod;
            }
        }


        public static void Main(String[] args) {
            initFibo();
            string line;
            while ((line = Console.ReadLine()) != null) {
                int[] ints = line.Split(' ').Select(int.Parse).ToArray();
                //int n = int.Parse(line);
                //if(n==0){break;}
                int v = ints[0];
                int d = ints[1];

                List<int> nodes = new List<int>();
                for (int i = 1; i <= v; i++) {
                    nodes.Add(fibo[i]);
                }
                nodes.Sort();

                int prev = nodes.ElementAt(0);
                int groupN = 1;
                for (int i = 1; i < v; i++) {
                    if (nodes.ElementAt(i) - prev < d) {
                        //nothing.
                    }
                    else {
                        groupN++;
                    }
                    prev = nodes.ElementAt(i);
                }


                Console.WriteLine(groupN);
            }   
        }   
    }
}

Measured memory_bytes: 6192
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] arg)throws IOException{
		 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		 //br.readline(); = 入力された１行分を日本語変換して返してくれる。
		 String str = br.readLine();

		 /*配列の型(intとかStringとか) [] 配列名 = 配列を用意
		  *今回はstrAryって配列にstrを入れてる。
		  *str.split = splitってのはString内に用意されてるメソッド
		  *文字列を分割するときに使用。今回は空白で区切ってって仕様なので
		  *split(" ")としてます。*/
		 String[] strAry = str.split(" ");

		 /*おなじみの文字列から数値への変換。
		  *ただし今回は指定先が配列の何番って風になってる。*/
		 int W = Integer.parseInt(strAry[0]);
		 int H = Integer.parseInt(strAry[1]);
		 int x = Integer.parseInt(strAry[2]);
		 int y = Integer.parseInt(strAry[3]);
		 int r = Integer.parseInt(strAry[4]);

		 /*複数条件の記述。if(条件 && 条件)は「かつ」だったが、
		  * if(条件 || 条件)で「または」の条件指定ができるらしい。
		  * 今回は半径(r)が円の中心座標(x,yそれぞれ)を上回ってしまうと枠を
		  * はみ出してしまうので条件で指定
		  * また、半径(r)と円の中心座標(x,yそれぞれ)の合計が外枠の座標(W,Hそれぞれ)を
		  * 上回ると枠をはみ出してしまうので条件指定
		  * それらを満たさない場合枠内に円が入りきる。
		  */

		 //Constraintを記述
		 if(!(-100 <=x && x<=100 &&
			-100 <=y && y<=100 &&
			0<W && W <=100 &&
			0<H && H <=100 &&
			0<r && r <=100)){
			 System.out.println("エラー");
		 } else {

		 if(x-r<0 || y-r<0 || x+r>W || y+r>H){
	            System.out.println("No");
	        }
	        else{
	            System.out.println("Yes");
	        }
		 }
	}
}

Measured memory_bytes: 17084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/


int ret_sum(int x){
  auto y = to_string(x);
  int ret = 0;
  rep(i,sz(y)){
    ret += (y[i] - '0');
  }
  return ret;
}

int main(){
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
  
  	int N;cin >> N;
  
    int ans = INF;
  
    REP(a,N-1){
      int b = N - a;
      int tmp = ret_sum(a) + ret_sum(b);
      chmin(ans,tmp);
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, begin, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    vector<int> A(5);
    int ans = 0;
    int min = 9;
    int a = 1;
    rep(i, 0, 5)
    {
        cin >> A.at(i);
        if (A.at(i) % 10 != 0)
        {
            a = 0;
            if (min > A.at(i) % 10)
            {
                min = A.at(i) % 10;
            }
            A.at(i) = A.at(i) / 10 + 1;
        }
        else
        {
            A.at(i) /= 10;
        }
        ans += A.at(i) * 10;
    }
    if (a)
    {
        cout << ans << endl;
    }
    else
    {
        cout << ans + min - 10 << endl;
    }
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc126d()
}

fun abc126d() {
    val n = readLine()!!.toInt()
    val edges = (1 until n)
        .map { readLine()!!.split(' ').map { it.toInt() }.let { Edge(it[0] - 1, it[1] - 1, it[2]) } }

    val graph = Array(n) { Vertex(it, mutableListOf(), null) }
    edges.forEach {
        val (from, to, cost) = it
        graph[from].neighbor.add(to to cost)
        graph[to].neighbor.add(from to cost)
    }

    fun dfs(index: Int, isRed: Boolean) {
        val vertex = graph[index]
        vertex.isRed = isRed

        vertex.neighbor.forEach {
            val (to, cost) = it
            if (graph[to].isRed == null) dfs(to, if (cost % 2 == 0) isRed else !isRed)
        }
    }

    dfs(0, true)

    val answer = graph.joinToString(System.lineSeparator()) { if (it.isRed!!) "0" else "1" }

    println(answer)
}

private data class Edge(val from: Int, val to: Int, val cost: Int)
private data class Vertex(val index: Int, val neighbor: MutableList<Pair<Int, Int>>, var isRed: Boolean? = null)


Measured memory_bytes: 87884