akhauriyash/Code-Regression huggingface dataset:
def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    mean_a = sum(a_list) / n
    diff_list = [abs(a - mean_a) for a in a_list]
    min_a = min(diff_list)
    print(diff_list.index(min_a))


if __name__ == "__main__":
    main()


Measured memory_bytes: 61980
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int h = scanner.nextInt();
        int w = scanner.nextInt();
        String[] ans = new String[h];
        for (int i = 0; i < h; i++) {
            ans[i] = "#" + scanner.next() + "#";
        }
        System.out.println(String.valueOf(new char[w + 2]).replace('\0', '#'));
        for (String s : ans) {
            System.out.println(s);
        }
        System.out.println(String.valueOf(new char[w + 2]).replace('\0', '#'));
    }
}

Measured memory_bytes: 21844
// AtCoder Beginner Contest 115 - C.cpp
#include <iostream>
#include <algorithm>
#include <cstdio>
const int maxn = 100200;
using namespace std;
int n, arr[maxn], K;
int main()
{
    scanf("%d%d", &n, &K);
    for (int i = 1; i <= n; i++)
        scanf("%d", &arr[i]);
    sort(arr + 1, arr + 1 + n);
    int min_val = 1e9;
    for (int i = K; i <= n; i++)
        min_val = min(min_val, arr[i] - arr[i - K + 1]);
    printf("%d", min_val);
    return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

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

    const int half = (N+1)/2;
    for(int i = 0; i < K; ++i) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        if(x >= half) {
            x = N-x-1;
        }
        if(y >= half) {
            y = N-y-1;
        }

        int level = min(x, y);
        cout << (level%3)+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 200000009
int n,k;
ll dp[105][100005];
int a[105];
const ll MOD=1e9+7;
inline void Add(ll &x,ll y){
	x+=y;if (x<0) x+=MOD;if (x>MOD) x-=MOD;return;
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for (int i=1;i<=n;++i) cin>>a[i];
	dp[0][0]=1;
	for (int i=1;i<=n;++i){
		for (int j=0;j<=k;++j){
			dp[i][j]=dp[i-1][j];
			if (j) Add(dp[i][j],dp[i][j-1]);
			if (j>a[i]) Add(dp[i][j],-dp[i-1][j-a[i]-1]);
		}
	}
	cout<<dp[n][k]<<endl;
	return 0; 
}

Measured memory_bytes: 79360
import java.util.InputMismatchException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try {
			Scanner scanner = new Scanner(System.in);
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			int c = scanner.nextInt();

			Main testA = new Main();
			System.out.println(testA.transfer(a, b, c));

			scanner.close();

		} catch (InputMismatchException e) {
			// TODO: handle exception
			System.out.println("整数を入力してください");
		}
	}


	public int transfer(int a, int b, int c) {
//		if 容器2の水が全部入る、else 全部入らない
		if (a-b > c) {
			return 0;
		} else {
			return c-(a-b);
		}
	}

}



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

int main() {
    int64_t N, M, K;
    cin >> N >> M >> K;
    vector<int64_t> A(N), B(M);
    for (int64_t& a : A) {
        cin >> a;
    }
    for (int64_t& b : B) {
        cin >> b;
    }

    vector<int64_t> sum_A(N + 1, 0), sum_B(M + 1, 0);
    for (int64_t i = 0; i < N; i++) {
        sum_A[i + 1] = sum_A[i] + A[i];
    }
    for (int64_t i = 0; i < M; i++) {
        sum_B[i + 1] = sum_B[i] + B[i];
    }

    int64_t ans = 0;
    for (int64_t i = 0; i <= N; i++) {
        //Aからi冊読む
        int64_t rem = K - sum_A[i];
        if (rem < 0) {
            break;
        }

        int64_t b_num = upper_bound(sum_B.begin(), sum_B.end(), rem) - sum_B.begin() - 1;

        ans = max(ans, i + b_num);
    }

    cout << ans << endl;
}

Measured memory_bytes: 9596
using System;

