akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;

int main() {
    int n;
    vector<int> vec;
    vector<int> sums;

    cin >> n;
    for (int i = 0; i < n; i++) {
        int w;
        cin >> w;
        vec.push_back(w);
        if (i == 0)
            sums.push_back(w);
        else
            sums.push_back(sums[i-1]+w);
    }

    int min = 1000000000;
    for (int i = 0; i < n-1; i++) {
        int diff = abs(sums[n-1] - 2*sums[i]);
        if (diff < min)
            min = diff;
    }

    cout << min << endl;
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(n%2!=0){
        cout << "No" << endl;
        return 0;
    }
    string ans="No";
    string t=s.substr(n/2);
    if(s==t+t){
        ans ="Yes";
    }
    cout << ans << endl;
    return 0;
}

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

int main(void){
    char n[201]={};
    char temp[201];
    int m,i,h,len,j;

    while(1){
        scanf("%s",n);
        if(n[0] == '-') break;
        len=strlen(n);
        scanf("%d",&h);
        for(i=0;i<h;i++){
            scanf("%d", &m);
            for(j=0;j<len;j++) temp[j] = n[j];
            for(j=0;j<len-m;j++){
            n[j] = n[j+m];
            }
            for(j=0;j<m;j++){
                n[j+len-m] = temp[j];
            }
        }
        printf("%s\n",n);
        }
    return(0);
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

unordered_map<int,ll> dp[101];

int main()
{
    int n,W;
    cin >>n >>W;
    vector<int> w(n),v(n);
    rep(i,n) cin >>w[i] >>v[i];

    dp[0][0]=0;
    rep(i,n)
    {
        for(const auto &p:dp[i])
        {
            int j=p.fi;
            // printf("  j= %d, p.se=  %d\n", j,p.se);
            if(j+w[i]<=W) dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], p.se+v[i]);
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
    }

    ll ans=0;
    for(const auto &p:dp[n]) ans=max(ans,p.se);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VS = vector<string>;
using graph = vector<vector<int>>;
int main()
{
int a,b;
cin>>a>>b;
if(a==1)a=14;
if(b==1)b=14;
if (a<b)
{
    cout<<"Bob"<<endl;
}
else if (a>b)
{
    cout<<"Alice"<<endl;
}
else cout<<"Draw"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <queue>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    if((n+m)%2 != 0) cout << (n+m)/2 + 1 << endl;
    if((n+m)%2 == 0) cout << (n+m)/2 << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    double a = sc.nextDouble();
    double b = sc.nextDouble();
    double c = sc.nextDouble();

    double s = a * b * Math.sin(Math.PI * c / 180) / 2;
    double l = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) - 2 * a * b * Math.cos(Math.PI * c / 180)) + a + b;
    double h = 2 * s / a;

    System.out.println(s);
    System.out.println(l);
    System.out.println(h);
  }
}



Measured memory_bytes: 27980
#include<bits/stdc++.h>
#define For(i,j,k) for(int i=j;i<=k;++i)
using namespace std;
int read(){
	int x=0,fh=1; char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') fh=-1;
	for (;isdigit(ch);ch=getchar()) x=x*10+(ch^48);
	return x*fh;
}
int main(){
	int q=read(),x,y; long long n,m,s;
	while(q--){
		x=read(),y=read(); n=(long long)x*y; m=sqrt(n);
		s=1; if (m*m==n&&x!=y) ++s; if (m*(m+1)>=n) ++s; printf("%d\n",m*2-s);
	}
	return 0;
}

Measured memory_bytes: 256
using System;

namespace ChokudaiScanner
{
    class MainClass
    {
        static void Main()
        {
            Scanner cin = new Scanner();

            string r = cin.Next();
            string g = cin.Next();
            string b = cin.Next();

            int sum = int.Parse(r + g + b) ;

            if (sum % 4 == 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string Next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next();
            i = 0;
            return s[i++];
        }

        public string[] ArrayNext(int N)
        {
            string[] Array = new string[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Next();
            }
            return Array;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextInt() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextLong() + add;
            }
            return Array;
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextDouble() + add;
            }
            return Array;
        }
    }
}



