akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		for(char c: str.toCharArray()){
			if((int)c <= 122 && 97 <= (int)c){
				c -= 32;
			}else if((int)c <=90 && 65 <= (int)c){
				c += 32;
			}
			System.out.print(c);
		}
		call();
	}

	public static void call(){
		System.out.println();
	}
}




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

int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;

    while(A != 0 || C != 0){
        C = C - B;
        if(C <= 0){
            cout << "Yes" <<endl;
            break;
        }
        A = A - D;
        if(A <= 0){
            cout << "No" << endl;
            break;
        }
    }
}

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

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


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

const int MAX_P = 3010;
int a[MAX_P];

ll inv[MAX_P];
ll fact[MAX_P];
ll fact_inv[MAX_P];

ll choose(int n, int r, int MOD) {
  if (n < 0 || r < 0 || n < r) return 0;
  return fact[n] * fact_inv[n-r] % MOD * fact_inv[r] % MOD;
}

int main2() {
  int P = nextInt();
  REP(i, P) a[i] = nextInt();

  const int MOD = P;

  {
    CLR(inv, 0);
    CLR(fact, 0);
    CLR(fact_inv, 0);
    const int SZ = P;
    inv[1] = 1;
    for (int i = 2; i < SZ; i++) inv[i] = inv[(int) (MOD % i)] * (MOD - MOD / i) % MOD;
    fact[0] = 1;
    for (int i = 1; i < SZ; i++) fact[i] = fact[i-1] * i % MOD;
    fact_inv[0] = 1;
    for (int i = 1; i < SZ; i++) fact_inv[i] = fact_inv[i-1] * inv[i] % MOD;
  }

  vector<int> b(P);
  REP(j, P) if (a[j]) {
    vector<int> c(P);

    c[0] += 1;
    int d = 1;
    for (int k = 0; k <= P; k++) {
      c[P-1-k] -= d * choose(P-1, k, P) % MOD;
      d = ((d * -j) % MOD + MOD) % MOD;
    }

    REP(i, P) {
      c[i] = (c[i] % MOD + MOD) % MOD;
      b[i] += c[i];
      b[i] %= MOD;
    }
  }

  REP(i, P) {
    if (i > 0) cout << " ";
    cout << b[i];
  }
  cout << endl;
  return 0;
}

