akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (long i = (s); i < (long)(n); i++)

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

    vector<vector<char>>a(n,vector<char>(n));
    rep(i,0,n){
        rep(j,0,n){
            cin>>a[i][j];
        }
    }

    vector<vector<char>>b(m,vector<char>(m));
    rep(i,0,m){
        rep(j,0,m){
            cin>>b[i][j];
        }
    }

    bool answer=false;
    rep(i,0,n-m+1){
        rep(j,0,n-m+1){
            bool jdg=true;
            rep(k,0,m){
                rep(l,0,m){
                    if(a[i+k][j+l]!=b[k][l]){
                        jdg=false;
                    }
                }
            }
            if(jdg){
                answer=true;
            }
        }
    }
    if(answer){
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String r = sc.next();
		String g = sc.next();
		String b = sc.next();
		int ans = Integer.parseInt(r + g + b);
		if(ans % 4 == 0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


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

int cnt;

void print(vector<int>& A) {
  int N = A.size();
  cout << A[0];
  for (int i = 1; i < N; i++) {
    cout << ' ' << A[i];
  }
  cout << endl;
}

void insertionSort(vector<int>& A, int N, int g) {
  for (int i = g; i < N; i++) {
    int v = A[i];
    int j = i - g;
    while (0 <= j and v < A[j]) {
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
  }
}

void shellSort(vector<int>& A, int N) {
  vector<int> G = {1};
  for (int i = 1; (3 * G[i-1] + 1) < N; i++) {
    G.push_back(3 * G[i-1] + 1);
  }
  reverse(G.begin(), G.end());
  int m = G.size();
  for (int i = 0; i < m; i++) {
    insertionSort(A, N, G[i]);
  }
  cout << m << endl;
  print(G);
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  shellSort(A, N);
  cout << cnt << endl;
  for (int a: A) cout << a << endl;
}


Measured memory_bytes: 6712
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main() {
	int S, h, m, s;
	scanf("%d", &S);

	h = S / 3600;
	m = (S-h*3600)/60;
	s = (S-h*3600)%60;
	printf("%d:%d:%d\n", h, m, s);
	return 0;

}

Measured memory_bytes: 2752
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1001001001;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    string S,T; cin >> S >> T;
    char s,t;
    sort(S.begin(),S.end());
    sort(T.begin(),T.end(),greater<int>());
    if (S<T) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;

long long int n;
long long int anum = 0;
int main(){
    cin >> n;

    vector<long long int> a(n);
    vector<long long int> num(n, 0);

    for(int i=0;i<n;i++){
        cin >> a[i];
        ++num[a[i]-1];
    }

    for(int i=0;i<n;i++){
        anum += (num[i]*(num[i]-1))/2;
    }

    for(int i=0;i<n;i++){
        long long int res = anum - num[a[i]-1] +1;
        cout << res << endl;
    }
}   

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(),v.end()
ll INF = 10010001010;

ll lcm(ll a,ll b)
{
    return a * b / __gcd(a, b);
}

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

int main(){
    string A;
    cin >> A;
    int N = A.size();
    int n, S, W, E;
    n = S = W = E = 0;
    for (int i = 0; i < N; i++)
    {
        if(A[i] == 'N'){
            n++;
        }
        else if(A[i] == 'S'){
            S++;
        }
        else if(A[i] == 'W'){
            W++;
        }
        else
        {
            E++;
        }
    }
    if(n != 0){
        if(S == 0){
            cout << "No" << endl;
            return 0;
        }
    }
    if(S != 0){
        if(n == 0){
            cout << "No" << endl;
            return 0;
        }
    }
    if (W != 0)
    {
        if (E == 0)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    if (E != 0)
    {
        if (W == 0)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main(){

	for(;;){
		int n,m;
		cin>>n>>m;
		if(n==0 && m==0) { cin.eof();return 0;}
		int a[100],b[100];
		int sum_a=0,sum_b=0;
		for(int i=0;i<n;i++){
			cin >> a[i];
			sum_a+=a[i];
		}

		for(int j=0;j<m;j++){
			cin >> b[j];
			sum_b+=b[j];
		}

		if((sum_a + sum_b) % 2  ==1){
			 cout << -1 <<endl;				
		}else {
		sort(a,a+n);
		sort(b,b+m);
		bool bl = false;	
		if(sum_a < sum_b){
			int diff1=(sum_b-sum_a)/2;
			for(int i=0;i<n;i++) {	
				for(int j=0;j<m;j++){
					if(a[i]+diff1== b[j] ){
						cout << a[i] <<" "<< b[j]<<endl;
						bl = true;
						break;
					}
				}
				if(bl==true) break;
			}	
		}else if(sum_a > sum_b)	{
			int diff2=(sum_a-sum_b)/2;
			for(int j=0;j<m;j++) {	
				for(int i=0;i<n;i++){
					if(b[j]+diff2 == a[i] ){
						cout << a[i] <<" "<< b[j]<<endl;
						bl = true;
						break;
					}
				}
				if(bl==true) break;
			}	
		}else {
			for(int i=0;i<n;i++) {	
				for(int j=0;j<m;j++){
					if(a[i]==b[j]){
						cout << a[i] <<" "<< b[j]<<endl;
						bl = true;
						break;
					}
				}
				if(bl==true) break;
			}	
		}	

		if(bl==false) cout << -1 <<endl;	
		}
	}

}

Measured memory_bytes: 1180
using System;

class Program
{
    static void Main(string[] args)
    {
        string[] num = Console.ReadLine().Split(' ');

        int a, b, c, d;
        a = int.Parse(num[0]);
        b = int.Parse(num[1]);
        c = int.Parse(num[2]);

        if (a > b)
        {
            d = a;
            a = b;
            b = d;
        }

        if (b > c)
        {
            d = b;
            b = c;
            c = d;
        }

        if (a > b)
        {
            d = a;
            a = b;
            b = d;
        }
        Console.WriteLine(a + " " + b + " " + c);  
    }
}


Measured memory_bytes: 9216
#include <iostream>
#include <sstream>
#include <fstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include<iomanip>
#define sqr(x) (x)*(x)
#define ll long long
using namespace std;
ll num[300005],l[300005],r[300005],ans=-1152921504606846976,n,i,j;
priority_queue<int,vector<int>,greater<int>/**/> le;
priority_queue<ll> ri;
int main()
{
	cin>>n;
	for (i=1;i<=n*3;i++)
	{
		cin>>num[i];
		if (i<=n) 
		{
			le.push(num[i]);
			l[n]+=num[i];
		}
		if (i>n*2) 
		{
			ri.push(num[i]);
			r[n+n+1]+=num[i];
		}
	}
	for (i=n+1;i<=n+n;i++)
	{
		l[i]=l[i-1];
		if (le.top()<num[i])
		{
			l[i]=l[i]-le.top()+num[i];
			le.pop();
			le.push(num[i]);
		}
	}
	for (i=n+n;i>n;i--)
	{
		r[i]=r[i+1];
		if (ri.top()>num[i])
		{
			r[i]=r[i]-ri.top()+num[i];
			ri.pop();
			ri.push(num[i]);
		}
	}
	for (i=n;i<=n+n;i++)
	{
		ans=max(ans,l[i]-r[i+1]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 7284
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  double ans = 0;
  for (int i = 0; i < n; i++) {
    double a;
    cin >> a;
    ans += 1 / a;
  }
  cout << fixed << setprecision(10) << 1 / ans << endl;
  return 0;
}

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

int k,s;
int jsq=0;
int x,y,z;

int main()
{
	cin>>k>>s;
	for(x=0;x<=k;x++)
	{
		for(y=0;y<=k;y++)
		{
			if(s-x-y>=0&&s-x-y<=k)
			{
				jsq++;
			}
		}
	}
	cout<<jsq<<endl;
	return 0;
}

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





class Solution {
  int n, m;
  long long f(long long A, long long B) {
    if (A == B) return A;
    if (A % 4) return A ^ f(A + 1, B);
    if (B % 4 != 3) return B ^ f(A, B - 1);
    return 0;
  }
public:
  void run() {
    long long A, B;
    cin >> A >> B;
    cout << f(A, B) << '\n';
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  Solution().run();
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  while(1){
    int ans=0,n,m,p[1001]={};
    cin>>n>>m;
    if(n==0 && m==0)break;
    for(int i=0;i<n;i++)
      cin>>p[i];
    
    for(int j=0;j<n;j++) 
      for(int i=0;i<n;i++)
	if(p[i]<p[i+1])swap(p[i],p[i+1]);

    for(int i=0;i<n;i++){
      if((i+1)%m==0)p[i]=0;
      ans+=p[i];
    }

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

Measured memory_bytes: 1160
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <map>
using namespace std;
int main()
{
  int n, k;
  string s;
  cin >> n >> k >> s;
  s[k-1] -= 'A' - 'a';
  cout << s;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}

int main()
{
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max({a*c,a*d,b*c,b*d}) << endl;
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main(void){
    int a=0;
    int b=0;
    int num1=0;
    int num2=0;
    int num3=0;
    int max=0;

    cin >> a >> b;

    num1=a+b;
    num2=a-b;
    num3=a*b;

    max=num1;
    if(max<=num2)max=num2;
    if(max<=num3)max=num3;

    cout << max << endl;
    
    return 0;
}


Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        EThisMessageWillSelfDestructIn5s solver = new EThisMessageWillSelfDestructIn5s();
        solver.solve(1, in, out);
        out.close();
    }

    static class EThisMessageWillSelfDestructIn5s {
        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            int n = sc.nextInt();
            long ans = 0;
            HashMap<Integer, Integer> map = new HashMap<>();
            for (int i = 0; i < n; i++) {
                int x = sc.nextInt();
                ans += map.getOrDefault(i - x, 0);
                map.put(x + i, map.getOrDefault(x + i, 0) + 1);
            }
            pw.println(ans);
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 57812
//
//  main.cpp
//  atcoder
//
//  Created by Hisaki Kobayashi on 2020/04/14.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
typedef long long ll;
using namespace std;


int main(int argc, const char * argv[]) {
    
//    // input from txt （提出時にこの箇所は削除すること）
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());
//
    ll N , K;
    cin >> N >> K;
    vector<double> s(N+1); s[0] = 0;
    vector<double> p(N+1); p[0] = 0;
    for(ll i=0;i<N;i++){
        cin >> p[i+1];
        s[i+1] = s[i] + p[i+1];
    }
    
    ll max_expect = 0;
    ll i_save=0;;
    for(ll i=1;i<=N-K+1;i++){
        if(max_expect < s[i+K-1] - s[i-1]){
            max_expect = s[i+K-1] - s[i-1];
            i_save = i;
        }
    }
    double sum=0.0;
    for(ll i=0;i<K;i++){
//        cout << "p[i_save] : " << p[i_save+i] << endl;
//        sum += (p[i_save+i] + 1.0) / 2.0;
        sum += p[i_save+i] + 1.0;
    }
    sum /= 2.0;
    cout << setprecision(10) <<sum << endl;
//    cout << "save_i : " << i_save << endl;
   
    return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>
#include <stdlib.h>

int *commu,*rank;

int root(int x) {
	if (commu[x] == x) {
		return x;
	} else {
		return commu[x] = root(commu[x]);
	}
}

int same(int x,int y) {
	return root(x) == root(y) ? 1 : 0;
}

void unite(int x,int y) {
	x = root(x);
	y = root(y);
	
	if (rank[x] < rank[y]) {
		commu[x] = y;
	} else {
		commu[y] = x;
		if (rank[x] == rank[y]) {
			rank[x]++;
		}
	}
}

int main(void) {
	int n,m,i,j,k,l;
	
	scanf("%d %d",&n,&m);

	commu = (int *)malloc((n+m)*sizeof(int));
	rank = (int *)calloc(n+m,sizeof(int));
	for (i = 0;i < n+m;i++) {
		commu[i] = i;
	}
	
	for (i = 0;i < n;i++) {
		scanf("%d",&k);
		for (j = 0;j < k;j++) {
			scanf("%d",&l);
			if (!same(i,l+n-1)) {
				unite(i,l+n-1);
			}
		}
	}

	int tmp = root(0);
	for (i = 1;i < n;i++) {
		if (root(i) != tmp) {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for(i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
 
int main(){
  ll K, X;
  string ans;
  cin >> K >> X;
  
  if(500*K >= X){
    ans = "Yes";
  } else {
    ans = "No";
  }
 
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

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


Measured memory_bytes: 2052
from sys import stdin 
n,m = [int(x) for x in stdin.readline().rstrip().split()]
a = []
for i in range(m):
    a.append([x for x in stdin.readline().rstrip().split()])
ac = [0] * n
wa = [0] * n
WA = 0
for i in range(m):
    if a[i][1] == 'WA':
        wa[int(a[i][0])-1] += 1
    if a[i][1] == 'AC':
        if ac[int(a[i][0])-1] == 0:
            WA += wa[int(a[i][0])-1]
        ac[int(a[i][0])-1] = 1
print(sum(ac),WA)


Measured memory_bytes: 64860
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

void printAns(int a) { cout << a << endl; }

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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

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

ll INF = 10000000;
ll mod = 1000000007;//10^9+7



//番号ズレ注意！！
int main() {
    ll N;
    cin>>N;
    vector<pair<ll,ll>> work(N);
    REP(i,N){cin>>work[i].second>>work[i].first;}
    sort(work.begin(),work.end());
    ll elapse=0;
    bool can=true;
    REP(i,N){
        elapse+=work[i].second;
        if(elapse>work[i].first){
            can=false;break;
        }
    }
    yesno(can);
}


Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> k;
  map<int, ll> mp;

  FOR(i, 1, n + 1) {
    mp[i % k]++;
  }

  ll ans = mp[0] * mp[0] * mp[0];
  if(k % 2 == 0) ans += mp[k/2] * mp[k/2] * mp[k/2];
  cout << ans << endl;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define ll long long
/*int main()
{int n,x,t;
cin>>n>>x>>t;
int ans=0;
int y=x;
for(int i=t;;i+=t){
if(n<=y){ans=i;break;}
y+=x;
}
cout<<ans<<endl;
return 0;
}*/

int main(){
string s;
cin>>s;
int sum=0;
for(int i=0;i<s.length();i++){
    sum+=(s[i]-'0');
    sum%=9;
}
if(sum==0)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}


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

using namespace std;

int n, arr[100005];
int main()
{
    cin >> n;
    for(int i = 0; i < n; i++) cin >> arr[i];
    int lw = 0;
    for(int i = 0; i < n-1; i++)
    {
        if(arr[i] - arr[i+1] > 1)
        {
            cout << "No" << endl;
            return 0;
        }
        if(arr[i] < lw)
        {
            cout << "No" << endl;
            return 0;
        }
        if(lw == arr[i]) lw = arr[i];
        else lw = arr[i]-1;
    }
    if(arr[n-1] < lw) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 640
#include <stdio.h>

int main()
{
	int n;
	scanf("%d", &n);
	int minv, val;
	scanf("%d %d", &minv, &val);
	int maxv = val - minv;
	minv = (minv < val) ? minv : val;
	for (int i = 2; i < n; i++) {
		scanf("%d", &val);
		maxv = (maxv < val - minv) ? val - minv : maxv;
		minv = (minv < val) ? minv : val;
	}

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


Measured memory_bytes: 2728
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

constexpr long long MOD = 1000000007;

int main() {
  int N;
  std::cin >> N;
  std::vector<int> W(N);
  for (auto& val: W)
    std::cin >> val;
  int ans = INT_MAX;
  for (int i = 1; i < N; ++i)
  {
    int x = std::accumulate(W.begin(), W.begin() + i, 0);
    int y = std::accumulate(W.begin() + i, W.end(), 0);
    ans = std::min(ans, std::abs(x - y));
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 256
L, N = map(int, input().split())
X = [0]
for _ in range(N):
    X.append(int(input()))

s = [0] * (N + 1)
t = [0] * (N + 1)
for i in range(1, N + 1):
    s[i] = s[i-1] + X[i]
    t[i] = t[i-1] + (L - X[N - i + 1])
Y = [0] + [L - X[N - i] for i in range(N)]

# i >= 1


def get_d(s, x, i):
    if i == N:
        return x[N]
    a = i + (N - i) // 2
    return (
        2 * (s[a] - s[i-1] + L * (N - a) - s[N] + s[a]) -
        (x[a] if (N - i) % 2 == 0 else (L - x[a + 1]))
    )


ans = 0
for i in range(1, N + 1):
    ans = max(ans, get_d(s, X, i), get_d(t, Y, i))

print(ans)


Measured memory_bytes: 39476
// https://atcoder.jp/contests/abc074/tasks/arc083_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    int n;
    cin >> n;
    vector<vector<int>> d(n, vector<int>(n));
    vector<vector<bool>> b(n, vector<bool>(n));

    REP(i, n) REP(j, n) cin >> d[i][j];
    REP(i, n) REP(j, n) REP(k, n) {
        if (k != i && k != j) {
            // 3辺の一番長い辺が、それ以外の辺の合計より大きければ不成立
            if (d[i][j] > d[i][k] + d[k][j]) {
                cout << "-1\n";
                return 0;
            }
            // 等しければ辺を作らない
            if (d[i][j] == d[i][k] + d[k][j]) {
                b[i][j] = true;
            }
        }
    }
    ll ans = 0;
    REP(i, n) FOR(j, i + 1, n) {
        if (!b[i][j]) {
            ans += d[i][j];
        }
    }
    cout << ans << endl;

    return 0;
}

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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX / 2;
const ll MOD = 1e9 + 7;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll N = S.length();
    ll sum = 0;
    for(int i = 0;i<N;i++){
        sum += (S[i]-'0')==(i&1);
    }
    ll ans=sum;
    sum=0;
    for(int i = 0;i<N;i++){
        sum += (S[i]-'0')!=(i&1);
    }
    ans = min(ans,sum);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;

#define pbds tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 

void solve(){
    int x,a; cin >> x >> a;
    cout << (x < a ? 0 : 10);
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    string A, B;
    cin >> A >> B;
    int a = (int)A.size();
    int b = (int)B.size();
    if (a > b) {
        cout << "GREATER\n";
    } else if (a < b) {
        cout << "LESS\n";
    } else {
        if (A > B) {
            cout << "GREATER\n";
        } else if (A < B) {
            cout << "LESS\n";
        } else {
            cout << "EQUAL\n";
        }
    }
}


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

using Lint=long long;

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

   Lint ans=a[0]-1;
   int mx=1;
   for(int i=1;i<N;i++){
      if(a[i]==mx+1){
         mx++;
      }else{
         ans+=(a[i]-1)/(mx+1);
      }
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 640
H, W = map(int, input().split())

sheet = []

for _ in range(H):
	sheet.append(list(input()))

for i in range(H):
	for j in range(W):
		if sheet[i][j] == '.':
			sV = (i if i == 0 else i - 1)
			eV = (i + 1 if i == H - 1 else i + 2)
			sH = (j if j == 0 else j - 1)
			eH = (j + 1 if j == W - 1 else j + 2)
			count = 0
			
			for p in range(sV, eV):
				for q in range(sH, eH):
					if sheet[p][q] == '#':
						count += 1
			
			sheet[i][j] = count

for i in range(H):
	for j in range(W):
		print(sheet[i][j],end='')
	print()

Measured memory_bytes: 3444
m,n = gets.chomp.split.map(&:to_i)
a = []
b = []

m.times do
  a.push(gets.chomp.split.map(&:to_i))
end

n.times do
  b.push(gets.chomp.to_i)
end

c = []
a.each do |item|
  p=0 
  n.times do |i| 
    p += item[i]*b[i]
  end 
    c.push(p)
end

puts c

Measured memory_bytes: 6132
n = int(input())
x_arr = [i for i in map(int,input().split())]
ans = 999999999
for i in range(1,100):
  temp = 0
  for j in range(len(x_arr)):
    temp += (x_arr[j] - i)**2
  if temp < ans:
    ans = temp
    
print(ans)

Measured memory_bytes: 3060
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-01-10 21:02:00
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#ifdef LOCAL
#define debug(_) cerr << #_ << ": " << (_) << '\n'
#else
#define debug(_) 1728
#endif

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

  int n; cin >> n;
  string s; cin >> s;
  int cnt = 0;

  s += '$'; s += '$';

  for (int i = 0; i < n; ++i) {
    if (s.substr(i, 3) == "ABC") ++cnt;
  }

  cout << cnt << endl;

  return 0;
}

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

int n;

struct node
{
	int id, pid, k, d;
	int* cid;
	string type;
}N[100005];

void GetDepth(node& GN)
{
	GN.d = 0;
	node temp = GN;

	while (temp.pid != -1)
	{
		GN.d++;
		temp = N[temp.pid];
	}
}

void GetType(node& GN)
{
	if (GN.pid == -1)
		GN.type = "root";
	else if (GN.k == 0)
		GN.type = "leaf";
	else
		GN.type = "internal node";
}

void print()
{
	for (int i = 0; i < n; i++)
	{
		cout << "node " << N[i].id << ": " << "parent = " << N[i].pid << ", " << "depth = " << N[i].d << ", " << N[i].type << ", " << "[";

		if (N[i].k != 0)
		{
			for (int j = 0; j < N[i].k - 1; j++)
				cout << N[i].cid[j] << ", ";
			cout << N[i].cid[N[i].k - 1];
		}

		cout << "]" << endl;
	}	
}

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

	int place;
	cin >> n;
	
	for (int i = 0; i < n; i++)
		N[i].pid = -1;
	
	for (int i = 0; i < n; i++)
	{
		cin >> place;
		N[place].id = place;
		cin >> N[place].k;

		if (N[place].k > 0)
			N[place].cid = new int[N[place].k];

		for (int j = 0; j < N[place].k; j++)
		{
			cin >> N[place].cid[j];
			N[N[place].cid[j]].pid = N[place].id;
		}			
	}

	for (int i = 0; i < n; i++)
		GetDepth(N[i]);

	for (int i = 0; i < n; i++)
		GetType(N[i]);	

	print();

	return 0;
}



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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] original_enemy = Console.ReadLine().Split();
            int enemy = int.Parse(original_enemy[0]);
            int special_attack = int.Parse(original_enemy[1]);

            string[] original_hp = Console.ReadLine().Split();
            long[] hp = original_hp.Select(long.Parse).ToArray();
            Array.Sort(hp);
            Array.Reverse(hp);
            if(special_attack > hp.Length)
            {
                special_attack = hp.Length;
            }
            for (int i = 0; i < special_attack; i++)
            {
                hp[i] = 0;
            }
            Console.WriteLine(hp.Where(x => x != 0).Sum());
            Console.Read();
        }
    }
}

Measured memory_bytes: 35584
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;

int main() {
    set<int> s;
    rep(i,3) {
        int a;
        cin >> a;
        s.insert(a);
    }
    cout << s.size() << endl;
}

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

using namespace std;
mt19937_64 rng(58);

typedef long long ll;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) { bool first = true; string res = ""; for (const auto &x : v) { if (!first) res += ", "; first = false; res += to_string(x); } return "{" + res + "}"; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

unordered_map<ll, ll> memo;

ll dfs(ll n, ll a, ll b, ll c, ll d) {
    if (n == 0) return 0;
    if (n == 1) return d;
    if (memo.find(n) != memo.end()) return memo[n];
    ll ans = ~(1ll<<63);
    if (d < ans / n) ans = d * n;
    for (int i=0; i<3; i++) {
        ll m = vector<ll>{2,3,5}[i];
        ll cost = vector<ll>{a,b,c}[i];
        ll r = n % m;

        ans = min(ans, (ll)dfs(n / m, a, b, c, d) + cost + d * r);
        if (r > 0) {
            ans = min(ans, (ll)dfs(n / m + 1, a, b, c, d) + cost + (ll)(m - r) * d);
        }
    }
    return memo[n] = (ll)ans;
}

void solve() {
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    memo.clear();
    cout << dfs(n, a, b, c, d) << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int T;
    cin >> T;
    for (int i = 1; i <= T; i++) {
        solve();
    }
}

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

int main() {  
	set<string> S;
  	string g;
  	string memo;
  	int n;
  	cin>>n;
  	for(int i=0;i<n;i++){
    	cin >>g>>memo;
    	if(g[0]=='i'){
        S.insert(memo);    
        } 
    	else if(g[0]=='f'){
        	if(S.count(memo)){
            cout<<"yes"<<endl;
            }
        	else{cout<<"no"<<endl;}
        }
    }
}


Measured memory_bytes: 32632
#include<bits/stdc++.h>
using namespace std;
int main(){
  	int a, b;
	cin >> a >> b;
	if(a>=1 && a<=9 && b>=1 && b<=9)
      	cout << a*b << endl;
 	else
      	cout << -1 <<endl;
  	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 100100100
#define MOD 1000000007

using namespace std;
using ll = long long;
using ull = unsigned long long ;

#define FOR(i,n) for(ll i=0;i<n;i++)

struct edge{ll to,cost;};

int main(int argc, char const* argv[]){
   ios::sync_with_stdio(false);
   cin.tie(0); 
   int N;
   cin >> N;
   if(N <= 999)cout << "ABC" << endl;
   else cout << "ABD" << endl;
   return 0;
}


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

    #define all(v) v.begin(),v.end()
    #define rall(v) v.rbegin(),v.rend()
    #define trav(i,a) for(auto i: a)
    #define ff first
    #define ss second
    #define eb emplace_back
    #define tc(t) ll t; cin>>t; while(t--)
    #define prec(n) fixed<<setprecission(n)
    #define mst(arr,value) memset(arr,value,sizeof(arr))
    #define sz(a) a.size()
    #define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    
    const long long inf = (long long)1e18;
    const long long M = (long long)1e9+7;
    
    #define fab(i,a,b) for(ll i=a; i<b; i++)
    #define fba(i,b,a) for(ll i=b; i>=a; i--)

    ll mpw(ll a, ll b, ll M = inf) {
        if(b == 0) return 1;
        if(b % 2 == 1) 
            return a * mpw((a * a) % M, b / 2, M) % M;
        return mpw((a * a) % M, b / 2, M);        
    } 

    ll knapsack(vector<pair<ll, ll>> items, ll n, ll w) {
        ll ans = 0;
        vector<ll> dp(w + 1, 0);
        fab(i, 0, n) {
            ll wt = items[i].ff;
            ll vl = items[i].ss;
            fba(j, w - wt, 0) {
                dp[wt + j] = max(dp[j] + vl, dp[wt + j]);
            }
        }
        fab(i, 0, w + 1) {
            ans = max(ans, dp[i]);
        }
        return ans;
    }

    int main() {
        fio

        ll n, w;
        cin >> n >> w;

        vector<pair<ll, ll>> items(n);

        fab(i, 0, n) { 
            cin >> items[i].ff >> items[i].ss;
        }

        cout << knapsack(items, n, w);

        
        return 0;
    }

Measured memory_bytes: 3980
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<a*b/2<<endl;
    return 0;
}


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

using P = pair<int,int>;
int main(void) {
    int H,W,D,a,Q;
    int l,r;
    cin >> H >> W >> D;

    // mod Dで累積和を取っておく
    map<int,P> mp;
    for(int i=1;i<=H;i++) {
        for(int j=1;j<=W;j++) {
            cin >> a;
            mp[a] = make_pair(i,j);
        }
    }

    vector<map<int,int>> sum(D);
    for(int i=0;i<D;i++) {
        sum[i][0] = 0;
    }
    vector<int> pos(D,0);
    for(int i=1;i<=(H*W);i++) {
        if(i+D > (H*W)) continue;
        sum[i%D][pos[i%D]+1] = sum[i%D][pos[i%D]] 
                     + abs(mp[i+D].first-mp[i].first)
                     + abs(mp[i+D].second-mp[i].second);
        pos[i%D]++;
    }

    cin >> Q;
    vector<int> ans(Q);
    for(int i=0;i<Q;i++) {
        cin >> l >> r;
        if(l == r) {
            ans[i] = 0;
        } else {
            if(l%D) {
            ans[i] = sum[r%D][r/D] - sum[l%D][l/D];
            } else {
            ans[i] = sum[r%D][r/D-1] - sum[l%D][l/D-1];
            }
        }
    }

    for(int i=0;i<Q;i++) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 15232
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2005,P=1e9+7;
int n,m,fa[N];ll X,ans[N];
struct E{int u,v,w;}e[N];
inline bool operator<(E a,E b){return a.w<b.w;}
inline int pw(int a,int b){int r=1;for(;b;b>>=1,a=1ll*a*a%P)if(b&1)r=1ll*r*a%P;return r;}
int fnd(int x){return fa[x]==x?x:fa[x]=fnd(fa[x]);}
ll calc(int o)
{
	for(int i=1;i<=n;i++)fa[i]=i;
	fa[e[o].u]=e[o].v;ll r=e[o].w;
	for(int i=1;i<=m;i++)
	{
		int u=fnd(e[i].u),v=fnd(e[i].v);
		if(u!=v)fa[u]=v,r+=e[i].w;
	}
	return r;
}
int main()
{
	scanf("%d%d%lld",&n,&m,&X);
	for(int i=1;i<=m;i++)scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].w);
	sort(e+1,e+m+1);int s=0,t=0;
	for(int i=0;i<=m;i++)ans[i]=calc(i);
	if(X<ans[0]){puts("0");return 0;}
	for(int i=1;i<=m;i++)s+=ans[i]==X;
	if(X==ans[0])
	{
		printf("%d\n",1ll*(pw(2,s)+P-2)*pw(2,m-s)%P);
		return 0;
	}
	for(int i=1;i<=m;i++)t+=ans[i]>X;
	printf("%d\n",2ll*(pw(2,s)+P-1)*pw(2,t)%P);
	return 0;
}


Measured memory_bytes: 256
n = int(input())
t1 = x1 = y1 = 0
flag = 0
for i in range(n):
    t2, x2, y2 = map(int,input().split())
    if t2-t1 >= abs(x2-x1)+abs(y2-y1) and (t2-t1)%2 == (abs(x2-x1)+abs(y2-y1))%2:
        pass
    else:
        flag = 1
    t1, x1, y1 = t2, x2, y2
if flag == 1:
    print('No')
else:
    print('Yes')


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

using namespace std;

using i64 = long long int;

const i64 mod = 998244353;
const i64 INF = (1LL<<62) - 1;

#define int i64
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(a) a.begin(), a.end()

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

using P = pair<pair<i64, i64>, i64>;

struct SegmentTree {
private:
    int n;
    vector<int> node;

public:
    SegmentTree(vector<int> v) {
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, INF);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = min(node[2*i+1], node[2*i+2]);
    }

    void update(int x, int val) {
        x += (n - 1);
        node[x] = val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = min(node[2*x+1], node[2*x+2]);
        }
    }

    int getmin(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return INF;
        if(a <= l && r <= b) return node[k];

        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};

signed main(){
    i64 n, m;
    cin >> n >> m;
    vector<P> v(m);
    rep(i, m){
        i64 a, b, c;
        cin >> a >> b >> c;
        v[i] = P(pair<i64, i64>(a, b), c);
    }
    sort(all(v));
    SegmentTree seg(vector<i64>(n, INF));
    seg.update(0, 0);
    for(i64 i = 0; i < m; ++i){
        auto x = v[i];
        i64 l = x.first.first, r = x.first.second, c = x.second;
        --l; --r;
        //cout << l << " " << r << endl;
        if(seg.getmin(r, r + 1) > seg.getmin(l, r + 1) + c) seg.update(r, seg.getmin(l, r + 1) + c);
    }
    if(seg.getmin(n - 1, n) == INF) cout << -1 << endl;
    else cout << seg.getmin(n - 1, n) << endl;
}

Measured memory_bytes: 5376
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

int main() {
	string S, T;
	cin >> S >> T;
	int ans = 0;
	for (int i = 0; i < 3; ++i) {
		if (S[i] == T[i]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

void push(int);
int pop();

int top,O[1000];

int main(){
  int x,y;
  char o[100];
  top = 0;

  while(scanf("%s",o) != EOF){
    if(o[0] == '+'){
      x = pop();
      y = pop();
      push(x + y);
    }
    else if(o[0] == '-'){
      y = pop();
      x = pop();
      push(x - y);
    }
    else if(o[0] == '*'){
      x = pop();
      y = pop();
      push(x * y);
    }
    else{
      push(atoi(o));
    }
  }

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

  return 0;
}

void push(int a){
  O[++top] = a;
}

int pop(){
  top--;

  return O[top+1];
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.20f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

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

int main() {
	ll x;
	cin >> x;

	cout << lcm(x, 360) / x << endl;

	return 0;
}


Measured memory_bytes: 3628
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n, m = list(map(int, input().split()))
    diff = abs(n - m)
    n_factorial = 1
    m_factorial = 1
    large_number = 10 ** 9 + 7

    for i in range(1, n + 1):
        n_factorial = (n_factorial * i) % large_number

    for k in range(1, m + 1):
        m_factorial = (m_factorial * k) % large_number

    rate = 0

    if diff == 1:
        rate = 1
    elif diff == 0:
        rate = 2

    print(((n_factorial * m_factorial * rate) % large_number))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

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

	int x = floor(static_cast<double>(m) / n);
	while(m % x != 0){
		x--;
	}
	cout << x << endl;
}


Measured memory_bytes: 256
package main

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

var h, w, k int
var fibs []int
var cache map[int]int

func init() {
	h, w, k = parseLine()
	fibs = fibnatch(w)
	cache = make(map[int]int)
}

func parseLine() (int, int, int) {

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	var ret [3]int

	for i := 0; i < 3; i++ {
		scanner.Scan()
		word := scanner.Text()
		ret[i], _ = strconv.Atoi(word)
	}

	return ret[0], ret[1], ret[2]
}

func fibnatch(max int) []int {

	ret := make([]int, max+1)

	ret[0] = 1
	ret[1] = 1

	for i := 2; i < max+1; i++ {
		ret[i] = ret[i-1] + ret[i-2]
	}

	return ret
}

func add(a, b int) int {
	return (a + b) % 1000000007
}

func mul(a, b int) int {
	return (a * b) % 1000000007
}

func cacheKey(start, goal, height int) int {
	return height*100 + start*10 + goal
}

func calc(start, goal, height int) int {

	if goal < start {
		return calc(goal, start, height)
	}

	if height < goal-start {
		return 0
	}

	if height == 1 {
		if start == goal {
			return mul(fibs[start-1], fibs[w-start])
		} else {
			return mul(fibs[start-1], fibs[w-start-1])
		}
	}

	if c := cache[cacheKey(start, goal, height)]; 0 < c {
		return c
	}

	ret := mul(mul(fibs[start-1], fibs[w-start]), calc(start, goal, height-1))

	if 1 < start {
		tmp := mul(mul(fibs[start-2], fibs[w-start]), calc(start-1, goal, height-1))
		ret = add(tmp, ret)
	}

	if start < w {
		tmp := mul(mul(fibs[start-1], fibs[w-start-1]), calc(start+1, goal, height-1))
		ret = add(tmp, ret)
	}

	cache[cacheKey(start, goal, height)] = ret

	return ret
}

func main() {
	fmt.Println(calc(1, k, h))
}


Measured memory_bytes: 896