Measured memory_bytes: 27084
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k, n;
    cin >> n >> k;
    vector<int> block(n);
    rep(i, n) {
      cin >> block[i];
    }
    sort(block.begin(), block.end(), greater<int>());
    int ans = 0;
    rep(i, k) {
      ans += block[i];
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
import collections
n = input()
a = list(map(int,input().split()))
c = collections.Counter(a)
c = dict(c)
ans = 0
for i in c.keys():
    if i < c[i]:
        ans +=c[i] - i
    elif i > c[i]:
        ans += c[i]
print(ans)

Measured memory_bytes: 21740
#include <bits/stdc++.h>
using namespace std;
long long dp[2][100005];
int v[101],w[101];
int W,n;
int main()
{
    cin>>n>>W;
    for(int i=0;i<n;i++)
    {
      cin>>w[i]>>v[i];
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<=W;j++)
        {
            dp[i&1][j]=dp[(i+1)&1][j];
            if(j>=w[i])
            dp[i&1][j]=max(dp[i&1][j],dp[(i+1)&1][j-w[i]]+v[i]);
        }
    }
    cout<<dp[(n-1)&1][W]<<endl;
    return 0;
}


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

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

public class Main
{
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    public void go() throws IOException
    {
        StringTokenizer tok = new StringTokenizer(in.readLine());
        String s = tok.nextToken();
        tok = new StringTokenizer(in.readLine());
        String t = tok.nextToken();
        int n = s.length();
        int m = t.length();
        int[][] next = new int[n][26];
        Arrays.fill(next[n-1], -1);
        next[n-1][s.charAt(n-1)-'a'] = n-1;
        // out.println(Arrays.toString(next[n-1]));
        for (int i = n-2; i >= 0; i--)
        {
            next[i] = Arrays.copyOf(next[i+1], 26);
            next[i][s.charAt(i)-'a'] = i;
            // out.println(Arrays.toString(next[i]));
        }
        int currIndex = 0;
        long len = 0;
        boolean works = true;
        for (int i = 0; i < m; i++)
        {
            int nextIndex = next[currIndex][t.charAt(i)-'a'];
            if (currIndex != 0 && nextIndex == -1)
            {
                nextIndex = next[0][t.charAt(i)-'a'];
            }
            // out.println(currIndex + " " + nextIndex);
            if (nextIndex == -1)
            {
                works = false;
                break;
            }
            if (currIndex > nextIndex)
            {
                len += nextIndex+n - currIndex + 1;
            }
            else
            {
                len += nextIndex - currIndex + 1;
            }
            currIndex = (nextIndex+1)%n;
        }
        if (works)
        {
            out.println(len);
        }
        else
        {
            out.println(-1);
        }

        out.flush();
        in.close();
    }

    public static void main(String[] args) throws IOException
    {
        new Main().go();
    }
}


Measured memory_bytes: 55732
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define ALL(a)              a.begin(), a.end()
#define ALLN(a, n)          (a, a+n)
#define MAX                 10000007
#define MIN                 -10000007

const int N=1e6+1; 
  
ll lpf[N], mobius[N]; 
ll fre[N] = { 0 }; 
  
// Function to calculate least 
// prime factor of each number 
void least_prime_factor() 
{ 
    for (ll i = 2; i < N; i++) 
  
        // If it is a prime number 
        if (!lpf[i]) 
  
            for (ll j = i; j < N; j += i) 
  
                // For all multiples which are not 
                // visited yet. 
                if (!lpf[j]) 
                    lpf[j] = i; 
} 
  
// Function to find the value of Mobius function 
// for all the numbers from 1 to n 
void Mobius() 
{ 
    for (ll i = 1; i < N; i++) { 
  
        // If number is one 
        if (i == 1) 
            mobius[i] = 1; 
        else { 
  
            // If number has a squared prime factor 
            if (lpf[i / lpf[i]] == lpf[i]) 
                mobius[i] = 0; 
  
            // Multiply -1 with the previous number 
            else
                mobius[i] = -1 * mobius[i / lpf[i]]; 
        } 
    } 
} 
  