int main() {

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() { 
    long long N;
  cin >> N;
  long long d[N];
  for (int i = 0; i < N;i++){
    cin >> d[i];
  }
  long long sum = 0;
  for (int i = 0; i < N;i++){
    for (int j = i+1; j < N;j++){
      sum += d[i] * d[j];
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
/* ex2_3
   masaaki52	*/
#include <stdio.h>
int main(void){
  int N;
  int A;
  int black;
  scanf("%d",&N);//入力受け取り
  scanf("%d",&A);//入力受け取り
  black = N*N - A;//計算結果をblackに代入
  printf("%d\n",black);//blackを出力
  return 0;
}


Measured memory_bytes: 128
import Foundation

extension String {
    subscript(i: Int) -> Character {
        self[index(startIndex, offsetBy: i)]
    }
}

func inputInt() -> Int {
    Int(readLine()!)!
}

func inputDouble() -> Double {
    Double(readLine()!)!
}

func inputArray() -> [String] {
    readLine()!.components(separatedBy: " ")
}

func inputIntArray() -> [Int] {
    inputArray().map({ Int($0)! })
}

func inputDoubleArray() -> [Float80] {
    inputArray().map({ Float80($0)! })
}

let i = inputDoubleArray()
let a = i[0]
let b = i[1]
print(Int(a * b))



Measured memory_bytes: 14320
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int a = sc.nextInt();
        // // スペース区切りの整数の入力
        // int b = sc.nextInt();
        // int c = sc.nextInt();
        // 文字列の入力
        // String s = sc.next();
        // 出力
        String ans = "hon";
        int dig = a % 10;
        if (dig == 3) {
            ans = "bon";
        } else if (dig == 0 || dig == 1 || dig == 6 || dig == 8) {
            ans = "pon";
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 35792
#include <iostream>

using namespace std;
using ll = long long;

int main()
{
    int n; cin >> n;
    ll ans = 0L;

    for (int i = 1; i <= n; ++i) {
        if (i % 3 == 0) continue;
        if (i % 5 == 0) continue;
        ans += i;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
int main(){
 
  int n;
  cin >> n;
  int v[n],c[n];
  for(int i=0; i<n; i++) cin>>v[i];
  for(int i=0; i<n; i++) cin>>c[i];
  int sum=0;
  for(int i=0; i<n; i++){
   if(v[i]-c[i]>0) sum+=(v[i]-c[i]);
  }
 
  cout << sum << endl;
}

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

int main() {
	int a, n, min, max;
	cin >> n;
	cin >> a;
	min = a;
	cin >> a;
	max = a - min;
	if (min > a)
		min = a;	
	for (int i = 0; i < n - 2; i++) {
		cin >> a;
		if (max < (a - min))
			max = a-min;
		if (min > a)
			min = a;
	}		
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 3100
//         Jai Saraswati Maa       Om Namah Shivaay        Jai Bhawani
// You have to work hard and keep coding till you get correct output never quit! :-)
// May the force be with you
// Ganpatai Bappa Morya! Mangal Murti Morya!
#include<bits/stdc++.h>
#define sc(x) scanf("%d",&x);
#define scc(x,y) scanf(" %d %d",&x,&y);
#define sccc(x,y,z) scanf("%d %d %d",&x,&y,&z);
#define sl(x) scanf("%lld",&x);
#define sll(x,y) scanf("%lld %lld",&x,&y);
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z);
#define pf(x) printf("%d",x);
#define pfn(x) printf("%d\n",x);
#define pl(x) printf("%lld",x);
#define pln(x) printf("%lld\n",x);
#define st(s) scanf("%s",s);
using namespace std;
int main()
{
    int a,b,i,j;
    scc(a,b)
    for(i=min(a,b);i<=max(a,b);i++)
    {
        if((a*b*i)%2!=0)
        {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define nl ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()

using namespace std;

int main() {
    nl // youtu.be/QosiU0JR_h8  
    int n, k; vector<int> p;
    cin >> n >> k;
    for(int i=0; i<n; ++i) {
        int x; cin >> x;
        p.push_back(x);
    }
    sort(all(p));
    int sum = 0;
    for(int i=0; i<k; ++i) sum += p[i];
    cout << sum;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
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; }

int n;
vector<long long> a(200200, 0);
long long dp[200200][2];
long long odddp[200200][2][2];

long long dpcheck(int limit) {
    dp[1][0] = a.at(0); dp[1][1] = a.at(1);
    for(int i = 1; i < limit; ++ i) {
        for(int j = 0; j < 2; ++j) {
            if(j == 0) chmax(dp[i+1][0], dp[i][j]+a.at(2*i));
            chmax(dp[i+1][1], dp[i][j]+a.at(2*i+1));
        }
    }
    return max(dp[limit][0], dp[limit][1]);
}

int main() {
    cin >> n;
    for(int i = 0; i < n; ++i) cin >> a.at(i);
    for(int i = 0; i <= n; ++i) {
        dp[i][0] = -1e18;
        dp[i][1] = -1e18;
        odddp[i][0][0] = odddp[i][0][1] = odddp[i][1][0] = odddp[i][1][1] = -1e18;
    }

    int nlimit = n/2;
    if(n % 2 == 0) {
        cout << dpcheck(nlimit) << endl;
    }else {
        // 奇数かつ最後の要素を使うパターン
        odddp[1][0][0] = a.at(n-1)+a.at(0); odddp[1][1][0] = a.at(n-1)+a.at(1);
        odddp[1][0][1] = a.at(n-1);
        for(int i = 1; i < nlimit; ++i) {
            for(int j = 0; j < 2; ++j) {
                for(int k = 0; k < 2; ++k) {
                    if(k == 0) chmax(odddp[i+1][0][1], odddp[i][j][k]);
                    if(j == 0) chmax(odddp[i+1][0][k], odddp[i][j][k]+a.at(2*i));
                    if(i != nlimit-1) chmax(odddp[i+1][1][k], odddp[i][j][k]+a.at(2*i+1));
                }
            }
        }
        cout << max({dpcheck(nlimit), odddp[nlimit][0][1], odddp[nlimit][1][1]}) << endl;
    }
}

Measured memory_bytes: 14304
#include <cstdio>
#include <vector>
#include <algorithm>

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

using namespace std;

int main(){
	for(int n;scanf("%d",&n),n;){
		static int a[40000],b[40000];
		rep(i,n) scanf("%d",a+i);
		rep(i,n) scanf("%d",b+i);

		sort(a,a+n);
		sort(b,b+n);

		int ans=-1,pos=n;
		vector<int> match;
		for(int i=n-1;i>=0;i--){
			if(pos>=0){
				pos=upper_bound(a,a+pos,b[i])-a-1;
			}
			match.push_back(pos);

			// binary search
			int lo=0,hi=match.size();
			while(lo<hi){
				int mi=(lo+hi)/2;
				if(match[mi]<i) hi=mi;
				else            lo=mi+1;
			}
			int m=n-i; // tatakau kaisuu
			int win=m-lo; // katsu kaisuu (lo: make or hikiwake kaisuu)
			if(win>m/2.0){ ans=m; break; }
		}

		if(ans==-1 || ans==n) puts("NA"); else printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 1756
BIG = 10**9+7

N,M = map(int,input().split())
a = []
for i in range(M):
    a.append(int(input()))


dp = [0 for i in range(N+1)]
for item in a:
    dp[item]=-1
dp[0]=1
if 1 in a:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2,N+1):
    if dp[i]!= -1:
        dp[i] = dp[i-1]+dp[i-2]
        dp[i] = dp[i]%BIG
    else:
        dp[i]=0

print(dp[-1])

Measured memory_bytes: 7856
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int [] a = new int [10];
			int h = 0;
			int b = 0;
			
			for(int i=1;i<=4;i++) {
				a[sc.nextInt()]=i;
			}
			for(int i=1;i<=4;i++) {
				int c = sc.nextInt();
				if(i==a[c])h++;
				else if(a[c]>0)b++;
			}
			System.out.println(h+" "+b);
		}
	}
}



Measured memory_bytes: 25904
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};

int main(){
  string S;
  cin>>S;
  ll N=S.size(),l=0,r=0;
  vector<ll> ans(N,0);
  for(ll i=0;i<N;i++){
    if(S[i]=='R'){
      r++;
      if(S[i+1]=='L'){
        ans[i]+=r-r/2;
        ans[i+1]+=r/2;
        r=0;
      }
    }
  }
  for(ll i=N;i>=0;i--){
    if(S[i]=='L'){
      l++;
      if(S[i-1]=='R'){
        ans[i]+=l-l/2;
        ans[i-1]+=l/2;
        l=0;
      }
    }
  }
  
  for(ll i=0;i<N;i++){
    cout<<ans[i];
    if(i!=N-1) cout<<" ";
  }
  cout<<endl;
}


Measured memory_bytes: 1408
def getinputdata():

    array_result = []    
    array_result.append(input().split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n= int(arr_data[0][0])

print(n if n% 2==0 else n*2)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(a-c) <= d) cout << "Yes";
  else if (abs(a-b) <= d && abs(b-c) <= d) cout << "Yes";
  else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
namespace ZDY{
	#pragma GCC optimize(3)
	#define il __inline__ __attribute__ ((always_inline))
	#define rg register
	#define ll long long
	#define ull unsigned long long
	#define db double
	#define sht short
	#define MB template <class T>il
	#define Fur(i,x,y) for(int i=x;i<=y;i++)
	#define Fdr(i,x,y) for(int i=x;i>=y;i--)
	#define fl(i,x) for(int i=head[x],to;to=e[i].to,i;i=e[i].nxt)
	#define clr(x,y) memset(x,y,sizeof(x))
	#define cpy(x,y) memcpy(x,y,sizeof(x))
	#define fin(s) freopen(s".in","r",stdin)
	#define fout(s) freopen(s".out","w",stdout)
	#define fcin ios::sync_with_stdio(false)
	#define l2(n) (int(log2(n)))
	#define inf 0x3f3f3f3f
	MB T ABS(T x){return x>0?x:-x;}
	MB T MAX(T x,T y){return x>y?x:y;}
	MB T MIN(T x,T y){return x<y?x:y;}
	MB T GCD(T x,T y){return y?GCD(y,x%y):x;}
	MB void SWAP(T &x,T &y){T t=x;x=y;y=t;}
}using namespace ZDY;using namespace std;
namespace IO{const char* ln="\n";const int str=1<<20;struct IN{char buf[str],*s,*t;bool _;IN():s(buf),t(buf),_(0){}il char gc(){return s==t&&((t=(s=buf)+fread(buf,1,str,stdin))==s)?EOF:(*s++);}IN&operator>>(char&ch){if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)_=1;else ch=c;return *this;}IN& operator>>(char* ch){if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)return _=1,*this;*ch=c;ch++;while((c=gc())!=EOF&&!isspace(c))*ch=c,ch++;if(c==EOF)_=1;return *this;}IN& operator>>(string& ch){if(_)return *this;char c;while((c=gc())!=EOF&&isspace(c));if(c==EOF)return _=1,*this;ch+=c;while((c=gc())!=EOF&&!isspace(c))ch+=c;if(c==EOF)_=1;return *this;}template<typename T>IN&operator>>(T&x){if(_)return *this;char c=gc();bool ff=0;while(c!=EOF&&(c<'0'||c>'9'))ff^=(c=='-'),c=gc();if(c==EOF){_=1;return *this;}x=0;while(c!=EOF&&'0'<=c&&c<='9')x=(x<<3)+(x<<1)+c-48,c=gc();if(c==EOF)_=1;if(ff)x=-x;return *this;}}in;struct OUT{char buf[str],*s,*t;OUT():s(buf),t(buf+str){}~OUT(){fwrite(buf,1,s-buf,stdout);}void pt(char c){(s==t)?(fwrite(s=buf,1,str,stdout),*s++=c):(*s++=c);}OUT&operator<<(const char*s){while(*s)pt(*s++);return *this;}OUT&operator<<(char*s){while(*s)pt(*s++);return *this;}OUT&operator<<(string s){for(int i=0;s[i];i++)pt(s[i]);return *this;}template<typename T>OUT&operator<<(T x){if(!x)return pt('0'),*this;if(x<0)pt('-'),x=-x;char a[30],t=0;while(x)a[t++]=x%10,x/=10;while(t--)pt(a[t]+'0');return *this;}}out;}using namespace IO;
#define N 10000011
#define int ll
int n,ans=0;
map<ll,int>b;
signed main(){
	in>>n;
	char s[10];
	int a[26];
	Fur(i,1,n){
		clr(a,0);
		in>>s;
		Fur(j,0,strlen(s)-1)a[s[j]-'a']++;
		ll x=0;
		Fur(j,0,25)x=x*10+a[j];
		int t=b[x];b[x]++;
		ans+=t;
	}
	out<<ans<<ln;
}

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

using namespace std;

long long inf=1000000007;

int main(){
	int n;
	cin>>n;
	vector<int> p(n);
	for(int i=0;i<n;i++){
		cin>>p.at(i);
		if(p.at(i)==i+1) p.at(i)=1;
		else p.at(i)=0;
	}

	int cnt=0;

	for(int i=0;i<n;i++){
		if(p.at(i)){
			p.at(i)=0;
			cnt++;

			if(i<n-1 && p.at(i+1)) p.at(i+1)=0;
		}
	}

	cout<<cnt<<endl;

	return 0;
}


Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split())) #料理の順番
B = list(map(int, input().split())) #料理の満足度
C = list(map(int, input().split())) #追加の満足度

ans = sum(B)

for i in range(N-1):
  if A[i] + 1 == A[i+1]:
    ans = ans + C[A[i]-1]
    
print(ans)

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

int main() {
	long n;
  	cin >> n;
  
	for (long l=1; l<=n; l++) {
      long cnt=0;
      for(long i=1; i<=100; i++) {
        long ii=i*i;
  	    for(long j=1; j<=100; j++) {
          long jj=j*j;
          long ij=i*j;
          if (jj>n || ij>n) continue;
  	      for(long k=1; k<=100; k++) {
            long kk=k*k;
            if (kk>n) break;
            long calc=(ii + jj + kk + ij + j*k + k*i);
            if (calc == l) {
              cnt++;
            } else if (calc > l) break;
          }
        }
      }
      cout << cnt << endl;
    }  
  	return 0;
}

Measured memory_bytes: 3580
import java.util.Scanner;

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 a[] = new int[n];
		for(int i=0; i<n; i++) {
			a[i]=sc.nextInt();
		}
		int cnt=0;
		for(int i=0; i<n-1; i++) {
			if(a[i] == i+1) {
				int tmp = a[i+1];
				a[i+1]=a[i];
				a[i]=tmp;
				cnt++;
			}
		}
		if(a[n-1]==n) {
			cnt++;
		}
		System.out.println(cnt);
		sc.close();
	}

}


Measured memory_bytes: 48976
n,k=map(int,input().split())
*L,=map(int,input().split())

ans=float('inf')
for i in range(n-(k-1)):
      ans=min(ans,min(abs(L[i+(k-1)]),abs(L[i]))+abs(L[i+(k-1)]-L[i]))

print(ans)

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

#define ran 101101

int n, k;
char s[ran], ch[ran];
int v[ran];

int main() {
	scanf("%d%d", &n, &k);
	scanf("%s", s);
	
	int cnt = 0, it = 0;
	for(int i=0;i<=n;i++) {
		if (i==0 || s[i]==s[i-1]) cnt++;
		else {
			v[it] = cnt;
			ch[it] = s[i-1];
			//printf("%d %c\n", v[it], ch[it]);
			it++;
			cnt = 1;
		}
	}
	
	int l = 0, rem = k;
	int ans = 0, cur = 0;
	for(int i=0;i<it;i++) {
		cur += v[i];
		if(ch[i]=='0') rem--;
		while(rem<0) {
			cur -= v[l];
			if(ch[l]=='0') rem++;
			l++;
		}
		ans = max(ans, cur);
	}
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<long long> A(N);
	for (auto& x : A) {
		cin >> x;
	}
	sort(A.rbegin(), A.rend());

	long long ans = 0;
	priority_queue<long long> q;
	q.push(A[0]);
	for (int i = 1; i < N; ++i) {
		ans += q.top();
		q.pop();
		q.push(A[i]);
		q.push(A[i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 6860
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	listA := make([]int, n)
	listB := make([]int, n)
	listC := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&listA[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&listB[i])
	}
	for i := 0; i < n-1; i++ {
		fmt.Scan(&listC[i])
	}

	manzoku := 0
	for i := 0; i < n; i++ {
		manzoku += listB[listA[i]-1]
		if i > 0 && listA[i] == listA[i-1]+1 {
			manzoku += listC[listA[i-1]-1]
		}
	}
	fmt.Println(manzoku)
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <stdio.h>
#include <cstdlib>
#include <numeric>
using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    int x[m],y[m-1];
    for(int i=0;i<m;i++){
        cin >> x[i];
    }
    if(n>=m){
        cout << 0;
        return 0;
    }
    sort(x,x+m);
    for(int j=0;j<m-1;j++){
        y[j]=x[j+1]-x[j];
    }
    sort(y,y+(m-1));
    cout << accumulate(y,y+(m-1)-(n-1),0);
}

Measured memory_bytes: 1024
n,c = map(int,input().split())
data = []
for i in range(n):
    x,v = map(int,input().split())
    data.append([x,c-x,v])

value_right = [data[0][2]]
for x,y,z in data[1:]:
    value_right.append(value_right[-1]+z)

value_left = [data[n-1][2]]
for x,y,z in data[::-1][1:]:
    value_left.append(value_left[-1]+z)
value_left = value_left[::-1]

opt_right = []
now_opt = 0
for i in range(n):
    next_opt = max(now_opt,value_right[i]-data[i][0])
    opt_right.append(next_opt)
    now_opt = next_opt

#print(opt_right)
opt_left = []
now_opt = 0
for i in range(n-1,-1,-1):
    next_opt = max(now_opt,value_left[i]-data[i][1])
    opt_left.append(next_opt)
    now_opt = next_opt

#print(opt_left)

ans = 0
for turn in range(n):
    now = -data[turn][0] + value_right[turn]
    #print(now)
    ans = max(ans,now)
    now -= data[turn][0]
    if turn < n-1:
        #print(now + opt_left[n-2-turn])
        ans = max(ans,now + opt_left[n-2-turn])

for turn in range(n-1,-1,-1):
    now = -data[turn][1] + value_left[turn]
    #print(now)
    ans = max(ans,now)
    now -= data[turn][1]
    if turn > 0:
        #print(now + opt_right[turn-1])
        ans = max(ans,now + opt_right[turn-1])

print(ans)

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    string s;
    cin >> s;
    ll ans = 0;
    rep(i,s.size()){
        ans += s.at(i) - '0';
    }
    if(ans%9) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3708
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
using namespace std;

int main() {

	string S;
	cin >> S;

	string dstr = S.substr(0, 1);
	string str = dstr;
	vector<string> vs;
	if (S.length() == 1) {
		vs.push_back(str);
	}

	for (int i = 1; i < S.length(); i++) {
		while (i < S.length() && dstr == S.substr(i, 1)) {
			str += dstr;
			i++;
		}
		vs.push_back(str);
		if (i < S.length()){
			dstr = S.substr(i, 1);
			str = dstr;
		}
		if (i == S.length() - 1) {
			vs.push_back(str);
		}
	}

	vector<long long> a(S.length() + 1, -1);
	int ind = 0;
	a[ind] = 0;

	for (int i = 0; i < vs.size(); i++) {
		if (vs[i][0] == '<') {
			for (int j = 0; j <= vs[i].length(); j++) {
				a[ind + j] = j;
			}
		}
		else {
			for (int j = 0; j <= vs[i].length(); j++) {
				a[ind + j] = max(a[ind + j], (long long)vs[i].length() - (long long)j);
			}
		}
		ind += vs[i].length();
	}

	long long ans = 0;
	for (int i = 0; i < a.size(); i++) {
		ans += a[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 15232
#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;

unordered_map<string, int> table;

int main() {
  string word, frequent, longest;
  size_t N = 0; // size_t represents size in bytes of word (length)
  while (cin >> word) {
    table[word] += 1;
    if (table[word] > N) {
      N = table[word];
      frequent = word;
    }
    if (word.size() > longest.size()) longest = word;
  }
  cout << frequent << " " << longest << endl;
}

Measured memory_bytes: 1208
import java.util.Arrays;
import java.util.Scanner;

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();
		long a[] = new long[n];
		long b[] = new long[n];
		long c[] = new long[n];

		for(int j=0; j<n; j++) {
			a[j]=sc.nextLong();
		}
		for(int j=0; j<n; j++) {
			b[j]=sc.nextLong();
		}
		for(int j=0; j<n; j++) {
			c[j]=sc.nextLong();
		}

		Arrays.sort(a);
		Arrays.sort(b);
		Arrays.sort(c);

		long bc[] = new long[n+1];
		int j=0;
		for(int i=0; i<n; i++) {
			while(j<n && b[i]>=c[j]) {
				j++;
			}
			bc[i+1]=bc[i] + n-j;
		}
		j=0;
		long cnt=0;
		for(int i=0; i<n; i++) {
			while(j<n && a[i]>=b[j]) {
				j++;
			}
			cnt += bc[n] - bc[j];
		}
		System.out.println(cnt);
		sc.close();
	}

}


Measured memory_bytes: 98628
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

double dp[310][310][310];
ll N;

double dfs(ll x, ll y, ll z){
    if(dp[x][y][z] >= 0.0) return dp[x][y][z];
    if(x == 0 && y == 0 && z == 0) return dp[0][0][0] = 0.0;
    
    
    double res = 0.0;
    if(x > 0) res += (double)x / N * dfs(x-1, y+1, z);
    if(y > 0) res += (double)y / N * dfs(x, y-1, z+1);
    if(z > 0) res += (double)z / N * dfs(x, y, z-1);
    res += 1.0;
    res *= (double) N / (x+y+z);
    return dp[x][y][z] = res;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    ll x = 0, y = 0, z = 0;
    REP(i, N){
        ll a; cin >> a;
        if(a == 3) x++;
        else if(a == 2) y++;
        else z++;
    }
    REP(i, 310) REP(j, 310) REP(k, 310) dp[i][j][k] = -1.0;
    cout << fixed << setprecision(20) << dfs(x, y, z) << endstr;
    return 0;
}


Measured memory_bytes: 233596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  ll a[n];
  rep(i,n) cin >> a[i];
  bool ok=true;
  
  ll sum=0;
  ll d[n];
  d[0]=a[0]-a[n-1];
  ll k;
  rep(i,n) sum+=a[i];
  k=sum*2LL/n/(n+1);
  //  cout << sum << endl;
  if(k*n*(n+1)/2LL!=sum){
    ok=false;
  }
  rep1(i,n-1) d[i]= a[i]-a[i-1];

  ll ans_s=0;
  rep(i,n){
    if((k-d[i])%n!=0) ok=false;
    if(k<d[i]) ok=false;
    ans_s += k-d[i];
  }
  //  cout << "k " << k << " ans_s " << ans_s << " " << ok <<endl;
  if(ans_s!=n*k) ok = false;
  if(ok) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  
  return 0;
    

}


Measured memory_bytes: 1792
//#define _GRIBCXX_DEBUG
#include <bits/stdc++.h>
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int solve(int n, int a, int b, int c, int x, vector<int> &y, vector<int> &z) {
  int head = 0;
  rep (t, 10000+1) {
    if (y[head] == z[t]) head++;
    if (head == n) return t;
  }
  return -1;
}

int main() {
  int n, a, b, c, x;
  vector<int> z(10000);
  vector<int> y;

  while(cin >> n >> a >> b >> c >> x, n) {
    y.resize(n);
    rep (i, n) cin >> y[i];

    z[0] = x;
    for (int i=1; i<=10000; i++) z[i] = (a*z[i-1] + b) % c;

    cout << solve(n, a, b, c, x, y, z) << endl;
  }
  return 0;
}

Measured memory_bytes: 3124
#include <iostream>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++) 

int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
string dd = "ENWS";
int main(){
	int H,W;
	while(cin >> W >> H && W){
		char c[31][31]={},C[31][31]={};
		for(int i = 0 ; i < H ; i++)
			for(int j = 0 ; j < W ; j++)
				cin >> c[i][j];
		int sec = 0 , ok = 0;
		while(sec <= 180){
			int endok = 1;
			rep(i,H)rep(j,W) if(c[i][j] == 'E' || c[i][j] == 'S' || c[i][j] == 'W' || c[i][j] == 'N') endok = 0;
			if(endok){
				cout << sec << endl;
				ok = true;
				break;
			}
			pair<int,int> next[31][31];
			int done[31][31] = {};
			
			rep(i,31)rep(j,31) next[i][j] = make_pair(-1,-1);
			rep(i,H)rep(j,W) C[i][j] = c[i][j];
			rep(i,31)rep(j,31) if(C[i][j] == 'E' || C[i][j] == 'S' || C[i][j] == 'W' || C[i][j] == 'N') C[i][j] = '.';
			
			rep(i,H)rep(j,W) {
				if(c[i][j] == 'E' || c[i][j] == 'S' || c[i][j] == 'W' || c[i][j] == 'N'){
					int b = (dd.find(c[i][j]) + 3)%4;
					int f = 1;
					rep(d,4){
						int nx = j + dx[(b+d)%4];
						int ny = i + dy[(b+d)%4];
						if(c[ny][nx] == '.' || c[ny][nx] == 'X'){
							next[i][j]= make_pair(nx,ny);
							f = 0;
							break;
						}
					}
					if( f) C[i][j] = c[i][j];
				}
			}
			rep(i,H)rep(j,W) {
				if( c[i][j] == '.' || c[i][j] == 'X'){
					rep(d,4){
						int nx = j + dx[d];
						int ny = i + dy[d];
						if( (c[ny][nx] == 'E' || c[ny][nx] == 'S' || c[ny][nx] == 'W' || c[ny][nx] == 'N') && next[ny][nx] == make_pair(j,i)){
							if(done[i][j]){
								C[ny][nx] = dd[(d + 2)%4]; 
							}else{
								if( c[i][j] == '.' ) {
									//if( sec < 10 ) cout << c[ny][nx] << " " << endl;
									C[i][j] = dd[(d + 2)%4]; 
									done[i][j] = true;
								}else{
									done[i][j] = true;
								}
							}
						}
					}
				}
			}
			//if(sec < 10){ rep(i,H) cout << C[i] << endl;cout << endl;}
			rep(i,H)rep(j,W) c[i][j] = C[i][j];
			sec++;
		}
		if(!ok) cout << "NA" << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

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

    for(ll w=1;w<=3500;w++){
        for(ll n=1;n<=3500;n++){
            ll divisor = 4 * w * n - N * (w + n);
            if(divisor > 0 && (N * n * w) % divisor == 0){
                cout << (N * n * w) / divisor << " " << n << " " << w << endl;
                return 0;
            }
        }
    }

    return 0;
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;

	auto f = [](int x) {
		int ret = 0;
		while (x) {
			x /= 10;
			ret++;
		}
		return ret % 2;
	};

	int ans = 0;
	rep(i, 1, N + 1) {
		ans += f(i);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <string> 
#include <sstream>  
#include <vector> 
#include <time.h>
#include <algorithm>
#include <list>
#include <fstream>
#include <math.h>
using namespace std;
void setZERO(int n[]){
	for(int i = 0;i <= 1000;i++){
		n[i] = 0;
	}
}
int getMax(int S[],int size){
	int max = 0,ans;
	for(int i = 0;i < size;i++){
		if(max < S[i]){
			max = S[i];
			//cout << i << " " << S[i] << endl;
			ans = i;
		}
	}	
	return ans;
}
int main(void){
	while(true){
		int n,m;
		cin >> n >> m;
		if(n == 0 and m == 0)break;
		int score[1000],a;
		setZERO(score);
		for(int i = 0;i < n;i++){
			for(int j = 0;j < m;j++){
				cin >> a;
				score[j] += a == 1 ? 1 : 0;
			}
		}
		int ans;
		for(int i = 0;i < m;i++){
			ans = getMax(score,m);
			score[ans] = -1;
			if(i + 1 == m){
				cout << ans + 1 << endl;
			}else{
				cout << ans + 1 << " ";
			}
		}
	}
}

Measured memory_bytes: 1160
def isPrime(n):    
    for i in range(2,int(n**(1/2))+2):
        if n%i==0:
            return False
    return True

N=int(input())

l=[]

for i in range(2,55556):
    if len(l)>=N:
        break
    if isPrime(i) and i%5==1:
        l.append(i)

print(*l)

Measured memory_bytes: 3060
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)

#define MP       make_pair
#define PB       push_back
#define ALL(x)   (x).begin(),(x).end()

const int INF = 1<<29;
const double EPS = 1e-9;
double zero(double d){
  return d < EPS ? 0.0 : d;
}

typedef long long LL;
typedef pair<string,string> P;


vector<P> graph; 
set<string> delay;
set<string> delay2;

int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(7);

  int targetNum=0;
  int W,N;    
  while(cin >> W, W){
    targetNum++;
    cin >> N;

    int v[N], w[N];
    REP(i,N){
      int co,we;
      char b;
      cin >> co >> b >> we;
      v[i] = co;
      w[i] = we;
    }

    int dp[N+1][W+1];
    memset(dp,0,sizeof(dp));

    REP(i,N){
      REP(j,W+1){
	if( j - w[i] < 0 )
	  dp[i+1][j] = dp[i][j];
	else{
	  dp[i+1][j] = max( dp[i][j], dp[i][j-w[i]] + v[i] );
	}
      }
    }

    cout << "Case " << targetNum << ":" << endl;

    int rj=0;
    REP(j,W+1){
      if( dp[N][rj] < dp[N][j] ){
	rj = j;
      }
    }


    cout << dp[N][rj] << endl << rj << endl;
  }

  return 0;
}

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

#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int compare(int h, int w, int x, int y) {
    return (h*h+w*w) == (x*x+y*y) ? h-x : (h*h+w*w) - (x*x+y*y);
}

int main() {
    int h, w, d;
    while (cin >> h >> w) {
        if (h==0) break;
        int ans_h = 150, ans_w = 150;
        for (int i=1; i < 150; i++) {
            for (int j=i+1; j < 150; j++) {
                if (compare(h,w,i,j) < 0 && compare(ans_h,ans_w,i,j) > 0) {
                    ans_h = i;
                    ans_w = j;
                }
            }
        }
        cout << ans_h << ' ' << ans_w << endl;
    }

}

Measured memory_bytes: 3016
def main():
    A, B, C = map(int, input().split())
    l = [A, B, C]
    l.sort()
    if l[0] == l[1]:
        print(l[2])
    elif l[0] == l[2]:
        print(l[1])
    else:
        print(l[0])
main()

Measured memory_bytes: 9176
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    if (n % 10 == 0)
    {
        cout << 10 << "\n";
    }
    else
    {
        int ans = 0;
        while (n)
        {
            ans+=n%10;
            n/=10;
        }
        cout<<ans<<"\n";
    }
}


Measured memory_bytes: 256
MAX = 1000001
isPrime = [True] * MAX
isPrime[0] = isPrime[1] = False
for i in range(2, 1000):
  if isPrime[i]:
    for j in range(i ** 2, MAX, i):
      isPrime[j] = False

def solve(a, d, n):
  if isPrime[a]:
    n -= 1
  while n:
    a += d
    if isPrime[a]:
      n -= 1
  return a

def main():
  while True:
    a, d, n = map(int, input().split())
    if a == 0:
      break
    print(solve(a, d, n))

main()


Measured memory_bytes: 13376
#include"bits/stdc++.h"
using namespace std;
int main(){
	int N, M, C;
	cin >> N >> M >> C;
	vector<int> x;
	for(int i = 0; i != M; ++i){
		int z;
		cin >> z;
		x.push_back(z);
	}
	int ans = 0;
	for(int i = 0; i != N; ++i){
		int cur = C;
		for(int j = 0; j != M; ++j){
			int s;
			cin >> s;
			cur += s * x[j];
		}
		if(cur > 0)
			++ans;
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <iostream>                                                                     
#include <bits/stdc++.h>                                                                
                                                                                        
using namespace std;                                                                    
                                                                                        
int main (void) {                                                                       
  while (true) {                                                                        
    int n, x;                                                                           
    fscanf(stdin, "%d %d", &n, &x);                                                     
    if (n==0 && x==0) {                                                                 
      break;                                                                            
    }                                                                                   
    int ans = 0;                                                                        
    for (int i=1; i<=n; i++) {                                                          
      for (int j=i+1; j<=n; j++) {                                                      
        int k = x-i-j;                                                                  
        if (k>i && k>j && k<=n) {                                                       
          ans++;                                                                        
        }                                                                               
      }                                                                                 
    }                                                                                   
    fprintf(stdout, "%d\n", ans);                                                       
  }                                                                                     
}                                                                                       
                                                                                        
                                                

Measured memory_bytes: 3228
def pow(x, n, mod=None):
    ret = 1
    while n > 0:
        if n % 2 == 1:
            ret = (ret * x) % mod
        x = (x * x) % mod
        n >>= 1
    return ret
n,k = map(int,input().split())
mod = 10**9+7
fact = [None]*(1+n)
finv = [None]*(1+n)
fact[0] = 1
for i in range(1,n+1):
    fact[i] = (fact[i-1]*i)%mod
finv[n] = pow(fact[n],mod-2, mod=mod)
for i in range(n,0,-1):
    finv[i-1] = (finv[i]*i)%mod
def comb(n,k):
    tmp = (finv[n-k]*finv[k])%mod
    return (tmp*fact[n])%mod
ans = 0
for m in range(min(n,k+1)):
    ans = (ans+comb(n,m)*comb(n-1,m))%mod
print(ans)

Measured memory_bytes: 18804
while True:
    h,w = map(int,raw_input().split())
    if h==0 and w==0:
        break
    oddlist = ["#","."]
    evenlist = [".","#"]

    for i in xrange(0,h):
        line=""
        for j in xrange(0,w):
            if i%2==0:
                line+=oddlist[j%2]
            else:
                line+=evenlist[j%2]
        print line
    print

Measured memory_bytes: 6344
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var n2 = n * 2;
            for (int i = (int)Sqrt(n2); i >= 1; i--)
                if (n2 % i == 0)
                {
                    var w = i + n2 / i - 1;
                    if (w % 2 == 0) { Console.WriteLine("{0} {1}", n2 / i - w / 2, i); break; }
                }
        }
    }
}




Measured memory_bytes: 17904
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long hxtype;
typedef pair<int,int> pii;
typedef pair<int,ll > pil;
typedef pair<ll ,int> pli;
typedef pair<ll ,ll > pll;
#define rep(i,l,r) for(i=(l);i<=(r);++i)
#define per(i,l,r) for(i=(l);i>=(r);--i)
#define REP(i,l,r) for(i=(l);i< (r);++i)
#define PER(i,l,r) for(i=(l);i> (r);--i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
const int N=255,N2=505;
ll dp[N2][N];
pii d[N2];
int main(){
//	freopen("f.out","w",stdout);
	int n,n2,i,j,k,m=1,xa,xc,y,w;ll ans=0ll,p,pp;
	scanf("%d%d",&n,&p);n2=n<<1;pp=p*p;
	j=n*n;k=n2*n2;
	d[1]=mp(n,n2);
	REP(i,1,n )d[++m]=mp((int) ceil(sqrt(j-i*i))  ,(int)floor(sqrt(k-i*i))+1);//printf("i=%d m=%d\n",i,m);
	REP(i,n,n2)d[++m]=mp((int)floor(sqrt(k-i*i))+1,0                        );//printf("i=%d m=%d\n",i,m);
	sort(d+1,d+m+1);
//	rep(i,1,m )printf("(%d,%d)\n",d[i].fi,d[i].se);
	rep(k,0,n ){
//		printf("\n\n\nk=%d\n",k);
		memset(dp,0,sizeof(dp));
		dp[0][0]=1ll;
		xa=xc=0;
		rep(i,1,m){
			w=d[i].fi;
			if(y=d[i].se){
//				printf("A w=%d y=%d xa=%d xc=%d\n",w,y,xa,xc);
				rep(j,0,k)if(dp[i-1][j]){
//					printf("(%d,%d) %lld --%d--> (%d,%d) %lld\n",i-1,j,dp[i-1][j],y-k-n -xa+j,i,j  ,dp[i][j  ]);
//					printf("(%d,%d) %lld --%d--> (%d,%d) %lld\n",i-1,j,dp[i-1][j],w-j   -xc  ,i,j+1,dp[i][j+1]);
					dp[i][j  ]=(dp[i][j  ]+dp[i-1][j]*(y-k-n -xa+j)+pp)%p;
					dp[i][j+1]=(dp[i][j+1]+dp[i-1][j]*(w-j   -xc  )+pp)%p;
//					printf("(%d,%d) %lld --%d--> (%d,%d) %lld\n",i-1,j,dp[i-1][j],y-k-n -xa+j,i,j  ,dp[i][j  ]);
//					printf("(%d,%d) %lld --%d--> (%d,%d) %lld\n",i-1,j,dp[i-1][j],w-j   -xc  ,i,j+1,dp[i][j+1]);
				}
				++xa;
			}else{
//				printf("C w=%d xa=%d xc=%d\n",w,xa,xc);
				rep(j,0,k)if(dp[i-1][j]){
//					printf("(%d,%d) %lld --%d--> (%d,%d) %lld\n",i-1,j,dp[i-1][j],w-j   -xc  ,i,j  ,dp[i][j  ]);
					dp[i][j  ]=(dp[i][j  ]+dp[i-1][j]*(w-j   -xc  )+pp)%p;
//					printf("(%d,%d) %lld --%d--> (%d,%d) %lld\n",i-1,j,dp[i-1][j],w-j   -xc  ,i,j  ,dp[i][j  ]);
				}
				++xc;
			}
		}
//		printf("%lld\n",dp[m][k]);
		if(k&1)ans-=dp[m][k];else ans+=dp[m][k];
	}
	printf("%lld\n",(ans+pp)%p);
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<pair<int,int> > arr;
	for(int i=1;i<=n;i++)
	{
		int a;
		cin>>a;
		arr.push_back(make_pair(a,i));
	}
	sort(arr.begin(),arr.end());
	for(int i=0;i<arr.size();i++)
	{
		pair<int,int> at = arr[i];
		cout<<at.second<<" ";
	}
	return 0;
}

Measured memory_bytes: 1780
#input
N = int(input())
P = list(map(int, input().split()))

#output
import heapq as hp
Q = []
answer = 0
for i in range(N):
    hp.heappush(Q, P[i])
    temp = hp.heappop(Q)
    hp.heappush(Q, temp)
    if temp == P[i]:
        answer += 1

print(answer)

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

int main(){
	int ang=90, walk, inang;
	double x=0.0, y=0.0, rad;
	while(true){
		scanf("%d,%d", &walk, &inang);
		if(walk==0 && inang==0) break;
		rad=ang*M_PI/180.0;
		x = x+( (double)walk*cos(rad) );
		y = y+( (double)walk*sin(rad) );
		ang = (ang-inang)%360;
	}
	cout<<int(x)<<endl<<int(y)<<endl;
	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
#define rep(i, seisu) for(int i = 0; i < (int)(seisu); i++)

typedef long long ll;
///vector<pair<string, int>>;

int main(){
 int n, k;
 cin >> n >> k;
 vector<int> a(n, 0);
 rep(i, n) cin >> a.at(i);
 if(n == k) {
   cout << 1;
   return 0;
 }
 else{
   int ans;
   if((n-1)%(k-1) ==0) ans = (n-1)/(k-1);
   else ans = (n-1)/(k-1) + 1;
   cout << ans << endl; 
 }
}


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

int main(){
    int n;
    cin >> n;
    int sum = 0;
    vector<vector<int>>a(2,vector<int>(n));
   for(int i = 0; i < 2; i++){
       for(int j = 0; j < n; j++){
           cin >> a[i][j];
           if(i == 1)
           sum += a[i][j];
       }
   }
   vector<int> b(n),c(n);
    int suma = 0;
   for(int i = 0; i < n; i++){
       suma += a[0][i];
       b[i] = suma;
   }
   c[0] = sum;
   for(int i = 1; i < n; i++){
       sum -= a[1][i - 1];
       c[i] = sum;
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans = max(b[i] + c[i], ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int n,m;
  cin>>n>>m;
  vector<int> ac(n,0),wa(n,0);
  REP(i,m){
    int p;
    string s;
    cin>>p>>s;
    if(ac[p-1]==1) continue;
    if(s=="WA") wa[p-1]++;
    if(s=="AC") ac[p-1]=1;
  }

  int a1=0,a2=0;
  REP(i,n){
    a1+=ac[i];
    if(ac[i]==1) a2+=wa[i];
  }
  cout<<a1<<" "<<a2<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>

using namespace std;

long long int val[1000],n,wt[1000],w,memo[1010][100000];

long long int dp(int w,int n){
    if(w == 0 || n == 0)
        return 0;
    if(memo[n][w] != -1){
        return memo[n][w];
    }
    if(w < wt[n-1]){
        memo[n][w] = dp(w,n-1);
    }
    else
        memo[n][w] = max(val[n-1] + dp(w-wt[n-1],n-1) , dp(w,n-1));
    return memo[n][w];
}

int main (){
    memset(memo,-1,sizeof(memo));
    cin >> n >> w;
    for(int i=0;i<n;i++)
        cin >> wt[i] >> val[i];
    cout<<dp(w,n);
    return 0;
}

Measured memory_bytes: 789376