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

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt();
		int t[] = new int[n];
		int v[] = new int[n];
		for(int i=0;i<n;i++)t[i] = fs.nextInt();
		for(int i=0;i<n;i++)v[i] = fs.nextInt();
		
		int tsum[] = new int[n+1];
		for(int i=0;i<n;i++)tsum[i+1]=tsum[i]+t[i];
		int total = 0;
		for(int i=0;i<n;i++) total += t[i];
		//0.5ずつ速度を求める。
		
		double maxV[] = new double[2*total+3];
		Arrays.fill(maxV, 1e9);
		for(int i=0;i<n;i++) {
			if(i==0) {
				for(int j=0;j<tsum[i+1];j++) {
					maxV[2*j] = Math.min(maxV[2*j],v[i]);
					maxV[2*j+1] = Math.min(maxV[2*j+1],v[i]);
					maxV[2*j+2] = Math.min(maxV[2*j+2],v[i]);
				}
			}
			else {
				for(int j=tsum[i];j<tsum[i+1];j++) {
					maxV[2*j] = Math.min(maxV[2*j],v[i]);
					maxV[2*j+1] = Math.min(maxV[2*j+1],v[i]);
					maxV[2*j+2] = Math.min(maxV[2*j+2],v[i]);
				}
			}
		}
		
		
		
		maxV[0]=0;
		for(int i=1;i<=2*total;i++) {
			maxV[i] = Math.min(maxV[i], maxV[i-1]+0.5); 
		}
		maxV[2*total]=0;
		for(int i=2*total;i>0;i--) {
			maxV[i-1] = Math.min(maxV[i-1], maxV[i]+0.5);  
		}
		
		double ans = 0;
		for(int i=0;i<2*total;i++) {
			double max = Math.max(maxV[i], maxV[i+1]);
			double min = Math.min(maxV[i], maxV[i+1]);
			double square = 0.5 * min;
			double triangle = 0.5 * 0.5 * (max - min);
			double s = square + triangle; //台形の面積
			ans += s;
		}
		System.out.println(ans);
		
		
		
		System.out.println();
		
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

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

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

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

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>

using namespace std;

/*
    let's try computer shogi!!!
    答えを見てから書いたので感慨もない。
 */

struct achist{
  int id;
  int height;
};


struct loc2d{
  int x;
  int y;
};

bool comp_loc2d(const loc2d &l1, const loc2d &l2){
  if(l1.x == l2.x){
    return l1.y < l2.y;
  }
  return l1.x < l2.x;
}


int main(){
  int H, W;

  cin >> H >> W;
  string data[H];
  vector<loc2d> badlocs;
  
  for(int i=0;i<H;++i){
    cin >> data[i];
  }

  for(int i=0;i<H-1;++i){
    for(int j=0;j<W-1;++j){
      int cnt = 0;
      if(data[i][j]=='.'){
	cnt++;
      }
      if(data[i+1][j]=='.'){
	cnt++;
      }
      if(data[i][j+1]=='.'){
	cnt++;
      }
      if(data[i+1][j+1]=='.'){
	cnt++;
      }
      if(cnt == 1 || cnt ==3){
	loc2d l;
	l.y = i; l.x = j;
	badlocs.push_back(l);
      }
    }
  }

  sort(badlocs.begin(), badlocs.end(), comp_loc2d);
  for(int i=0;i<badlocs.size();++i){
    //cout<<badlocs[i].x<<","<<badlocs[i].y<<endl;
  }
  
  // 最大長方形アルゴリズムの準備
  // http://algorithms.blog55.fc2.com/blog-entry-133.html
  int hists[H-1][W-1];
  
  for(int j=0;j<W-1;++j){
    int seq = 0;
    for(int i=0;i<H-1;++i){
      loc2d l;
      l.x = j;
      l.y = i;
      bool block = binary_search(badlocs.begin(),badlocs.end(),l,comp_loc2d);
      if(block){
	//cout<<"b"<<j<<","<<i<<endl;
	hists[i][j]=0;
	for(int l=0;l<seq;++l){
	  hists[i-1-l][j] = l+1;
	}
	seq = 0;
      }else{
	seq++;
	if(i == H-2){
	  for(int l=0;l<seq;++l){
	    hists[i-l][j] = l+1;
	  }
	}
      }
    }
  }
  for(int i=0;i<H-1;++i){
    for(int j=0;j<W-1;++j){
      //cout<<hists[i][j]<<",";
    }
    //cout<<endl;
  }

  // ヒストグラムの最大を取る
  stack<achist> acs;
  int maxv = max(H,W);
  for(int i=0;i<H-1;++i){
    for(int j=0;j<W;++j){
      achist ac;
      if(j!=W-1){
	ac.id = j;
	ac.height = hists[i][j];
      }else{
	ac.id = W-1;
	ac.height = 0;
      }
      if(acs.empty()){
	acs.push(ac);
      }else{
	if(acs.top().height < ac.height){
	  acs.push(ac);
	}else if(acs.top().height > ac.height){
	  achist ac2;
	  ac2.height = ac.height;
	  while(!acs.empty() && acs.top().height >= ac.height){
	    const int v = (ac.id - acs.top().id+1) * (acs.top().height+1);
	    maxv = max(maxv,v);
	    ac2.id = acs.top().id;
	    acs.pop();
	  }
	  if(acs.empty()){
	    ac2.id = 0;
	  }
	  acs.push(ac2);
	
	}
      }
    }
  }
  cout<<maxv<<endl;
  return 0;
}

Measured memory_bytes: 42980
import math
def plot(x,y):
    print(f'{x:.8f} {y:.8f}')