// Function to find the number of pairs 
// such that gcd equals to 1 
ll gcd_pairs(ll a[], ll n) 
{ 
    // To store maximum number 
    ll maxi = 0; 
  
    // To store frequency of each number 
    
  
    // Find frequency and maximum number 
    for (ll i = 0; i < n; i++) { 
        fre[a[i]]++; 
        maxi = max(a[i], maxi); 
    } 
  
    least_prime_factor(); 
    Mobius(); 
  
    // To store number of pairs with gcd equals to 1 
    ll ans = 0; 
  
    // Traverse through the all possible elements 
    for (ll i = 1; i <= maxi; i++) { 
        if (!mobius[i]) 
            continue; 
  
        ll temp = 0; 
        for (ll j = i; j <= maxi; j += i) 
            temp += fre[j]; 
  
        ans += temp * (temp - 1) / 2 * mobius[i]; 
    } 
  
    // Return the number of pairs 
    return ans; 
} 
  

              
int main()
{
  ios::sync_with_stdio(0);
    cin.tie(0);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
      
    int t;
    t=1;
     //  cin>>t;
    while(t--){
            ll n;
            cin>>n;
            ll a[n];
            cin>>a[0];
            ll res=a[0];
            REP(i,1,n-1){
              cin>>a[i];
              res=__gcd(res,a[i]);
            }  
            bool value=false;
            ll k=gcd_pairs(a,n);
            if(k==(n*(n-1)/2)) value=true;
            if(value) cout<<"pairwise coprime";
            else if(res==1) cout<<"setwise coprime";
            else cout<<"not coprime";

       


             }
             cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
    return 0;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    string s;
    cin >> s;
    ll n;
    n = s.length();
    bool exist[4] = {};
    rep(i, n) {
        if (s[i] == 'N') {
            exist[0] = true;
        } else if (s[i] == 'S') {
            exist[1] = true;
        } else if (s[i] == 'W') {
            exist[2] = true;
        } else if (s[i] == 'E') {
            exist[3] = true;
        }
    }

    /* cout << exist[0] << " " << exist[1] << " " << exist[2] << " " << exist[3]
     */
    /*      << endl; */
    bool judge[2];
    judge[0] = exist[0] ^ exist[1];
    judge[1] = exist[2] ^ exist[3];
    /* cout << judge[0] << " " << judge[1] << endl; */

    if (judge[0] | judge[1]) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}



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

string S;
int sums,sumt;

int main()
{
    cin>>S;
    for(int i=0;i<S.size();i++)
    {
        if(S[i] == 'S') sums++;
        if((sums)&&(S[i]=='T'))
        {
            sums--;
            sumt+=2;
        }
    }
    cout<<S.size()-sumt<<"\n";
}

Measured memory_bytes: 640
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def main():
  n = ni()
  print(n**2)

if __name__ == '__main__':
  main()

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	ll n;
	cin>>n;
	vector<P> p(n);
	rep(i,n)cin>>p[i].first>>p[i].second;

	map<P,P> mp;
	ll zero = 0;
	rep(i,n){
		if(p[i].first==0 && p[i].second==0){
			zero += 1;
			continue;
		}
		ll x;
		if(p[i].first==0 || p[i].second==0){
			p[i].first = abs(p[i].first);
			p[i].second = abs(p[i].second);
			x = max(abs(p[i].first), abs(p[i].second));
		}else if(p[i].second>0) x = gcd(p[i].first, p[i].second);
		else if(p[i].second<0) x = gcd(-p[i].first, -p[i].second);

		p[i].first /= x;
		p[i].second /= x;

		if(p[i].first < 0){
			p[i].first *= -1;
			p[i].second *= -1;
		}
		if(p[i].first==0)p[i].second = 1;
		if(p[i].second==0)p[i].first = 1;

		if(p[i] == P(1,0)) mp[P(1,0)].first += 1;
		else if(p[i] == P(0,1)) mp[P(1,0)].second += 1;
		else if(p[i].second < 0) mp[P(-p[i].second,p[i].first)].second += 1;
		else mp[p[i]].first += 1;
	}


	ll ans = 1;
	for(auto x: mp){
		P q = x.second;
		ans *= (power(2,q.first) + power(2, q.second) - 1) % mod;
		ans %= mod;
	}

	ans += zero-1 + mod;
	ans %= mod;

	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 21784
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