namespace AtCoder
{
    public class Program
    {
        public static void Main()
        {
            long i=0,j=0;
            long n;
            long []height;
            string line = Console.ReadLine();
            string []input = line.Split(' ');
            n=long.Parse(input[0]);

            height = new long[n];
            line = Console.ReadLine();
            input = line.Split(' ');
            for(i=0;i<n;i++){
                height[i]=int.Parse(input[i]);
            }
            long []L;
            long []R;
            L = new long[n];
            R = new long[n];
            for(i=0;i<n;i++){
                L[i] = i+height[i];
                R[i] = i-height[i];
            }
            Array.Sort(L);
            Array.Sort(R);
            /*for(i=0;i<n;i++){
                Console.WriteLine(i.ToString() + " " + L[i].ToString()+ " " + R[i].ToString());
            }*/

            long t=0;
            long x;
            long nl=0,nr=0;
            for(i=0;i<n;i++){
                x=L[i];
                nr=0;
                for(;j<n;j++){
                    if(R[j] > x) break;
                    if(R[j] == x){
                        nr=1;
                        for(j++;j<n;j++){
                            if(R[j]==x)
                                nr++;
                            else{
                                j--;break;
                            }
                        }
                    }
                    
                }
                nl=1;
                for(i++;i<n;i++){
                    if(L[i]==x)
                        nl++;
                    else{
                        i--;
                        break;
                    }
                }
                t+=nr*nl;
                //Console.WriteLine(i.ToString() + " " + j.ToString());
            }
            Console.WriteLine(t);
        }
        public static long abs(long a,long b)
        {
            long c = a - b;
            if(c<0) c=-c;
            return c;
        }
    }
}

Measured memory_bytes: 46816
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    int n , m;
    cin >> n;
    vector<int> a(n);
    rep(i ,n) cin >> a[i];
    cin >> m;
    vector<int> b(m);
    rep(i ,m) cin >> b[i];
    vector<int> result;
    set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(result,end(result)));

    for( auto x : result){
        cout << x << endl;
    }
}


Measured memory_bytes: 6536
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

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, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}




int N, M;
string S;

void solve() {
    vector<int> res;
    vector<int> next(N+1, N);
    for (int i = N; i >= 0; --i) {
        if (S[i] == '1') next[i] = next[i+1];
        else next[i] = i;
    }       
    int s = N;
    while (s) {
        int ns = next[max(0, s-M)];
        if (ns == s) {
            cout << -1 << endl;
            return;
        }
        res.push_back(s-ns);
        s = ns;
    }
    reverse(res.begin(), res.end());
    for (auto v : res) cout << v << " ";
    cout  << endl;
}

int main() {
    while (cin >> N >> M >> S) solve();
}


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

int main(){
    int H,W;
    while (1){
        cin >> H >> W ;
        if (H == 0 && W == 0){
            break;
        }
        for (int i = 0; i < H; i++){
            for (int j = 0; j < W; j++){
                cout << "#" ;
            }
            cout << endl;
        }
        cout << endl;
    }
    //cout << endl;
    return 0;
}


Measured memory_bytes: 3100
import sys
from collections import defaultdict

n, m = map(int, input().split())
ac = 0
# 初期化
wa = defaultdict(lambda: 0)
already = set()
for line in sys.stdin:
    p, s = line.strip().split()
    p = int(p)
    # すでに正解していたらスキップ
    if p in already:
        continue
    # 初正解ならAC+1, 失敗回数を追加
    if s == 'AC':
        ac += 1
        already.add(p)
    # 失敗なら失敗回数を増やす
    else:
        wa[p] += 1

print(ac, sum(wa[i] for i in already))


Measured memory_bytes: 22888
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static long result = Long.parseLong(sc.nextLine());
	public static void main(String[] args) {
		calculator();

	}

	private static void calculator() {
		do {
				String op = sc.nextLine();

					if (op.equals("=")) {
						break;
					}

				int num = Integer.parseInt(sc.nextLine());

					switch(op) {
						case "+":
							result += num;
							break;
						case "-":
							result -= num;
							break;
						case "*":
							result *= num;
							break;
						case "/":
							result /= num;
							break;
						default:

						break;
					}

		}while(true);

		System.out.println(result);
	}

}


Measured memory_bytes: 26496
#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 H, W;
	cin >> H >> W;
	char a[100][100];
	rep(i, H) {
		rep(j, W) {
			cin >> a[i][j];
		}
	}
	rep(i, W+2) {
		cout << "#";
	}
	cout << endl;
	rep(i, H) {
		cout << "#";
		rep(j, W) {
			cout << a[i][j];
		}
		cout << "#" << endl;
	}
	rep(i, W+2) {
		cout << "#";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map(String::toInt).sortedBy { it }
    val validation = if (n % 2 == 0) {
        { i: Int -> a[i] == i / 2 * 2 + 1 }
    } else {
        { i: Int -> a[i] == (i + 1) / 2 * 2 }
    }
    if (!(0 until n).all(validation)) {
        println(0)
        return
    }
    val result = (1..n / 2).fold(1L) { acc, cur -> (acc shl 1) % 1000000007L }
    println(result)
}