def koch(n,x1,y1,x2,y2):
    if n==0:
        plot(x1,y1)
        return
    sx=(2*x1+x2)/3
    sy=(2*y1+y2)/3
    tx=(x1+2*x2)/3
    ty=(y1+2*y2)/3
    ux=(tx-sx)*(1/2)-(ty-sy)*(math.sqrt(3)/2)+sx
    uy=(tx-sx)*(math.sqrt(3)/2)+(ty-sy)*(1/2)+sy
    koch(n-1,x1,y1,sx,sy)
    koch(n-1,sx,sy,ux,uy)
    koch(n-1,ux,uy,tx,ty)
    koch(n-1,tx,ty,x2,y2)
    
n=int(input())
koch(n,0,0,100,0)
plot(100,0)





Measured memory_bytes: 5752
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
const int MAXN = (int)1e6+7;

vector<int> G[MAXN];
int val[MAXN];
int add[MAXN];

inline void dfs(int u,int fa,int ad) {
    val[u] = add[u]+ad;
    rep(i,0,G[u].size()-1) {
        int v = G[u][i];
        if (v == fa) continue;
        dfs(v,u,ad+add[u]);
    }
}

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

    int N,Q;
    cin >> N >> Q;
    rep(i,1,N-1) {
        int x,y;
        cin >> x >> y;
        G[x].pb(y);
        G[y].pb(x);
    }
    rep(i,1,Q) {
        int po,v;
        cin >> po >> v;
        add[po] += v;
    }
    dfs(1,-1,0);
    rep(i,1,N) {
        cout << val[i] << " ";
    }cout << endl;
}




Measured memory_bytes: 47872
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<vector>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=4e18;
const ll MOD=1e9+7;
const double EPS=1e-7;