int main() {
    int N;
    cin>>N;
    int s[N];
    int sum=0;
    REP(i,N){
        cin>>s[i];
        sum+=s[i];
    }

    sort(s,s+N);
    if(sum%10==0){
        REP(i,N){
            if(s[i]%10!=0){
                sum-=s[i];
                cout<<sum<<endl;
                return 0;
            }
        }
        cout<<0<<endl;



    }else{
        cout<<sum<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,c,a[11];
  while(1){
    memset(a,0,sizeof(a));
    cin>>n;
    if(n==0) break;
    for(int i=0;i<n;i++){
      cin>>c;
      a[c]++;
    }
    for(int i=0;i<10;i++){
      if(a[i]!=0){
	for(int j=0;j<a[i];j++){
	  cout<<'*';
	}
      }else{
	cout<<'-';
      }
      cout<<endl;
    }
  }
  return(0);
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define wfile freopen("output.txt", "w", stdout)
#define rfile freopen("input.txt", "r", stdin)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
void enable_io(){
    #ifdef LOCAL_PROJECT
        wfile;
        rfile;
    #endif
}

int main(int argc, char const *argv[])
{   
    fastio;
    enable_io();
    int T = 1;
    //cin >> T;
    for(int t = 0; t < T; t++){
        int n;
        cin >> n;
        set<string> sx;
        for (int i = 0; i < n; ++i)
            {
                string a;
                cin >> a;
                sx.insert(a);
            }    
        cout << sx.size() << endl; 
    }
    return 0;
}


Measured memory_bytes: 19248
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef unsigned int U;

int n;
U p, p_sum, j[65000], ans;

int main(){
    while( scanf("%d", &n), n ){
        p_sum = 0;
        for(int x = 0; x < n; x++){
            scanf(" %u", &p);
            p_sum += p;
        }
        for(int x = 0; x < n-1; x++){
            scanf(" %u", &j[x]);
            p_sum += j[x];
        }
        sort(j, j+n-1);
        ans = p_sum;
        for(int x = 0; x < n-1; x++){
            p_sum -= j[x];
            ans = max(ans, p_sum*(x+2));
        }
        printf("%u\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1304
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
int INF = 100000000;

int main() {
  int N, C, K; cin >> N >> C >> K;
  vector<int> T(N);
  rep(i, N) {
    cin >> T[i];
  }
  sort(all(T));
  int ans = 0;
  for (int i = 0; i < N;) {
    int cnt = 1;
    int s = T[i];
    int e = s + K;
    while (T[i+1] <= e && cnt < C) {
      i++;
      cnt++;
    }
    i++;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n=0,m,a,b,c,d,e;
	long double z,w;
	string str;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>a>>b;
	if(max(a,b)>8){cout<<":(";}
	else{cout<<"Yay!";}
	





	cout<<endl;
} 


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

using namespace std;

int main()
{
    string n;
    cin >> n;
    int acc = 0 ;
    for (char c : n) 
    {
        acc += c - '0';
    }

    cout << (acc % 9 == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3748
#include "bits/stdc++.h"
#define REP(i, m, n) for(long long i = m; i < n; ++i)
#define CO(n) cout << n << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int q;
string X[150], Y[150];
int dp[1001][1001];
//dp[i][j] Xのi文字目までとYのj文字目まででできるLSCの長さ

int main()
{
    ios::sync_with_stdio(false);
    cin >> q;
    REP(n,0,q) cin >> X[n] >> Y[n];
    REP(n,0,q){
        int lx = X[n].size(); int ly = Y[n].size();
        //dpテーブル初期化
        REP(i,0,lx+1) dp[i][0] = 0;
        REP(j,0,ly+1) dp[0][j] = 0;
        //dp
        REP(i,0,lx){
            REP(j,0,ly){
                if (X[n][i]==Y[n][j]) dp[i+1][j+1] = dp[i][j] + 1;
                else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            }
        }
        CO(dp[lx][ly]);
    }
    return 0;
}


Measured memory_bytes: 7188
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		if ((s.length() == t.length()) && (s + s).contains(t)) {
			System.out.println("Yes");
			return;
		}
		System.out.println("No");
	}
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr ll MOD = 2;

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  int n, m;
  cin >> n >> m;

  vector<vector<int>> switches(m);
  vector<int> p(m);
  for (vector<int>& v : switches) {
    int k;
    cin >> k;
    v.resize(k);
    scan(v);
  }
  scan(p);

  ll ans = 0;
  rep(i, 0, 1 << n) {
    bool result = true;
    rep(j, 0, m) {
      int count = 0;
      for (int s : switches[j]) count += bool(i & (1 << (s - 1)));
      result &= (count % 2 == p[j]);
    }

    ans += result;
  }

  put(ans);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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; }
typedef pair<int,int> P;

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

int main(){
  int n;
  cin >> n;
  int a[n];
  rep(i,n)cin >> a[i];
  int l[n],r[n];
  rep(i,n){
    if(i==0)l[i]=a[i];
    else l[i]=gcd(l[i-1],a[i]);
  }
  for(int i=n-1;i>=0;i--){
    if(i==(n-1))r[i]=a[i];
    else r[i]=gcd(r[i+1],a[i]);
  }
  int ans = 0;
  for(int i=1;i<n-1;i++){
    chmax(ans,gcd(l[i-1],r[i+1]));
  }
  chmax(ans,l[n-2]);
  chmax(ans,r[1]);
  cout << ans << endl;
}


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

using namespace std;

int main(void){
	int h[10];
	for (int i=0; i<10; i++){
		cin >> h[i];
	}
	sort(h,h+10);

	cout << h[9] << endl << h[8] << endl << h[7] << endl;

	return 0;
}

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

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

  int result = 0;
  if (N < K)
  {
    result += N * X;
  }
  else
  {
    result += K * X + (N - K) * Y;
  }

  cout << result << endl;

  return 0;
}

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

#define X first
#define Y second

using namespace std;

const int N=100;
int n,k;

int cnt;
pair<int,int> Edge[N*N/2];

void Print()
{
	printf("%d\n",cnt);
	for(int k=1;k<=cnt;k++)
		printf("%d %d\n",Edge[k].X,Edge[k].Y);
}

int main()
{
	scanf("%d %d",&n,&k);
	int num=(n-1)*(n-2)/2;
	if(k>num)
	{
		printf("-1\n");
		return 0;
	}
	
	for(int i=2;i<=n;i++)
		Edge[++cnt]=make_pair(1,i);
	if(num>k)
	{
		for(int i=2;i<=n;i++)
			for(int j=i+1;j<=n;j++)
			{
				Edge[++cnt]=make_pair(i,j);
				if( --num == k )
				{
					Print();
					return 0;
				}
			}
	}
	Print();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a, b, Ans;
    char op;
    while(1){
        cin >> a >> op >> b;
        if(op == '+'){
            Ans = a + b;
            cout << Ans << endl;
        }
        if(op == '-'){
            Ans = a - b;
            cout << Ans << endl;
        }
        if(op == '*'){
            Ans = a * b;
            cout << Ans << endl;
        }
        if(op == '/'){
            Ans = a / b;
            cout << Ans << endl;
        }
        if(op == '?'){
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3084
# 最終的な倒叙回数だけで決まりそうな気がした(登場回数+1を掛けて最後に空文字ぶん1を引く)
# なんでかというと、同じ文字は含まないので、結局登場する順番は関係ないから。ある文字が複数あったとき、ひとつだけ選ぶ（あるいは選ばない）というのは、「どの時点で登場した文字を採用するか」と同義。
# などとドヤったけど6WAくらいだしましたしにます
# と思ったらMODしてなかった件


from functools import reduce

n = int(input())
s = input()
d = {}
for sv in s:
    if sv not in d:
        d[sv] = 1
    else:
        d[sv] += 1
ans = reduce(lambda x, y: x * y, list(map(lambda x: x[1] + 1, d.items()))) - 1
print(ans % (10**9+7))


Measured memory_bytes: 3812
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)

	ws := make([]int,n)
	sum := 0
	for i := 0; i < n; i++ {
		var w int
		fmt.Scan(&w)
		ws[i] = w
		sum += w
	}

	s1 := 0
	abs := sum
	for i := 0; i < n; i++ {
		s1 += ws[i]
		abs = int(math.Min(float64(abs),math.Abs(float64(s1) - float64(sum - s1))))
	}
	fmt.Println(abs)
}

Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
using namespace std;

int main() {
	char S[101],T[101];
	bool ans=false;
	cin>>S>>T;
	sort(S,S+strlen(S));
	sort(T,T+strlen(T));
	for(int i=0;i<strlen(S);i++){
		if(S[i]<T[strlen(T)-i-1]){
			ans=true;
			break;
		}
		else if(S[i]>T[strlen(T)-i-1])break;
		if(i==strlen(S)-1&&strlen(S)<strlen(T))ans=true;
	}
	cout<<(ans?"Yes":"No");
}


Measured memory_bytes: 1020
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

int main(){
	string s;
    cin >> s;
  	for(int i = 0; i+1 < s.size(); ++i){
    	if(s[i] == s[i+1]){
        	cout << i+1 << " " << i+2;
          return 0;
        }
    }
  
  	for(int i = 0; i+2 < s.size(); ++i){
    	if(s[i] == s[i+2]){
        	cout << i+1 << " " << i+3;
          return 0;
        }
    }
  	cout << "-1 -1";
   return 0;
}

Measured memory_bytes: 512
/* Author rumoisen */
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
 
using namespace std;
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==1) puts("Hello World");
    else
    cout<<b+c<<endl;
    return 0;
}

Measured memory_bytes: 256
people = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

n = int(input())
for i in range(n):
    b, f, r, v = map(int, input().split())
    people[b-1][f-1][r-1] += v

for i in range(4):
    for j in range(3):
        for k in range(10):
            print(f" {people[i][j][k]}", end="")
        print()
    if i != 3:
        print("####################")


Measured memory_bytes: 5632
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int n,k;
    cin>>n>>k;
    int t = (n-1)*(n-2)/2;
    if(k>t){
        cout<<-1<<endl;
        return 0;
    }

//
//    if(n==2){
//        if(k>=1){
//            cout<<-1<<endl;
//        }
//        cout<<1<<endl;
//
//    }else if(n==3){
//
//    }
//

    int masu[n][n];
    rep(i,n){
        rep(j,n){
            masu[i][j]=INF;
        }
    }
    rep(i,n){
        masu[0][i]=1;
        masu[i][0]=1;
    }
    int t2 = t-k;
    int tt=0;
    
    bool f = false;
    for(int i=1;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(t2==tt){
                f = true;
                break;
            }
            masu[i][j]=1;
            masu[j][i]=1;
            tt++;

        }
        if(f)break;
    }

    set<pair<int,int>> s;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(i!=j&&(masu[i][j]==1||masu[j][i]==1)){

                if(i>=j){
                    s.insert({i+1,j+1});
                }else{
                    s.insert({j+1,i+1});
                }
            }
        }
    }

    cout<<s.size()<<endl;

    for(auto &a:s){
        cout<<a.first<<" "<<a.second<<endl;
    }





    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
int main(void){
    // Here your code !
    int x,y;
    
    scanf("%d %d",&x,&y);
    if(x==1||x==3||x==5||x==7||x==8||x==10)
    {
        if(y==3||y==5||y==7||y==8||y==10||y==12)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    if(x==4||x==6||x==9||x==11)
    {
        if(y==6||y==9||y==11)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    if(x==2)
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int i,n,k;
  cin >> n >> k;
  int p[1010];
  for(i=0;i<n;i++){
    cin >> p[i];
  }
  sort(p,p+n);
  int sum=0;
  for(i=0;i<k;i++){
    sum+=p[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 3528
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll X;
  cin >> X;
  vector<bool> dp(X+1);
  dp[0] = true;;
  rep (i, X+1) {
    if (not dp[i]) continue;
    if (i + 100 <= X) dp[i + 100] = true;
    if (i + 101 <= X) dp[i + 101] = true;
    if (i + 102 <= X) dp[i + 102] = true;
    if (i + 103 <= X) dp[i + 103] = true;
    if (i + 104 <= X) dp[i + 104] = true;
    if (i + 105 <= X) dp[i + 105] = true;
  }
  cout << (dp[X] ? 1 : 0) << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n-2):
    t = [p[i], p[i+1], p[i+2]]
    a = sorted(t)
    #print(t, a)
    if t[1] == a[1]:ans+=1
print(ans)

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)


int main() {
	cin.sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<int>x(N);
	int a, b;
	rep(i, M) {
		cin >> a >> b;
		x[a-1]++;
		x[b-1]++;
	}
	bool flag = true;
	rep(i, N) {
		if (x[i] % 2 == 1) {
			cout << "NO" << endl;
			flag = false;
			break;
		}
	}
	if (flag) {
		cout << "YES" << endl;
	}
	return 0;
}

Measured memory_bytes: 640
/**
 *      author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *      created : 2019-11-23 13:36:49
**/

#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 <functional>
#include <iomanip>
#include <random>
#include <utility>

using namespace std;

using int64 = long long;
#define debug(_) cerr << #_ << ": " << (_) << '\n'
template<typename T> inline void chmin(T &a, T b) { if (a > b) a = b; return; }
template<typename T> inline void chmax(T &a, T b) { if (a < b) a = b; return; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& vec) { os << '{'; for (size_t i = 0; i < vec.size(); ++i) { os << vec[i]; if (i != vec.size() - 1) os << ','; } os << '}'; return os; }
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

class food {
 public:
  int cost, delicious;
};

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

  int n, t; cin >> n >> t;
  vector<food> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i].cost >> v[i].delicious;
  }

  sort(v.begin(), v.end(), [](const food& x, const food& y){
      return x.cost < y.cost;
  });

  int ans = 0;

  vector<vector<int>> dp(n + 5, vector<int>(t + 5, 0));

  for (int i = 0; i < n - 1; ++i) {
    for (int j = 0; j <= t - 1; ++j) {
      if (j - v[i].cost >= 0) {
        dp[i + 1][j] = max(dp[i][j], dp[i][j - v[i].cost] + v[i].delicious);
      } else {
        dp[i + 1][j] = dp[i][j];
      }
      //ans = max(ans, dp[i + 1][j] + v[i + 1].delicious);
    }
    ans = max(ans, dp[i + 1][t - 1] + v[i + 1].delicious);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 35712
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * 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);
        TaskATC64C solver = new TaskATC64C();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskATC64C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();

            int x = in.nextInt();

            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }

            long o = 0L;

            for (int i = 0; i < n - 1; i++) {
                int f = a[i];
                int s = a[i + 1];

                int sum = f + s;
                if (sum > x) {
                    int delta = sum - x;
                    o += delta;

                    int m = Math.min(delta, s);
                    a[i + 1] = a[i + 1] - m;
                    int rem = delta - m;
                    a[i] = a[i] - rem;
                }
            }
            out.println(o);
        }
    }
}