Measured memory_bytes: 66536
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public int[] A;
        public void Run()
        {
            N = Input.ReadInt();
            A = Input.ReadIntArray();

            int prev = -1;
            int succeed = 1;
            int ret = 0;
            for (int i = 0; i < N; i++)
            {
                int c = A[i];
                if (c == prev)
                {
                    succeed++;
                }
                else
                {
                    ret += succeed / 2;
                    prev = c;
                    succeed = 1;
                }
            }

            ret += succeed / 2;

            Console.WriteLine(ret);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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; }
//end

char c[11][1100];

int main(){
   int h,w; scanf("%d%d",&h,&w);
   int k; scanf("%d",&k);
   rep(i,0,h)rep(j,0,w)cin>>c[i][j];
   int m=1<<(h-1); int res=inf;
   rep(mask,0,m){
      int sub=__builtin_popcount(mask);
      int cnt[11]={}; bool g=1;
      rep(j,0,w){
         int idx=0;
         int add[11]={};
         rep(i,0,h){
            add[idx]+=(c[i][j]=='1');
            if(mask>>i&1)idx++;
         } bool f=1;
         rep(i,0,11){
            if(cnt[i]+add[i]>k){
               sub++; f=0; break;
            }
         }
         if(f)rep(i,0,11)cnt[i]+=add[i];
         else rep(i,0,11)cnt[i]=add[i];
         rep(i,0,11)if(cnt[i]>k)g=0;
      }
      if(g)chmin(res,sub);
   } printf("%d\n",res);
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#define  go return 0
#define pb push_back
#include<utility>
#include <algorithm>
#include<iterator>
typedef long long ll;
typedef double db;
#define lp1(i, n)  for(int i=0; i<(int)(n); ++i)
#define lp2(i, n)  for(int i=0; i<(int)(n-1); ++i)
#define lp3(j, n)  for(int j=1; j<=(int)(n); ++j)
#define all(v)   ((v).begin()), ((v).end())
#define sz(v)    ( (int)((v).size()) )
typedef vector<int> vi;
const int N=1e5+5;
int arr[N];
int main(){

 string s1,s2;
 int count=0;
 cin>>s1;
 s2=s1;
 reverse(all(s2));
 for(int i=0 ; i<s1.size() ; i++)
 {
     if(s1[i]!=s2[i])
        count++;
 }
 cout<<count/2;

go;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll p=988244353ll,pp=p*p,q=2109888ll;
const int N=500005;
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
ll ar[N*3];char s[N*3],t[N];
int vis[N],dp[N],fa[N],cnt;
inline int dfs(int v){
	if(vis[v])return vis[v]==cnt?dp[v]=N:dp[v];
	vis[v]=cnt;
	int u=fa[v];
	if(!u)return 0;
	return dp[v]=dfs(u)+1;
}
int main(){
	int l,n,m,i,z=0;ll at=0ll,b=1ll;
	scanf("%s%s",s+1,t+1);
	l=n=strlen(s+1);
	  m=strlen(t+1);
	while(l<n+m)for(i=1;i<=n;++i)s[++l]=s[i];
//	printf("%s %s\n",s+1,t+1);
	for(i=1;i<=m;++i)b=b*q%p;
	for(i=1;i<=l;++i)ar[i]=(ar[i-1]*q+s[i])%p;
	for(i=1;i<=m;++i)at=(at*q+t[i])%p;
	for(i=0;i< n;++i)if((ar[i+m]-ar[i]*b+pp)%p==at)fa[i+1]=(i+m)%n+1;
//	for(i=1;i<=n;++i)printf("fa %d = %d\n",i,fa[i]);
	for(i=1;i<=n;++i){cnt=i;cmax(z,dfs(i));}
	printf("%d",z>=N?-1:z);
	return 0;
}

Measured memory_bytes: 27520
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

int main() {
    int n;  cin >> n;
    ll *a = new ll[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    ll mod = 1e9+7, *s = new ll[n];

    s[n-1] = a[n-1];
    for (int i = n-1; i > 1; i--) {
        s[i-1] = s[i] + a[i-1];
        s[i-1] %= mod;
    }

    ll ans = 0;
    for (int i = 0; i < n-1; i++) {
        ans += a[i]*s[i+1];
        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6756
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#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>

#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>
//#include <tchar.h>
//#include <intrin.h>

#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 1000000000000000000

using namespace std;

const int N = 4e5 + 10;

unordered_map<string, int>mp;

int main()
{
	LL n;
	scanf("%lld", &n);
	
	mp["AC"] = mp["WA"] = mp["TLE"] = mp["RE"] = 0;

	while (n--) {
		string s;
		cin >> s;
		mp[s]++;
	}
 
		cout << "AC" << " x " << mp["AC"] << endl;
		cout << "WA" << " x " << mp["WA"] << endl;
		cout << "TLE" << " x " << mp["TLE"] << endl;
		cout << "RE" << " x " << mp["RE"] << endl;
	
	cin >> n;
}

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

using namespace std;
const int N = 1e5 + 5;
long long arr[N];

int main() {

//    freopen("in.txt", "r", stdin);
    int n, x;
    scanf("%d%d", &n, &x);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &arr[i]);
    }
    long long tot = 0;
    for(int i = 1; i < n; i++) {
        if(arr[i] + arr[i + 1] > x) {
            long long over = arr[i + 1] + arr[i] - x;
            tot += over;
            arr[i + 1] -= over;
            if(arr[i + 1] < 0) {
                arr[i] += arr[i + 1];
                arr[i + 1] = 0;
            }
        }
    }
    cout << tot;
    return 0;
}


Measured memory_bytes: 1024
//--- pC ---//
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Reader reader;
	PrintWriter out;
	public Solution() {
		reader = new Reader();
		out = new PrintWriter(System.out);
		// int t = reader.ni();
		while (reader.hasNext()) {
			run_case();
		}
		out.flush();
	}

	private void run_case() {
		int n = reader.ni();
		long res = 0;
		for (int i=1; i<=n; i++) {
			for (int j=1; j<=n; j++) {
				for (int k=1; k<=n; k++) {
					res += gcd(k, gcd(i, j));
				}
			}
		}
		System.out.println(res);
		return;
	}

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

class Reader {
	BufferedReader br;
	StringTokenizer st;
	public Reader(){
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public String next() {
		if (st.hasMoreTokens()) return st.nextToken();
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return st.nextToken();
	}
	public boolean hasNext() {
		try {
			if (!st.hasMoreTokens() && !br.ready()) return false;
			else return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	public int ni() {return Integer.parseInt(this.next());}
	public long nl() {return Long.parseLong(this.next());}
	public String ns() {return this.next();}
}


Measured memory_bytes: 32932
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    num = int(input())        
    a_list = list(map(int, input().split()))
    a = sum(a_list)
    b_list = list(map(int, input().split()))

    for i in range(num):
        if a_list[i] >= b_list[i]:
            a_list[i] -= b_list[i]
            b_list[i] = 0
        else:
            b_list[i] -= a_list[i]
            a_list[i] = 0
            if a_list[i+1] >= b_list[i]:
                a_list[i+1] -= b_list[i]
            else:
                a_list[i+1] = 0
        

    print(a - sum(a_list))


if __name__ == "__main__":
    main()

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

using namespace std;
using ll = long long;

int main() {
#ifdef LOCAL
    freopen("in1.txt", "r", stdin);
    freopen("out1.txt", "w", stdout);
#endif

    int n;
    cin >> n;
    vector<int> a;
    vector<int> b;
    for(int i = 0; i < n; ++i){
        int u, v;
        cin >> u >> v;
        a.push_back(u+v);
        b.push_back(u-v);
    }
    cout << max(*max_element(a.begin(), a.end()) - *min_element(a.begin(), a.end()), *max_element(b.begin(), b.end()) - *min_element(b.begin(), b.end())) << endl;
    return 0;
}

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

int main(){
	int i,ans=0;
	string s;
	cin>>s;
	
	for(i=0;i<s.size();i++)
	if(s[i]=='A') ans++;
	
	if(ans==0||ans==3){
		cout<<"No";
	}else{
		cout<<"Yes";
	}
	
	return 0;
} 

Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
anslist = []
N = int(input())
for div in make_divisors(N):
  div2 = N//div
  anslist.append(max(len(str(div)),len(str(div2))))
print(min(anslist))

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

#define int long long

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

	vector<int> x(n), y(n);
	for(int i = 0; i < n; i++)
		cin >> x[i] >> y[i];

	vector<int> add(n);
	for(int i = 0; i < n; i++)
		add[i] = x[i] + y[i];

	int res = 0;
	sort(add.begin(), add.end());
	res = abs(add.front() - add.back());

	vector<int> sub(n);
	for(int i = 0; i < n; i++)
		sub[i] = x[i] - y[i];

	sort(sub.begin(), sub.end());
	res = max(res, abs(sub.front() - sub.back()));

	cout << res << endl;

}

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

	solve();
	return 0;
}


Measured memory_bytes: 9504
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
#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++)
#define _GLIBCXX_DEBUG
int main()
{
    int n,x;
    cin>>n>>x;
    vin l(n);
    rep(i,n)cin>>l[i];
    vin d(n+1);
    d[0]=0;
    int sum=0;
    int i=0;
    while(d[i]<=x&&i<n+1){
        sum++;
        d[i+1]=d[i]+l[i];
        i++;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007

map <int, vector <int> > adj;
vector <int> vis;

void dfs(int sv, int& count){
  vis[sv]=true;
  count++;
  for(auto i:adj[sv]){
     if(!vis[i]) dfs(i,count);
  }
}

int32_t main(){
    int n,m; cin>>n>>m;
    adj.clear();
    vis.clear();
    vis.resize(n+1);
    
    set < pair<int,int> > Set;
    vector <int> v;

    for(int i=0 ; i<m ; i++){
        int u,v; cin>>u>>v;
        if(Set.find({u,v})==Set.end()){
           Set.insert({u,v});
           Set.insert({v,u});
            adj[u].push_back(v);
            adj[v].push_back(u);
        } 
    }

      for(int i=1 ; i<=n ; i++){
         if(!vis[i]){
            int count=0;
            dfs(i,count);
            v.push_back(count);
          }
      }

       int ans=0;
       sort(v.begin(),v.end());

      while(v.size()){
         vector <int> temp;
         for(int i=0 ; i<v.size() ; i++){
            int val = v[i]-v[0];
            if(val) temp.push_back(val);
         }
            ans += v[0];
            v = temp;
      }
         cout<<ans;
}

Measured memory_bytes: 70536
#include<stdio.h>
int main()
{
    int n,i,a=0,t=0,w=0,r=0;
    char c[4];
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%s",c);
        if(c[0]=='A')a++;
        else if(c[0]=='T')t++;
        else if(c[0]=='W')w++;
        else r++;
        
    }
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d",a,w,t,r);
    return 0;
}

Measured memory_bytes: 1728
#include <iostream>
using namespace std;
int main(void){
    int sx,sy,tx,ty ;
    cin >> sx >> sy >> tx >> ty ;
    
    for(int i=0;i<tx-sx;i++){
         cout << 'R' ;
    }
    for(int i=0;i<ty-sy;i++){
         cout << 'U' ;
    }
    for(int i=0;i<tx-sx;i++){
         cout << 'L' ;
    }
    for(int i=0;i<ty-sy;i++){
         cout << 'D' ;
    }
    cout << 'D' ;
    for(int i=0;i<tx-sx+1;i++){
         cout << 'R' ;
    }
    for(int i=0;i<ty-sy+1;i++){
         cout << 'U' ;
    }
    cout << 'L' << 'U' ;
    for(int i=0;i<tx-sx+1;i++){
         cout << 'L' ;
    }
    for(int i=0;i<ty-sy+1;i++){
         cout << 'D' ;
    }
    cout << 'R' ;
    
}


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

int main(){
    stack<int> S;
    int a,b;
    string s;
    
    while(cin >> s){
        if(s[0]=='+'){
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(a+b);
        }else if(s[0]=='-'){
            b = S.top(); S.pop();
            a = S.top(); S.pop();
            S.push(a-b);
        }else if(s[0]=='*'){
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(a*b);
        }else{
            S.push(atoi(s.c_str()));
        }
    }
    
    cout << S.top() << endl;
    
    return 0;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);

  string S, T;
  cin >> S >> T;

  set<ll> s;
  mll m;
  bool ok = true;
  for (ll i = 0; i < S.size(); ++i) {
    ll b = S[i] - 'a' + 1;
    ll a = T[i] - 'a' + 1;

    if (m[b] == 0) {
      m[b] = a;
      if ((s.find(a) != s.end())) {
        ok = false;
        break;
      }
      s.insert(a);
    } else {
      if (m[b] != a) {
        ok = false;
        break;
      }
    }
  }

  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3900
import scala.io.StdIn
import Math.{sqrt,pow}
/**
  * AOJ
  */
object Main {

  def main(args: Array[String]): Unit = {
    while(true){
      val n = StdIn.readInt()
      if(n == 0){return}
      val sArray = StdIn.readLine().split(" ").map(_.toDouble)
      val m:Double = sArray.sum / n
      println("%.8f".format(sqrt(sArray.map(x => pow((x - m),2)).sum / n)))
    }
  }
}

Measured memory_bytes: 45224
using System;
using System.Collections.Generic;
using System.Linq;
 
class Solution
{
    static void Main()
    {
        var n = 50;
        long k = long.Parse(Console.ReadLine());
        var plus = k / n;
        var rem = k % n;
        var a = Enumerable.Repeat(n - 1 + plus, n).ToArray();
        for (int t = 0; t < rem; t++)
        {
            var min = a.Min();
            var minIndex = Array.IndexOf(a, min);
            a[minIndex] += n;
            for (int i = 0; i < n; i++)
            {
                if (i != minIndex)
                {
                    a[i]--;
                }
            }
        }
        Console.WriteLine(n);
        Console.WriteLine(String.Join(" ", a));
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int q;
char x[1010],y[1010];
int dp[1010][1010];
int lcs(char * str1,char* str2){
	for(int i=0;i<=strlen(str1);i++){
		dp[i][0]=0;
	}
	for(int j=0;j<=strlen(str2);j++){
		dp[0][j]=0;
	}
	int temp;
	for(int i=1;i<=strlen(str1);i++){
		for(int j=1;j<=strlen(str2);j++){
			if(str1[i-1]==str2[j-1]){
				dp[i][j]=dp[i-1][j-1]+1;
			}
			else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	return dp[strlen(str1)][strlen(str2)];
}
int main(){
	cin>>q;
	for(int time=0;time<q;time++){
		cin>>x>>y;
		int re=lcs(x,y);
		cout<<re<<endl;
	}
	return 0;
} 



Measured memory_bytes: 7012
#include<iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;
int main()
{
	int K, S = 0;
	cin >> K >> S;

	int count = 0;

	for (int i = 0; i < K+1; i++) {
		for (int j = 0; j < K+1; j++) {
			if (S - i - j <= K && S - i - j >= 0) { count++; }
		}
	}

	cout << count;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100001
#define NIL -1

struct Node{
  int left;
  int right;
  int parent;
};

struct Node Tree[MAX];

void Preorder(int);
void Inorder(int);
void Postorder(int);

int main(){
  int n, i;
  int id,l,r,root;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    Tree[i].parent = NIL;
  }

  for(i = 0 ; i < n ; i++){
    scanf("%d %d %d",&id, &l, &r);
    Tree[id].left = l;
    Tree[id].right = r;
    if(l != NIL) Tree[l].parent = id;
    if(r != NIL) Tree[r].parent = id;
  }

  for(i = 0 ; i < n ; i++) if(Tree[i].parent == NIL) root = i;

  printf("Preorder\n");
  Preorder(root);
  printf("\n");

  printf("Inorder\n");
  Inorder(root);
  printf("\n");

  printf("Postorder\n");
  Postorder(root);
  printf("\n");

  return 0;
}

void Preorder(int x){
  if(x == NIL) return;
  printf(" %d",x);
  Preorder(Tree[x].left);
  Preorder(Tree[x].right);
}

void Inorder(int x){
  if(x == NIL) return;
  Inorder(Tree[x].left);
  printf(" %d",x);
  Inorder(Tree[x].right);
}

void Postorder(int x){
  if(x == NIL) return;
  Postorder(Tree[x].left);
  Postorder(Tree[x].right);
  printf(" %d",x);
}



Measured memory_bytes: 2052
while 1:
 a={};b=1
 n=int(input())
 if n==0:break
 for _ in[0]*n:
  e,p,q=map(int,input().split())
  a.setdefault(e,0);a[e]+=p*q
 for e in a:
  if a[e]>=1e6:print(e);b=0
 if b:print('NA')


Measured memory_bytes: 5792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
#include<deque>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int a, b;
	cin >> a >> b;
	if (a == b) {
		cout << "Draw";
	}
	else if (a == 1 || (b != 1 && a > b)) {
		cout << "Alice";
	}
	else if (b == 1 || (a != 1 && a < b)) {
		cout << "Bob";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll	long long 
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define mod 1000000007
//cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;
int gcd(int a, int b) 
{ 
	if(a>b)
	{
		swap(a,b);
	}
	if (a == 0) 
		return b; 
	return gcd(b % a, a); 
} 
int invertBits(int num) 
{  
    int x = log2(num) + 1; 
    for (int i = 0; i < x; i++)  
       num = (num ^ (1 << i));  
   
    return num; 
} 
///////////////////////////////////////////////////////////////////////////////////////////////////////////
string add(string f,string s)
{
    reverse(f.begin(),f.end());
    reverse(s.begin(),s.end());
    
    int i=0,j=0;
    string t="";
    int carry=0;
    while(i<f.size() && j<s.size())
    {
        int k=(f[i]-'0')+(s[j]-'0')+carry;
        carry=k/10;
        int sum=k%10;
        t+=(sum+'0');
        i++;
        j++;
    }
    while(i<f.size())
    {
        int k=(f[i]-'0')+carry;
        carry=k/10;
        int sum=k%10;
        t+=(sum+'0');
        i++;
    }
    
    while(j<s.size())
    {
        int k=(s[j]-'0')+carry;
        carry=k/10;
        int sum=k%10;
        t+=(sum+'0');
        j++;
    }
    
    if(carry)
    {
        t+=(carry+'0');
    }
    reverse(t.begin(),t.end());
    return t;
}
  int calculate(vector<vector<int> > &t,int row,int col,map<pair<int,int>,int > &m)
    {   
        if(row==t.size()-1)
        {
            return t[row][col];
        }
        
        if(m.find(make_pair(row,col))!=m.end())
        {
              return m[make_pair(row,col)];
        }
        
        int k=min(calculate(t,row+1,col,m),calculate(t,row+1,col+1,m))+t[row][col];
        m[make_pair(row,col)]=k;
        return k;
    }
int main()
{
	int n,k;
	cin>>n>>k;
	int i;
	int b[n+1];
	vector<int> v[n+1];
	for(i=0;i<n-1;i++)
	{
		int s,d;
		cin>>s>>d;
		v[s].pb(d);
		v[d].pb(s);
	} 
	b[1]=k;
	int visited[n+1]={0};
	queue<pair<int,int> > q;
	q.push(mp(1,0));
	visited[1]=1;
	int prev=0,left=0;
	while(!q.empty())
	{
		pair<int,int> a=q.front();
		
		if(prev!=a.second)
		{
			prev=a.second;
			if(prev==1)
			{
				b[a.first]=k-1;
			}
			else
			{
				b[a.first]=k-2;
			}
			left=a.first;
		}
		else
		{
			if(a.first!=1)
			{
				b[a.first]=b[left]-1;
				left=a.first;	
			}
		}
		for(i=0;i<v[a.first].size();i++)
		{	
			if(!visited[v[a.first][i]])
			{
				visited[v[a.first][i]]=1;
				q.push(mp(v[a.first][i],a.first));
			}
		}
		q.pop();
	}
	long long int ans=1;
	for(i=1;i<=n;i++)
	{
		//cout<<b[i]<<" ";
		ans=((ans%mod)*(b[i]%mod))%mod;
	}
	cout<<ans%mod;
	return 0;
}


Measured memory_bytes: 7672
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
int C[4];
void Calc(){
	string S = res();
	for(int i=0;i<4;i++){
		C[i] = S[i] - 'A';
	}
	sort(C,C+4);
	if(C[0] == C[1] && C[1] != C[2] && C[2] == C[3]){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int a, b, c, d;
	int max = 0;
	for (int i = 0; i < 2; ++i) {
		cin >> a >> b >> c >> d;
		int sum = a + b + c + d;
		if (sum > max) max = sum;
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 100000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

/*---------------------------------------------------*/

bool binary_search(int data[],int size,int target){
  int l=0,r=size;
  while(r-l>0){
    int mid=(l+r)/2;
    if(data[mid]==target)return true;
    else if(target<data[mid])r=mid;
    else l=mid+1;
			 
  }
  return false;
}

int main(){
  int n,q,s[100005],t;
  scanf("%d",&n);
  rep(i,n)scanf("%d",&s[i]);
  scanf("%d",&q);
  int ans=0;
  rep(i,q){
    scanf("%d",&t);
    if(binary_search(s,n,t))ans++;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 3540
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()
    DD = ((1,0),(0,1),(-1,0),(0,-1))

    S = NI()

    x = [0] * (S+1)

    x[0] = 1
    for i in range(S+1):
        for j in range(3,S+1):
            if i + j <= S:
                x[i+j] = (x[i+j] + x[i]) % MOD
    print(x[-1])


if __name__ == '__main__':
    main()

Measured memory_bytes: 70324
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int A;
  cin>>A;

  int ans=A+A*A+A*A*A;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    string s,t;
    cin>>s>>t;
    int n=s.size(),m=t.size();
    int ind=-1;
    rep(i,n){
        if(n-i<m) break;
        string now=s.substr(i,m);
        bool f=true;
        rep(j,m){
            if(now[j]=='?') continue;
            if(now[j]!=t[j]){
                f=false;
                break;
            }
        }
        if(f) ind=i;
    }
    if(ind==-1){
        cout<<"UNRESTORABLE"<<endl;
    }else{
        string ans;
        rep(i,n){
            if(ind<=i && i<=ind+m-1){
                ans+=t[i-ind];
                continue;
            }
            if(s[i]=='?') ans+='a';
            else ans+=s[i];
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
// -*- coding: utf-8 -*-
// Last-Updated : <2014/06/20 07:41:43 by samui>

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <bitset>

#define MP(a, b) std::make_pair(a, b)
#define X first
#define Y second
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); ++(i))
#define rer(i,l,n) for(int (i) = l; (i) <= (int)(n); ++(i))
#define reu(i,l,n) for(int (i) = l; (i) < (int)(n); ++(i))
template<typename T,typename U> inline void amin(T &x,U y){ if(y<x) x = y;}
template<typename T,typename U> inline void amax(T &x,U y){ if(x<y) x = y;}
template<typename TYPE,std::size_t SIZE>
std::size_t len(const TYPE (&array)[SIZE]){return SIZE;}

// 幾何ライブ
typedef long double LD;
const LD INF = 1e100;
const LD EPS = 1e-8;
const LD PI = acos(-1);
typedef std::pair<LD,LD> PLD;
typedef std::vector<std::pair<LD,LD>> VPLD2;

class Point{
public:
  LD x,y;
  Point(LD x = 0,LD y = 0): x(x),y(y){ };
  Point operator + (Point p) {return Point(x+p.x,y+p.y);};
  Point operator - (Point p) {return Point(x-p.x,y-p.y);};
  Point operator * (LD a) {return Point(x*a,y*a);};
  Point operator / (LD a) {return Point(x/a,y/a);};
  LD abs(){return std::sqrt(x*x+y*y);};
  Point unit(){LD u = abs();return Point(x,y)/u; };
};
typedef Point Vector2D;
LD dotProduct(const Vector2D a,const Vector2D b){
  return a.x*b.x+a.y*b.y;
}
LD angle(Vector2D a,Vector2D b){
  return acos(dotProduct(a,b)/(a.abs()*b.abs()));
}
LD norm(Vector2D a){return a.x*a.x+a.y*a.y;}
Point Projection(Point a1,Point a2,Point a3){
  // 線分a1-a2上への射影をもとめる。
  LD d = dotProduct(a3-a1,a2-a1)/norm(a2-a1);
  return (a1+(a2-a1)*d);
  
}


int main(int argc, char *argv[])
{
  Vector2D c,d;
  int x0,x1,y0,y1;
  std::cin>>x0>>y0>>x1>>y1;
  c = Vector2D(x1-x0,y1-y0);
  int t;
  int a,b;
  std::cin>>t;
  while(t>0){
    std::cin>>a>>b;
    Vector2D e = Projection(Point(x0,y0),Point(x1,y1),Point(a,b));
    printf("%.10Lf %.10Lf\n",e.x,e.y);
    t--;
  }
  return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

i64 n,l,t;

i64 calc_count(i64 a,i64 b){
    i64 d;
    if(a<b) d=b-a;
    else d=l-a+b;
    if(2*t<d) return 0;
    return 1+(2*t-(d+d%2))/l;
}

void solve(){
    cin >> n >> l >> t;
    vector<i64> x(n),w(n);
    rep(i,0,n) cin >> x[i] >> w[i];
    i64 num=0;
    rep(i,1,n){
        if(w[i]==w[0]) continue;
        i64 a=x[0],b=x[i];
        if(w[i]==1) swap(a,b);
        num=((num+calc_count(a,b)*(w[0]==1?1:-1)%n)%n+n)%n;
    }
    vector<pair<i64,i64>> y(n);
    rep(i,0,n) y[i]=make_pair(((x[i]+t*(w[i]==1?1:-1))%l+l)%l,-w[i]);
    auto tmp=y[0];
    sort(y.begin(),y.end());
    int j=find(y.begin(),y.end(),tmp)-y.begin();
    vector<i64> ans(n);
    rep(i,0,n) ans[(num+i)%n]=y[(i+j)%n].first;
    rep(i,0,n) cout << ans[i] << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> num(4);
    int a, b;
    cin >> a >> b;
    num[a]++, num[b]++;
    for(int i=1;i<=3;i++){
        if(num[i] == 0){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <limits.h>
using namespace std;
 
int main()
{
    int n;
    cin >> n;
    std::vector<long long int> v;
    for(int i=0; i<n; i++){
        long long int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    
    long long int sum = 1000;
    long long int num = 0;
    for(int i=0; i<n-1; i++){
        // 連続で上がる場合もあるので毎回現金化する
        sum += num * v[i];
        num = 0;
        
        if(v[i+1] > v[i]){ // 明日上がるなら
            num = sum / v[i];
            sum = sum % v[i];
        }
        //cout << sum << ":" << num <<  " ( " << v[n-1] << endl;
    }
    if(num > 0) sum += num * v[n-1];  // 
    //cout << sum << ":" << num <<  " ( " << v[n-1] << endl;
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>
#include <vector>
#define ll long long
const int N=1e6+10;
using namespace std;
int n;

int main() {
     cin>>n;
     cout<<n*n*n<<endl;
    return 0;
}

Measured memory_bytes: 256