ll N,M;
ll d[101][101];
ll nxt[101][101];
int main(){
    cin>>N>>M;
    for(ll i=0;i<N;i++){
        for(ll j=0;j<N;j++){
            if(i==j){
                d[i][j]=0;
            }else{
                d[i][j]=INF;
            }
            nxt[i][j]=j;
        }
    }
    for(ll i=0;i<M;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        d[a][b]=c;
        d[b][a]=c;
    }
    for(ll k=0;k<N;k++){
        for(ll i=0;i<N;i++){
            for(ll j=0;j<N;j++){
                if(d[i][j]>d[i][k]+d[k][j]){
                    d[i][j]=d[i][k]+d[k][j];
                    nxt[i][j]=nxt[i][k];
                }
            }
        }
    }
    set<P> st;
    for(ll s=0;s<N;s++){
        for(ll t=s+1;t<N;t++){ 
            for(ll cur=s;cur!=t;cur=nxt[cur][t]){
                st.insert(P(min(cur,nxt[cur][t]),max(cur,nxt[cur][t])));
            }
        }
    }
    cout<<M-st.size()<<endl;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int L = int.Parse(str[0]);
		int R = int.Parse(str[1]);
		long mod = 2019;
		long ans = 2018;
		Random rnd = new System.Random();
		for(var i=0;i<30000000;i++){
			long a1 = L+i%(R-L);
			long a2 = a1+1+rnd.Next(R-(int)a1);
			ans = Math.Min(ans,(a1*a2)%mod);
          	//Console.WriteLine(a1+" "+a2);
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13136
#include<bits/stdc++.h>
using namespace std;
typedef long  ll;
#define fr(i,k,n) for(ll i = k;i<n;i++)
#define mo map<ll,ll> 
#define mod 1000000007
unordered_map<ll,vector<ll>> ms;
ll cd = 1;

ll dfs(ll j,bool visited[]){
	visited[j] = true;
	for(auto it = ms[j].begin();it != ms[j].end();it++){
		if(!visited[*it]){
			cd++;
			dfs(*it,visited);
		}
	}
	return cd;
}
int main(){
	 ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 ll n,m;
 cin>>n>>m;

 ll x,y;
bool visited[n+2];
memset(visited,false,sizeof(visited));
 fr(i,0,m){
 	cin>>x>>y;
 	ms[x].push_back(y);
 	ms[y].push_back(x);
 }
 ll ans = LLONG_MIN;
 fr(i,1,n+1){
 	if(!visited[i]){
 		ans = max(dfs(i,visited),ans);
 	}
 
 cd = 1;
 }
 ans = max(ans,ll(1));
 cout<<ans<<"\n";

 
}

Measured memory_bytes: 33560
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int long long
#define ends ' '
#define endl '\n'
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>

int32_t main()
{
	IOS;

	int n, k;
	cin >> n >> k;

	if(k != 1)
	cout << n-k;
	else
	cout << 0;

	return 0;
}

Measured memory_bytes: 256
/*
    AUTHOR:hruday pabbisetty
    NIT ROURKElA
*/
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
using namespace std::tr1;
#define opt ios_base::sync_with_stdio(0)
#define lli long long int
#define ulli unsigned long long int
#define I int
#define S string
#define D double
#define rep(i,a,b) for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define in(n) scanf("%lld",&n)
#define in2(a,b) scanf("%lld %lld",&a,&b)
#define in3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define out(n) printf("%lld\n",n)
#define inu(a) scanf("%lld",&a)
#define outu(a) printf("%llu",a)
#define ins(s) scanf("%s",&s)
#define outs(s) printf("%s",s)
#define mod 1000000007
#define inf 100000000000000
typedef long long       ll;
typedef pair<lli,lli>  plli;
typedef vector<lli>     vlli;
typedef vector<ulli>    vulli;
typedef vector<ll>      vll;
typedef vector<string>  vs;
typedef vector<plli>     vplli;
#define MM(a,x)  memset(a,x,sizeof(a));
#define ALL(x)   (x).begin(), (x).end()
#define P(x)       cerr<<"{"#x<<" = "<<(x)<<"}"<<endl;
#define P2(x,y)       cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<"}"<<endl;
#define P3(x,y,z)  cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<", "#z" = "<<(z)<<"}"<<endl;
#define P4(x,y,z,w)cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<", "#z" = "<<(z)<<", "#w" = "<<(w)<<"}"<<endl;
#define PP(x,i)     cerr<<"{"#x"["<<i<<"] = "<<x[i]<<"}"<<endl;
#define TM(a,b)     cerr<<"{"#a" -> "#b": "<<1000*(b-a)/CLOCKS_PER_SEC<<"ms}\n";
#define UN(v)    sort(ALL(v)), v.resize(unique(ALL(v))-v.begin())
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define sz() size()
#define nl cout<<"\n"
#define MX1 100005
#define MX2 1000005
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
lli dx[]={0,0,-1,1,-1,-1,1,1};
lli dy[]={1,-1,0,0,1,-1,-1,1};
lli power(lli a,lli b)
    {
    lli value;
    if(b==0)
        {
        return 1;
    }
    else if(b%2==0)
        {
        value=power(a,b/2)%mod;
        return(value*value)%mod;
    }
    else
        {
        value=power(a,b/2)%mod;
        return ((a*value)%mod*(value))%mod;
    }
}
int main()
{
      /*  #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #endif*/
    opt;
    lli a,b,ans=1;
    cin>>a>>b;
    while(a<=b)
    {
        a*=2;
        if(a<=b)
        {
            ans++;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
int n, a[100001],b,cnt;

scanf("%d",&n);  

for(int i=1;i<=n;i++)
{
	scanf("%d",&a[i]); 
}

for(int i=1;i<=n;i++)
{
	b=a[i];
	if(i==a[b]) cnt++;
}

printf("%d\n",cnt/2);

return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	int K, S;
	cin >> K >> S;



	long long ret = 0;
	for(int i=0; i<=K; i++)
	{
		for(int j=0; j<=K; j++)
		{
			int d = S - (i + j);

			if(d >= 0 && d <= K)
				ret++;
		}
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  string s;
  cin>>s;
  
  int n=s.size();
  vector<int> A(n);
  rep(i,n) A[i]=s[n-1-i]-'0';
  
  ll ans=0;
  for(int bit=0;bit<(1<<(n-1));bit++){
    ll c=1;
    for(int i=0;i<n;i++){
      ans+=c*A[i];
      if(bit&(1<<i)){
        c=1;
        continue;
      }
      c*=10;
    }
  }
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll inf=1e9+7;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int lcnt=0;
  int rcnt=0;
  int l=0,r=0;
  rep(i,n){
    if(s[i]=='(')lcnt++;
    else lcnt--;
    l=min(l,lcnt);
  }
  for(int i=n-1;i>=0;i--){
    if(s[i]==')')rcnt++;
    else rcnt--;
    r=min(r,rcnt);
  }
  rep(i,-l)cout << '(' ;
  cout << s ;
  rep(i,-r)cout << ')' ;
  cout << endl;
return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long num[1005],u,p[1005],n,cnt,mm=1;
vector<long long> v;
int main()
{
	num[1]=1;
	for(int i=2;i<=1000;i++)
	{
		p[i]=1;
		num[i]=1;
	}
	for(int i=2;i<=1000;i++)
	{
		if(p[i]==1)
		{
			for(int j=2;j*i<=1000;j++)
			{
				p[i*j]=0;
			}
		}
	}
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		u=i;
		for(int j=1;j<=1000;j++)
		{
			if(p[j]==1)
			{
				cnt=0;
				while(1)
				{
					if(u%j!=0)
					{
						break;
					}
					u/=j;
					++cnt;
				}
				v.push_back(cnt);
			}
		}
		for(int j=0;j<v.size();j++)
		{
			num[j+1]+=v[j];
			//printf("%d\n",v[j]);
		}
		v.clear();
	}
	for(int i=1;i<=168;i++)
	{
		mm*=num[i];
		mm%=1000000007;
	}
	printf("%lld\n",mm);
}

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

int main() {
  long n,ans=0;
  cin >> n;
  vector<long> rate(n);
  vector<long> color(9);
  for(long i=0;i<n;i++) cin >> rate[i];
  for(long i=0;i<n;i++) color[min(8L,rate[i]/400)]++;
  for(long i=0;i<8;i++) if(color[i]>0) ans++;
  cout << max(1L,ans) << " " << ans+color[8] << endl;
}

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

int main() {
  string word;
  getline(cin, word);
  int last = word.length() - 1;
  if( word[last] == 's' ) {
    cout << word << "es";
  } else {
    cout << word << "s";
  }
  return 0;
}

Measured memory_bytes: 3604
from collections import deque

_strings = deque(input())
num = int(input())

isReverse = False

for i in range(num):
    query = input().split()
    type = int(query[0])

    if type == 1:
        # _strings.reverse()
        isReverse = not isReverse
    else:
        mode = int(query[1])

        if (mode == 1 and not isReverse) or (mode == 2 and isReverse):
            _strings.appendleft(str(query[2]))
            # _strings.insert(0, str(query[2]))
        else:
            _strings.append(str(query[2]))
            # _strings.append(str(query[2]))

if isReverse:
    _strings.reverse()

print(''.join(_strings))

Measured memory_bytes: 76248
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for i in range(n):
    temp = c
    for j in range(m):
        temp += b[j] * a[i][j]
    if temp > 0:
        ans += 1

print(ans)

Measured memory_bytes: 3060
//2020-05-09 18:42:58
//Writer : SakaTaku
//文字列探索アルゴリズム(KMP法)
#include<string>
#include<vector>
using namespace std;

template <class Type>
struct KMP
{
    vector<Type> s, w;
    KMP(vector<Type> s, vector<Type> w):s(s),w(w){}
    vector<int> T;//次に照合する位置までバックトラック

    void KMP_table(){
        int i = 2, j = 0;
        T.push_back(-1);
        T.push_back(0);
        while (i <= w.size())
        {
            if (w[i-1] == w[j]){
                T.push_back(j+1); i++; j++;
            }
            else if (j > 0)j = T[j];
            else {
                T.push_back(0); i++;
            }
        }
    }
    //wと一致するsの部分文字列の先頭のインデックスを全て求める
    vector<int> kmp_search() {
        int m = 0;//s内の照合開始位置
        int i = 0;//w内の現在位置
        vector<int> ReturnValue;//返り値
        while (m+i < s.size()) {
            if (w[i] == s[m+i]) {
                i++;
                if (i == w.size()) {
                    ReturnValue.push_back(m);
                    m = m+i-T[i];
                    if (i > 0)i = T[i];
                }
            }
            else{
                m = m+i-T[i];
                if (i > 0)i = T[i];
            }
        }
        return ReturnValue;
    }
};
#include<iostream>
int main(){
    cin.tie(nullptr); ios::sync_with_stdio(false);
    string s, p; cin >> s >> p;
    vector <char> v1, v2;
    for (int i = 0; i < s.size(); i++)
        v1.push_back(s[i]);
    for (int i = 0; i < p.size(); i++)
        v2.push_back(p[i]);
    KMP<char> kmp = KMP<char>(v1, v2);
    kmp.KMP_table();
    vector<int> ans = kmp.kmp_search();
    for (int i : ans)cout << i << endl;
}


Measured memory_bytes: 11340
#include<bits/stdc++.h>
#define ll long long
#define up(x,y) ((x+y-1)/(y))
using namespace std;
ll T,a,b,c,d,len,l,r,mid,he,ta,mia;
string s;
bool ck(){
	ll la=a-mid*len, lb=b-mid;
	if (!la) return !lb;
	if (lb<0) return 0;
	return max(up(la,lb+1),up(lb,la))<=len;
}
char cal(ll p){
	if (p<=(len+1)*he) return p%(len+1)? 'A': 'B';
	if (a+b-p+1<=(len+1)*ta) return (a+b-p+1)%(len+1)? 'B': 'A';
	return p<=(len+1)*he+mia? 'A': 'B';
}
void realmain(){
	len=max(up(a,b+1),up(b,a+1));
	for (l=he=0,r=a/len;l<=r;ck()? l=(he=mid)+1: r=mid-1) mid=l+r>>1;
	ll la=a-he*len, lb=b-he;
	ta=lb/len; mia=la-ta;
	for (ll i=c;i<=d;++i) s+=cal(i);
}
int main(){
	for (cin>>T;T--;s+="\n") cin>>a>>b>>c>>d,realmain();
	cout<<s;
}

Measured memory_bytes: 512
n = int(input())
sum = 0.0
box = []
a = []
b = []
for num in range(n):
  box = input().split(" ")
  a.append(box[0])
  b.append(box[1])
  if b[num] == "JPY":
    sum += float(a[num])
  else:
    sum += (float(a[num]) * 380000.0)

print(sum)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
bool order=true;
deque<char> ch;
int main()
{
	char c[100005];
	cin>>c;
	int length=strlen(c);
	for(int i=0;i<strlen(c);i++)
	{
		ch.push_back(c[i]);
	}
	int Q;
	cin>>Q;
	for(int q=0;q<Q;q++)
	{
		int t;
		cin>>t;
		if(t==1)
		{
			order=!order;
		}
		else
		{
			int f;
			cin>>f;
			if(f==1)
			{
				char temp;
				cin>>temp;
				if(order)
				{
					ch.push_front(temp);
				}
				else
				{
					ch.push_back(temp);
				}
			}
			else
			{
				char temp;
				cin>>temp;
				if(order)
				ch.push_back(temp);
				else ch.push_front(temp);
			}
		}
	}
	if(order)
	{
		//cout<<endl<<"END:"<<order;
		while(!ch.empty())
		{
			cout<<ch.front();
			ch.pop_front();
		}
	}
	else
	{
		
		//cout<<order<<"END:";
		while(!ch.empty())
		{
			cout<<ch.back();
			ch.pop_back();
		}
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin>>N;
  string color;
  cin>>color;
  int count=1;
  for(int i=0;i<N-1;i++){
    if(color.at(i)!=color.at(i+1)){
      count++;
    }
  }
  cout<<count;
}

Measured memory_bytes: 512
#include <stdio.h>
int main() {
	int n, k, x, y, money = 0;
	scanf("%d%d%d%d", &n, &k, &x, &y);
	if (k >= n) printf("%d\n", n * x);
	if (k < n) printf("%d\n", (n - k) * y + k * x);
}

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

#define all(x)        (x).begin(),(x).end()
#define eb            emplace_back
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define sz(x)         ((int)(x).size())
#define rep(x,y,z)    for(int x=y;x<z;x++)
#define per(x,z,y)    for(int x=z-1;x>=y;x--)
#define trav(y,x)     for(auto& y:x)
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define vi            vector<int>
#define vpi           vector<pii>

int dbg = 0;
#define cri           if(0)
#define shame         cri cerr<<(++dbg)<<"\n\n";

// aaaaaaaaaaaaaaaa
void solve() {
  int n; cin >> n;
  string s;
  map<string, int> u;
  while (n--) {
    cin >> s;
    auto it = u.find(s);
    if (it == u.end())
      u[s] = 0;
  }
  cout << sz(u) << '\n';
}

int main() {
  // int _; scanf("%d", &_); while (_--)
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // int _; cin >> _; while(_--)
  solve();
	return 0;
}



Measured memory_bytes: 19120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += (b % mod + mod)) %= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    string s;
    cin >> s;
    int n = sz(s);
    
    deque<char> dq;
    rep(i, n) dq.eb(s[i]);
    
    int q;
    cin >> q;
    int flg = 0;
    while (q--) {
        int k;
        cin >> k;
        if (k == 1) flg ^= 1;
        else {
            int a; char c;
            cin >> a >> c;
            int x = (flg + a) % 2;
            if (x == 1) dq.emplace_front(c);
            else dq.eb(c);
        }
    }
    s = "";
    while (sz(dq)) {
        s += dq.front();
        dq.pop_front();
    }
    
    if (flg) reverse(all(s));
    cout << s << endl;
}


Measured memory_bytes: 4244
#include <bits/stdc++.h>
#define fr first
#define sc scanf
#define pf printf
#define se second
#define sq(x) x * x
#define ll long long
#define pb push_back
#define mk make_pair
#define ld long double
#define pr pair<int,int>
#define sz(s) int(s.size())
#define piip pair< pair<ll,ll>,ll >
#define fin(s) freopen( s, "r", stdin )
#define fout(s) freopen( s, "w", stdout )
#define TIME ios_base::sync_with_stdio(0)
using namespace std;

const ll INF = 1e9;
const ll N = 1e5 + 1;
const ll mod = 1e9 + 7;
const long double eps = 1E-7;

int n, a[N];
int main()
{
    TIME;
    int ans = 0;
    cin >> n;
    for( int i = 1; i <= n; i ++ )
        cin >> a[i];
    for( int i = 2; i < n; i ++ )
    {
        ans += a[i] > a[i-1] && a[i] < a[i+1];
        ans += a[i] < a[i-1] && a[i] > a[i+1];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define FORN(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define REP(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 fgdsdhsdgfsdf
#define y1 rgfhgghgbegdt
#define x2 wegdg5hdrydgs
#define y2 eyewytrgsfhre
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
int main()
{
	int n;
	cin>>n;
	cout<<(n+1)/2<<endl;
	return 0;
}



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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

int main() {
	double a,b,x;

	cin >> a >> b >> x;
	double ans = 0;

	if(x == a*a*b) {
		ans = 0;
	} else if(x*2 == a*a*b) { // half
		ans = atan(double(b)/double(a));
	} else if(x*2 > a*a*b) { // more than half
		double d = 2*b - (x*2)/(a*a);
		ans = atan(d/double(a));
	} else { // less than half
		double e = (x*2) / (a*b);
		ans = atan(b/e);
	}
	printf("%.10lf\n", ans*180/3.14159265359);

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
   
   
        
       ll x1,x2,x3,x4,x5;
       cin>>x1>>x2>>x3>>x4>>x5;
       if(x1==0)
       {cout<<"1";}
       if(x2==0)
       {cout<<"2";}
       if(x3==0)
       {cout<<"3";}
       if(x4==0)
       {cout<<"4";}
       if(x5==0)
       {cout<<"5";}
	return 0;
}

Measured memory_bytes: 3636
let pn n =
  let pt = Array.make (n+1) 1 in
  pt.(0) <- 0;
  pt.(1) <- 0;
  let rec iter i =
    if i * i > n then Array.fold_left (+) 0 pt
    else
      if pt.(i) = 1 then
        let rec clr j =
          if j > n then ()
          else begin
              pt.(j) <- 0;
              clr (j+i)
            end in
        clr (i*i);
        iter (i+1)
      else
        iter (i+1)
  in iter 2
     
let () =
  let rec loop () =
    let n = try read_int () with _ -> 0 in
    if n = 0 then ()
    else begin
        pn n |> string_of_int |> print_endline;
        loop ()
      end
  in
  loop ()

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

int main(){
    long long D, G;
    std::cin >> D >> G;
    G /= 100;
    std::vector< int > P(D);
    std::vector< int > C(D);
    for(int i=0; i<D; i++){
        std::cin >> P[i] >> C[i];
        P[i];
        C[i] /= 100;
    }
    
    std::vector< std::vector< int > > dp(D+1, std::vector< int >(G+1, 1e8));
    dp[0][0] = 0;
    
    for(int i=1; i<=D; i++){
        std::vector< int > cur(G+1, 1e8);
        cur[0] = 0;
        for(int j=1; j<=G; j++){
            if(i * P[i-1] + C[i-1] < j){
                break;
            }else if(i * P[i-1] < j){
                cur[j] = P[i-1];
            }else{
                cur[j] = j / i + (j % i != 0);
            }
        }
        int index_a1 = 1, index_a2 = 0, index_b1 = 0, index_b2 = 1;
        dp[i][0] = 0;
        while(index_a1 + index_a2 <= G){
            int a = dp[i-1][index_a1] + cur[index_a2];
            int b = dp[i-1][index_b1] + cur[index_b2];
            if(a > b){
                dp[i][index_a1 + index_a2] = b;
            }else{
                dp[i][index_a1 + index_a2] = a;
            }
            
            if(index_a1 == G || dp[i-1][index_a1+1] >= 1e8){
                index_a2++;
            }else{
                index_a1++;
            }
            
            if(index_b2 == G || cur[index_b2+1] >= 1e8){
                index_b1++;
            }else{
                index_b2++;
            }
        }
    }
    
    
    std::cout << dp[D][G] << std::endl;
    
    
    return 0;
    
}


Measured memory_bytes: 8084
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string X;
  cin >> X;
  ll N = X.size();
  int scount = 0;
  int ans = 0;
  for(int i = 0; i < N; i++){
    char c = X.at(i);
    if(c == 'S'){
      scount++;
    }
    else{
      if(scount > 0){
        scount--;
      }
      else{
        ans++;
      }
    }
  }
  ans += scount;
  cout << ans << endl;
}

Measured memory_bytes: 720
use std::io;
use std::str::FromStr;

fn main(){
    let stdin = io::stdin();
    let mut buf = String::new();

    stdin.read_line(&mut buf).expect("");
    let n: i32 = buf.trim().parse().unwrap();
    let mut ans = 0;
    for _ in 0..n {
        let mut buf2 = String::new();
        stdin.read_line(&mut buf2).ok();
        let mut it = buf2.split_whitespace().map(|n| i32::from_str(n).unwrap());
        let (n, m) = (it.next().unwrap(), it.next().unwrap());
        ans += m - n + 1;
    }
    println!("{}", ans);
}

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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> p;
  rep(i,n){
    int tmp;
    cin >> tmp;
    p.push_back(tmp);
  }
  sort(p.begin(),p.end());
  long ans = 0;
  rep(i,k)ans += p[i];
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int n;
bool day[35][55];



int main(){
    while(true){
        cin >> n;
        if(n == 0)break;

        for(int i = 1;i <= n;i++){
            int f;
            cin >> f;
            for(int j = 0;j < 33;j++)day[j][i] = false;
            for(int j = 0;j < f;j++){
                int tmp;
                cin >> tmp;
                day[tmp][i] = true;
            }
        }
        set<int> s[33][55];
        for(int i = 1;i <= n;i++)s[0][i].insert(i);
        int ans = -1;
        for(int i = 1;i <= 30;i++){
            for(int j = 1;j <= n;j++){
                for(auto itr = s[i-1][j].begin(); itr != s[i-1][j].end(); ++itr){
                    s[i][j].insert(*itr);
                }
            }
            set<int> tmps;
            for(int j = 1;j <= n;j++){
                if(day[i][j] == false)continue;
                for(auto itr = s[i][j].begin(); itr != s[i][j].end();++itr){
                    tmps.insert(*itr);
                }
            }
            if(tmps.size() == n){
                ans = i;
                break;
            }
            for(int j = 1;j <= n;j++){
                if(day[i][j] == false)continue;
                for(auto itr = tmps.begin();itr != tmps.end();++itr){
                    s[i][j].insert(*itr);
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 6556
N = int(input())
a = list(map(int, input().split()))
ans = 0
while True:
	odd = 0 
	for i in range(len(a)):
		if a[i] % 2 == 0:
			a[i] /= 2
			ans += 1
		else:
			odd += 1
	if odd == len(a):
		break
print(ans) 

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

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

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int H,W,M;
    cin >> H >> W >> M;
    vector<vector<int>> Ah(H,vector<int> (2));
    vector<vector<int>> Aw(W,vector<int> (2));
    
    rep(i,H) {
        Ah[i][1] = i;
    }
    rep(i,W) {
        Aw[i][1] = i;
    }
    set<pair<int,int>> S;
    rep(i,M) {
        int h,w;
        cin >> h >> w;
        h--,w--;
        Ah[h][0]++;
        Aw[w][0]++;
        S.insert(make_pair(h,w));
    }
    sort(Ah.begin(),Ah.end());
    sort(Aw.begin(),Aw.end());

    int h_max = Ah.back()[0];
    int w_max = Aw.back()[0];

    set<int> Sh,Sw;

    int idx = H-1;
    while(1) {
        if (Ah[idx][0] == h_max) {
            Sh.insert(Ah[idx][1]);
        }
        else {
            break;
        }
        idx--;
        if (idx<0) break;
    }
    idx = W-1;
    while(1) {
        if (Aw[idx][0] == w_max) {
            Sw.insert(Aw[idx][1]);
        }
        else break;
        idx--;
        if(idx<0) break;
    }
    int ans = h_max + w_max - 1;

    int tmp = Sh.size()*Sw.size();

    for (auto s:S) {
        int h = s.first;
        int w = s.second;
        if (Sh.count(h) && Sw.count(w)) {
            tmp--;
        }
    }
    if (tmp!=0) ans++;
    cout << ans << endl;

}


Measured memory_bytes: 78108
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] grid = new char[H][];
		for (int i = 0; i < grid.length; i++) {
			grid[i] = sc.next().toCharArray();
		}
		short[][][][] max = new short[2][W][H][H];
		int tmp;
		for (int from2 = W-1; from2 >= 0; from2--) {
			for (int from1 = 0; from1 < H; from1++) {
				max[0][from2][from1][from1] = (short)(from2 + 1);
				if (from2 + 1 < W && grid[from1][from2] == grid[from1][from2 + 1]) {
					max[0][from2][from1][from1] = max[0][from2 + 1][from1][from1];
				}
			}
			for (int from1 = 0; from1 < H; from1++) {
				for (int to1 = from1 + 1; to1 < H; to1++) {
					max[0][from2][from1][to1] = (short)from2;
					if (grid[to1-1][from2] == grid[to1][from2]) {
						max[0][from2][from1][to1] = (short)Math.min(max[0][from2][from1][to1-1], max[0][from2][to1][to1]);
					}
				}
			}
		}
		int ans = -1;
		for (int i = 1; i < 17; i++) {
			int me = i & 1;
			int prev = 1 - me;
			if (max[prev][0][0][H-1] >= W) {
				ans = i - 1;
				break;
			}
			for (int from2 = 0; from2 < W; from2++) {
				for (int from1 = 0; from1 < H; from1++) {
					int med = from1;
					for (int to1 = from1; to1 < H; to1++) {
						tmp = max[prev][from2][from1][to1];
						max[me][from2][from1][to1] = tmp < W ? max[prev][tmp][from1][to1] : (short)W;
						int cur = med + 1 <= to1 ? Math.min(max[prev][from2][from1][med], max[prev][from2][med+1][to1]) : -1, next;
						while (med + 2 <= to1 && (next = Math.min(max[prev][from2][from1][med+1], max[prev][from2][med+2][to1])) >= cur) {
							med++;
							cur = next;
						}
						if (cur != -1) max[me][from2][from1][to1] = (short)Math.max(max[me][from2][from1][to1], cur);
					}
				}
			}
		}
		if (ans == -1) ans = 16;
		out.println(ans);
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


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

using namespace std;

typedef long long ll;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int n;
  cin >> n;
  int a[n];
  rep(i, 0, n) {
    cin >> a[i];
  }

  sort(a, a + n);

  cout << a[n - 1] - a[0] << endl;
}


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

typedef long long LL;
const int MN=105;
const int MW=1e5+5;
int w[MN],v[MN];
LL dp[MW];

int main()
{
	int n,ww; scanf("%d%d",&n,&ww);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&w[i],&v[i]);
	for(int i=1;i<=n;i++)
	{
		for(int j=ww;j>=w[i];j--)
			dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
	}
	printf("%lld\n",dp[ww]);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<algorithm>
    #include<string>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    using namespace std;
    #define INF 10000000;
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define vec(n) vector<int> vec(n)
    #define vvec(m,n) vector<vector<int>> vec(m,vector(n))

    int main(){
      int n;
      string s,t,r;
      cin >> n >> s >> t;

      rep(i,n){
        r += s[i];
        r += t[i];
      }

      cout << r <<endl;
    }

Measured memory_bytes: 256
from collections import Counter

N, M = input().split()
N, M = int(N), int(M)
p = [0] * M
S = [0] * M

cnt_wa = Counter()
cnt_ac = Counter()
cnt_wa_all = 0
cnt_ac_all = 0
for i in range(M):
    pt, S = input().split()
    p = int(pt)

    if cnt_ac[p] == 0:
        if S == 'WA':
            cnt_wa.update([p])
        if S == 'AC':
            cnt_ac.update([p])
            cnt_ac_all += 1
            cnt_wa_all += cnt_wa[p]

print(cnt_ac_all, cnt_wa_all)

Measured memory_bytes: 15452
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  while(cin >> n){
    if(n==0)break;
    int ans[n][n];
    bool f[n][n];
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        f[i][j]=true;
      }
    }
    ans[n/2+1][n/2]=1;
    f[n/2+1][n/2]=false;
    int nowi=n/2+1,nowj=n/2;
    for(int i=2;i<=n*n;i++){
      nowi++;
      nowj++;
      if(nowi==n){
        nowi=0;
      }
      if(nowj==n){
        nowj=0;
      }
      while(1){
        if(f[nowi][nowj]){
          f[nowi][nowj]=false;
          ans[nowi][nowj]=i;
          break;
        }else{
          nowi=((nowi+1==n)?0:nowi+1);
          nowj=((nowj)?nowj-1:n-1);
        }
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if(ans[i][j]<1000){
          cout << " ";
        }
        if(ans[i][j]<100){
          cout << " ";
        }
        if(ans[i][j]<10){
          cout << " ";
        }
        cout << ans[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}



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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

ll N;
ll a[25][25];
const ll MA = (1ll<<21);

ll dp[MA];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    REP(i, MA) dp[i] = 0;
    dp[0] = 1;

    cin >> N;
    REP(i, N){
    	REP(j, N){
    		cin >> a[i][j];
    	}
    }

    REP(mask, (1ll<<N)){
    	ll cnt = __builtin_popcountll(mask);
    	REP(i, N){
    		if(!(mask>>i & 1) && a[cnt][i]==1){
    			ll next_mask = (mask ^ (1<<i));
    			dp[next_mask] += dp[mask];
    			dp[next_mask] %= mod;
    		}
    	}
    }
    cout << dp[(1ll<<N)-1] << endl;

    /*
    REP(i, (1<<N)){
        cout << dp[i] << " ";
    }
    cout << endl;
    */
    return 0;
}

Measured memory_bytes: 16640
//atcoder beginner contest 60
import java.util.Scanner;
class Main{
  private int n;
  private int bettime;
  private int[] time;
  public static void main(String[] args){
    Main s = new Main();
    s.readcommand();
    System.out.println(s.calctime());
  }

  void readcommand(){
    Scanner scan = new Scanner(System.in);
    n = scan.nextInt();
    bettime = scan.nextInt();
    time = new int[n];
    for(int i=0;i<n;i++) time[i] = scan.nextInt();
  }

  int calctime(){
    int counttime = 0;
    for(int i=0;i<n-1;i++){
      if(time[i+1]-time[i] < bettime){
        counttime += time[i+1]-time[i];
      }else{
        counttime += bettime;
      }
    }
    return counttime+bettime;
  }
}


Measured memory_bytes: 65648
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forab(i, a, b) for(int i=(a);i<(b);++i)
#define foreach(i, n) for (__typeof(n.begin()) i = n.begin(); i != n.end(); ++i)
#define sqr(x) ((x)*(x))
#define clr(a, b) memset(a, b, sizeof(a))
#define MP make_pair
#define PB push_back
#define SZ(a) ((int)a.size())
#define all(a) (a).begin(),(a).end()
#define inf 0x3f3f3f3f
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
const double eps = 1e-8;
int dcmp(double x) { if (x < -eps) return -1; else return x > eps;}
#define se(x) cout<<#x<<" = "<<x<<endl

#ifdef CHEN_PC
	#define debug(...) printf(__VA_ARGS__)
#else 
	#define debug(...)
#endif

const int N = 100010;
const int mod = 1000000007; // 10^9+7
int dp[N];
int val[N];
int pnt[N];

int trans(char a) {
	return  a == 'a' ? 1 : 2;
}

int solve(char *s, int n) {
	bool flag = true;
	forab (i, 1, n) {
		if (s[i] == s[i - 1]) {
			flag = false;
			break;
		} 
	}
	if (flag) {
		return 1;
	}
	val[n] = 0;
	int z[3];
	z[0] = n;
	z[1] = z[2] = pnt[n+1] = n+1;
	ford (i, n) {
		val[i] = val[i + 1] + trans(s[i]);
		val[i] %= 3;
		pnt[i] = z[val[i]];
		z[val[i]] = i;
	}

	// debug("%s\n", s);
	// forn (i, n) {
	// 	debug("%d", val[i]);
	// }
	// puts("");
	// forn (i, n) {
	// 	debug("%d", pnt[i]);
	// }
	// puts("");
	// debug("%d,%d,%d\n", z[0], z[1], z[2]);

	clr(dp, 0);
	dp[0] = 1;
	forn (i, n) {
		dp[i + 1] += dp[i];
		dp[i + 1] %= mod;
		int tag = val[i] - (3 - trans(s[i]));
		tag = (tag % 3 + 3) % 3;
		dp[z[tag]] += dp[i];
		dp[z[tag]] %= mod;
		z[val[i]] = pnt[i];
		// debug("-- %d, %d, dp[%d] = %d, dp[%d] = %d\n", tag, z[tag], i, dp[i], z[tag], dp[z[tag]]);
	}
	int ret = 0;
	forab (i, 1, n+1) {
		// debug("%d %d %d\n", i, val[i], dp[i]);
		if (val[i] == 0) {
			ret += dp[i];
			ret %= mod;
		}
	}
	return ret;
}

int main(int argc, char *argv[]) {
#ifdef CHEN_PC
	freopen("E.in", "r", stdin);
#endif

	char str[N];
	while (scanf("%s", str) != EOF) {
		int n = strlen(str);
		int ret = solve(str, n);
		printf("%d\n", ret);
		// debug("=====\n");
	}
	return 0;
}



Measured memory_bytes: 1536
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

void call(int n)
{
	int i = 1;
	int x;

	do {
		x = i;
		if (x % 3 == 0) {
			printf(" %d", i);
		}
		else {
			do {
				if (x % 10 == 3) {
					printf(" %d", i);
					x = 0;
				}
				else x /= 10;
			} while (x);
		}
	} while (++i <= n);
	putchar('\n');
}

#if 1
int main()
{
	int n;

	scanf("%d", &n);
	call(n);
	return 0;
}
#endif



Measured memory_bytes: 2048
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		int w = sc.nextInt();
		if (w >= s) {
		    System.out.println("unsafe");
		} else {
		    System.out.println("safe");
		}
	}
}



Measured memory_bytes: 35712
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  string S, T; cin >> S >> T;
  bool ans = false;
  rep(i,S.size()) {
    if (S == T) {
      ans = true;
      break;
    }
    S = S.back() + S.substr(0, S.size()-1);
  }
  
  if (ans) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,s) for(int i=1;i<n;++i)

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

const ll INF = 1010101010;
const ll MOD = 1000000007;

ll n, m, ans = 0;
char last;
string A[10101];
int main() {
	map <string, int> m;
	cin >> n;
	rep(i, n) {
		cin >> A[i];
		if (m.count(A[i]) == 0)
			m.insert(make_pair(A[i], 1));
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	last = A[0][A[0].size() - 1];
	FOR(i, n) {
		if (last != A[i][0]) {
			cout << "No" << endl;
			return 0;
		}
		else
			last = A[i][A[i].size() - 1];
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 384
ans = 0
def dfs(v, visitedNode, graph):
    visitedNode[v] = 1
    # print(visitedNode)
    if all(visitedNode):
        global ans
        ans += 1
        return
    for node in graph[v]:
        if visitedNode[node]:
            # 探索済みならば、ほかの隣接候補へ。
            continue
        else:
            # 未探索ならば、次の階層を調べる。
            dfs(node, visitedNode[:], graph)


N, M = map(int, input().split())
v = 0
visitedNode = [0] * N


graph = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
# print(graph)


dfs(v, visitedNode, graph)
print(ans)


Measured memory_bytes: 3064
N = int(input())
L = list(map(int,input().split()))

ans = 0

while len(L) :
    if L[0] == 0 :
        L.pop(0)
    else :
        ans += 1
        for i in range(len(L)) :
            if L[i] != 0 :
                L[i] -= 1
            else :
                break
print(ans)


Measured memory_bytes: 2940