Measured memory_bytes: 33472
import java.util.*;

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int max1 = 0;
		int max2 = 0;
		int cnt[] = new int[200000+1];
		int a[] = new int[200000];
		for(int i=0; i<n; i++) {
			int v = sc.nextInt();
			if(max1 < v) {
				max2 = max1;
				max1 = v;
			}else if(max2 < v){
				max2 = v;
			}
			a[i]=v;
			cnt[v]++;
		}
		for(int i=0; i<n; i++) {
			int v = a[i];
			if(v==max1 && cnt[v]==1) {
				System.out.println(max2);
			}else {
				System.out.println(max1);
			}
		}
		sc.close();
	}
}


Measured memory_bytes: 74808
#include <iostream>

using namespace std;

int main(void){
	for(int cost; cin >> cost, cost;){
		int result = 0;
		for(int i = 1, in, out; i <= 12; i ++){
			cin >> in >> out;
			cost -= (in - out);
			if(cost <= 0 && !result) result = i;
		}
		if(!result) cout << "NA" << endl;
		else cout << result << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007ll;


static int red[82][82];
static int blue[82][82];

static bool memo[82][82][10000];

int main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	long long h, w;
	cin >> h >> w;
	
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			cin >> red[i][j];
		}
	}
	
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			cin >> blue[i][j];
		}
	}
	int ans = 120343232;
	
	for(int r = 0;r < h;r++){
		for(int c = 0;c < w;c++){
			int d = abs(blue[r][c] - red[r][c]);
			if(r == 0 && c == 0){
				memo[r][c][d] = true;
			}	
			
			
			if(r != 0){
				for(int i = 0;i < 10000;i++){
					if(memo[r-1][c][i]){
						if(i+d < 10000) memo[r][c][i+d] = true;
						if(abs(i-d) < 10000) memo[r][c][abs(i-d)] = true;
					}
				}
			}
			if(c != 0){
				for(int i = 0;i < 10000;i++){
					if(memo[r][c-1][i]){
						if(i+d < 10000) memo[r][c][i+d] = true;
						if(abs(i-d) < 10000) memo[r][c][abs(i-d)] = true;
					}
				}
			}
		}
	}
	for(int i = 0;i < 10000;i++){
		if(memo[h-1][w-1][i]){
			cout << i;
			return 0;
		}
	}
	//cout << ans;
	
	
	
	
}


Measured memory_bytes: 65152
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int[] array = new int[3];
    array[0] = scan.nextInt();
    array[1] = scan.nextInt();
    array[2] = scan.nextInt();
    for (int i = 0; i < 2; i++) {
      for (int j = i + 1; j < 3; j++) {
        if (array[i] > array[j]) {
          int tmp = array[i];
          array[i] = array[j];
          array[j] = tmp;
        }
      }
    }
    for (int i = 0; i < array.length-1; i++){
      System.out.print(array[i] + " ");
    }
    System.out.println(array[array.length-1]);
  }
}



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

using namespace std;

int main()
{
  int W, H, P[100000], Q[100000];

  cin >> W >> H;
  for(int i = 0; i < W; ++i) {
    cin >> P[i];
  }
  for(int i = 0; i < H; ++i) {
    cin >> Q[i];
  }

  int az = W + 1, bz = H + 1;
  vector< int > idx(W + H);
  iota(begin(idx), end(idx), 0);
  sort(begin(idx), end(idx), [&](int a, int b)
  {
    int a1 = a < W ? P[a] : Q[a - W];
    int a2 = b < W ? P[b] : Q[b - W];
    return (a1 < a2);
  });

  long long ret = 0;
  for(int& k : idx) {
    if(k < W) {
      ret += 1LL * P[k] * bz;
      --az;
    } else {
      k -= W;
      ret += 1LL * Q[k] * az;
      --bz;
    }
  }

  cout << ret << endl;
}


Measured memory_bytes: 1792
///not today

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

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair<int, pair<int, int> >

const int maxn = 1000* 100 + 5;
int a[maxn];

int32_t main(){
    int n, c, k, ans = 0;
    cin >>n >>c >>k;
    for(int i = 0; i < n; i ++)
        cin >>a[i];
    sort(a, a + n);
    int pt = 0;
    while(pt < n){
        int mn = a[pt], cn = 1;
        ans ++;
        while(pt + 1 < n and a[pt + 1] - mn <= k and cn < c){
            pt ++;
            cn ++;
        }
        pt ++;
    }
    cout <<ans <<endl;
    return false;
}


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

ll l, r, cnt;

int main()
{
//	freopen("D:\\test\\in.txt", "r+", stdin);
	ios::sync_with_stdio(false);
	cin >> l >> r;
	while (l <= r && l > 0) {
		cnt++;
		l *= 2;
	}
	cout << cnt << endl;
	return 0;
}

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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

vector< vs32 > g;
vector< bool > reached;
vector< vs32 > d;

void dfs(int u, int id)
{
    reached[u] = true;
    for (auto v : g[u])
    {
        if (reached[v]) continue;
        d[id][v] = d[id][u] + 1;
        dfs(v, id);
    }
}

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

    int n;
    cin >> n;
    reached.resize(n);
    g.resize(n);
    d.resize(2, vs32(n, (int)1e9));

    int a, b;
    rep (i, n - 1)
    {
        cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    d[0][0] = d[1][n - 1] = 0;
    rep (i, n) reached[i] = false;
    dfs(0, 0);
    rep (i, n) reached[i] = false;
    dfs(n - 1, 1);

    int black = 0;
    rep (i, n)
    {
        if (d[0][i] <= d[1][i]) ++black;
    }

    string s = "Fennec";
    string t = "Snuke";
    cout << (black * 2 > n ? s : t) << "\n";
    return 0;
}



Measured memory_bytes: 12792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int H,W,h,w;
	cin >> H >> W >> h >> w;
	cout << ((H-h)*(W-w)) << endl;
	return 0;
}


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

namespace CSharpSample01
{


    class Program
    {

        static int cnt = 0;

        static void Selection_Sort(int[] data_ary)
        {
            int length = data_ary.Length;

            for(int ch_in = 0; ch_in < length - 1; ch_in++)
            {
                int min = data_ary[ch_in];
                int min_in = ch_in;
                for(int seek_in = ch_in + 1; seek_in < length; seek_in++)
                {
                    if(min > data_ary[seek_in])
                    {
                        min = data_ary[seek_in];
                        min_in = seek_in;                    
                    }
                }
                if (data_ary[ch_in] != data_ary[min_in]) cnt++;
                int tmp = data_ary[ch_in];
                data_ary[ch_in] = min;
                data_ary[min_in] = tmp;           
            }
            
        }
        

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] data_ary = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            Selection_Sort(data_ary);

            Console.WriteLine(String.Join(" ", data_ary));
            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 18264